summaryrefslogtreecommitdiffabout
path: root/kmicromail
authorzautrix <zautrix>2004-09-16 23:05:56 (UTC)
committer zautrix <zautrix>2004-09-16 23:05:56 (UTC)
commitaf411746b1480e7b331ea7d163f39d2507cf7264 (patch) (unidiff)
treebc839893f0bd002a34368987bdda3e71aad630c4 /kmicromail
parentb44edfb21be0eee91c4f47401e3fe6ff37e4c16c (diff)
downloadkdepimpi-af411746b1480e7b331ea7d163f39d2507cf7264.zip
kdepimpi-af411746b1480e7b331ea7d163f39d2507cf7264.tar.gz
kdepimpi-af411746b1480e7b331ea7d163f39d2507cf7264.tar.bz2
Fixed timezone problems in ompi
Diffstat (limited to 'kmicromail') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/accountitem.cpp7
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp1
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.cpp35
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.h2
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp17
-rw-r--r--kmicromail/libmailwrapper/mailtypes.cpp20
-rw-r--r--kmicromail/libmailwrapper/mailtypes.h4
-rw-r--r--kmicromail/opiemail.cpp5
8 files changed, 63 insertions, 28 deletions
diff --git a/kmicromail/accountitem.cpp b/kmicromail/accountitem.cpp
index 7795055..49d86fc 100644
--- a/kmicromail/accountitem.cpp
+++ b/kmicromail/accountitem.cpp
@@ -1,1148 +1,1147 @@
1 1
2#include "accountitem.h" 2#include "accountitem.h"
3#include "accountview.h" 3#include "accountview.h"
4#include "newmaildir.h" 4#include "newmaildir.h"
5#include "nntpgroupsdlg.h" 5#include "nntpgroupsdlg.h"
6#include "defines.h" 6#include "defines.h"
7 7
8#include <libmailwrapper/mailtypes.h> 8#include <libmailwrapper/mailtypes.h>
9#include <libmailwrapper/abstractmail.h> 9#include <libmailwrapper/abstractmail.h>
10#include <libmailwrapper/mailwrapper.h> 10#include <libmailwrapper/mailwrapper.h>
11/* OPIE */ 11/* OPIE */
12//#include <qpe/qpeapplication.h> 12//#include <qpe/qpeapplication.h>
13 13
14/* QT */ 14/* QT */
15#include <qpopupmenu.h> 15#include <qpopupmenu.h>
16#include <qmessagebox.h> 16#include <qmessagebox.h>
17#include <kiconloader.h> 17#include <kiconloader.h>
18 18
19#define GET_NEW_MAILS 101 19#define GET_NEW_MAILS 101
20 20
21using namespace Opie::Core; 21using namespace Opie::Core;
22#define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} 22#define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );}
23/** 23/**
24 * POP3 Account stuff 24 * POP3 Account stuff
25 */ 25 */
26POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) 26POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent )
27 : AccountViewItem( parent ) 27 : AccountViewItem( parent )
28{ 28{
29 account = a; 29 account = a;
30 wrapper = AbstractMail::getWrapper( account ); 30 wrapper = AbstractMail::getWrapper( account );
31 SETPIX(PIXMAP_POP3FOLDER); 31 SETPIX(PIXMAP_POP3FOLDER);
32#if 0 32#if 0
33 if (!account->getOffline()) 33 if (!account->getOffline())
34 { 34 {
35 setPixmap( 0, ); 35 setPixmap( 0, );
36 } 36 }
37 else 37 else
38 { 38 {
39 setPixmap( 0, PIXMAP_OFFLINE ); 39 setPixmap( 0, PIXMAP_OFFLINE );
40 } 40 }
41#endif 41#endif
42 setText( 0, account->getAccountName() ); 42 setText( 0, account->getAccountName() );
43 setOpen( true ); 43 setOpen( true );
44} 44}
45 45
46POP3viewItem::~POP3viewItem() 46POP3viewItem::~POP3viewItem()
47{ 47{
48 delete wrapper; 48 delete wrapper;
49} 49}
50 50
51AbstractMail *POP3viewItem::getWrapper() 51AbstractMail *POP3viewItem::getWrapper()
52{ 52{
53 return wrapper; 53 return wrapper;
54} 54}
55 55
56void POP3viewItem::refresh(QValueList<Opie::Core::OSmartPointer<RecMail> > & ) 56void POP3viewItem::refresh(QValueList<Opie::Core::OSmartPointer<RecMail> > & )
57{ 57{
58 refresh(); 58 refresh();
59} 59}
60 60
61void POP3viewItem::refresh() 61void POP3viewItem::refresh()
62{ 62{
63 if (account->getOffline()) return; 63 if (account->getOffline()) return;
64 QValueList<FolderP> *folders = wrapper->listFolders(); 64 QValueList<FolderP> *folders = wrapper->listFolders();
65 QListViewItem *child = firstChild(); 65 QListViewItem *child = firstChild();
66 while ( child ) 66 while ( child )
67 { 67 {
68 QListViewItem *tmp = child; 68 QListViewItem *tmp = child;
69 child = child->nextSibling(); 69 child = child->nextSibling();
70 delete tmp; 70 delete tmp;
71 } 71 }
72 QValueList<FolderP>::ConstIterator it; 72 QValueList<FolderP>::ConstIterator it;
73 QListViewItem*item = 0; 73 QListViewItem*item = 0;
74 for ( it = folders->begin(); it!=folders->end(); ++it) 74 for ( it = folders->begin(); it!=folders->end(); ++it)
75 { 75 {
76 item = new POP3folderItem( (*it), this , item ); 76 item = new POP3folderItem( (*it), this , item );
77 item->setSelectable( (*it)->may_select()); 77 item->setSelectable( (*it)->may_select());
78 } 78 }
79 delete folders; 79 delete folders;
80} 80}
81 81
82RECBODYP POP3viewItem::fetchBody( const RecMailP &mail ) 82RECBODYP POP3viewItem::fetchBody( const RecMailP &mail )
83{ 83{
84 84
85 return wrapper->fetchBody( mail ); 85 return wrapper->fetchBody( mail );
86} 86}
87 87
88QPopupMenu * POP3viewItem::getContextMenu() 88QPopupMenu * POP3viewItem::getContextMenu()
89{ 89{
90 QPopupMenu *m = new QPopupMenu(0); 90 QPopupMenu *m = new QPopupMenu(0);
91 if (m) 91 if (m)
92 { 92 {
93 if (!account->getOffline()) 93 if (!account->getOffline())
94 { 94 {
95 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); 95 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS);
96 m->insertItem(QObject::tr("Disconnect",contextName),0); 96 m->insertItem(QObject::tr("Disconnect",contextName),0);
97 m->insertItem(QObject::tr("Set offline",contextName),1); 97 m->insertItem(QObject::tr("Set offline",contextName),1);
98 } 98 }
99 else 99 else
100 { 100 {
101 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); 101 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS);
102 m->insertItem(QObject::tr("Set online",contextName),1); 102 m->insertItem(QObject::tr("Set online",contextName),1);
103 } 103 }
104 } 104 }
105 return m; 105 return m;
106} 106}
107 107
108void POP3viewItem::disconnect() 108void POP3viewItem::disconnect()
109{ 109{
110 QListViewItem *child = firstChild(); 110 QListViewItem *child = firstChild();
111 while ( child ) 111 while ( child )
112 { 112 {
113 QListViewItem *tmp = child; 113 QListViewItem *tmp = child;
114 child = child->nextSibling(); 114 child = child->nextSibling();
115 delete tmp; 115 delete tmp;
116 } 116 }
117 wrapper->logout(); 117 wrapper->logout();
118} 118}
119 119
120void POP3viewItem::setOnOffline() 120void POP3viewItem::setOnOffline()
121{ 121{
122 if (!account->getOffline()) 122 if (!account->getOffline())
123 { 123 {
124 disconnect(); 124 disconnect();
125 } 125 }
126 account->setOffline(!account->getOffline()); 126 account->setOffline(!account->getOffline());
127 account->save(); 127 account->save();
128 SETPIX(PIXMAP_POP3FOLDER); 128 SETPIX(PIXMAP_POP3FOLDER);
129 refresh(); 129 refresh();
130} 130}
131 131
132void POP3viewItem::contextMenuSelected(int which) 132void POP3viewItem::contextMenuSelected(int which)
133{ 133{
134 switch (which) 134 switch (which)
135 { 135 {
136 case 0: 136 case 0:
137 disconnect(); 137 disconnect();
138 break; 138 break;
139 case 1: 139 case 1:
140 setOnOffline(); 140 setOnOffline();
141 break; 141 break;
142 case GET_NEW_MAILS: // daunlood 142 case GET_NEW_MAILS: // daunlood
143 if (account->getOffline()) 143 if (account->getOffline())
144 setOnOffline(); 144 setOnOffline();
145 AccountView*bl = accountView(); 145 AccountView*bl = accountView();
146 if (!bl) return; 146 if (!bl) return;
147 AccountViewItem* in = findSubItem( "inbox" , 0); 147 AccountViewItem* in = findSubItem( "inbox" , 0);
148 if ( ! in ) 148 if ( ! in )
149 return; 149 return;
150 bl->downloadMailsInbox(in->getFolder() ,getWrapper()); 150 bl->downloadMailsInbox(in->getFolder() ,getWrapper());
151 setOnOffline(); 151 setOnOffline();
152 break; 152 break;
153 } 153 }
154} 154}
155 155
156POP3folderItem::~POP3folderItem() 156POP3folderItem::~POP3folderItem()
157{} 157{}
158 158
159POP3folderItem::POP3folderItem( const FolderP&folderInit, POP3viewItem *parent , QListViewItem*after ) 159POP3folderItem::POP3folderItem( const FolderP&folderInit, POP3viewItem *parent , QListViewItem*after )
160 : AccountViewItem(folderInit,parent,after ) 160 : AccountViewItem(folderInit,parent,after )
161{ 161{
162 pop3 = parent; 162 pop3 = parent;
163 if (folder->getDisplayName().lower()!="inbox") 163 if (folder->getDisplayName().lower()!="inbox")
164 { 164 {
165 setPixmap( 0, PIXMAP_POP3FOLDER ); 165 setPixmap( 0, PIXMAP_POP3FOLDER );
166 } 166 }
167 else 167 else
168 { 168 {
169 setPixmap( 0, PIXMAP_INBOXFOLDER); 169 setPixmap( 0, PIXMAP_INBOXFOLDER);
170 } 170 }
171 setText( 0, folder->getDisplayName() ); 171 setText( 0, folder->getDisplayName() );
172} 172}
173 173
174void POP3folderItem::refresh(QValueList<RecMailP>&target) 174void POP3folderItem::refresh(QValueList<RecMailP>&target)
175{ 175{
176 if (folder->may_select()) 176 if (folder->may_select())
177 pop3->getWrapper()->listMessages( folder->getName(),target ); 177 pop3->getWrapper()->listMessages( folder->getName(),target );
178} 178}
179 179
180RECBODYP POP3folderItem::fetchBody(const RecMailP&aMail) 180RECBODYP POP3folderItem::fetchBody(const RecMailP&aMail)
181{ 181{
182 return pop3->getWrapper()->fetchBody(aMail); 182 return pop3->getWrapper()->fetchBody(aMail);
183} 183}
184 184
185QPopupMenu * POP3folderItem::getContextMenu() 185QPopupMenu * POP3folderItem::getContextMenu()
186{ 186{
187 QPopupMenu *m = new QPopupMenu(0); 187 QPopupMenu *m = new QPopupMenu(0);
188 if (m) 188 if (m)
189 { 189 {
190 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); 190 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS);
191 m->insertItem(QObject::tr("Refresh header list",contextName),0); 191 m->insertItem(QObject::tr("Refresh header list",contextName),0);
192 m->insertItem(QObject::tr("Delete all mails",contextName),1); 192 m->insertItem(QObject::tr("Delete all mails",contextName),1);
193 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); 193 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
194 } 194 }
195 return m; 195 return m;
196} 196}
197 197
198void POP3folderItem::downloadMails() 198void POP3folderItem::downloadMails()
199{ 199{
200 AccountView*bl = pop3->accountView(); 200 AccountView*bl = pop3->accountView();
201 if (!bl) return; 201 if (!bl) return;
202 bl->downloadMails(folder,pop3->getWrapper()); 202 bl->downloadMails(folder,pop3->getWrapper());
203} 203}
204 204
205void POP3folderItem::contextMenuSelected(int which) 205void POP3folderItem::contextMenuSelected(int which)
206{ 206{
207 AccountView * view = (AccountView*)listView(); 207 AccountView * view = (AccountView*)listView();
208 switch (which) 208 switch (which)
209 { 209 {
210 case 0: 210 case 0:
211 /* must be 'cause pop3 lists are cached */ 211 /* must be 'cause pop3 lists are cached */
212 pop3->getWrapper()->logout(); 212 pop3->getWrapper()->logout();
213 view->refreshCurrent(); 213 view->refreshCurrent();
214 break; 214 break;
215 case 1: 215 case 1:
216 deleteAllMail(pop3->getWrapper(),folder); 216 deleteAllMail(pop3->getWrapper(),folder);
217 break; 217 break;
218 case 2: 218 case 2:
219 downloadMails(); 219 downloadMails();
220 break; 220 break;
221 case GET_NEW_MAILS: // daunlood 221 case GET_NEW_MAILS: // daunlood
222 view->downloadMailsInbox(getFolder() ,pop3->getWrapper()); 222 view->downloadMailsInbox(getFolder() ,pop3->getWrapper());
223 break; 223 break;
224 default: 224 default:
225 break; 225 break;
226 } 226 }
227} 227}
228 228
229/** 229/**
230 * NNTP Account stuff 230 * NNTP Account stuff
231 */ 231 */
232NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent ) 232NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent )
233 : AccountViewItem( parent ) 233 : AccountViewItem( parent )
234{ 234{
235 account = a; 235 account = a;
236 wrapper = AbstractMail::getWrapper( account ); 236 wrapper = AbstractMail::getWrapper( account );
237 //FIXME 237 //FIXME
238 SETPIX(PIXMAP_POP3FOLDER); 238 SETPIX(PIXMAP_POP3FOLDER);
239#if 0 239#if 0
240 if (!account->getOffline()) 240 if (!account->getOffline())
241 { 241 {
242 setPixmap( 0, ); 242 setPixmap( 0, );
243 } 243 }
244 else 244 else
245 { 245 {
246 setPixmap( 0, PIXMAP_OFFLINE ); 246 setPixmap( 0, PIXMAP_OFFLINE );
247 } 247 }
248#endif 248#endif
249 setText( 0, account->getAccountName() ); 249 setText( 0, account->getAccountName() );
250 setOpen( true ); 250 setOpen( true );
251} 251}
252 252
253NNTPviewItem::~NNTPviewItem() 253NNTPviewItem::~NNTPviewItem()
254{ 254{
255 delete wrapper; 255 delete wrapper;
256} 256}
257 257
258AbstractMail *NNTPviewItem::getWrapper() 258AbstractMail *NNTPviewItem::getWrapper()
259{ 259{
260 return wrapper; 260 return wrapper;
261} 261}
262 262
263void NNTPviewItem::refresh( QValueList<RecMailP> & ) 263void NNTPviewItem::refresh( QValueList<RecMailP> & )
264{ 264{
265 refresh(); 265 refresh();
266} 266}
267 267
268void NNTPviewItem::refresh() 268void NNTPviewItem::refresh()
269{ 269{
270 if (account->getOffline()) return; 270 if (account->getOffline()) return;
271 QValueList<FolderP> *folders = wrapper->listFolders(); 271 QValueList<FolderP> *folders = wrapper->listFolders();
272 272
273 QListViewItem *child = firstChild(); 273 QListViewItem *child = firstChild();
274 while ( child ) 274 while ( child )
275 { 275 {
276 QListViewItem *tmp = child; 276 QListViewItem *tmp = child;
277 child = child->nextSibling(); 277 child = child->nextSibling();
278 delete tmp; 278 delete tmp;
279 } 279 }
280 QValueList<FolderP>::ConstIterator it; 280 QValueList<FolderP>::ConstIterator it;
281 QListViewItem*item = 0; 281 QListViewItem*item = 0;
282 for ( it = folders->begin(); it!=folders->end(); ++it) 282 for ( it = folders->begin(); it!=folders->end(); ++it)
283 { 283 {
284 item = new NNTPfolderItem( (*it), this , item ); 284 item = new NNTPfolderItem( (*it), this , item );
285 item->setSelectable( (*it)->may_select()); 285 item->setSelectable( (*it)->may_select());
286 } 286 }
287 delete folders; 287 delete folders;
288} 288}
289 289
290RECBODYP NNTPviewItem::fetchBody( const RecMailP &mail ) 290RECBODYP NNTPviewItem::fetchBody( const RecMailP &mail )
291{ 291{
292 292
293 return wrapper->fetchBody( mail ); 293 return wrapper->fetchBody( mail );
294} 294}
295 295
296QPopupMenu * NNTPviewItem::getContextMenu() 296QPopupMenu * NNTPviewItem::getContextMenu()
297{ 297{
298 QPopupMenu *m = new QPopupMenu(0); 298 QPopupMenu *m = new QPopupMenu(0);
299 if (m) 299 if (m)
300 { 300 {
301 if (!account->getOffline()) 301 if (!account->getOffline())
302 { 302 {
303 m->insertItem(QObject::tr("Disconnect",contextName),0); 303 m->insertItem(QObject::tr("Disconnect",contextName),0);
304 m->insertItem(QObject::tr("Set offline",contextName),1); 304 m->insertItem(QObject::tr("Set offline",contextName),1);
305 m->insertItem(QObject::tr("(Un-)Subscribe groups",contextName),2); 305 //m->insertItem(QObject::tr("(Un-)Subscribe groups",contextName),2);
306 } 306 }
307 else 307 else
308 { 308 {
309 m->insertItem(QObject::tr("Set online",contextName),1); 309 m->insertItem(QObject::tr("Set online",contextName),1);
310 } 310 }
311 } 311 }
312 return m; 312 return m;
313} 313}
314 314
315void NNTPviewItem::subscribeGroups() 315void NNTPviewItem::subscribeGroups()
316{ 316{
317 NNTPGroupsDlg dlg(account); 317 NNTPGroupsDlg dlg(account);
318 dlg.showMaximized(); 318 dlg.showMaximized();
319 if ( dlg.exec()== QDialog::Accepted ){ 319 if ( dlg.exec()== QDialog::Accepted ){
320 refresh(); 320 refresh();
321 } 321 }
322} 322}
323 323
324void NNTPviewItem::disconnect() 324void NNTPviewItem::disconnect()
325{ 325{
326 QListViewItem *child = firstChild(); 326 QListViewItem *child = firstChild();
327 while ( child ) 327 while ( child )
328 { 328 {
329 QListViewItem *tmp = child; 329 QListViewItem *tmp = child;
330 child = child->nextSibling(); 330 child = child->nextSibling();
331 delete tmp; 331 delete tmp;
332 } 332 }
333 wrapper->logout(); 333 wrapper->logout();
334} 334}
335 335
336void NNTPviewItem::setOnOffline() 336void NNTPviewItem::setOnOffline()
337{ 337{
338 if (!account->getOffline()) 338 if (!account->getOffline())
339 { 339 {
340 disconnect(); 340 disconnect();
341 } 341 }
342 account->setOffline(!account->getOffline()); 342 account->setOffline(!account->getOffline());
343 account->save(); 343 account->save();
344 //FIXME 344 //FIXME
345 SETPIX(PIXMAP_POP3FOLDER); 345 SETPIX(PIXMAP_POP3FOLDER);
346 refresh(); 346 refresh();
347} 347}
348 348
349void NNTPviewItem::contextMenuSelected(int which) 349void NNTPviewItem::contextMenuSelected(int which)
350{ 350{
351 switch (which) 351 switch (which)
352 { 352 {
353 case 0: 353 case 0:
354 disconnect(); 354 disconnect();
355 break; 355 break;
356 case 1: 356 case 1:
357 setOnOffline(); 357 setOnOffline();
358 break; 358 break;
359 case 2: 359 case 2:
360 subscribeGroups(); 360 subscribeGroups();
361 break; 361 break;
362 } 362 }
363} 363}
364 364
365NNTPfolderItem::~NNTPfolderItem() 365NNTPfolderItem::~NNTPfolderItem()
366{} 366{}
367 367
368NNTPfolderItem::NNTPfolderItem( const FolderP &folderInit, NNTPviewItem *parent , QListViewItem*after ) 368NNTPfolderItem::NNTPfolderItem( const FolderP &folderInit, NNTPviewItem *parent , QListViewItem*after )
369 : AccountViewItem( folderInit, parent,after ) 369 : AccountViewItem( folderInit, parent,after )
370{ 370{
371 nntp = parent; 371 nntp = parent;
372 if (folder->getDisplayName().lower()!="inbox") 372 if (folder->getDisplayName().lower()!="inbox")
373 { 373 {
374 setPixmap( 0, PIXMAP_POP3FOLDER ); 374 setPixmap( 0, PIXMAP_POP3FOLDER );
375 } 375 }
376 else 376 else
377 { 377 {
378 setPixmap( 0, PIXMAP_INBOXFOLDER); 378 setPixmap( 0, PIXMAP_INBOXFOLDER);
379 } 379 }
380 setText( 0, folder->getDisplayName() ); 380 setText( 0, folder->getDisplayName() );
381} 381}
382 382
383void NNTPfolderItem::refresh(QValueList<RecMailP>&target) 383void NNTPfolderItem::refresh(QValueList<RecMailP>&target)
384{ 384{
385 if (folder->may_select()) 385 if (folder->may_select())
386 nntp->getWrapper()->listMessages( folder->getName(),target ); 386 nntp->getWrapper()->listMessages( folder->getName(),target );
387} 387}
388 388
389RECBODYP NNTPfolderItem::fetchBody(const RecMailP&aMail) 389RECBODYP NNTPfolderItem::fetchBody(const RecMailP&aMail)
390{ 390{
391 return nntp->getWrapper()->fetchBody(aMail); 391 return nntp->getWrapper()->fetchBody(aMail);
392} 392}
393 393
394QPopupMenu * NNTPfolderItem::getContextMenu() 394QPopupMenu * NNTPfolderItem::getContextMenu()
395{ 395{
396 QPopupMenu *m = new QPopupMenu(0); 396 QPopupMenu *m = new QPopupMenu(0);
397 if (m) 397 if (m)
398 { 398 {
399 m->insertItem(QObject::tr("Refresh header list",contextName),0); 399 m->insertItem(QObject::tr("Refresh header list",contextName),0);
400 m->insertItem(QObject::tr("Copy all postings",contextName),1); 400 m->insertItem(QObject::tr("Copy all postings",contextName),1);
401 } 401 }
402 return m; 402 return m;
403} 403}
404 404
405void NNTPfolderItem::downloadMails() 405void NNTPfolderItem::downloadMails()
406{ 406{
407 AccountView*bl = nntp->accountView(); 407 AccountView*bl = nntp->accountView();
408 if (!bl) return; 408 if (!bl) return;
409 bl->downloadMails(folder,nntp->getWrapper()); 409 bl->downloadMails(folder,nntp->getWrapper());
410} 410}
411 411
412void NNTPfolderItem::contextMenuSelected(int which) 412void NNTPfolderItem::contextMenuSelected(int which)
413{ 413{
414 AccountView * view = (AccountView*)listView(); 414 AccountView * view = (AccountView*)listView();
415 switch (which) 415 switch (which)
416 { 416 {
417 case 0: 417 case 0:
418 /* must be 'cause pop3 lists are cached */ 418 /* must be 'cause pop3 lists are cached */
419 nntp->getWrapper()->logout(); 419 nntp->getWrapper()->logout();
420 view->refreshCurrent(); 420 view->refreshCurrent();
421 break; 421 break;
422 case 1: 422 case 1:
423 downloadMails(); 423 downloadMails();
424 break; 424 break;
425 default: 425 default:
426 break; 426 break;
427 } 427 }
428} 428}
429 429
430/** 430/**
431 * IMAP Account stuff 431 * IMAP Account stuff
432 */ 432 */
433IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) 433IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent )
434 : AccountViewItem( parent ) 434 : AccountViewItem( parent )
435{ 435{
436 account = a; 436 account = a;
437 wrapper = AbstractMail::getWrapper( account ); 437 wrapper = AbstractMail::getWrapper( account );
438 SETPIX(PIXMAP_IMAPFOLDER); 438 SETPIX(PIXMAP_IMAPFOLDER);
439 setText( 0, account->getAccountName() ); 439 setText( 0, account->getAccountName() );
440 setOpen( true ); 440 setOpen( true );
441} 441}
442 442
443IMAPviewItem::~IMAPviewItem() 443IMAPviewItem::~IMAPviewItem()
444{ 444{
445 delete wrapper; 445 delete wrapper;
446} 446}
447 447
448AbstractMail *IMAPviewItem::getWrapper() 448AbstractMail *IMAPviewItem::getWrapper()
449{ 449{
450 return wrapper; 450 return wrapper;
451} 451}
452 452
453void IMAPviewItem::refresh(QValueList<RecMailP>&) 453void IMAPviewItem::refresh(QValueList<RecMailP>&)
454{ 454{
455 refreshFolders(false); 455 refreshFolders(false);
456} 456}
457 457
458const QStringList&IMAPviewItem::subFolders() 458const QStringList&IMAPviewItem::subFolders()
459{ 459{
460 return currentFolders; 460 return currentFolders;
461} 461}
462 462
463void IMAPviewItem::refreshFolders(bool force) 463void IMAPviewItem::refreshFolders(bool force)
464{ 464{
465 if (childCount()>0 && force==false) return; 465 if (childCount()>0 && force==false) return;
466 if (account->getOffline()) return; 466 if (account->getOffline()) return;
467 467
468 removeChilds(); 468 removeChilds();
469 currentFolders.clear(); 469 currentFolders.clear();
470 QValueList<FolderP> * folders = wrapper->listFolders(); 470 QValueList<FolderP> * folders = wrapper->listFolders();
471 471
472 QValueList<FolderP>::Iterator it; 472 QValueList<FolderP>::Iterator it;
473 QListViewItem*item = 0; 473 QListViewItem*item = 0;
474 QListViewItem*titem = 0; 474 QListViewItem*titem = 0;
475 QString fname,del,search; 475 QString fname,del,search;
476 int pos; 476 int pos;
477 477
478 for ( it = folders->begin(); it!=folders->end(); ++it) 478 for ( it = folders->begin(); it!=folders->end(); ++it)
479 { 479 {
480 if ((*it)->getDisplayName().lower()=="inbox") 480 if ((*it)->getDisplayName().lower()=="inbox")
481 { 481 {
482 item = new IMAPfolderItem( (*it), this , item ); 482 item = new IMAPfolderItem( (*it), this , item );
483 folders->remove(it); 483 folders->remove(it);
484 break; 484 break;
485 } 485 }
486 } 486 }
487 for ( it = folders->begin(); it!=folders->end(); ++it) 487 for ( it = folders->begin(); it!=folders->end(); ++it)
488 { 488 {
489 fname = (*it)->getDisplayName(); 489 fname = (*it)->getDisplayName();
490 currentFolders.append((*it)->getName()); 490 currentFolders.append((*it)->getName());
491 pos = fname.findRev((*it)->Separator()); 491 pos = fname.findRev((*it)->Separator());
492 if (pos != -1) 492 if (pos != -1)
493 { 493 {
494 fname = fname.left(pos); 494 fname = fname.left(pos);
495 } 495 }
496 IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname); 496 IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname);
497 if (pitem) 497 if (pitem)
498 { 498 {
499 titem = item; 499 titem = item;
500 item = new IMAPfolderItem( (*it),pitem,pitem->firstChild(),this); 500 item = new IMAPfolderItem( (*it),pitem,pitem->firstChild(),this);
501 /* setup the short name */ 501 /* setup the short name */
502 item->setText(0,(*it)->getDisplayName().mid(pos+1)); 502 item->setText(0,(*it)->getDisplayName().mid(pos+1));
503 item = titem; 503 item = titem;
504 } 504 }
505 else 505 else
506 { 506 {
507 item = new IMAPfolderItem( (*it), this , item ); 507 item = new IMAPfolderItem( (*it), this , item );
508 } 508 }
509 } 509 }
510 delete folders; 510 delete folders;
511} 511}
512 512
513QPopupMenu * IMAPviewItem::getContextMenu() 513QPopupMenu * IMAPviewItem::getContextMenu()
514{ 514{
515 QPopupMenu *m = new QPopupMenu(0); 515 QPopupMenu *m = new QPopupMenu(0);
516 if (m) 516 if (m)
517 { 517 {
518 if (!account->getOffline()) 518 if (!account->getOffline())
519 { 519 {
520 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); 520 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS);
521 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 521 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
522 m->insertItem(QObject::tr("Create new folder",contextName),1); 522 m->insertItem(QObject::tr("Create new folder",contextName),1);
523 m->insertSeparator(); 523 m->insertSeparator();
524 m->insertItem(QObject::tr("Disconnect",contextName),2); 524 m->insertItem(QObject::tr("Disconnect",contextName),2);
525 m->insertItem(QObject::tr("Set offline",contextName),3); 525 m->insertItem(QObject::tr("Set offline",contextName),3);
526 m->insertSeparator(); 526 m->insertSeparator();
527 } 527 }
528 else 528 else
529 { 529 {
530 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); 530 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS);
531 m->insertItem(QObject::tr("Set online",contextName),3); 531 m->insertItem(QObject::tr("Set online",contextName),3);
532 } 532 }
533 } 533 }
534 return m; 534 return m;
535} 535}
536 536
537void IMAPviewItem::createNewFolder() 537void IMAPviewItem::createNewFolder()
538{ 538{
539 Newmdirdlg ndirdlg; 539 Newmdirdlg ndirdlg;
540 540
541 ndirdlg.showMaximized(); 541 ndirdlg.showMaximized();
542 if ( ndirdlg.exec() ) 542 if ( ndirdlg.exec() )
543 { 543 {
544 QString ndir = ndirdlg.Newdir(); 544 QString ndir = ndirdlg.Newdir();
545 bool makesubs = ndirdlg.subpossible(); 545 bool makesubs = ndirdlg.subpossible();
546 QString delemiter = "/"; 546 QString delemiter = "/";
547 IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); 547 IMAPfolderItem*item = (IMAPfolderItem*)firstChild();
548 if (item) 548 if (item)
549 { 549 {
550 delemiter = item->Delemiter(); 550 delemiter = item->Delemiter();
551 } 551 }
552 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) 552 if (wrapper->createMbox(ndir,0,delemiter,makesubs))
553 { 553 {
554 refreshFolders(true); 554 refreshFolders(true);
555 } 555 }
556 } 556 }
557} 557}
558 558
559void IMAPviewItem::contextMenuSelected(int id) 559void IMAPviewItem::contextMenuSelected(int id)
560{ 560{
561 561
562 switch (id) 562 switch (id)
563 { 563 {
564 case 0: 564 case 0:
565 refreshFolders(true); 565 refreshFolders(true);
566 break; 566 break;
567 case 1: 567 case 1:
568 createNewFolder(); 568 createNewFolder();
569 break; 569 break;
570 case 2: 570 case 2:
571 removeChilds(); 571 removeChilds();
572 wrapper->logout(); 572 wrapper->logout();
573 break; 573 break;
574 case 3: 574 case 3:
575 if (account->getOffline()==false) 575 if (account->getOffline()==false)
576 { 576 {
577 removeChilds(); 577 removeChilds();
578 wrapper->logout(); 578 wrapper->logout();
579 } 579 }
580 account->setOffline(!account->getOffline()); 580 account->setOffline(!account->getOffline());
581 account->save(); 581 account->save();
582 SETPIX(PIXMAP_IMAPFOLDER); 582 SETPIX(PIXMAP_IMAPFOLDER);
583 refreshFolders(false); 583 refreshFolders(false);
584 break; 584 break;
585 case GET_NEW_MAILS: // daunlood 585 case GET_NEW_MAILS: // daunlood
586 { 586 {
587 if (account->getOffline()) { 587 if (account->getOffline()) {
588 contextMenuSelected( 3 ); 588 contextMenuSelected( 3 );
589 } 589 }
590 AccountView*bl = accountView(); 590 AccountView*bl = accountView();
591 if (!bl) return; 591 if (!bl) return;
592 AccountViewItem* in = findSubItem( "inbox" , 0); 592 AccountViewItem* in = findSubItem( "inbox" , 0);
593 if ( ! in ) 593 if ( ! in )
594 return; 594 return;
595 bl->downloadMailsInbox(in->getFolder(),getWrapper()); 595 bl->downloadMailsInbox(in->getFolder(),getWrapper());
596 } 596 }
597 break; 597 break;
598 default: 598 default:
599 break; 599 break;
600 } 600 }
601} 601}
602 602
603RECBODYP IMAPviewItem::fetchBody(const RecMailP&) 603RECBODYP IMAPviewItem::fetchBody(const RecMailP&)
604{ 604{
605 return new RecBody(); 605 return new RecBody();
606} 606}
607 607
608bool IMAPviewItem::offline() 608bool IMAPviewItem::offline()
609{ 609{
610 return account->getOffline(); 610 return account->getOffline();
611} 611}
612 612
613IMAPfolderItem::IMAPfolderItem( const FolderP& folderInit, IMAPviewItem *parent , QListViewItem*after ) 613IMAPfolderItem::IMAPfolderItem( const FolderP& folderInit, IMAPviewItem *parent , QListViewItem*after )
614 : AccountViewItem( folderInit, parent , after ) 614 : AccountViewItem( folderInit, parent , after )
615{ 615{
616 imap = parent; 616 imap = parent;
617 if (folder->getDisplayName().lower()!="inbox") 617 if (folder->getDisplayName().lower()!="inbox")
618 { 618 {
619 setPixmap( 0, PIXMAP_IMAPFOLDER ); 619 setPixmap( 0, PIXMAP_IMAPFOLDER );
620 } 620 }
621 else 621 else
622 { 622 {
623 setPixmap( 0, PIXMAP_INBOXFOLDER); 623 setPixmap( 0, PIXMAP_INBOXFOLDER);
624 } 624 }
625 setText( 0, folder->getDisplayName() ); 625 setText( 0, folder->getDisplayName() );
626} 626}
627 627
628IMAPfolderItem::IMAPfolderItem(const FolderP &folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) 628IMAPfolderItem::IMAPfolderItem(const FolderP &folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master )
629 : AccountViewItem(folderInit, parent,after ) 629 : AccountViewItem(folderInit, parent,after )
630{ 630{
631 imap = master; 631 imap = master;
632 if (folder->getDisplayName().lower()!="inbox") 632 if (folder->getDisplayName().lower()!="inbox")
633 { 633 {
634 setPixmap( 0, PIXMAP_IMAPFOLDER ); 634 setPixmap( 0, PIXMAP_IMAPFOLDER );
635 } 635 }
636 else 636 else
637 { 637 {
638 setPixmap( 0, PIXMAP_INBOXFOLDER); 638 setPixmap( 0, PIXMAP_INBOXFOLDER);
639 } 639 }
640 setText( 0, folder->getDisplayName() ); 640 setText( 0, folder->getDisplayName() );
641} 641}
642 642
643IMAPfolderItem::~IMAPfolderItem() 643IMAPfolderItem::~IMAPfolderItem()
644{} 644{}
645 645
646const QString& IMAPfolderItem::Delemiter()const 646const QString& IMAPfolderItem::Delemiter()const
647{ 647{
648 return folder->Separator(); 648 return folder->Separator();
649} 649}
650 650
651void IMAPfolderItem::refresh(QValueList<RecMailP>&target) 651void IMAPfolderItem::refresh(QValueList<RecMailP>&target)
652{ 652{
653 if (folder->may_select()) 653 if (folder->may_select())
654 { 654 {
655 imap->getWrapper()->listMessages( folder->getName(),target ); 655 imap->getWrapper()->listMessages( folder->getName(),target );
656 } 656 }
657 else 657 else
658 { 658 {
659 target.clear(); 659 target.clear();
660 } 660 }
661} 661}
662 662
663RECBODYP IMAPfolderItem::fetchBody(const RecMailP&aMail) 663RECBODYP IMAPfolderItem::fetchBody(const RecMailP&aMail)
664{ 664{
665 return imap->getWrapper()->fetchBody(aMail); 665 return imap->getWrapper()->fetchBody(aMail);
666} 666}
667 667
668QPopupMenu * IMAPfolderItem::getContextMenu() 668QPopupMenu * IMAPfolderItem::getContextMenu()
669{ 669{
670 QPopupMenu *m = new QPopupMenu(0); 670 QPopupMenu *m = new QPopupMenu(0);
671 if (m) 671 if (m)
672 { 672 {
673 if (folder->may_select()) 673 if (folder->may_select())
674 { 674 {
675 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS); 675 m->insertItem(QObject::tr("Get new messages",contextName),GET_NEW_MAILS);
676 m->insertItem(QObject::tr("Refresh header list",contextName),0); 676 m->insertItem(QObject::tr("Refresh header list",contextName),0);
677 m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); 677 m->insertItem(QObject::tr("Move/Copie all mails",contextName),4);
678 m->insertItem(QObject::tr("Delete all mails",contextName),1); 678 m->insertItem(QObject::tr("Delete all mails",contextName),1);
679 } 679 }
680 if (folder->no_inferior()==false) 680 if (folder->no_inferior()==false)
681 { 681 {
682 m->insertItem(QObject::tr("Create new subfolder",contextName),2); 682 m->insertItem(QObject::tr("Create new subfolder",contextName),2);
683 } 683 }
684 if (folder->getDisplayName().lower()!="inbox") 684 if (folder->getDisplayName().lower()!="inbox")
685 { 685 {
686 m->insertItem(QObject::tr("Delete folder",contextName),3); 686 m->insertItem(QObject::tr("Delete folder",contextName),3);
687 } 687 }
688 } 688 }
689 return m; 689 return m;
690} 690}
691 691
692void IMAPfolderItem::createNewFolder() 692void IMAPfolderItem::createNewFolder()
693{ 693{
694 Newmdirdlg ndirdlg; 694 Newmdirdlg ndirdlg;
695 ndirdlg.showMaximized(); 695 ndirdlg.showMaximized();
696 if ( ndirdlg.exec() ) 696 if ( ndirdlg.exec() )
697 { 697 {
698 QString ndir = ndirdlg.Newdir(); 698 QString ndir = ndirdlg.Newdir();
699 bool makesubs = ndirdlg.subpossible(); 699 bool makesubs = ndirdlg.subpossible();
700 QString delemiter = Delemiter(); 700 QString delemiter = Delemiter();
701 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) 701 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs))
702 { 702 {
703 imap->refreshFolders(true); 703 imap->refreshFolders(true);
704 } 704 }
705 } 705 }
706} 706}
707 707
708void IMAPfolderItem::deleteFolder() 708void IMAPfolderItem::deleteFolder()
709{ 709{
710 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 710 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
711 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 711 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
712 QObject::tr("Yes",contextName), 712 QObject::tr("Yes",contextName),
713 QObject::tr("No",contextName),QString::null,1,1); 713 QObject::tr("No",contextName),QString::null,1,1);
714 714
715 if (yesno == 0) 715 if (yesno == 0)
716 { 716 {
717 if (imap->getWrapper()->deleteMbox(folder)) 717 if (imap->getWrapper()->deleteMbox(folder))
718 { 718 {
719 QListView*v=listView(); 719 QListView*v=listView();
720 IMAPviewItem * box = imap; 720 IMAPviewItem * box = imap;
721 /* be carefull - after that this object is destroyd so don't use 721 /* be carefull - after that this object is destroyd so don't use
722 * any member of it after that call!!*/ 722 * any member of it after that call!!*/
723 imap->refreshFolders(true); 723 imap->refreshFolders(true);
724 if (v) 724 if (v)
725 { 725 {
726 v->setSelected(box,true); 726 v->setSelected(box,true);
727 } 727 }
728 } 728 }
729 } 729 }
730} 730}
731 731
732void IMAPfolderItem::downloadMails() 732void IMAPfolderItem::downloadMails()
733{ 733{
734 AccountView*bl = imap->accountView(); 734 AccountView*bl = imap->accountView();
735 if (!bl) return; 735 if (!bl) return;
736 bl->downloadMails(folder,imap->getWrapper()); 736 bl->downloadMails(folder,imap->getWrapper());
737} 737}
738 738
739void IMAPfolderItem::contextMenuSelected(int id) 739void IMAPfolderItem::contextMenuSelected(int id)
740{ 740{
741 741
742 AccountView * view = (AccountView*)listView(); 742 AccountView * view = (AccountView*)listView();
743 switch(id) 743 switch(id)
744 { 744 {
745 case 0: 745 case 0:
746 view->refreshCurrent(); 746 view->refreshCurrent();
747 break; 747 break;
748 case 1: 748 case 1:
749 deleteAllMail(imap->getWrapper(),folder); 749 deleteAllMail(imap->getWrapper(),folder);
750 break; 750 break;
751 case 2: 751 case 2:
752 createNewFolder(); 752 createNewFolder();
753 break; 753 break;
754 case 3: 754 case 3:
755 deleteFolder(); 755 deleteFolder();
756 break; 756 break;
757 case 4: 757 case 4:
758 downloadMails(); 758 downloadMails();
759 break; 759 break;
760 case GET_NEW_MAILS: // daunlood 760 case GET_NEW_MAILS: // daunlood
761 { 761 {
762 AccountView*bl = accountView(); 762 if (!view) return;
763 if (!bl) return; 763 view->downloadMailsInbox(getFolder(),imap->getWrapper());
764 bl->downloadMailsInbox(getFolder(),imap->getWrapper());
765 } 764 }
766 break; 765 break;
767 default: 766 default:
768 break; 767 break;
769 } 768 }
770} 769}
771 770
772/** 771/**
773 * MH Account stuff 772 * MH Account stuff
774 */ 773 */
775/* MH is a little bit different - the top folder can contains messages other than in IMAP and 774/* MH is a little bit different - the top folder can contains messages other than in IMAP and
776 POP3 and MBOX */ 775 POP3 and MBOX */
777MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) 776MHviewItem::MHviewItem( const QString&aPath, AccountView *parent )
778 : AccountViewItem( parent ) 777 : AccountViewItem( parent )
779{ 778{
780 m_Path = aPath; 779 m_Path = aPath;
781 /* be carefull - the space within settext is wanted - thats why the string twice */ 780 /* be carefull - the space within settext is wanted - thats why the string twice */
782 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); 781 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders");
783 setPixmap( 0, PIXMAP_LOCALFOLDER ); 782 setPixmap( 0, PIXMAP_LOCALFOLDER );
784 setText( 0, " Local Folders" ); 783 setText( 0, " Local Folders" );
785 setOpen( true ); 784 setOpen( true );
786 folder = 0; 785 folder = 0;
787} 786}
788 787
789MHviewItem::~MHviewItem() 788MHviewItem::~MHviewItem()
790{ 789{
791 delete wrapper; 790 delete wrapper;
792} 791}
793 792
794AbstractMail *MHviewItem::getWrapper() 793AbstractMail *MHviewItem::getWrapper()
795{ 794{
796 return wrapper; 795 return wrapper;
797} 796}
798 797
799void MHviewItem::refresh( QValueList<RecMailP> & target) 798void MHviewItem::refresh( QValueList<RecMailP> & target)
800{ 799{
801 refresh(false); 800 refresh(false);
802 getWrapper()->listMessages( "",target ); 801 getWrapper()->listMessages( "",target );
803} 802}
804 803
805void MHviewItem::refresh(bool force) 804void MHviewItem::refresh(bool force)
806{ 805{
807 if (childCount()>0 && force==false) return; 806 if (childCount()>0 && force==false) return;
808 removeChilds(); 807 removeChilds();
809 currentFolders.clear(); 808 currentFolders.clear();
810 QValueList<FolderP> *folders = wrapper->listFolders(); 809 QValueList<FolderP> *folders = wrapper->listFolders();
811 QValueList<FolderP>::ConstIterator it; 810 QValueList<FolderP>::ConstIterator it;
812 MHfolderItem*item = 0; 811 MHfolderItem*item = 0;
813 MHfolderItem*pmaster = 0; 812 MHfolderItem*pmaster = 0;
814 QString fname = ""; 813 QString fname = "";
815 int pos; 814 int pos;
816 for ( it = folders->begin(); it!=folders->end(); ++it) 815 for ( it = folders->begin(); it!=folders->end(); ++it)
817 { 816 {
818 fname = (*it)->getDisplayName(); 817 fname = (*it)->getDisplayName();
819 /* this folder itself */ 818 /* this folder itself */
820 if (fname=="/") 819 if (fname=="/")
821 { 820 {
822 currentFolders.append(fname); 821 currentFolders.append(fname);
823 folder = (*it); 822 folder = (*it);
824 continue; 823 continue;
825 } 824 }
826 currentFolders.append(fname); 825 currentFolders.append(fname);
827 pos = fname.findRev("/"); 826 pos = fname.findRev("/");
828 if (pos > 0) 827 if (pos > 0)
829 { 828 {
830 fname = fname.left(pos); 829 fname = fname.left(pos);
831 pmaster = (MHfolderItem*)findSubItem(fname); 830 pmaster = (MHfolderItem*)findSubItem(fname);
832 } 831 }
833 else 832 else
834 { 833 {
835 pmaster = 0; 834 pmaster = 0;
836 } 835 }
837 if (pmaster) 836 if (pmaster)
838 { 837 {
839 item = new MHfolderItem( (*it), pmaster, item, this ); 838 item = new MHfolderItem( (*it), pmaster, item, this );
840 } 839 }
841 else 840 else
842 { 841 {
843 item = new MHfolderItem( (*it), this , item ); 842 item = new MHfolderItem( (*it), this , item );
844 } 843 }
845 item->setSelectable((*it)->may_select()); 844 item->setSelectable((*it)->may_select());
846 } 845 }
847 delete folders; 846 delete folders;
848} 847}
849 848
850RECBODYP MHviewItem::fetchBody( const RecMailP &mail ) 849RECBODYP MHviewItem::fetchBody( const RecMailP &mail )
851{ 850{
852 851
853 return wrapper->fetchBody( mail ); 852 return wrapper->fetchBody( mail );
854} 853}
855 854
856QPopupMenu * MHviewItem::getContextMenu() 855QPopupMenu * MHviewItem::getContextMenu()
857{ 856{
858 QPopupMenu *m = new QPopupMenu(0); 857 QPopupMenu *m = new QPopupMenu(0);
859 if (m) 858 if (m)
860 { 859 {
861 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 860 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
862 m->insertItem(QObject::tr("Create new folder",contextName),1); 861 m->insertItem(QObject::tr("Create new folder",contextName),1);
863 m->insertItem(QObject::tr("Delete all mails",contextName),2); 862 m->insertItem(QObject::tr("Delete all mails",contextName),2);
864 m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); 863 m->insertItem(QObject::tr("Move/Copie all mails",contextName),3);
865 } 864 }
866 return m; 865 return m;
867} 866}
868 867
869void MHviewItem::createFolder() 868void MHviewItem::createFolder()
870{ 869{
871 Newmdirdlg ndirdlg(0,0,true); 870 Newmdirdlg ndirdlg(0,0,true);
872 ndirdlg.showMaximized(); 871 ndirdlg.showMaximized();
873 if ( ndirdlg.exec() ) 872 if ( ndirdlg.exec() )
874 { 873 {
875 QString ndir = ndirdlg.Newdir(); 874 QString ndir = ndirdlg.Newdir();
876 if (wrapper->createMbox(ndir)) 875 if (wrapper->createMbox(ndir))
877 { 876 {
878 refresh(true); 877 refresh(true);
879 } 878 }
880 } 879 }
881} 880}
882 881
883void MHviewItem::downloadMails() 882void MHviewItem::downloadMails()
884{ 883{
885 AccountView*bl = accountView(); 884 AccountView*bl = accountView();
886 if (!bl) return; 885 if (!bl) return;
887 bl->downloadMails(folder,getWrapper()); 886 bl->downloadMails(folder,getWrapper());
888} 887}
889 888
890QStringList MHviewItem::subFolders() 889QStringList MHviewItem::subFolders()
891{ 890{
892 return currentFolders; 891 return currentFolders;
893} 892}
894 893
895void MHviewItem::contextMenuSelected(int which) 894void MHviewItem::contextMenuSelected(int which)
896{ 895{
897 switch (which) 896 switch (which)
898 { 897 {
899 case 0: 898 case 0:
900 refresh(true); 899 refresh(true);
901 break; 900 break;
902 case 1: 901 case 1:
903 createFolder(); 902 createFolder();
904 break; 903 break;
905 case 2: 904 case 2:
906 deleteAllMail(getWrapper(),folder); 905 deleteAllMail(getWrapper(),folder);
907 break; 906 break;
908 case 3: 907 case 3:
909 downloadMails(); 908 downloadMails();
910 break; 909 break;
911 default: 910 default:
912 break; 911 break;
913 } 912 }
914} 913}
915 914
916MHfolderItem::~MHfolderItem() 915MHfolderItem::~MHfolderItem()
917{} 916{}
918 917
919MHfolderItem::MHfolderItem( const FolderP &folderInit, MHviewItem *parent , QListViewItem*after ) 918MHfolderItem::MHfolderItem( const FolderP &folderInit, MHviewItem *parent , QListViewItem*after )
920 : AccountViewItem(folderInit, parent,after ) 919 : AccountViewItem(folderInit, parent,after )
921{ 920{
922 mbox = parent; 921 mbox = parent;
923 initName(); 922 initName();
924} 923}
925 924
926MHfolderItem::MHfolderItem(const FolderP& folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) 925MHfolderItem::MHfolderItem(const FolderP& folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master)
927 : AccountViewItem(folderInit, parent,after ) 926 : AccountViewItem(folderInit, parent,after )
928{ 927{
929 folder = folderInit; 928 folder = folderInit;
930 mbox = master; 929 mbox = master;
931 initName(); 930 initName();
932} 931}
933 932
934void MHfolderItem::initName() 933void MHfolderItem::initName()
935{ 934{
936 QString bName = folder->getDisplayName(); 935 QString bName = folder->getDisplayName();
937 if (bName.startsWith("/")&&bName.length()>1) 936 if (bName.startsWith("/")&&bName.length()>1)
938 { 937 {
939 bName.replace(0,1,""); 938 bName.replace(0,1,"");
940 } 939 }
941 int pos = bName.findRev("/"); 940 int pos = bName.findRev("/");
942 if (pos > 0) 941 if (pos > 0)
943 { 942 {
944 bName.replace(0,pos+1,""); 943 bName.replace(0,pos+1,"");
945 } 944 }
946 if (bName.lower() == "outgoing") 945 if (bName.lower() == "outgoing")
947 { 946 {
948 setPixmap( 0, PIXMAP_OUTBOXFOLDER ); 947 setPixmap( 0, PIXMAP_OUTBOXFOLDER );
949 } 948 }
950 else if (bName.lower() == "inbox") 949 else if (bName.lower() == "inbox")
951 { 950 {
952 setPixmap( 0, PIXMAP_INBOXFOLDER); 951 setPixmap( 0, PIXMAP_INBOXFOLDER);
953 } else if (bName.lower() == "drafts") { 952 } else if (bName.lower() == "drafts") {
954 setPixmap(0, SmallIcon ("edit")); 953 setPixmap(0, SmallIcon ("edit"));
955 } else { 954 } else {
956 setPixmap( 0, PIXMAP_MBOXFOLDER ); 955 setPixmap( 0, PIXMAP_MBOXFOLDER );
957 } 956 }
958 setText( 0, bName ); 957 setText( 0, bName );
959} 958}
960 959
961const FolderP&MHfolderItem::getFolder()const 960const FolderP&MHfolderItem::getFolder()const
962{ 961{
963 return folder; 962 return folder;
964} 963}
965 964
966void MHfolderItem::refresh(QValueList<RecMailP>&target) 965void MHfolderItem::refresh(QValueList<RecMailP>&target)
967{ 966{
968 if (folder->may_select()) 967 if (folder->may_select())
969 mbox->getWrapper()->listMessages( folder->getName(),target ); 968 mbox->getWrapper()->listMessages( folder->getName(),target );
970} 969}
971 970
972RECBODYP MHfolderItem::fetchBody(const RecMailP&aMail) 971RECBODYP MHfolderItem::fetchBody(const RecMailP&aMail)
973{ 972{
974 return mbox->getWrapper()->fetchBody(aMail); 973 return mbox->getWrapper()->fetchBody(aMail);
975} 974}
976 975
977void MHfolderItem::deleteFolder() 976void MHfolderItem::deleteFolder()
978{ 977{
979 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 978 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
980 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 979 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
981 QObject::tr("Yes",contextName), 980 QObject::tr("Yes",contextName),
982 QObject::tr("No",contextName),QString::null,1,1); 981 QObject::tr("No",contextName),QString::null,1,1);
983 982
984 if (yesno == 0) 983 if (yesno == 0)
985 { 984 {
986 if (mbox->getWrapper()->deleteMbox(folder)) 985 if (mbox->getWrapper()->deleteMbox(folder))
987 { 986 {
988 QListView*v=listView(); 987 QListView*v=listView();
989 MHviewItem * box = mbox; 988 MHviewItem * box = mbox;
990 /* be carefull - after that this object is destroyd so don't use 989 /* be carefull - after that this object is destroyd so don't use
991 * any member of it after that call!!*/ 990 * any member of it after that call!!*/
992 mbox->refresh(true); 991 mbox->refresh(true);
993 if (v) 992 if (v)
994 { 993 {
995 v->setSelected(box,true); 994 v->setSelected(box,true);
996 } 995 }
997 } 996 }
998 } 997 }
999} 998}
1000 999
1001QPopupMenu * MHfolderItem::getContextMenu() 1000QPopupMenu * MHfolderItem::getContextMenu()
1002{ 1001{
1003 QPopupMenu *m = new QPopupMenu(0); 1002 QPopupMenu *m = new QPopupMenu(0);
1004 if (m) 1003 if (m)
1005 { 1004 {
1006 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); 1005 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
1007 m->insertItem(QObject::tr("Delete all mails",contextName),0); 1006 m->insertItem(QObject::tr("Delete all mails",contextName),0);
1008 m->insertItem(QObject::tr("Create new subfolder",contextName),3); 1007 m->insertItem(QObject::tr("Create new subfolder",contextName),3);
1009 m->insertItem(QObject::tr("Delete folder",contextName),1); 1008 m->insertItem(QObject::tr("Delete folder",contextName),1);
1010 } 1009 }
1011 return m; 1010 return m;
1012} 1011}
1013 1012
1014void MHfolderItem::downloadMails() 1013void MHfolderItem::downloadMails()
1015{ 1014{
1016 AccountView*bl = mbox->accountView(); 1015 AccountView*bl = mbox->accountView();
1017 if (!bl) return; 1016 if (!bl) return;
1018 bl->downloadMails(folder,mbox->getWrapper()); 1017 bl->downloadMails(folder,mbox->getWrapper());
1019} 1018}
1020 1019
1021void MHfolderItem::createFolder() 1020void MHfolderItem::createFolder()
1022{ 1021{
1023 Newmdirdlg ndirdlg(0,0,true); 1022 Newmdirdlg ndirdlg(0,0,true);
1024 ndirdlg.showMaximized(); 1023 ndirdlg.showMaximized();
1025 if (ndirdlg.exec() ) 1024 if (ndirdlg.exec() )
1026 { 1025 {
1027 QString ndir = ndirdlg.Newdir(); 1026 QString ndir = ndirdlg.Newdir();
1028 if (mbox->getWrapper()->createMbox(ndir,folder)) 1027 if (mbox->getWrapper()->createMbox(ndir,folder))
1029 { 1028 {
1030 QListView*v=listView(); 1029 QListView*v=listView();
1031 MHviewItem * box = mbox; 1030 MHviewItem * box = mbox;
1032 /* be carefull - after that this object is destroyd so don't use 1031 /* be carefull - after that this object is destroyd so don't use
1033 * any member of it after that call!!*/ 1032 * any member of it after that call!!*/
1034 mbox->refresh(true); 1033 mbox->refresh(true);
1035 if (v) 1034 if (v)
1036 { 1035 {
1037 v->setSelected(box,true); 1036 v->setSelected(box,true);
1038 } 1037 }
1039 } 1038 }
1040 } 1039 }
1041} 1040}
1042 1041
1043void MHfolderItem::contextMenuSelected(int which) 1042void MHfolderItem::contextMenuSelected(int which)
1044{ 1043{
1045 switch(which) 1044 switch(which)
1046 { 1045 {
1047 case 0: 1046 case 0:
1048 deleteAllMail(mbox->getWrapper(),folder); 1047 deleteAllMail(mbox->getWrapper(),folder);
1049 break; 1048 break;
1050 case 1: 1049 case 1:
1051 deleteFolder(); 1050 deleteFolder();
1052 break; 1051 break;
1053 case 2: 1052 case 2:
1054 downloadMails(); 1053 downloadMails();
1055 break; 1054 break;
1056 case 3: 1055 case 3:
1057 createFolder(); 1056 createFolder();
1058 break; 1057 break;
1059 default: 1058 default:
1060 break; 1059 break;
1061 } 1060 }
1062} 1061}
1063 1062
1064bool MHfolderItem::isDraftfolder() 1063bool MHfolderItem::isDraftfolder()
1065{ 1064{
1066 if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true; 1065 if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true;
1067 return false; 1066 return false;
1068} 1067}
1069 1068
1070/** 1069/**
1071 * Generic stuff 1070 * Generic stuff
1072 */ 1071 */
1073 1072
1074const QString AccountViewItem::contextName="AccountViewItem"; 1073const QString AccountViewItem::contextName="AccountViewItem";
1075 1074
1076AccountViewItem::AccountViewItem( AccountView *parent ) 1075AccountViewItem::AccountViewItem( AccountView *parent )
1077 : QListViewItem( parent ) 1076 : QListViewItem( parent )
1078{ 1077{
1079 init(); 1078 init();
1080 m_Backlink = parent; 1079 m_Backlink = parent;
1081} 1080}
1082 1081
1083AccountViewItem::AccountViewItem( QListViewItem *parent) 1082AccountViewItem::AccountViewItem( QListViewItem *parent)
1084 : QListViewItem( parent),folder(0) 1083 : QListViewItem( parent),folder(0)
1085{ 1084{
1086 init(); 1085 init();
1087} 1086}
1088 1087
1089AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) 1088AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after )
1090 :QListViewItem( parent,after ),folder(0) 1089 :QListViewItem( parent,after ),folder(0)
1091{ 1090{
1092 init(); 1091 init();
1093} 1092}
1094 1093
1095AccountViewItem::AccountViewItem( const Opie::Core::OSmartPointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after ) 1094AccountViewItem::AccountViewItem( const Opie::Core::OSmartPointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after )
1096 :QListViewItem( parent,after ),folder(folderInit) 1095 :QListViewItem( parent,after ),folder(folderInit)
1097{ 1096{
1098 init(); 1097 init();
1099} 1098}
1100 1099
1101void AccountViewItem::init() 1100void AccountViewItem::init()
1102{ 1101{
1103 m_Backlink = 0; 1102 m_Backlink = 0;
1104} 1103}
1105 1104
1106AccountViewItem::~AccountViewItem() 1105AccountViewItem::~AccountViewItem()
1107{ 1106{
1108 folder = 0; 1107 folder = 0;
1109} 1108}
1110 1109
1111AccountView*AccountViewItem::accountView() 1110AccountView*AccountViewItem::accountView()
1112{ 1111{
1113 return m_Backlink; 1112 return m_Backlink;
1114} 1113}
1115 1114
1116void AccountViewItem::deleteAllMail(AbstractMail*wrapper,const FolderP&folder) 1115void AccountViewItem::deleteAllMail(AbstractMail*wrapper,const FolderP&folder)
1117{ 1116{
1118 if (!wrapper) return; 1117 if (!wrapper) return;
1119 QString fname=""; 1118 QString fname="";
1120 if (folder) fname = folder->getDisplayName(); 1119 if (folder) fname = folder->getDisplayName();
1121 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), 1120 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
1122 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). 1121 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).
1123 arg(fname), 1122 arg(fname),
1124 QObject::tr("Yes",contextName), 1123 QObject::tr("Yes",contextName),
1125 QObject::tr("No",contextName),QString::null,1,1); 1124 QObject::tr("No",contextName),QString::null,1,1);
1126 1125
1127 if (yesno == 0) 1126 if (yesno == 0)
1128 { 1127 {
1129 if (wrapper->deleteAllMail(folder)) 1128 if (wrapper->deleteAllMail(folder))
1130 { 1129 {
1131 AccountView * view = (AccountView*)listView(); 1130 AccountView * view = (AccountView*)listView();
1132 if (view) view->refreshCurrent(); 1131 if (view) view->refreshCurrent();
1133 } 1132 }
1134 } 1133 }
1135} 1134}
1136 1135
1137void AccountViewItem::removeChilds() 1136void AccountViewItem::removeChilds()
1138{ 1137{
1139 QListViewItem *child = firstChild(); 1138 QListViewItem *child = firstChild();
1140 while ( child ) 1139 while ( child )
1141 { 1140 {
1142 QListViewItem *tmp = child; 1141 QListViewItem *tmp = child;
1143 child = child->nextSibling(); 1142 child = child->nextSibling();
1144 delete tmp; 1143 delete tmp;
1145 } 1144 }
1146} 1145}
1147 1146
1148bool AccountViewItem::matchName(const QString&name)const 1147bool AccountViewItem::matchName(const QString&name)const
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index 8f67566..88545f8 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -1,277 +1,278 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "abstractmail.h" 2#include "abstractmail.h"
3#include "imapwrapper.h" 3#include "imapwrapper.h"
4#include "pop3wrapper.h" 4#include "pop3wrapper.h"
5#include "nntpwrapper.h" 5#include "nntpwrapper.h"
6#include "mhwrapper.h" 6#include "mhwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include <qpe/global.h> 8#include <qpe/global.h>
9 9
10 10
11#include <qprogressbar.h> 11#include <qprogressbar.h>
12#include <qapplication.h> 12#include <qapplication.h>
13#include <qmessagebox.h> 13#include <qmessagebox.h>
14 14
15#include <kdecore/kstandarddirs.h> 15#include <kdecore/kstandarddirs.h>
16#include <qfile.h> 16#include <qfile.h>
17#include <qtextstream.h> 17#include <qtextstream.h>
18#include <stdlib.h> 18#include <stdlib.h>
19#include <libetpan/mailmime_content.h> 19#include <libetpan/mailmime_content.h>
20#include <libetpan/mailmime.h> 20#include <libetpan/mailmime.h>
21 21
22using namespace Opie::Core; 22using namespace Opie::Core;
23AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 23AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
24{ 24{
25 return new IMAPwrapper(a); 25 return new IMAPwrapper(a);
26} 26}
27 27
28AbstractMail* AbstractMail::getWrapper(POP3account *a) 28AbstractMail* AbstractMail::getWrapper(POP3account *a)
29{ 29{
30 return new POP3wrapper(a); 30 return new POP3wrapper(a);
31} 31}
32 32
33AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 33AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
34{ 34{
35 return new NNTPwrapper(a); 35 return new NNTPwrapper(a);
36} 36}
37 37
38AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 38AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
39{ 39{
40 return new MHwrapper(a,name); 40 return new MHwrapper(a,name);
41} 41}
42 42
43AbstractMail* AbstractMail::getWrapper(Account*a) 43AbstractMail* AbstractMail::getWrapper(Account*a)
44{ 44{
45 if (!a) return 0; 45 if (!a) return 0;
46 switch (a->getType()) { 46 switch (a->getType()) {
47 case MAILLIB::A_IMAP: 47 case MAILLIB::A_IMAP:
48 return new IMAPwrapper((IMAPaccount*)a); 48 return new IMAPwrapper((IMAPaccount*)a);
49 break; 49 break;
50 case MAILLIB::A_POP3: 50 case MAILLIB::A_POP3:
51 return new POP3wrapper((POP3account*)a); 51 return new POP3wrapper((POP3account*)a);
52 break; 52 break;
53 case MAILLIB::A_NNTP: 53 case MAILLIB::A_NNTP:
54 return new NNTPwrapper((NNTPaccount*)a); 54 return new NNTPwrapper((NNTPaccount*)a);
55 break; 55 break;
56 default: 56 default:
57 return 0; 57 return 0;
58 } 58 }
59} 59}
60 60
61encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 61encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
62{ 62{
63 // odebug << "Decode string start" << oendl; 63 // odebug << "Decode string start" << oendl;
64 char*result_text; 64 char*result_text;
65 size_t index = 0; 65 size_t index = 0;
66 /* reset for recursive use! */ 66 /* reset for recursive use! */
67 size_t target_length = 0; 67 size_t target_length = 0;
68 result_text = 0; 68 result_text = 0;
69 int mimetype = MAILMIME_MECHANISM_7BIT; 69 int mimetype = MAILMIME_MECHANISM_7BIT;
70 if (enc.lower()=="quoted-printable") { 70 if (enc.lower()=="quoted-printable") {
71 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 71 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
72 } else if (enc.lower()=="base64") { 72 } else if (enc.lower()=="base64") {
73 mimetype = MAILMIME_MECHANISM_BASE64; 73 mimetype = MAILMIME_MECHANISM_BASE64;
74 } else if (enc.lower()=="8bit") { 74 } else if (enc.lower()=="8bit") {
75 mimetype = MAILMIME_MECHANISM_8BIT; 75 mimetype = MAILMIME_MECHANISM_8BIT;
76 } else if (enc.lower()=="binary") { 76 } else if (enc.lower()=="binary") {
77 mimetype = MAILMIME_MECHANISM_BINARY; 77 mimetype = MAILMIME_MECHANISM_BINARY;
78 } 78 }
79 79
80 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 80 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
81 &result_text,&target_length); 81 &result_text,&target_length);
82 82
83 encodedString* result = new encodedString(); 83 encodedString* result = new encodedString();
84 if (err == MAILIMF_NO_ERROR) { 84 if (err == MAILIMF_NO_ERROR) {
85 result->setContent(result_text,target_length); 85 result->setContent(result_text,target_length);
86 } 86 }
87 //odebug << "Decode string finished" << oendl; 87 //odebug << "Decode string finished" << oendl;
88 return result; 88 return result;
89} 89}
90 90
91QString AbstractMail::convert_String(const char*text) 91QString AbstractMail::convert_String(const char*text)
92{ 92{
93 //size_t index = 0; 93 //size_t index = 0;
94 char*res = 0; 94 char*res = 0;
95 int err = MAILIMF_NO_ERROR; 95 int err = MAILIMF_NO_ERROR;
96 96
97 QString result(text); 97 QString result(text);
98 98
99 /* due a bug in libetpan it isn't usable this moment */ 99 /* due a bug in libetpan it isn't usable this moment */
100/* int err = mailmime_encoded_phrase_parse("iso-8859-1", 100/* int err = mailmime_encoded_phrase_parse("iso-8859-1",
101 text, strlen(text),&index, "iso-8859-1",&res);*/ 101 text, strlen(text),&index, "iso-8859-1",&res);*/
102 //odebug << "Input: " << text << "" << oendl; 102 //odebug << "Input: " << text << "" << oendl;
103 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 103 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
104// result = QString(res); 104// result = QString(res);
105// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; 105// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl;
106 } 106 }
107 if (res) free(res); 107 if (res) free(res);
108 return result; 108 return result;
109} 109}
110 110
111/* cp & paste from launcher */ 111/* cp & paste from launcher */
112QString AbstractMail::gen_attachment_id() 112QString AbstractMail::gen_attachment_id()
113{ 113{
114 QFile file( "/proc/sys/kernel/random/uuid" ); 114 QFile file( "/proc/sys/kernel/random/uuid" );
115 if (!file.open(IO_ReadOnly ) ) 115 if (!file.open(IO_ReadOnly ) )
116 return QString::null; 116 return QString::null;
117 117
118 QTextStream stream(&file); 118 QTextStream stream(&file);
119 119
120 return "{" + stream.read().stripWhiteSpace() + "}"; 120 return "{" + stream.read().stripWhiteSpace() + "}";
121} 121}
122 122
123int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) 123int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
124{ 124{
125 return 0; 125 return 0;
126} 126}
127 127
128QString AbstractMail::defaultLocalfolder() 128QString AbstractMail::defaultLocalfolder()
129{ 129{
130 // QString f = getenv( "HOME" ); 130 // QString f = getenv( "HOME" );
131 QString f = locateLocal( "data", "kopiemail/localmail"); 131 QString f = locateLocal( "data", "kopiemail/localmail");
132 // f += "/Applications/opiemail/localmail"; 132 // f += "/Applications/opiemail/localmail";
133 return f; 133 return f;
134} 134}
135 135
136QString AbstractMail::draftFolder() 136QString AbstractMail::draftFolder()
137{ 137{
138 return QString("Drafts"); 138 return QString("Drafts");
139} 139}
140 140
141/* temporary - will be removed when implemented in all classes */ 141/* temporary - will be removed when implemented in all classes */
142void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) 142void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &)
143{ 143{
144} 144}
145void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) 145void AbstractMail::deleteMailList(const QValueList<RecMailP>&target)
146{ 146{
147 //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); 147 //qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
148 // this is currently re-implemented in pop3wrapper and imapwrapper 148 // this is currently re-implemented in pop3wrapper and imapwrapper
149 int iii = 0; 149 int iii = 0;
150 int count = target.count(); 150 int count = target.count();
151 QProgressBar wid ( count ); 151 QProgressBar wid ( count );
152 wid.setCaption( tr("Deleting ...")); 152 wid.setCaption( tr("Deleting ..."));
153 wid.show(); 153 wid.show();
154 while (iii < count ) { 154 while (iii < count ) {
155 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); 155 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count));
156 wid.setProgress( iii ); 156 wid.setProgress( iii );
157 wid.raise(); 157 wid.raise();
158 qApp->processEvents(); 158 qApp->processEvents();
159 RecMailP mail = (*target.at( iii )); 159 RecMailP mail = (*target.at( iii ));
160 deleteMail(mail); 160 deleteMail(mail);
161 ++iii; 161 ++iii;
162 } 162 }
163} 163}
164 164
165void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) 165void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail )
166{ 166{
167 //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); 167 //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1());
168 // get local folder 168 // get local folder
169 Account * acc = getAccount(); 169 Account * acc = getAccount();
170 if ( !acc ) return; 170 if ( !acc ) return;
171 QString lfName = acc->getLocalFolder(); 171 QString lfName = acc->getLocalFolder();
172 if ( lfName.isEmpty() ) 172 if ( lfName.isEmpty() )
173 lfName = acc->getAccountName(); 173 lfName = acc->getAccountName();
174 // create local folder 174 // create local folder
175 if ( !targetMail->createMbox(lfName)) 175 if ( !targetMail->createMbox(lfName))
176 { 176 {
177 QMessageBox::critical(0,tr("Error creating new Folder"), 177 QMessageBox::critical(0,tr("Error creating new Folder"),
178 tr("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); 178 tr("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName));
179 return; 179 return;
180 } 180 }
181 QValueList<RecMailP> t; 181 QValueList<RecMailP> t;
182 listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); 182 listMessages(fromFolder->getName(),t,acc->getMaxMailSize() );
183 if ( t.count() == 0 ) { 183 if ( t.count() == 0 ) {
184 Global::statusMessage(tr("There are no new messages")); 184 Global::statusMessage(tr("There are no new messages"));
185 return; 185 return;
186 } 186 }
187 QValueList<RecMailP> e; 187 QValueList<RecMailP> e;
188 targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); 188 targetMail->listMessages(lfName,e,acc->getMaxMailSize() );
189 //qDebug("target has mails %d ", e.count()); 189 //qDebug("target has mails %d ", e.count());
190 QValueList<RecMailP> n; 190 QValueList<RecMailP> n;
191 int iii = 0; 191 int iii = 0;
192 int count = t.count(); 192 int count = t.count();
193 while (iii < count ) { 193 while (iii < count ) {
194 RecMailP r = (*t.at( iii )); 194 RecMailP r = (*t.at( iii ));
195 bool found = false; 195 bool found = false;
196 int jjj = 0; 196 int jjj = 0;
197 int countE = e.count(); 197 int countE = e.count();
198 while (jjj < countE ) { 198 while (jjj < countE ) {
199 RecMailP re = (*e.at( jjj )); 199 RecMailP re = (*e.at( jjj ));
200 if ( re->isEqual(r) ) { 200 if ( re->isEqual(r) ) {
201 found = true; 201 found = true;
202 break; 202 break;
203 } 203 }
204 ++jjj; 204 ++jjj;
205 } 205 }
206 if ( !found ) { 206 if ( !found ) {
207 //qDebug("AAAdate *%s* ", r->isodate.latin1() );
207 n.append( r ); 208 n.append( r );
208 } 209 }
209 ++iii; 210 ++iii;
210 } 211 }
211 if ( n.count() == 0 ) { 212 if ( n.count() == 0 ) {
212 Global::statusMessage(tr("There are no new messages")); 213 Global::statusMessage(tr("There are no new messages"));
213 return; 214 return;
214 } 215 }
215 mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); 216 mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer());
216 Global::statusMessage(tr("Downloaded %1 messages").arg(n.count())); 217 Global::statusMessage(tr("Downloaded %1 messages").arg(n.count()));
217 218
218#if 0 219#if 0
219 QValueList<RecMailP> t; 220 QValueList<RecMailP> t;
220 listMessages(fromFolder->getName(),t, maxSizeInKb); 221 listMessages(fromFolder->getName(),t, maxSizeInKb);
221 mvcpMailList( t,targetFolder,targetWrapper,moveit); 222 mvcpMailList( t,targetFolder,targetWrapper,moveit);
222#endif 223#endif
223 224
224} 225}
225void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 226void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
226 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 227 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
227{ 228{
228 QValueList<RecMailP> t; 229 QValueList<RecMailP> t;
229 listMessages(fromFolder->getName(),t, maxSizeInKb); 230 listMessages(fromFolder->getName(),t, maxSizeInKb);
230 mvcpMailList( t,targetFolder,targetWrapper,moveit); 231 mvcpMailList( t,targetFolder,targetWrapper,moveit);
231 232
232} 233}
233void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, 234void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t,
234 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 235 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
235{ 236{
236 encodedString*st = 0; 237 encodedString*st = 0;
237 int iii = 0; 238 int iii = 0;
238 int count = t.count(); 239 int count = t.count();
239 if ( count == 0 ) 240 if ( count == 0 )
240 return; 241 return;
241 // wel, processevents is qite strange, we need a widget for getting 242 // wel, processevents is qite strange, we need a widget for getting
242 // Global::statusMessage(tr("Copy2 message %1").arg(iii)); displaye 243 // Global::statusMessage(tr("Copy2 message %1").arg(iii)); displaye
243 244
244 QProgressBar wid ( count ); 245 QProgressBar wid ( count );
245 wid.setCaption( tr("Copying ...")); 246 wid.setCaption( tr("Copying ..."));
246 wid.show(); 247 wid.show();
247 while (iii < count ) { 248 while (iii < count ) {
248 Global::statusMessage(tr("Copy message %1 of %2").arg(iii).arg(count)); 249 Global::statusMessage(tr("Copy message %1 of %2").arg(iii).arg(count));
249 wid.setProgress( iii ); 250 wid.setProgress( iii );
250 wid.raise(); 251 wid.raise();
251 qApp->processEvents(); 252 qApp->processEvents();
252 RecMailP r = (*t.at( iii )); 253 RecMailP r = (*t.at( iii ));
253 st = fetchRawBody(r); 254 st = fetchRawBody(r);
254 if (st) { 255 if (st) {
255 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 256 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
256 delete st; 257 delete st;
257 } 258 }
258 ++iii; 259 ++iii;
259 } 260 }
260 if (moveit) { 261 if (moveit) {
261 deleteMailList( t ); 262 deleteMailList( t );
262 //deleteAllMail(fromFolder); 263 //deleteAllMail(fromFolder);
263 } 264 }
264} 265}
265 266
266void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 267void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
267{ 268{
268 encodedString*st = 0; 269 encodedString*st = 0;
269 st = fetchRawBody(mail); 270 st = fetchRawBody(mail);
270 if (st) { 271 if (st) {
271 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 272 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
272 delete st; 273 delete st;
273 } 274 }
274 if (moveit) { 275 if (moveit) {
275 deleteMail(mail); 276 deleteMail(mail);
276 } 277 }
277} 278}
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp
index c3a1627..d99c6a3 100644
--- a/kmicromail/libmailwrapper/genericwrapper.cpp
+++ b/kmicromail/libmailwrapper/genericwrapper.cpp
@@ -1,533 +1,548 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "genericwrapper.h" 2#include "genericwrapper.h"
3#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
4#include "mailtypes.h" 4#include "mailtypes.h"
5 5
6#include <kconfig.h> 6#include <kconfig.h>
7#include <kglobal.h> 7#include <kglobal.h>
8#include <kstandarddirs.h> 8#include <kstandarddirs.h>
9 9
10 10
11using namespace Opie::Core; 11using namespace Opie::Core;
12Genericwrapper::Genericwrapper() 12Genericwrapper::Genericwrapper()
13 : AbstractMail() 13 : AbstractMail()
14{ 14{
15 bodyCache.clear(); 15 bodyCache.clear();
16 m_storage = 0; 16 m_storage = 0;
17 m_folder = 0; 17 m_folder = 0;
18} 18}
19 19
20Genericwrapper::~Genericwrapper() 20Genericwrapper::~Genericwrapper()
21{ 21{
22 if (m_folder) { 22 if (m_folder) {
23 mailfolder_free(m_folder); 23 mailfolder_free(m_folder);
24 } 24 }
25 if (m_storage) { 25 if (m_storage) {
26 mailstorage_free(m_storage); 26 mailstorage_free(m_storage);
27 } 27 }
28 cleanMimeCache(); 28 cleanMimeCache();
29} 29}
30QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 30const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date )
31{ 31{
32 static bool init = false ; 32 static bool init = false ;
33 if ( ! init ) { 33 if ( ! init ) {
34 KConfig kon ( locateLocal( "config", "korganizerrc" ) ); 34 KConfig kon ( locateLocal( "config", "korganizerrc" ) );
35 kon.setGroup("Locale"); 35 kon.setGroup("Locale");
36 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)kon.readNumEntry( "PreferredDate",0) ); 36 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)kon.readNumEntry( "PreferredDate",0) );
37 QString dummy = kon.readEntry( "UserDateFormatShort","%aK %d.%m.%y" );// kon.readEntry( ""); 37 QString dummy = kon.readEntry( "UserDateFormatShort","%aK %d.%m.%y" );// kon.readEntry( "");
38 KGlobal::locale()->setHore24Format( !kon.readBoolEntry( "PreferredTime",0 ) ); 38 KGlobal::locale()->setHore24Format( !kon.readBoolEntry( "PreferredTime",0 ) );
39 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 39 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
40 dummy = kon.readEntry( "UserDateFormatLong","%A %d %b %y" ); 40 dummy = kon.readEntry( "UserDateFormatLong","%A %d %b %y" );
41 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 41 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
42 kon.setGroup("Time & Date"); 42 kon.setGroup("Time & Date");
43 KGlobal::locale()->setDaylightSaving( kon.readBoolEntry( "UseDaylightsaving", true ), 43 KGlobal::locale()->setDaylightSaving( kon.readBoolEntry( "UseDaylightsaving", true ),
44 kon.readNumEntry( "DaylightsavingStart", 90), 44 kon.readNumEntry( "DaylightsavingStart", 90),
45 kon.readNumEntry( "DaylightsavingEnd",304) ); 45 kon.readNumEntry( "DaylightsavingEnd",304) );
46 KGlobal::locale()->setTimezone( kon.readEntry( "TimeZoneName" ," 00:00 Europe/London(UTC)") ); 46 KGlobal::locale()->setTimezone( kon.readEntry( "TimeZoneName" ," 00:00 Europe/London(UTC)") );
47 47
48 init = true; 48 init = true;
49 49
50 } 50 }
51 QDate da (date->dt_year,date->dt_month, date->dt_day ); 51 QDate da (date->dt_year,date->dt_month, date->dt_day );
52 QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); 52 QTime ti ( date->dt_hour, date->dt_min, date->dt_sec );
53 QDateTime dt ( da ,ti ); 53 QDateTime dt ( da ,ti );
54 int addsec = -date->dt_zone*36;
55 //qDebug("adsec1 %d ",addsec );
56 dt = dt.addSecs( addsec );
54 int off = KGlobal::locale()->localTimeOffset( dt ); 57 int off = KGlobal::locale()->localTimeOffset( dt );
55 //dt = dt.addSecs( off*60 ); 58 //qDebug("adsec2 %d ",off*60 );
59
60 dt = dt.addSecs( off*60 );
61 return dt;
62#if 0
56 QString ret; 63 QString ret;
57 if ( da == QDate::currentDate () ) 64 if ( dt.date() == QDate::currentDate () )
58 ret = KGlobal::locale()->formatTime( ti,true); 65 ret = KGlobal::locale()->formatTime( dt.time(),true);
59 66
60 else { 67 else {
61 ret = KGlobal::locale()->formatDateTime( dt,true,true); 68 ret = KGlobal::locale()->formatDateTime( dt,true,true);
62 } 69 }
70#endif
63#if 0 71#if 0
64 if ( off < 0 ) 72 if ( off < 0 )
65 ret += " -"; 73 ret += " -";
66 else 74 else
67 ret += " +"; 75 ret += " +";
68 ret += QString::number( off / 60 ); 76 ret += QString::number( off / 60 );
69 ret += "h"; 77 ret += "h";
70#endif 78#endif
71#if 0 79#if 0
72 char tmp[23]; 80 char tmp[23];
73 81
74 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 82 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
75 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 83 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
76 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", 84 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i",
77 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 85 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
78 86
79 87
80 return QString( tmp ); 88 return QString( tmp );
81#endif 89#endif
82 return ret; 90 //return ret;
83} 91}
84 92
85void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) 93void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime)
86{ 94{
87 if (!mime) { 95 if (!mime) {
88 return; 96 return;
89 } 97 }
90 mailmime_field*field = 0; 98 mailmime_field*field = 0;
91 mailmime_single_fields fields; 99 mailmime_single_fields fields;
92 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 100 memset(&fields, 0, sizeof(struct mailmime_single_fields));
93 if (mime->mm_mime_fields != NULL) { 101 if (mime->mm_mime_fields != NULL) {
94 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 102 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
95 mime->mm_content_type); 103 mime->mm_content_type);
96 } 104 }
97 105
98 mailmime_content*type = fields.fld_content; 106 mailmime_content*type = fields.fld_content;
99 clistcell*current; 107 clistcell*current;
100 if (!type) { 108 if (!type) {
101 target->setType("text"); 109 target->setType("text");
102 target->setSubtype("plain"); 110 target->setSubtype("plain");
103 } else { 111 } else {
104 target->setSubtype(type->ct_subtype); 112 target->setSubtype(type->ct_subtype);
105 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 113 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
106 case MAILMIME_DISCRETE_TYPE_TEXT: 114 case MAILMIME_DISCRETE_TYPE_TEXT:
107 target->setType("text"); 115 target->setType("text");
108 break; 116 break;
109 case MAILMIME_DISCRETE_TYPE_IMAGE: 117 case MAILMIME_DISCRETE_TYPE_IMAGE:
110 target->setType("image"); 118 target->setType("image");
111 break; 119 break;
112 case MAILMIME_DISCRETE_TYPE_AUDIO: 120 case MAILMIME_DISCRETE_TYPE_AUDIO:
113 target->setType("audio"); 121 target->setType("audio");
114 break; 122 break;
115 case MAILMIME_DISCRETE_TYPE_VIDEO: 123 case MAILMIME_DISCRETE_TYPE_VIDEO:
116 target->setType("video"); 124 target->setType("video");
117 break; 125 break;
118 case MAILMIME_DISCRETE_TYPE_APPLICATION: 126 case MAILMIME_DISCRETE_TYPE_APPLICATION:
119 target->setType("application"); 127 target->setType("application");
120 break; 128 break;
121 case MAILMIME_DISCRETE_TYPE_EXTENSION: 129 case MAILMIME_DISCRETE_TYPE_EXTENSION:
122 default: 130 default:
123 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 131 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
124 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); 132 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
125 } 133 }
126 break; 134 break;
127 } 135 }
128 if (type->ct_parameters) { 136 if (type->ct_parameters) {
129 fillParameters(target,type->ct_parameters); 137 fillParameters(target,type->ct_parameters);
130 } 138 }
131 } 139 }
132 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 140 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
133 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { 141 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
134 field = (mailmime_field*)current->data; 142 field = (mailmime_field*)current->data;
135 switch(field->fld_type) { 143 switch(field->fld_type) {
136 case MAILMIME_FIELD_TRANSFER_ENCODING: 144 case MAILMIME_FIELD_TRANSFER_ENCODING:
137 target->setEncoding(getencoding(field->fld_data.fld_encoding)); 145 target->setEncoding(getencoding(field->fld_data.fld_encoding));
138 break; 146 break;
139 case MAILMIME_FIELD_ID: 147 case MAILMIME_FIELD_ID:
140 target->setIdentifier(field->fld_data.fld_id); 148 target->setIdentifier(field->fld_data.fld_id);
141 break; 149 break;
142 case MAILMIME_FIELD_DESCRIPTION: 150 case MAILMIME_FIELD_DESCRIPTION:
143 target->setDescription(field->fld_data.fld_description); 151 target->setDescription(field->fld_data.fld_description);
144 break; 152 break;
145 default: 153 default:
146 break; 154 break;
147 } 155 }
148 } 156 }
149 } 157 }
150} 158}
151 159
152void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) 160void Genericwrapper::fillParameters(RecPartP&target,clist*parameters)
153{ 161{
154 if (!parameters) {return;} 162 if (!parameters) {return;}
155 clistcell*current=0; 163 clistcell*current=0;
156 mailmime_parameter*param; 164 mailmime_parameter*param;
157 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 165 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
158 param = (mailmime_parameter*)current->data; 166 param = (mailmime_parameter*)current->data;
159 if (param) { 167 if (param) {
160 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 168 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
161 } 169 }
162 } 170 }
163} 171}
164 172
165QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 173QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
166{ 174{
167 QString enc="7bit"; 175 QString enc="7bit";
168 if (!aEnc) return enc; 176 if (!aEnc) return enc;
169 switch(aEnc->enc_type) { 177 switch(aEnc->enc_type) {
170 case MAILMIME_MECHANISM_7BIT: 178 case MAILMIME_MECHANISM_7BIT:
171 enc = "7bit"; 179 enc = "7bit";
172 break; 180 break;
173 case MAILMIME_MECHANISM_8BIT: 181 case MAILMIME_MECHANISM_8BIT:
174 enc = "8bit"; 182 enc = "8bit";
175 break; 183 break;
176 case MAILMIME_MECHANISM_BINARY: 184 case MAILMIME_MECHANISM_BINARY:
177 enc = "binary"; 185 enc = "binary";
178 break; 186 break;
179 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 187 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
180 enc = "quoted-printable"; 188 enc = "quoted-printable";
181 break; 189 break;
182 case MAILMIME_MECHANISM_BASE64: 190 case MAILMIME_MECHANISM_BASE64:
183 enc = "base64"; 191 enc = "base64";
184 break; 192 break;
185 case MAILMIME_MECHANISM_TOKEN: 193 case MAILMIME_MECHANISM_TOKEN:
186 default: 194 default:
187 if (aEnc->enc_token) { 195 if (aEnc->enc_token) {
188 enc = QString(aEnc->enc_token); 196 enc = QString(aEnc->enc_token);
189 } 197 }
190 break; 198 break;
191 } 199 }
192 return enc; 200 return enc;
193} 201}
194 202
195void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) 203void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count)
196{ 204{
197 if (current_rec >= 10) { 205 if (current_rec >= 10) {
198 ; // odebug << "too deep recursion!" << oendl; 206 ; // odebug << "too deep recursion!" << oendl;
199 } 207 }
200 if (!message || !mime) { 208 if (!message || !mime) {
201 return; 209 return;
202 } 210 }
203 int r; 211 int r;
204 char*data = 0; 212 char*data = 0;
205 size_t len; 213 size_t len;
206 clistiter * cur = 0; 214 clistiter * cur = 0;
207 QString b; 215 QString b;
208 RecPartP part = new RecPart(); 216 RecPartP part = new RecPart();
209 217
210 switch (mime->mm_type) { 218 switch (mime->mm_type) {
211 case MAILMIME_SINGLE: 219 case MAILMIME_SINGLE:
212 { 220 {
213 QValueList<int>countlist = recList; 221 QValueList<int>countlist = recList;
214 countlist.append(current_count); 222 countlist.append(current_count);
215 r = mailmessage_fetch_section(message,mime,&data,&len); 223 r = mailmessage_fetch_section(message,mime,&data,&len);
216 part->setSize(len); 224 part->setSize(len);
217 part->setPositionlist(countlist); 225 part->setPositionlist(countlist);
218 b = gen_attachment_id(); 226 b = gen_attachment_id();
219 part->setIdentifier(b); 227 part->setIdentifier(b);
220 fillSingleBody(part,message,mime); 228 fillSingleBody(part,message,mime);
221 if (part->Type()=="text" && target->Bodytext().isNull()) { 229 if (part->Type()=="text" && target->Bodytext().isNull()) {
222 encodedString*rs = new encodedString(); 230 encodedString*rs = new encodedString();
223 rs->setContent(data,len); 231 rs->setContent(data,len);
224 encodedString*res = decode_String(rs,part->Encoding()); 232 encodedString*res = decode_String(rs,part->Encoding());
225 if (countlist.count()>2) { 233 if (countlist.count()>2) {
226 bodyCache[b]=rs; 234 bodyCache[b]=rs;
227 target->addPart(part); 235 target->addPart(part);
228 } else { 236 } else {
229 delete rs; 237 delete rs;
230 } 238 }
231 b = QString(res->Content()); 239 b = QString(res->Content());
232 delete res; 240 delete res;
233 target->setBodytext(b); 241 target->setBodytext(b);
234 target->setDescription(part); 242 target->setDescription(part);
235 } else { 243 } else {
236 bodyCache[b]=new encodedString(data,len); 244 bodyCache[b]=new encodedString(data,len);
237 target->addPart(part); 245 target->addPart(part);
238 } 246 }
239 } 247 }
240 break; 248 break;
241 case MAILMIME_MULTIPLE: 249 case MAILMIME_MULTIPLE:
242 { 250 {
243 unsigned int ccount = 1; 251 unsigned int ccount = 1;
244 mailmime*cbody=0; 252 mailmime*cbody=0;
245 QValueList<int>countlist = recList; 253 QValueList<int>countlist = recList;
246 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 254 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
247 cbody = (mailmime*)clist_content(cur); 255 cbody = (mailmime*)clist_content(cur);
248 if (cbody->mm_type==MAILMIME_MULTIPLE) { 256 if (cbody->mm_type==MAILMIME_MULTIPLE) {
249 RecPartP targetPart = new RecPart(); 257 RecPartP targetPart = new RecPart();
250 targetPart->setType("multipart"); 258 targetPart->setType("multipart");
251 countlist.append(current_count); 259 countlist.append(current_count);
252 targetPart->setPositionlist(countlist); 260 targetPart->setPositionlist(countlist);
253 target->addPart(targetPart); 261 target->addPart(targetPart);
254 } 262 }
255 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 263 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
256 if (cbody->mm_type==MAILMIME_MULTIPLE) { 264 if (cbody->mm_type==MAILMIME_MULTIPLE) {
257 countlist = recList; 265 countlist = recList;
258 } 266 }
259 ++ccount; 267 ++ccount;
260 } 268 }
261 } 269 }
262 break; 270 break;
263 case MAILMIME_MESSAGE: 271 case MAILMIME_MESSAGE:
264 { 272 {
265 QValueList<int>countlist = recList; 273 QValueList<int>countlist = recList;
266 countlist.append(current_count); 274 countlist.append(current_count);
267 /* the own header is always at recursion 0 - we don't need that */ 275 /* the own header is always at recursion 0 - we don't need that */
268 if (current_rec > 0) { 276 if (current_rec > 0) {
269 part->setPositionlist(countlist); 277 part->setPositionlist(countlist);
270 r = mailmessage_fetch_section(message,mime,&data,&len); 278 r = mailmessage_fetch_section(message,mime,&data,&len);
271 part->setSize(len); 279 part->setSize(len);
272 part->setPositionlist(countlist); 280 part->setPositionlist(countlist);
273 b = gen_attachment_id(); 281 b = gen_attachment_id();
274 part->setIdentifier(b); 282 part->setIdentifier(b);
275 part->setType("message"); 283 part->setType("message");
276 part->setSubtype("rfc822"); 284 part->setSubtype("rfc822");
277 bodyCache[b]=new encodedString(data,len); 285 bodyCache[b]=new encodedString(data,len);
278 target->addPart(part); 286 target->addPart(part);
279 } 287 }
280 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 288 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
281 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 289 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
282 } 290 }
283 } 291 }
284 break; 292 break;
285 } 293 }
286} 294}
287 295
288RecBodyP Genericwrapper::parseMail( mailmessage * msg ) 296RecBodyP Genericwrapper::parseMail( mailmessage * msg )
289{ 297{
290 int err = MAILIMF_NO_ERROR; 298 int err = MAILIMF_NO_ERROR;
291 mailmime_single_fields fields; 299 mailmime_single_fields fields;
292 /* is bound to msg and will be freed there */ 300 /* is bound to msg and will be freed there */
293 mailmime * mime=0; 301 mailmime * mime=0;
294 RecBodyP body = new RecBody(); 302 RecBodyP body = new RecBody();
295 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 303 memset(&fields, 0, sizeof(struct mailmime_single_fields));
296 err = mailmessage_get_bodystructure(msg,&mime); 304 err = mailmessage_get_bodystructure(msg,&mime);
297 QValueList<int>recList; 305 QValueList<int>recList;
298 traverseBody(body,msg,mime,recList); 306 traverseBody(body,msg,mime,recList);
299 return body; 307 return body;
300} 308}
301 309
302 310
303QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 311QString Genericwrapper::parseAddressList( mailimf_address_list *list )
304{ 312{
305 QString result( "" ); 313 QString result( "" );
306 314
307 bool first = true; 315 bool first = true;
308 if (list == 0) return result; 316 if (list == 0) return result;
309 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 317 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
310 mailimf_address *addr = (mailimf_address *) current->data; 318 mailimf_address *addr = (mailimf_address *) current->data;
311 319
312 if ( !first ) { 320 if ( !first ) {
313 result.append( "," ); 321 result.append( "," );
314 } else { 322 } else {
315 first = false; 323 first = false;
316 } 324 }
317 325
318 switch ( addr->ad_type ) { 326 switch ( addr->ad_type ) {
319 case MAILIMF_ADDRESS_MAILBOX: 327 case MAILIMF_ADDRESS_MAILBOX:
320 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 328 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
321 break; 329 break;
322 case MAILIMF_ADDRESS_GROUP: 330 case MAILIMF_ADDRESS_GROUP:
323 result.append( parseGroup( addr->ad_data.ad_group ) ); 331 result.append( parseGroup( addr->ad_data.ad_group ) );
324 break; 332 break;
325 default: 333 default:
326 ; // odebug << "Generic: unkown mailimf address type" << oendl; 334 ; // odebug << "Generic: unkown mailimf address type" << oendl;
327 break; 335 break;
328 } 336 }
329 } 337 }
330 338
331 return result; 339 return result;
332} 340}
333 341
334QString Genericwrapper::parseGroup( mailimf_group *group ) 342QString Genericwrapper::parseGroup( mailimf_group *group )
335{ 343{
336 QString result( "" ); 344 QString result( "" );
337 345
338 result.append( group->grp_display_name ); 346 result.append( group->grp_display_name );
339 result.append( ": " ); 347 result.append( ": " );
340 348
341 if ( group->grp_mb_list != NULL ) { 349 if ( group->grp_mb_list != NULL ) {
342 result.append( parseMailboxList( group->grp_mb_list ) ); 350 result.append( parseMailboxList( group->grp_mb_list ) );
343 } 351 }
344 352
345 result.append( ";" ); 353 result.append( ";" );
346 354
347 return result; 355 return result;
348} 356}
349 357
350QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 358QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
351{ 359{
352 QString result( "" ); 360 QString result( "" );
353 361
354 if ( box->mb_display_name == NULL ) { 362 if ( box->mb_display_name == NULL ) {
355 result.append( box->mb_addr_spec ); 363 result.append( box->mb_addr_spec );
356 } else { 364 } else {
357 result.append( convert_String(box->mb_display_name).latin1() ); 365 result.append( convert_String(box->mb_display_name).latin1() );
358 result.append( " <" ); 366 result.append( " <" );
359 result.append( box->mb_addr_spec ); 367 result.append( box->mb_addr_spec );
360 result.append( ">" ); 368 result.append( ">" );
361 } 369 }
362 370
363 return result; 371 return result;
364} 372}
365 373
366QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 374QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
367{ 375{
368 QString result( "" ); 376 QString result( "" );
369 377
370 bool first = true; 378 bool first = true;
371 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 379 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
372 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 380 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
373 381
374 if ( !first ) { 382 if ( !first ) {
375 result.append( "," ); 383 result.append( "," );
376 } else { 384 } else {
377 first = false; 385 first = false;
378 } 386 }
379 387
380 result.append( parseMailbox( box ) ); 388 result.append( parseMailbox( box ) );
381 } 389 }
382 390
383 return result; 391 return result;
384} 392}
385 393
386encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) 394encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part)
387{ 395{
388 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 396 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
389 if (it==bodyCache.end()) return new encodedString(); 397 if (it==bodyCache.end()) return new encodedString();
390 encodedString*t = decode_String(it.data(),part->Encoding()); 398 encodedString*t = decode_String(it.data(),part->Encoding());
391 return t; 399 return t;
392} 400}
393 401
394encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) 402encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part)
395{ 403{
396 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 404 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
397 if (it==bodyCache.end()) return new encodedString(); 405 if (it==bodyCache.end()) return new encodedString();
398 encodedString*t = it.data(); 406 encodedString*t = it.data();
399 return t; 407 return t;
400} 408}
401 409
402QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 410QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
403{ 411{
404 encodedString*t = fetchDecodedPart(mail,part); 412 encodedString*t = fetchDecodedPart(mail,part);
405 QString text=t->Content(); 413 QString text=t->Content();
406 delete t; 414 delete t;
407 return text; 415 return text;
408} 416}
409 417
410void Genericwrapper::cleanMimeCache() 418void Genericwrapper::cleanMimeCache()
411{ 419{
412 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 420 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
413 for (;it!=bodyCache.end();++it) { 421 for (;it!=bodyCache.end();++it) {
414 encodedString*t = it.data(); 422 encodedString*t = it.data();
415 //it.setValue(0); 423 //it.setValue(0);
416 if (t) delete t; 424 if (t) delete t;
417 } 425 }
418 bodyCache.clear(); 426 bodyCache.clear();
419 ; // odebug << "Genericwrapper: cache cleaned" << oendl; 427 ; // odebug << "Genericwrapper: cache cleaned" << oendl;
420} 428}
421 429
422QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) 430QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies)
423{ 431{
424 QStringList res; 432 QStringList res;
425 if (!in_replies || !in_replies->mid_list) return res; 433 if (!in_replies || !in_replies->mid_list) return res;
426 clistiter * current = 0; 434 clistiter * current = 0;
427 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { 435 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) {
428 QString h((char*)current->data); 436 QString h((char*)current->data);
429 while (h.length()>0 && h[0]=='<') { 437 while (h.length()>0 && h[0]=='<') {
430 h.remove(0,1); 438 h.remove(0,1);
431 } 439 }
432 while (h.length()>0 && h[h.length()-1]=='>') { 440 while (h.length()>0 && h[h.length()-1]=='>') {
433 h.remove(h.length()-1,1); 441 h.remove(h.length()-1,1);
434 } 442 }
435 if (h.length()>0) { 443 if (h.length()>0) {
436 res.append(h); 444 res.append(h);
437 } 445 }
438 } 446 }
439 return res; 447 return res;
440} 448}
441 449
442void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) 450void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb)
443{ 451{
444 int r; 452 int r;
445 mailmessage_list * env_list = 0; 453 mailmessage_list * env_list = 0;
446 r = mailsession_get_messages_list(session,&env_list); 454 r = mailsession_get_messages_list(session,&env_list);
447 if (r != MAIL_NO_ERROR) { 455 if (r != MAIL_NO_ERROR) {
448 ; // odebug << "Error message list" << oendl; 456 ; // odebug << "Error message list" << oendl;
449 return; 457 return;
450 } 458 }
451 r = mailsession_get_envelopes_list(session, env_list); 459 r = mailsession_get_envelopes_list(session, env_list);
452 if (r != MAIL_NO_ERROR) { 460 if (r != MAIL_NO_ERROR) {
453 ; // odebug << "Error filling message list" << oendl; 461 ; // odebug << "Error filling message list" << oendl;
454 if (env_list) { 462 if (env_list) {
455 mailmessage_list_free(env_list); 463 mailmessage_list_free(env_list);
456 } 464 }
457 return; 465 return;
458 } 466 }
459 mailimf_references * refs = 0; 467 mailimf_references * refs = 0;
460 mailimf_in_reply_to * in_replies = 0; 468 mailimf_in_reply_to * in_replies = 0;
461 uint32_t i = 0; 469 uint32_t i = 0;
462 for(; i < carray_count(env_list->msg_tab) ; ++i) { 470 for(; i < carray_count(env_list->msg_tab) ; ++i) {
463 mailmessage * msg; 471 mailmessage * msg;
464 QBitArray mFlags(7); 472 QBitArray mFlags(7);
465 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 473 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
466 if (msg->msg_fields == NULL) { 474 if (msg->msg_fields == NULL) {
467 //; // odebug << "could not fetch envelope of message " << i << "" << oendl; 475 //; // odebug << "could not fetch envelope of message " << i << "" << oendl;
468 continue; 476 continue;
469 } 477 }
470 RecMailP mail = new RecMail(); 478 RecMailP mail = new RecMail();
471 mail->setWrapper(this); 479 mail->setWrapper(this);
472 mail_flags * flag_result = 0; 480 mail_flags * flag_result = 0;
473 r = mailmessage_get_flags(msg,&flag_result); 481 r = mailmessage_get_flags(msg,&flag_result);
474 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 482 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
475 mFlags.setBit(FLAG_SEEN); 483 mFlags.setBit(FLAG_SEEN);
476 } 484 }
477 mailimf_single_fields single_fields; 485 mailimf_single_fields single_fields;
478 mailimf_single_fields_init(&single_fields, msg->msg_fields); 486 mailimf_single_fields_init(&single_fields, msg->msg_fields);
479 mail->setMsgsize(msg->msg_size); 487 mail->setMsgsize(msg->msg_size);
480 mail->setFlags(mFlags); 488 mail->setFlags(mFlags);
481 mail->setMbox(mailbox); 489 mail->setMbox(mailbox);
482 mail->setNumber(msg->msg_index); 490 mail->setNumber(msg->msg_index);
483 if (single_fields.fld_subject) 491 if (single_fields.fld_subject)
484 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 492 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
485 if (single_fields.fld_from) 493 if (single_fields.fld_from)
486 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 494 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
487 if (!mbox_as_to) { 495 if (!mbox_as_to) {
488 if (single_fields.fld_to) 496 if (single_fields.fld_to)
489 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 497 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
490 } else { 498 } else {
491 mail->setTo(mailbox); 499 mail->setTo(mailbox);
492 } 500 }
493 if (single_fields.fld_cc) 501 if (single_fields.fld_cc)
494 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 502 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
495 if (single_fields.fld_bcc) 503 if (single_fields.fld_bcc)
496 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 504 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
497 if (single_fields.fld_orig_date) { 505 if (single_fields.fld_orig_date) {
498 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); 506 QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time );
499 char tmp[23]; 507 QString ret;
500 struct mailimf_date_time* date = single_fields.fld_orig_date->dt_date_time; 508 if ( dt.date() == QDate::currentDate () )
501 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %05i", 509 ret = KGlobal::locale()->formatTime( dt.time(),true);
502 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 510 else {
511 ret = KGlobal::locale()->formatDateTime( dt,true,true);
512 }
513 mail->setDate( ret );
514 char tmp[20];
515 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i",
516 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() );
517 //qDebug(" iso %s ", tmp);
503 mail->setIsoDate( QString( tmp ) ); 518 mail->setIsoDate( QString( tmp ) );
504 } 519 }
505 // crashes when accessing pop3 account? 520 // crashes when accessing pop3 account?
506 if (single_fields.fld_message_id) { 521 if (single_fields.fld_message_id) {
507 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 522 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
508 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; 523 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl;
509 } 524 }
510 if (single_fields.fld_reply_to) { 525 if (single_fields.fld_reply_to) {
511 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); 526 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list);
512 if (t.count()>0) { 527 if (t.count()>0) {
513 mail->setReplyto(t[0]); 528 mail->setReplyto(t[0]);
514 } 529 }
515 } 530 }
516#if 0 531#if 0
517 refs = single_fields.fld_references; 532 refs = single_fields.fld_references;
518 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 533 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
519 char * text = (char*)refs->mid_list->first->data; 534 char * text = (char*)refs->mid_list->first->data;
520 mail->setReplyto(QString(text)); 535 mail->setReplyto(QString(text));
521 } 536 }
522#endif 537#endif
523 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && 538 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list &&
524 clist_count(single_fields.fld_in_reply_to->mid_list)) { 539 clist_count(single_fields.fld_in_reply_to->mid_list)) {
525 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); 540 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to));
526 } 541 }
527 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) 542 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 )
528 target.append(mail); 543 target.append(mail);
529 } 544 }
530 if (env_list) { 545 if (env_list) {
531 mailmessage_list_free(env_list); 546 mailmessage_list_free(env_list);
532 } 547 }
533} 548}
diff --git a/kmicromail/libmailwrapper/genericwrapper.h b/kmicromail/libmailwrapper/genericwrapper.h
index 244212f..c35a6da 100644
--- a/kmicromail/libmailwrapper/genericwrapper.h
+++ b/kmicromail/libmailwrapper/genericwrapper.h
@@ -1,68 +1,68 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __GENERIC_WRAPPER_H 2#ifndef __GENERIC_WRAPPER_H
3#define __GENERIC_WRAPPER_H 3#define __GENERIC_WRAPPER_H
4 4
5#include "abstractmail.h" 5#include "abstractmail.h"
6#include <qmap.h> 6#include <qmap.h>
7#include <qstring.h> 7#include <qstring.h>
8#include <libetpan/clist.h> 8#include <libetpan/clist.h>
9 9
10class RecMail; 10class RecMail;
11class RecBody; 11class RecBody;
12class encodedString; 12class encodedString;
13struct mailpop3; 13struct mailpop3;
14struct mailmessage; 14struct mailmessage;
15struct mailmime; 15struct mailmime;
16struct mailmime_mechanism; 16struct mailmime_mechanism;
17struct mailimf_mailbox_list; 17struct mailimf_mailbox_list;
18struct mailimf_mailbox; 18struct mailimf_mailbox;
19struct mailimf_date_time; 19struct mailimf_date_time;
20struct mailimf_group; 20struct mailimf_group;
21struct mailimf_address_list; 21struct mailimf_address_list;
22struct mailsession; 22struct mailsession;
23struct mailstorage; 23struct mailstorage;
24struct mailfolder; 24struct mailfolder;
25struct mailimf_in_reply_to; 25struct mailimf_in_reply_to;
26 26
27/* this class hold just the funs shared between 27/* this class hold just the funs shared between
28 * mbox and pop3 (later mh, too) mail access. 28 * mbox and pop3 (later mh, too) mail access.
29 * it is not desigend to make a instance of it! 29 * it is not desigend to make a instance of it!
30 */ 30 */
31class Genericwrapper : public AbstractMail 31class Genericwrapper : public AbstractMail
32{ 32{
33 Q_OBJECT 33 Q_OBJECT
34public: 34public:
35 Genericwrapper(); 35 Genericwrapper();
36 virtual ~Genericwrapper(); 36 virtual ~Genericwrapper();
37 37
38 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); 38 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part);
39 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); 39 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part);
40 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); 40 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part);
41 virtual void cleanMimeCache(); 41 virtual void cleanMimeCache();
42 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&){return 1;} 42 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&){return 1;}
43 virtual void logout(){}; 43 virtual void logout(){};
44 virtual void storeMessage(const char*msg,size_t length, const QString&folder){}; 44 virtual void storeMessage(const char*msg,size_t length, const QString&folder){};
45 static QString parseDateTime( mailimf_date_time *date ); 45 static const QDateTime parseDateTime( mailimf_date_time *date );
46 46
47protected: 47protected:
48 RecBodyP parseMail( mailmessage * msg ); 48 RecBodyP parseMail( mailmessage * msg );
49 QString parseMailboxList( mailimf_mailbox_list *list ); 49 QString parseMailboxList( mailimf_mailbox_list *list );
50 QString parseMailbox( mailimf_mailbox *box ); 50 QString parseMailbox( mailimf_mailbox *box );
51 QString parseGroup( mailimf_group *group ); 51 QString parseGroup( mailimf_group *group );
52 QString parseAddressList( mailimf_address_list *list ); 52 QString parseAddressList( mailimf_address_list *list );
53 53
54 void traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1); 54 void traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1);
55 static void fillSingleBody(RecPartP&target,mailmessage*message,mailmime*mime); 55 static void fillSingleBody(RecPartP&target,mailmessage*message,mailmime*mime);
56 static void fillParameters(RecPartP&target,clist*parameters); 56 static void fillParameters(RecPartP&target,clist*parameters);
57 static QString getencoding(mailmime_mechanism*aEnc); 57 static QString getencoding(mailmime_mechanism*aEnc);
58 virtual void parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false, int maxSizeInKb = 0); 58 virtual void parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false, int maxSizeInKb = 0);
59 QStringList parseInreplies(mailimf_in_reply_to * in_replies); 59 QStringList parseInreplies(mailimf_in_reply_to * in_replies);
60 60
61 QString msgTempName; 61 QString msgTempName;
62 unsigned int last_msg_id; 62 unsigned int last_msg_id;
63 QMap<QString,encodedString*> bodyCache; 63 QMap<QString,encodedString*> bodyCache;
64 mailstorage * m_storage; 64 mailstorage * m_storage;
65 mailfolder*m_folder; 65 mailfolder*m_folder;
66}; 66};
67 67
68#endif 68#endif
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index d79df4f..b0dd1b8 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,855 +1,864 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include <stdlib.h> 2#include <stdlib.h>
3#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
4#include <qpe/global.h> 4#include <qpe/global.h>
5#include <qapplication.h> 5#include <qapplication.h>
6#include "imapwrapper.h" 6#include "imapwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include "logindialog.h" 8#include "logindialog.h"
9#include <qprogressbar.h> 9#include <qprogressbar.h>
10#include "genericwrapper.h" 10#include "genericwrapper.h"
11#include <kglobal.h>
11 12
12using namespace Opie::Core; 13using namespace Opie::Core;
13int IMAPwrapper::mMax = 0; 14int IMAPwrapper::mMax = 0;
14int IMAPwrapper::mCurrent = 0; 15int IMAPwrapper::mCurrent = 0;
15 16
16IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 17IMAPwrapper::IMAPwrapper( IMAPaccount *a )
17 : AbstractMail() 18 : AbstractMail()
18{ 19{
19 account = a; 20 account = a;
20 m_imap = 0; 21 m_imap = 0;
21 m_Lastmbox = ""; 22 m_Lastmbox = "";
22 mCurrent = 0; 23 mCurrent = 0;
23 mMax = 0; 24 mMax = 0;
24} 25}
25 26
26IMAPwrapper::~IMAPwrapper() 27IMAPwrapper::~IMAPwrapper()
27{ 28{
28 logout(); 29 logout();
29} 30}
30 31
31/* to avoid to often select statements in loops etc. 32/* to avoid to often select statements in loops etc.
32 we trust that we are logged in and connection is established!*/ 33 we trust that we are logged in and connection is established!*/
33int IMAPwrapper::selectMbox(const QString&mbox) 34int IMAPwrapper::selectMbox(const QString&mbox)
34{ 35{
35 if (mbox == m_Lastmbox) { 36 if (mbox == m_Lastmbox) {
36 return MAILIMAP_NO_ERROR; 37 return MAILIMAP_NO_ERROR;
37 } 38 }
38 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 39 int err = mailimap_select( m_imap, (char*)mbox.latin1());
39 if ( err != MAILIMAP_NO_ERROR ) { 40 if ( err != MAILIMAP_NO_ERROR ) {
40 m_Lastmbox = ""; 41 m_Lastmbox = "";
41 return err; 42 return err;
42 } 43 }
43 m_Lastmbox = mbox; 44 m_Lastmbox = mbox;
44 return err; 45 return err;
45} 46}
46 47
47void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 48void IMAPwrapper::imap_progress( size_t current, size_t maximum )
48{ 49{
49 //qDebug("imap progress %d of %d ",current,maximum ); 50 //qDebug("imap progress %d of %d ",current,maximum );
50 //Global::statusMessage(tr("Downloading message %1 of %2").arg( current).arg(maximum)); 51 //Global::statusMessage(tr("Downloading message %1 of %2").arg( current).arg(maximum));
51 //qApp->processEvents() 52 //qApp->processEvents()
52 static int last = 0; 53 static int last = 0;
53 if ( last != current ) 54 if ( last != current )
54 IMAPwrapper::progress(); 55 IMAPwrapper::progress();
55 last = current; 56 last = current;
56} 57}
57void IMAPwrapper::progress( QString m ) 58void IMAPwrapper::progress( QString m )
58{ 59{
59 60
60 static QString mProgrMess; 61 static QString mProgrMess;
61 if ( m != QString::null ) { 62 if ( m != QString::null ) {
62 mProgrMess = m; 63 mProgrMess = m;
63 mCurrent = 0; 64 mCurrent = 0;
64 return; 65 return;
65 } 66 }
66 QString mess; 67 QString mess;
67 //qDebug("progress "); 68 //qDebug("progress ");
68 if ( mMax ) mess = mProgrMess +tr(" message %1 of %2").arg( mCurrent++).arg(mMax); 69 if ( mMax ) mess = mProgrMess +tr(" message %1 of %2").arg( mCurrent++).arg(mMax);
69 else mess = mProgrMess +tr(" message %1").arg( mCurrent++); 70 else mess = mProgrMess +tr(" message %1").arg( mCurrent++);
70 Global::statusMessage(mess); 71 Global::statusMessage(mess);
71 qApp->processEvents(); 72 qApp->processEvents();
72} 73}
73bool IMAPwrapper::start_tls(bool force_tls) 74bool IMAPwrapper::start_tls(bool force_tls)
74{ 75{
75 int err; 76 int err;
76 bool try_tls; 77 bool try_tls;
77 mailimap_capability_data * cap_data = 0; 78 mailimap_capability_data * cap_data = 0;
78 79
79 err = mailimap_capability(m_imap,&cap_data); 80 err = mailimap_capability(m_imap,&cap_data);
80 if (err != MAILIMAP_NO_ERROR) { 81 if (err != MAILIMAP_NO_ERROR) {
81 Global::statusMessage("error getting capabilities!"); 82 Global::statusMessage("error getting capabilities!");
82 return false; 83 return false;
83 } 84 }
84 clistiter * cur; 85 clistiter * cur;
85 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 86 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
86 struct mailimap_capability * cap; 87 struct mailimap_capability * cap;
87 cap = (struct mailimap_capability *)clist_content(cur); 88 cap = (struct mailimap_capability *)clist_content(cur);
88 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 89 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
89 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 90 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
90 try_tls = true; 91 try_tls = true;
91 break; 92 break;
92 } 93 }
93 } 94 }
94 } 95 }
95 if (cap_data) { 96 if (cap_data) {
96 mailimap_capability_data_free(cap_data); 97 mailimap_capability_data_free(cap_data);
97 } 98 }
98 if (try_tls) { 99 if (try_tls) {
99 err = mailimap_starttls(m_imap); 100 err = mailimap_starttls(m_imap);
100 if (err != MAILIMAP_NO_ERROR && force_tls) { 101 if (err != MAILIMAP_NO_ERROR && force_tls) {
101 Global::statusMessage(tr("Server has no TLS support!")); 102 Global::statusMessage(tr("Server has no TLS support!"));
102 try_tls = false; 103 try_tls = false;
103 } else { 104 } else {
104 mailstream_low * low; 105 mailstream_low * low;
105 mailstream_low * new_low; 106 mailstream_low * new_low;
106 low = mailstream_get_low(m_imap->imap_stream); 107 low = mailstream_get_low(m_imap->imap_stream);
107 if (!low) { 108 if (!low) {
108 try_tls = false; 109 try_tls = false;
109 } else { 110 } else {
110 int fd = mailstream_low_get_fd(low); 111 int fd = mailstream_low_get_fd(low);
111 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 112 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
112 mailstream_low_free(low); 113 mailstream_low_free(low);
113 mailstream_set_low(m_imap->imap_stream, new_low); 114 mailstream_set_low(m_imap->imap_stream, new_low);
114 } else { 115 } else {
115 try_tls = false; 116 try_tls = false;
116 } 117 }
117 } 118 }
118 } 119 }
119 } 120 }
120 return try_tls; 121 return try_tls;
121} 122}
122 123
123void IMAPwrapper::login() 124void IMAPwrapper::login()
124{ 125{
125 QString server, user, pass; 126 QString server, user, pass;
126 uint16_t port; 127 uint16_t port;
127 int err = MAILIMAP_NO_ERROR; 128 int err = MAILIMAP_NO_ERROR;
128 129
129 if (account->getOffline()) return; 130 if (account->getOffline()) return;
130 /* we are connected this moment */ 131 /* we are connected this moment */
131 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 132 /* TODO: setup a timer holding the line or if connection closed - delete the value */
132 if (m_imap) { 133 if (m_imap) {
133 err = mailimap_noop(m_imap); 134 err = mailimap_noop(m_imap);
134 if (err!=MAILIMAP_NO_ERROR) { 135 if (err!=MAILIMAP_NO_ERROR) {
135 logout(); 136 logout();
136 } else { 137 } else {
137 mailstream_flush(m_imap->imap_stream); 138 mailstream_flush(m_imap->imap_stream);
138 return; 139 return;
139 } 140 }
140 } 141 }
141 server = account->getServer(); 142 server = account->getServer();
142 port = account->getPort().toUInt(); 143 port = account->getPort().toUInt();
143 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 144 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
144 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 145 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
145 login.show(); 146 login.show();
146 if ( QDialog::Accepted == login.exec() ) { 147 if ( QDialog::Accepted == login.exec() ) {
147 // ok 148 // ok
148 user = login.getUser(); 149 user = login.getUser();
149 pass = login.getPassword(); 150 pass = login.getPassword();
150 } else { 151 } else {
151 // cancel 152 // cancel
152 return; 153 return;
153 } 154 }
154 } else { 155 } else {
155 user = account->getUser(); 156 user = account->getUser();
156 pass = account->getPassword(); 157 pass = account->getPassword();
157 } 158 }
158 159
159 m_imap = mailimap_new( 20, &imap_progress ); 160 m_imap = mailimap_new( 20, &imap_progress );
160 161
161 /* connect */ 162 /* connect */
162 bool ssl = false; 163 bool ssl = false;
163 bool try_tls = false; 164 bool try_tls = false;
164 bool force_tls = false; 165 bool force_tls = false;
165 166
166 if ( account->ConnectionType() == 2 ) { 167 if ( account->ConnectionType() == 2 ) {
167 ssl = true; 168 ssl = true;
168 } 169 }
169 if (account->ConnectionType()==1) { 170 if (account->ConnectionType()==1) {
170 force_tls = true; 171 force_tls = true;
171 } 172 }
172 173
173 if ( ssl ) { 174 if ( ssl ) {
174 //qDebug("using ssl "); 175 //qDebug("using ssl ");
175 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); 176 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port );
176 } else { 177 } else {
177 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); 178 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port );
178 } 179 }
179 180
180 if ( err != MAILIMAP_NO_ERROR && 181 if ( err != MAILIMAP_NO_ERROR &&
181 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 182 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
182 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 183 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
183 QString failure = ""; 184 QString failure = "";
184 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 185 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
185 failure="Connection refused"; 186 failure="Connection refused";
186 } else { 187 } else {
187 failure="Unknown failure"; 188 failure="Unknown failure";
188 } 189 }
189 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 190 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
190 mailimap_free( m_imap ); 191 mailimap_free( m_imap );
191 m_imap = 0; 192 m_imap = 0;
192 return; 193 return;
193 } 194 }
194 195
195 if (!ssl) { 196 if (!ssl) {
196 try_tls = start_tls(force_tls); 197 try_tls = start_tls(force_tls);
197 } 198 }
198 199
199 bool ok = true; 200 bool ok = true;
200 if (force_tls && !try_tls) { 201 if (force_tls && !try_tls) {
201 Global::statusMessage(tr("Server has no TLS support!")); 202 Global::statusMessage(tr("Server has no TLS support!"));
202 ok = false; 203 ok = false;
203 } 204 }
204 205
205 206
206 /* login */ 207 /* login */
207 208
208 if (ok) { 209 if (ok) {
209 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); 210 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() );
210 if ( err != MAILIMAP_NO_ERROR ) { 211 if ( err != MAILIMAP_NO_ERROR ) {
211 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 212 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
212 ok = false; 213 ok = false;
213 } 214 }
214 } 215 }
215 if (!ok) { 216 if (!ok) {
216 err = mailimap_close( m_imap ); 217 err = mailimap_close( m_imap );
217 mailimap_free( m_imap ); 218 mailimap_free( m_imap );
218 m_imap = 0; 219 m_imap = 0;
219 } 220 }
220} 221}
221 222
222void IMAPwrapper::logout() 223void IMAPwrapper::logout()
223{ 224{
224 int err = MAILIMAP_NO_ERROR; 225 int err = MAILIMAP_NO_ERROR;
225 if (!m_imap) return; 226 if (!m_imap) return;
226 err = mailimap_logout( m_imap ); 227 err = mailimap_logout( m_imap );
227 err = mailimap_close( m_imap ); 228 err = mailimap_close( m_imap );
228 mailimap_free( m_imap ); 229 mailimap_free( m_imap );
229 m_imap = 0; 230 m_imap = 0;
230 m_Lastmbox = ""; 231 m_Lastmbox = "";
231} 232}
232 233
233void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) 234void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
234{ 235{
235 int err = MAILIMAP_NO_ERROR; 236 int err = MAILIMAP_NO_ERROR;
236 clist *result = 0; 237 clist *result = 0;
237 clistcell *current; 238 clistcell *current;
238 mailimap_fetch_type *fetchType = 0; 239 mailimap_fetch_type *fetchType = 0;
239 mailimap_set *set = 0; 240 mailimap_set *set = 0;
240 241
241 login(); 242 login();
242 if (!m_imap) { 243 if (!m_imap) {
243 return; 244 return;
244 } 245 }
245 /* select mailbox READONLY for operations */ 246 /* select mailbox READONLY for operations */
246 err = selectMbox(mailbox); 247 err = selectMbox(mailbox);
247 if ( err != MAILIMAP_NO_ERROR ) { 248 if ( err != MAILIMAP_NO_ERROR ) {
248 return; 249 return;
249 } 250 }
250 251
251 int last = m_imap->imap_selection_info->sel_exists; 252 int last = m_imap->imap_selection_info->sel_exists;
252 253
253 if (last == 0) { 254 if (last == 0) {
254 Global::statusMessage(tr("Mailbox has no mails")); 255 Global::statusMessage(tr("Mailbox has no mails"));
255 return; 256 return;
256 } else { 257 } else {
257 } 258 }
258 259
259 Global::statusMessage(tr("Fetching header list")); 260 Global::statusMessage(tr("Fetching header list"));
260 qApp->processEvents(); 261 qApp->processEvents();
261 /* the range has to start at 1!!! not with 0!!!! */ 262 /* the range has to start at 1!!! not with 0!!!! */
262 set = mailimap_set_new_interval( 1, last ); 263 set = mailimap_set_new_interval( 1, last );
263 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 264 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
264 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 265 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
265 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 266 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
266 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 267 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
267 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 268 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
268 269
269 err = mailimap_fetch( m_imap, set, fetchType, &result ); 270 err = mailimap_fetch( m_imap, set, fetchType, &result );
270 mailimap_set_free( set ); 271 mailimap_set_free( set );
271 mailimap_fetch_type_free( fetchType ); 272 mailimap_fetch_type_free( fetchType );
272 273
273 QString date,subject,from; 274 QString date,subject,from;
274 275
275 if ( err == MAILIMAP_NO_ERROR ) { 276 if ( err == MAILIMAP_NO_ERROR ) {
276 mailimap_msg_att * msg_att; 277 mailimap_msg_att * msg_att;
277 int i = 0; 278 int i = 0;
278 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 279 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
279 ++i; 280 ++i;
280 msg_att = (mailimap_msg_att*)current->data; 281 msg_att = (mailimap_msg_att*)current->data;
281 RecMail*m = parse_list_result(msg_att); 282 RecMail*m = parse_list_result(msg_att);
282 if (m) { 283 if (m) {
283 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { 284 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) {
284 m->setNumber(i); 285 m->setNumber(i);
285 m->setMbox(mailbox); 286 m->setMbox(mailbox);
286 m->setWrapper(this); 287 m->setWrapper(this);
287 target.append(m); 288 target.append(m);
288 } 289 }
289 } 290 }
290 } 291 }
291 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); 292 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count()));
292 } else { 293 } else {
293 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 294 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
294 } 295 }
295 if (result) mailimap_fetch_list_free(result); 296 if (result) mailimap_fetch_list_free(result);
296} 297}
297 298
298QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 299QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
299{ 300{
300 const char *path, *mask; 301 const char *path, *mask;
301 int err = MAILIMAP_NO_ERROR; 302 int err = MAILIMAP_NO_ERROR;
302 clist *result = 0; 303 clist *result = 0;
303 clistcell *current = 0; 304 clistcell *current = 0;
304 clistcell*cur_flag = 0; 305 clistcell*cur_flag = 0;
305 mailimap_mbx_list_flags*bflags = 0; 306 mailimap_mbx_list_flags*bflags = 0;
306 307
307 QValueList<FolderP>* folders = new QValueList<FolderP>(); 308 QValueList<FolderP>* folders = new QValueList<FolderP>();
308 login(); 309 login();
309 if (!m_imap) { 310 if (!m_imap) {
310 return folders; 311 return folders;
311 } 312 }
312 313
313/* 314/*
314 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 315 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
315 * We must not forget to filter them out in next loop! 316 * We must not forget to filter them out in next loop!
316 * it seems like ugly code. and yes - it is ugly code. but the best way. 317 * it seems like ugly code. and yes - it is ugly code. but the best way.
317 */ 318 */
318 Global::statusMessage(tr("Fetching folder list")); 319 Global::statusMessage(tr("Fetching folder list"));
319 qApp->processEvents(); 320 qApp->processEvents();
320 QString temp; 321 QString temp;
321 mask = "INBOX" ; 322 mask = "INBOX" ;
322 mailimap_mailbox_list *list; 323 mailimap_mailbox_list *list;
323 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 324 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
324 QString del; 325 QString del;
325 bool selectable = true; 326 bool selectable = true;
326 bool no_inferiors = false; 327 bool no_inferiors = false;
327 if ( err == MAILIMAP_NO_ERROR ) { 328 if ( err == MAILIMAP_NO_ERROR ) {
328 current = result->first; 329 current = result->first;
329 for ( int i = result->count; i > 0; i-- ) { 330 for ( int i = result->count; i > 0; i-- ) {
330 list = (mailimap_mailbox_list *) current->data; 331 list = (mailimap_mailbox_list *) current->data;
331 // it is better use the deep copy mechanism of qt itself 332 // it is better use the deep copy mechanism of qt itself
332 // instead of using strdup! 333 // instead of using strdup!
333 temp = list->mb_name; 334 temp = list->mb_name;
334 del = list->mb_delimiter; 335 del = list->mb_delimiter;
335 current = current->next; 336 current = current->next;
336 if ( (bflags = list->mb_flag) ) { 337 if ( (bflags = list->mb_flag) ) {
337 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 338 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
338 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 339 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
339 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 340 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
340 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 341 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
341 no_inferiors = true; 342 no_inferiors = true;
342 } 343 }
343 } 344 }
344 } 345 }
345 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 346 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
346 } 347 }
347 } else { 348 } else {
348 qDebug("error fetching folders: "); 349 qDebug("error fetching folders: ");
349 350
350 } 351 }
351 mailimap_list_result_free( result ); 352 mailimap_list_result_free( result );
352 353
353/* 354/*
354 * second stage - get the other then inbox folders 355 * second stage - get the other then inbox folders
355 */ 356 */
356 mask = "*" ; 357 mask = "*" ;
357 path = account->getPrefix().latin1(); 358 path = account->getPrefix().latin1();
358 if (!path) path = ""; 359 if (!path) path = "";
359 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 360 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
360 if ( err == MAILIMAP_NO_ERROR ) { 361 if ( err == MAILIMAP_NO_ERROR ) {
361 current = result->first; 362 current = result->first;
362 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 363 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
363 no_inferiors = false; 364 no_inferiors = false;
364 list = (mailimap_mailbox_list *) current->data; 365 list = (mailimap_mailbox_list *) current->data;
365 // it is better use the deep copy mechanism of qt itself 366 // it is better use the deep copy mechanism of qt itself
366 // instead of using strdup! 367 // instead of using strdup!
367 temp = list->mb_name; 368 temp = list->mb_name;
368 if (temp.lower()=="inbox") 369 if (temp.lower()=="inbox")
369 continue; 370 continue;
370 if (temp.lower()==account->getPrefix().lower()) 371 if (temp.lower()==account->getPrefix().lower())
371 continue; 372 continue;
372 if ( (bflags = list->mb_flag) ) { 373 if ( (bflags = list->mb_flag) ) {
373 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 374 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
374 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 375 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
375 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 376 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
376 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 377 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
377 no_inferiors = true; 378 no_inferiors = true;
378 } 379 }
379 } 380 }
380 } 381 }
381 del = list->mb_delimiter; 382 del = list->mb_delimiter;
382 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 383 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
383 } 384 }
384 } else { 385 } else {
385 qDebug("error fetching folders "); 386 qDebug("error fetching folders ");
386 387
387 } 388 }
388 if (result) mailimap_list_result_free( result ); 389 if (result) mailimap_list_result_free( result );
389 return folders; 390 return folders;
390} 391}
391 392
392RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 393RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
393{ 394{
394 RecMail * m = 0; 395 RecMail * m = 0;
395 mailimap_msg_att_item *item=0; 396 mailimap_msg_att_item *item=0;
396 clistcell *current,*c,*cf; 397 clistcell *current,*c,*cf;
397 mailimap_msg_att_dynamic*flist; 398 mailimap_msg_att_dynamic*flist;
398 mailimap_flag_fetch*cflag; 399 mailimap_flag_fetch*cflag;
399 int size; 400 int size;
400 QBitArray mFlags(7); 401 QBitArray mFlags(7);
401 QStringList addresslist; 402 QStringList addresslist;
402 403
403 if (!m_att) { 404 if (!m_att) {
404 return m; 405 return m;
405 } 406 }
406 m = new RecMail(); 407 m = new RecMail();
407 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 408 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
408 current = c; 409 current = c;
409 size = 0; 410 size = 0;
410 item = (mailimap_msg_att_item*)current->data; 411 item = (mailimap_msg_att_item*)current->data;
411 if ( !item ) 412 if ( !item )
412 continue; 413 continue;
413 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 414 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
414 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 415 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
415 if (!flist || !flist->att_list) { 416 if (!flist || !flist->att_list) {
416 continue; 417 continue;
417 } 418 }
418 cf = flist->att_list->first; 419 cf = flist->att_list->first;
419 if( ! cf ) 420 if( ! cf )
420 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 421 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
421 cflag = (mailimap_flag_fetch*)cf->data; 422 cflag = (mailimap_flag_fetch*)cf->data;
422 if( ! cflag ) 423 if( ! cflag )
423 qDebug("imap:not cflag "); 424 qDebug("imap:not cflag ");
424 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 425 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
425 switch (cflag->fl_flag->fl_type) { 426 switch (cflag->fl_flag->fl_type) {
426 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 427 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
427 mFlags.setBit(FLAG_ANSWERED); 428 mFlags.setBit(FLAG_ANSWERED);
428 break; 429 break;
429 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 430 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
430 mFlags.setBit(FLAG_FLAGGED); 431 mFlags.setBit(FLAG_FLAGGED);
431 break; 432 break;
432 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 433 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
433 mFlags.setBit(FLAG_DELETED); 434 mFlags.setBit(FLAG_DELETED);
434 break; 435 break;
435 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 436 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
436 mFlags.setBit(FLAG_SEEN); 437 mFlags.setBit(FLAG_SEEN);
437 break; 438 break;
438 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 439 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
439 mFlags.setBit(FLAG_DRAFT); 440 mFlags.setBit(FLAG_DRAFT);
440 break; 441 break;
441 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 442 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
442 break; 443 break;
443 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 444 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
444 break; 445 break;
445 default: 446 default:
446 break; 447 break;
447 } 448 }
448 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 449 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
449 mFlags.setBit(FLAG_RECENT); 450 mFlags.setBit(FLAG_RECENT);
450 } 451 }
451 } 452 }
452 continue; 453 continue;
453 } 454 }
454 if ( item->att_data.att_static == NULL ) 455 if ( item->att_data.att_static == NULL )
455 continue; 456 continue;
456 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 457 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
457 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 458 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
458 if ( head == NULL ) 459 if ( head == NULL )
459 continue; 460 continue;
460 if ( head->env_date != NULL ) { 461 if ( head->env_date != NULL ) {
461 m->setDate(head->env_date); 462 m->setDate(head->env_date);
462 struct mailimf_date_time result; 463 struct mailimf_date_time result;
463 struct mailimf_date_time* date = &result; 464 struct mailimf_date_time* date = &result;
464 struct mailimf_date_time **re = &date; 465 struct mailimf_date_time **re = &date;
465 size_t length = m->getDate().length(); 466 size_t length = m->getDate().length();
466 size_t index = 0; 467 size_t index = 0;
467 if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) { 468 if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) {
468 m->setDate( Genericwrapper::parseDateTime( date ) ); 469 QDateTime dt = Genericwrapper::parseDateTime( date );
469 char tmp[23]; 470 QString ret;
470 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %05i", 471 if ( dt.date() == QDate::currentDate () )
471 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 472 ret = KGlobal::locale()->formatTime( dt.time(),true);
473 else {
474 ret = KGlobal::locale()->formatDateTime( dt,true,true);
475 }
476 m->setDate( ret );
477 char tmp[20];
478 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i",
479 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() );
480 //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date);
472 m->setIsoDate( QString( tmp ) ); 481 m->setIsoDate( QString( tmp ) );
473 } else { 482 } else {
474 m->setIsoDate(head->env_date); 483 m->setIsoDate(head->env_date);
475 } 484 }
476 } 485 }
477 if ( head->env_subject != NULL ) 486 if ( head->env_subject != NULL )
478 m->setSubject(convert_String((const char*)head->env_subject)); 487 m->setSubject(convert_String((const char*)head->env_subject));
479 //m->setSubject(head->env_subject); 488 //m->setSubject(head->env_subject);
480 if (head->env_from!=NULL) { 489 if (head->env_from!=NULL) {
481 addresslist = address_list_to_stringlist(head->env_from->frm_list); 490 addresslist = address_list_to_stringlist(head->env_from->frm_list);
482 if (addresslist.count()) { 491 if (addresslist.count()) {
483 m->setFrom(addresslist.first()); 492 m->setFrom(addresslist.first());
484 } 493 }
485 } 494 }
486 if (head->env_to!=NULL) { 495 if (head->env_to!=NULL) {
487 addresslist = address_list_to_stringlist(head->env_to->to_list); 496 addresslist = address_list_to_stringlist(head->env_to->to_list);
488 m->setTo(addresslist); 497 m->setTo(addresslist);
489 } 498 }
490 if (head->env_cc!=NULL) { 499 if (head->env_cc!=NULL) {
491 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 500 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
492 m->setCC(addresslist); 501 m->setCC(addresslist);
493 } 502 }
494 if (head->env_bcc!=NULL) { 503 if (head->env_bcc!=NULL) {
495 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 504 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
496 m->setBcc(addresslist); 505 m->setBcc(addresslist);
497 } 506 }
498 /* reply to address, eg. email. */ 507 /* reply to address, eg. email. */
499 if (head->env_reply_to!=NULL) { 508 if (head->env_reply_to!=NULL) {
500 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 509 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
501 if (addresslist.count()) { 510 if (addresslist.count()) {
502 m->setReplyto(addresslist.first()); 511 m->setReplyto(addresslist.first());
503 } 512 }
504 } 513 }
505 if (head->env_in_reply_to!=NULL) { 514 if (head->env_in_reply_to!=NULL) {
506 QString h(head->env_in_reply_to); 515 QString h(head->env_in_reply_to);
507 while (h.length()>0 && h[0]=='<') { 516 while (h.length()>0 && h[0]=='<') {
508 h.remove(0,1); 517 h.remove(0,1);
509 } 518 }
510 while (h.length()>0 && h[h.length()-1]=='>') { 519 while (h.length()>0 && h[h.length()-1]=='>') {
511 h.remove(h.length()-1,1); 520 h.remove(h.length()-1,1);
512 } 521 }
513 if (h.length()>0) { 522 if (h.length()>0) {
514 m->setInreply(QStringList(h)); 523 m->setInreply(QStringList(h));
515 } 524 }
516 } 525 }
517 if (head->env_message_id != NULL) { 526 if (head->env_message_id != NULL) {
518 m->setMsgid(QString(head->env_message_id)); 527 m->setMsgid(QString(head->env_message_id));
519 } 528 }
520 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 529 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
521#if 0 530#if 0
522 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 531 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
523 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 532 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
524 qDebug("time %s ",da.toString().latin1() ); 533 qDebug("time %s ",da.toString().latin1() );
525#endif 534#endif
526 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 535 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
527 size = item->att_data.att_static->att_data.att_rfc822_size; 536 size = item->att_data.att_static->att_data.att_rfc822_size;
528 } 537 }
529 } 538 }
530 /* msg is already deleted */ 539 /* msg is already deleted */
531 if (mFlags.testBit(FLAG_DELETED) && m) { 540 if (mFlags.testBit(FLAG_DELETED) && m) {
532 delete m; 541 delete m;
533 m = 0; 542 m = 0;
534 } 543 }
535 if (m) { 544 if (m) {
536 m->setFlags(mFlags); 545 m->setFlags(mFlags);
537 m->setMsgsize(size); 546 m->setMsgsize(size);
538 } 547 }
539 return m; 548 return m;
540} 549}
541 550
542RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) 551RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail)
543{ 552{
544 RecBodyP body = new RecBody(); 553 RecBodyP body = new RecBody();
545 const char *mb; 554 const char *mb;
546 int err = MAILIMAP_NO_ERROR; 555 int err = MAILIMAP_NO_ERROR;
547 clist *result = 0; 556 clist *result = 0;
548 clistcell *current; 557 clistcell *current;
549 mailimap_fetch_att *fetchAtt = 0; 558 mailimap_fetch_att *fetchAtt = 0;
550 mailimap_fetch_type *fetchType = 0; 559 mailimap_fetch_type *fetchType = 0;
551 mailimap_set *set = 0; 560 mailimap_set *set = 0;
552 mailimap_body*body_desc = 0; 561 mailimap_body*body_desc = 0;
553 562
554 mb = mail->getMbox().latin1(); 563 mb = mail->getMbox().latin1();
555 564
556 login(); 565 login();
557 if (!m_imap) { 566 if (!m_imap) {
558 return body; 567 return body;
559 } 568 }
560 err = selectMbox(mail->getMbox()); 569 err = selectMbox(mail->getMbox());
561 if ( err != MAILIMAP_NO_ERROR ) { 570 if ( err != MAILIMAP_NO_ERROR ) {
562 return body; 571 return body;
563 } 572 }
564 573
565 /* the range has to start at 1!!! not with 0!!!! */ 574 /* the range has to start at 1!!! not with 0!!!! */
566 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); 575 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
567 fetchAtt = mailimap_fetch_att_new_bodystructure(); 576 fetchAtt = mailimap_fetch_att_new_bodystructure();
568 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 577 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
569 err = mailimap_fetch( m_imap, set, fetchType, &result ); 578 err = mailimap_fetch( m_imap, set, fetchType, &result );
570 mailimap_set_free( set ); 579 mailimap_set_free( set );
571 mailimap_fetch_type_free( fetchType ); 580 mailimap_fetch_type_free( fetchType );
572 581
573 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 582 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
574 mailimap_msg_att * msg_att; 583 mailimap_msg_att * msg_att;
575 msg_att = (mailimap_msg_att*)current->data; 584 msg_att = (mailimap_msg_att*)current->data;
576 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 585 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
577 QValueList<int> path; 586 QValueList<int> path;
578 body_desc = item->att_data.att_static->att_data.att_body; 587 body_desc = item->att_data.att_static->att_data.att_body;
579 traverseBody(mail,body_desc,body,0,path); 588 traverseBody(mail,body_desc,body,0,path);
580 } else { 589 } else {
581 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; 590 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl;
582 } 591 }
583 if (result) mailimap_fetch_list_free(result); 592 if (result) mailimap_fetch_list_free(result);
584 return body; 593 return body;
585} 594}
586 595
587QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 596QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
588{ 597{
589 QStringList l; 598 QStringList l;
590 QString from; 599 QString from;
591 bool named_from; 600 bool named_from;
592 clistcell *current = NULL; 601 clistcell *current = NULL;
593 mailimap_address * current_address=NULL; 602 mailimap_address * current_address=NULL;
594 if (!list) { 603 if (!list) {
595 return l; 604 return l;
596 } 605 }
597 unsigned int count = 0; 606 unsigned int count = 0;
598 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 607 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
599 from = ""; 608 from = "";
600 named_from = false; 609 named_from = false;
601 current_address=(mailimap_address*)current->data; 610 current_address=(mailimap_address*)current->data;
602 if (current_address->ad_personal_name){ 611 if (current_address->ad_personal_name){
603 from+=convert_String((const char*)current_address->ad_personal_name); 612 from+=convert_String((const char*)current_address->ad_personal_name);
604 from+=" "; 613 from+=" ";
605 named_from = true; 614 named_from = true;
606 } 615 }
607 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 616 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
608 from+="<"; 617 from+="<";
609 } 618 }
610 if (current_address->ad_mailbox_name) { 619 if (current_address->ad_mailbox_name) {
611 from+=QString(current_address->ad_mailbox_name); 620 from+=QString(current_address->ad_mailbox_name);
612 from+="@"; 621 from+="@";
613 } 622 }
614 if (current_address->ad_host_name) { 623 if (current_address->ad_host_name) {
615 from+=QString(current_address->ad_host_name); 624 from+=QString(current_address->ad_host_name);
616 } 625 }
617 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 626 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
618 from+=">"; 627 from+=">";
619 } 628 }
620 l.append(QString(from)); 629 l.append(QString(from));
621 if (++count > 99) { 630 if (++count > 99) {
622 break; 631 break;
623 } 632 }
624 } 633 }
625 return l; 634 return l;
626} 635}
627 636
628encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) 637encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call)
629{ 638{
630 encodedString*res=new encodedString; 639 encodedString*res=new encodedString;
631 int err; 640 int err;
632 mailimap_fetch_type *fetchType; 641 mailimap_fetch_type *fetchType;
633 mailimap_set *set; 642 mailimap_set *set;
634 clistcell*current,*cur; 643 clistcell*current,*cur;
635 mailimap_section_part * section_part = 0; 644 mailimap_section_part * section_part = 0;
636 mailimap_section_spec * section_spec = 0; 645 mailimap_section_spec * section_spec = 0;
637 mailimap_section * section = 0; 646 mailimap_section * section = 0;
638 mailimap_fetch_att * fetch_att = 0; 647 mailimap_fetch_att * fetch_att = 0;
639 648
640 login(); 649 login();
641 if (!m_imap) { 650 if (!m_imap) {
642 return res; 651 return res;
643 } 652 }
644 if (!internal_call) { 653 if (!internal_call) {
645 err = selectMbox(mail->getMbox()); 654 err = selectMbox(mail->getMbox());
646 if ( err != MAILIMAP_NO_ERROR ) { 655 if ( err != MAILIMAP_NO_ERROR ) {
647 return res; 656 return res;
648 } 657 }
649 } 658 }
650 set = mailimap_set_new_single(mail->getNumber()); 659 set = mailimap_set_new_single(mail->getNumber());
651 660
652 clist*id_list = 0; 661 clist*id_list = 0;
653 662
654 /* if path == empty then its a request for the whole rfc822 mail and generates 663 /* if path == empty then its a request for the whole rfc822 mail and generates
655 a "fetch <id> (body[])" statement on imap server */ 664 a "fetch <id> (body[])" statement on imap server */
656 if (path.count()>0 ) { 665 if (path.count()>0 ) {
657 id_list = clist_new(); 666 id_list = clist_new();
658 for (unsigned j=0; j < path.count();++j) { 667 for (unsigned j=0; j < path.count();++j) {
659 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 668 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
660 *p_id = path[j]; 669 *p_id = path[j];
661 clist_append(id_list,p_id); 670 clist_append(id_list,p_id);
662 } 671 }
663 section_part = mailimap_section_part_new(id_list); 672 section_part = mailimap_section_part_new(id_list);
664 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 673 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
665 } 674 }
666 675
667 section = mailimap_section_new(section_spec); 676 section = mailimap_section_new(section_spec);
668 fetch_att = mailimap_fetch_att_new_body_section(section); 677 fetch_att = mailimap_fetch_att_new_body_section(section);
669 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 678 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
670 679
671 clist*result = 0; 680 clist*result = 0;
672 681
673 err = mailimap_fetch( m_imap, set, fetchType, &result ); 682 err = mailimap_fetch( m_imap, set, fetchType, &result );
674 mailimap_set_free( set ); 683 mailimap_set_free( set );
675 mailimap_fetch_type_free( fetchType ); 684 mailimap_fetch_type_free( fetchType );
676 685
677 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 686 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
678 mailimap_msg_att * msg_att; 687 mailimap_msg_att * msg_att;
679 msg_att = (mailimap_msg_att*)current->data; 688 msg_att = (mailimap_msg_att*)current->data;
680 mailimap_msg_att_item*msg_att_item; 689 mailimap_msg_att_item*msg_att_item;
681 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 690 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
682 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 691 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
683 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 692 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
684 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 693 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
685 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 694 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
686 /* detach - we take over the content */ 695 /* detach - we take over the content */
687 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 696 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
688 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 697 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
689 } 698 }
690 } 699 }
691 } 700 }
692 } else { 701 } else {
693 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; 702 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl;
694 } 703 }
695 if (result) mailimap_fetch_list_free(result); 704 if (result) mailimap_fetch_list_free(result);
696 return res; 705 return res;
697} 706}
698 707
699/* current_recursion is for recursive calls. 708/* current_recursion is for recursive calls.
700 current_count means the position inside the internal loop! */ 709 current_count means the position inside the internal loop! */
701void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, 710void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,
702 int current_recursion,QValueList<int>recList,int current_count) 711 int current_recursion,QValueList<int>recList,int current_count)
703{ 712{
704 if (!body || current_recursion>=10) { 713 if (!body || current_recursion>=10) {
705 return; 714 return;
706 } 715 }
707 switch (body->bd_type) { 716 switch (body->bd_type) {
708 case MAILIMAP_BODY_1PART: 717 case MAILIMAP_BODY_1PART:
709 { 718 {
710 QValueList<int>countlist = recList; 719 QValueList<int>countlist = recList;
711 countlist.append(current_count); 720 countlist.append(current_count);
712 RecPartP currentPart = new RecPart(); 721 RecPartP currentPart = new RecPart();
713 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 722 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
714 QString id(""); 723 QString id("");
715 currentPart->setPositionlist(countlist); 724 currentPart->setPositionlist(countlist);
716 for (unsigned int j = 0; j < countlist.count();++j) { 725 for (unsigned int j = 0; j < countlist.count();++j) {
717 id+=(j>0?" ":""); 726 id+=(j>0?" ":"");
718 id+=QString("%1").arg(countlist[j]); 727 id+=QString("%1").arg(countlist[j]);
719 } 728 }
720 //odebug << "ID = " << id.latin1() << "" << oendl; 729 //odebug << "ID = " << id.latin1() << "" << oendl;
721 currentPart->setIdentifier(id); 730 currentPart->setIdentifier(id);
722 fillSinglePart(currentPart,part1); 731 fillSinglePart(currentPart,part1);
723 /* important: Check for is NULL 'cause a body can be empty! 732 /* important: Check for is NULL 'cause a body can be empty!
724 And we put it only into the mail if it is the FIRST part */ 733 And we put it only into the mail if it is the FIRST part */
725 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { 734 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) {
726 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); 735 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
727 target_body->setDescription(currentPart); 736 target_body->setDescription(currentPart);
728 target_body->setBodytext(body_text); 737 target_body->setBodytext(body_text);
729 if (countlist.count()>1) { 738 if (countlist.count()>1) {
730 target_body->addPart(currentPart); 739 target_body->addPart(currentPart);
731 } 740 }
732 } else { 741 } else {
733 target_body->addPart(currentPart); 742 target_body->addPart(currentPart);
734 } 743 }
735 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 744 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
736 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 745 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
737 } 746 }
738 } 747 }
739 break; 748 break;
740 case MAILIMAP_BODY_MPART: 749 case MAILIMAP_BODY_MPART:
741 { 750 {
742 QValueList<int>countlist = recList; 751 QValueList<int>countlist = recList;
743 clistcell*current=0; 752 clistcell*current=0;
744 mailimap_body*current_body=0; 753 mailimap_body*current_body=0;
745 unsigned int ccount = 1; 754 unsigned int ccount = 1;
746 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 755 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
747 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 756 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
748 current_body = (mailimap_body*)current->data; 757 current_body = (mailimap_body*)current->data;
749 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 758 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
750 RecPartP targetPart = new RecPart(); 759 RecPartP targetPart = new RecPart();
751 targetPart->setType("multipart"); 760 targetPart->setType("multipart");
752 fillMultiPart(targetPart,mailDescription); 761 fillMultiPart(targetPart,mailDescription);
753 countlist.append(current_count); 762 countlist.append(current_count);
754 targetPart->setPositionlist(countlist); 763 targetPart->setPositionlist(countlist);
755 target_body->addPart(targetPart); 764 target_body->addPart(targetPart);
756 QString id(""); 765 QString id("");
757 for (unsigned int j = 0; j < countlist.count();++j) { 766 for (unsigned int j = 0; j < countlist.count();++j) {
758 id+=(j>0?" ":""); 767 id+=(j>0?" ":"");
759 id+=QString("%1").arg(countlist[j]); 768 id+=QString("%1").arg(countlist[j]);
760 } 769 }
761 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; 770 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
762 } 771 }
763 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 772 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
764 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 773 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
765 countlist = recList; 774 countlist = recList;
766 } 775 }
767 ++ccount; 776 ++ccount;
768 } 777 }
769 } 778 }
770 break; 779 break;
771 default: 780 default:
772 break; 781 break;
773 } 782 }
774} 783}
775 784
776void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) 785void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description)
777{ 786{
778 if (!Description) { 787 if (!Description) {
779 return; 788 return;
780 } 789 }
781 switch (Description->bd_type) { 790 switch (Description->bd_type) {
782 case MAILIMAP_BODY_TYPE_1PART_TEXT: 791 case MAILIMAP_BODY_TYPE_1PART_TEXT:
783 target_part->setType("text"); 792 target_part->setType("text");
784 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 793 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
785 break; 794 break;
786 case MAILIMAP_BODY_TYPE_1PART_BASIC: 795 case MAILIMAP_BODY_TYPE_1PART_BASIC:
787 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 796 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
788 break; 797 break;
789 case MAILIMAP_BODY_TYPE_1PART_MSG: 798 case MAILIMAP_BODY_TYPE_1PART_MSG:
790 target_part->setType("message"); 799 target_part->setType("message");
791 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 800 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
792 break; 801 break;
793 default: 802 default:
794 break; 803 break;
795 } 804 }
796} 805}
797 806
798void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) 807void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which)
799{ 808{
800 if (!which) { 809 if (!which) {
801 return; 810 return;
802 } 811 }
803 QString sub; 812 QString sub;
804 sub = which->bd_media_text; 813 sub = which->bd_media_text;
805 //odebug << "Type= text/" << which->bd_media_text << "" << oendl; 814 //odebug << "Type= text/" << which->bd_media_text << "" << oendl;
806 target_part->setSubtype(sub.lower()); 815 target_part->setSubtype(sub.lower());
807 target_part->setLines(which->bd_lines); 816 target_part->setLines(which->bd_lines);
808 fillBodyFields(target_part,which->bd_fields); 817 fillBodyFields(target_part,which->bd_fields);
809} 818}
810 819
811void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) 820void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
812{ 821{
813 if (!which) { 822 if (!which) {
814 return; 823 return;
815 } 824 }
816 target_part->setSubtype("rfc822"); 825 target_part->setSubtype("rfc822");
817 //odebug << "Message part" << oendl; 826 //odebug << "Message part" << oendl;
818 /* we set this type to text/plain */ 827 /* we set this type to text/plain */
819 target_part->setLines(which->bd_lines); 828 target_part->setLines(which->bd_lines);
820 fillBodyFields(target_part,which->bd_fields); 829 fillBodyFields(target_part,which->bd_fields);
821} 830}
822 831
823void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) 832void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
824{ 833{
825 if (!which) return; 834 if (!which) return;
826 QString sub = which->bd_media_subtype; 835 QString sub = which->bd_media_subtype;
827 target_part->setSubtype(sub.lower()); 836 target_part->setSubtype(sub.lower());
828 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 837 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
829 clistcell*cur = 0; 838 clistcell*cur = 0;
830 mailimap_single_body_fld_param*param=0; 839 mailimap_single_body_fld_param*param=0;
831 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 840 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
832 param = (mailimap_single_body_fld_param*)cur->data; 841 param = (mailimap_single_body_fld_param*)cur->data;
833 if (param) { 842 if (param) {
834 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 843 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
835 } 844 }
836 } 845 }
837 } 846 }
838} 847}
839 848
840void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) 849void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
841{ 850{
842 if (!which) { 851 if (!which) {
843 return; 852 return;
844 } 853 }
845 QString type,sub; 854 QString type,sub;
846 switch (which->bd_media_basic->med_type) { 855 switch (which->bd_media_basic->med_type) {
847 case MAILIMAP_MEDIA_BASIC_APPLICATION: 856 case MAILIMAP_MEDIA_BASIC_APPLICATION:
848 type = "application"; 857 type = "application";
849 break; 858 break;
850 case MAILIMAP_MEDIA_BASIC_AUDIO: 859 case MAILIMAP_MEDIA_BASIC_AUDIO:
851 type = "audio"; 860 type = "audio";
852 break; 861 break;
853 case MAILIMAP_MEDIA_BASIC_IMAGE: 862 case MAILIMAP_MEDIA_BASIC_IMAGE:
854 type = "image"; 863 type = "image";
855 break; 864 break;
diff --git a/kmicromail/libmailwrapper/mailtypes.cpp b/kmicromail/libmailwrapper/mailtypes.cpp
index 1a4ffd1..af3b9d0 100644
--- a/kmicromail/libmailwrapper/mailtypes.cpp
+++ b/kmicromail/libmailwrapper/mailtypes.cpp
@@ -1,422 +1,428 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2 2
3//#include <opie2/odebug.h> 3//#include <opie2/odebug.h>
4 4
5#include <stdlib.h> 5#include <stdlib.h>
6 6
7using namespace Opie::Core; 7using namespace Opie::Core;
8RecMail::RecMail() 8RecMail::RecMail()
9 :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) 9 :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
10{ 10{
11 init(); 11 init();
12} 12}
13 13
14RecMail::RecMail(const RecMail&old) 14RecMail::RecMail(const RecMail&old)
15 :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) 15 :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
16{ 16{
17 init(); 17 init();
18 copy_old(old); 18 copy_old(old);
19 // odebug << "Copy constructor RecMail" << oendl; 19 // odebug << "Copy constructor RecMail" << oendl;
20} 20}
21 21
22RecMail::~RecMail() 22RecMail::~RecMail()
23{ 23{
24 wrapper = 0; 24 wrapper = 0;
25} 25}
26static bool stringCompareRec( const QString& s1, const QString& s2 ) 26static bool stringCompareRec( const QString& s1, const QString& s2 )
27{ 27{
28 if ( s1.isEmpty() && s2.isEmpty() ) 28 if ( s1.isEmpty() && s2.isEmpty() )
29 return true; 29 return true;
30 return s1 == s2; 30 return s1 == s2;
31} 31}
32 32
33bool RecMail::isEqual( RecMail* r1 ) 33bool RecMail::isEqual( RecMail* r1 )
34{ 34{
35 if ( !stringCompareRec( isodate, r1->isodate ) ) { 35 if ( !stringCompareRec( isodate, r1->isodate ) ) {
36 // qDebug("date *%s* *%s* ", isodate.latin1(), r1->isodate.latin1()); 36 //qDebug("date *%s* *%s* ", isodate.latin1(), r1->isodate.latin1());
37 return false; 37 return false;
38 } 38 }
39 if ( !stringCompareRec( from, r1->from ) ) { 39 if ( !stringCompareRec( subject.left(40), r1->subject.left(40) ) ) {
40 //qDebug("from *%s* *%s* ", from.latin1(), r1->from.latin1()); 40 //qDebug("sub *%s* *%s*", subject.latin1(), r1->subject.latin1());
41 return false; 41 return false;
42 } 42 }
43 if ( !stringCompareRec( subject, r1->subject ) ) { 43
44 //qDebug("sub "); 44 //qDebug("date *%s* *%s* ", isodate.latin1(), r1->isodate.latin1());
45 return false; 45 if ( !stringCompareRec( from.left(40), r1->from.left(40)) ) {
46 if ( r1->from.find ( from ) < 0 ) {
47 if ( !stringCompareRec( from.simplifyWhiteSpace ().left(40), r1->from.simplifyWhiteSpace ().left(40)) ) {
48 //qDebug("from *%s* *%s* ", from.left(40).latin1(), r1->from.left(20).latin1());
49 return false;
50 }
51 }
46 } 52 }
47 53
48 return true; 54 return true;
49} 55}
50void RecMail::copy_old(const RecMail&old) 56void RecMail::copy_old(const RecMail&old)
51{ 57{
52 subject = old.subject; 58 subject = old.subject;
53 date = old.date; 59 date = old.date;
54 mbox = old.mbox; 60 mbox = old.mbox;
55 msg_id = old.msg_id; 61 msg_id = old.msg_id;
56 msg_size = old.msg_size; 62 msg_size = old.msg_size;
57 msg_number = old.msg_number; 63 msg_number = old.msg_number;
58 from = old.from; 64 from = old.from;
59 msg_flags = old.msg_flags; 65 msg_flags = old.msg_flags;
60 to = old.to; 66 to = old.to;
61 cc = old.cc; 67 cc = old.cc;
62 bcc = old.bcc; 68 bcc = old.bcc;
63 wrapper = old.wrapper; 69 wrapper = old.wrapper;
64 in_reply_to = old.in_reply_to; 70 in_reply_to = old.in_reply_to;
65 references = old.references; 71 references = old.references;
66 replyto = old.replyto; 72 replyto = old.replyto;
67} 73}
68 74
69void RecMail::init() 75void RecMail::init()
70{ 76{
71 to.clear(); 77 to.clear();
72 cc.clear(); 78 cc.clear();
73 bcc.clear(); 79 bcc.clear();
74 in_reply_to.clear(); 80 in_reply_to.clear();
75 references.clear(); 81 references.clear();
76 wrapper = 0; 82 wrapper = 0;
77} 83}
78 84
79void RecMail::setWrapper(AbstractMail*awrapper) 85void RecMail::setWrapper(AbstractMail*awrapper)
80{ 86{
81 wrapper = awrapper; 87 wrapper = awrapper;
82} 88}
83 89
84AbstractMail* RecMail::Wrapper() 90AbstractMail* RecMail::Wrapper()
85{ 91{
86 return wrapper; 92 return wrapper;
87} 93}
88 94
89void RecMail::setTo(const QStringList&list) 95void RecMail::setTo(const QStringList&list)
90{ 96{
91 to = list; 97 to = list;
92} 98}
93 99
94const QStringList&RecMail::To()const 100const QStringList&RecMail::To()const
95{ 101{
96 return to; 102 return to;
97} 103}
98 104
99void RecMail::setCC(const QStringList&list) 105void RecMail::setCC(const QStringList&list)
100{ 106{
101 cc = list; 107 cc = list;
102} 108}
103 109
104const QStringList&RecMail::CC()const 110const QStringList&RecMail::CC()const
105{ 111{
106 return cc; 112 return cc;
107} 113}
108 114
109void RecMail::setBcc(const QStringList&list) 115void RecMail::setBcc(const QStringList&list)
110{ 116{
111 bcc = list; 117 bcc = list;
112} 118}
113 119
114const QStringList& RecMail::Bcc()const 120const QStringList& RecMail::Bcc()const
115{ 121{
116 return bcc; 122 return bcc;
117} 123}
118 124
119void RecMail::setInreply(const QStringList&list) 125void RecMail::setInreply(const QStringList&list)
120{ 126{
121 in_reply_to = list; 127 in_reply_to = list;
122} 128}
123 129
124const QStringList& RecMail::Inreply()const 130const QStringList& RecMail::Inreply()const
125{ 131{
126 return in_reply_to; 132 return in_reply_to;
127} 133}
128 134
129void RecMail::setReferences(const QStringList&list) 135void RecMail::setReferences(const QStringList&list)
130{ 136{
131 references = list; 137 references = list;
132} 138}
133 139
134const QStringList& RecMail::References()const 140const QStringList& RecMail::References()const
135{ 141{
136 return references; 142 return references;
137} 143}
138 144
139RecPart::RecPart() 145RecPart::RecPart()
140 : Opie::Core::ORefCount(), 146 : Opie::Core::ORefCount(),
141 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) 147 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0)
142{ 148{
143 m_Parameters.clear(); 149 m_Parameters.clear();
144 m_poslist.clear(); 150 m_poslist.clear();
145} 151}
146 152
147RecPart::RecPart(const RecPart&old) 153RecPart::RecPart(const RecPart&old)
148 : Opie::Core::ORefCount(), 154 : Opie::Core::ORefCount(),
149 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) 155 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0)
150{ 156{
151 m_type = old.m_type; 157 m_type = old.m_type;
152 m_subtype = old.m_subtype; 158 m_subtype = old.m_subtype;
153 m_identifier = old.m_identifier; 159 m_identifier = old.m_identifier;
154 m_encoding = old.m_encoding; 160 m_encoding = old.m_encoding;
155 m_description = old.m_description; 161 m_description = old.m_description;
156 m_lines = old.m_lines; 162 m_lines = old.m_lines;
157 m_size = old.m_size; 163 m_size = old.m_size;
158 m_Parameters = old.m_Parameters; 164 m_Parameters = old.m_Parameters;
159 m_poslist = old.m_poslist; 165 m_poslist = old.m_poslist;
160 // odebug << "RecPart copy constructor" << oendl; 166 // odebug << "RecPart copy constructor" << oendl;
161} 167}
162 168
163RecPart::~RecPart() 169RecPart::~RecPart()
164{ 170{
165} 171}
166 172
167void RecPart::setSize(unsigned int size) 173void RecPart::setSize(unsigned int size)
168{ 174{
169 m_size = size; 175 m_size = size;
170} 176}
171 177
172const unsigned int RecPart::Size()const 178const unsigned int RecPart::Size()const
173{ 179{
174 return m_size; 180 return m_size;
175} 181}
176 182
177void RecPart::setLines(unsigned int lines) 183void RecPart::setLines(unsigned int lines)
178{ 184{
179 m_lines = lines; 185 m_lines = lines;
180} 186}
181 187
182const unsigned int RecPart::Lines()const 188const unsigned int RecPart::Lines()const
183{ 189{
184 return m_lines; 190 return m_lines;
185} 191}
186 192
187const QString& RecPart::Type()const 193const QString& RecPart::Type()const
188{ 194{
189 return m_type; 195 return m_type;
190} 196}
191 197
192void RecPart::setType(const QString&type) 198void RecPart::setType(const QString&type)
193{ 199{
194 m_type = type; 200 m_type = type;
195} 201}
196 202
197const QString& RecPart::Subtype()const 203const QString& RecPart::Subtype()const
198{ 204{
199 return m_subtype; 205 return m_subtype;
200} 206}
201 207
202void RecPart::setSubtype(const QString&subtype) 208void RecPart::setSubtype(const QString&subtype)
203{ 209{
204 m_subtype = subtype; 210 m_subtype = subtype;
205} 211}
206 212
207const QString& RecPart::Identifier()const 213const QString& RecPart::Identifier()const
208{ 214{
209 return m_identifier; 215 return m_identifier;
210} 216}
211 217
212void RecPart::setIdentifier(const QString&identifier) 218void RecPart::setIdentifier(const QString&identifier)
213{ 219{
214 m_identifier = identifier; 220 m_identifier = identifier;
215} 221}
216 222
217const QString& RecPart::Encoding()const 223const QString& RecPart::Encoding()const
218{ 224{
219 return m_encoding; 225 return m_encoding;
220} 226}
221 227
222void RecPart::setEncoding(const QString&encoding) 228void RecPart::setEncoding(const QString&encoding)
223{ 229{
224 m_encoding = encoding; 230 m_encoding = encoding;
225} 231}
226 232
227const QString& RecPart::Description()const 233const QString& RecPart::Description()const
228{ 234{
229 return m_description; 235 return m_description;
230} 236}
231 237
232void RecPart::setDescription(const QString&desc) 238void RecPart::setDescription(const QString&desc)
233{ 239{
234 m_description = desc; 240 m_description = desc;
235} 241}
236 242
237void RecPart::setParameters(const part_plist_t&list) 243void RecPart::setParameters(const part_plist_t&list)
238{ 244{
239 m_Parameters = list; 245 m_Parameters = list;
240} 246}
241 247
242const part_plist_t& RecPart::Parameters()const 248const part_plist_t& RecPart::Parameters()const
243{ 249{
244 return m_Parameters; 250 return m_Parameters;
245} 251}
246 252
247void RecPart::addParameter(const QString&key,const QString&value) 253void RecPart::addParameter(const QString&key,const QString&value)
248{ 254{
249 m_Parameters[key]=value; 255 m_Parameters[key]=value;
250} 256}
251 257
252const QString RecPart::searchParamter(const QString&key)const 258const QString RecPart::searchParamter(const QString&key)const
253{ 259{
254 QString value(""); 260 QString value("");
255 part_plist_t::ConstIterator it = m_Parameters.find(key); 261 part_plist_t::ConstIterator it = m_Parameters.find(key);
256 if (it != m_Parameters.end()) { 262 if (it != m_Parameters.end()) {
257 value = it.data(); 263 value = it.data();
258 } 264 }
259 return value; 265 return value;
260} 266}
261 267
262void RecPart::setPositionlist(const QValueList<int>&poslist) 268void RecPart::setPositionlist(const QValueList<int>&poslist)
263{ 269{
264 m_poslist = poslist; 270 m_poslist = poslist;
265} 271}
266 272
267const QValueList<int>& RecPart::Positionlist()const 273const QValueList<int>& RecPart::Positionlist()const
268{ 274{
269 return m_poslist; 275 return m_poslist;
270} 276}
271 277
272RecBody::RecBody() 278RecBody::RecBody()
273 : Opie::Core::ORefCount(),m_BodyText(),m_description(new RecPart()) 279 : Opie::Core::ORefCount(),m_BodyText(),m_description(new RecPart())
274{ 280{
275 m_PartsList.clear(); 281 m_PartsList.clear();
276} 282}
277 283
278RecBody::RecBody(const RecBody&old) 284RecBody::RecBody(const RecBody&old)
279 :Opie::Core::ORefCount(),m_BodyText(),m_PartsList(),m_description(new RecPart()) 285 :Opie::Core::ORefCount(),m_BodyText(),m_PartsList(),m_description(new RecPart())
280{ 286{
281 m_BodyText = old.m_BodyText; 287 m_BodyText = old.m_BodyText;
282 m_PartsList = old.m_PartsList; 288 m_PartsList = old.m_PartsList;
283 m_description = old.m_description; 289 m_description = old.m_description;
284 // odebug << "Recbody copy constructor" << oendl; 290 // odebug << "Recbody copy constructor" << oendl;
285} 291}
286 292
287RecBody::~RecBody() 293RecBody::~RecBody()
288{ 294{
289} 295}
290 296
291void RecBody::setBodytext(const QString&bodyText) 297void RecBody::setBodytext(const QString&bodyText)
292{ 298{
293 m_BodyText = bodyText; 299 m_BodyText = bodyText;
294} 300}
295 301
296const QString& RecBody::Bodytext()const 302const QString& RecBody::Bodytext()const
297{ 303{
298 return m_BodyText; 304 return m_BodyText;
299} 305}
300 306
301void RecBody::setParts(const QValueList<RecPartP>&parts) 307void RecBody::setParts(const QValueList<RecPartP>&parts)
302{ 308{
303 m_PartsList.clear(); 309 m_PartsList.clear();
304 m_PartsList = parts; 310 m_PartsList = parts;
305} 311}
306 312
307const QValueList<RecPartP>& RecBody::Parts()const 313const QValueList<RecPartP>& RecBody::Parts()const
308{ 314{
309 return m_PartsList; 315 return m_PartsList;
310} 316}
311 317
312void RecBody::addPart(const RecPartP& part) 318void RecBody::addPart(const RecPartP& part)
313{ 319{
314 m_PartsList.append(part); 320 m_PartsList.append(part);
315} 321}
316 322
317void RecBody::setDescription(const RecPartP&des) 323void RecBody::setDescription(const RecPartP&des)
318{ 324{
319 m_description = des; 325 m_description = des;
320} 326}
321 327
322const RecPartP& RecBody::Description()const 328const RecPartP& RecBody::Description()const
323{ 329{
324 return m_description; 330 return m_description;
325} 331}
326 332
327/* handling encoded content */ 333/* handling encoded content */
328encodedString::encodedString() 334encodedString::encodedString()
329{ 335{
330 init(); 336 init();
331} 337}
332 338
333encodedString::encodedString(const char*nContent,unsigned int nSize) 339encodedString::encodedString(const char*nContent,unsigned int nSize)
334{ 340{
335 init(); 341 init();
336 setContent(nContent,nSize); 342 setContent(nContent,nSize);
337} 343}
338 344
339encodedString::encodedString(char*nContent,unsigned int nSize) 345encodedString::encodedString(char*nContent,unsigned int nSize)
340{ 346{
341 init(); 347 init();
342 setContent(nContent,nSize); 348 setContent(nContent,nSize);
343} 349}
344 350
345encodedString::encodedString(const encodedString&old) 351encodedString::encodedString(const encodedString&old)
346{ 352{
347 init(); 353 init();
348 copy_old(old); 354 copy_old(old);
349 // odebug << "encodedeString: copy constructor!" << oendl; 355 // odebug << "encodedeString: copy constructor!" << oendl;
350} 356}
351 357
352encodedString& encodedString::operator=(const encodedString&old) 358encodedString& encodedString::operator=(const encodedString&old)
353{ 359{
354 init(); 360 init();
355 copy_old(old); 361 copy_old(old);
356 // odebug << "encodedString: assign operator!" << oendl; 362 // odebug << "encodedString: assign operator!" << oendl;
357 return *this; 363 return *this;
358} 364}
359 365
360encodedString::~encodedString() 366encodedString::~encodedString()
361{ 367{
362 clean(); 368 clean();
363} 369}
364 370
365void encodedString::init() 371void encodedString::init()
366{ 372{
367 content = 0; 373 content = 0;
368 size = 0; 374 size = 0;
369} 375}
370 376
371void encodedString::clean() 377void encodedString::clean()
372{ 378{
373 if (content) { 379 if (content) {
374 free(content); 380 free(content);
375 } 381 }
376 content = 0; 382 content = 0;
377 size = 0; 383 size = 0;
378} 384}
379 385
380void encodedString::copy_old(const encodedString&old) 386void encodedString::copy_old(const encodedString&old)
381{ 387{
382 clean(); 388 clean();
383 if (old.size>0 && old.content) { 389 if (old.size>0 && old.content) {
384 content = (char*)malloc(old.size*sizeof(char)); 390 content = (char*)malloc(old.size*sizeof(char));
385 memcpy(content,old.content,size); 391 memcpy(content,old.content,size);
386 size = old.size; 392 size = old.size;
387 } 393 }
388} 394}
389 395
390const char*encodedString::Content()const 396const char*encodedString::Content()const
391{ 397{
392 return content; 398 return content;
393} 399}
394 400
395const int encodedString::Length()const 401const int encodedString::Length()const
396{ 402{
397 return size; 403 return size;
398} 404}
399 405
400void encodedString::setContent(const char*nContent,int nSize) 406void encodedString::setContent(const char*nContent,int nSize)
401{ 407{
402 if (nSize>0 && nContent) { 408 if (nSize>0 && nContent) {
403 content = (char*)malloc(nSize*sizeof(char)); 409 content = (char*)malloc(nSize*sizeof(char));
404 memcpy(content,nContent,nSize); 410 memcpy(content,nContent,nSize);
405 size = nSize; 411 size = nSize;
406 } 412 }
407} 413}
408 414
409void encodedString::setContent(char*nContent,int nSize) 415void encodedString::setContent(char*nContent,int nSize)
410{ 416{
411 content = nContent; 417 content = nContent;
412 size = nSize; 418 size = nSize;
413} 419}
414 420
415folderStat&folderStat::operator=(const folderStat&old) 421folderStat&folderStat::operator=(const folderStat&old)
416{ 422{
417 message_count = old.message_count; 423 message_count = old.message_count;
418 message_unseen = old.message_unseen; 424 message_unseen = old.message_unseen;
419 message_recent = old.message_recent; 425 message_recent = old.message_recent;
420 return *this; 426 return *this;
421} 427}
422 428
diff --git a/kmicromail/libmailwrapper/mailtypes.h b/kmicromail/libmailwrapper/mailtypes.h
index 020278d..c1c1a74 100644
--- a/kmicromail/libmailwrapper/mailtypes.h
+++ b/kmicromail/libmailwrapper/mailtypes.h
@@ -1,209 +1,211 @@
1#ifndef __MAIL_TYPES_H 1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H 2#define __MAIL_TYPES_H
3 3
4#define FLAG_ANSWERED 0 4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1 5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2 6#define FLAG_DELETED 2
7#define FLAG_SEEN 3 7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4 8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5 9#define FLAG_RECENT 5
10 10
11#include <opie2/osmartpointer.h> 11#include <opie2/osmartpointer.h>
12 12
13#include <qbitarray.h> 13#include <qbitarray.h>
14#include <qstring.h> 14#include <qstring.h>
15#include <qstringlist.h> 15#include <qstringlist.h>
16#include <qmap.h> 16#include <qmap.h>
17#include <qvaluelist.h> 17#include <qvaluelist.h>
18 18
19class AbstractMail; 19class AbstractMail;
20/* a class to describe mails in a mailbox */ 20/* a class to describe mails in a mailbox */
21/* Attention! 21/* Attention!
22 From programmers point of view it would make sense to 22 From programmers point of view it would make sense to
23 store the mail body into this class, too. 23 store the mail body into this class, too.
24 But: not from the point of view of the device. 24 But: not from the point of view of the device.
25 Mailbodies can be real large. So we request them when 25 Mailbodies can be real large. So we request them when
26 needed from the mail-wrapper class direct from the server itself 26 needed from the mail-wrapper class direct from the server itself
27 (imap) or from a file-based cache (pop3?) 27 (imap) or from a file-based cache (pop3?)
28 So there is no interface "const QString&body()" but you should 28 So there is no interface "const QString&body()" but you should
29 make a request to the mailwrapper with this class as parameter to 29 make a request to the mailwrapper with this class as parameter to
30 get the body. Same words for the attachments. 30 get the body. Same words for the attachments.
31*/ 31*/
32class RecMail:public Opie::Core::ORefCount 32class RecMail:public Opie::Core::ORefCount
33{ 33{
34public: 34public:
35 RecMail(); 35 RecMail();
36 RecMail(const RecMail&old); 36 RecMail(const RecMail&old);
37 virtual ~RecMail(); 37 virtual ~RecMail();
38 bool isEqual( RecMail* r1 ); 38 bool isEqual( RecMail* r1 );
39 39
40 const unsigned int getNumber()const{return msg_number;} 40 const unsigned int getNumber()const{return msg_number;}
41 void setNumber(unsigned int number){msg_number=number;} 41 void setNumber(unsigned int number){msg_number=number;}
42 const QString&getDate()const{ return date; } 42 const QString&getDate()const{ return date; }
43 void setDate( const QString&a ) { date = a; } 43 void setDate( const QString&a ) { date = a; }
44 const QString&getIsoDate()const{ return isodate; } 44 const QString&getIsoDate()const{ return isodate; }
45 void setIsoDate( const QString&a ) { isodate = a; } 45 void setIsoDate( const QString&a ) { isodate = a; }
46 const QString&getFrom()const{ return from; } 46 const QString&getFrom()const{ return from; }
47 void setFrom( const QString&a ) { from = a; } 47 void setFrom( const QString&a ) { from = a; }
48 const QString&getSubject()const { return subject; } 48 const QString&getSubject()const { return subject; }
49 void setSubject( const QString&s ) { subject = s; } 49 void setSubject( const QString&s ) { subject = s; }
50 const QString&getMbox()const{return mbox;} 50 const QString&getMbox()const{return mbox;}
51 void setMbox(const QString&box){mbox = box;} 51 void setMbox(const QString&box){mbox = box;}
52 void setMsgid(const QString&id){msg_id=id;} 52 void setMsgid(const QString&id){msg_id=id;}
53 const QString&Msgid()const{return msg_id;} 53 const QString&Msgid()const{return msg_id;}
54 void setReplyto(const QString&reply){replyto=reply;} 54 void setReplyto(const QString&reply){replyto=reply;}
55 const QString&Replyto()const{return replyto;} 55 const QString&Replyto()const{return replyto;}
56 void setMsgsize(unsigned int size){msg_size = size;} 56 void setMsgsize(unsigned int size){msg_size = size;}
57 const unsigned int Msgsize()const{return msg_size;} 57 const unsigned int Msgsize()const{return msg_size;}
58 58
59 59
60 void setTo(const QStringList&list); 60 void setTo(const QStringList&list);
61 const QStringList&To()const; 61 const QStringList&To()const;
62 void setCC(const QStringList&list); 62 void setCC(const QStringList&list);
63 const QStringList&CC()const; 63 const QStringList&CC()const;
64 void setBcc(const QStringList&list); 64 void setBcc(const QStringList&list);
65 const QStringList&Bcc()const; 65 const QStringList&Bcc()const;
66 void setInreply(const QStringList&list); 66 void setInreply(const QStringList&list);
67 const QStringList&Inreply()const; 67 const QStringList&Inreply()const;
68 void setReferences(const QStringList&list); 68 void setReferences(const QStringList&list);
69 const QStringList&References()const; 69 const QStringList&References()const;
70 70
71 const QBitArray&getFlags()const{return msg_flags;} 71 const QBitArray&getFlags()const{return msg_flags;}
72 void setFlags(const QBitArray&flags){msg_flags = flags;} 72 void setFlags(const QBitArray&flags){msg_flags = flags;}
73 73
74 void setWrapper(AbstractMail*wrapper); 74 void setWrapper(AbstractMail*wrapper);
75 AbstractMail* Wrapper(); 75 AbstractMail* Wrapper();
76 // public for debugging
77 QString subject,date,isodate,from,mbox,msg_id,replyto;
76 78
77protected: 79protected:
78 QString subject,date,isodate,from,mbox,msg_id,replyto; 80 //QString subject,date,isodate,from,mbox,msg_id,replyto;
79 unsigned int msg_number,msg_size; 81 unsigned int msg_number,msg_size;
80 QBitArray msg_flags; 82 QBitArray msg_flags;
81 QStringList to,cc,bcc,in_reply_to,references; 83 QStringList to,cc,bcc,in_reply_to,references;
82 AbstractMail*wrapper; 84 AbstractMail*wrapper;
83 void init(); 85 void init();
84 void copy_old(const RecMail&old); 86 void copy_old(const RecMail&old);
85}; 87};
86 88
87typedef Opie::Core::OSmartPointer<RecMail> RecMailP; 89typedef Opie::Core::OSmartPointer<RecMail> RecMailP;
88typedef QMap<QString,QString> part_plist_t; 90typedef QMap<QString,QString> part_plist_t;
89 91
90class RecPart:public Opie::Core::ORefCount 92class RecPart:public Opie::Core::ORefCount
91{ 93{
92protected: 94protected:
93 QString m_type,m_subtype,m_identifier,m_encoding,m_description; 95 QString m_type,m_subtype,m_identifier,m_encoding,m_description;
94 unsigned int m_lines,m_size; 96 unsigned int m_lines,m_size;
95 part_plist_t m_Parameters; 97 part_plist_t m_Parameters;
96 /* describes the position in the mail */ 98 /* describes the position in the mail */
97 QValueList<int> m_poslist; 99 QValueList<int> m_poslist;
98 100
99public: 101public:
100 RecPart(); 102 RecPart();
101 RecPart(const RecPart&); 103 RecPart(const RecPart&);
102 virtual ~RecPart(); 104 virtual ~RecPart();
103 105
104 const QString&Type()const; 106 const QString&Type()const;
105 void setType(const QString&type); 107 void setType(const QString&type);
106 const QString&Subtype()const; 108 const QString&Subtype()const;
107 void setSubtype(const QString&subtype); 109 void setSubtype(const QString&subtype);
108 const QString&Identifier()const; 110 const QString&Identifier()const;
109 void setIdentifier(const QString&identifier); 111 void setIdentifier(const QString&identifier);
110 const QString&Encoding()const; 112 const QString&Encoding()const;
111 void setEncoding(const QString&encoding); 113 void setEncoding(const QString&encoding);
112 const QString&Description()const; 114 const QString&Description()const;
113 void setDescription(const QString&desc); 115 void setDescription(const QString&desc);
114 void setLines(unsigned int lines); 116 void setLines(unsigned int lines);
115 const unsigned int Lines()const; 117 const unsigned int Lines()const;
116 void setSize(unsigned int size); 118 void setSize(unsigned int size);
117 const unsigned int Size()const; 119 const unsigned int Size()const;
118 120
119 121
120 void setParameters(const part_plist_t&list); 122 void setParameters(const part_plist_t&list);
121 const part_plist_t&Parameters()const; 123 const part_plist_t&Parameters()const;
122 void addParameter(const QString&key,const QString&value); 124 void addParameter(const QString&key,const QString&value);
123 const QString searchParamter(const QString&key)const; 125 const QString searchParamter(const QString&key)const;
124 void setPositionlist(const QValueList<int>&poslist); 126 void setPositionlist(const QValueList<int>&poslist);
125 const QValueList<int>& Positionlist()const; 127 const QValueList<int>& Positionlist()const;
126}; 128};
127 129
128typedef Opie::Core::OSmartPointer<RecPart> RecPartP; 130typedef Opie::Core::OSmartPointer<RecPart> RecPartP;
129 131
130class RecBody:public Opie::Core::ORefCount 132class RecBody:public Opie::Core::ORefCount
131{ 133{
132protected: 134protected:
133 QString m_BodyText; 135 QString m_BodyText;
134 QValueList<RecPartP> m_PartsList; 136 QValueList<RecPartP> m_PartsList;
135 RecPartP m_description; 137 RecPartP m_description;
136 138
137public: 139public:
138 RecBody(); 140 RecBody();
139 RecBody(const RecBody&old); 141 RecBody(const RecBody&old);
140 virtual ~RecBody(); 142 virtual ~RecBody();
141 void setBodytext(const QString&); 143 void setBodytext(const QString&);
142 const QString& Bodytext()const; 144 const QString& Bodytext()const;
143 145
144 void setDescription(const RecPartP&des); 146 void setDescription(const RecPartP&des);
145 const RecPartP& Description()const; 147 const RecPartP& Description()const;
146 148
147 void setParts(const QValueList<RecPartP>&parts); 149 void setParts(const QValueList<RecPartP>&parts);
148 const QValueList<RecPartP>& Parts()const; 150 const QValueList<RecPartP>& Parts()const;
149 void addPart(const RecPartP&part); 151 void addPart(const RecPartP&part);
150}; 152};
151 153
152typedef Opie::Core::OSmartPointer<RecBody> RecBodyP; 154typedef Opie::Core::OSmartPointer<RecBody> RecBodyP;
153 155
154class encodedString 156class encodedString
155{ 157{
156public: 158public:
157 encodedString(); 159 encodedString();
158 /* 160 /*
159 creates an new content string. 161 creates an new content string.
160 it makes a deep copy of it! 162 it makes a deep copy of it!
161 */ 163 */
162 encodedString(const char*nContent,unsigned int length); 164 encodedString(const char*nContent,unsigned int length);
163 /* 165 /*
164 Take over the nContent. Means: it will just copy the pointer, not the content. 166 Take over the nContent. Means: it will just copy the pointer, not the content.
165 so make sure: No one else frees the string, the string has allocated with 167 so make sure: No one else frees the string, the string has allocated with
166 malloc for compatibility with c-based libs 168 malloc for compatibility with c-based libs
167 */ 169 */
168 encodedString(char*nContent,unsigned int nSize); 170 encodedString(char*nContent,unsigned int nSize);
169 /* copy construkor - makes ALWAYS a deep copy!!!! */ 171 /* copy construkor - makes ALWAYS a deep copy!!!! */
170 encodedString(const encodedString&old); 172 encodedString(const encodedString&old);
171 /* assign operator - makes ALWAYS a deep copy!!!! */ 173 /* assign operator - makes ALWAYS a deep copy!!!! */
172 encodedString& operator=(const encodedString&old); 174 encodedString& operator=(const encodedString&old);
173 /* destructor - cleans the content */ 175 /* destructor - cleans the content */
174 virtual ~encodedString(); 176 virtual ~encodedString();
175 177
176 /* returns a pointer to the content - do not delete yoursel! */ 178 /* returns a pointer to the content - do not delete yoursel! */
177 const char*Content()const; 179 const char*Content()const;
178 /* returns the lengths of the content 'cause it must not be a null-terminated string! */ 180 /* returns the lengths of the content 'cause it must not be a null-terminated string! */
179 const int Length()const; 181 const int Length()const;
180 182
181 /* 183 /*
182 makes a deep copy of nContent! 184 makes a deep copy of nContent!
183 */ 185 */
184 void setContent(const char*nContent,int nSize); 186 void setContent(const char*nContent,int nSize);
185 /* 187 /*
186 Take over the nContent. Means: it will just copy the pointer, not the content. 188 Take over the nContent. Means: it will just copy the pointer, not the content.
187 so make sure: No one else frees the string, the string has allocated with 189 so make sure: No one else frees the string, the string has allocated with
188 malloc for compatibility with c-based libs 190 malloc for compatibility with c-based libs
189 */ 191 */
190 void setContent(char*nContent,int nSize); 192 void setContent(char*nContent,int nSize);
191 193
192protected: 194protected:
193 char * content; 195 char * content;
194 unsigned int size; 196 unsigned int size;
195 197
196 void init(); 198 void init();
197 void copy_old(const encodedString&old); 199 void copy_old(const encodedString&old);
198 void clean(); 200 void clean();
199}; 201};
200 202
201struct folderStat 203struct folderStat
202{ 204{
203 unsigned int message_count; 205 unsigned int message_count;
204 unsigned int message_unseen; 206 unsigned int message_unseen;
205 unsigned int message_recent; 207 unsigned int message_recent;
206 folderStat&operator=(const folderStat&old); 208 folderStat&operator=(const folderStat&old);
207}; 209};
208 210
209#endif 211#endif
diff --git a/kmicromail/opiemail.cpp b/kmicromail/opiemail.cpp
index 7ccfb65..3cbac8e 100644
--- a/kmicromail/opiemail.cpp
+++ b/kmicromail/opiemail.cpp
@@ -1,465 +1,468 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2// CHANGED 2004-08-06 Lutz Rogowski 2// CHANGED 2004-08-06 Lutz Rogowski
3 3
4#include "settingsdialog.h" 4#include "settingsdialog.h"
5#include "opiemail.h" 5#include "opiemail.h"
6#include "editaccounts.h" 6#include "editaccounts.h"
7#include "composemail.h" 7#include "composemail.h"
8#include "mailistviewitem.h" 8#include "mailistviewitem.h"
9#include "viewmail.h" 9#include "viewmail.h"
10#include "selectstore.h" 10#include "selectstore.h"
11#include "selectsmtp.h" 11#include "selectsmtp.h"
12#include "accountitem.h" 12#include "accountitem.h"
13#include "koprefsdialog.h" 13#include "koprefsdialog.h"
14 14
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16#include <qtimer.h> 16#include <qtimer.h>
17#include <libkdepim/externalapphandler.h> 17#include <libkdepim/externalapphandler.h>
18 18
19#include <qpe/qpeapplication.h> 19#include <qpe/qpeapplication.h>
20#include <libmailwrapper/smtpwrapper.h> 20#include <libmailwrapper/smtpwrapper.h>
21#include <libmailwrapper/mailtypes.h> 21#include <libmailwrapper/mailtypes.h>
22#include <libmailwrapper/abstractmail.h> 22#include <libmailwrapper/abstractmail.h>
23/* OPIE */ 23/* OPIE */
24//#include <qpe/resource.h> 24//#include <qpe/resource.h>
25//#include <qpe/qpeapplication.h> 25//#include <qpe/qpeapplication.h>
26 26
27/* QT */ 27/* QT */
28 28
29//using namespace Opie::Core; 29//using namespace Opie::Core;
30 30
31OpieMail::OpieMail( QWidget *parent, const char *name ) 31OpieMail::OpieMail( QWidget *parent, const char *name )
32 : MainWindow( parent, name) //, WStyle_ContextHelp ) 32 : MainWindow( parent, name) //, WStyle_ContextHelp )
33{ 33{
34 settings = new Settings(); 34 settings = new Settings();
35 35
36 folderView->populate( settings->getAccounts() ); 36 folderView->populate( settings->getAccounts() );
37 37
38} 38}
39 39
40OpieMail::~OpieMail() 40OpieMail::~OpieMail()
41{ 41{
42 if (settings) delete settings; 42 if (settings) delete settings;
43} 43}
44 44
45void OpieMail::appMessage(const QCString &msg, const QByteArray &data) 45void OpieMail::appMessage(const QCString &msg, const QByteArray &data)
46{ 46{
47 47
48} 48}
49#include <stdlib.h> 49#include <stdlib.h>
50void OpieMail::message(const QCString &msg, const QByteArray &data) 50void OpieMail::message(const QCString &msg, const QByteArray &data)
51{ 51{
52 // copied from old mail2 52 // copied from old mail2
53 static int ii = 0; 53 static int ii = 0;
54 //qDebug("QCOP CALL ############################# %d ", ii); 54 //qDebug("QCOP CALL ############################# %d ", ii);
55 //QString mess ( msg ); 55 //QString mess ( msg );
56 //qDebug("Message = %s ",mess.latin1()); 56 //qDebug("Message = %s ",mess.latin1());
57 ++ii; 57 ++ii;
58 //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this); 58 //qDebug("KM:appMessage %d *%s* %x", ii, msg.data(), this);
59 59
60 mPendingEmail = QString::null; 60 mPendingEmail = QString::null;
61 mPendingName = QString::null; 61 mPendingName = QString::null;
62 if (msg == "writeMail(QString,QString)") 62 if (msg == "writeMail(QString,QString)")
63 { 63 {
64 //qDebug("writeMail(QString,QString) "); 64 //qDebug("writeMail(QString,QString) ");
65 QDataStream stream(data,IO_ReadOnly); 65 QDataStream stream(data,IO_ReadOnly);
66 stream >> mPendingName >> mPendingEmail; 66 stream >> mPendingName >> mPendingEmail;
67 // removing the whitespaces at beginning and end is needed! 67 // removing the whitespaces at beginning and end is needed!
68 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 68 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
69 } 69 }
70 else if (msg == "newMail()") 70 else if (msg == "newMail()")
71 { 71 {
72 //qDebug("slotComposeMail() "); 72 //qDebug("slotComposeMail() ");
73 // we cannot call slotComposeMail(); directly, because may be executing a QCOP call 73 // we cannot call slotComposeMail(); directly, because may be executing a QCOP call
74 // and a QCOP call does not like a processevents in his execution 74 // and a QCOP call does not like a processevents in his execution
75 // with the Qtimer we call slotComposeMail() after we reached the main event loop 75 // with the Qtimer we call slotComposeMail() after we reached the main event loop
76 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 76 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
77 // slotComposeMail(); 77 // slotComposeMail();
78 } 78 }
79 else if (msg == "newMail(QString)") 79 else if (msg == "newMail(QString)")
80 { 80 {
81 //qDebug(" newMail(QString)"); 81 //qDebug(" newMail(QString)");
82 QDataStream stream(data,IO_ReadOnly); 82 QDataStream stream(data,IO_ReadOnly);
83 stream >> mPendingName; 83 stream >> mPendingName;
84 // the format is 84 // the format is
85 // NAME <EMAIL>:SUBJECT 85 // NAME <EMAIL>:SUBJECT
86 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) ); 86 QTimer::singleShot ( 50, this, SLOT(slotComposeMail() ) );
87 } else { 87 } else {
88 mPendingData = data; 88 mPendingData = data;
89 mPendingMessage = msg; 89 mPendingMessage = msg;
90 QTimer::singleShot ( 50, this, SLOT(slotExtAppHandler() ) ); 90 QTimer::singleShot ( 50, this, SLOT(slotExtAppHandler() ) );
91 } 91 }
92 92
93 //qDebug("END OpieMail::message "); 93 //qDebug("END OpieMail::message ");
94} 94}
95void OpieMail::slotExtAppHandler() 95void OpieMail::slotExtAppHandler()
96{ 96{
97 ExternalAppHandler::instance()->appMessage ( mPendingMessage, mPendingData ); 97 ExternalAppHandler::instance()->appMessage ( mPendingMessage, mPendingData );
98} 98}
99void OpieMail::slotwriteMail2(const QString& namemail ) 99void OpieMail::slotwriteMail2(const QString& namemail )
100{ 100{
101 //qDebug("OpieMail::slotwriteMail2 "); 101 //qDebug("OpieMail::slotwriteMail2 ");
102 //qApp->processEvents(); 102 //qApp->processEvents();
103 ComposeMail compose( settings, this, 0, true ); 103 ComposeMail compose( settings, this, 0, true );
104 if ( !namemail.isEmpty() ) { 104 if ( !namemail.isEmpty() ) {
105 QString to = namemail; 105 QString to = namemail;
106 if ( namemail.find( " <") > 1 ) { 106 if ( namemail.find( " <") > 1 ) {
107 to = "\"" +to.replace( QRegExp( " <"), "\" <") ; 107 to = "\"" +to.replace( QRegExp( " <"), "\" <") ;
108 } else 108 } else
109 if ( namemail.find( "<") > 1 ) { 109 if ( namemail.find( "<") > 1 ) {
110 to = "\"" +to.replace( QRegExp( "<"), "\" <") ; 110 to = "\"" +to.replace( QRegExp( "<"), "\" <") ;
111 } 111 }
112 int sub = to.find( ">:"); 112 int sub = to.find( ">:");
113 if ( sub > 0 ) { 113 if ( sub > 0 ) {
114 compose.setTo( to.left(sub+1) ); 114 compose.setTo( to.left(sub+1) );
115 compose.setSubject( to.mid(sub+2) ); 115 compose.setSubject( to.mid(sub+2) );
116 } else 116 } else
117 compose.setTo( to ); 117 compose.setTo( to );
118 } 118 }
119 compose.slotAdjustColumns(); 119 compose.slotAdjustColumns();
120 compose.showMaximized(); 120 compose.showMaximized();
121 compose.exec(); 121 compose.exec();
122 raise(); 122 raise();
123 //qDebug("retttich "); 123 //qDebug("retttich ");
124} 124}
125void OpieMail::slotwriteMail(const QString&name,const QString&email) 125void OpieMail::slotwriteMail(const QString&name,const QString&email)
126{ 126{
127 // qDebug("OpieMail::slotwriteMail "); 127 // qDebug("OpieMail::slotwriteMail ");
128 ComposeMail compose( settings, this, 0, true ); 128 ComposeMail compose( settings, this, 0, true );
129 if (!email.isEmpty()) 129 if (!email.isEmpty())
130 { 130 {
131 if (!name.isEmpty()) 131 if (!name.isEmpty())
132 { 132 {
133 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); 133 compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">");
134 } 134 }
135 else 135 else
136 { 136 {
137 compose.setTo(email); 137 compose.setTo(email);
138 } 138 }
139 } 139 }
140 compose.slotAdjustColumns(); 140 compose.slotAdjustColumns();
141 compose.showMaximized(); 141 compose.showMaximized();
142 compose.exec(); 142 compose.exec();
143 raise(); 143 raise();
144} 144}
145 145
146void OpieMail::slotComposeMail() 146void OpieMail::slotComposeMail()
147{ 147{
148 if ( mPendingEmail == QString::null && mPendingName == QString::null) 148 if ( mPendingEmail == QString::null && mPendingName == QString::null)
149 slotwriteMail2( QString () ); 149 slotwriteMail2( QString () );
150 else { 150 else {
151 if ( mPendingEmail == QString::null ) 151 if ( mPendingEmail == QString::null )
152 slotwriteMail2( mPendingName ); 152 slotwriteMail2( mPendingName );
153 else 153 else
154 slotwriteMail( mPendingName, mPendingEmail ); 154 slotwriteMail( mPendingName, mPendingEmail );
155 } 155 }
156 //slotwriteMail(0l,0l); 156 //slotwriteMail(0l,0l);
157} 157}
158 158
159void OpieMail::slotSendQueued() 159void OpieMail::slotSendQueued()
160{ 160{
161 SMTPaccount *smtp = 0; 161 SMTPaccount *smtp = 0;
162 162
163 QList<Account> list = settings->getAccounts(); 163 QList<Account> list = settings->getAccounts();
164 QList<SMTPaccount> smtpList; 164 QList<SMTPaccount> smtpList;
165 smtpList.setAutoDelete(false); 165 smtpList.setAutoDelete(false);
166 Account *it; 166 Account *it;
167 for ( it = list.first(); it; it = list.next() ) 167 for ( it = list.first(); it; it = list.next() )
168 { 168 {
169 if ( it->getType() == MAILLIB::A_SMTP ) 169 if ( it->getType() == MAILLIB::A_SMTP )
170 { 170 {
171 smtp = static_cast<SMTPaccount *>(it); 171 smtp = static_cast<SMTPaccount *>(it);
172 smtpList.append(smtp); 172 smtpList.append(smtp);
173 } 173 }
174 } 174 }
175 if (smtpList.count()==0) 175 if (smtpList.count()==0)
176 { 176 {
177 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first!\n")); 177 QMessageBox::information(0,tr("Info"),tr("Define a smtp account first!\n"));
178 return; 178 return;
179 } 179 }
180 if (smtpList.count()==1) 180 if (smtpList.count()==1)
181 { 181 {
182 smtp = smtpList.at(0); 182 smtp = smtpList.at(0);
183 } 183 }
184 else 184 else
185 { 185 {
186 smtp = 0; 186 smtp = 0;
187 selectsmtp selsmtp; 187 selectsmtp selsmtp;
188 selsmtp.setSelectionlist(&smtpList); 188 selsmtp.setSelectionlist(&smtpList);
189 selsmtp.showMaximized(); 189 selsmtp.showMaximized();
190 if ( selsmtp.exec() == QDialog::Accepted ) 190 if ( selsmtp.exec() == QDialog::Accepted )
191 { 191 {
192 smtp = selsmtp.selected_smtp(); 192 smtp = selsmtp.selected_smtp();
193 } 193 }
194 } 194 }
195 if (smtp) 195 if (smtp)
196 { 196 {
197 SMTPwrapper * wrap = new SMTPwrapper(smtp); 197 SMTPwrapper * wrap = new SMTPwrapper(smtp);
198 if ( wrap->flushOutbox() ) 198 if ( wrap->flushOutbox() )
199 { 199 {
200 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); 200 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed"));
201 } 201 }
202 delete wrap; 202 delete wrap;
203 } 203 }
204} 204}
205 205
206void OpieMail::slotSearchMails() 206void OpieMail::slotSearchMails()
207{ 207{
208 qDebug("OpieMail::slotSearchMails():not implemented "); 208 qDebug("OpieMail::slotSearchMails():not implemented ");
209} 209}
210 210
211void OpieMail::slotEditSettings() 211void OpieMail::slotEditSettings()
212{ 212{
213#if 0 213#if 0
214 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); 214 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp );
215 settingsDialog.showMaximized(); 215 settingsDialog.showMaximized();
216 settingsDialog.exec(); 216 settingsDialog.exec();
217#endif 217#endif
218 KOPrefsDialog settingsDialog( this, "koprefs", true ); 218 KOPrefsDialog settingsDialog( this, "koprefs", true );
219 settingsDialog.showMaximized(); 219 settingsDialog.showMaximized();
220 settingsDialog.exec(); 220 settingsDialog.exec();
221} 221}
222 222
223void OpieMail::slotEditAccounts() 223void OpieMail::slotEditAccounts()
224{ 224{
225 EditAccounts eaDialog( settings, this, 0, true ); 225 EditAccounts eaDialog( settings, this, 0, true );
226 eaDialog.slotAdjustColumns(); 226 eaDialog.slotAdjustColumns();
227 eaDialog.showMaximized(); 227 eaDialog.showMaximized();
228 eaDialog.exec(); 228 eaDialog.exec();
229 if ( settings ) delete settings; 229 if ( settings ) delete settings;
230 settings = new Settings(); 230 settings = new Settings();
231 231
232 folderView->populate( settings->getAccounts() ); 232 folderView->populate( settings->getAccounts() );
233} 233}
234 234
235void OpieMail::displayMail() 235void OpieMail::displayMail()
236{ 236{
237 QListViewItem*item = mailView->currentItem(); 237 QListViewItem*item = mailView->currentItem();
238 if (!item) return; 238 if (!item) return;
239 RecMailP mail = ((MailListViewItem*)item)->data(); 239 RecMailP mail = ((MailListViewItem*)item)->data();
240 RecBodyP body = folderView->fetchBody(mail); 240 RecBodyP body = folderView->fetchBody(mail);
241 ViewMail readMail( this,"", Qt::WType_Modal ); 241 ViewMail readMail( this,"", Qt::WType_Modal );
242 readMail.setBody( body ); 242 readMail.setBody( body );
243 readMail.setMail( mail ); 243 readMail.setMail( mail );
244 readMail.showMaximized(); 244 readMail.showMaximized();
245 readMail.exec(); 245 readMail.exec();
246 246
247 if ( readMail.deleted ) 247 if ( readMail.deleted )
248 { 248 {
249 folderView->refreshCurrent(); 249 folderView->refreshCurrent();
250 } 250 }
251 else 251 else
252 { 252 {
253 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() ); 253 ( (MailListViewItem*)item )->setPixmap( 0, QPixmap() );
254 } 254 }
255} 255}
256void OpieMail::slotGetAllMail() 256void OpieMail::slotGetAllMail()
257{ 257{
258 QListViewItem * item = folderView->firstChild(); 258 QListViewItem * item = folderView->firstChild();
259 while ( item ){ 259 while ( item ){
260 ((AccountViewItem *)item)->contextMenuSelected( 101 ); 260 ((AccountViewItem *)item)->contextMenuSelected( 101 );
261 item = item->nextSibling (); 261 item = item->nextSibling ();
262 } 262 }
263} 263}
264void OpieMail::slotGetMail() 264void OpieMail::slotGetMail()
265{ 265{
266 QListViewItem * item = folderView->currentItem(); 266 QListViewItem * item = folderView->currentItem();
267 if ( ! item ) return; 267 if ( ! item ) return;
268 while ( item->parent () ) 268 while ( item->parent () )
269 item = item->parent (); 269 item = item->parent ();
270 ((AccountViewItem *)item)->contextMenuSelected( 101 ); 270 ((AccountViewItem *)item)->contextMenuSelected( 101 );
271} 271}
272void OpieMail::slotDeleteMail() 272void OpieMail::slotDeleteMail()
273{ 273{
274 if (!mailView->currentItem()) return; 274 if (!mailView->currentItem()) return;
275 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 275 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
276 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 276 if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail->getFrom() + " - " + mail->getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
277 { 277 {
278 mail->Wrapper()->deleteMail( mail ); 278 mail->Wrapper()->deleteMail( mail );
279 folderView->refreshCurrent(); 279 folderView->refreshCurrent();
280 } 280 }
281} 281}
282void OpieMail::slotDeleteAllMail() 282void OpieMail::slotDeleteAllMail()
283{ 283{
284 284
285 QValueList<RecMailP> t; 285 QValueList<RecMailP> t;
286 if ( QMessageBox::warning(this, tr("Delete All Mails"), tr("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 286 if ( QMessageBox::warning(this, tr("Delete All Mails"), tr("Do you really want to delete\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
287 { 287 {
288 MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); 288 MailListViewItem* item = (MailListViewItem*)mailView->firstChild ();
289 while ( item ) { 289 while ( item ) {
290 if ( item->isSelected() ) { 290 if ( item->isSelected() ) {
291 t.append( item->data() ); 291 t.append( item->data() );
292 } 292 }
293 item = (MailListViewItem*)item->nextSibling(); 293 item = (MailListViewItem*)item->nextSibling();
294 } 294 }
295 } 295 }
296 else 296 else
297 return; 297 return;
298 if ( t.count() == 0 ) 298 if ( t.count() == 0 )
299 return; 299 return;
300 RecMailP mail = t.first(); 300 RecMailP mail = t.first();
301 mail->Wrapper()->deleteMailList(t); 301 mail->Wrapper()->deleteMailList(t);
302 folderView->refreshCurrent(); 302 folderView->refreshCurrent();
303 303
304 304
305} 305}
306void OpieMail::clearSelection() 306void OpieMail::clearSelection()
307{ 307{
308 mailView->clearSelection(); 308 mailView->clearSelection();
309 309
310} 310}
311 311
312void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int ) 312void OpieMail::mailHold(int button, QListViewItem *item,const QPoint&,int )
313{ 313{
314 if (!mailView->currentItem()) return; 314 if (!mailView->currentItem()) return;
315 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType(); 315 MAILLIB::ATYPE mailtype = ((MailListViewItem*)mailView->currentItem() )->wrapperType();
316 /* just the RIGHT button - or hold on pda */ 316 /* just the RIGHT button - or hold on pda */
317 if (button!=2) {return;} 317 if (button!=2) {return;}
318 if (!item) return; 318 if (!item) return;
319 QPopupMenu *m = new QPopupMenu(0); 319 QPopupMenu *m = new QPopupMenu(0);
320 if (m) 320 if (m)
321 { 321 {
322 if (mailtype==MAILLIB::A_NNTP) { 322 if (mailtype==MAILLIB::A_NNTP) {
323 m->insertItem(tr("Read this posting"),this,SLOT(displayMail())); 323 m->insertItem(tr("Read this posting"),this,SLOT(displayMail()));
324// m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail())); 324 m->insertItem(tr("Copy this posting"),this,SLOT(slotMoveCopyMail()));
325 m->insertSeparator();
326 m->insertItem(tr("Copy all selected postings"),this,SLOT(slotMoveCopyAllMail()));
327 m->insertItem(tr("Clear selection"),this,SLOT(clearSelection()));
325 } else { 328 } else {
326 if (folderView->currentisDraft()) { 329 if (folderView->currentisDraft()) {
327 m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail())); 330 m->insertItem(tr("Edit this mail"),this,SLOT(reEditMail()));
328 } 331 }
329 m->insertItem(tr("Read this mail"),this,SLOT(displayMail())); 332 m->insertItem(tr("Read this mail"),this,SLOT(displayMail()));
330 m->insertItem(tr("Move/Copy this mail"),this,SLOT(slotMoveCopyMail())); 333 m->insertItem(tr("Move/Copy this mail"),this,SLOT(slotMoveCopyMail()));
331 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail())); 334 m->insertItem(tr("Delete this mail"),this,SLOT(slotDeleteMail()));
332 m->insertSeparator(); 335 m->insertSeparator();
333 m->insertItem(tr("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail())); 336 m->insertItem(tr("Move/Copy all selected mail"),this,SLOT(slotMoveCopyAllMail()));
334 m->insertItem(tr("Delete all selected mails"),this,SLOT(slotDeleteAllMail())); 337 m->insertItem(tr("Delete all selected mails"),this,SLOT(slotDeleteAllMail()));
335 m->insertItem(tr("Clear selection"),this,SLOT(clearSelection())); 338 m->insertItem(tr("Clear selection"),this,SLOT(clearSelection()));
336 } 339 }
337 m->setFocus(); 340 m->setFocus();
338 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 341 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
339 delete m; 342 delete m;
340 } 343 }
341} 344}
342 345
343void OpieMail::slotShowFolders( bool show ) 346void OpieMail::slotShowFolders( bool show )
344{ 347{
345 if ( show && folderView->isHidden() ) 348 if ( show && folderView->isHidden() )
346 { 349 {
347 folderView->show(); 350 folderView->show();
348 } 351 }
349 else if ( !show && !folderView->isHidden() ) 352 else if ( !show && !folderView->isHidden() )
350 { 353 {
351 folderView->hide(); 354 folderView->hide();
352 } 355 }
353} 356}
354 357
355void OpieMail::refreshMailView(const QValueList<RecMailP>&list) 358void OpieMail::refreshMailView(const QValueList<RecMailP>&list)
356{ 359{
357 MailListViewItem*item = 0; 360 MailListViewItem*item = 0;
358 mailView->clear(); 361 mailView->clear();
359 362
360 QValueList<RecMailP>::ConstIterator it; 363 QValueList<RecMailP>::ConstIterator it;
361 for (it = list.begin(); it != list.end();++it) 364 for (it = list.begin(); it != list.end();++it)
362 { 365 {
363 item = new MailListViewItem(mailView,item); 366 item = new MailListViewItem(mailView,item);
364 item->storeData((*it)); 367 item->storeData((*it));
365 item->showEntry(); 368 item->showEntry();
366 } 369 }
367} 370}
368 371
369void OpieMail::mailLeftClicked( QListViewItem *item ) 372void OpieMail::mailLeftClicked( QListViewItem *item )
370{ 373{
371 mailView->clearSelection(); 374 mailView->clearSelection();
372 /* just LEFT button - or tap with stylus on pda */ 375 /* just LEFT button - or tap with stylus on pda */
373 //if (button!=1) return; 376 //if (button!=1) return;
374 if (!item) return; 377 if (!item) return;
375 if (folderView->currentisDraft()) { 378 if (folderView->currentisDraft()) {
376 reEditMail(); 379 reEditMail();
377 } else { 380 } else {
378 displayMail(); 381 displayMail();
379 } 382 }
380} 383}
381 384
382void OpieMail::slotMoveCopyMail() 385void OpieMail::slotMoveCopyMail()
383{ 386{
384 if (!mailView->currentItem()) return; 387 if (!mailView->currentItem()) return;
385 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data(); 388 RecMailP mail = ((MailListViewItem*)mailView->currentItem() )->data();
386 AbstractMail*targetMail = 0; 389 AbstractMail*targetMail = 0;
387 QString targetFolder = ""; 390 QString targetFolder = "";
388 Selectstore sels; 391 Selectstore sels;
389 folderView->setupFolderselect(&sels); 392 folderView->setupFolderselect(&sels);
390 if (!sels.exec()) return; 393 if (!sels.exec()) return;
391 targetMail = sels.currentMail(); 394 targetMail = sels.currentMail();
392 targetFolder = sels.currentFolder(); 395 targetFolder = sels.currentFolder();
393 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || 396 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
394 targetFolder.isEmpty()) 397 targetFolder.isEmpty())
395 { 398 {
396 return; 399 return;
397 } 400 }
398 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 401 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
399 { 402 {
400 QMessageBox::critical(0,tr("Error creating new Folder"), 403 QMessageBox::critical(0,tr("Error creating new Folder"),
401 tr("<center>Error while creating<br>new folder - breaking.</center>")); 404 tr("<center>Error while creating<br>new folder - breaking.</center>"));
402 return; 405 return;
403 } 406 }
404 sels.hide(); 407 sels.hide();
405 qApp->processEvents(); 408 qApp->processEvents();
406 // qDebug("hiding sels "); 409 // qDebug("hiding sels ");
407 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails()); 410 mail->Wrapper()->mvcpMail(mail,targetFolder,targetMail,sels.moveMails());
408 folderView->refreshCurrent(); 411 folderView->refreshCurrent();
409} 412}
410 413
411void OpieMail::slotMoveCopyAllMail() 414void OpieMail::slotMoveCopyAllMail()
412{ 415{
413 416
414 if (!mailView->currentItem()) return; 417 if (!mailView->currentItem()) return;
415 QValueList<RecMailP> t; 418 QValueList<RecMailP> t;
416 // if ( QMessageBox::warning(this, tr("Move/Copy all selected mails"), tr("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) 419 // if ( QMessageBox::warning(this, tr("Move/Copy all selected mails"), tr("Do you really want to copy/move\nall selected mails?" ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
417 { 420 {
418 MailListViewItem* item = (MailListViewItem*)mailView->firstChild (); 421 MailListViewItem* item = (MailListViewItem*)mailView->firstChild ();
419 while ( item ) { 422 while ( item ) {
420 if ( item->isSelected() ) { 423 if ( item->isSelected() ) {
421 t.append( item->data() ); 424 t.append( item->data() );
422 } 425 }
423 item = (MailListViewItem*)item->nextSibling(); 426 item = (MailListViewItem*)item->nextSibling();
424 } 427 }
425 } 428 }
426 // else 429 // else
427 // return; 430 // return;
428 if ( t.count() == 0 ) 431 if ( t.count() == 0 )
429 return; 432 return;
430 RecMailP mail = t.first(); 433 RecMailP mail = t.first();
431 AbstractMail*targetMail = 0; 434 AbstractMail*targetMail = 0;
432 QString targetFolder = ""; 435 QString targetFolder = "";
433 Selectstore sels; 436 Selectstore sels;
434 folderView->setupFolderselect(&sels); 437 folderView->setupFolderselect(&sels);
435 if (!sels.exec()) return; 438 if (!sels.exec()) return;
436 targetMail = sels.currentMail(); 439 targetMail = sels.currentMail();
437 targetFolder = sels.currentFolder(); 440 targetFolder = sels.currentFolder();
438 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) || 441 if ( (mail->Wrapper()==targetMail && mail->getMbox()==targetFolder) ||
439 targetFolder.isEmpty()) 442 targetFolder.isEmpty())
440 { 443 {
441 return; 444 return;
442 } 445 }
443 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 446 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
444 { 447 {
445 QMessageBox::critical(0,tr("Error creating new Folder"), 448 QMessageBox::critical(0,tr("Error creating new Folder"),
446 tr("<center>Error while creating<br>new folder - breaking.</center>")); 449 tr("<center>Error while creating<br>new folder - breaking.</center>"));
447 return; 450 return;
448 } 451 }
449 sels.hide(); 452 sels.hide();
450 qApp->processEvents(); 453 qApp->processEvents();
451 //qDebug("hiding sels "); 454 //qDebug("hiding sels ");
452 mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails()); 455 mail->Wrapper()->mvcpMailList(t,targetFolder,targetMail,sels.moveMails());
453 folderView->refreshCurrent(); 456 folderView->refreshCurrent();
454} 457}
455 458
456void OpieMail::reEditMail() 459void OpieMail::reEditMail()
457{ 460{
458 if (!mailView->currentItem()) return; 461 if (!mailView->currentItem()) return;
459 462
460 ComposeMail compose( settings, this, 0, true ); 463 ComposeMail compose( settings, this, 0, true );
461 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data()); 464 compose.reEditMail(((MailListViewItem*)mailView->currentItem() )->data());
462 compose.slotAdjustColumns(); 465 compose.slotAdjustColumns();
463 compose.showMaximized(); 466 compose.showMaximized();
464 compose.exec(); 467 compose.exec();
465} 468}