summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/accountitem.cpp22
-rw-r--r--kmicromail/accountview.cpp5
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp67
-rw-r--r--kmicromail/libmailwrapper/abstractmail.h7
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.cpp64
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.h2
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp18
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.h1
-rw-r--r--kmicromail/libmailwrapper/mailtypes.cpp23
-rw-r--r--kmicromail/libmailwrapper/mailtypes.h5
-rw-r--r--kmicromail/libmailwrapper/mboxwrapper.h1
-rw-r--r--kmicromail/libmailwrapper/mhwrapper.cpp1
-rw-r--r--kmicromail/libmailwrapper/mhwrapper.h1
-rw-r--r--kmicromail/libmailwrapper/nntpwrapper.h1
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.h2
-rw-r--r--kmicromail/libmailwrapper/smtpwrapper.h1
-rw-r--r--kmicromail/mailistviewitem.cpp9
17 files changed, 208 insertions, 22 deletions
diff --git a/kmicromail/accountitem.cpp b/kmicromail/accountitem.cpp
index 1698b40..7b9b881 100644
--- a/kmicromail/accountitem.cpp
+++ b/kmicromail/accountitem.cpp
@@ -1,1150 +1,1170 @@
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
19using namespace Opie::Core; 19using namespace Opie::Core;
20#define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} 20#define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );}
21/** 21/**
22 * POP3 Account stuff 22 * POP3 Account stuff
23 */ 23 */
24POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) 24POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent )
25 : AccountViewItem( parent ) 25 : AccountViewItem( parent )
26{ 26{
27 account = a; 27 account = a;
28 wrapper = AbstractMail::getWrapper( account ); 28 wrapper = AbstractMail::getWrapper( account );
29 SETPIX(PIXMAP_POP3FOLDER); 29 SETPIX(PIXMAP_POP3FOLDER);
30#if 0 30#if 0
31 if (!account->getOffline()) 31 if (!account->getOffline())
32 { 32 {
33 setPixmap( 0, ); 33 setPixmap( 0, );
34 } 34 }
35 else 35 else
36 { 36 {
37 setPixmap( 0, PIXMAP_OFFLINE ); 37 setPixmap( 0, PIXMAP_OFFLINE );
38 } 38 }
39#endif 39#endif
40 setText( 0, account->getAccountName() ); 40 setText( 0, account->getAccountName() );
41 setOpen( true ); 41 setOpen( true );
42} 42}
43 43
44POP3viewItem::~POP3viewItem() 44POP3viewItem::~POP3viewItem()
45{ 45{
46 delete wrapper; 46 delete wrapper;
47} 47}
48 48
49AbstractMail *POP3viewItem::getWrapper() 49AbstractMail *POP3viewItem::getWrapper()
50{ 50{
51 return wrapper; 51 return wrapper;
52} 52}
53 53
54void POP3viewItem::refresh(QValueList<Opie::Core::OSmartPointer<RecMail> > & ) 54void POP3viewItem::refresh(QValueList<Opie::Core::OSmartPointer<RecMail> > & )
55{ 55{
56 refresh(); 56 refresh();
57} 57}
58 58
59void POP3viewItem::refresh() 59void POP3viewItem::refresh()
60{ 60{
61 if (account->getOffline()) return; 61 if (account->getOffline()) return;
62 QValueList<FolderP> *folders = wrapper->listFolders(); 62 QValueList<FolderP> *folders = wrapper->listFolders();
63 QListViewItem *child = firstChild(); 63 QListViewItem *child = firstChild();
64 while ( child ) 64 while ( child )
65 { 65 {
66 QListViewItem *tmp = child; 66 QListViewItem *tmp = child;
67 child = child->nextSibling(); 67 child = child->nextSibling();
68 delete tmp; 68 delete tmp;
69 } 69 }
70 QValueList<FolderP>::ConstIterator it; 70 QValueList<FolderP>::ConstIterator it;
71 QListViewItem*item = 0; 71 QListViewItem*item = 0;
72 for ( it = folders->begin(); it!=folders->end(); ++it) 72 for ( it = folders->begin(); it!=folders->end(); ++it)
73 { 73 {
74 item = new POP3folderItem( (*it), this , item ); 74 item = new POP3folderItem( (*it), this , item );
75 item->setSelectable( (*it)->may_select()); 75 item->setSelectable( (*it)->may_select());
76 } 76 }
77 delete folders; 77 delete folders;
78} 78}
79 79
80RECBODYP POP3viewItem::fetchBody( const RecMailP &mail ) 80RECBODYP POP3viewItem::fetchBody( const RecMailP &mail )
81{ 81{
82 82
83 return wrapper->fetchBody( mail ); 83 return wrapper->fetchBody( mail );
84} 84}
85 85
86QPopupMenu * POP3viewItem::getContextMenu() 86QPopupMenu * POP3viewItem::getContextMenu()
87{ 87{
88 QPopupMenu *m = new QPopupMenu(0); 88 QPopupMenu *m = new QPopupMenu(0);
89 if (m) 89 if (m)
90 { 90 {
91 if (!account->getOffline()) 91 if (!account->getOffline())
92 { 92 {
93 m->insertItem(QObject::tr("Disconnect",contextName),0); 93 m->insertItem(QObject::tr("Disconnect",contextName),0);
94 m->insertItem(QObject::tr("Set offline",contextName),1); 94 m->insertItem(QObject::tr("Set offline",contextName),1);
95 m->insertItem(QObject::tr("Download messages",contextName),2); 95 m->insertItem(QObject::tr("Download new INBOX messages",contextName),2);
96 } 96 }
97 else 97 else
98 { 98 {
99 m->insertItem(QObject::tr("Set online",contextName),1); 99 m->insertItem(QObject::tr("Set online",contextName),1);
100 m->insertItem(QObject::tr("Download new INBOX messages",contextName),2);
100 } 101 }
101 } 102 }
102 return m; 103 return m;
103} 104}
104 105
105void POP3viewItem::disconnect() 106void POP3viewItem::disconnect()
106{ 107{
107 QListViewItem *child = firstChild(); 108 QListViewItem *child = firstChild();
108 while ( child ) 109 while ( child )
109 { 110 {
110 QListViewItem *tmp = child; 111 QListViewItem *tmp = child;
111 child = child->nextSibling(); 112 child = child->nextSibling();
112 delete tmp; 113 delete tmp;
113 } 114 }
114 wrapper->logout(); 115 wrapper->logout();
115} 116}
116 117
117void POP3viewItem::setOnOffline() 118void POP3viewItem::setOnOffline()
118{ 119{
119 if (!account->getOffline()) 120 if (!account->getOffline())
120 { 121 {
121 disconnect(); 122 disconnect();
122 } 123 }
123 account->setOffline(!account->getOffline()); 124 account->setOffline(!account->getOffline());
124 account->save(); 125 account->save();
125 SETPIX(PIXMAP_POP3FOLDER); 126 SETPIX(PIXMAP_POP3FOLDER);
126 refresh(); 127 refresh();
127} 128}
128 129
129void POP3viewItem::contextMenuSelected(int which) 130void POP3viewItem::contextMenuSelected(int which)
130{ 131{
131 switch (which) 132 switch (which)
132 { 133 {
133 case 0: 134 case 0:
134 disconnect(); 135 disconnect();
135 break; 136 break;
136 case 1: 137 case 1:
137 setOnOffline(); 138 setOnOffline();
138 break; 139 break;
139 case 2: // daunlood 140 case 2: // daunlood
141 if (account->getOffline())
142 setOnOffline();
140 AccountView*bl = accountView(); 143 AccountView*bl = accountView();
141 if (!bl) return; 144 if (!bl) return;
142 AccountViewItem* in = findSubItem( "inbox" , 0); 145 AccountViewItem* in = findSubItem( "inbox" , 0);
143 if ( ! in ) 146 if ( ! in )
144 return; 147 return;
145 bl->downloadMailsInbox(in->getFolder() ,getWrapper()); 148 bl->downloadMailsInbox(in->getFolder() ,getWrapper());
146 setOnOffline(); 149 setOnOffline();
147 break; 150 break;
148 } 151 }
149} 152}
150 153
151POP3folderItem::~POP3folderItem() 154POP3folderItem::~POP3folderItem()
152{} 155{}
153 156
154POP3folderItem::POP3folderItem( const FolderP&folderInit, POP3viewItem *parent , QListViewItem*after ) 157POP3folderItem::POP3folderItem( const FolderP&folderInit, POP3viewItem *parent , QListViewItem*after )
155 : AccountViewItem(folderInit,parent,after ) 158 : AccountViewItem(folderInit,parent,after )
156{ 159{
157 pop3 = parent; 160 pop3 = parent;
158 if (folder->getDisplayName().lower()!="inbox") 161 if (folder->getDisplayName().lower()!="inbox")
159 { 162 {
160 setPixmap( 0, PIXMAP_POP3FOLDER ); 163 setPixmap( 0, PIXMAP_POP3FOLDER );
161 } 164 }
162 else 165 else
163 { 166 {
164 setPixmap( 0, PIXMAP_INBOXFOLDER); 167 setPixmap( 0, PIXMAP_INBOXFOLDER);
165 } 168 }
166 setText( 0, folder->getDisplayName() ); 169 setText( 0, folder->getDisplayName() );
167} 170}
168 171
169void POP3folderItem::refresh(QValueList<RecMailP>&target) 172void POP3folderItem::refresh(QValueList<RecMailP>&target)
170{ 173{
171 if (folder->may_select()) 174 if (folder->may_select())
172 pop3->getWrapper()->listMessages( folder->getName(),target ); 175 pop3->getWrapper()->listMessages( folder->getName(),target );
173} 176}
174 177
175RECBODYP POP3folderItem::fetchBody(const RecMailP&aMail) 178RECBODYP POP3folderItem::fetchBody(const RecMailP&aMail)
176{ 179{
177 return pop3->getWrapper()->fetchBody(aMail); 180 return pop3->getWrapper()->fetchBody(aMail);
178} 181}
179 182
180QPopupMenu * POP3folderItem::getContextMenu() 183QPopupMenu * POP3folderItem::getContextMenu()
181{ 184{
182 QPopupMenu *m = new QPopupMenu(0); 185 QPopupMenu *m = new QPopupMenu(0);
183 if (m) 186 if (m)
184 { 187 {
185 m->insertItem(QObject::tr("Refresh header list",contextName),0); 188 m->insertItem(QObject::tr("Refresh header list",contextName),0);
186 m->insertItem(QObject::tr("Delete all mails",contextName),1); 189 m->insertItem(QObject::tr("Delete all mails",contextName),1);
187 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); 190 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
188 } 191 }
189 return m; 192 return m;
190} 193}
191 194
192void POP3folderItem::downloadMails() 195void POP3folderItem::downloadMails()
193{ 196{
194 AccountView*bl = pop3->accountView(); 197 AccountView*bl = pop3->accountView();
195 if (!bl) return; 198 if (!bl) return;
196 bl->downloadMails(folder,pop3->getWrapper()); 199 bl->downloadMails(folder,pop3->getWrapper());
197} 200}
198 201
199void POP3folderItem::contextMenuSelected(int which) 202void POP3folderItem::contextMenuSelected(int which)
200{ 203{
201 AccountView * view = (AccountView*)listView(); 204 AccountView * view = (AccountView*)listView();
202 switch (which) 205 switch (which)
203 { 206 {
204 case 0: 207 case 0:
205 /* must be 'cause pop3 lists are cached */ 208 /* must be 'cause pop3 lists are cached */
206 pop3->getWrapper()->logout(); 209 pop3->getWrapper()->logout();
207 view->refreshCurrent(); 210 view->refreshCurrent();
208 break; 211 break;
209 case 1: 212 case 1:
210 deleteAllMail(pop3->getWrapper(),folder); 213 deleteAllMail(pop3->getWrapper(),folder);
211 break; 214 break;
212 case 2: 215 case 2:
213 downloadMails(); 216 downloadMails();
214 break; 217 break;
215 default: 218 default:
216 break; 219 break;
217 } 220 }
218} 221}
219 222
220/** 223/**
221 * NNTP Account stuff 224 * NNTP Account stuff
222 */ 225 */
223NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent ) 226NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent )
224 : AccountViewItem( parent ) 227 : AccountViewItem( parent )
225{ 228{
226 account = a; 229 account = a;
227 wrapper = AbstractMail::getWrapper( account ); 230 wrapper = AbstractMail::getWrapper( account );
228 //FIXME 231 //FIXME
229 SETPIX(PIXMAP_POP3FOLDER); 232 SETPIX(PIXMAP_POP3FOLDER);
230#if 0 233#if 0
231 if (!account->getOffline()) 234 if (!account->getOffline())
232 { 235 {
233 setPixmap( 0, ); 236 setPixmap( 0, );
234 } 237 }
235 else 238 else
236 { 239 {
237 setPixmap( 0, PIXMAP_OFFLINE ); 240 setPixmap( 0, PIXMAP_OFFLINE );
238 } 241 }
239#endif 242#endif
240 setText( 0, account->getAccountName() ); 243 setText( 0, account->getAccountName() );
241 setOpen( true ); 244 setOpen( true );
242} 245}
243 246
244NNTPviewItem::~NNTPviewItem() 247NNTPviewItem::~NNTPviewItem()
245{ 248{
246 delete wrapper; 249 delete wrapper;
247} 250}
248 251
249AbstractMail *NNTPviewItem::getWrapper() 252AbstractMail *NNTPviewItem::getWrapper()
250{ 253{
251 return wrapper; 254 return wrapper;
252} 255}
253 256
254void NNTPviewItem::refresh( QValueList<RecMailP> & ) 257void NNTPviewItem::refresh( QValueList<RecMailP> & )
255{ 258{
256 refresh(); 259 refresh();
257} 260}
258 261
259void NNTPviewItem::refresh() 262void NNTPviewItem::refresh()
260{ 263{
261 if (account->getOffline()) return; 264 if (account->getOffline()) return;
262 QValueList<FolderP> *folders = wrapper->listFolders(); 265 QValueList<FolderP> *folders = wrapper->listFolders();
263 266
264 QListViewItem *child = firstChild(); 267 QListViewItem *child = firstChild();
265 while ( child ) 268 while ( child )
266 { 269 {
267 QListViewItem *tmp = child; 270 QListViewItem *tmp = child;
268 child = child->nextSibling(); 271 child = child->nextSibling();
269 delete tmp; 272 delete tmp;
270 } 273 }
271 QValueList<FolderP>::ConstIterator it; 274 QValueList<FolderP>::ConstIterator it;
272 QListViewItem*item = 0; 275 QListViewItem*item = 0;
273 for ( it = folders->begin(); it!=folders->end(); ++it) 276 for ( it = folders->begin(); it!=folders->end(); ++it)
274 { 277 {
275 item = new NNTPfolderItem( (*it), this , item ); 278 item = new NNTPfolderItem( (*it), this , item );
276 item->setSelectable( (*it)->may_select()); 279 item->setSelectable( (*it)->may_select());
277 } 280 }
278 delete folders; 281 delete folders;
279} 282}
280 283
281RECBODYP NNTPviewItem::fetchBody( const RecMailP &mail ) 284RECBODYP NNTPviewItem::fetchBody( const RecMailP &mail )
282{ 285{
283 286
284 return wrapper->fetchBody( mail ); 287 return wrapper->fetchBody( mail );
285} 288}
286 289
287QPopupMenu * NNTPviewItem::getContextMenu() 290QPopupMenu * NNTPviewItem::getContextMenu()
288{ 291{
289 QPopupMenu *m = new QPopupMenu(0); 292 QPopupMenu *m = new QPopupMenu(0);
290 if (m) 293 if (m)
291 { 294 {
292 if (!account->getOffline()) 295 if (!account->getOffline())
293 { 296 {
294 m->insertItem(QObject::tr("Disconnect",contextName),0); 297 m->insertItem(QObject::tr("Disconnect",contextName),0);
295 m->insertItem(QObject::tr("Set offline",contextName),1); 298 m->insertItem(QObject::tr("Set offline",contextName),1);
296 m->insertItem(QObject::tr("(Un-)Subscribe groups",contextName),2); 299 m->insertItem(QObject::tr("(Un-)Subscribe groups",contextName),2);
297 } 300 }
298 else 301 else
299 { 302 {
300 m->insertItem(QObject::tr("Set online",contextName),1); 303 m->insertItem(QObject::tr("Set online",contextName),1);
301 } 304 }
302 } 305 }
303 return m; 306 return m;
304} 307}
305 308
306void NNTPviewItem::subscribeGroups() 309void NNTPviewItem::subscribeGroups()
307{ 310{
308 NNTPGroupsDlg dlg(account); 311 NNTPGroupsDlg dlg(account);
309 dlg.showMaximized(); 312 dlg.showMaximized();
310 if ( dlg.exec()== QDialog::Accepted ){ 313 if ( dlg.exec()== QDialog::Accepted ){
311 refresh(); 314 refresh();
312 } 315 }
313} 316}
314 317
315void NNTPviewItem::disconnect() 318void NNTPviewItem::disconnect()
316{ 319{
317 QListViewItem *child = firstChild(); 320 QListViewItem *child = firstChild();
318 while ( child ) 321 while ( child )
319 { 322 {
320 QListViewItem *tmp = child; 323 QListViewItem *tmp = child;
321 child = child->nextSibling(); 324 child = child->nextSibling();
322 delete tmp; 325 delete tmp;
323 } 326 }
324 wrapper->logout(); 327 wrapper->logout();
325} 328}
326 329
327void NNTPviewItem::setOnOffline() 330void NNTPviewItem::setOnOffline()
328{ 331{
329 if (!account->getOffline()) 332 if (!account->getOffline())
330 { 333 {
331 disconnect(); 334 disconnect();
332 } 335 }
333 account->setOffline(!account->getOffline()); 336 account->setOffline(!account->getOffline());
334 account->save(); 337 account->save();
335 //FIXME 338 //FIXME
336 SETPIX(PIXMAP_POP3FOLDER); 339 SETPIX(PIXMAP_POP3FOLDER);
337 refresh(); 340 refresh();
338} 341}
339 342
340void NNTPviewItem::contextMenuSelected(int which) 343void NNTPviewItem::contextMenuSelected(int which)
341{ 344{
342 switch (which) 345 switch (which)
343 { 346 {
344 case 0: 347 case 0:
345 disconnect(); 348 disconnect();
346 break; 349 break;
347 case 1: 350 case 1:
348 setOnOffline(); 351 setOnOffline();
349 break; 352 break;
350 case 2: 353 case 2:
351 subscribeGroups(); 354 subscribeGroups();
352 break; 355 break;
353 } 356 }
354} 357}
355 358
356NNTPfolderItem::~NNTPfolderItem() 359NNTPfolderItem::~NNTPfolderItem()
357{} 360{}
358 361
359NNTPfolderItem::NNTPfolderItem( const FolderP &folderInit, NNTPviewItem *parent , QListViewItem*after ) 362NNTPfolderItem::NNTPfolderItem( const FolderP &folderInit, NNTPviewItem *parent , QListViewItem*after )
360 : AccountViewItem( folderInit, parent,after ) 363 : AccountViewItem( folderInit, parent,after )
361{ 364{
362 nntp = parent; 365 nntp = parent;
363 if (folder->getDisplayName().lower()!="inbox") 366 if (folder->getDisplayName().lower()!="inbox")
364 { 367 {
365 setPixmap( 0, PIXMAP_POP3FOLDER ); 368 setPixmap( 0, PIXMAP_POP3FOLDER );
366 } 369 }
367 else 370 else
368 { 371 {
369 setPixmap( 0, PIXMAP_INBOXFOLDER); 372 setPixmap( 0, PIXMAP_INBOXFOLDER);
370 } 373 }
371 setText( 0, folder->getDisplayName() ); 374 setText( 0, folder->getDisplayName() );
372} 375}
373 376
374void NNTPfolderItem::refresh(QValueList<RecMailP>&target) 377void NNTPfolderItem::refresh(QValueList<RecMailP>&target)
375{ 378{
376 if (folder->may_select()) 379 if (folder->may_select())
377 nntp->getWrapper()->listMessages( folder->getName(),target ); 380 nntp->getWrapper()->listMessages( folder->getName(),target );
378} 381}
379 382
380RECBODYP NNTPfolderItem::fetchBody(const RecMailP&aMail) 383RECBODYP NNTPfolderItem::fetchBody(const RecMailP&aMail)
381{ 384{
382 return nntp->getWrapper()->fetchBody(aMail); 385 return nntp->getWrapper()->fetchBody(aMail);
383} 386}
384 387
385QPopupMenu * NNTPfolderItem::getContextMenu() 388QPopupMenu * NNTPfolderItem::getContextMenu()
386{ 389{
387 QPopupMenu *m = new QPopupMenu(0); 390 QPopupMenu *m = new QPopupMenu(0);
388 if (m) 391 if (m)
389 { 392 {
390 m->insertItem(QObject::tr("Refresh header list",contextName),0); 393 m->insertItem(QObject::tr("Refresh header list",contextName),0);
391 m->insertItem(QObject::tr("Copy all postings",contextName),1); 394 m->insertItem(QObject::tr("Copy all postings",contextName),1);
392 } 395 }
393 return m; 396 return m;
394} 397}
395 398
396void NNTPfolderItem::downloadMails() 399void NNTPfolderItem::downloadMails()
397{ 400{
398 AccountView*bl = nntp->accountView(); 401 AccountView*bl = nntp->accountView();
399 if (!bl) return; 402 if (!bl) return;
400 bl->downloadMails(folder,nntp->getWrapper()); 403 bl->downloadMails(folder,nntp->getWrapper());
401} 404}
402 405
403void NNTPfolderItem::contextMenuSelected(int which) 406void NNTPfolderItem::contextMenuSelected(int which)
404{ 407{
405 AccountView * view = (AccountView*)listView(); 408 AccountView * view = (AccountView*)listView();
406 switch (which) 409 switch (which)
407 { 410 {
408 case 0: 411 case 0:
409 /* must be 'cause pop3 lists are cached */ 412 /* must be 'cause pop3 lists are cached */
410 nntp->getWrapper()->logout(); 413 nntp->getWrapper()->logout();
411 view->refreshCurrent(); 414 view->refreshCurrent();
412 break; 415 break;
413 case 1: 416 case 1:
414 downloadMails(); 417 downloadMails();
415 break; 418 break;
416 default: 419 default:
417 break; 420 break;
418 } 421 }
419} 422}
420 423
421/** 424/**
422 * IMAP Account stuff 425 * IMAP Account stuff
423 */ 426 */
424IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) 427IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent )
425 : AccountViewItem( parent ) 428 : AccountViewItem( parent )
426{ 429{
427 account = a; 430 account = a;
428 wrapper = AbstractMail::getWrapper( account ); 431 wrapper = AbstractMail::getWrapper( account );
429 SETPIX(PIXMAP_IMAPFOLDER); 432 SETPIX(PIXMAP_IMAPFOLDER);
430 setText( 0, account->getAccountName() ); 433 setText( 0, account->getAccountName() );
431 setOpen( true ); 434 setOpen( true );
432} 435}
433 436
434IMAPviewItem::~IMAPviewItem() 437IMAPviewItem::~IMAPviewItem()
435{ 438{
436 delete wrapper; 439 delete wrapper;
437} 440}
438 441
439AbstractMail *IMAPviewItem::getWrapper() 442AbstractMail *IMAPviewItem::getWrapper()
440{ 443{
441 return wrapper; 444 return wrapper;
442} 445}
443 446
444void IMAPviewItem::refresh(QValueList<RecMailP>&) 447void IMAPviewItem::refresh(QValueList<RecMailP>&)
445{ 448{
446 refreshFolders(false); 449 refreshFolders(false);
447} 450}
448 451
449const QStringList&IMAPviewItem::subFolders() 452const QStringList&IMAPviewItem::subFolders()
450{ 453{
451 return currentFolders; 454 return currentFolders;
452} 455}
453 456
454void IMAPviewItem::refreshFolders(bool force) 457void IMAPviewItem::refreshFolders(bool force)
455{ 458{
456 if (childCount()>0 && force==false) return; 459 if (childCount()>0 && force==false) return;
457 if (account->getOffline()) return; 460 if (account->getOffline()) return;
458 461
459 removeChilds(); 462 removeChilds();
460 currentFolders.clear(); 463 currentFolders.clear();
461 QValueList<FolderP> * folders = wrapper->listFolders(); 464 QValueList<FolderP> * folders = wrapper->listFolders();
462 465
463 QValueList<FolderP>::Iterator it; 466 QValueList<FolderP>::Iterator it;
464 QListViewItem*item = 0; 467 QListViewItem*item = 0;
465 QListViewItem*titem = 0; 468 QListViewItem*titem = 0;
466 QString fname,del,search; 469 QString fname,del,search;
467 int pos; 470 int pos;
468 471
469 for ( it = folders->begin(); it!=folders->end(); ++it) 472 for ( it = folders->begin(); it!=folders->end(); ++it)
470 { 473 {
471 if ((*it)->getDisplayName().lower()=="inbox") 474 if ((*it)->getDisplayName().lower()=="inbox")
472 { 475 {
473 item = new IMAPfolderItem( (*it), this , item ); 476 item = new IMAPfolderItem( (*it), this , item );
474 folders->remove(it); 477 folders->remove(it);
475 break; 478 break;
476 } 479 }
477 } 480 }
478 for ( it = folders->begin(); it!=folders->end(); ++it) 481 for ( it = folders->begin(); it!=folders->end(); ++it)
479 { 482 {
480 fname = (*it)->getDisplayName(); 483 fname = (*it)->getDisplayName();
481 currentFolders.append((*it)->getName()); 484 currentFolders.append((*it)->getName());
482 pos = fname.findRev((*it)->Separator()); 485 pos = fname.findRev((*it)->Separator());
483 if (pos != -1) 486 if (pos != -1)
484 { 487 {
485 fname = fname.left(pos); 488 fname = fname.left(pos);
486 } 489 }
487 IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname); 490 IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname);
488 if (pitem) 491 if (pitem)
489 { 492 {
490 titem = item; 493 titem = item;
491 item = new IMAPfolderItem( (*it),pitem,pitem->firstChild(),this); 494 item = new IMAPfolderItem( (*it),pitem,pitem->firstChild(),this);
492 /* setup the short name */ 495 /* setup the short name */
493 item->setText(0,(*it)->getDisplayName().right((*it)->getDisplayName().length()-pos-1)); 496 item->setText(0,(*it)->getDisplayName().right((*it)->getDisplayName().length()-pos-1));
494 item = titem; 497 item = titem;
495 } 498 }
496 else 499 else
497 { 500 {
498 item = new IMAPfolderItem( (*it), this , item ); 501 item = new IMAPfolderItem( (*it), this , item );
499 } 502 }
500 } 503 }
501 delete folders; 504 delete folders;
502} 505}
503 506
504QPopupMenu * IMAPviewItem::getContextMenu() 507QPopupMenu * IMAPviewItem::getContextMenu()
505{ 508{
506 QPopupMenu *m = new QPopupMenu(0); 509 QPopupMenu *m = new QPopupMenu(0);
507 if (m) 510 if (m)
508 { 511 {
509 if (!account->getOffline()) 512 if (!account->getOffline())
510 { 513 {
511 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 514 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
512 m->insertItem(QObject::tr("Create new folder",contextName),1); 515 m->insertItem(QObject::tr("Create new folder",contextName),1);
513 m->insertSeparator(); 516 m->insertSeparator();
514 m->insertItem(QObject::tr("Disconnect",contextName),2); 517 m->insertItem(QObject::tr("Disconnect",contextName),2);
515 m->insertItem(QObject::tr("Set offline",contextName),3); 518 m->insertItem(QObject::tr("Set offline",contextName),3);
519 m->insertSeparator();
520 m->insertItem(QObject::tr("Download new INBOX messages",contextName),4);
516 } 521 }
517 else 522 else
518 { 523 {
519 m->insertItem(QObject::tr("Set online",contextName),3); 524 m->insertItem(QObject::tr("Set online",contextName),3);
525 m->insertSeparator();
526 m->insertItem(QObject::tr("Download new INBOX messages",contextName),4);
520 } 527 }
521 } 528 }
522 return m; 529 return m;
523} 530}
524 531
525void IMAPviewItem::createNewFolder() 532void IMAPviewItem::createNewFolder()
526{ 533{
527 Newmdirdlg ndirdlg; 534 Newmdirdlg ndirdlg;
528 535
529 ndirdlg.showMaximized(); 536 ndirdlg.showMaximized();
530 if ( ndirdlg.exec() ) 537 if ( ndirdlg.exec() )
531 { 538 {
532 QString ndir = ndirdlg.Newdir(); 539 QString ndir = ndirdlg.Newdir();
533 bool makesubs = ndirdlg.subpossible(); 540 bool makesubs = ndirdlg.subpossible();
534 QString delemiter = "/"; 541 QString delemiter = "/";
535 IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); 542 IMAPfolderItem*item = (IMAPfolderItem*)firstChild();
536 if (item) 543 if (item)
537 { 544 {
538 delemiter = item->Delemiter(); 545 delemiter = item->Delemiter();
539 } 546 }
540 if (wrapper->createMbox(ndir,0,delemiter,makesubs)) 547 if (wrapper->createMbox(ndir,0,delemiter,makesubs))
541 { 548 {
542 refreshFolders(true); 549 refreshFolders(true);
543 } 550 }
544 } 551 }
545} 552}
546 553
547void IMAPviewItem::contextMenuSelected(int id) 554void IMAPviewItem::contextMenuSelected(int id)
548{ 555{
549 556
550 switch (id) 557 switch (id)
551 { 558 {
552 case 0: 559 case 0:
553 refreshFolders(true); 560 refreshFolders(true);
554 break; 561 break;
555 case 1: 562 case 1:
556 createNewFolder(); 563 createNewFolder();
557 break; 564 break;
558 case 2: 565 case 2:
559 removeChilds(); 566 removeChilds();
560 wrapper->logout(); 567 wrapper->logout();
561 break; 568 break;
562 case 3: 569 case 3:
563 if (account->getOffline()==false) 570 if (account->getOffline()==false)
564 { 571 {
565 removeChilds(); 572 removeChilds();
566 wrapper->logout(); 573 wrapper->logout();
567 } 574 }
568 account->setOffline(!account->getOffline()); 575 account->setOffline(!account->getOffline());
569 account->save(); 576 account->save();
570 SETPIX(PIXMAP_IMAPFOLDER); 577 SETPIX(PIXMAP_IMAPFOLDER);
571 refreshFolders(false); 578 refreshFolders(false);
572 break; 579 break;
580 case 4: // daunlood
581 {
582 if (account->getOffline()) {
583 contextMenuSelected( 3 );
584 }
585 AccountView*bl = accountView();
586 if (!bl) return;
587 AccountViewItem* in = findSubItem( "inbox" , 0);
588 if ( ! in )
589 return;
590 bl->downloadMailsInbox(in->getFolder(),getWrapper());
591 }
592 break;
573 default: 593 default:
574 break; 594 break;
575 } 595 }
576} 596}
577 597
578RECBODYP IMAPviewItem::fetchBody(const RecMailP&) 598RECBODYP IMAPviewItem::fetchBody(const RecMailP&)
579{ 599{
580 return new RecBody(); 600 return new RecBody();
581} 601}
582 602
583bool IMAPviewItem::offline() 603bool IMAPviewItem::offline()
584{ 604{
585 return account->getOffline(); 605 return account->getOffline();
586} 606}
587 607
588IMAPfolderItem::IMAPfolderItem( const FolderP& folderInit, IMAPviewItem *parent , QListViewItem*after ) 608IMAPfolderItem::IMAPfolderItem( const FolderP& folderInit, IMAPviewItem *parent , QListViewItem*after )
589 : AccountViewItem( folderInit, parent , after ) 609 : AccountViewItem( folderInit, parent , after )
590{ 610{
591 imap = parent; 611 imap = parent;
592 if (folder->getDisplayName().lower()!="inbox") 612 if (folder->getDisplayName().lower()!="inbox")
593 { 613 {
594 setPixmap( 0, PIXMAP_IMAPFOLDER ); 614 setPixmap( 0, PIXMAP_IMAPFOLDER );
595 } 615 }
596 else 616 else
597 { 617 {
598 setPixmap( 0, PIXMAP_INBOXFOLDER); 618 setPixmap( 0, PIXMAP_INBOXFOLDER);
599 } 619 }
600 setText( 0, folder->getDisplayName() ); 620 setText( 0, folder->getDisplayName() );
601} 621}
602 622
603IMAPfolderItem::IMAPfolderItem(const FolderP &folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) 623IMAPfolderItem::IMAPfolderItem(const FolderP &folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master )
604 : AccountViewItem(folderInit, parent,after ) 624 : AccountViewItem(folderInit, parent,after )
605{ 625{
606 imap = master; 626 imap = master;
607 if (folder->getDisplayName().lower()!="inbox") 627 if (folder->getDisplayName().lower()!="inbox")
608 { 628 {
609 setPixmap( 0, PIXMAP_IMAPFOLDER ); 629 setPixmap( 0, PIXMAP_IMAPFOLDER );
610 } 630 }
611 else 631 else
612 { 632 {
613 setPixmap( 0, PIXMAP_INBOXFOLDER); 633 setPixmap( 0, PIXMAP_INBOXFOLDER);
614 } 634 }
615 setText( 0, folder->getDisplayName() ); 635 setText( 0, folder->getDisplayName() );
616} 636}
617 637
618IMAPfolderItem::~IMAPfolderItem() 638IMAPfolderItem::~IMAPfolderItem()
619{} 639{}
620 640
621const QString& IMAPfolderItem::Delemiter()const 641const QString& IMAPfolderItem::Delemiter()const
622{ 642{
623 return folder->Separator(); 643 return folder->Separator();
624} 644}
625 645
626void IMAPfolderItem::refresh(QValueList<RecMailP>&target) 646void IMAPfolderItem::refresh(QValueList<RecMailP>&target)
627{ 647{
628 if (folder->may_select()) 648 if (folder->may_select())
629 { 649 {
630 imap->getWrapper()->listMessages( folder->getName(),target ); 650 imap->getWrapper()->listMessages( folder->getName(),target );
631 } 651 }
632 else 652 else
633 { 653 {
634 target.clear(); 654 target.clear();
635 } 655 }
636} 656}
637 657
638RECBODYP IMAPfolderItem::fetchBody(const RecMailP&aMail) 658RECBODYP IMAPfolderItem::fetchBody(const RecMailP&aMail)
639{ 659{
640 return imap->getWrapper()->fetchBody(aMail); 660 return imap->getWrapper()->fetchBody(aMail);
641} 661}
642 662
643QPopupMenu * IMAPfolderItem::getContextMenu() 663QPopupMenu * IMAPfolderItem::getContextMenu()
644{ 664{
645 QPopupMenu *m = new QPopupMenu(0); 665 QPopupMenu *m = new QPopupMenu(0);
646 if (m) 666 if (m)
647 { 667 {
648 if (folder->may_select()) 668 if (folder->may_select())
649 { 669 {
650 m->insertItem(QObject::tr("Refresh header list",contextName),0); 670 m->insertItem(QObject::tr("Refresh header list",contextName),0);
651 m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); 671 m->insertItem(QObject::tr("Move/Copie all mails",contextName),4);
652 m->insertItem(QObject::tr("Delete all mails",contextName),1); 672 m->insertItem(QObject::tr("Delete all mails",contextName),1);
653 } 673 }
654 if (folder->no_inferior()==false) 674 if (folder->no_inferior()==false)
655 { 675 {
656 m->insertItem(QObject::tr("Create new subfolder",contextName),2); 676 m->insertItem(QObject::tr("Create new subfolder",contextName),2);
657 } 677 }
658 if (folder->getDisplayName().lower()!="inbox") 678 if (folder->getDisplayName().lower()!="inbox")
659 { 679 {
660 m->insertItem(QObject::tr("Delete folder",contextName),3); 680 m->insertItem(QObject::tr("Delete folder",contextName),3);
661 } 681 }
662 } 682 }
663 return m; 683 return m;
664} 684}
665 685
666void IMAPfolderItem::createNewFolder() 686void IMAPfolderItem::createNewFolder()
667{ 687{
668 Newmdirdlg ndirdlg; 688 Newmdirdlg ndirdlg;
669 ndirdlg.showMaximized(); 689 ndirdlg.showMaximized();
670 if ( ndirdlg.exec() ) 690 if ( ndirdlg.exec() )
671 { 691 {
672 QString ndir = ndirdlg.Newdir(); 692 QString ndir = ndirdlg.Newdir();
673 bool makesubs = ndirdlg.subpossible(); 693 bool makesubs = ndirdlg.subpossible();
674 QString delemiter = Delemiter(); 694 QString delemiter = Delemiter();
675 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) 695 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs))
676 { 696 {
677 imap->refreshFolders(true); 697 imap->refreshFolders(true);
678 } 698 }
679 } 699 }
680} 700}
681 701
682void IMAPfolderItem::deleteFolder() 702void IMAPfolderItem::deleteFolder()
683{ 703{
684 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 704 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
685 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 705 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
686 QObject::tr("Yes",contextName), 706 QObject::tr("Yes",contextName),
687 QObject::tr("No",contextName),QString::null,1,1); 707 QObject::tr("No",contextName),QString::null,1,1);
688 708
689 if (yesno == 0) 709 if (yesno == 0)
690 { 710 {
691 if (imap->getWrapper()->deleteMbox(folder)) 711 if (imap->getWrapper()->deleteMbox(folder))
692 { 712 {
693 QListView*v=listView(); 713 QListView*v=listView();
694 IMAPviewItem * box = imap; 714 IMAPviewItem * box = imap;
695 /* be carefull - after that this object is destroyd so don't use 715 /* be carefull - after that this object is destroyd so don't use
696 * any member of it after that call!!*/ 716 * any member of it after that call!!*/
697 imap->refreshFolders(true); 717 imap->refreshFolders(true);
698 if (v) 718 if (v)
699 { 719 {
700 v->setSelected(box,true); 720 v->setSelected(box,true);
701 } 721 }
702 } 722 }
703 } 723 }
704} 724}
705 725
706void IMAPfolderItem::downloadMails() 726void IMAPfolderItem::downloadMails()
707{ 727{
708 AccountView*bl = imap->accountView(); 728 AccountView*bl = imap->accountView();
709 if (!bl) return; 729 if (!bl) return;
710 bl->downloadMails(folder,imap->getWrapper()); 730 bl->downloadMails(folder,imap->getWrapper());
711} 731}
712 732
713void IMAPfolderItem::contextMenuSelected(int id) 733void IMAPfolderItem::contextMenuSelected(int id)
714{ 734{
715 735
716 AccountView * view = (AccountView*)listView(); 736 AccountView * view = (AccountView*)listView();
717 switch(id) 737 switch(id)
718 { 738 {
719 case 0: 739 case 0:
720 view->refreshCurrent(); 740 view->refreshCurrent();
721 break; 741 break;
722 case 1: 742 case 1:
723 deleteAllMail(imap->getWrapper(),folder); 743 deleteAllMail(imap->getWrapper(),folder);
724 break; 744 break;
725 case 2: 745 case 2:
726 createNewFolder(); 746 createNewFolder();
727 break; 747 break;
728 case 3: 748 case 3:
729 deleteFolder(); 749 deleteFolder();
730 break; 750 break;
731 case 4: 751 case 4:
732 downloadMails(); 752 downloadMails();
733 break; 753 break;
734 default: 754 default:
735 break; 755 break;
736 } 756 }
737} 757}
738 758
739/** 759/**
740 * MH Account stuff 760 * MH Account stuff
741 */ 761 */
742/* MH is a little bit different - the top folder can contains messages other than in IMAP and 762/* MH is a little bit different - the top folder can contains messages other than in IMAP and
743 POP3 and MBOX */ 763 POP3 and MBOX */
744MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) 764MHviewItem::MHviewItem( const QString&aPath, AccountView *parent )
745 : AccountViewItem( parent ) 765 : AccountViewItem( parent )
746{ 766{
747 m_Path = aPath; 767 m_Path = aPath;
748 /* be carefull - the space within settext is wanted - thats why the string twice */ 768 /* be carefull - the space within settext is wanted - thats why the string twice */
749 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); 769 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders");
750 setPixmap( 0, PIXMAP_LOCALFOLDER ); 770 setPixmap( 0, PIXMAP_LOCALFOLDER );
751 setText( 0, " Local Folders" ); 771 setText( 0, " Local Folders" );
752 setOpen( true ); 772 setOpen( true );
753 folder = 0; 773 folder = 0;
754} 774}
755 775
756MHviewItem::~MHviewItem() 776MHviewItem::~MHviewItem()
757{ 777{
758 delete wrapper; 778 delete wrapper;
759} 779}
760 780
761AbstractMail *MHviewItem::getWrapper() 781AbstractMail *MHviewItem::getWrapper()
762{ 782{
763 return wrapper; 783 return wrapper;
764} 784}
765 785
766void MHviewItem::refresh( QValueList<RecMailP> & target) 786void MHviewItem::refresh( QValueList<RecMailP> & target)
767{ 787{
768 refresh(false); 788 refresh(false);
769 getWrapper()->listMessages( "",target ); 789 getWrapper()->listMessages( "",target );
770} 790}
771 791
772void MHviewItem::refresh(bool force) 792void MHviewItem::refresh(bool force)
773{ 793{
774 if (childCount()>0 && force==false) return; 794 if (childCount()>0 && force==false) return;
775 removeChilds(); 795 removeChilds();
776 currentFolders.clear(); 796 currentFolders.clear();
777 QValueList<FolderP> *folders = wrapper->listFolders(); 797 QValueList<FolderP> *folders = wrapper->listFolders();
778 QValueList<FolderP>::ConstIterator it; 798 QValueList<FolderP>::ConstIterator it;
779 MHfolderItem*item = 0; 799 MHfolderItem*item = 0;
780 MHfolderItem*pmaster = 0; 800 MHfolderItem*pmaster = 0;
781 QString fname = ""; 801 QString fname = "";
782 int pos; 802 int pos;
783 for ( it = folders->begin(); it!=folders->end(); ++it) 803 for ( it = folders->begin(); it!=folders->end(); ++it)
784 { 804 {
785 fname = (*it)->getDisplayName(); 805 fname = (*it)->getDisplayName();
786 /* this folder itself */ 806 /* this folder itself */
787 if (fname=="/") 807 if (fname=="/")
788 { 808 {
789 currentFolders.append(fname); 809 currentFolders.append(fname);
790 folder = (*it); 810 folder = (*it);
791 continue; 811 continue;
792 } 812 }
793 currentFolders.append(fname); 813 currentFolders.append(fname);
794 pos = fname.findRev("/"); 814 pos = fname.findRev("/");
795 if (pos > 0) 815 if (pos > 0)
796 { 816 {
797 fname = fname.left(pos); 817 fname = fname.left(pos);
798 pmaster = (MHfolderItem*)findSubItem(fname); 818 pmaster = (MHfolderItem*)findSubItem(fname);
799 } 819 }
800 else 820 else
801 { 821 {
802 pmaster = 0; 822 pmaster = 0;
803 } 823 }
804 if (pmaster) 824 if (pmaster)
805 { 825 {
806 item = new MHfolderItem( (*it), pmaster, item, this ); 826 item = new MHfolderItem( (*it), pmaster, item, this );
807 } 827 }
808 else 828 else
809 { 829 {
810 item = new MHfolderItem( (*it), this , item ); 830 item = new MHfolderItem( (*it), this , item );
811 } 831 }
812 item->setSelectable((*it)->may_select()); 832 item->setSelectable((*it)->may_select());
813 } 833 }
814 delete folders; 834 delete folders;
815} 835}
816 836
817RECBODYP MHviewItem::fetchBody( const RecMailP &mail ) 837RECBODYP MHviewItem::fetchBody( const RecMailP &mail )
818{ 838{
819 839
820 return wrapper->fetchBody( mail ); 840 return wrapper->fetchBody( mail );
821} 841}
822 842
823QPopupMenu * MHviewItem::getContextMenu() 843QPopupMenu * MHviewItem::getContextMenu()
824{ 844{
825 QPopupMenu *m = new QPopupMenu(0); 845 QPopupMenu *m = new QPopupMenu(0);
826 if (m) 846 if (m)
827 { 847 {
828 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 848 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
829 m->insertItem(QObject::tr("Create new folder",contextName),1); 849 m->insertItem(QObject::tr("Create new folder",contextName),1);
830 m->insertItem(QObject::tr("Delete all mails",contextName),2); 850 m->insertItem(QObject::tr("Delete all mails",contextName),2);
831 m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); 851 m->insertItem(QObject::tr("Move/Copie all mails",contextName),3);
832 } 852 }
833 return m; 853 return m;
834} 854}
835 855
836void MHviewItem::createFolder() 856void MHviewItem::createFolder()
837{ 857{
838 Newmdirdlg ndirdlg(0,0,true); 858 Newmdirdlg ndirdlg(0,0,true);
839 ndirdlg.showMaximized(); 859 ndirdlg.showMaximized();
840 if ( ndirdlg.exec() ) 860 if ( ndirdlg.exec() )
841 { 861 {
842 QString ndir = ndirdlg.Newdir(); 862 QString ndir = ndirdlg.Newdir();
843 if (wrapper->createMbox(ndir)) 863 if (wrapper->createMbox(ndir))
844 { 864 {
845 refresh(true); 865 refresh(true);
846 } 866 }
847 } 867 }
848} 868}
849 869
850void MHviewItem::downloadMails() 870void MHviewItem::downloadMails()
851{ 871{
852 AccountView*bl = accountView(); 872 AccountView*bl = accountView();
853 if (!bl) return; 873 if (!bl) return;
854 bl->downloadMails(folder,getWrapper()); 874 bl->downloadMails(folder,getWrapper());
855} 875}
856 876
857QStringList MHviewItem::subFolders() 877QStringList MHviewItem::subFolders()
858{ 878{
859 return currentFolders; 879 return currentFolders;
860} 880}
861 881
862void MHviewItem::contextMenuSelected(int which) 882void MHviewItem::contextMenuSelected(int which)
863{ 883{
864 switch (which) 884 switch (which)
865 { 885 {
866 case 0: 886 case 0:
867 refresh(true); 887 refresh(true);
868 break; 888 break;
869 case 1: 889 case 1:
870 createFolder(); 890 createFolder();
871 break; 891 break;
872 case 2: 892 case 2:
873 deleteAllMail(getWrapper(),folder); 893 deleteAllMail(getWrapper(),folder);
874 break; 894 break;
875 case 3: 895 case 3:
876 downloadMails(); 896 downloadMails();
877 break; 897 break;
878 default: 898 default:
879 break; 899 break;
880 } 900 }
881} 901}
882 902
883MHfolderItem::~MHfolderItem() 903MHfolderItem::~MHfolderItem()
884{} 904{}
885 905
886MHfolderItem::MHfolderItem( const FolderP &folderInit, MHviewItem *parent , QListViewItem*after ) 906MHfolderItem::MHfolderItem( const FolderP &folderInit, MHviewItem *parent , QListViewItem*after )
887 : AccountViewItem(folderInit, parent,after ) 907 : AccountViewItem(folderInit, parent,after )
888{ 908{
889 mbox = parent; 909 mbox = parent;
890 initName(); 910 initName();
891} 911}
892 912
893MHfolderItem::MHfolderItem(const FolderP& folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) 913MHfolderItem::MHfolderItem(const FolderP& folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master)
894 : AccountViewItem(folderInit, parent,after ) 914 : AccountViewItem(folderInit, parent,after )
895{ 915{
896 folder = folderInit; 916 folder = folderInit;
897 mbox = master; 917 mbox = master;
898 initName(); 918 initName();
899} 919}
900 920
901void MHfolderItem::initName() 921void MHfolderItem::initName()
902{ 922{
903 QString bName = folder->getDisplayName(); 923 QString bName = folder->getDisplayName();
904 if (bName.startsWith("/")&&bName.length()>1) 924 if (bName.startsWith("/")&&bName.length()>1)
905 { 925 {
906 bName.replace(0,1,""); 926 bName.replace(0,1,"");
907 } 927 }
908 int pos = bName.findRev("/"); 928 int pos = bName.findRev("/");
909 if (pos > 0) 929 if (pos > 0)
910 { 930 {
911 bName.replace(0,pos+1,""); 931 bName.replace(0,pos+1,"");
912 } 932 }
913 if (bName.lower() == "outgoing") 933 if (bName.lower() == "outgoing")
914 { 934 {
915 setPixmap( 0, PIXMAP_OUTBOXFOLDER ); 935 setPixmap( 0, PIXMAP_OUTBOXFOLDER );
916 } 936 }
917 else if (bName.lower() == "inbox") 937 else if (bName.lower() == "inbox")
918 { 938 {
919 setPixmap( 0, PIXMAP_INBOXFOLDER); 939 setPixmap( 0, PIXMAP_INBOXFOLDER);
920 } else if (bName.lower() == "drafts") { 940 } else if (bName.lower() == "drafts") {
921 setPixmap(0, SmallIcon ("edit")); 941 setPixmap(0, SmallIcon ("edit"));
922 } else { 942 } else {
923 setPixmap( 0, PIXMAP_MBOXFOLDER ); 943 setPixmap( 0, PIXMAP_MBOXFOLDER );
924 } 944 }
925 setText( 0, bName ); 945 setText( 0, bName );
926} 946}
927 947
928const FolderP&MHfolderItem::getFolder()const 948const FolderP&MHfolderItem::getFolder()const
929{ 949{
930 return folder; 950 return folder;
931} 951}
932 952
933void MHfolderItem::refresh(QValueList<RecMailP>&target) 953void MHfolderItem::refresh(QValueList<RecMailP>&target)
934{ 954{
935 if (folder->may_select()) 955 if (folder->may_select())
936 mbox->getWrapper()->listMessages( folder->getName(),target ); 956 mbox->getWrapper()->listMessages( folder->getName(),target );
937} 957}
938 958
939RECBODYP MHfolderItem::fetchBody(const RecMailP&aMail) 959RECBODYP MHfolderItem::fetchBody(const RecMailP&aMail)
940{ 960{
941 return mbox->getWrapper()->fetchBody(aMail); 961 return mbox->getWrapper()->fetchBody(aMail);
942} 962}
943 963
944void MHfolderItem::deleteFolder() 964void MHfolderItem::deleteFolder()
945{ 965{
946 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 966 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
947 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), 967 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
948 QObject::tr("Yes",contextName), 968 QObject::tr("Yes",contextName),
949 QObject::tr("No",contextName),QString::null,1,1); 969 QObject::tr("No",contextName),QString::null,1,1);
950 970
951 if (yesno == 0) 971 if (yesno == 0)
952 { 972 {
953 if (mbox->getWrapper()->deleteMbox(folder)) 973 if (mbox->getWrapper()->deleteMbox(folder))
954 { 974 {
955 QListView*v=listView(); 975 QListView*v=listView();
956 MHviewItem * box = mbox; 976 MHviewItem * box = mbox;
957 /* be carefull - after that this object is destroyd so don't use 977 /* be carefull - after that this object is destroyd so don't use
958 * any member of it after that call!!*/ 978 * any member of it after that call!!*/
959 mbox->refresh(true); 979 mbox->refresh(true);
960 if (v) 980 if (v)
961 { 981 {
962 v->setSelected(box,true); 982 v->setSelected(box,true);
963 } 983 }
964 } 984 }
965 } 985 }
966} 986}
967 987
968QPopupMenu * MHfolderItem::getContextMenu() 988QPopupMenu * MHfolderItem::getContextMenu()
969{ 989{
970 QPopupMenu *m = new QPopupMenu(0); 990 QPopupMenu *m = new QPopupMenu(0);
971 if (m) 991 if (m)
972 { 992 {
973 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); 993 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
974 m->insertItem(QObject::tr("Delete all mails",contextName),0); 994 m->insertItem(QObject::tr("Delete all mails",contextName),0);
975 m->insertItem(QObject::tr("Create new subfolder",contextName),3); 995 m->insertItem(QObject::tr("Create new subfolder",contextName),3);
976 m->insertItem(QObject::tr("Delete folder",contextName),1); 996 m->insertItem(QObject::tr("Delete folder",contextName),1);
977 } 997 }
978 return m; 998 return m;
979} 999}
980 1000
981void MHfolderItem::downloadMails() 1001void MHfolderItem::downloadMails()
982{ 1002{
983 AccountView*bl = mbox->accountView(); 1003 AccountView*bl = mbox->accountView();
984 if (!bl) return; 1004 if (!bl) return;
985 bl->downloadMails(folder,mbox->getWrapper()); 1005 bl->downloadMails(folder,mbox->getWrapper());
986} 1006}
987 1007
988void MHfolderItem::createFolder() 1008void MHfolderItem::createFolder()
989{ 1009{
990 Newmdirdlg ndirdlg(0,0,true); 1010 Newmdirdlg ndirdlg(0,0,true);
991 ndirdlg.showMaximized(); 1011 ndirdlg.showMaximized();
992 if (ndirdlg.exec() ) 1012 if (ndirdlg.exec() )
993 { 1013 {
994 QString ndir = ndirdlg.Newdir(); 1014 QString ndir = ndirdlg.Newdir();
995 if (mbox->getWrapper()->createMbox(ndir,folder)) 1015 if (mbox->getWrapper()->createMbox(ndir,folder))
996 { 1016 {
997 QListView*v=listView(); 1017 QListView*v=listView();
998 MHviewItem * box = mbox; 1018 MHviewItem * box = mbox;
999 /* be carefull - after that this object is destroyd so don't use 1019 /* be carefull - after that this object is destroyd so don't use
1000 * any member of it after that call!!*/ 1020 * any member of it after that call!!*/
1001 mbox->refresh(true); 1021 mbox->refresh(true);
1002 if (v) 1022 if (v)
1003 { 1023 {
1004 v->setSelected(box,true); 1024 v->setSelected(box,true);
1005 } 1025 }
1006 } 1026 }
1007 } 1027 }
1008} 1028}
1009 1029
1010void MHfolderItem::contextMenuSelected(int which) 1030void MHfolderItem::contextMenuSelected(int which)
1011{ 1031{
1012 switch(which) 1032 switch(which)
1013 { 1033 {
1014 case 0: 1034 case 0:
1015 deleteAllMail(mbox->getWrapper(),folder); 1035 deleteAllMail(mbox->getWrapper(),folder);
1016 break; 1036 break;
1017 case 1: 1037 case 1:
1018 deleteFolder(); 1038 deleteFolder();
1019 break; 1039 break;
1020 case 2: 1040 case 2:
1021 downloadMails(); 1041 downloadMails();
1022 break; 1042 break;
1023 case 3: 1043 case 3:
1024 createFolder(); 1044 createFolder();
1025 break; 1045 break;
1026 default: 1046 default:
1027 break; 1047 break;
1028 } 1048 }
1029} 1049}
1030 1050
1031bool MHfolderItem::isDraftfolder() 1051bool MHfolderItem::isDraftfolder()
1032{ 1052{
1033 if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true; 1053 if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true;
1034 return false; 1054 return false;
1035} 1055}
1036 1056
1037/** 1057/**
1038 * Generic stuff 1058 * Generic stuff
1039 */ 1059 */
1040 1060
1041const QString AccountViewItem::contextName="AccountViewItem"; 1061const QString AccountViewItem::contextName="AccountViewItem";
1042 1062
1043AccountViewItem::AccountViewItem( AccountView *parent ) 1063AccountViewItem::AccountViewItem( AccountView *parent )
1044 : QListViewItem( parent ) 1064 : QListViewItem( parent )
1045{ 1065{
1046 init(); 1066 init();
1047 m_Backlink = parent; 1067 m_Backlink = parent;
1048} 1068}
1049 1069
1050AccountViewItem::AccountViewItem( QListViewItem *parent) 1070AccountViewItem::AccountViewItem( QListViewItem *parent)
1051 : QListViewItem( parent),folder(0) 1071 : QListViewItem( parent),folder(0)
1052{ 1072{
1053 init(); 1073 init();
1054} 1074}
1055 1075
1056AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) 1076AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after )
1057 :QListViewItem( parent,after ),folder(0) 1077 :QListViewItem( parent,after ),folder(0)
1058{ 1078{
1059 init(); 1079 init();
1060} 1080}
1061 1081
1062AccountViewItem::AccountViewItem( const Opie::Core::OSmartPointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after ) 1082AccountViewItem::AccountViewItem( const Opie::Core::OSmartPointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after )
1063 :QListViewItem( parent,after ),folder(folderInit) 1083 :QListViewItem( parent,after ),folder(folderInit)
1064{ 1084{
1065 init(); 1085 init();
1066} 1086}
1067 1087
1068void AccountViewItem::init() 1088void AccountViewItem::init()
1069{ 1089{
1070 m_Backlink = 0; 1090 m_Backlink = 0;
1071} 1091}
1072 1092
1073AccountViewItem::~AccountViewItem() 1093AccountViewItem::~AccountViewItem()
1074{ 1094{
1075 folder = 0; 1095 folder = 0;
1076} 1096}
1077 1097
1078AccountView*AccountViewItem::accountView() 1098AccountView*AccountViewItem::accountView()
1079{ 1099{
1080 return m_Backlink; 1100 return m_Backlink;
1081} 1101}
1082 1102
1083void AccountViewItem::deleteAllMail(AbstractMail*wrapper,const FolderP&folder) 1103void AccountViewItem::deleteAllMail(AbstractMail*wrapper,const FolderP&folder)
1084{ 1104{
1085 if (!wrapper) return; 1105 if (!wrapper) return;
1086 QString fname=""; 1106 QString fname="";
1087 if (folder) fname = folder->getDisplayName(); 1107 if (folder) fname = folder->getDisplayName();
1088 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), 1108 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
1089 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). 1109 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).
1090 arg(fname), 1110 arg(fname),
1091 QObject::tr("Yes",contextName), 1111 QObject::tr("Yes",contextName),
1092 QObject::tr("No",contextName),QString::null,1,1); 1112 QObject::tr("No",contextName),QString::null,1,1);
1093 1113
1094 if (yesno == 0) 1114 if (yesno == 0)
1095 { 1115 {
1096 if (wrapper->deleteAllMail(folder)) 1116 if (wrapper->deleteAllMail(folder))
1097 { 1117 {
1098 AccountView * view = (AccountView*)listView(); 1118 AccountView * view = (AccountView*)listView();
1099 if (view) view->refreshCurrent(); 1119 if (view) view->refreshCurrent();
1100 } 1120 }
1101 } 1121 }
1102} 1122}
1103 1123
1104void AccountViewItem::removeChilds() 1124void AccountViewItem::removeChilds()
1105{ 1125{
1106 QListViewItem *child = firstChild(); 1126 QListViewItem *child = firstChild();
1107 while ( child ) 1127 while ( child )
1108 { 1128 {
1109 QListViewItem *tmp = child; 1129 QListViewItem *tmp = child;
1110 child = child->nextSibling(); 1130 child = child->nextSibling();
1111 delete tmp; 1131 delete tmp;
1112 } 1132 }
1113} 1133}
1114 1134
1115bool AccountViewItem::matchName(const QString&name)const 1135bool AccountViewItem::matchName(const QString&name)const
1116{ 1136{
1117 if (!folder) return false; 1137 if (!folder) return false;
1118 return folder->getDisplayName().lower()==name.lower(); 1138 return folder->getDisplayName().lower()==name.lower();
1119} 1139}
1120 1140
1121 1141
1122AccountViewItem*AccountViewItem::findSubItem(const QString&path,AccountViewItem*start) 1142AccountViewItem*AccountViewItem::findSubItem(const QString&path,AccountViewItem*start)
1123{ 1143{
1124 AccountViewItem*pitem,*sitem; 1144 AccountViewItem*pitem,*sitem;
1125 if (!start) pitem = (AccountViewItem*)firstChild(); 1145 if (!start) pitem = (AccountViewItem*)firstChild();
1126 else pitem = (AccountViewItem*)start->firstChild(); 1146 else pitem = (AccountViewItem*)start->firstChild();
1127 while (pitem) 1147 while (pitem)
1128 { 1148 {
1129 if (pitem->matchName(path)) 1149 if (pitem->matchName(path))
1130 { 1150 {
1131 break; 1151 break;
1132 } 1152 }
1133 if (pitem->childCount()>0) 1153 if (pitem->childCount()>0)
1134 { 1154 {
1135 sitem = findSubItem(path,pitem); 1155 sitem = findSubItem(path,pitem);
1136 if (sitem) 1156 if (sitem)
1137 { 1157 {
1138 pitem = sitem; 1158 pitem = sitem;
1139 break; 1159 break;
1140 } 1160 }
1141 } 1161 }
1142 pitem=(AccountViewItem*)pitem->nextSibling(); 1162 pitem=(AccountViewItem*)pitem->nextSibling();
1143 } 1163 }
1144 return pitem; 1164 return pitem;
1145} 1165}
1146 1166
1147bool AccountViewItem::isDraftfolder() 1167bool AccountViewItem::isDraftfolder()
1148{ 1168{
1149 return false; 1169 return false;
1150} 1170}
diff --git a/kmicromail/accountview.cpp b/kmicromail/accountview.cpp
index 85523b1..de8c5bb 100644
--- a/kmicromail/accountview.cpp
+++ b/kmicromail/accountview.cpp
@@ -1,203 +1,206 @@
1 1
2#include "accountview.h" 2#include "accountview.h"
3#include "accountitem.h" 3#include "accountitem.h"
4#include "selectstore.h" 4#include "selectstore.h"
5 5
6#include <libmailwrapper/settings.h> 6#include <libmailwrapper/settings.h>
7#include <libmailwrapper/mailwrapper.h> 7#include <libmailwrapper/mailwrapper.h>
8#include <libmailwrapper/mailtypes.h> 8#include <libmailwrapper/mailtypes.h>
9#include <libmailwrapper/abstractmail.h> 9#include <libmailwrapper/abstractmail.h>
10 10
11/* OPIE */ 11/* OPIE */
12#include <qpe/qpeapplication.h> 12#include <qpe/qpeapplication.h>
13 13
14/* QT */ 14/* QT */
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16#include <qpopupmenu.h> 16#include <qpopupmenu.h>
17#include <qcheckbox.h> 17#include <qcheckbox.h>
18#include <qspinbox.h> 18#include <qspinbox.h>
19 19
20using namespace Opie::Core; 20using namespace Opie::Core;
21AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 21AccountView::AccountView( QWidget *parent, const char *name, WFlags flags )
22 : QListView( parent, name, flags ) 22 : QListView( parent, name, flags )
23{ 23{
24 connect( this, SIGNAL( selectionChanged(QListViewItem*) ), 24 connect( this, SIGNAL( selectionChanged(QListViewItem*) ),
25 SLOT( refresh(QListViewItem*) ) ); 25 SLOT( refresh(QListViewItem*) ) );
26 connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, 26 connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this,
27 SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) ); 27 SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) );
28 setSorting(0); 28 setSorting(0);
29} 29}
30 30
31AccountView::~AccountView() 31AccountView::~AccountView()
32{ 32{
33 imapAccounts.clear(); 33 imapAccounts.clear();
34 mhAccounts.clear(); 34 mhAccounts.clear();
35} 35}
36 36
37void AccountView::slotContextMenu(int id) 37void AccountView::slotContextMenu(int id)
38{ 38{
39 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 39 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
40 if (!view) return; 40 if (!view) return;
41 view->contextMenuSelected(id); 41 view->contextMenuSelected(id);
42} 42}
43 43
44void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) 44void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int)
45{ 45{
46 if (button==1) {return;} 46 if (button==1) {return;}
47 if (!item) return; 47 if (!item) return;
48 AccountViewItem *view = static_cast<AccountViewItem *>(item); 48 AccountViewItem *view = static_cast<AccountViewItem *>(item);
49 QPopupMenu*m = view->getContextMenu(); 49 QPopupMenu*m = view->getContextMenu();
50 if (!m) return; 50 if (!m) return;
51 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); 51 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int)));
52 m->setFocus(); 52 m->setFocus();
53 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 53 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
54 delete m; 54 delete m;
55} 55}
56 56
57void AccountView::populate( QList<Account> list ) 57void AccountView::populate( QList<Account> list )
58{ 58{
59 clear(); 59 clear();
60 60
61 imapAccounts.clear(); 61 imapAccounts.clear();
62 mhAccounts.clear(); 62 mhAccounts.clear();
63 63
64 mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this)); 64 mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this));
65 65
66 Account *it; 66 Account *it;
67 for ( it = list.first(); it; it = list.next() ) 67 for ( it = list.first(); it; it = list.next() )
68 { 68 {
69 if ( it->getType() == MAILLIB::A_IMAP ) 69 if ( it->getType() == MAILLIB::A_IMAP )
70 { 70 {
71 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 71 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
72 imapAccounts.append(new IMAPviewItem( imap, this )); 72 imapAccounts.append(new IMAPviewItem( imap, this ));
73 } 73 }
74 else if ( it->getType() == MAILLIB::A_POP3 ) 74 else if ( it->getType() == MAILLIB::A_POP3 )
75 { 75 {
76 POP3account *pop3 = static_cast<POP3account *>(it); 76 POP3account *pop3 = static_cast<POP3account *>(it);
77 /* must not be hold 'cause it isn't required */ 77 /* must not be hold 'cause it isn't required */
78 (void) new POP3viewItem( pop3, this ); 78 (void) new POP3viewItem( pop3, this );
79 } 79 }
80 else if ( it->getType() == MAILLIB::A_NNTP ) 80 else if ( it->getType() == MAILLIB::A_NNTP )
81 { 81 {
82 NNTPaccount *nntp = static_cast<NNTPaccount *>(it); 82 NNTPaccount *nntp = static_cast<NNTPaccount *>(it);
83 /* must not be hold 'cause it isn't required */ 83 /* must not be hold 'cause it isn't required */
84 (void) new NNTPviewItem( nntp, this ); 84 (void) new NNTPviewItem( nntp, this );
85 } 85 }
86 } 86 }
87} 87}
88 88
89void AccountView::refresh(QListViewItem *item) 89void AccountView::refresh(QListViewItem *item)
90{ 90{
91 if ( item ) 91 if ( item )
92 { 92 {
93 m_currentItem = item; 93 m_currentItem = item;
94 QValueList<RecMailP> headerlist; 94 QValueList<RecMailP> headerlist;
95 AccountViewItem *view = static_cast<AccountViewItem *>(item); 95 AccountViewItem *view = static_cast<AccountViewItem *>(item);
96 view->refresh(headerlist); 96 view->refresh(headerlist);
97 emit refreshMailview(headerlist); 97 emit refreshMailview(headerlist);
98 } 98 }
99} 99}
100 100
101void AccountView::refreshCurrent() 101void AccountView::refreshCurrent()
102{ 102{
103 m_currentItem = currentItem(); 103 m_currentItem = currentItem();
104 if ( !m_currentItem ) return; 104 if ( !m_currentItem ) return;
105 QValueList<RecMailP> headerlist; 105 QValueList<RecMailP> headerlist;
106 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 106 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
107 view->refresh(headerlist); 107 view->refresh(headerlist);
108 emit refreshMailview(headerlist); 108 emit refreshMailview(headerlist);
109} 109}
110 110
111void AccountView::refreshAll() 111void AccountView::refreshAll()
112{ 112{
113} 113}
114 114
115RecBodyP AccountView::fetchBody(const RecMailP&aMail) 115RecBodyP AccountView::fetchBody(const RecMailP&aMail)
116{ 116{
117 QListViewItem*item = selectedItem (); 117 QListViewItem*item = selectedItem ();
118 if (!item) return new RecBody(); 118 if (!item) return new RecBody();
119 AccountViewItem *view = static_cast<AccountViewItem *>(item); 119 AccountViewItem *view = static_cast<AccountViewItem *>(item);
120 return view->fetchBody(aMail); 120 return view->fetchBody(aMail);
121} 121}
122 122
123void AccountView::setupFolderselect(Selectstore*sels) 123void AccountView::setupFolderselect(Selectstore*sels)
124{ 124{
125 sels->showMaximized(); 125 sels->showMaximized();
126 QStringList sFolders; 126 QStringList sFolders;
127 unsigned int i = 0; 127 unsigned int i = 0;
128 for (i=0; i < mhAccounts.count();++i) 128 for (i=0; i < mhAccounts.count();++i)
129 { 129 {
130 mhAccounts[i]->refresh(false); 130 mhAccounts[i]->refresh(false);
131 sFolders = mhAccounts[i]->subFolders(); 131 sFolders = mhAccounts[i]->subFolders();
132 sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); 132 sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders);
133 } 133 }
134 for (i=0; i < imapAccounts.count();++i) 134 for (i=0; i < imapAccounts.count();++i)
135 { 135 {
136 if (imapAccounts[i]->offline()) 136 if (imapAccounts[i]->offline())
137 continue; 137 continue;
138 imapAccounts[i]->refreshFolders(false); 138 imapAccounts[i]->refreshFolders(false);
139 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); 139 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders());
140 } 140 }
141} 141}
142void AccountView::downloadMailsInbox(const FolderP&fromFolder,AbstractMail*fromWrapper) 142void AccountView::downloadMailsInbox(const FolderP&fromFolder,AbstractMail*fromWrapper)
143{ 143{
144#if 0
144 AbstractMail*targetMail = 0; 145 AbstractMail*targetMail = 0;
145 QString targetFolder = ""; 146 QString targetFolder = "";
146 Selectstore sels; 147 Selectstore sels;
147 setupFolderselect(&sels); 148 setupFolderselect(&sels);
148 if (!sels.exec()) return; 149 if (!sels.exec()) return;
149 targetMail = sels.currentMail(); 150 targetMail = sels.currentMail();
150 targetFolder = sels.currentFolder(); 151 targetFolder = sels.currentFolder();
151 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || 152 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) ||
152 targetFolder.isEmpty()) 153 targetFolder.isEmpty())
153 { 154 {
154 return; 155 return;
155 } 156 }
156 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 157 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
157 { 158 {
158 QMessageBox::critical(0,tr("Error creating new Folder"), 159 QMessageBox::critical(0,tr("Error creating new Folder"),
159 tr("<center>Error while creating<br>new folder - breaking.</center>")); 160 tr("<center>Error while creating<br>new folder - breaking.</center>"));
160 return; 161 return;
161 } 162 }
162 int maxsize = 0; 163 int maxsize = 0;
163 if ( sels.useSize->isChecked()) 164 if ( sels.useSize->isChecked())
164 maxsize = sels.sizeSpinBox->value(); 165 maxsize = sels.sizeSpinBox->value();
165
166 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize); 166 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize);
167#endif
168 fromWrapper->downloadNewMails( fromFolder, mhAccounts[0]->getWrapper());
167 refreshCurrent(); 169 refreshCurrent();
170
168} 171}
169 172
170void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper) 173void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper)
171{ 174{
172 AbstractMail*targetMail = 0; 175 AbstractMail*targetMail = 0;
173 QString targetFolder = ""; 176 QString targetFolder = "";
174 Selectstore sels; 177 Selectstore sels;
175 setupFolderselect(&sels); 178 setupFolderselect(&sels);
176 if (!sels.exec()) return; 179 if (!sels.exec()) return;
177 targetMail = sels.currentMail(); 180 targetMail = sels.currentMail();
178 targetFolder = sels.currentFolder(); 181 targetFolder = sels.currentFolder();
179 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || 182 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) ||
180 targetFolder.isEmpty()) 183 targetFolder.isEmpty())
181 { 184 {
182 return; 185 return;
183 } 186 }
184 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 187 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
185 { 188 {
186 QMessageBox::critical(0,tr("Error creating new Folder"), 189 QMessageBox::critical(0,tr("Error creating new Folder"),
187 tr("<center>Error while creating<br>new folder - breaking.</center>")); 190 tr("<center>Error while creating<br>new folder - breaking.</center>"));
188 return; 191 return;
189 } 192 }
190 int maxsize = 0; 193 int maxsize = 0;
191 if ( sels.useSize->isChecked()) 194 if ( sels.useSize->isChecked())
192 maxsize = sels.sizeSpinBox->value(); 195 maxsize = sels.sizeSpinBox->value();
193 196
194 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize); 197 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize);
195 refreshCurrent(); 198 refreshCurrent();
196} 199}
197 200
198bool AccountView::currentisDraft() 201bool AccountView::currentisDraft()
199{ 202{
200 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 203 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
201 if (!view) return false; 204 if (!view) return false;
202 return view->isDraftfolder(); 205 return view->isDraftfolder();
203} 206}
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index f876235..374d606 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -1,210 +1,277 @@
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 14
14#include <kdecore/kstandarddirs.h> 15#include <kdecore/kstandarddirs.h>
15#include <qfile.h> 16#include <qfile.h>
16#include <qtextstream.h> 17#include <qtextstream.h>
17#include <stdlib.h> 18#include <stdlib.h>
18#include <libetpan/mailmime_content.h> 19#include <libetpan/mailmime_content.h>
19#include <libetpan/mailmime.h> 20#include <libetpan/mailmime.h>
20 21
21using namespace Opie::Core; 22using namespace Opie::Core;
22AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 23AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
23{ 24{
24 return new IMAPwrapper(a); 25 return new IMAPwrapper(a);
25} 26}
26 27
27AbstractMail* AbstractMail::getWrapper(POP3account *a) 28AbstractMail* AbstractMail::getWrapper(POP3account *a)
28{ 29{
29 return new POP3wrapper(a); 30 return new POP3wrapper(a);
30} 31}
31 32
32AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 33AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
33{ 34{
34 return new NNTPwrapper(a); 35 return new NNTPwrapper(a);
35} 36}
36 37
37AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 38AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
38{ 39{
39 return new MHwrapper(a,name); 40 return new MHwrapper(a,name);
40} 41}
41 42
42AbstractMail* AbstractMail::getWrapper(Account*a) 43AbstractMail* AbstractMail::getWrapper(Account*a)
43{ 44{
44 if (!a) return 0; 45 if (!a) return 0;
45 switch (a->getType()) { 46 switch (a->getType()) {
46 case MAILLIB::A_IMAP: 47 case MAILLIB::A_IMAP:
47 return new IMAPwrapper((IMAPaccount*)a); 48 return new IMAPwrapper((IMAPaccount*)a);
48 break; 49 break;
49 case MAILLIB::A_POP3: 50 case MAILLIB::A_POP3:
50 return new POP3wrapper((POP3account*)a); 51 return new POP3wrapper((POP3account*)a);
51 break; 52 break;
52 case MAILLIB::A_NNTP: 53 case MAILLIB::A_NNTP:
53 return new NNTPwrapper((NNTPaccount*)a); 54 return new NNTPwrapper((NNTPaccount*)a);
54 break; 55 break;
55 default: 56 default:
56 return 0; 57 return 0;
57 } 58 }
58} 59}
59 60
60encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 61encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
61{ 62{
62 // odebug << "Decode string start" << oendl; 63 // odebug << "Decode string start" << oendl;
63 char*result_text; 64 char*result_text;
64 size_t index = 0; 65 size_t index = 0;
65 /* reset for recursive use! */ 66 /* reset for recursive use! */
66 size_t target_length = 0; 67 size_t target_length = 0;
67 result_text = 0; 68 result_text = 0;
68 int mimetype = MAILMIME_MECHANISM_7BIT; 69 int mimetype = MAILMIME_MECHANISM_7BIT;
69 if (enc.lower()=="quoted-printable") { 70 if (enc.lower()=="quoted-printable") {
70 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 71 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
71 } else if (enc.lower()=="base64") { 72 } else if (enc.lower()=="base64") {
72 mimetype = MAILMIME_MECHANISM_BASE64; 73 mimetype = MAILMIME_MECHANISM_BASE64;
73 } else if (enc.lower()=="8bit") { 74 } else if (enc.lower()=="8bit") {
74 mimetype = MAILMIME_MECHANISM_8BIT; 75 mimetype = MAILMIME_MECHANISM_8BIT;
75 } else if (enc.lower()=="binary") { 76 } else if (enc.lower()=="binary") {
76 mimetype = MAILMIME_MECHANISM_BINARY; 77 mimetype = MAILMIME_MECHANISM_BINARY;
77 } 78 }
78 79
79 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 80 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
80 &result_text,&target_length); 81 &result_text,&target_length);
81 82
82 encodedString* result = new encodedString(); 83 encodedString* result = new encodedString();
83 if (err == MAILIMF_NO_ERROR) { 84 if (err == MAILIMF_NO_ERROR) {
84 result->setContent(result_text,target_length); 85 result->setContent(result_text,target_length);
85 } 86 }
86 //odebug << "Decode string finished" << oendl; 87 //odebug << "Decode string finished" << oendl;
87 return result; 88 return result;
88} 89}
89 90
90QString AbstractMail::convert_String(const char*text) 91QString AbstractMail::convert_String(const char*text)
91{ 92{
92 //size_t index = 0; 93 //size_t index = 0;
93 char*res = 0; 94 char*res = 0;
94 int err = MAILIMF_NO_ERROR; 95 int err = MAILIMF_NO_ERROR;
95 96
96 QString result(text); 97 QString result(text);
97 98
98 /* due a bug in libetpan it isn't usable this moment */ 99 /* due a bug in libetpan it isn't usable this moment */
99/* int err = mailmime_encoded_phrase_parse("iso-8859-1", 100/* int err = mailmime_encoded_phrase_parse("iso-8859-1",
100 text, strlen(text),&index, "iso-8859-1",&res);*/ 101 text, strlen(text),&index, "iso-8859-1",&res);*/
101 //odebug << "Input: " << text << "" << oendl; 102 //odebug << "Input: " << text << "" << oendl;
102 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 103 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
103// result = QString(res); 104// result = QString(res);
104// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; 105// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl;
105 } 106 }
106 if (res) free(res); 107 if (res) free(res);
107 return result; 108 return result;
108} 109}
109 110
110/* cp & paste from launcher */ 111/* cp & paste from launcher */
111QString AbstractMail::gen_attachment_id() 112QString AbstractMail::gen_attachment_id()
112{ 113{
113 QFile file( "/proc/sys/kernel/random/uuid" ); 114 QFile file( "/proc/sys/kernel/random/uuid" );
114 if (!file.open(IO_ReadOnly ) ) 115 if (!file.open(IO_ReadOnly ) )
115 return QString::null; 116 return QString::null;
116 117
117 QTextStream stream(&file); 118 QTextStream stream(&file);
118 119
119 return "{" + stream.read().stripWhiteSpace() + "}"; 120 return "{" + stream.read().stripWhiteSpace() + "}";
120} 121}
121 122
122int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) 123int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
123{ 124{
124 return 0; 125 return 0;
125} 126}
126 127
127QString AbstractMail::defaultLocalfolder() 128QString AbstractMail::defaultLocalfolder()
128{ 129{
129 // QString f = getenv( "HOME" ); 130 // QString f = getenv( "HOME" );
130 QString f = locateLocal( "data", "kopiemail/localmail"); 131 QString f = locateLocal( "data", "kopiemail/localmail");
131 // f += "/Applications/opiemail/localmail"; 132 // f += "/Applications/opiemail/localmail";
132 return f; 133 return f;
133} 134}
134 135
135QString AbstractMail::draftFolder() 136QString AbstractMail::draftFolder()
136{ 137{
137 return QString("Drafts"); 138 return QString("Drafts");
138} 139}
139 140
140/* temporary - will be removed when implemented in all classes */ 141/* temporary - will be removed when implemented in all classes */
141void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) 142void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &)
142{ 143{
143} 144}
144void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) 145void AbstractMail::deleteMailList(const QValueList<RecMailP>&target)
145{ 146{
146 //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); 147 //qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
147 // this is currently re-implemented in pop3wrapper and imapwrapper 148 // this is currently re-implemented in pop3wrapper and imapwrapper
148 int iii = 0; 149 int iii = 0;
149 int count = target.count(); 150 int count = target.count();
150 QWidget wid; 151 QWidget wid;
151 wid.show(); 152 wid.show();
152 while (iii < count ) { 153 while (iii < count ) {
153 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); 154 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count));
154 wid.raise(); 155 wid.raise();
155 qApp->processEvents(); 156 qApp->processEvents();
156 RecMailP mail = (*target.at( iii )); 157 RecMailP mail = (*target.at( iii ));
157 deleteMail(mail); 158 deleteMail(mail);
158 ++iii; 159 ++iii;
159 } 160 }
160} 161}
162
163void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail )
164{
165 qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1());
166 // get local folder
167 Account * acc = getAccount();
168 if ( !acc ) return;
169 QString lfName = acc->getLocalFolder();
170 if ( lfName.isEmpty() )
171 lfName = acc->getAccountName();
172 // create local folder
173 if ( !targetMail->createMbox(lfName))
174 {
175 QMessageBox::critical(0,tr("Error creating new Folder"),
176 tr("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName));
177 return;
178 }
179 QValueList<RecMailP> t;
180 listMessages(fromFolder->getName(),t,acc->getMaxMailSize() );
181 if ( t.count() == 0 ) {
182 Global::statusMessage(tr("There are no new messages"));
183 return;
184 }
185 QValueList<RecMailP> e;
186 targetMail->listMessages(lfName,e,acc->getMaxMailSize() );
187 qDebug("target has mails %d ", e.count());
188 QValueList<RecMailP> n;
189 int iii = 0;
190 int count = t.count();
191 while (iii < count ) {
192 RecMailP r = (*t.at( iii ));
193 bool found = false;
194 int jjj = 0;
195 int countE = e.count();
196 while (jjj < countE ) {
197 RecMailP re = (*e.at( jjj ));
198 if ( re->isEqual(r) ) {
199 found = true;
200 break;
201 }
202 ++jjj;
203 }
204 if ( found )
205 qDebug("found ");
206 else
207 qDebug("NOT found ");
208
209 if ( !found ) {
210 n.append( r );
211 }
212 ++iii;
213 }
214 if ( n.count() == 0 ) {
215 Global::statusMessage(tr("There are no new messages"));
216 return;
217 }
218 mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer());
219
220
221#if 0
222 QValueList<RecMailP> t;
223 listMessages(fromFolder->getName(),t, maxSizeInKb);
224 mvcpMailList( t,targetFolder,targetWrapper,moveit);
225#endif
226
227}
161void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 228void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
162 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 229 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
163{ 230{
164 QValueList<RecMailP> t; 231 QValueList<RecMailP> t;
165 listMessages(fromFolder->getName(),t, maxSizeInKb); 232 listMessages(fromFolder->getName(),t, maxSizeInKb);
166 mvcpMailList( t,targetFolder,targetWrapper,moveit); 233 mvcpMailList( t,targetFolder,targetWrapper,moveit);
167 234
168} 235}
169void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, 236void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t,
170 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 237 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
171{ 238{
172 encodedString*st = 0; 239 encodedString*st = 0;
173 int iii = 0; 240 int iii = 0;
174 int count = t.count(); 241 int count = t.count();
175 if ( count == 0 ) 242 if ( count == 0 )
176 return; 243 return;
177 // wel, processevents is qite strange, we need a widget for getting 244 // wel, processevents is qite strange, we need a widget for getting
178 // Global::statusMessage(tr("Copy2 message %1").arg(iii)); displayed 245 // Global::statusMessage(tr("Copy2 message %1").arg(iii)); displayed
179 QWidget wid; 246 QWidget wid;
180 wid.show(); 247 wid.show();
181 while (iii < count ) { 248 while (iii < count ) {
182 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));
183 wid.raise(); 250 wid.raise();
184 qApp->processEvents(); 251 qApp->processEvents();
185 RecMailP r = (*t.at( iii )); 252 RecMailP r = (*t.at( iii ));
186 st = fetchRawBody(r); 253 st = fetchRawBody(r);
187 if (st) { 254 if (st) {
188 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 255 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
189 delete st; 256 delete st;
190 } 257 }
191 ++iii; 258 ++iii;
192 } 259 }
193 if (moveit) { 260 if (moveit) {
194 deleteMailList( t ); 261 deleteMailList( t );
195 //deleteAllMail(fromFolder); 262 //deleteAllMail(fromFolder);
196 } 263 }
197} 264}
198 265
199void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 266void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
200{ 267{
201 encodedString*st = 0; 268 encodedString*st = 0;
202 st = fetchRawBody(mail); 269 st = fetchRawBody(mail);
203 if (st) { 270 if (st) {
204 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 271 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
205 delete st; 272 delete st;
206 } 273 }
207 if (moveit) { 274 if (moveit) {
208 deleteMail(mail); 275 deleteMail(mail);
209 } 276 }
210} 277}
diff --git a/kmicromail/libmailwrapper/abstractmail.h b/kmicromail/libmailwrapper/abstractmail.h
index cae83f4..2069ca1 100644
--- a/kmicromail/libmailwrapper/abstractmail.h
+++ b/kmicromail/libmailwrapper/abstractmail.h
@@ -1,76 +1,81 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __abstract_mail_ 2#ifndef __abstract_mail_
3#define __abstract_mail_ 3#define __abstract_mail_
4 4
5#include "maildefines.h" 5#include "maildefines.h"
6 6
7#include "settings.h" 7#include "settings.h"
8 8
9#include <qobject.h> 9#include <qobject.h>
10#include <opie2/osmartpointer.h> 10#include <opie2/osmartpointer.h>
11#include "mailtypes.h" 11#include "mailtypes.h"
12 12
13
14#include "mailwrapper.h"
15
13class IMAPwrapper; 16class IMAPwrapper;
14class POP3wrapper; 17class POP3wrapper;
15class Folder; 18class Folder;
16class encodedString; 19class encodedString;
17struct folderStat; 20struct folderStat;
18 21
19class AbstractMail:public QObject 22class AbstractMail:public QObject
20{ 23{
21 Q_OBJECT 24 Q_OBJECT
22public: 25public:
23 AbstractMail(){}; 26 AbstractMail(){};
24 virtual ~AbstractMail(){} 27 virtual ~AbstractMail(){}
25 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders()=0; 28 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders()=0;
26 virtual void listMessages(const QString & mailbox,QValueList<RecMailP>&target, int sizeInKb = 0 )=0; 29 virtual void listMessages(const QString & mailbox,QValueList<RecMailP>&target, int sizeInKb = 0 )=0;
27 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; 30 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0;
28 virtual RecBodyP fetchBody(const RecMailP&mail)=0; 31 virtual RecBodyP fetchBody(const RecMailP&mail)=0;
29 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part)=0; 32 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part)=0;
30 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part)=0; 33 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part)=0;
31 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part)=0; 34 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part)=0;
32 virtual encodedString* fetchRawBody(const RecMailP&mail)=0; 35 virtual encodedString* fetchRawBody(const RecMailP&mail)=0;
33 36
34 virtual void deleteMail(const RecMailP&mail)=0; 37 virtual void deleteMail(const RecMailP&mail)=0;
35 virtual void deleteMailList(const QValueList<RecMailP>&target); 38 virtual void deleteMailList(const QValueList<RecMailP>&target);
36 virtual void answeredMail(const RecMailP&mail)=0; 39 virtual void answeredMail(const RecMailP&mail)=0;
37 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&)=0; 40 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&)=0;
38 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> >&target); 41 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> >&target);
39 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&)=0; 42 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&)=0;
40 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; 43 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0;
41 44 void downloadNewMails(const FolderP&fromFolder,AbstractMail*targetWrapper );
42 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, 45 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,
43 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int sizeInKb = 0); 46 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int sizeInKb = 0);
44 virtual void mvcpMailList(const QValueList<RecMailP>& t, 47 virtual void mvcpMailList(const QValueList<RecMailP>& t,
45 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 48 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
46 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 49 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
47 50
48 virtual void cleanMimeCache(){}; 51 virtual void cleanMimeCache(){};
49 /* mail box methods */ 52 /* mail box methods */
50 /* parameter is the box to create. 53 /* parameter is the box to create.
51 * if the implementing subclass has prefixes, 54 * if the implementing subclass has prefixes,
52 * them has to be appended automatic. 55 * them has to be appended automatic.
53 */ 56 */
54 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, 57 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0,
55 const QString& delemiter="/",bool getsubfolder=false); 58 const QString& delemiter="/",bool getsubfolder=false);
56 virtual void logout()=0; 59 virtual void logout()=0;
57 60
61 virtual Account* getAccount() = 0;
62
58 static AbstractMail* getWrapper(IMAPaccount *a); 63 static AbstractMail* getWrapper(IMAPaccount *a);
59 static AbstractMail* getWrapper(POP3account *a); 64 static AbstractMail* getWrapper(POP3account *a);
60 static AbstractMail* getWrapper(NNTPaccount *a); 65 static AbstractMail* getWrapper(NNTPaccount *a);
61 /* mbox only! */ 66 /* mbox only! */
62 static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders"); 67 static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders");
63 static AbstractMail* getWrapper(Account*a); 68 static AbstractMail* getWrapper(Account*a);
64 69
65 static QString defaultLocalfolder(); 70 static QString defaultLocalfolder();
66 static QString draftFolder(); 71 static QString draftFolder();
67 72
68 virtual MAILLIB::ATYPE getType()const=0; 73 virtual MAILLIB::ATYPE getType()const=0;
69 virtual const QString&getName()const=0; 74 virtual const QString&getName()const=0;
70 75
71protected: 76protected:
72 static encodedString*decode_String(const encodedString*text,const QString&enc); 77 static encodedString*decode_String(const encodedString*text,const QString&enc);
73 static QString convert_String(const char*text); 78 static QString convert_String(const char*text);
74 static QString gen_attachment_id(); 79 static QString gen_attachment_id();
75}; 80};
76#endif 81#endif
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp
index 9614d53..2b04847 100644
--- a/kmicromail/libmailwrapper/genericwrapper.cpp
+++ b/kmicromail/libmailwrapper/genericwrapper.cpp
@@ -1,481 +1,521 @@
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>
7#include <kglobal.h>
8#include <kstandarddirs.h>
6 9
7 10
8using namespace Opie::Core; 11using namespace Opie::Core;
9Genericwrapper::Genericwrapper() 12Genericwrapper::Genericwrapper()
10 : AbstractMail() 13 : AbstractMail()
11{ 14{
12 bodyCache.clear(); 15 bodyCache.clear();
13 m_storage = 0; 16 m_storage = 0;
14 m_folder = 0; 17 m_folder = 0;
15} 18}
16 19
17Genericwrapper::~Genericwrapper() 20Genericwrapper::~Genericwrapper()
18{ 21{
19 if (m_folder) { 22 if (m_folder) {
20 mailfolder_free(m_folder); 23 mailfolder_free(m_folder);
21 } 24 }
22 if (m_storage) { 25 if (m_storage) {
23 mailstorage_free(m_storage); 26 mailstorage_free(m_storage);
24 } 27 }
25 cleanMimeCache(); 28 cleanMimeCache();
26} 29}
30QString Genericwrapper::parseDateTime( mailimf_date_time *date )
31{
32 static bool init = false ;
33 if ( ! init ) {
34 KConfig kon ( locateLocal( "config", "korganizerrc" ) );
35 kon.setGroup("Locale");
36 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)kon.readNumEntry( "PreferredDate",0) );
37 QString dummy = kon.readEntry( "UserDateFormatShort","%aK %d.%m.%y" );// kon.readEntry( "");
38 KGlobal::locale()->setHore24Format( !kon.readBoolEntry( "PreferredTime",0 ) );
39 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
40 kon.setGroup("Time & Date");
41 KGlobal::locale()->setDaylightSaving( kon.readBoolEntry( "UseDaylightsaving", true ),
42 kon.readNumEntry( "DaylightsavingStart", 90),
43 kon.readNumEntry( "DaylightsavingEnd",304) );
44 KGlobal::locale()->setTimezone( kon.readEntry( "TimeZoneName" ," 00:00 Europe/London(UTC)") );
45
46 init = true;
47
48 }
49 QDateTime dt (QDate(date->dt_year,date->dt_month, date->dt_day ),QTime(date->dt_hour, date->dt_min, date->dt_sec ) );
50 int off = KGlobal::locale()->localTimeOffset( dt );
51 dt = dt.addSecs( off*60 );
52 QString ret = KGlobal::locale()->formatDateTime( dt,true,true);
53 if ( off < 0 )
54 ret += " -";
55 else
56 ret += " +";
57 ret += QString::number( off / 60 );
58 ret += "h";
59#if 0
60 char tmp[23];
61
62 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
63 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
64 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i",
65 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
66
67
68 return QString( tmp );
69#endif
70 return ret;
71}
27 72
28void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) 73void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime)
29{ 74{
30 if (!mime) { 75 if (!mime) {
31 return; 76 return;
32 } 77 }
33 mailmime_field*field = 0; 78 mailmime_field*field = 0;
34 mailmime_single_fields fields; 79 mailmime_single_fields fields;
35 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 80 memset(&fields, 0, sizeof(struct mailmime_single_fields));
36 if (mime->mm_mime_fields != NULL) { 81 if (mime->mm_mime_fields != NULL) {
37 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 82 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
38 mime->mm_content_type); 83 mime->mm_content_type);
39 } 84 }
40 85
41 mailmime_content*type = fields.fld_content; 86 mailmime_content*type = fields.fld_content;
42 clistcell*current; 87 clistcell*current;
43 if (!type) { 88 if (!type) {
44 target->setType("text"); 89 target->setType("text");
45 target->setSubtype("plain"); 90 target->setSubtype("plain");
46 } else { 91 } else {
47 target->setSubtype(type->ct_subtype); 92 target->setSubtype(type->ct_subtype);
48 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 93 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
49 case MAILMIME_DISCRETE_TYPE_TEXT: 94 case MAILMIME_DISCRETE_TYPE_TEXT:
50 target->setType("text"); 95 target->setType("text");
51 break; 96 break;
52 case MAILMIME_DISCRETE_TYPE_IMAGE: 97 case MAILMIME_DISCRETE_TYPE_IMAGE:
53 target->setType("image"); 98 target->setType("image");
54 break; 99 break;
55 case MAILMIME_DISCRETE_TYPE_AUDIO: 100 case MAILMIME_DISCRETE_TYPE_AUDIO:
56 target->setType("audio"); 101 target->setType("audio");
57 break; 102 break;
58 case MAILMIME_DISCRETE_TYPE_VIDEO: 103 case MAILMIME_DISCRETE_TYPE_VIDEO:
59 target->setType("video"); 104 target->setType("video");
60 break; 105 break;
61 case MAILMIME_DISCRETE_TYPE_APPLICATION: 106 case MAILMIME_DISCRETE_TYPE_APPLICATION:
62 target->setType("application"); 107 target->setType("application");
63 break; 108 break;
64 case MAILMIME_DISCRETE_TYPE_EXTENSION: 109 case MAILMIME_DISCRETE_TYPE_EXTENSION:
65 default: 110 default:
66 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 111 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
67 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); 112 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
68 } 113 }
69 break; 114 break;
70 } 115 }
71 if (type->ct_parameters) { 116 if (type->ct_parameters) {
72 fillParameters(target,type->ct_parameters); 117 fillParameters(target,type->ct_parameters);
73 } 118 }
74 } 119 }
75 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 120 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
76 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { 121 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
77 field = (mailmime_field*)current->data; 122 field = (mailmime_field*)current->data;
78 switch(field->fld_type) { 123 switch(field->fld_type) {
79 case MAILMIME_FIELD_TRANSFER_ENCODING: 124 case MAILMIME_FIELD_TRANSFER_ENCODING:
80 target->setEncoding(getencoding(field->fld_data.fld_encoding)); 125 target->setEncoding(getencoding(field->fld_data.fld_encoding));
81 break; 126 break;
82 case MAILMIME_FIELD_ID: 127 case MAILMIME_FIELD_ID:
83 target->setIdentifier(field->fld_data.fld_id); 128 target->setIdentifier(field->fld_data.fld_id);
84 break; 129 break;
85 case MAILMIME_FIELD_DESCRIPTION: 130 case MAILMIME_FIELD_DESCRIPTION:
86 target->setDescription(field->fld_data.fld_description); 131 target->setDescription(field->fld_data.fld_description);
87 break; 132 break;
88 default: 133 default:
89 break; 134 break;
90 } 135 }
91 } 136 }
92 } 137 }
93} 138}
94 139
95void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) 140void Genericwrapper::fillParameters(RecPartP&target,clist*parameters)
96{ 141{
97 if (!parameters) {return;} 142 if (!parameters) {return;}
98 clistcell*current=0; 143 clistcell*current=0;
99 mailmime_parameter*param; 144 mailmime_parameter*param;
100 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 145 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
101 param = (mailmime_parameter*)current->data; 146 param = (mailmime_parameter*)current->data;
102 if (param) { 147 if (param) {
103 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 148 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
104 } 149 }
105 } 150 }
106} 151}
107 152
108QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 153QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
109{ 154{
110 QString enc="7bit"; 155 QString enc="7bit";
111 if (!aEnc) return enc; 156 if (!aEnc) return enc;
112 switch(aEnc->enc_type) { 157 switch(aEnc->enc_type) {
113 case MAILMIME_MECHANISM_7BIT: 158 case MAILMIME_MECHANISM_7BIT:
114 enc = "7bit"; 159 enc = "7bit";
115 break; 160 break;
116 case MAILMIME_MECHANISM_8BIT: 161 case MAILMIME_MECHANISM_8BIT:
117 enc = "8bit"; 162 enc = "8bit";
118 break; 163 break;
119 case MAILMIME_MECHANISM_BINARY: 164 case MAILMIME_MECHANISM_BINARY:
120 enc = "binary"; 165 enc = "binary";
121 break; 166 break;
122 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 167 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
123 enc = "quoted-printable"; 168 enc = "quoted-printable";
124 break; 169 break;
125 case MAILMIME_MECHANISM_BASE64: 170 case MAILMIME_MECHANISM_BASE64:
126 enc = "base64"; 171 enc = "base64";
127 break; 172 break;
128 case MAILMIME_MECHANISM_TOKEN: 173 case MAILMIME_MECHANISM_TOKEN:
129 default: 174 default:
130 if (aEnc->enc_token) { 175 if (aEnc->enc_token) {
131 enc = QString(aEnc->enc_token); 176 enc = QString(aEnc->enc_token);
132 } 177 }
133 break; 178 break;
134 } 179 }
135 return enc; 180 return enc;
136} 181}
137 182
138void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) 183void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count)
139{ 184{
140 if (current_rec >= 10) { 185 if (current_rec >= 10) {
141 ; // odebug << "too deep recursion!" << oendl; 186 ; // odebug << "too deep recursion!" << oendl;
142 } 187 }
143 if (!message || !mime) { 188 if (!message || !mime) {
144 return; 189 return;
145 } 190 }
146 int r; 191 int r;
147 char*data = 0; 192 char*data = 0;
148 size_t len; 193 size_t len;
149 clistiter * cur = 0; 194 clistiter * cur = 0;
150 QString b; 195 QString b;
151 RecPartP part = new RecPart(); 196 RecPartP part = new RecPart();
152 197
153 switch (mime->mm_type) { 198 switch (mime->mm_type) {
154 case MAILMIME_SINGLE: 199 case MAILMIME_SINGLE:
155 { 200 {
156 QValueList<int>countlist = recList; 201 QValueList<int>countlist = recList;
157 countlist.append(current_count); 202 countlist.append(current_count);
158 r = mailmessage_fetch_section(message,mime,&data,&len); 203 r = mailmessage_fetch_section(message,mime,&data,&len);
159 part->setSize(len); 204 part->setSize(len);
160 part->setPositionlist(countlist); 205 part->setPositionlist(countlist);
161 b = gen_attachment_id(); 206 b = gen_attachment_id();
162 part->setIdentifier(b); 207 part->setIdentifier(b);
163 fillSingleBody(part,message,mime); 208 fillSingleBody(part,message,mime);
164 if (part->Type()=="text" && target->Bodytext().isNull()) { 209 if (part->Type()=="text" && target->Bodytext().isNull()) {
165 encodedString*rs = new encodedString(); 210 encodedString*rs = new encodedString();
166 rs->setContent(data,len); 211 rs->setContent(data,len);
167 encodedString*res = decode_String(rs,part->Encoding()); 212 encodedString*res = decode_String(rs,part->Encoding());
168 if (countlist.count()>2) { 213 if (countlist.count()>2) {
169 bodyCache[b]=rs; 214 bodyCache[b]=rs;
170 target->addPart(part); 215 target->addPart(part);
171 } else { 216 } else {
172 delete rs; 217 delete rs;
173 } 218 }
174 b = QString(res->Content()); 219 b = QString(res->Content());
175 delete res; 220 delete res;
176 target->setBodytext(b); 221 target->setBodytext(b);
177 target->setDescription(part); 222 target->setDescription(part);
178 } else { 223 } else {
179 bodyCache[b]=new encodedString(data,len); 224 bodyCache[b]=new encodedString(data,len);
180 target->addPart(part); 225 target->addPart(part);
181 } 226 }
182 } 227 }
183 break; 228 break;
184 case MAILMIME_MULTIPLE: 229 case MAILMIME_MULTIPLE:
185 { 230 {
186 unsigned int ccount = 1; 231 unsigned int ccount = 1;
187 mailmime*cbody=0; 232 mailmime*cbody=0;
188 QValueList<int>countlist = recList; 233 QValueList<int>countlist = recList;
189 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 234 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
190 cbody = (mailmime*)clist_content(cur); 235 cbody = (mailmime*)clist_content(cur);
191 if (cbody->mm_type==MAILMIME_MULTIPLE) { 236 if (cbody->mm_type==MAILMIME_MULTIPLE) {
192 RecPartP targetPart = new RecPart(); 237 RecPartP targetPart = new RecPart();
193 targetPart->setType("multipart"); 238 targetPart->setType("multipart");
194 countlist.append(current_count); 239 countlist.append(current_count);
195 targetPart->setPositionlist(countlist); 240 targetPart->setPositionlist(countlist);
196 target->addPart(targetPart); 241 target->addPart(targetPart);
197 } 242 }
198 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 243 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
199 if (cbody->mm_type==MAILMIME_MULTIPLE) { 244 if (cbody->mm_type==MAILMIME_MULTIPLE) {
200 countlist = recList; 245 countlist = recList;
201 } 246 }
202 ++ccount; 247 ++ccount;
203 } 248 }
204 } 249 }
205 break; 250 break;
206 case MAILMIME_MESSAGE: 251 case MAILMIME_MESSAGE:
207 { 252 {
208 QValueList<int>countlist = recList; 253 QValueList<int>countlist = recList;
209 countlist.append(current_count); 254 countlist.append(current_count);
210 /* the own header is always at recursion 0 - we don't need that */ 255 /* the own header is always at recursion 0 - we don't need that */
211 if (current_rec > 0) { 256 if (current_rec > 0) {
212 part->setPositionlist(countlist); 257 part->setPositionlist(countlist);
213 r = mailmessage_fetch_section(message,mime,&data,&len); 258 r = mailmessage_fetch_section(message,mime,&data,&len);
214 part->setSize(len); 259 part->setSize(len);
215 part->setPositionlist(countlist); 260 part->setPositionlist(countlist);
216 b = gen_attachment_id(); 261 b = gen_attachment_id();
217 part->setIdentifier(b); 262 part->setIdentifier(b);
218 part->setType("message"); 263 part->setType("message");
219 part->setSubtype("rfc822"); 264 part->setSubtype("rfc822");
220 bodyCache[b]=new encodedString(data,len); 265 bodyCache[b]=new encodedString(data,len);
221 target->addPart(part); 266 target->addPart(part);
222 } 267 }
223 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 268 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
224 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 269 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
225 } 270 }
226 } 271 }
227 break; 272 break;
228 } 273 }
229} 274}
230 275
231RecBodyP Genericwrapper::parseMail( mailmessage * msg ) 276RecBodyP Genericwrapper::parseMail( mailmessage * msg )
232{ 277{
233 int err = MAILIMF_NO_ERROR; 278 int err = MAILIMF_NO_ERROR;
234 mailmime_single_fields fields; 279 mailmime_single_fields fields;
235 /* is bound to msg and will be freed there */ 280 /* is bound to msg and will be freed there */
236 mailmime * mime=0; 281 mailmime * mime=0;
237 RecBodyP body = new RecBody(); 282 RecBodyP body = new RecBody();
238 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 283 memset(&fields, 0, sizeof(struct mailmime_single_fields));
239 err = mailmessage_get_bodystructure(msg,&mime); 284 err = mailmessage_get_bodystructure(msg,&mime);
240 QValueList<int>recList; 285 QValueList<int>recList;
241 traverseBody(body,msg,mime,recList); 286 traverseBody(body,msg,mime,recList);
242 return body; 287 return body;
243} 288}
244 289
245QString Genericwrapper::parseDateTime( mailimf_date_time *date )
246{
247 char tmp[23];
248
249 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
250 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
251 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i",
252 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
253
254 return QString( tmp );
255}
256 290
257QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 291QString Genericwrapper::parseAddressList( mailimf_address_list *list )
258{ 292{
259 QString result( "" ); 293 QString result( "" );
260 294
261 bool first = true; 295 bool first = true;
262 if (list == 0) return result; 296 if (list == 0) return result;
263 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 297 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
264 mailimf_address *addr = (mailimf_address *) current->data; 298 mailimf_address *addr = (mailimf_address *) current->data;
265 299
266 if ( !first ) { 300 if ( !first ) {
267 result.append( "," ); 301 result.append( "," );
268 } else { 302 } else {
269 first = false; 303 first = false;
270 } 304 }
271 305
272 switch ( addr->ad_type ) { 306 switch ( addr->ad_type ) {
273 case MAILIMF_ADDRESS_MAILBOX: 307 case MAILIMF_ADDRESS_MAILBOX:
274 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 308 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
275 break; 309 break;
276 case MAILIMF_ADDRESS_GROUP: 310 case MAILIMF_ADDRESS_GROUP:
277 result.append( parseGroup( addr->ad_data.ad_group ) ); 311 result.append( parseGroup( addr->ad_data.ad_group ) );
278 break; 312 break;
279 default: 313 default:
280 ; // odebug << "Generic: unkown mailimf address type" << oendl; 314 ; // odebug << "Generic: unkown mailimf address type" << oendl;
281 break; 315 break;
282 } 316 }
283 } 317 }
284 318
285 return result; 319 return result;
286} 320}
287 321
288QString Genericwrapper::parseGroup( mailimf_group *group ) 322QString Genericwrapper::parseGroup( mailimf_group *group )
289{ 323{
290 QString result( "" ); 324 QString result( "" );
291 325
292 result.append( group->grp_display_name ); 326 result.append( group->grp_display_name );
293 result.append( ": " ); 327 result.append( ": " );
294 328
295 if ( group->grp_mb_list != NULL ) { 329 if ( group->grp_mb_list != NULL ) {
296 result.append( parseMailboxList( group->grp_mb_list ) ); 330 result.append( parseMailboxList( group->grp_mb_list ) );
297 } 331 }
298 332
299 result.append( ";" ); 333 result.append( ";" );
300 334
301 return result; 335 return result;
302} 336}
303 337
304QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 338QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
305{ 339{
306 QString result( "" ); 340 QString result( "" );
307 341
308 if ( box->mb_display_name == NULL ) { 342 if ( box->mb_display_name == NULL ) {
309 result.append( box->mb_addr_spec ); 343 result.append( box->mb_addr_spec );
310 } else { 344 } else {
311 result.append( convert_String(box->mb_display_name).latin1() ); 345 result.append( convert_String(box->mb_display_name).latin1() );
312 result.append( " <" ); 346 result.append( " <" );
313 result.append( box->mb_addr_spec ); 347 result.append( box->mb_addr_spec );
314 result.append( ">" ); 348 result.append( ">" );
315 } 349 }
316 350
317 return result; 351 return result;
318} 352}
319 353
320QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 354QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
321{ 355{
322 QString result( "" ); 356 QString result( "" );
323 357
324 bool first = true; 358 bool first = true;
325 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 359 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
326 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 360 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
327 361
328 if ( !first ) { 362 if ( !first ) {
329 result.append( "," ); 363 result.append( "," );
330 } else { 364 } else {
331 first = false; 365 first = false;
332 } 366 }
333 367
334 result.append( parseMailbox( box ) ); 368 result.append( parseMailbox( box ) );
335 } 369 }
336 370
337 return result; 371 return result;
338} 372}
339 373
340encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) 374encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part)
341{ 375{
342 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 376 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
343 if (it==bodyCache.end()) return new encodedString(); 377 if (it==bodyCache.end()) return new encodedString();
344 encodedString*t = decode_String(it.data(),part->Encoding()); 378 encodedString*t = decode_String(it.data(),part->Encoding());
345 return t; 379 return t;
346} 380}
347 381
348encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) 382encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part)
349{ 383{
350 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 384 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
351 if (it==bodyCache.end()) return new encodedString(); 385 if (it==bodyCache.end()) return new encodedString();
352 encodedString*t = it.data(); 386 encodedString*t = it.data();
353 return t; 387 return t;
354} 388}
355 389
356QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 390QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
357{ 391{
358 encodedString*t = fetchDecodedPart(mail,part); 392 encodedString*t = fetchDecodedPart(mail,part);
359 QString text=t->Content(); 393 QString text=t->Content();
360 delete t; 394 delete t;
361 return text; 395 return text;
362} 396}
363 397
364void Genericwrapper::cleanMimeCache() 398void Genericwrapper::cleanMimeCache()
365{ 399{
366 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 400 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
367 for (;it!=bodyCache.end();++it) { 401 for (;it!=bodyCache.end();++it) {
368 encodedString*t = it.data(); 402 encodedString*t = it.data();
369 //it.setValue(0); 403 //it.setValue(0);
370 if (t) delete t; 404 if (t) delete t;
371 } 405 }
372 bodyCache.clear(); 406 bodyCache.clear();
373 ; // odebug << "Genericwrapper: cache cleaned" << oendl; 407 ; // odebug << "Genericwrapper: cache cleaned" << oendl;
374} 408}
375 409
376QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) 410QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies)
377{ 411{
378 QStringList res; 412 QStringList res;
379 if (!in_replies || !in_replies->mid_list) return res; 413 if (!in_replies || !in_replies->mid_list) return res;
380 clistiter * current = 0; 414 clistiter * current = 0;
381 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { 415 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) {
382 QString h((char*)current->data); 416 QString h((char*)current->data);
383 while (h.length()>0 && h[0]=='<') { 417 while (h.length()>0 && h[0]=='<') {
384 h.remove(0,1); 418 h.remove(0,1);
385 } 419 }
386 while (h.length()>0 && h[h.length()-1]=='>') { 420 while (h.length()>0 && h[h.length()-1]=='>') {
387 h.remove(h.length()-1,1); 421 h.remove(h.length()-1,1);
388 } 422 }
389 if (h.length()>0) { 423 if (h.length()>0) {
390 res.append(h); 424 res.append(h);
391 } 425 }
392 } 426 }
393 return res; 427 return res;
394} 428}
395 429
396void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) 430void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb)
397{ 431{
398 int r; 432 int r;
399 mailmessage_list * env_list = 0; 433 mailmessage_list * env_list = 0;
400 r = mailsession_get_messages_list(session,&env_list); 434 r = mailsession_get_messages_list(session,&env_list);
401 if (r != MAIL_NO_ERROR) { 435 if (r != MAIL_NO_ERROR) {
402 ; // odebug << "Error message list" << oendl; 436 ; // odebug << "Error message list" << oendl;
403 return; 437 return;
404 } 438 }
405 r = mailsession_get_envelopes_list(session, env_list); 439 r = mailsession_get_envelopes_list(session, env_list);
406 if (r != MAIL_NO_ERROR) { 440 if (r != MAIL_NO_ERROR) {
407 ; // odebug << "Error filling message list" << oendl; 441 ; // odebug << "Error filling message list" << oendl;
408 if (env_list) { 442 if (env_list) {
409 mailmessage_list_free(env_list); 443 mailmessage_list_free(env_list);
410 } 444 }
411 return; 445 return;
412 } 446 }
413 mailimf_references * refs = 0; 447 mailimf_references * refs = 0;
414 mailimf_in_reply_to * in_replies = 0; 448 mailimf_in_reply_to * in_replies = 0;
415 uint32_t i = 0; 449 uint32_t i = 0;
416 for(; i < carray_count(env_list->msg_tab) ; ++i) { 450 for(; i < carray_count(env_list->msg_tab) ; ++i) {
417 mailmessage * msg; 451 mailmessage * msg;
418 QBitArray mFlags(7); 452 QBitArray mFlags(7);
419 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 453 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
420 if (msg->msg_fields == NULL) { 454 if (msg->msg_fields == NULL) {
421 //; // odebug << "could not fetch envelope of message " << i << "" << oendl; 455 //; // odebug << "could not fetch envelope of message " << i << "" << oendl;
422 continue; 456 continue;
423 } 457 }
424 RecMailP mail = new RecMail(); 458 RecMailP mail = new RecMail();
425 mail->setWrapper(this); 459 mail->setWrapper(this);
426 mail_flags * flag_result = 0; 460 mail_flags * flag_result = 0;
427 r = mailmessage_get_flags(msg,&flag_result); 461 r = mailmessage_get_flags(msg,&flag_result);
428 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 462 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
429 mFlags.setBit(FLAG_SEEN); 463 mFlags.setBit(FLAG_SEEN);
430 } 464 }
431 mailimf_single_fields single_fields; 465 mailimf_single_fields single_fields;
432 mailimf_single_fields_init(&single_fields, msg->msg_fields); 466 mailimf_single_fields_init(&single_fields, msg->msg_fields);
433 mail->setMsgsize(msg->msg_size); 467 mail->setMsgsize(msg->msg_size);
434 mail->setFlags(mFlags); 468 mail->setFlags(mFlags);
435 mail->setMbox(mailbox); 469 mail->setMbox(mailbox);
436 mail->setNumber(msg->msg_index); 470 mail->setNumber(msg->msg_index);
437 if (single_fields.fld_subject) 471 if (single_fields.fld_subject)
438 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 472 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
439 if (single_fields.fld_from) 473 if (single_fields.fld_from)
440 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 474 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
441 if (!mbox_as_to) { 475 if (!mbox_as_to) {
442 if (single_fields.fld_to) 476 if (single_fields.fld_to)
443 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 477 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
444 } else { 478 } else {
445 mail->setTo(mailbox); 479 mail->setTo(mailbox);
446 } 480 }
447 if (single_fields.fld_cc) 481 if (single_fields.fld_cc)
448 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 482 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
449 if (single_fields.fld_bcc) 483 if (single_fields.fld_bcc)
450 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 484 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
451 if (single_fields.fld_orig_date) 485 if (single_fields.fld_orig_date) {
452 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); 486 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
487 char tmp[23];
488 struct mailimf_date_time* date = single_fields.fld_orig_date->dt_date_time;
489 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %05i",
490 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
491 mail->setIsoDate( QString( tmp ) );
492 }
453 // crashes when accessing pop3 account? 493 // crashes when accessing pop3 account?
454 if (single_fields.fld_message_id) { 494 if (single_fields.fld_message_id) {
455 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 495 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
456 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; 496 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl;
457 } 497 }
458 if (single_fields.fld_reply_to) { 498 if (single_fields.fld_reply_to) {
459 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); 499 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list);
460 if (t.count()>0) { 500 if (t.count()>0) {
461 mail->setReplyto(t[0]); 501 mail->setReplyto(t[0]);
462 } 502 }
463 } 503 }
464#if 0 504#if 0
465 refs = single_fields.fld_references; 505 refs = single_fields.fld_references;
466 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 506 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
467 char * text = (char*)refs->mid_list->first->data; 507 char * text = (char*)refs->mid_list->first->data;
468 mail->setReplyto(QString(text)); 508 mail->setReplyto(QString(text));
469 } 509 }
470#endif 510#endif
471 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && 511 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list &&
472 clist_count(single_fields.fld_in_reply_to->mid_list)) { 512 clist_count(single_fields.fld_in_reply_to->mid_list)) {
473 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); 513 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to));
474 } 514 }
475 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) 515 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 )
476 target.append(mail); 516 target.append(mail);
477 } 517 }
478 if (env_list) { 518 if (env_list) {
479 mailmessage_list_free(env_list); 519 mailmessage_list_free(env_list);
480 } 520 }
481} 521}
diff --git a/kmicromail/libmailwrapper/genericwrapper.h b/kmicromail/libmailwrapper/genericwrapper.h
index 235e116..244212f 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 46
46protected: 47protected:
47 RecBodyP parseMail( mailmessage * msg ); 48 RecBodyP parseMail( mailmessage * msg );
48 QString parseMailboxList( mailimf_mailbox_list *list ); 49 QString parseMailboxList( mailimf_mailbox_list *list );
49 QString parseMailbox( mailimf_mailbox *box ); 50 QString parseMailbox( mailimf_mailbox *box );
50 QString parseGroup( mailimf_group *group ); 51 QString parseGroup( mailimf_group *group );
51 QString parseAddressList( mailimf_address_list *list ); 52 QString parseAddressList( mailimf_address_list *list );
52 QString parseDateTime( mailimf_date_time *date );
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 6faa524..5441a9b 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,1228 +1,1244 @@
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 11
11using namespace Opie::Core; 12using namespace Opie::Core;
12int IMAPwrapper::mMax = 0; 13int IMAPwrapper::mMax = 0;
13int IMAPwrapper::mCurrent = 0; 14int IMAPwrapper::mCurrent = 0;
14 15
15IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 16IMAPwrapper::IMAPwrapper( IMAPaccount *a )
16 : AbstractMail() 17 : AbstractMail()
17{ 18{
18 account = a; 19 account = a;
19 m_imap = 0; 20 m_imap = 0;
20 m_Lastmbox = ""; 21 m_Lastmbox = "";
21 mCurrent = 0; 22 mCurrent = 0;
22 mMax = 0; 23 mMax = 0;
23} 24}
24 25
25IMAPwrapper::~IMAPwrapper() 26IMAPwrapper::~IMAPwrapper()
26{ 27{
27 logout(); 28 logout();
28} 29}
29 30
30/* to avoid to often select statements in loops etc. 31/* to avoid to often select statements in loops etc.
31 we trust that we are logged in and connection is established!*/ 32 we trust that we are logged in and connection is established!*/
32int IMAPwrapper::selectMbox(const QString&mbox) 33int IMAPwrapper::selectMbox(const QString&mbox)
33{ 34{
34 if (mbox == m_Lastmbox) { 35 if (mbox == m_Lastmbox) {
35 return MAILIMAP_NO_ERROR; 36 return MAILIMAP_NO_ERROR;
36 } 37 }
37 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 38 int err = mailimap_select( m_imap, (char*)mbox.latin1());
38 if ( err != MAILIMAP_NO_ERROR ) { 39 if ( err != MAILIMAP_NO_ERROR ) {
39 m_Lastmbox = ""; 40 m_Lastmbox = "";
40 return err; 41 return err;
41 } 42 }
42 m_Lastmbox = mbox; 43 m_Lastmbox = mbox;
43 return err; 44 return err;
44} 45}
45 46
46void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 47void IMAPwrapper::imap_progress( size_t current, size_t maximum )
47{ 48{
48 //qDebug("imap progress %d of %d ",current,maximum ); 49 //qDebug("imap progress %d of %d ",current,maximum );
49 //Global::statusMessage(tr("Downloading message %1 of %2").arg( current).arg(maximum)); 50 //Global::statusMessage(tr("Downloading message %1 of %2").arg( current).arg(maximum));
50 //qApp->processEvents() 51 //qApp->processEvents()
51 static int last = 0; 52 static int last = 0;
52 if ( last != current ) 53 if ( last != current )
53 IMAPwrapper::progress(); 54 IMAPwrapper::progress();
54 last = current; 55 last = current;
55} 56}
56void IMAPwrapper::progress( QString m ) 57void IMAPwrapper::progress( QString m )
57{ 58{
58 59
59 static QString mProgrMess; 60 static QString mProgrMess;
60 if ( m != QString::null ) { 61 if ( m != QString::null ) {
61 mProgrMess = m; 62 mProgrMess = m;
62 mCurrent = 0; 63 mCurrent = 0;
63 return; 64 return;
64 } 65 }
65 QString mess; 66 QString mess;
66 //qDebug("progress "); 67 //qDebug("progress ");
67 if ( mMax ) mess = mProgrMess +tr(" message %1 of %2").arg( mCurrent++).arg(mMax); 68 if ( mMax ) mess = mProgrMess +tr(" message %1 of %2").arg( mCurrent++).arg(mMax);
68 else mess = mProgrMess +tr(" message %1").arg( mCurrent++); 69 else mess = mProgrMess +tr(" message %1").arg( mCurrent++);
69 Global::statusMessage(mess); 70 Global::statusMessage(mess);
70 qApp->processEvents(); 71 qApp->processEvents();
71} 72}
72bool IMAPwrapper::start_tls(bool force_tls) 73bool IMAPwrapper::start_tls(bool force_tls)
73{ 74{
74 int err; 75 int err;
75 bool try_tls; 76 bool try_tls;
76 mailimap_capability_data * cap_data = 0; 77 mailimap_capability_data * cap_data = 0;
77 78
78 err = mailimap_capability(m_imap,&cap_data); 79 err = mailimap_capability(m_imap,&cap_data);
79 if (err != MAILIMAP_NO_ERROR) { 80 if (err != MAILIMAP_NO_ERROR) {
80 Global::statusMessage("error getting capabilities!"); 81 Global::statusMessage("error getting capabilities!");
81 return false; 82 return false;
82 } 83 }
83 clistiter * cur; 84 clistiter * cur;
84 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 85 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
85 struct mailimap_capability * cap; 86 struct mailimap_capability * cap;
86 cap = (struct mailimap_capability *)clist_content(cur); 87 cap = (struct mailimap_capability *)clist_content(cur);
87 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 88 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
88 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 89 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
89 try_tls = true; 90 try_tls = true;
90 break; 91 break;
91 } 92 }
92 } 93 }
93 } 94 }
94 if (cap_data) { 95 if (cap_data) {
95 mailimap_capability_data_free(cap_data); 96 mailimap_capability_data_free(cap_data);
96 } 97 }
97 if (try_tls) { 98 if (try_tls) {
98 err = mailimap_starttls(m_imap); 99 err = mailimap_starttls(m_imap);
99 if (err != MAILIMAP_NO_ERROR && force_tls) { 100 if (err != MAILIMAP_NO_ERROR && force_tls) {
100 Global::statusMessage(tr("Server has no TLS support!")); 101 Global::statusMessage(tr("Server has no TLS support!"));
101 try_tls = false; 102 try_tls = false;
102 } else { 103 } else {
103 mailstream_low * low; 104 mailstream_low * low;
104 mailstream_low * new_low; 105 mailstream_low * new_low;
105 low = mailstream_get_low(m_imap->imap_stream); 106 low = mailstream_get_low(m_imap->imap_stream);
106 if (!low) { 107 if (!low) {
107 try_tls = false; 108 try_tls = false;
108 } else { 109 } else {
109 int fd = mailstream_low_get_fd(low); 110 int fd = mailstream_low_get_fd(low);
110 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 111 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
111 mailstream_low_free(low); 112 mailstream_low_free(low);
112 mailstream_set_low(m_imap->imap_stream, new_low); 113 mailstream_set_low(m_imap->imap_stream, new_low);
113 } else { 114 } else {
114 try_tls = false; 115 try_tls = false;
115 } 116 }
116 } 117 }
117 } 118 }
118 } 119 }
119 return try_tls; 120 return try_tls;
120} 121}
121 122
122void IMAPwrapper::login() 123void IMAPwrapper::login()
123{ 124{
124 QString server, user, pass; 125 QString server, user, pass;
125 uint16_t port; 126 uint16_t port;
126 int err = MAILIMAP_NO_ERROR; 127 int err = MAILIMAP_NO_ERROR;
127 128
128 if (account->getOffline()) return; 129 if (account->getOffline()) return;
129 /* we are connected this moment */ 130 /* we are connected this moment */
130 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 131 /* TODO: setup a timer holding the line or if connection closed - delete the value */
131 if (m_imap) { 132 if (m_imap) {
132 err = mailimap_noop(m_imap); 133 err = mailimap_noop(m_imap);
133 if (err!=MAILIMAP_NO_ERROR) { 134 if (err!=MAILIMAP_NO_ERROR) {
134 logout(); 135 logout();
135 } else { 136 } else {
136 mailstream_flush(m_imap->imap_stream); 137 mailstream_flush(m_imap->imap_stream);
137 return; 138 return;
138 } 139 }
139 } 140 }
140 server = account->getServer(); 141 server = account->getServer();
141 port = account->getPort().toUInt(); 142 port = account->getPort().toUInt();
142 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 143 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
143 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 144 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
144 login.show(); 145 login.show();
145 if ( QDialog::Accepted == login.exec() ) { 146 if ( QDialog::Accepted == login.exec() ) {
146 // ok 147 // ok
147 user = login.getUser(); 148 user = login.getUser();
148 pass = login.getPassword(); 149 pass = login.getPassword();
149 } else { 150 } else {
150 // cancel 151 // cancel
151 return; 152 return;
152 } 153 }
153 } else { 154 } else {
154 user = account->getUser(); 155 user = account->getUser();
155 pass = account->getPassword(); 156 pass = account->getPassword();
156 } 157 }
157 158
158 m_imap = mailimap_new( 20, &imap_progress ); 159 m_imap = mailimap_new( 20, &imap_progress );
159 160
160 /* connect */ 161 /* connect */
161 bool ssl = false; 162 bool ssl = false;
162 bool try_tls = false; 163 bool try_tls = false;
163 bool force_tls = false; 164 bool force_tls = false;
164 165
165 if ( account->ConnectionType() == 2 ) { 166 if ( account->ConnectionType() == 2 ) {
166 ssl = true; 167 ssl = true;
167 } 168 }
168 if (account->ConnectionType()==1) { 169 if (account->ConnectionType()==1) {
169 force_tls = true; 170 force_tls = true;
170 } 171 }
171 172
172 if ( ssl ) { 173 if ( ssl ) {
173 qDebug("using ssl "); 174 qDebug("using ssl ");
174 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); 175 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port );
175 } else { 176 } else {
176 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); 177 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port );
177 } 178 }
178 179
179 if ( err != MAILIMAP_NO_ERROR && 180 if ( err != MAILIMAP_NO_ERROR &&
180 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 181 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
181 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 182 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
182 QString failure = ""; 183 QString failure = "";
183 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 184 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
184 failure="Connection refused"; 185 failure="Connection refused";
185 } else { 186 } else {
186 failure="Unknown failure"; 187 failure="Unknown failure";
187 } 188 }
188 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 189 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
189 mailimap_free( m_imap ); 190 mailimap_free( m_imap );
190 m_imap = 0; 191 m_imap = 0;
191 return; 192 return;
192 } 193 }
193 194
194 if (!ssl) { 195 if (!ssl) {
195 try_tls = start_tls(force_tls); 196 try_tls = start_tls(force_tls);
196 } 197 }
197 198
198 bool ok = true; 199 bool ok = true;
199 if (force_tls && !try_tls) { 200 if (force_tls && !try_tls) {
200 Global::statusMessage(tr("Server has no TLS support!")); 201 Global::statusMessage(tr("Server has no TLS support!"));
201 ok = false; 202 ok = false;
202 } 203 }
203 204
204 205
205 /* login */ 206 /* login */
206 207
207 if (ok) { 208 if (ok) {
208 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); 209 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() );
209 if ( err != MAILIMAP_NO_ERROR ) { 210 if ( err != MAILIMAP_NO_ERROR ) {
210 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 211 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
211 ok = false; 212 ok = false;
212 } 213 }
213 } 214 }
214 if (!ok) { 215 if (!ok) {
215 err = mailimap_close( m_imap ); 216 err = mailimap_close( m_imap );
216 mailimap_free( m_imap ); 217 mailimap_free( m_imap );
217 m_imap = 0; 218 m_imap = 0;
218 } 219 }
219} 220}
220 221
221void IMAPwrapper::logout() 222void IMAPwrapper::logout()
222{ 223{
223 int err = MAILIMAP_NO_ERROR; 224 int err = MAILIMAP_NO_ERROR;
224 if (!m_imap) return; 225 if (!m_imap) return;
225 err = mailimap_logout( m_imap ); 226 err = mailimap_logout( m_imap );
226 err = mailimap_close( m_imap ); 227 err = mailimap_close( m_imap );
227 mailimap_free( m_imap ); 228 mailimap_free( m_imap );
228 m_imap = 0; 229 m_imap = 0;
229 m_Lastmbox = ""; 230 m_Lastmbox = "";
230} 231}
231 232
232void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) 233void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
233{ 234{
234 int err = MAILIMAP_NO_ERROR; 235 int err = MAILIMAP_NO_ERROR;
235 clist *result = 0; 236 clist *result = 0;
236 clistcell *current; 237 clistcell *current;
237 mailimap_fetch_type *fetchType = 0; 238 mailimap_fetch_type *fetchType = 0;
238 mailimap_set *set = 0; 239 mailimap_set *set = 0;
239 240
240 login(); 241 login();
241 if (!m_imap) { 242 if (!m_imap) {
242 return; 243 return;
243 } 244 }
244 /* select mailbox READONLY for operations */ 245 /* select mailbox READONLY for operations */
245 err = selectMbox(mailbox); 246 err = selectMbox(mailbox);
246 if ( err != MAILIMAP_NO_ERROR ) { 247 if ( err != MAILIMAP_NO_ERROR ) {
247 return; 248 return;
248 } 249 }
249 250
250 int last = m_imap->imap_selection_info->sel_exists; 251 int last = m_imap->imap_selection_info->sel_exists;
251 252
252 if (last == 0) { 253 if (last == 0) {
253 Global::statusMessage(tr("Mailbox has no mails")); 254 Global::statusMessage(tr("Mailbox has no mails"));
254 return; 255 return;
255 } else { 256 } else {
256 } 257 }
257 258
258 Global::statusMessage(tr("Fetching header list")); 259 Global::statusMessage(tr("Fetching header list"));
259 qApp->processEvents(); 260 qApp->processEvents();
260 /* the range has to start at 1!!! not with 0!!!! */ 261 /* the range has to start at 1!!! not with 0!!!! */
261 set = mailimap_set_new_interval( 1, last ); 262 set = mailimap_set_new_interval( 1, last );
262 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 263 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
263 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 264 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
264 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 265 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
265 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 266 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
266 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 267 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
267 268
268 err = mailimap_fetch( m_imap, set, fetchType, &result ); 269 err = mailimap_fetch( m_imap, set, fetchType, &result );
269 mailimap_set_free( set ); 270 mailimap_set_free( set );
270 mailimap_fetch_type_free( fetchType ); 271 mailimap_fetch_type_free( fetchType );
271 272
272 QString date,subject,from; 273 QString date,subject,from;
273 274
274 if ( err == MAILIMAP_NO_ERROR ) { 275 if ( err == MAILIMAP_NO_ERROR ) {
275 mailimap_msg_att * msg_att; 276 mailimap_msg_att * msg_att;
276 int i = 0; 277 int i = 0;
277 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 278 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
278 ++i; 279 ++i;
279 msg_att = (mailimap_msg_att*)current->data; 280 msg_att = (mailimap_msg_att*)current->data;
280 RecMail*m = parse_list_result(msg_att); 281 RecMail*m = parse_list_result(msg_att);
281 if (m) { 282 if (m) {
282 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { 283 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) {
283 m->setNumber(i); 284 m->setNumber(i);
284 m->setMbox(mailbox); 285 m->setMbox(mailbox);
285 m->setWrapper(this); 286 m->setWrapper(this);
286 target.append(m); 287 target.append(m);
287 } 288 }
288 } 289 }
289 } 290 }
290 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); 291 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count()));
291 } else { 292 } else {
292 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 293 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
293 } 294 }
294 if (result) mailimap_fetch_list_free(result); 295 if (result) mailimap_fetch_list_free(result);
295} 296}
296 297
297QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 298QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
298{ 299{
299 const char *path, *mask; 300 const char *path, *mask;
300 int err = MAILIMAP_NO_ERROR; 301 int err = MAILIMAP_NO_ERROR;
301 clist *result = 0; 302 clist *result = 0;
302 clistcell *current = 0; 303 clistcell *current = 0;
303 clistcell*cur_flag = 0; 304 clistcell*cur_flag = 0;
304 mailimap_mbx_list_flags*bflags = 0; 305 mailimap_mbx_list_flags*bflags = 0;
305 306
306 QValueList<FolderP>* folders = new QValueList<FolderP>(); 307 QValueList<FolderP>* folders = new QValueList<FolderP>();
307 login(); 308 login();
308 if (!m_imap) { 309 if (!m_imap) {
309 return folders; 310 return folders;
310 } 311 }
311 312
312/* 313/*
313 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 314 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
314 * We must not forget to filter them out in next loop! 315 * We must not forget to filter them out in next loop!
315 * it seems like ugly code. and yes - it is ugly code. but the best way. 316 * it seems like ugly code. and yes - it is ugly code. but the best way.
316 */ 317 */
317 Global::statusMessage(tr("Fetching folder list")); 318 Global::statusMessage(tr("Fetching folder list"));
318 qApp->processEvents(); 319 qApp->processEvents();
319 QString temp; 320 QString temp;
320 mask = "INBOX" ; 321 mask = "INBOX" ;
321 mailimap_mailbox_list *list; 322 mailimap_mailbox_list *list;
322 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 323 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
323 QString del; 324 QString del;
324 bool selectable = true; 325 bool selectable = true;
325 bool no_inferiors = false; 326 bool no_inferiors = false;
326 if ( err == MAILIMAP_NO_ERROR ) { 327 if ( err == MAILIMAP_NO_ERROR ) {
327 current = result->first; 328 current = result->first;
328 for ( int i = result->count; i > 0; i-- ) { 329 for ( int i = result->count; i > 0; i-- ) {
329 list = (mailimap_mailbox_list *) current->data; 330 list = (mailimap_mailbox_list *) current->data;
330 // it is better use the deep copy mechanism of qt itself 331 // it is better use the deep copy mechanism of qt itself
331 // instead of using strdup! 332 // instead of using strdup!
332 temp = list->mb_name; 333 temp = list->mb_name;
333 del = list->mb_delimiter; 334 del = list->mb_delimiter;
334 current = current->next; 335 current = current->next;
335 if ( (bflags = list->mb_flag) ) { 336 if ( (bflags = list->mb_flag) ) {
336 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 337 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
337 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 338 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
338 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 339 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
339 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 340 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
340 no_inferiors = true; 341 no_inferiors = true;
341 } 342 }
342 } 343 }
343 } 344 }
344 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 345 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
345 } 346 }
346 } else { 347 } else {
347 qDebug("error fetching folders: "); 348 qDebug("error fetching folders: ");
348 349
349 } 350 }
350 mailimap_list_result_free( result ); 351 mailimap_list_result_free( result );
351 352
352/* 353/*
353 * second stage - get the other then inbox folders 354 * second stage - get the other then inbox folders
354 */ 355 */
355 mask = "*" ; 356 mask = "*" ;
356 path = account->getPrefix().latin1(); 357 path = account->getPrefix().latin1();
357 if (!path) path = ""; 358 if (!path) path = "";
358 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 359 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
359 if ( err == MAILIMAP_NO_ERROR ) { 360 if ( err == MAILIMAP_NO_ERROR ) {
360 current = result->first; 361 current = result->first;
361 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 362 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
362 no_inferiors = false; 363 no_inferiors = false;
363 list = (mailimap_mailbox_list *) current->data; 364 list = (mailimap_mailbox_list *) current->data;
364 // it is better use the deep copy mechanism of qt itself 365 // it is better use the deep copy mechanism of qt itself
365 // instead of using strdup! 366 // instead of using strdup!
366 temp = list->mb_name; 367 temp = list->mb_name;
367 if (temp.lower()=="inbox") 368 if (temp.lower()=="inbox")
368 continue; 369 continue;
369 if (temp.lower()==account->getPrefix().lower()) 370 if (temp.lower()==account->getPrefix().lower())
370 continue; 371 continue;
371 if ( (bflags = list->mb_flag) ) { 372 if ( (bflags = list->mb_flag) ) {
372 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 373 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
373 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 374 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
374 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 375 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
375 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 376 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
376 no_inferiors = true; 377 no_inferiors = true;
377 } 378 }
378 } 379 }
379 } 380 }
380 del = list->mb_delimiter; 381 del = list->mb_delimiter;
381 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 382 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
382 } 383 }
383 } else { 384 } else {
384 qDebug("error fetching folders "); 385 qDebug("error fetching folders ");
385 386
386 } 387 }
387 if (result) mailimap_list_result_free( result ); 388 if (result) mailimap_list_result_free( result );
388 return folders; 389 return folders;
389} 390}
390 391
391RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 392RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
392{ 393{
393 RecMail * m = 0; 394 RecMail * m = 0;
394 mailimap_msg_att_item *item=0; 395 mailimap_msg_att_item *item=0;
395 clistcell *current,*c,*cf; 396 clistcell *current,*c,*cf;
396 mailimap_msg_att_dynamic*flist; 397 mailimap_msg_att_dynamic*flist;
397 mailimap_flag_fetch*cflag; 398 mailimap_flag_fetch*cflag;
398 int size; 399 int size;
399 QBitArray mFlags(7); 400 QBitArray mFlags(7);
400 QStringList addresslist; 401 QStringList addresslist;
401 402
402 if (!m_att) { 403 if (!m_att) {
403 return m; 404 return m;
404 } 405 }
405 m = new RecMail(); 406 m = new RecMail();
406 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 407 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
407 current = c; 408 current = c;
408 size = 0; 409 size = 0;
409 item = (mailimap_msg_att_item*)current->data; 410 item = (mailimap_msg_att_item*)current->data;
410 if ( !item ) 411 if ( !item )
411 continue; 412 continue;
412 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 413 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
413 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 414 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
414 if (!flist || !flist->att_list) { 415 if (!flist || !flist->att_list) {
415 continue; 416 continue;
416 } 417 }
417 cf = flist->att_list->first; 418 cf = flist->att_list->first;
418 if( ! cf ) 419 if( ! cf )
419 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 420 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
420 cflag = (mailimap_flag_fetch*)cf->data; 421 cflag = (mailimap_flag_fetch*)cf->data;
421 if( ! cflag ) 422 if( ! cflag )
422 qDebug("imap:not cflag "); 423 qDebug("imap:not cflag ");
423 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 424 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
424 switch (cflag->fl_flag->fl_type) { 425 switch (cflag->fl_flag->fl_type) {
425 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 426 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
426 mFlags.setBit(FLAG_ANSWERED); 427 mFlags.setBit(FLAG_ANSWERED);
427 break; 428 break;
428 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 429 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
429 mFlags.setBit(FLAG_FLAGGED); 430 mFlags.setBit(FLAG_FLAGGED);
430 break; 431 break;
431 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 432 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
432 mFlags.setBit(FLAG_DELETED); 433 mFlags.setBit(FLAG_DELETED);
433 break; 434 break;
434 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 435 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
435 mFlags.setBit(FLAG_SEEN); 436 mFlags.setBit(FLAG_SEEN);
436 break; 437 break;
437 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 438 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
438 mFlags.setBit(FLAG_DRAFT); 439 mFlags.setBit(FLAG_DRAFT);
439 break; 440 break;
440 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 441 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
441 break; 442 break;
442 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 443 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
443 break; 444 break;
444 default: 445 default:
445 break; 446 break;
446 } 447 }
447 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 448 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
448 mFlags.setBit(FLAG_RECENT); 449 mFlags.setBit(FLAG_RECENT);
449 } 450 }
450 } 451 }
451 continue; 452 continue;
452 } 453 }
453 if ( item->att_data.att_static == NULL ) 454 if ( item->att_data.att_static == NULL )
454 continue; 455 continue;
455 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 456 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
456 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 457 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
457 if ( head == NULL ) 458 if ( head == NULL )
458 continue; 459 continue;
459 if ( head->env_date != NULL ) 460 if ( head->env_date != NULL ) {
460 m->setDate(head->env_date); 461 m->setDate(head->env_date);
462 struct mailimf_date_time result;
463 struct mailimf_date_time* date = &result;
464 struct mailimf_date_time **re = &date;
465 size_t length = m->getDate().length();
466 size_t index = 0;
467 if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) {
468 m->setDate( Genericwrapper::parseDateTime( date ) );
469 char tmp[23];
470 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %05i",
471 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
472 m->setIsoDate( QString( tmp ) );
473 } else {
474 m->setIsoDate(head->env_date);
475 }
476 }
461 if ( head->env_subject != NULL ) 477 if ( head->env_subject != NULL )
462 m->setSubject(convert_String((const char*)head->env_subject)); 478 m->setSubject(convert_String((const char*)head->env_subject));
463 //m->setSubject(head->env_subject); 479 //m->setSubject(head->env_subject);
464 if (head->env_from!=NULL) { 480 if (head->env_from!=NULL) {
465 addresslist = address_list_to_stringlist(head->env_from->frm_list); 481 addresslist = address_list_to_stringlist(head->env_from->frm_list);
466 if (addresslist.count()) { 482 if (addresslist.count()) {
467 m->setFrom(addresslist.first()); 483 m->setFrom(addresslist.first());
468 } 484 }
469 } 485 }
470 if (head->env_to!=NULL) { 486 if (head->env_to!=NULL) {
471 addresslist = address_list_to_stringlist(head->env_to->to_list); 487 addresslist = address_list_to_stringlist(head->env_to->to_list);
472 m->setTo(addresslist); 488 m->setTo(addresslist);
473 } 489 }
474 if (head->env_cc!=NULL) { 490 if (head->env_cc!=NULL) {
475 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 491 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
476 m->setCC(addresslist); 492 m->setCC(addresslist);
477 } 493 }
478 if (head->env_bcc!=NULL) { 494 if (head->env_bcc!=NULL) {
479 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 495 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
480 m->setBcc(addresslist); 496 m->setBcc(addresslist);
481 } 497 }
482 /* reply to address, eg. email. */ 498 /* reply to address, eg. email. */
483 if (head->env_reply_to!=NULL) { 499 if (head->env_reply_to!=NULL) {
484 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 500 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
485 if (addresslist.count()) { 501 if (addresslist.count()) {
486 m->setReplyto(addresslist.first()); 502 m->setReplyto(addresslist.first());
487 } 503 }
488 } 504 }
489 if (head->env_in_reply_to!=NULL) { 505 if (head->env_in_reply_to!=NULL) {
490 QString h(head->env_in_reply_to); 506 QString h(head->env_in_reply_to);
491 while (h.length()>0 && h[0]=='<') { 507 while (h.length()>0 && h[0]=='<') {
492 h.remove(0,1); 508 h.remove(0,1);
493 } 509 }
494 while (h.length()>0 && h[h.length()-1]=='>') { 510 while (h.length()>0 && h[h.length()-1]=='>') {
495 h.remove(h.length()-1,1); 511 h.remove(h.length()-1,1);
496 } 512 }
497 if (h.length()>0) { 513 if (h.length()>0) {
498 m->setInreply(QStringList(h)); 514 m->setInreply(QStringList(h));
499 } 515 }
500 } 516 }
501 if (head->env_message_id != NULL) { 517 if (head->env_message_id != NULL) {
502 m->setMsgid(QString(head->env_message_id)); 518 m->setMsgid(QString(head->env_message_id));
503 } 519 }
504 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 520 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
505#if 0 521#if 0
506 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 522 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
507 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 523 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
508 qDebug("time %s ",da.toString().latin1() ); 524 qDebug("time %s ",da.toString().latin1() );
509#endif 525#endif
510 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 526 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
511 size = item->att_data.att_static->att_data.att_rfc822_size; 527 size = item->att_data.att_static->att_data.att_rfc822_size;
512 } 528 }
513 } 529 }
514 /* msg is already deleted */ 530 /* msg is already deleted */
515 if (mFlags.testBit(FLAG_DELETED) && m) { 531 if (mFlags.testBit(FLAG_DELETED) && m) {
516 delete m; 532 delete m;
517 m = 0; 533 m = 0;
518 } 534 }
519 if (m) { 535 if (m) {
520 m->setFlags(mFlags); 536 m->setFlags(mFlags);
521 m->setMsgsize(size); 537 m->setMsgsize(size);
522 } 538 }
523 return m; 539 return m;
524} 540}
525 541
526RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) 542RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail)
527{ 543{
528 RecBodyP body = new RecBody(); 544 RecBodyP body = new RecBody();
529 const char *mb; 545 const char *mb;
530 int err = MAILIMAP_NO_ERROR; 546 int err = MAILIMAP_NO_ERROR;
531 clist *result = 0; 547 clist *result = 0;
532 clistcell *current; 548 clistcell *current;
533 mailimap_fetch_att *fetchAtt = 0; 549 mailimap_fetch_att *fetchAtt = 0;
534 mailimap_fetch_type *fetchType = 0; 550 mailimap_fetch_type *fetchType = 0;
535 mailimap_set *set = 0; 551 mailimap_set *set = 0;
536 mailimap_body*body_desc = 0; 552 mailimap_body*body_desc = 0;
537 553
538 mb = mail->getMbox().latin1(); 554 mb = mail->getMbox().latin1();
539 555
540 login(); 556 login();
541 if (!m_imap) { 557 if (!m_imap) {
542 return body; 558 return body;
543 } 559 }
544 err = selectMbox(mail->getMbox()); 560 err = selectMbox(mail->getMbox());
545 if ( err != MAILIMAP_NO_ERROR ) { 561 if ( err != MAILIMAP_NO_ERROR ) {
546 return body; 562 return body;
547 } 563 }
548 564
549 /* the range has to start at 1!!! not with 0!!!! */ 565 /* the range has to start at 1!!! not with 0!!!! */
550 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); 566 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
551 fetchAtt = mailimap_fetch_att_new_bodystructure(); 567 fetchAtt = mailimap_fetch_att_new_bodystructure();
552 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 568 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
553 err = mailimap_fetch( m_imap, set, fetchType, &result ); 569 err = mailimap_fetch( m_imap, set, fetchType, &result );
554 mailimap_set_free( set ); 570 mailimap_set_free( set );
555 mailimap_fetch_type_free( fetchType ); 571 mailimap_fetch_type_free( fetchType );
556 572
557 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 573 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
558 mailimap_msg_att * msg_att; 574 mailimap_msg_att * msg_att;
559 msg_att = (mailimap_msg_att*)current->data; 575 msg_att = (mailimap_msg_att*)current->data;
560 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 576 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
561 QValueList<int> path; 577 QValueList<int> path;
562 body_desc = item->att_data.att_static->att_data.att_body; 578 body_desc = item->att_data.att_static->att_data.att_body;
563 traverseBody(mail,body_desc,body,0,path); 579 traverseBody(mail,body_desc,body,0,path);
564 } else { 580 } else {
565 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; 581 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl;
566 } 582 }
567 if (result) mailimap_fetch_list_free(result); 583 if (result) mailimap_fetch_list_free(result);
568 return body; 584 return body;
569} 585}
570 586
571QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 587QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
572{ 588{
573 QStringList l; 589 QStringList l;
574 QString from; 590 QString from;
575 bool named_from; 591 bool named_from;
576 clistcell *current = NULL; 592 clistcell *current = NULL;
577 mailimap_address * current_address=NULL; 593 mailimap_address * current_address=NULL;
578 if (!list) { 594 if (!list) {
579 return l; 595 return l;
580 } 596 }
581 unsigned int count = 0; 597 unsigned int count = 0;
582 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 598 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
583 from = ""; 599 from = "";
584 named_from = false; 600 named_from = false;
585 current_address=(mailimap_address*)current->data; 601 current_address=(mailimap_address*)current->data;
586 if (current_address->ad_personal_name){ 602 if (current_address->ad_personal_name){
587 from+=convert_String((const char*)current_address->ad_personal_name); 603 from+=convert_String((const char*)current_address->ad_personal_name);
588 from+=" "; 604 from+=" ";
589 named_from = true; 605 named_from = true;
590 } 606 }
591 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 607 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
592 from+="<"; 608 from+="<";
593 } 609 }
594 if (current_address->ad_mailbox_name) { 610 if (current_address->ad_mailbox_name) {
595 from+=QString(current_address->ad_mailbox_name); 611 from+=QString(current_address->ad_mailbox_name);
596 from+="@"; 612 from+="@";
597 } 613 }
598 if (current_address->ad_host_name) { 614 if (current_address->ad_host_name) {
599 from+=QString(current_address->ad_host_name); 615 from+=QString(current_address->ad_host_name);
600 } 616 }
601 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 617 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
602 from+=">"; 618 from+=">";
603 } 619 }
604 l.append(QString(from)); 620 l.append(QString(from));
605 if (++count > 99) { 621 if (++count > 99) {
606 break; 622 break;
607 } 623 }
608 } 624 }
609 return l; 625 return l;
610} 626}
611 627
612encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) 628encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call)
613{ 629{
614 encodedString*res=new encodedString; 630 encodedString*res=new encodedString;
615 int err; 631 int err;
616 mailimap_fetch_type *fetchType; 632 mailimap_fetch_type *fetchType;
617 mailimap_set *set; 633 mailimap_set *set;
618 clistcell*current,*cur; 634 clistcell*current,*cur;
619 mailimap_section_part * section_part = 0; 635 mailimap_section_part * section_part = 0;
620 mailimap_section_spec * section_spec = 0; 636 mailimap_section_spec * section_spec = 0;
621 mailimap_section * section = 0; 637 mailimap_section * section = 0;
622 mailimap_fetch_att * fetch_att = 0; 638 mailimap_fetch_att * fetch_att = 0;
623 639
624 login(); 640 login();
625 if (!m_imap) { 641 if (!m_imap) {
626 return res; 642 return res;
627 } 643 }
628 if (!internal_call) { 644 if (!internal_call) {
629 err = selectMbox(mail->getMbox()); 645 err = selectMbox(mail->getMbox());
630 if ( err != MAILIMAP_NO_ERROR ) { 646 if ( err != MAILIMAP_NO_ERROR ) {
631 return res; 647 return res;
632 } 648 }
633 } 649 }
634 set = mailimap_set_new_single(mail->getNumber()); 650 set = mailimap_set_new_single(mail->getNumber());
635 651
636 clist*id_list = 0; 652 clist*id_list = 0;
637 653
638 /* if path == empty then its a request for the whole rfc822 mail and generates 654 /* if path == empty then its a request for the whole rfc822 mail and generates
639 a "fetch <id> (body[])" statement on imap server */ 655 a "fetch <id> (body[])" statement on imap server */
640 if (path.count()>0 ) { 656 if (path.count()>0 ) {
641 id_list = clist_new(); 657 id_list = clist_new();
642 for (unsigned j=0; j < path.count();++j) { 658 for (unsigned j=0; j < path.count();++j) {
643 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 659 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
644 *p_id = path[j]; 660 *p_id = path[j];
645 clist_append(id_list,p_id); 661 clist_append(id_list,p_id);
646 } 662 }
647 section_part = mailimap_section_part_new(id_list); 663 section_part = mailimap_section_part_new(id_list);
648 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 664 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
649 } 665 }
650 666
651 section = mailimap_section_new(section_spec); 667 section = mailimap_section_new(section_spec);
652 fetch_att = mailimap_fetch_att_new_body_section(section); 668 fetch_att = mailimap_fetch_att_new_body_section(section);
653 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 669 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
654 670
655 clist*result = 0; 671 clist*result = 0;
656 672
657 err = mailimap_fetch( m_imap, set, fetchType, &result ); 673 err = mailimap_fetch( m_imap, set, fetchType, &result );
658 mailimap_set_free( set ); 674 mailimap_set_free( set );
659 mailimap_fetch_type_free( fetchType ); 675 mailimap_fetch_type_free( fetchType );
660 676
661 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 677 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
662 mailimap_msg_att * msg_att; 678 mailimap_msg_att * msg_att;
663 msg_att = (mailimap_msg_att*)current->data; 679 msg_att = (mailimap_msg_att*)current->data;
664 mailimap_msg_att_item*msg_att_item; 680 mailimap_msg_att_item*msg_att_item;
665 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 681 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
666 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 682 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
667 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 683 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
668 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 684 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
669 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 685 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
670 /* detach - we take over the content */ 686 /* detach - we take over the content */
671 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 687 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
672 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 688 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
673 } 689 }
674 } 690 }
675 } 691 }
676 } else { 692 } else {
677 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; 693 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl;
678 } 694 }
679 if (result) mailimap_fetch_list_free(result); 695 if (result) mailimap_fetch_list_free(result);
680 return res; 696 return res;
681} 697}
682 698
683/* current_recursion is for recursive calls. 699/* current_recursion is for recursive calls.
684 current_count means the position inside the internal loop! */ 700 current_count means the position inside the internal loop! */
685void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, 701void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,
686 int current_recursion,QValueList<int>recList,int current_count) 702 int current_recursion,QValueList<int>recList,int current_count)
687{ 703{
688 if (!body || current_recursion>=10) { 704 if (!body || current_recursion>=10) {
689 return; 705 return;
690 } 706 }
691 switch (body->bd_type) { 707 switch (body->bd_type) {
692 case MAILIMAP_BODY_1PART: 708 case MAILIMAP_BODY_1PART:
693 { 709 {
694 QValueList<int>countlist = recList; 710 QValueList<int>countlist = recList;
695 countlist.append(current_count); 711 countlist.append(current_count);
696 RecPartP currentPart = new RecPart(); 712 RecPartP currentPart = new RecPart();
697 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 713 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
698 QString id(""); 714 QString id("");
699 currentPart->setPositionlist(countlist); 715 currentPart->setPositionlist(countlist);
700 for (unsigned int j = 0; j < countlist.count();++j) { 716 for (unsigned int j = 0; j < countlist.count();++j) {
701 id+=(j>0?" ":""); 717 id+=(j>0?" ":"");
702 id+=QString("%1").arg(countlist[j]); 718 id+=QString("%1").arg(countlist[j]);
703 } 719 }
704 //odebug << "ID = " << id.latin1() << "" << oendl; 720 //odebug << "ID = " << id.latin1() << "" << oendl;
705 currentPart->setIdentifier(id); 721 currentPart->setIdentifier(id);
706 fillSinglePart(currentPart,part1); 722 fillSinglePart(currentPart,part1);
707 /* important: Check for is NULL 'cause a body can be empty! 723 /* important: Check for is NULL 'cause a body can be empty!
708 And we put it only into the mail if it is the FIRST part */ 724 And we put it only into the mail if it is the FIRST part */
709 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { 725 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) {
710 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); 726 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
711 target_body->setDescription(currentPart); 727 target_body->setDescription(currentPart);
712 target_body->setBodytext(body_text); 728 target_body->setBodytext(body_text);
713 if (countlist.count()>1) { 729 if (countlist.count()>1) {
714 target_body->addPart(currentPart); 730 target_body->addPart(currentPart);
715 } 731 }
716 } else { 732 } else {
717 target_body->addPart(currentPart); 733 target_body->addPart(currentPart);
718 } 734 }
719 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 735 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
720 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 736 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
721 } 737 }
722 } 738 }
723 break; 739 break;
724 case MAILIMAP_BODY_MPART: 740 case MAILIMAP_BODY_MPART:
725 { 741 {
726 QValueList<int>countlist = recList; 742 QValueList<int>countlist = recList;
727 clistcell*current=0; 743 clistcell*current=0;
728 mailimap_body*current_body=0; 744 mailimap_body*current_body=0;
729 unsigned int ccount = 1; 745 unsigned int ccount = 1;
730 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 746 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
731 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 747 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
732 current_body = (mailimap_body*)current->data; 748 current_body = (mailimap_body*)current->data;
733 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 749 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
734 RecPartP targetPart = new RecPart(); 750 RecPartP targetPart = new RecPart();
735 targetPart->setType("multipart"); 751 targetPart->setType("multipart");
736 fillMultiPart(targetPart,mailDescription); 752 fillMultiPart(targetPart,mailDescription);
737 countlist.append(current_count); 753 countlist.append(current_count);
738 targetPart->setPositionlist(countlist); 754 targetPart->setPositionlist(countlist);
739 target_body->addPart(targetPart); 755 target_body->addPart(targetPart);
740 QString id(""); 756 QString id("");
741 for (unsigned int j = 0; j < countlist.count();++j) { 757 for (unsigned int j = 0; j < countlist.count();++j) {
742 id+=(j>0?" ":""); 758 id+=(j>0?" ":"");
743 id+=QString("%1").arg(countlist[j]); 759 id+=QString("%1").arg(countlist[j]);
744 } 760 }
745 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; 761 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
746 } 762 }
747 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 763 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
748 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 764 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
749 countlist = recList; 765 countlist = recList;
750 } 766 }
751 ++ccount; 767 ++ccount;
752 } 768 }
753 } 769 }
754 break; 770 break;
755 default: 771 default:
756 break; 772 break;
757 } 773 }
758} 774}
759 775
760void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) 776void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description)
761{ 777{
762 if (!Description) { 778 if (!Description) {
763 return; 779 return;
764 } 780 }
765 switch (Description->bd_type) { 781 switch (Description->bd_type) {
766 case MAILIMAP_BODY_TYPE_1PART_TEXT: 782 case MAILIMAP_BODY_TYPE_1PART_TEXT:
767 target_part->setType("text"); 783 target_part->setType("text");
768 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 784 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
769 break; 785 break;
770 case MAILIMAP_BODY_TYPE_1PART_BASIC: 786 case MAILIMAP_BODY_TYPE_1PART_BASIC:
771 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 787 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
772 break; 788 break;
773 case MAILIMAP_BODY_TYPE_1PART_MSG: 789 case MAILIMAP_BODY_TYPE_1PART_MSG:
774 target_part->setType("message"); 790 target_part->setType("message");
775 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 791 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
776 break; 792 break;
777 default: 793 default:
778 break; 794 break;
779 } 795 }
780} 796}
781 797
782void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) 798void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which)
783{ 799{
784 if (!which) { 800 if (!which) {
785 return; 801 return;
786 } 802 }
787 QString sub; 803 QString sub;
788 sub = which->bd_media_text; 804 sub = which->bd_media_text;
789 //odebug << "Type= text/" << which->bd_media_text << "" << oendl; 805 //odebug << "Type= text/" << which->bd_media_text << "" << oendl;
790 target_part->setSubtype(sub.lower()); 806 target_part->setSubtype(sub.lower());
791 target_part->setLines(which->bd_lines); 807 target_part->setLines(which->bd_lines);
792 fillBodyFields(target_part,which->bd_fields); 808 fillBodyFields(target_part,which->bd_fields);
793} 809}
794 810
795void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) 811void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
796{ 812{
797 if (!which) { 813 if (!which) {
798 return; 814 return;
799 } 815 }
800 target_part->setSubtype("rfc822"); 816 target_part->setSubtype("rfc822");
801 //odebug << "Message part" << oendl; 817 //odebug << "Message part" << oendl;
802 /* we set this type to text/plain */ 818 /* we set this type to text/plain */
803 target_part->setLines(which->bd_lines); 819 target_part->setLines(which->bd_lines);
804 fillBodyFields(target_part,which->bd_fields); 820 fillBodyFields(target_part,which->bd_fields);
805} 821}
806 822
807void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) 823void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
808{ 824{
809 if (!which) return; 825 if (!which) return;
810 QString sub = which->bd_media_subtype; 826 QString sub = which->bd_media_subtype;
811 target_part->setSubtype(sub.lower()); 827 target_part->setSubtype(sub.lower());
812 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 828 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
813 clistcell*cur = 0; 829 clistcell*cur = 0;
814 mailimap_single_body_fld_param*param=0; 830 mailimap_single_body_fld_param*param=0;
815 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 831 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
816 param = (mailimap_single_body_fld_param*)cur->data; 832 param = (mailimap_single_body_fld_param*)cur->data;
817 if (param) { 833 if (param) {
818 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 834 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
819 } 835 }
820 } 836 }
821 } 837 }
822} 838}
823 839
824void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) 840void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
825{ 841{
826 if (!which) { 842 if (!which) {
827 return; 843 return;
828 } 844 }
829 QString type,sub; 845 QString type,sub;
830 switch (which->bd_media_basic->med_type) { 846 switch (which->bd_media_basic->med_type) {
831 case MAILIMAP_MEDIA_BASIC_APPLICATION: 847 case MAILIMAP_MEDIA_BASIC_APPLICATION:
832 type = "application"; 848 type = "application";
833 break; 849 break;
834 case MAILIMAP_MEDIA_BASIC_AUDIO: 850 case MAILIMAP_MEDIA_BASIC_AUDIO:
835 type = "audio"; 851 type = "audio";
836 break; 852 break;
837 case MAILIMAP_MEDIA_BASIC_IMAGE: 853 case MAILIMAP_MEDIA_BASIC_IMAGE:
838 type = "image"; 854 type = "image";
839 break; 855 break;
840 case MAILIMAP_MEDIA_BASIC_MESSAGE: 856 case MAILIMAP_MEDIA_BASIC_MESSAGE:
841 type = "message"; 857 type = "message";
842 break; 858 break;
843 case MAILIMAP_MEDIA_BASIC_VIDEO: 859 case MAILIMAP_MEDIA_BASIC_VIDEO:
844 type = "video"; 860 type = "video";
845 break; 861 break;
846 case MAILIMAP_MEDIA_BASIC_OTHER: 862 case MAILIMAP_MEDIA_BASIC_OTHER:
847 default: 863 default:
848 if (which->bd_media_basic->med_basic_type) { 864 if (which->bd_media_basic->med_basic_type) {
849 type = which->bd_media_basic->med_basic_type; 865 type = which->bd_media_basic->med_basic_type;
850 } else { 866 } else {
851 type = ""; 867 type = "";
852 } 868 }
853 break; 869 break;
854 } 870 }
855 if (which->bd_media_basic->med_subtype) { 871 if (which->bd_media_basic->med_subtype) {
856 sub = which->bd_media_basic->med_subtype; 872 sub = which->bd_media_basic->med_subtype;
857 } else { 873 } else {
858 sub = ""; 874 sub = "";
859 } 875 }
860 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; 876 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
861 target_part->setType(type.lower()); 877 target_part->setType(type.lower());
862 target_part->setSubtype(sub.lower()); 878 target_part->setSubtype(sub.lower());
863 fillBodyFields(target_part,which->bd_fields); 879 fillBodyFields(target_part,which->bd_fields);
864} 880}
865 881
866void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) 882void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
867{ 883{
868 if (!which) return; 884 if (!which) return;
869 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 885 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
870 clistcell*cur; 886 clistcell*cur;
871 mailimap_single_body_fld_param*param=0; 887 mailimap_single_body_fld_param*param=0;
872 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 888 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
873 param = (mailimap_single_body_fld_param*)cur->data; 889 param = (mailimap_single_body_fld_param*)cur->data;
874 if (param) { 890 if (param) {
875 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 891 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
876 } 892 }
877 } 893 }
878 } 894 }
879 mailimap_body_fld_enc*enc = which->bd_encoding; 895 mailimap_body_fld_enc*enc = which->bd_encoding;
880 QString encoding(""); 896 QString encoding("");
881 switch (enc->enc_type) { 897 switch (enc->enc_type) {
882 case MAILIMAP_BODY_FLD_ENC_7BIT: 898 case MAILIMAP_BODY_FLD_ENC_7BIT:
883 encoding = "7bit"; 899 encoding = "7bit";
884 break; 900 break;
885 case MAILIMAP_BODY_FLD_ENC_8BIT: 901 case MAILIMAP_BODY_FLD_ENC_8BIT:
886 encoding = "8bit"; 902 encoding = "8bit";
887 break; 903 break;
888 case MAILIMAP_BODY_FLD_ENC_BINARY: 904 case MAILIMAP_BODY_FLD_ENC_BINARY:
889 encoding="binary"; 905 encoding="binary";
890 break; 906 break;
891 case MAILIMAP_BODY_FLD_ENC_BASE64: 907 case MAILIMAP_BODY_FLD_ENC_BASE64:
892 encoding="base64"; 908 encoding="base64";
893 break; 909 break;
894 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 910 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
895 encoding="quoted-printable"; 911 encoding="quoted-printable";
896 break; 912 break;
897 case MAILIMAP_BODY_FLD_ENC_OTHER: 913 case MAILIMAP_BODY_FLD_ENC_OTHER:
898 default: 914 default:
899 if (enc->enc_value) { 915 if (enc->enc_value) {
900 char*t=enc->enc_value; 916 char*t=enc->enc_value;
901 encoding=QString(enc->enc_value); 917 encoding=QString(enc->enc_value);
902 enc->enc_value=0L; 918 enc->enc_value=0L;
903 free(t); 919 free(t);
904 } 920 }
905 } 921 }
906 if (which->bd_description) { 922 if (which->bd_description) {
907 target_part->setDescription(QString(which->bd_description)); 923 target_part->setDescription(QString(which->bd_description));
908 } 924 }
909 target_part->setEncoding(encoding); 925 target_part->setEncoding(encoding);
910 target_part->setSize(which->bd_size); 926 target_part->setSize(which->bd_size);
911} 927}
912void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) 928void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target)
913{ 929{
914 //#if 0 930 //#if 0
915 mailimap_flag_list*flist; 931 mailimap_flag_list*flist;
916 mailimap_set *set; 932 mailimap_set *set;
917 mailimap_store_att_flags * store_flags; 933 mailimap_store_att_flags * store_flags;
918 int err; 934 int err;
919 login(); 935 login();
920 //#endif 936 //#endif
921 if (!m_imap) { 937 if (!m_imap) {
922 return; 938 return;
923 } 939 }
924 int iii = 0; 940 int iii = 0;
925 int count = target.count(); 941 int count = target.count();
926 // qDebug("imap remove count %d ", count); 942 // qDebug("imap remove count %d ", count);
927 943
928 944
929 mMax = count; 945 mMax = count;
930 //progress( tr("Delete")); 946 //progress( tr("Delete"));
931 QWidget wid; 947 QWidget wid;
932 wid.show(); 948 wid.show();
933 while (iii < count ) { 949 while (iii < count ) {
934 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); 950 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count));
935 wid.raise(); 951 wid.raise();
936 qApp->processEvents(); 952 qApp->processEvents();
937 RecMailP mail = (*target.at( iii )); 953 RecMailP mail = (*target.at( iii ));
938 //#if 0 954 //#if 0
939 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); 955 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() );
940 err = selectMbox(mail->getMbox()); 956 err = selectMbox(mail->getMbox());
941 if ( err != MAILIMAP_NO_ERROR ) { 957 if ( err != MAILIMAP_NO_ERROR ) {
942 return; 958 return;
943 } 959 }
944 flist = mailimap_flag_list_new_empty(); 960 flist = mailimap_flag_list_new_empty();
945 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 961 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
946 store_flags = mailimap_store_att_flags_new_set_flags(flist); 962 store_flags = mailimap_store_att_flags_new_set_flags(flist);
947 set = mailimap_set_new_single(mail->getNumber()); 963 set = mailimap_set_new_single(mail->getNumber());
948 err = mailimap_store(m_imap,set,store_flags); 964 err = mailimap_store(m_imap,set,store_flags);
949 mailimap_set_free( set ); 965 mailimap_set_free( set );
950 mailimap_store_att_flags_free(store_flags); 966 mailimap_store_att_flags_free(store_flags);
951 967
952 if (err != MAILIMAP_NO_ERROR) { 968 if (err != MAILIMAP_NO_ERROR) {
953 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 969 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
954 return; 970 return;
955 } 971 }
956 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 972 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
957 /* should we realy do that at this moment? */ 973 /* should we realy do that at this moment? */
958 974
959 // err = mailimap_expunge(m_imap); 975 // err = mailimap_expunge(m_imap);
960 //if (err != MAILIMAP_NO_ERROR) { 976 //if (err != MAILIMAP_NO_ERROR) {
961 // Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); 977 // Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response));
962 // } 978 // }
963 //#endif 979 //#endif
964 //deleteMail( mail); 980 //deleteMail( mail);
965 ++iii; 981 ++iii;
966 } 982 }
967 //qDebug("Deleting imap mails... "); 983 //qDebug("Deleting imap mails... ");
968 err = mailimap_expunge(m_imap); 984 err = mailimap_expunge(m_imap);
969 if (err != MAILIMAP_NO_ERROR) { 985 if (err != MAILIMAP_NO_ERROR) {
970 Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); 986 Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response));
971 } 987 }
972} 988}
973void IMAPwrapper::deleteMail(const RecMailP&mail) 989void IMAPwrapper::deleteMail(const RecMailP&mail)
974{ 990{
975 mailimap_flag_list*flist; 991 mailimap_flag_list*flist;
976 mailimap_set *set; 992 mailimap_set *set;
977 mailimap_store_att_flags * store_flags; 993 mailimap_store_att_flags * store_flags;
978 int err; 994 int err;
979 login(); 995 login();
980 if (!m_imap) { 996 if (!m_imap) {
981 return; 997 return;
982 } 998 }
983 err = selectMbox(mail->getMbox()); 999 err = selectMbox(mail->getMbox());
984 if ( err != MAILIMAP_NO_ERROR ) { 1000 if ( err != MAILIMAP_NO_ERROR ) {
985 return; 1001 return;
986 } 1002 }
987 flist = mailimap_flag_list_new_empty(); 1003 flist = mailimap_flag_list_new_empty();
988 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1004 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
989 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1005 store_flags = mailimap_store_att_flags_new_set_flags(flist);
990 set = mailimap_set_new_single(mail->getNumber()); 1006 set = mailimap_set_new_single(mail->getNumber());
991 err = mailimap_store(m_imap,set,store_flags); 1007 err = mailimap_store(m_imap,set,store_flags);
992 mailimap_set_free( set ); 1008 mailimap_set_free( set );
993 mailimap_store_att_flags_free(store_flags); 1009 mailimap_store_att_flags_free(store_flags);
994 1010
995 if (err != MAILIMAP_NO_ERROR) { 1011 if (err != MAILIMAP_NO_ERROR) {
996 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 1012 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
997 return; 1013 return;
998 } 1014 }
999 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1015 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1000 /* should we realy do that at this moment? */ 1016 /* should we realy do that at this moment? */
1001 1017
1002 err = mailimap_expunge(m_imap); 1018 err = mailimap_expunge(m_imap);
1003 if (err != MAILIMAP_NO_ERROR) { 1019 if (err != MAILIMAP_NO_ERROR) {
1004 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1020 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1005 } 1021 }
1006 //qDebug("IMAPwrapper::deleteMail 2"); 1022 //qDebug("IMAPwrapper::deleteMail 2");
1007 1023
1008} 1024}
1009 1025
1010void IMAPwrapper::answeredMail(const RecMailP&mail) 1026void IMAPwrapper::answeredMail(const RecMailP&mail)
1011{ 1027{
1012 mailimap_flag_list*flist; 1028 mailimap_flag_list*flist;
1013 mailimap_set *set; 1029 mailimap_set *set;
1014 mailimap_store_att_flags * store_flags; 1030 mailimap_store_att_flags * store_flags;
1015 int err; 1031 int err;
1016 login(); 1032 login();
1017 if (!m_imap) { 1033 if (!m_imap) {
1018 return; 1034 return;
1019 } 1035 }
1020 err = selectMbox(mail->getMbox()); 1036 err = selectMbox(mail->getMbox());
1021 if ( err != MAILIMAP_NO_ERROR ) { 1037 if ( err != MAILIMAP_NO_ERROR ) {
1022 return; 1038 return;
1023 } 1039 }
1024 flist = mailimap_flag_list_new_empty(); 1040 flist = mailimap_flag_list_new_empty();
1025 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 1041 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
1026 store_flags = mailimap_store_att_flags_new_add_flags(flist); 1042 store_flags = mailimap_store_att_flags_new_add_flags(flist);
1027 set = mailimap_set_new_single(mail->getNumber()); 1043 set = mailimap_set_new_single(mail->getNumber());
1028 err = mailimap_store(m_imap,set,store_flags); 1044 err = mailimap_store(m_imap,set,store_flags);
1029 mailimap_set_free( set ); 1045 mailimap_set_free( set );
1030 mailimap_store_att_flags_free(store_flags); 1046 mailimap_store_att_flags_free(store_flags);
1031 1047
1032 if (err != MAILIMAP_NO_ERROR) { 1048 if (err != MAILIMAP_NO_ERROR) {
1033 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; 1049 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
1034 return; 1050 return;
1035 } 1051 }
1036} 1052}
1037 1053
1038QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 1054QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
1039{ 1055{
1040 QString body(""); 1056 QString body("");
1041 encodedString*res = fetchRawPart(mail,path,internal_call); 1057 encodedString*res = fetchRawPart(mail,path,internal_call);
1042 encodedString*r = decode_String(res,enc); 1058 encodedString*r = decode_String(res,enc);
1043 delete res; 1059 delete res;
1044 if (r) { 1060 if (r) {
1045 if (r->Length()>0) { 1061 if (r->Length()>0) {
1046 body = r->Content(); 1062 body = r->Content();
1047 } 1063 }
1048 delete r; 1064 delete r;
1049 } 1065 }
1050 return body; 1066 return body;
1051} 1067}
1052 1068
1053QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 1069QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
1054{ 1070{
1055 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 1071 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
1056} 1072}
1057 1073
1058encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1074encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
1059{ 1075{
1060 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1076 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
1061 encodedString*r = decode_String(res,part->Encoding()); 1077 encodedString*r = decode_String(res,part->Encoding());
1062 delete res; 1078 delete res;
1063 return r; 1079 return r;
1064} 1080}
1065 1081
1066encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1082encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
1067{ 1083{
1068 return fetchRawPart(mail,part->Positionlist(),false); 1084 return fetchRawPart(mail,part->Positionlist(),false);
1069} 1085}
1070 1086
1071int IMAPwrapper::deleteAllMail(const FolderP&folder) 1087int IMAPwrapper::deleteAllMail(const FolderP&folder)
1072{ 1088{
1073 login(); 1089 login();
1074 if (!m_imap) { 1090 if (!m_imap) {
1075 return 0; 1091 return 0;
1076 } 1092 }
1077 mailimap_flag_list*flist; 1093 mailimap_flag_list*flist;
1078 mailimap_set *set; 1094 mailimap_set *set;
1079 mailimap_store_att_flags * store_flags; 1095 mailimap_store_att_flags * store_flags;
1080 int err = selectMbox(folder->getName()); 1096 int err = selectMbox(folder->getName());
1081 if ( err != MAILIMAP_NO_ERROR ) { 1097 if ( err != MAILIMAP_NO_ERROR ) {
1082 return 0; 1098 return 0;
1083 } 1099 }
1084 1100
1085 int last = m_imap->imap_selection_info->sel_exists; 1101 int last = m_imap->imap_selection_info->sel_exists;
1086 if (last == 0) { 1102 if (last == 0) {
1087 Global::statusMessage(tr("Mailbox has no mails!")); 1103 Global::statusMessage(tr("Mailbox has no mails!"));
1088 return 0; 1104 return 0;
1089 } 1105 }
1090 flist = mailimap_flag_list_new_empty(); 1106 flist = mailimap_flag_list_new_empty();
1091 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1107 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1092 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1108 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1093 set = mailimap_set_new_interval( 1, last ); 1109 set = mailimap_set_new_interval( 1, last );
1094 err = mailimap_store(m_imap,set,store_flags); 1110 err = mailimap_store(m_imap,set,store_flags);
1095 mailimap_set_free( set ); 1111 mailimap_set_free( set );
1096 mailimap_store_att_flags_free(store_flags); 1112 mailimap_store_att_flags_free(store_flags);
1097 if (err != MAILIMAP_NO_ERROR) { 1113 if (err != MAILIMAP_NO_ERROR) {
1098 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1114 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1099 return 0; 1115 return 0;
1100 } 1116 }
1101 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1117 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1102 /* should we realy do that at this moment? */ 1118 /* should we realy do that at this moment? */
1103 err = mailimap_expunge(m_imap); 1119 err = mailimap_expunge(m_imap);
1104 if (err != MAILIMAP_NO_ERROR) { 1120 if (err != MAILIMAP_NO_ERROR) {
1105 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1121 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1106 return 0; 1122 return 0;
1107 } 1123 }
1108 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1124 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1109 return 1; 1125 return 1;
1110} 1126}
1111 1127
1112int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1128int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1113{ 1129{
1114 if (folder.length()==0) return 0; 1130 if (folder.length()==0) return 0;
1115 login(); 1131 login();
1116 if (!m_imap) {return 0;} 1132 if (!m_imap) {return 0;}
1117 QString pre = account->getPrefix(); 1133 QString pre = account->getPrefix();
1118 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1134 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
1119 pre+=delemiter; 1135 pre+=delemiter;
1120 } 1136 }
1121 if (parentfolder) { 1137 if (parentfolder) {
1122 pre += parentfolder->getDisplayName()+delemiter; 1138 pre += parentfolder->getDisplayName()+delemiter;
1123 } 1139 }
1124 pre+=folder; 1140 pre+=folder;
1125 if (getsubfolder) { 1141 if (getsubfolder) {
1126 if (delemiter.length()>0) { 1142 if (delemiter.length()>0) {
1127 pre+=delemiter; 1143 pre+=delemiter;
1128 } else { 1144 } else {
1129 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 1145 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
1130 return 0; 1146 return 0;
1131 } 1147 }
1132 } 1148 }
1133 // odebug << "Creating " << pre.latin1() << "" << oendl; 1149 // odebug << "Creating " << pre.latin1() << "" << oendl;
1134 int res = mailimap_create(m_imap,pre.latin1()); 1150 int res = mailimap_create(m_imap,pre.latin1());
1135 if (res != MAILIMAP_NO_ERROR) { 1151 if (res != MAILIMAP_NO_ERROR) {
1136 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1152 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1137 return 0; 1153 return 0;
1138 } 1154 }
1139 return 1; 1155 return 1;
1140} 1156}
1141 1157
1142int IMAPwrapper::deleteMbox(const FolderP&folder) 1158int IMAPwrapper::deleteMbox(const FolderP&folder)
1143{ 1159{
1144 if (!folder) return 0; 1160 if (!folder) return 0;
1145 login(); 1161 login();
1146 if (!m_imap) {return 0;} 1162 if (!m_imap) {return 0;}
1147 int res = mailimap_delete(m_imap,folder->getName()); 1163 int res = mailimap_delete(m_imap,folder->getName());
1148 if (res != MAILIMAP_NO_ERROR) { 1164 if (res != MAILIMAP_NO_ERROR) {
1149 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1165 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1150 return 0; 1166 return 0;
1151 } 1167 }
1152 return 1; 1168 return 1;
1153} 1169}
1154 1170
1155void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1171void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1156{ 1172{
1157 mailimap_status_att_list * att_list =0; 1173 mailimap_status_att_list * att_list =0;
1158 mailimap_mailbox_data_status * status=0; 1174 mailimap_mailbox_data_status * status=0;
1159 clistiter * cur = 0; 1175 clistiter * cur = 0;
1160 int r = 0; 1176 int r = 0;
1161 target_stat.message_count = 0; 1177 target_stat.message_count = 0;
1162 target_stat.message_unseen = 0; 1178 target_stat.message_unseen = 0;
1163 target_stat.message_recent = 0; 1179 target_stat.message_recent = 0;
1164 login(); 1180 login();
1165 if (!m_imap) { 1181 if (!m_imap) {
1166 return; 1182 return;
1167 } 1183 }
1168 att_list = mailimap_status_att_list_new_empty(); 1184 att_list = mailimap_status_att_list_new_empty();
1169 if (!att_list) return; 1185 if (!att_list) return;
1170 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1186 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1171 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1187 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1172 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1188 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1173 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1189 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1174 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1190 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1175 for (cur = clist_begin(status->st_info_list); 1191 for (cur = clist_begin(status->st_info_list);
1176 cur != NULL ; cur = clist_next(cur)) { 1192 cur != NULL ; cur = clist_next(cur)) {
1177 mailimap_status_info * status_info; 1193 mailimap_status_info * status_info;
1178 status_info = (mailimap_status_info *)clist_content(cur); 1194 status_info = (mailimap_status_info *)clist_content(cur);
1179 switch (status_info->st_att) { 1195 switch (status_info->st_att) {
1180 case MAILIMAP_STATUS_ATT_MESSAGES: 1196 case MAILIMAP_STATUS_ATT_MESSAGES:
1181 target_stat.message_count = status_info->st_value; 1197 target_stat.message_count = status_info->st_value;
1182 break; 1198 break;
1183 case MAILIMAP_STATUS_ATT_RECENT: 1199 case MAILIMAP_STATUS_ATT_RECENT:
1184 target_stat.message_recent = status_info->st_value; 1200 target_stat.message_recent = status_info->st_value;
1185 break; 1201 break;
1186 case MAILIMAP_STATUS_ATT_UNSEEN: 1202 case MAILIMAP_STATUS_ATT_UNSEEN:
1187 target_stat.message_unseen = status_info->st_value; 1203 target_stat.message_unseen = status_info->st_value;
1188 break; 1204 break;
1189 } 1205 }
1190 } 1206 }
1191 } else { 1207 } else {
1192 // odebug << "Error retrieving status" << oendl; 1208 // odebug << "Error retrieving status" << oendl;
1193 } 1209 }
1194 if (status) mailimap_mailbox_data_status_free(status); 1210 if (status) mailimap_mailbox_data_status_free(status);
1195 if (att_list) mailimap_status_att_list_free(att_list); 1211 if (att_list) mailimap_status_att_list_free(att_list);
1196} 1212}
1197 1213
1198void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1214void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1199{ 1215{
1200 login(); 1216 login();
1201 if (!m_imap) return; 1217 if (!m_imap) return;
1202 if (!msg) return; 1218 if (!msg) return;
1203 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1219 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1204 if (r != MAILIMAP_NO_ERROR) { 1220 if (r != MAILIMAP_NO_ERROR) {
1205 Global::statusMessage("Error storing mail!"); 1221 Global::statusMessage("Error storing mail!");
1206 } 1222 }
1207} 1223}
1208 1224
1209MAILLIB::ATYPE IMAPwrapper::getType()const 1225MAILLIB::ATYPE IMAPwrapper::getType()const
1210{ 1226{
1211 return account->getType(); 1227 return account->getType();
1212} 1228}
1213 1229
1214const QString&IMAPwrapper::getName()const 1230const QString&IMAPwrapper::getName()const
1215{ 1231{
1216 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1232 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1217 return account->getAccountName(); 1233 return account->getAccountName();
1218} 1234}
1219 1235
1220encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1236encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1221{ 1237{
1222 // dummy 1238 // dummy
1223 QValueList<int> path; 1239 QValueList<int> path;
1224 return fetchRawPart(mail,path,false); 1240 return fetchRawPart(mail,path,false);
1225} 1241}
1226 1242
1227void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1243void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1228 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 1244 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
diff --git a/kmicromail/libmailwrapper/imapwrapper.h b/kmicromail/libmailwrapper/imapwrapper.h
index db8ab5b..5535d8d 100644
--- a/kmicromail/libmailwrapper/imapwrapper.h
+++ b/kmicromail/libmailwrapper/imapwrapper.h
@@ -1,84 +1,85 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __IMAPWRAPPER 2#ifndef __IMAPWRAPPER
3#define __IMAPWRAPPER 3#define __IMAPWRAPPER
4 4
5#include <qlist.h> 5#include <qlist.h>
6#include "mailwrapper.h" 6#include "mailwrapper.h"
7#include "abstractmail.h" 7#include "abstractmail.h"
8#include <libetpan/clist.h> 8#include <libetpan/clist.h>
9 9
10struct mailimap; 10struct mailimap;
11struct mailimap_body; 11struct mailimap_body;
12struct mailimap_body_type_1part; 12struct mailimap_body_type_1part;
13struct mailimap_body_type_text; 13struct mailimap_body_type_text;
14struct mailimap_body_type_basic; 14struct mailimap_body_type_basic;
15struct mailimap_body_type_msg; 15struct mailimap_body_type_msg;
16struct mailimap_body_type_mpart; 16struct mailimap_body_type_mpart;
17struct mailimap_body_fields; 17struct mailimap_body_fields;
18struct mailimap_msg_att; 18struct mailimap_msg_att;
19class encodedString; 19class encodedString;
20 20
21class IMAPwrapper : public AbstractMail 21class IMAPwrapper : public AbstractMail
22{ 22{
23 Q_OBJECT 23 Q_OBJECT
24public: 24public:
25 IMAPwrapper( IMAPaccount *a ); 25 IMAPwrapper( IMAPaccount *a );
26 virtual ~IMAPwrapper(); 26 virtual ~IMAPwrapper();
27 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 27 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
28 virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target , int sizeInKb = 0); 28 virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target , int sizeInKb = 0);
29 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 29 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
30 30
31 virtual void deleteMail(const RecMailP&mail); 31 virtual void deleteMail(const RecMailP&mail);
32 void deleteMailList(const QValueList<RecMailP>&target); 32 void deleteMailList(const QValueList<RecMailP>&target);
33 virtual void answeredMail(const RecMailP&mail); 33 virtual void answeredMail(const RecMailP&mail);
34 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder); 34 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder);
35 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 35 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
36 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, 36 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,
37 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit,int sizeInKb = 0); 37 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit,int sizeInKb = 0);
38 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 38 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
39 39
40 virtual RecBodyP fetchBody(const RecMailP&mail); 40 virtual RecBodyP fetchBody(const RecMailP&mail);
41 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); 41 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part);
42 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); 42 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part);
43 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); 43 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part);
44 virtual encodedString* fetchRawBody(const RecMailP&mail); 44 virtual encodedString* fetchRawBody(const RecMailP&mail);
45 45
46 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, 46 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0,
47 const QString& delemiter="/",bool getsubfolder=false); 47 const QString& delemiter="/",bool getsubfolder=false);
48 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder); 48 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder);
49 49
50 static void imap_progress( size_t current, size_t maximum ); 50 static void imap_progress( size_t current, size_t maximum );
51 51
52 virtual void logout(); 52 virtual void logout();
53 virtual MAILLIB::ATYPE getType()const; 53 virtual MAILLIB::ATYPE getType()const;
54 virtual const QString&getName()const; 54 virtual const QString&getName()const;
55 virtual Account* getAccount() { return account; };
55 56
56protected: 57protected:
57 RecMail*parse_list_result(mailimap_msg_att*); 58 RecMail*parse_list_result(mailimap_msg_att*);
58 void login(); 59 void login();
59 bool start_tls(bool force=true); 60 bool start_tls(bool force=true);
60 61
61 virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 62 virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
62 virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call); 63 virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call);
63 int selectMbox(const QString&mbox); 64 int selectMbox(const QString&mbox);
64 65
65 void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description); 66 void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description);
66 void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which); 67 void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which);
67 void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which); 68 void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which);
68 void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which); 69 void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which);
69 void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which); 70 void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which);
70 void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1); 71 void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
71 72
72 /* just helpers */ 73 /* just helpers */
73 static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which); 74 static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which);
74 static QStringList address_list_to_stringlist(clist*list); 75 static QStringList address_list_to_stringlist(clist*list);
75 76
76 static void progress(QString mess = QString::null); 77 static void progress(QString mess = QString::null);
77 static int mCurrent; 78 static int mCurrent;
78 static int mMax; 79 static int mMax;
79 IMAPaccount *account; 80 IMAPaccount *account;
80 mailimap *m_imap; 81 mailimap *m_imap;
81 QString m_Lastmbox; 82 QString m_Lastmbox;
82}; 83};
83 84
84#endif 85#endif
diff --git a/kmicromail/libmailwrapper/mailtypes.cpp b/kmicromail/libmailwrapper/mailtypes.cpp
index d43bdc6..1a4ffd1 100644
--- a/kmicromail/libmailwrapper/mailtypes.cpp
+++ b/kmicromail/libmailwrapper/mailtypes.cpp
@@ -1,399 +1,422 @@
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 )
27{
28 if ( s1.isEmpty() && s2.isEmpty() )
29 return true;
30 return s1 == s2;
31}
26 32
33bool RecMail::isEqual( RecMail* r1 )
34{
35 if ( !stringCompareRec( isodate, r1->isodate ) ) {
36 // qDebug("date *%s* *%s* ", isodate.latin1(), r1->isodate.latin1());
37 return false;
38 }
39 if ( !stringCompareRec( from, r1->from ) ) {
40 //qDebug("from *%s* *%s* ", from.latin1(), r1->from.latin1());
41 return false;
42 }
43 if ( !stringCompareRec( subject, r1->subject ) ) {
44 //qDebug("sub ");
45 return false;
46 }
47
48 return true;
49}
27void RecMail::copy_old(const RecMail&old) 50void RecMail::copy_old(const RecMail&old)
28{ 51{
29 subject = old.subject; 52 subject = old.subject;
30 date = old.date; 53 date = old.date;
31 mbox = old.mbox; 54 mbox = old.mbox;
32 msg_id = old.msg_id; 55 msg_id = old.msg_id;
33 msg_size = old.msg_size; 56 msg_size = old.msg_size;
34 msg_number = old.msg_number; 57 msg_number = old.msg_number;
35 from = old.from; 58 from = old.from;
36 msg_flags = old.msg_flags; 59 msg_flags = old.msg_flags;
37 to = old.to; 60 to = old.to;
38 cc = old.cc; 61 cc = old.cc;
39 bcc = old.bcc; 62 bcc = old.bcc;
40 wrapper = old.wrapper; 63 wrapper = old.wrapper;
41 in_reply_to = old.in_reply_to; 64 in_reply_to = old.in_reply_to;
42 references = old.references; 65 references = old.references;
43 replyto = old.replyto; 66 replyto = old.replyto;
44} 67}
45 68
46void RecMail::init() 69void RecMail::init()
47{ 70{
48 to.clear(); 71 to.clear();
49 cc.clear(); 72 cc.clear();
50 bcc.clear(); 73 bcc.clear();
51 in_reply_to.clear(); 74 in_reply_to.clear();
52 references.clear(); 75 references.clear();
53 wrapper = 0; 76 wrapper = 0;
54} 77}
55 78
56void RecMail::setWrapper(AbstractMail*awrapper) 79void RecMail::setWrapper(AbstractMail*awrapper)
57{ 80{
58 wrapper = awrapper; 81 wrapper = awrapper;
59} 82}
60 83
61AbstractMail* RecMail::Wrapper() 84AbstractMail* RecMail::Wrapper()
62{ 85{
63 return wrapper; 86 return wrapper;
64} 87}
65 88
66void RecMail::setTo(const QStringList&list) 89void RecMail::setTo(const QStringList&list)
67{ 90{
68 to = list; 91 to = list;
69} 92}
70 93
71const QStringList&RecMail::To()const 94const QStringList&RecMail::To()const
72{ 95{
73 return to; 96 return to;
74} 97}
75 98
76void RecMail::setCC(const QStringList&list) 99void RecMail::setCC(const QStringList&list)
77{ 100{
78 cc = list; 101 cc = list;
79} 102}
80 103
81const QStringList&RecMail::CC()const 104const QStringList&RecMail::CC()const
82{ 105{
83 return cc; 106 return cc;
84} 107}
85 108
86void RecMail::setBcc(const QStringList&list) 109void RecMail::setBcc(const QStringList&list)
87{ 110{
88 bcc = list; 111 bcc = list;
89} 112}
90 113
91const QStringList& RecMail::Bcc()const 114const QStringList& RecMail::Bcc()const
92{ 115{
93 return bcc; 116 return bcc;
94} 117}
95 118
96void RecMail::setInreply(const QStringList&list) 119void RecMail::setInreply(const QStringList&list)
97{ 120{
98 in_reply_to = list; 121 in_reply_to = list;
99} 122}
100 123
101const QStringList& RecMail::Inreply()const 124const QStringList& RecMail::Inreply()const
102{ 125{
103 return in_reply_to; 126 return in_reply_to;
104} 127}
105 128
106void RecMail::setReferences(const QStringList&list) 129void RecMail::setReferences(const QStringList&list)
107{ 130{
108 references = list; 131 references = list;
109} 132}
110 133
111const QStringList& RecMail::References()const 134const QStringList& RecMail::References()const
112{ 135{
113 return references; 136 return references;
114} 137}
115 138
116RecPart::RecPart() 139RecPart::RecPart()
117 : Opie::Core::ORefCount(), 140 : Opie::Core::ORefCount(),
118 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) 141 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0)
119{ 142{
120 m_Parameters.clear(); 143 m_Parameters.clear();
121 m_poslist.clear(); 144 m_poslist.clear();
122} 145}
123 146
124RecPart::RecPart(const RecPart&old) 147RecPart::RecPart(const RecPart&old)
125 : Opie::Core::ORefCount(), 148 : Opie::Core::ORefCount(),
126 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) 149 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0)
127{ 150{
128 m_type = old.m_type; 151 m_type = old.m_type;
129 m_subtype = old.m_subtype; 152 m_subtype = old.m_subtype;
130 m_identifier = old.m_identifier; 153 m_identifier = old.m_identifier;
131 m_encoding = old.m_encoding; 154 m_encoding = old.m_encoding;
132 m_description = old.m_description; 155 m_description = old.m_description;
133 m_lines = old.m_lines; 156 m_lines = old.m_lines;
134 m_size = old.m_size; 157 m_size = old.m_size;
135 m_Parameters = old.m_Parameters; 158 m_Parameters = old.m_Parameters;
136 m_poslist = old.m_poslist; 159 m_poslist = old.m_poslist;
137 // odebug << "RecPart copy constructor" << oendl; 160 // odebug << "RecPart copy constructor" << oendl;
138} 161}
139 162
140RecPart::~RecPart() 163RecPart::~RecPart()
141{ 164{
142} 165}
143 166
144void RecPart::setSize(unsigned int size) 167void RecPart::setSize(unsigned int size)
145{ 168{
146 m_size = size; 169 m_size = size;
147} 170}
148 171
149const unsigned int RecPart::Size()const 172const unsigned int RecPart::Size()const
150{ 173{
151 return m_size; 174 return m_size;
152} 175}
153 176
154void RecPart::setLines(unsigned int lines) 177void RecPart::setLines(unsigned int lines)
155{ 178{
156 m_lines = lines; 179 m_lines = lines;
157} 180}
158 181
159const unsigned int RecPart::Lines()const 182const unsigned int RecPart::Lines()const
160{ 183{
161 return m_lines; 184 return m_lines;
162} 185}
163 186
164const QString& RecPart::Type()const 187const QString& RecPart::Type()const
165{ 188{
166 return m_type; 189 return m_type;
167} 190}
168 191
169void RecPart::setType(const QString&type) 192void RecPart::setType(const QString&type)
170{ 193{
171 m_type = type; 194 m_type = type;
172} 195}
173 196
174const QString& RecPart::Subtype()const 197const QString& RecPart::Subtype()const
175{ 198{
176 return m_subtype; 199 return m_subtype;
177} 200}
178 201
179void RecPart::setSubtype(const QString&subtype) 202void RecPart::setSubtype(const QString&subtype)
180{ 203{
181 m_subtype = subtype; 204 m_subtype = subtype;
182} 205}
183 206
184const QString& RecPart::Identifier()const 207const QString& RecPart::Identifier()const
185{ 208{
186 return m_identifier; 209 return m_identifier;
187} 210}
188 211
189void RecPart::setIdentifier(const QString&identifier) 212void RecPart::setIdentifier(const QString&identifier)
190{ 213{
191 m_identifier = identifier; 214 m_identifier = identifier;
192} 215}
193 216
194const QString& RecPart::Encoding()const 217const QString& RecPart::Encoding()const
195{ 218{
196 return m_encoding; 219 return m_encoding;
197} 220}
198 221
199void RecPart::setEncoding(const QString&encoding) 222void RecPart::setEncoding(const QString&encoding)
200{ 223{
201 m_encoding = encoding; 224 m_encoding = encoding;
202} 225}
203 226
204const QString& RecPart::Description()const 227const QString& RecPart::Description()const
205{ 228{
206 return m_description; 229 return m_description;
207} 230}
208 231
209void RecPart::setDescription(const QString&desc) 232void RecPart::setDescription(const QString&desc)
210{ 233{
211 m_description = desc; 234 m_description = desc;
212} 235}
213 236
214void RecPart::setParameters(const part_plist_t&list) 237void RecPart::setParameters(const part_plist_t&list)
215{ 238{
216 m_Parameters = list; 239 m_Parameters = list;
217} 240}
218 241
219const part_plist_t& RecPart::Parameters()const 242const part_plist_t& RecPart::Parameters()const
220{ 243{
221 return m_Parameters; 244 return m_Parameters;
222} 245}
223 246
224void RecPart::addParameter(const QString&key,const QString&value) 247void RecPart::addParameter(const QString&key,const QString&value)
225{ 248{
226 m_Parameters[key]=value; 249 m_Parameters[key]=value;
227} 250}
228 251
229const QString RecPart::searchParamter(const QString&key)const 252const QString RecPart::searchParamter(const QString&key)const
230{ 253{
231 QString value(""); 254 QString value("");
232 part_plist_t::ConstIterator it = m_Parameters.find(key); 255 part_plist_t::ConstIterator it = m_Parameters.find(key);
233 if (it != m_Parameters.end()) { 256 if (it != m_Parameters.end()) {
234 value = it.data(); 257 value = it.data();
235 } 258 }
236 return value; 259 return value;
237} 260}
238 261
239void RecPart::setPositionlist(const QValueList<int>&poslist) 262void RecPart::setPositionlist(const QValueList<int>&poslist)
240{ 263{
241 m_poslist = poslist; 264 m_poslist = poslist;
242} 265}
243 266
244const QValueList<int>& RecPart::Positionlist()const 267const QValueList<int>& RecPart::Positionlist()const
245{ 268{
246 return m_poslist; 269 return m_poslist;
247} 270}
248 271
249RecBody::RecBody() 272RecBody::RecBody()
250 : Opie::Core::ORefCount(),m_BodyText(),m_description(new RecPart()) 273 : Opie::Core::ORefCount(),m_BodyText(),m_description(new RecPart())
251{ 274{
252 m_PartsList.clear(); 275 m_PartsList.clear();
253} 276}
254 277
255RecBody::RecBody(const RecBody&old) 278RecBody::RecBody(const RecBody&old)
256 :Opie::Core::ORefCount(),m_BodyText(),m_PartsList(),m_description(new RecPart()) 279 :Opie::Core::ORefCount(),m_BodyText(),m_PartsList(),m_description(new RecPart())
257{ 280{
258 m_BodyText = old.m_BodyText; 281 m_BodyText = old.m_BodyText;
259 m_PartsList = old.m_PartsList; 282 m_PartsList = old.m_PartsList;
260 m_description = old.m_description; 283 m_description = old.m_description;
261 // odebug << "Recbody copy constructor" << oendl; 284 // odebug << "Recbody copy constructor" << oendl;
262} 285}
263 286
264RecBody::~RecBody() 287RecBody::~RecBody()
265{ 288{
266} 289}
267 290
268void RecBody::setBodytext(const QString&bodyText) 291void RecBody::setBodytext(const QString&bodyText)
269{ 292{
270 m_BodyText = bodyText; 293 m_BodyText = bodyText;
271} 294}
272 295
273const QString& RecBody::Bodytext()const 296const QString& RecBody::Bodytext()const
274{ 297{
275 return m_BodyText; 298 return m_BodyText;
276} 299}
277 300
278void RecBody::setParts(const QValueList<RecPartP>&parts) 301void RecBody::setParts(const QValueList<RecPartP>&parts)
279{ 302{
280 m_PartsList.clear(); 303 m_PartsList.clear();
281 m_PartsList = parts; 304 m_PartsList = parts;
282} 305}
283 306
284const QValueList<RecPartP>& RecBody::Parts()const 307const QValueList<RecPartP>& RecBody::Parts()const
285{ 308{
286 return m_PartsList; 309 return m_PartsList;
287} 310}
288 311
289void RecBody::addPart(const RecPartP& part) 312void RecBody::addPart(const RecPartP& part)
290{ 313{
291 m_PartsList.append(part); 314 m_PartsList.append(part);
292} 315}
293 316
294void RecBody::setDescription(const RecPartP&des) 317void RecBody::setDescription(const RecPartP&des)
295{ 318{
296 m_description = des; 319 m_description = des;
297} 320}
298 321
299const RecPartP& RecBody::Description()const 322const RecPartP& RecBody::Description()const
300{ 323{
301 return m_description; 324 return m_description;
302} 325}
303 326
304/* handling encoded content */ 327/* handling encoded content */
305encodedString::encodedString() 328encodedString::encodedString()
306{ 329{
307 init(); 330 init();
308} 331}
309 332
310encodedString::encodedString(const char*nContent,unsigned int nSize) 333encodedString::encodedString(const char*nContent,unsigned int nSize)
311{ 334{
312 init(); 335 init();
313 setContent(nContent,nSize); 336 setContent(nContent,nSize);
314} 337}
315 338
316encodedString::encodedString(char*nContent,unsigned int nSize) 339encodedString::encodedString(char*nContent,unsigned int nSize)
317{ 340{
318 init(); 341 init();
319 setContent(nContent,nSize); 342 setContent(nContent,nSize);
320} 343}
321 344
322encodedString::encodedString(const encodedString&old) 345encodedString::encodedString(const encodedString&old)
323{ 346{
324 init(); 347 init();
325 copy_old(old); 348 copy_old(old);
326 // odebug << "encodedeString: copy constructor!" << oendl; 349 // odebug << "encodedeString: copy constructor!" << oendl;
327} 350}
328 351
329encodedString& encodedString::operator=(const encodedString&old) 352encodedString& encodedString::operator=(const encodedString&old)
330{ 353{
331 init(); 354 init();
332 copy_old(old); 355 copy_old(old);
333 // odebug << "encodedString: assign operator!" << oendl; 356 // odebug << "encodedString: assign operator!" << oendl;
334 return *this; 357 return *this;
335} 358}
336 359
337encodedString::~encodedString() 360encodedString::~encodedString()
338{ 361{
339 clean(); 362 clean();
340} 363}
341 364
342void encodedString::init() 365void encodedString::init()
343{ 366{
344 content = 0; 367 content = 0;
345 size = 0; 368 size = 0;
346} 369}
347 370
348void encodedString::clean() 371void encodedString::clean()
349{ 372{
350 if (content) { 373 if (content) {
351 free(content); 374 free(content);
352 } 375 }
353 content = 0; 376 content = 0;
354 size = 0; 377 size = 0;
355} 378}
356 379
357void encodedString::copy_old(const encodedString&old) 380void encodedString::copy_old(const encodedString&old)
358{ 381{
359 clean(); 382 clean();
360 if (old.size>0 && old.content) { 383 if (old.size>0 && old.content) {
361 content = (char*)malloc(old.size*sizeof(char)); 384 content = (char*)malloc(old.size*sizeof(char));
362 memcpy(content,old.content,size); 385 memcpy(content,old.content,size);
363 size = old.size; 386 size = old.size;
364 } 387 }
365} 388}
366 389
367const char*encodedString::Content()const 390const char*encodedString::Content()const
368{ 391{
369 return content; 392 return content;
370} 393}
371 394
372const int encodedString::Length()const 395const int encodedString::Length()const
373{ 396{
374 return size; 397 return size;
375} 398}
376 399
377void encodedString::setContent(const char*nContent,int nSize) 400void encodedString::setContent(const char*nContent,int nSize)
378{ 401{
379 if (nSize>0 && nContent) { 402 if (nSize>0 && nContent) {
380 content = (char*)malloc(nSize*sizeof(char)); 403 content = (char*)malloc(nSize*sizeof(char));
381 memcpy(content,nContent,nSize); 404 memcpy(content,nContent,nSize);
382 size = nSize; 405 size = nSize;
383 } 406 }
384} 407}
385 408
386void encodedString::setContent(char*nContent,int nSize) 409void encodedString::setContent(char*nContent,int nSize)
387{ 410{
388 content = nContent; 411 content = nContent;
389 size = nSize; 412 size = nSize;
390} 413}
391 414
392folderStat&folderStat::operator=(const folderStat&old) 415folderStat&folderStat::operator=(const folderStat&old)
393{ 416{
394 message_count = old.message_count; 417 message_count = old.message_count;
395 message_unseen = old.message_unseen; 418 message_unseen = old.message_unseen;
396 message_recent = old.message_recent; 419 message_recent = old.message_recent;
397 return *this; 420 return *this;
398} 421}
399 422
diff --git a/kmicromail/libmailwrapper/mailtypes.h b/kmicromail/libmailwrapper/mailtypes.h
index c317880..020278d 100644
--- a/kmicromail/libmailwrapper/mailtypes.h
+++ b/kmicromail/libmailwrapper/mailtypes.h
@@ -1,206 +1,209 @@
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 39
39 const unsigned int getNumber()const{return msg_number;} 40 const unsigned int getNumber()const{return msg_number;}
40 void setNumber(unsigned int number){msg_number=number;} 41 void setNumber(unsigned int number){msg_number=number;}
41 const QString&getDate()const{ return date; } 42 const QString&getDate()const{ return date; }
42 void setDate( const QString&a ) { date = a; } 43 void setDate( const QString&a ) { date = a; }
44 const QString&getIsoDate()const{ return isodate; }
45 void setIsoDate( const QString&a ) { isodate = a; }
43 const QString&getFrom()const{ return from; } 46 const QString&getFrom()const{ return from; }
44 void setFrom( const QString&a ) { from = a; } 47 void setFrom( const QString&a ) { from = a; }
45 const QString&getSubject()const { return subject; } 48 const QString&getSubject()const { return subject; }
46 void setSubject( const QString&s ) { subject = s; } 49 void setSubject( const QString&s ) { subject = s; }
47 const QString&getMbox()const{return mbox;} 50 const QString&getMbox()const{return mbox;}
48 void setMbox(const QString&box){mbox = box;} 51 void setMbox(const QString&box){mbox = box;}
49 void setMsgid(const QString&id){msg_id=id;} 52 void setMsgid(const QString&id){msg_id=id;}
50 const QString&Msgid()const{return msg_id;} 53 const QString&Msgid()const{return msg_id;}
51 void setReplyto(const QString&reply){replyto=reply;} 54 void setReplyto(const QString&reply){replyto=reply;}
52 const QString&Replyto()const{return replyto;} 55 const QString&Replyto()const{return replyto;}
53 void setMsgsize(unsigned int size){msg_size = size;} 56 void setMsgsize(unsigned int size){msg_size = size;}
54 const unsigned int Msgsize()const{return msg_size;} 57 const unsigned int Msgsize()const{return msg_size;}
55 58
56 59
57 void setTo(const QStringList&list); 60 void setTo(const QStringList&list);
58 const QStringList&To()const; 61 const QStringList&To()const;
59 void setCC(const QStringList&list); 62 void setCC(const QStringList&list);
60 const QStringList&CC()const; 63 const QStringList&CC()const;
61 void setBcc(const QStringList&list); 64 void setBcc(const QStringList&list);
62 const QStringList&Bcc()const; 65 const QStringList&Bcc()const;
63 void setInreply(const QStringList&list); 66 void setInreply(const QStringList&list);
64 const QStringList&Inreply()const; 67 const QStringList&Inreply()const;
65 void setReferences(const QStringList&list); 68 void setReferences(const QStringList&list);
66 const QStringList&References()const; 69 const QStringList&References()const;
67 70
68 const QBitArray&getFlags()const{return msg_flags;} 71 const QBitArray&getFlags()const{return msg_flags;}
69 void setFlags(const QBitArray&flags){msg_flags = flags;} 72 void setFlags(const QBitArray&flags){msg_flags = flags;}
70 73
71 void setWrapper(AbstractMail*wrapper); 74 void setWrapper(AbstractMail*wrapper);
72 AbstractMail* Wrapper(); 75 AbstractMail* Wrapper();
73 76
74protected: 77protected:
75 QString subject,date,from,mbox,msg_id,replyto; 78 QString subject,date,isodate,from,mbox,msg_id,replyto;
76 unsigned int msg_number,msg_size; 79 unsigned int msg_number,msg_size;
77 QBitArray msg_flags; 80 QBitArray msg_flags;
78 QStringList to,cc,bcc,in_reply_to,references; 81 QStringList to,cc,bcc,in_reply_to,references;
79 AbstractMail*wrapper; 82 AbstractMail*wrapper;
80 void init(); 83 void init();
81 void copy_old(const RecMail&old); 84 void copy_old(const RecMail&old);
82}; 85};
83 86
84typedef Opie::Core::OSmartPointer<RecMail> RecMailP; 87typedef Opie::Core::OSmartPointer<RecMail> RecMailP;
85typedef QMap<QString,QString> part_plist_t; 88typedef QMap<QString,QString> part_plist_t;
86 89
87class RecPart:public Opie::Core::ORefCount 90class RecPart:public Opie::Core::ORefCount
88{ 91{
89protected: 92protected:
90 QString m_type,m_subtype,m_identifier,m_encoding,m_description; 93 QString m_type,m_subtype,m_identifier,m_encoding,m_description;
91 unsigned int m_lines,m_size; 94 unsigned int m_lines,m_size;
92 part_plist_t m_Parameters; 95 part_plist_t m_Parameters;
93 /* describes the position in the mail */ 96 /* describes the position in the mail */
94 QValueList<int> m_poslist; 97 QValueList<int> m_poslist;
95 98
96public: 99public:
97 RecPart(); 100 RecPart();
98 RecPart(const RecPart&); 101 RecPart(const RecPart&);
99 virtual ~RecPart(); 102 virtual ~RecPart();
100 103
101 const QString&Type()const; 104 const QString&Type()const;
102 void setType(const QString&type); 105 void setType(const QString&type);
103 const QString&Subtype()const; 106 const QString&Subtype()const;
104 void setSubtype(const QString&subtype); 107 void setSubtype(const QString&subtype);
105 const QString&Identifier()const; 108 const QString&Identifier()const;
106 void setIdentifier(const QString&identifier); 109 void setIdentifier(const QString&identifier);
107 const QString&Encoding()const; 110 const QString&Encoding()const;
108 void setEncoding(const QString&encoding); 111 void setEncoding(const QString&encoding);
109 const QString&Description()const; 112 const QString&Description()const;
110 void setDescription(const QString&desc); 113 void setDescription(const QString&desc);
111 void setLines(unsigned int lines); 114 void setLines(unsigned int lines);
112 const unsigned int Lines()const; 115 const unsigned int Lines()const;
113 void setSize(unsigned int size); 116 void setSize(unsigned int size);
114 const unsigned int Size()const; 117 const unsigned int Size()const;
115 118
116 119
117 void setParameters(const part_plist_t&list); 120 void setParameters(const part_plist_t&list);
118 const part_plist_t&Parameters()const; 121 const part_plist_t&Parameters()const;
119 void addParameter(const QString&key,const QString&value); 122 void addParameter(const QString&key,const QString&value);
120 const QString searchParamter(const QString&key)const; 123 const QString searchParamter(const QString&key)const;
121 void setPositionlist(const QValueList<int>&poslist); 124 void setPositionlist(const QValueList<int>&poslist);
122 const QValueList<int>& Positionlist()const; 125 const QValueList<int>& Positionlist()const;
123}; 126};
124 127
125typedef Opie::Core::OSmartPointer<RecPart> RecPartP; 128typedef Opie::Core::OSmartPointer<RecPart> RecPartP;
126 129
127class RecBody:public Opie::Core::ORefCount 130class RecBody:public Opie::Core::ORefCount
128{ 131{
129protected: 132protected:
130 QString m_BodyText; 133 QString m_BodyText;
131 QValueList<RecPartP> m_PartsList; 134 QValueList<RecPartP> m_PartsList;
132 RecPartP m_description; 135 RecPartP m_description;
133 136
134public: 137public:
135 RecBody(); 138 RecBody();
136 RecBody(const RecBody&old); 139 RecBody(const RecBody&old);
137 virtual ~RecBody(); 140 virtual ~RecBody();
138 void setBodytext(const QString&); 141 void setBodytext(const QString&);
139 const QString& Bodytext()const; 142 const QString& Bodytext()const;
140 143
141 void setDescription(const RecPartP&des); 144 void setDescription(const RecPartP&des);
142 const RecPartP& Description()const; 145 const RecPartP& Description()const;
143 146
144 void setParts(const QValueList<RecPartP>&parts); 147 void setParts(const QValueList<RecPartP>&parts);
145 const QValueList<RecPartP>& Parts()const; 148 const QValueList<RecPartP>& Parts()const;
146 void addPart(const RecPartP&part); 149 void addPart(const RecPartP&part);
147}; 150};
148 151
149typedef Opie::Core::OSmartPointer<RecBody> RecBodyP; 152typedef Opie::Core::OSmartPointer<RecBody> RecBodyP;
150 153
151class encodedString 154class encodedString
152{ 155{
153public: 156public:
154 encodedString(); 157 encodedString();
155 /* 158 /*
156 creates an new content string. 159 creates an new content string.
157 it makes a deep copy of it! 160 it makes a deep copy of it!
158 */ 161 */
159 encodedString(const char*nContent,unsigned int length); 162 encodedString(const char*nContent,unsigned int length);
160 /* 163 /*
161 Take over the nContent. Means: it will just copy the pointer, not the content. 164 Take over the nContent. Means: it will just copy the pointer, not the content.
162 so make sure: No one else frees the string, the string has allocated with 165 so make sure: No one else frees the string, the string has allocated with
163 malloc for compatibility with c-based libs 166 malloc for compatibility with c-based libs
164 */ 167 */
165 encodedString(char*nContent,unsigned int nSize); 168 encodedString(char*nContent,unsigned int nSize);
166 /* copy construkor - makes ALWAYS a deep copy!!!! */ 169 /* copy construkor - makes ALWAYS a deep copy!!!! */
167 encodedString(const encodedString&old); 170 encodedString(const encodedString&old);
168 /* assign operator - makes ALWAYS a deep copy!!!! */ 171 /* assign operator - makes ALWAYS a deep copy!!!! */
169 encodedString& operator=(const encodedString&old); 172 encodedString& operator=(const encodedString&old);
170 /* destructor - cleans the content */ 173 /* destructor - cleans the content */
171 virtual ~encodedString(); 174 virtual ~encodedString();
172 175
173 /* returns a pointer to the content - do not delete yoursel! */ 176 /* returns a pointer to the content - do not delete yoursel! */
174 const char*Content()const; 177 const char*Content()const;
175 /* returns the lengths of the content 'cause it must not be a null-terminated string! */ 178 /* returns the lengths of the content 'cause it must not be a null-terminated string! */
176 const int Length()const; 179 const int Length()const;
177 180
178 /* 181 /*
179 makes a deep copy of nContent! 182 makes a deep copy of nContent!
180 */ 183 */
181 void setContent(const char*nContent,int nSize); 184 void setContent(const char*nContent,int nSize);
182 /* 185 /*
183 Take over the nContent. Means: it will just copy the pointer, not the content. 186 Take over the nContent. Means: it will just copy the pointer, not the content.
184 so make sure: No one else frees the string, the string has allocated with 187 so make sure: No one else frees the string, the string has allocated with
185 malloc for compatibility with c-based libs 188 malloc for compatibility with c-based libs
186 */ 189 */
187 void setContent(char*nContent,int nSize); 190 void setContent(char*nContent,int nSize);
188 191
189protected: 192protected:
190 char * content; 193 char * content;
191 unsigned int size; 194 unsigned int size;
192 195
193 void init(); 196 void init();
194 void copy_old(const encodedString&old); 197 void copy_old(const encodedString&old);
195 void clean(); 198 void clean();
196}; 199};
197 200
198struct folderStat 201struct folderStat
199{ 202{
200 unsigned int message_count; 203 unsigned int message_count;
201 unsigned int message_unseen; 204 unsigned int message_unseen;
202 unsigned int message_recent; 205 unsigned int message_recent;
203 folderStat&operator=(const folderStat&old); 206 folderStat&operator=(const folderStat&old);
204}; 207};
205 208
206#endif 209#endif
diff --git a/kmicromail/libmailwrapper/mboxwrapper.h b/kmicromail/libmailwrapper/mboxwrapper.h
index 9731b85..d03940f 100644
--- a/kmicromail/libmailwrapper/mboxwrapper.h
+++ b/kmicromail/libmailwrapper/mboxwrapper.h
@@ -1,46 +1,47 @@
1#ifndef __MBOX_WRAPPER_H 1#ifndef __MBOX_WRAPPER_H
2#define __MBOX_WRAPPER_H 2#define __MBOX_WRAPPER_H
3 3
4#include "genericwrapper.h" 4#include "genericwrapper.h"
5#include <qstring.h> 5#include <qstring.h>
6 6
7class encodedString; 7class encodedString;
8struct mailmbox_folder; 8struct mailmbox_folder;
9 9
10class MBOXwrapper : public Genericwrapper 10class MBOXwrapper : public Genericwrapper
11{ 11{
12 Q_OBJECT 12 Q_OBJECT
13 13
14public: 14public:
15 MBOXwrapper(const QString & dir,const QString&name); 15 MBOXwrapper(const QString & dir,const QString&name);
16 virtual ~MBOXwrapper(); 16 virtual ~MBOXwrapper();
17 17
18 virtual void listMessages(const QString & mailbox, QValueList<RecMailP>&target ); 18 virtual void listMessages(const QString & mailbox, QValueList<RecMailP>&target );
19 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 19 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
20 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 20 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
21 21
22 virtual void deleteMail(const RecMailP&mail); 22 virtual void deleteMail(const RecMailP&mail);
23 virtual void answeredMail(const RecMailP&mail); 23 virtual void answeredMail(const RecMailP&mail);
24 24
25 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0, 25 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0,
26 const QString&d="",bool s=false); 26 const QString&d="",bool s=false);
27 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&); 27 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&);
28 28
29 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 29 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
30 30
31 virtual RecBodyP fetchBody( const RecMailP &mail ); 31 virtual RecBodyP fetchBody( const RecMailP &mail );
32 static void mbox_progress( size_t current, size_t maximum ); 32 static void mbox_progress( size_t current, size_t maximum );
33 33
34 virtual encodedString* fetchRawBody(const RecMailP&mail); 34 virtual encodedString* fetchRawBody(const RecMailP&mail);
35 virtual void deleteMails(const QString & FolderName,const QValueList<RecMailP> &target); 35 virtual void deleteMails(const QString & FolderName,const QValueList<RecMailP> &target);
36 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 36 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
37 virtual MAILLIB::ATYPE getType()const; 37 virtual MAILLIB::ATYPE getType()const;
38 virtual const QString&getName()const; 38 virtual const QString&getName()const;
39 virtual Account* getAccount() { return 0; };
39 40
40protected: 41protected:
41 static void deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target); 42 static void deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target);
42 QString MBOXPath; 43 QString MBOXPath;
43 QString MBOXName; 44 QString MBOXName;
44}; 45};
45 46
46#endif 47#endif
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp
index cbc52d9..962dac0 100644
--- a/kmicromail/libmailwrapper/mhwrapper.cpp
+++ b/kmicromail/libmailwrapper/mhwrapper.cpp
@@ -1,447 +1,448 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "mhwrapper.h" 2#include "mhwrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
6#include <qdir.h> 6#include <qdir.h>
7#include <qmessagebox.h> 7#include <qmessagebox.h>
8#include <stdlib.h> 8#include <stdlib.h>
9#include <qpe/global.h> 9#include <qpe/global.h>
10#include <oprocess.h> 10#include <oprocess.h>
11//#include <opie2/odebug.h> 11//#include <opie2/odebug.h>
12 12
13using namespace Opie::Core; 13using namespace Opie::Core;
14MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) 14MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name)
15 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) 15 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name)
16{ 16{
17 if (MHPath.length()>0) { 17 if (MHPath.length()>0) {
18 if (MHPath[MHPath.length()-1]=='/') { 18 if (MHPath[MHPath.length()-1]=='/') {
19 MHPath=MHPath.left(MHPath.length()-1); 19 MHPath=MHPath.left(MHPath.length()-1);
20 } 20 }
21 //odebug << MHPath << oendl; 21 //odebug << MHPath << oendl;
22 QDir dir(MHPath); 22 QDir dir(MHPath);
23 if (!dir.exists()) { 23 if (!dir.exists()) {
24 dir.mkdir(MHPath); 24 dir.mkdir(MHPath);
25 } 25 }
26 init_storage(); 26 init_storage();
27 } 27 }
28} 28}
29 29
30void MHwrapper::init_storage() 30void MHwrapper::init_storage()
31{ 31{
32 int r; 32 int r;
33 QString pre = MHPath; 33 QString pre = MHPath;
34 if (!m_storage) { 34 if (!m_storage) {
35 m_storage = mailstorage_new(NULL); 35 m_storage = mailstorage_new(NULL);
36 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); 36 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0);
37 if (r != MAIL_NO_ERROR) { 37 if (r != MAIL_NO_ERROR) {
38 qDebug(" error init storage "); 38 qDebug(" error init storage ");
39 mailstorage_free(m_storage); 39 mailstorage_free(m_storage);
40 m_storage = 0; 40 m_storage = 0;
41 return; 41 return;
42 } 42 }
43 } 43 }
44 r = mailstorage_connect(m_storage); 44 r = mailstorage_connect(m_storage);
45 if (r!=MAIL_NO_ERROR) { 45 if (r!=MAIL_NO_ERROR) {
46 qDebug("error connecting storage "); 46 qDebug("error connecting storage ");
47 mailstorage_free(m_storage); 47 mailstorage_free(m_storage);
48 m_storage = 0; 48 m_storage = 0;
49 } 49 }
50} 50}
51 51
52void MHwrapper::clean_storage() 52void MHwrapper::clean_storage()
53{ 53{
54 if (m_storage) { 54 if (m_storage) {
55 mailstorage_disconnect(m_storage); 55 mailstorage_disconnect(m_storage);
56 mailstorage_free(m_storage); 56 mailstorage_free(m_storage);
57 m_storage = 0; 57 m_storage = 0;
58 } 58 }
59} 59}
60 60
61MHwrapper::~MHwrapper() 61MHwrapper::~MHwrapper()
62{ 62{
63 clean_storage(); 63 clean_storage();
64} 64}
65 65
66void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) 66void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
67{ 67{
68 qDebug("MHwrapper::listMessages ");
68 init_storage(); 69 init_storage();
69 if (!m_storage) { 70 if (!m_storage) {
70 return; 71 return;
71 } 72 }
72 QString f = buildPath(mailbox); 73 QString f = buildPath(mailbox);
73 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 74 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
74 if (r!=MAIL_NO_ERROR) { 75 if (r!=MAIL_NO_ERROR) {
75 qDebug("listMessages: error selecting folder! "); 76 qDebug("listMessages: error selecting folder! ");
76 return; 77 return;
77 } 78 }
78 parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); 79 parseList(target,m_storage->sto_session,f, false, maxSizeInKb );
79 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); 80 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
80} 81}
81 82
82QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() 83QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders()
83{ 84{
84 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); 85 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >();
85 /* this is needed! */ 86 /* this is needed! */
86 if (m_storage) mailstorage_disconnect(m_storage); 87 if (m_storage) mailstorage_disconnect(m_storage);
87 init_storage(); 88 init_storage();
88 if (!m_storage) { 89 if (!m_storage) {
89 return folders; 90 return folders;
90 } 91 }
91 mail_list*flist = 0; 92 mail_list*flist = 0;
92 clistcell*current=0; 93 clistcell*current=0;
93 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); 94 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist);
94 if (r != MAIL_NO_ERROR || !flist) { 95 if (r != MAIL_NO_ERROR || !flist) {
95 qDebug("error getting folder list "); 96 qDebug("error getting folder list ");
96 return folders; 97 return folders;
97 } 98 }
98 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { 99 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) {
99 QString t = (char*)current->data; 100 QString t = (char*)current->data;
100 t.replace(0,MHPath.length(),""); 101 t.replace(0,MHPath.length(),"");
101 folders->append(new MHFolder(t,MHPath)); 102 folders->append(new MHFolder(t,MHPath));
102 } 103 }
103 mail_list_free(flist); 104 mail_list_free(flist);
104 return folders; 105 return folders;
105} 106}
106 107
107void MHwrapper::deleteMail(const RecMailP&mail) 108void MHwrapper::deleteMail(const RecMailP&mail)
108{ 109{
109 init_storage(); 110 init_storage();
110 if (!m_storage) { 111 if (!m_storage) {
111 return; 112 return;
112 } 113 }
113 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 114 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
114 if (r!=MAIL_NO_ERROR) { 115 if (r!=MAIL_NO_ERROR) {
115 qDebug("error selecting folder! "); 116 qDebug("error selecting folder! ");
116 return; 117 return;
117 } 118 }
118 r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); 119 r = mailsession_remove_message(m_storage->sto_session,mail->getNumber());
119 if (r != MAIL_NO_ERROR) { 120 if (r != MAIL_NO_ERROR) {
120 qDebug("error deleting mail "); 121 qDebug("error deleting mail ");
121 } 122 }
122} 123}
123 124
124void MHwrapper::answeredMail(const RecMailP&) 125void MHwrapper::answeredMail(const RecMailP&)
125{ 126{
126} 127}
127 128
128RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) 129RecBodyP MHwrapper::fetchBody( const RecMailP &mail )
129{ 130{
130 RecBodyP body = new RecBody(); 131 RecBodyP body = new RecBody();
131 init_storage(); 132 init_storage();
132 if (!m_storage) { 133 if (!m_storage) {
133 return body; 134 return body;
134 } 135 }
135 mailmessage * msg; 136 mailmessage * msg;
136 char*data=0; 137 char*data=0;
137 138
138 /* mail should hold the complete path! */ 139 /* mail should hold the complete path! */
139 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 140 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
140 if (r != MAIL_NO_ERROR) { 141 if (r != MAIL_NO_ERROR) {
141 return body; 142 return body;
142 } 143 }
143 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); 144 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg);
144 if (r != MAIL_NO_ERROR) { 145 if (r != MAIL_NO_ERROR) {
145 qDebug("Error fetching mail "); 146 qDebug("Error fetching mail ");
146 147
147 return body; 148 return body;
148 } 149 }
149 body = parseMail(msg); 150 body = parseMail(msg);
150 mailmessage_fetch_result_free(msg,data); 151 mailmessage_fetch_result_free(msg,data);
151 return body; 152 return body;
152} 153}
153 154
154void MHwrapper::mbox_progress( size_t current, size_t maximum ) 155void MHwrapper::mbox_progress( size_t current, size_t maximum )
155{ 156{
156 qDebug("MBox Progress %d of %d",current,maximum ); 157 qDebug("MBox Progress %d of %d",current,maximum );
157 //odebug << "MH " << current << " von " << maximum << "" << oendl; 158 //odebug << "MH " << current << " von " << maximum << "" << oendl;
158} 159}
159 160
160QString MHwrapper::buildPath(const QString&p) 161QString MHwrapper::buildPath(const QString&p)
161{ 162{
162 QString f=""; 163 QString f="";
163 if (p.length()==0||p=="/") 164 if (p.length()==0||p=="/")
164 return MHPath; 165 return MHPath;
165 if (!p.startsWith(MHPath)) { 166 if (!p.startsWith(MHPath)) {
166 f+=MHPath; 167 f+=MHPath;
167 } 168 }
168 if (!p.startsWith("/")) { 169 if (!p.startsWith("/")) {
169 f+="/"; 170 f+="/";
170 } 171 }
171 f+=p; 172 f+=p;
172 return f; 173 return f;
173} 174}
174 175
175int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) 176int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool )
176{ 177{
177 init_storage(); 178 init_storage();
178 if (!m_storage) { 179 if (!m_storage) {
179 return 0; 180 return 0;
180 } 181 }
181 QString f; 182 QString f;
182 if (!pfolder) { 183 if (!pfolder) {
183 // toplevel folder 184 // toplevel folder
184 f = buildPath(folder); 185 f = buildPath(folder);
185 } else { 186 } else {
186 f = pfolder->getName(); 187 f = pfolder->getName();
187 f+="/"; 188 f+="/";
188 f+=folder; 189 f+=folder;
189 } 190 }
190 191
191 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); 192 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1());
192 if (r != MAIL_NO_ERROR) { 193 if (r != MAIL_NO_ERROR) {
193 qDebug("error creating folder "); 194 qDebug("error creating folder ");
194 return 0; 195 return 0;
195 } 196 }
196 qDebug("Folder created "); 197 qDebug("Folder created ");
197 return 1; 198 return 1;
198} 199}
199 200
200void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) 201void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder)
201{ 202{
202 init_storage(); 203 init_storage();
203 if (!m_storage) { 204 if (!m_storage) {
204 return; 205 return;
205 } 206 }
206 QString f = buildPath(Folder); 207 QString f = buildPath(Folder);
207 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 208 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
208 if (r!=MAIL_NO_ERROR) { 209 if (r!=MAIL_NO_ERROR) {
209 qDebug("error selecting folder! "); 210 qDebug("error selecting folder! ");
210 return; 211 return;
211 } 212 }
212 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); 213 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length);
213 if (r!=MAIL_NO_ERROR) { 214 if (r!=MAIL_NO_ERROR) {
214 qDebug("error storing mail "); 215 qDebug("error storing mail ");
215 } 216 }
216 return; 217 return;
217} 218}
218 219
219encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) 220encodedString* MHwrapper::fetchRawBody(const RecMailP&mail)
220{ 221{
221 encodedString*result = 0; 222 encodedString*result = 0;
222 init_storage(); 223 init_storage();
223 if (!m_storage) { 224 if (!m_storage) {
224 return result; 225 return result;
225 } 226 }
226 mailmessage * msg = 0; 227 mailmessage * msg = 0;
227 char*data=0; 228 char*data=0;
228 size_t size; 229 size_t size;
229 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 230 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
230 if (r!=MAIL_NO_ERROR) { 231 if (r!=MAIL_NO_ERROR) {
231 qDebug("error selecting folder! "); 232 qDebug("error selecting folder! ");
232 return result; 233 return result;
233 } 234 }
234 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); 235 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg);
235 if (r != MAIL_NO_ERROR) { 236 if (r != MAIL_NO_ERROR) {
236 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); 237 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber()));
237 return 0; 238 return 0;
238 } 239 }
239 r = mailmessage_fetch(msg,&data,&size); 240 r = mailmessage_fetch(msg,&data,&size);
240 if (r != MAIL_NO_ERROR) { 241 if (r != MAIL_NO_ERROR) {
241 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); 242 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber()));
242 if (msg) mailmessage_free(msg); 243 if (msg) mailmessage_free(msg);
243 return 0; 244 return 0;
244 } 245 }
245 result = new encodedString(data,size); 246 result = new encodedString(data,size);
246 if (msg) mailmessage_free(msg); 247 if (msg) mailmessage_free(msg);
247 return result; 248 return result;
248} 249}
249 250
250void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) 251void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target)
251{ 252{
252 QString f = buildPath(mailbox); 253 QString f = buildPath(mailbox);
253 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 254 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
254 if (r!=MAIL_NO_ERROR) { 255 if (r!=MAIL_NO_ERROR) {
255 qDebug("deleteMails: error selecting folder! "); 256 qDebug("deleteMails: error selecting folder! ");
256 return; 257 return;
257 } 258 }
258 QValueList<RecMailP>::ConstIterator it; 259 QValueList<RecMailP>::ConstIterator it;
259 for (it=target.begin(); it!=target.end();++it) { 260 for (it=target.begin(); it!=target.end();++it) {
260 r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); 261 r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber());
261 if (r != MAIL_NO_ERROR) { 262 if (r != MAIL_NO_ERROR) {
262 qDebug("error deleting mail "); 263 qDebug("error deleting mail ");
263 break; 264 break;
264 } 265 }
265 } 266 }
266} 267}
267 268
268int MHwrapper::deleteAllMail(const FolderP&tfolder) 269int MHwrapper::deleteAllMail(const FolderP&tfolder)
269{ 270{
270 init_storage(); 271 init_storage();
271 if (!m_storage) { 272 if (!m_storage) {
272 return 0; 273 return 0;
273 } 274 }
274 int res = 1; 275 int res = 1;
275 if (!tfolder) return 0; 276 if (!tfolder) return 0;
276 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 277 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
277 if (r!=MAIL_NO_ERROR) { 278 if (r!=MAIL_NO_ERROR) {
278 qDebug("error selecting folder! "); 279 qDebug("error selecting folder! ");
279 return 0; 280 return 0;
280 } 281 }
281 mailmessage_list*l=0; 282 mailmessage_list*l=0;
282 r = mailsession_get_messages_list(m_storage->sto_session,&l); 283 r = mailsession_get_messages_list(m_storage->sto_session,&l);
283 if (r != MAIL_NO_ERROR) { 284 if (r != MAIL_NO_ERROR) {
284 qDebug("Error message list "); 285 qDebug("Error message list ");
285 res = 0; 286 res = 0;
286 } 287 }
287 unsigned j = 0; 288 unsigned j = 0;
288 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 289 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
289 mailmessage * msg; 290 mailmessage * msg;
290 msg = (mailmessage*)carray_get(l->msg_tab, i); 291 msg = (mailmessage*)carray_get(l->msg_tab, i);
291 j = msg->msg_index; 292 j = msg->msg_index;
292 r = mailsession_remove_message(m_storage->sto_session,j); 293 r = mailsession_remove_message(m_storage->sto_session,j);
293 if (r != MAIL_NO_ERROR) { 294 if (r != MAIL_NO_ERROR) {
294 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 295 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
295 res = 0; 296 res = 0;
296 break; 297 break;
297 } 298 }
298 } 299 }
299 if (l) mailmessage_list_free(l); 300 if (l) mailmessage_list_free(l);
300 return res; 301 return res;
301} 302}
302 303
303int MHwrapper::deleteMbox(const FolderP&tfolder) 304int MHwrapper::deleteMbox(const FolderP&tfolder)
304{ 305{
305 init_storage(); 306 init_storage();
306 if (!m_storage) { 307 if (!m_storage) {
307 return 0; 308 return 0;
308 } 309 }
309 if (!tfolder) return 0; 310 if (!tfolder) return 0;
310 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; 311 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0;
311 312
312 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 313 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
313 314
314 if (r != MAIL_NO_ERROR) { 315 if (r != MAIL_NO_ERROR) {
315 qDebug("error deleting mail box "); 316 qDebug("error deleting mail box ");
316 return 0; 317 return 0;
317 } 318 }
318 QString cmd = "rm -rf "+tfolder->getName(); 319 QString cmd = "rm -rf "+tfolder->getName();
319 QStringList command; 320 QStringList command;
320 command << "/bin/sh"; 321 command << "/bin/sh";
321 command << "-c"; 322 command << "-c";
322 command << cmd.latin1(); 323 command << cmd.latin1();
323 OProcess *process = new OProcess(); 324 OProcess *process = new OProcess();
324 325
325 connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), 326 connect(process, SIGNAL(processExited(Opie::Core::OProcess*)),
326 this, SLOT( processEnded(Opie::Core::OProcess*))); 327 this, SLOT( processEnded(Opie::Core::OProcess*)));
327 connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)), 328 connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)),
328 this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int))); 329 this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int)));
329 330
330 *process << command; 331 *process << command;
331 removeMboxfailed = false; 332 removeMboxfailed = false;
332 if(!process->start(OProcess::Block, OProcess::All) ) { 333 if(!process->start(OProcess::Block, OProcess::All) ) {
333 qDebug("could not start process "); 334 qDebug("could not start process ");
334 return 0; 335 return 0;
335 } 336 }
336 qDebug("mail box deleted "); 337 qDebug("mail box deleted ");
337 return 1; 338 return 1;
338} 339}
339 340
340void MHwrapper::processEnded(OProcess *p) 341void MHwrapper::processEnded(OProcess *p)
341{ 342{
342 if (p) delete p; 343 if (p) delete p;
343} 344}
344 345
345void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) 346void MHwrapper::oprocessStderr(OProcess*, char *buffer, int )
346{ 347{
347 QString lineStr = buffer; 348 QString lineStr = buffer;
348 QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); 349 QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") );
349 removeMboxfailed = true; 350 removeMboxfailed = true;
350} 351}
351 352
352void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 353void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
353{ 354{
354 init_storage(); 355 init_storage();
355 if (!m_storage) { 356 if (!m_storage) {
356 return; 357 return;
357 } 358 }
358 target_stat.message_count = 0; 359 target_stat.message_count = 0;
359 target_stat.message_unseen = 0; 360 target_stat.message_unseen = 0;
360 target_stat.message_recent = 0; 361 target_stat.message_recent = 0;
361 QString f = buildPath(mailbox); 362 QString f = buildPath(mailbox);
362 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, 363 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count,
363 &target_stat.message_recent,&target_stat.message_unseen); 364 &target_stat.message_recent,&target_stat.message_unseen);
364 if (r != MAIL_NO_ERROR) { 365 if (r != MAIL_NO_ERROR) {
365 Global::statusMessage(tr("Error retrieving status")); 366 Global::statusMessage(tr("Error retrieving status"));
366 } 367 }
367} 368}
368 369
369MAILLIB::ATYPE MHwrapper::getType()const 370MAILLIB::ATYPE MHwrapper::getType()const
370{ 371{
371 return MAILLIB::A_MH; 372 return MAILLIB::A_MH;
372} 373}
373 374
374const QString&MHwrapper::getName()const 375const QString&MHwrapper::getName()const
375{ 376{
376 return MHName; 377 return MHName;
377} 378}
378void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 379void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
379{ 380{
380 init_storage(); 381 init_storage();
381 if (!m_storage) { 382 if (!m_storage) {
382 return; 383 return;
383 } 384 }
384 if (targetWrapper != this) { 385 if (targetWrapper != this) {
385 qDebug("Using generic "); 386 qDebug("Using generic ");
386 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); 387 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit);
387 return; 388 return;
388 } 389 }
389 qDebug("Using internal routines for move/copy "); 390 qDebug("Using internal routines for move/copy ");
390 QString tf = buildPath(targetFolder); 391 QString tf = buildPath(targetFolder);
391 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 392 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
392 if (r != MAIL_NO_ERROR) { 393 if (r != MAIL_NO_ERROR) {
393 qDebug("Error selecting source mailbox "); 394 qDebug("Error selecting source mailbox ");
394 return; 395 return;
395 } 396 }
396 if (moveit) { 397 if (moveit) {
397 r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); 398 r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1());
398 } else { 399 } else {
399 r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); 400 r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1());
400 } 401 }
401 if (r != MAIL_NO_ERROR) { 402 if (r != MAIL_NO_ERROR) {
402 qDebug("Error copy/moving mail internal "); 403 qDebug("Error copy/moving mail internal ");
403 } 404 }
404} 405}
405 406
406void MHwrapper::mvcpAllMails(const FolderP&fromFolder, 407void MHwrapper::mvcpAllMails(const FolderP&fromFolder,
407 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 408 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
408{ 409{
409 init_storage(); 410 init_storage();
410 if (!m_storage) { 411 if (!m_storage) {
411 return; 412 return;
412 } 413 }
413 if (targetWrapper != this) { 414 if (targetWrapper != this) {
414 qDebug("Using generic "); 415 qDebug("Using generic ");
415 Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); 416 Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit);
416 return; 417 return;
417 } 418 }
418 if (!fromFolder) return; 419 if (!fromFolder) return;
419 int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); 420 int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1());
420 if (r!=MAIL_NO_ERROR) { 421 if (r!=MAIL_NO_ERROR) {
421 qDebug("error selecting source folder! "); 422 qDebug("error selecting source folder! ");
422 return; 423 return;
423 } 424 }
424 QString tf = buildPath(targetFolder); 425 QString tf = buildPath(targetFolder);
425 mailmessage_list*l=0; 426 mailmessage_list*l=0;
426 r = mailsession_get_messages_list(m_storage->sto_session,&l); 427 r = mailsession_get_messages_list(m_storage->sto_session,&l);
427 if (r != MAIL_NO_ERROR) { 428 if (r != MAIL_NO_ERROR) {
428 qDebug("Error message list "); 429 qDebug("Error message list ");
429 } 430 }
430 unsigned j = 0; 431 unsigned j = 0;
431 for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { 432 for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) {
432 mailmessage * msg; 433 mailmessage * msg;
433 msg = (mailmessage*)carray_get(l->msg_tab, i); 434 msg = (mailmessage*)carray_get(l->msg_tab, i);
434 j = msg->msg_index; 435 j = msg->msg_index;
435 if (moveit) { 436 if (moveit) {
436 r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); 437 r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1());
437 } else { 438 } else {
438 r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); 439 r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1());
439 } 440 }
440 if (r != MAIL_NO_ERROR) { 441 if (r != MAIL_NO_ERROR) {
441 qDebug("Error copy/moving mail interna "); 442 qDebug("Error copy/moving mail interna ");
442 443
443 break; 444 break;
444 } 445 }
445 } 446 }
446 if (l) mailmessage_list_free(l); 447 if (l) mailmessage_list_free(l);
447} 448}
diff --git a/kmicromail/libmailwrapper/mhwrapper.h b/kmicromail/libmailwrapper/mhwrapper.h
index 550824d..d1b7d1f 100644
--- a/kmicromail/libmailwrapper/mhwrapper.h
+++ b/kmicromail/libmailwrapper/mhwrapper.h
@@ -1,61 +1,62 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __MH_WRAPPER_H 2#ifndef __MH_WRAPPER_H
3#define __MH_WRAPPER_H 3#define __MH_WRAPPER_H
4 4
5#include "maildefines.h" 5#include "maildefines.h"
6 6
7#include "genericwrapper.h" 7#include "genericwrapper.h"
8#include <qstring.h> 8#include <qstring.h>
9 9
10class encodedString; 10class encodedString;
11struct mailmbox_folder; 11struct mailmbox_folder;
12namespace Opie {namespace Core {class OProcess;}} 12namespace Opie {namespace Core {class OProcess;}}
13 13
14class MHwrapper : public Genericwrapper 14class MHwrapper : public Genericwrapper
15{ 15{
16 Q_OBJECT 16 Q_OBJECT
17public: 17public:
18 MHwrapper(const QString & dir,const QString&name); 18 MHwrapper(const QString & dir,const QString&name);
19 virtual ~MHwrapper(); 19 virtual ~MHwrapper();
20 20
21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); 21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
23 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 23 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
24 24
25 virtual void deleteMail(const RecMailP&mail); 25 virtual void deleteMail(const RecMailP&mail);
26 virtual void answeredMail(const RecMailP&mail); 26 virtual void answeredMail(const RecMailP&mail);
27 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 27 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
28 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, 28 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,
29 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 29 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
30 30
31 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0, 31 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0,
32 const QString&d="",bool s=false); 32 const QString&d="",bool s=false);
33 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&); 33 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&);
34 34
35 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 35 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
36 36
37 virtual RecBodyP fetchBody( const RecMailP &mail ); 37 virtual RecBodyP fetchBody( const RecMailP &mail );
38 static void mbox_progress( size_t current, size_t maximum ); 38 static void mbox_progress( size_t current, size_t maximum );
39 39
40 virtual encodedString* fetchRawBody(const RecMailP&mail); 40 virtual encodedString* fetchRawBody(const RecMailP&mail);
41 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> > &target); 41 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> > &target);
42 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 42 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
43 virtual MAILLIB::ATYPE getType()const; 43 virtual MAILLIB::ATYPE getType()const;
44 virtual const QString&getName()const; 44 virtual const QString&getName()const;
45 virtual Account* getAccount() { return 0; };
45 46
46public slots: 47public slots:
47 /* for deleting maildirs we are using a system call */ 48 /* for deleting maildirs we are using a system call */
48 virtual void oprocessStderr(Opie::Core::OProcess*, char *buffer, int ); 49 virtual void oprocessStderr(Opie::Core::OProcess*, char *buffer, int );
49 virtual void processEnded(Opie::Core::OProcess *); 50 virtual void processEnded(Opie::Core::OProcess *);
50protected: 51protected:
51 QString buildPath(const QString&p); 52 QString buildPath(const QString&p);
52 QString MHPath; 53 QString MHPath;
53 QString MHName; 54 QString MHName;
54 55
55 void init_storage(); 56 void init_storage();
56 void clean_storage(); 57 void clean_storage();
57 58
58 bool removeMboxfailed; 59 bool removeMboxfailed;
59}; 60};
60 61
61#endif 62#endif
diff --git a/kmicromail/libmailwrapper/nntpwrapper.h b/kmicromail/libmailwrapper/nntpwrapper.h
index 5d4e5ce..8c54f12 100644
--- a/kmicromail/libmailwrapper/nntpwrapper.h
+++ b/kmicromail/libmailwrapper/nntpwrapper.h
@@ -1,49 +1,50 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __NNTPWRAPPER 2#ifndef __NNTPWRAPPER
3#define __NNTPWRAPPER 3#define __NNTPWRAPPER
4 4
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "genericwrapper.h" 6#include "genericwrapper.h"
7#include <qstring.h> 7#include <qstring.h>
8#include <libetpan/clist.h> 8#include <libetpan/clist.h>
9 9
10class encodedString; 10class encodedString;
11struct mailstorage; 11struct mailstorage;
12struct mailfolder; 12struct mailfolder;
13 13
14class NNTPwrapper : public Genericwrapper 14class NNTPwrapper : public Genericwrapper
15{ 15{
16 16
17 Q_OBJECT 17 Q_OBJECT
18 18
19public: 19public:
20 NNTPwrapper( NNTPaccount *a ); 20 NNTPwrapper( NNTPaccount *a );
21 virtual ~NNTPwrapper(); 21 virtual ~NNTPwrapper();
22 22
23 /* mailbox will be ignored */ 23 /* mailbox will be ignored */
24 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); 24 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
25 /* should only get the subscribed one */ 25 /* should only get the subscribed one */
26 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 26 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
27 /* mailbox will be ignored */ 27 /* mailbox will be ignored */
28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
29 QStringList listAllNewsgroups(const QString&mask = QString::null); 29 QStringList listAllNewsgroups(const QString&mask = QString::null);
30 virtual void deleteMail(const RecMailP&mail); 30 virtual void deleteMail(const RecMailP&mail);
31 virtual void answeredMail(const RecMailP&mail); 31 virtual void answeredMail(const RecMailP&mail);
32 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 32 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
33 33
34 virtual RecBodyP fetchBody( const RecMailP &mail ); 34 virtual RecBodyP fetchBody( const RecMailP &mail );
35 virtual encodedString* fetchRawBody(const RecMailP&mail); 35 virtual encodedString* fetchRawBody(const RecMailP&mail);
36 virtual void logout(); 36 virtual void logout();
37 virtual MAILLIB::ATYPE getType()const; 37 virtual MAILLIB::ATYPE getType()const;
38 virtual const QString&getName()const; 38 virtual const QString&getName()const;
39 static void nntp_progress( size_t current, size_t maximum ); 39 static void nntp_progress( size_t current, size_t maximum );
40 virtual Account* getAccount() { return account; };
40 41
41protected: 42protected:
42 void login(); 43 void login();
43 NNTPaccount *account; 44 NNTPaccount *account;
44 mailstorage* m_nntp; 45 mailstorage* m_nntp;
45 46
46 47
47}; 48};
48 49
49#endif 50#endif
diff --git a/kmicromail/libmailwrapper/pop3wrapper.h b/kmicromail/libmailwrapper/pop3wrapper.h
index 7c70942..ebc2fc7 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.h
+++ b/kmicromail/libmailwrapper/pop3wrapper.h
@@ -1,44 +1,44 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __POP3WRAPPER 2#ifndef __POP3WRAPPER
3#define __POP3WRAPPER 3#define __POP3WRAPPER
4 4
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "genericwrapper.h" 6#include "genericwrapper.h"
7#include <qstring.h> 7#include <qstring.h>
8 8
9class encodedString; 9class encodedString;
10struct mailstorage; 10struct mailstorage;
11struct mailfolder; 11struct mailfolder;
12 12
13class POP3wrapper : public Genericwrapper 13class POP3wrapper : public Genericwrapper
14{ 14{
15 Q_OBJECT 15 Q_OBJECT
16 16
17public: 17public:
18 POP3wrapper( POP3account *a ); 18 POP3wrapper( POP3account *a );
19 virtual ~POP3wrapper(); 19 virtual ~POP3wrapper();
20 /* mailbox will be ignored */ 20 /* mailbox will be ignored */
21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); 21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
23 /* mailbox will be ignored */ 23 /* mailbox will be ignored */
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
25 25
26 virtual void deleteMail(const RecMailP&mail); 26 virtual void deleteMail(const RecMailP&mail);
27 virtual void deleteMailList(const QValueList<RecMailP>&target); 27 virtual void deleteMailList(const QValueList<RecMailP>&target);
28 virtual void answeredMail(const RecMailP&mail); 28 virtual void answeredMail(const RecMailP&mail);
29 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 29 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
30 30
31 virtual RecBodyP fetchBody( const RecMailP &mail ); 31 virtual RecBodyP fetchBody( const RecMailP &mail );
32 virtual encodedString* fetchRawBody(const RecMailP&mail); 32 virtual encodedString* fetchRawBody(const RecMailP&mail);
33 virtual void logout(); 33 virtual void logout();
34 virtual MAILLIB::ATYPE getType()const; 34 virtual MAILLIB::ATYPE getType()const;
35 virtual const QString&getName()const; 35 virtual const QString&getName()const;
36 static void pop3_progress( size_t current, size_t maximum ); 36 static void pop3_progress( size_t current, size_t maximum );
37 37 virtual Account* getAccount() { return account; };
38protected: 38protected:
39 void login(); 39 void login();
40 POP3account *account; 40 POP3account *account;
41 mailstorage*m_pop3; 41 mailstorage*m_pop3;
42}; 42};
43 43
44#endif 44#endif
diff --git a/kmicromail/libmailwrapper/smtpwrapper.h b/kmicromail/libmailwrapper/smtpwrapper.h
index 105cbf5..ec42b56 100644
--- a/kmicromail/libmailwrapper/smtpwrapper.h
+++ b/kmicromail/libmailwrapper/smtpwrapper.h
@@ -1,63 +1,64 @@
1// -*- Mode: C++; -*- 1// -*- Mode: C++; -*-
2#ifndef SMTPwrapper_H 2#ifndef SMTPwrapper_H
3#define SMTPwrapper_H 3#define SMTPwrapper_H
4 4
5#include <qpe/applnk.h> 5#include <qpe/applnk.h>
6 6
7#include <qbitarray.h> 7#include <qbitarray.h>
8#include <qdatetime.h> 8#include <qdatetime.h>
9#include <libetpan/clist.h> 9#include <libetpan/clist.h>
10 10
11#include "settings.h" 11#include "settings.h"
12#include "generatemail.h" 12#include "generatemail.h"
13 13
14#include <opie2/osmartpointer.h> 14#include <opie2/osmartpointer.h>
15 15
16class SMTPaccount; 16class SMTPaccount;
17class AbstractMail; 17class AbstractMail;
18 18
19class SMTPwrapper : public Generatemail 19class SMTPwrapper : public Generatemail
20{ 20{
21 Q_OBJECT 21 Q_OBJECT
22 22
23public: 23public:
24 SMTPwrapper(SMTPaccount * aSmtp); 24 SMTPwrapper(SMTPaccount * aSmtp);
25 virtual ~SMTPwrapper(); 25 virtual ~SMTPwrapper();
26 bool sendMail(const Opie::Core::OSmartPointer<Mail>& mail,bool later=false ); 26 bool sendMail(const Opie::Core::OSmartPointer<Mail>& mail,bool later=false );
27 bool flushOutbox(); 27 bool flushOutbox();
28 28
29 static progressMailSend*sendProgress; 29 static progressMailSend*sendProgress;
30 virtual Account* getAccount() { return m_SmtpAccount; };
30 31
31signals: 32signals:
32 void queuedMails( int ); 33 void queuedMails( int );
33 34
34protected: 35protected:
35 mailsmtp *m_smtp; 36 mailsmtp *m_smtp;
36 SMTPaccount * m_SmtpAccount; 37 SMTPaccount * m_SmtpAccount;
37 38
38 void connect_server(); 39 void connect_server();
39 void disc_server(); 40 void disc_server();
40 int start_smtp_tls(); 41 int start_smtp_tls();
41 42
42 43
43 bool smtpSend( mailmime *mail,bool later); 44 bool smtpSend( mailmime *mail,bool later);
44 45
45 static void storeMail(const char*mail, size_t length, const QString&box); 46 static void storeMail(const char*mail, size_t length, const QString&box);
46 static QString mailsmtpError( int err ); 47 static QString mailsmtpError( int err );
47 static void progress( size_t current, size_t maximum ); 48 static void progress( size_t current, size_t maximum );
48 49
49 int smtpSend(char*from,clist*rcpts,const char*data,size_t size); 50 int smtpSend(char*from,clist*rcpts,const char*data,size_t size);
50 51
51 void storeMail(mailmime*mail, const QString&box); 52 void storeMail(mailmime*mail, const QString&box);
52 53
53 int sendQueuedMail(AbstractMail*wrap,const Opie::Core::OSmartPointer<RecMail>&which); 54 int sendQueuedMail(AbstractMail*wrap,const Opie::Core::OSmartPointer<RecMail>&which);
54 void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); 55 void storeFailedMail(const char*data,unsigned int size, const char*failuremessage);
55 56
56 int m_queuedMail; 57 int m_queuedMail;
57 58
58protected slots: 59protected slots:
59 void emitQCop( int queued ); 60 void emitQCop( int queued );
60 61
61}; 62};
62 63
63#endif 64#endif
diff --git a/kmicromail/mailistviewitem.cpp b/kmicromail/mailistviewitem.cpp
index b92b0cf..484a635 100644
--- a/kmicromail/mailistviewitem.cpp
+++ b/kmicromail/mailistviewitem.cpp
@@ -1,143 +1,146 @@
1// CHANGED 2004-08-06 Lutz Rogowski 1// CHANGED 2004-08-06 Lutz Rogowski
2#include "mailistviewitem.h" 2#include "mailistviewitem.h"
3#include <libmailwrapper/abstractmail.h> 3#include <libmailwrapper/abstractmail.h>
4#include <qtextstream.h> 4#include <qtextstream.h>
5#include <kiconloader.h> 5#include <kiconloader.h>
6//#include <qpe/resource.h> 6//#include <qpe/resource.h>
7 7
8MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item ) 8MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item )
9 :QListViewItem(parent,item),mail_data() 9 :QListViewItem(parent,item),mail_data()
10{ 10{
11} 11}
12 12
13void MailListViewItem::showEntry() 13void MailListViewItem::showEntry()
14{ 14{
15 if ( mail_data->getFlags().testBit( FLAG_ANSWERED ) == true) { 15 if ( mail_data->getFlags().testBit( FLAG_ANSWERED ) == true) {
16 setPixmap( 0, SmallIcon ( "kmmsgreplied") ); 16 setPixmap( 0, SmallIcon ( "kmmsgreplied") );
17 } else if ( mail_data->getFlags().testBit( FLAG_SEEN ) == true ) { 17 } else if ( mail_data->getFlags().testBit( FLAG_SEEN ) == true ) {
18 /* I think it looks nicer if there are not such a log of icons but only on mails 18 /* I think it looks nicer if there are not such a log of icons but only on mails
19 replied or new - Alwin*/ 19 replied or new - Alwin*/
20 //setPixmap( 0,SmallIcon ("kmmsgunseen") ); 20 //setPixmap( 0,SmallIcon ("kmmsgunseen") );
21 } else { 21 } else {
22 setPixmap( 0,SmallIcon ( "kmmsgnew") ); 22 setPixmap( 0,SmallIcon ( "kmmsgnew") );
23 } 23 }
24 double s = mail_data->Msgsize(); 24 double s = mail_data->Msgsize();
25 int w = 0; 25 int w = 0;
26 s/=1024; 26 s/=1024;
27 if (s>999.0) { 27 if (s>999.0) {
28 s/=1024.0; 28 s/=1024.0;
29 ++w; 29 ++w;
30 } 30 }
31 QString fsort; 31 QString fsort;
32 fsort.sprintf( "%.2f", s ); 32 fsort.sprintf( "%.2f", s );
33 QString fsize = QString::number( s, 'f', 2 ); 33 QString fsize = QString::number( s, 'f', 2 );
34 // 1.23 34 // 1.23
35 // 11.23 35 // 11.23
36 // 111.23 36 // 111.23
37 // 999.23 maxlen 37 // 999.23 maxlen
38 switch(fsize.length() ) { 38 switch(fsize.length() ) {
39 case 4: 39 case 4:
40 fsort = "00" + fsize ; 40 fsort = "00" + fsize ;
41 break; 41 break;
42 case 5: 42 case 5:
43 fsort = "0" + fsize ; 43 fsort = "0" + fsize ;
44 break; 44 break;
45 default: 45 default:
46 fsort = fsize ; 46 fsort = fsize ;
47 break; 47 break;
48 48
49 } 49 }
50 if ( w == 0 ) { 50 if ( w == 0 ) {
51 setText(3, fsize + "kB" ); 51 setText(3, fsize + "kB" );
52 mKeyMap.insert(3, "k" + fsort); 52 mKeyMap.insert(3, "k" + fsort);
53 //setText(3, "kB" + fsort ); // test only 53 //setText(3, "kB" + fsort ); // test only
54 } else { 54 } else {
55 //setText(3, fsize + "MB"); 55 //setText(3, fsize + "MB");
56 mKeyMap.insert(4, "M" +fsort ); 56 mKeyMap.insert(3, "M" +fsort );
57 } 57 }
58 setText(1,mail_data->getSubject()); 58 setText(1,mail_data->getSubject());
59 setText(2,mail_data->getFrom()); 59 setText(2,mail_data->getFrom());
60 60#if 0
61 QString date = mail_data->getDate(); 61 QString date = mail_data->getDate();
62 62
63 int kom = date.find( ",")+2; 63 int kom = date.find( ",")+2;
64 if ( kom == 1 ) 64 if ( kom == 1 )
65 kom = 0; 65 kom = 0;
66 if ( date.mid(kom,1) == " ") 66 if ( date.mid(kom,1) == " ")
67 ++kom; 67 ++kom;
68 if ( date.mid(kom+1,1) == " " ) 68 if ( date.mid(kom+1,1) == " " )
69 date = "0" + date.mid( kom ); 69 date = "0" + date.mid( kom );
70 else if ( kom ) 70 else if ( kom )
71 date = date.mid( kom ); 71 date = date.mid( kom );
72 if ( kom || date.mid(2,1 ) == " ") { 72 if ( kom || date.mid(2,1 ) == " ") {
73 QString mon = date.mid(3,3); 73 QString mon = date.mid(3,3);
74 QString so = 00; 74 QString so = 00;
75 if ( mon == "Jan" ) 75 if ( mon == "Jan" )
76 so = "01"; 76 so = "01";
77 else if ( mon == "Feb" ) 77 else if ( mon == "Feb" )
78 so = "02"; 78 so = "02";
79 else if ( mon == "Mar" ) 79 else if ( mon == "Mar" )
80 so = "03"; 80 so = "03";
81 else if ( mon == "Apr" ) 81 else if ( mon == "Apr" )
82 so = "04"; 82 so = "04";
83 else if ( mon == "May" ) 83 else if ( mon == "May" )
84 so = "05"; 84 so = "05";
85 else if ( mon == "Jun" ) 85 else if ( mon == "Jun" )
86 so = "06"; 86 so = "06";
87 else if ( mon == "Jul" ) 87 else if ( mon == "Jul" )
88 so = "07"; 88 so = "07";
89 else if ( mon == "Aug" ) 89 else if ( mon == "Aug" )
90 so = "08"; 90 so = "08";
91 else if ( mon == "Sep" ) 91 else if ( mon == "Sep" )
92 so = "09"; 92 so = "09";
93 else if ( mon == "Oct" ) 93 else if ( mon == "Oct" )
94 so = "10"; 94 so = "10";
95 else if ( mon == "Nov" ) 95 else if ( mon == "Nov" )
96 so = "11"; 96 so = "11";
97 else if ( mon == "Dec" ) 97 else if ( mon == "Dec" )
98 so = "12"; 98 so = "12";
99 date = date.mid(7,4)+so+date.left(2)+date.mid(12,14); 99 date = date.mid(7,4)+so+date.left(2)+date.mid(12,14);
100 } 100 }
101 //qDebug("insert Date %s ", date.latin1());
101 // if ( date.left(1) != "1" || date.left(1) != "2" ) 102 // if ( date.left(1) != "1" || date.left(1) != "2" )
102 // date = date.mid(5); 103 // date = date.mid(5);
103 mKeyMap.insert(4,date); 104 mKeyMap.insert(4,date);
105#endif
106 mKeyMap.insert(4,mail_data->getIsoDate());
104 setText(4,mail_data->getDate()); 107 setText(4,mail_data->getDate());
105} 108}
106 109
107void MailListViewItem::storeData(const RecMailP&data) 110void MailListViewItem::storeData(const RecMailP&data)
108{ 111{
109 mail_data = data; 112 mail_data = data;
110} 113}
111void MailListViewItem::setSortKey(int column,const QString &key) 114void MailListViewItem::setSortKey(int column,const QString &key)
112{ 115{
113 mKeyMap.insert(column,key); 116 mKeyMap.insert(column,key);
114} 117}
115QString MailListViewItem::key(int column, bool) const 118QString MailListViewItem::key(int column, bool) const
116{ 119{
117 // to make is fast, we use here special cases 120 // to make is fast, we use here special cases
118 if ( column == 3 || column == 4 ) { 121 if ( column == 3 || column == 4 ) {
119 return *mKeyMap.find(column); 122 return *mKeyMap.find(column);
120 } 123 }
121 if ( column == 1 ) { 124 if ( column == 1 ) {
122 if ( text(1).left(4).lower() == "re: " ) 125 if ( text(1).left(4).lower() == "re: " )
123 return text(1).mid(4); 126 return text(1).mid(4);
124 127
125 } 128 }
126 return text(column); 129 return text(column);
127 /* 130 /*
128 QMap<int,QString>::ConstIterator it = mKeyMap.find(column); 131 QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
129 if (it == mKeyMap.end()) return text(column); 132 if (it == mKeyMap.end()) return text(column);
130 else return *it; 133 else return *it;
131 */ 134 */
132} 135}
133 136
134const RecMailP& MailListViewItem::data()const 137const RecMailP& MailListViewItem::data()const
135{ 138{
136 return mail_data; 139 return mail_data;
137} 140}
138 141
139MAILLIB::ATYPE MailListViewItem::wrapperType() 142MAILLIB::ATYPE MailListViewItem::wrapperType()
140{ 143{
141 if (!mail_data->Wrapper()) return MAILLIB::A_UNDEFINED; 144 if (!mail_data->Wrapper()) return MAILLIB::A_UNDEFINED;
142 return mail_data->Wrapper()->getType(); 145 return mail_data->Wrapper()->getType();
143} 146}