summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h2
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp5
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h1
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.cpp7
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp5
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h2
7 files changed, 23 insertions, 1 deletions
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index a070fb0..7c060db 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -1,57 +1,59 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include "settings.h" 5#include "settings.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class RecPart; 9class RecPart;
10class IMAPwrapper; 10class IMAPwrapper;
11class POP3wrapper; 11class POP3wrapper;
12class Folder; 12class Folder;
13class encodedString; 13class encodedString;
14struct folderStat; 14struct folderStat;
15 15
16class AbstractMail:public QObject 16class AbstractMail:public QObject
17{ 17{
18 Q_OBJECT 18 Q_OBJECT
19public: 19public:
20 AbstractMail(){}; 20 AbstractMail(){};
21 virtual ~AbstractMail(){} 21 virtual ~AbstractMail(){}
22 virtual QList<Folder>* listFolders()=0; 22 virtual QList<Folder>* listFolders()=0;
23 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 23 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; 24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0;
25 virtual RecBody fetchBody(const RecMail&mail)=0; 25 virtual RecBody fetchBody(const RecMail&mail)=0;
26 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 26 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
27 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 27 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
28 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 28 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
29 29
30 virtual void deleteMail(const RecMail&mail)=0; 30 virtual void deleteMail(const RecMail&mail)=0;
31 virtual void answeredMail(const RecMail&mail)=0; 31 virtual void answeredMail(const RecMail&mail)=0;
32 virtual int deleteAllMail(const Folder*)=0; 32 virtual int deleteAllMail(const Folder*)=0;
33 virtual int deleteMbox(const Folder*)=0; 33 virtual int deleteMbox(const Folder*)=0;
34 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; 34 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0;
35 35
36 virtual void cleanMimeCache(){}; 36 virtual void cleanMimeCache(){};
37 /* mail box methods */ 37 /* mail box methods */
38 /* parameter is the box to create. 38 /* parameter is the box to create.
39 * if the implementing subclass has prefixes, 39 * if the implementing subclass has prefixes,
40 * them has to be appended automatic. 40 * them has to be appended automatic.
41 */ 41 */
42 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 42 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
43 virtual void logout()=0; 43 virtual void logout()=0;
44 44
45 static AbstractMail* getWrapper(IMAPaccount *a); 45 static AbstractMail* getWrapper(IMAPaccount *a);
46 static AbstractMail* getWrapper(POP3account *a); 46 static AbstractMail* getWrapper(POP3account *a);
47 /* mbox only! */ 47 /* mbox only! */
48 static AbstractMail* getWrapper(const QString&a); 48 static AbstractMail* getWrapper(const QString&a);
49 49
50 static QString defaultLocalfolder(); 50 static QString defaultLocalfolder();
51 51
52 virtual const QString&getType()const=0;
53
52protected: 54protected:
53 static encodedString*decode_String(const encodedString*text,const QString&enc); 55 static encodedString*decode_String(const encodedString*text,const QString&enc);
54 static QString convert_String(const char*text); 56 static QString convert_String(const char*text);
55 static QString gen_attachment_id(); 57 static QString gen_attachment_id();
56}; 58};
57#endif 59#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 0c1e05e..95b317a 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -220,768 +220,773 @@ QList<Folder>* IMAPwrapper::listFolders()
220 qDebug("error fetching folders: %s",m_imap->imap_response); 220 qDebug("error fetching folders: %s",m_imap->imap_response);
221 } 221 }
222 mailimap_list_result_free( result ); 222 mailimap_list_result_free( result );
223 223
224/* 224/*
225 * second stage - get the other then inbox folders 225 * second stage - get the other then inbox folders
226 */ 226 */
227 mask = "*" ; 227 mask = "*" ;
228 path = account->getPrefix().latin1(); 228 path = account->getPrefix().latin1();
229 if (!path) path = ""; 229 if (!path) path = "";
230 qDebug(path); 230 qDebug(path);
231 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 231 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
232 if ( err == MAILIMAP_NO_ERROR ) { 232 if ( err == MAILIMAP_NO_ERROR ) {
233 current = result->first; 233 current = result->first;
234 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 234 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
235 no_inferiors = false; 235 no_inferiors = false;
236 list = (mailimap_mailbox_list *) current->data; 236 list = (mailimap_mailbox_list *) current->data;
237 // it is better use the deep copy mechanism of qt itself 237 // it is better use the deep copy mechanism of qt itself
238 // instead of using strdup! 238 // instead of using strdup!
239 temp = list->mb_name; 239 temp = list->mb_name;
240 if (temp.lower()=="inbox") 240 if (temp.lower()=="inbox")
241 continue; 241 continue;
242 if (temp.lower()==account->getPrefix().lower()) 242 if (temp.lower()==account->getPrefix().lower())
243 continue; 243 continue;
244 if ( (bflags = list->mb_flag) ) { 244 if ( (bflags = list->mb_flag) ) {
245 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 245 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
246 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 246 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
247 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 247 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
248 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 248 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
249 no_inferiors = true; 249 no_inferiors = true;
250 } 250 }
251 } 251 }
252 } 252 }
253 del = list->mb_delimiter; 253 del = list->mb_delimiter;
254 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 254 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
255 } 255 }
256 } else { 256 } else {
257 qDebug("error fetching folders %s",m_imap->imap_response); 257 qDebug("error fetching folders %s",m_imap->imap_response);
258 } 258 }
259 if (result) mailimap_list_result_free( result ); 259 if (result) mailimap_list_result_free( result );
260 return folders; 260 return folders;
261} 261}
262 262
263RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 263RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
264{ 264{
265 RecMail * m = 0; 265 RecMail * m = 0;
266 mailimap_msg_att_item *item=0; 266 mailimap_msg_att_item *item=0;
267 clistcell *current,*c,*cf; 267 clistcell *current,*c,*cf;
268 mailimap_msg_att_dynamic*flist; 268 mailimap_msg_att_dynamic*flist;
269 mailimap_flag_fetch*cflag; 269 mailimap_flag_fetch*cflag;
270 int size; 270 int size;
271 QBitArray mFlags(7); 271 QBitArray mFlags(7);
272 QStringList addresslist; 272 QStringList addresslist;
273 273
274 if (!m_att) { 274 if (!m_att) {
275 return m; 275 return m;
276 } 276 }
277 m = new RecMail(); 277 m = new RecMail();
278 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 278 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
279 current = c; 279 current = c;
280 size = 0; 280 size = 0;
281 item = (mailimap_msg_att_item*)current->data; 281 item = (mailimap_msg_att_item*)current->data;
282 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 282 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
283 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 283 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
284 if (!flist->att_list) { 284 if (!flist->att_list) {
285 continue; 285 continue;
286 } 286 }
287 cf = flist->att_list->first; 287 cf = flist->att_list->first;
288 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 288 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
289 cflag = (mailimap_flag_fetch*)cf->data; 289 cflag = (mailimap_flag_fetch*)cf->data;
290 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 290 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
291 switch (cflag->fl_flag->fl_type) { 291 switch (cflag->fl_flag->fl_type) {
292 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 292 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
293 mFlags.setBit(FLAG_ANSWERED); 293 mFlags.setBit(FLAG_ANSWERED);
294 break; 294 break;
295 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 295 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
296 mFlags.setBit(FLAG_FLAGGED); 296 mFlags.setBit(FLAG_FLAGGED);
297 break; 297 break;
298 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 298 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
299 mFlags.setBit(FLAG_DELETED); 299 mFlags.setBit(FLAG_DELETED);
300 break; 300 break;
301 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 301 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
302 mFlags.setBit(FLAG_SEEN); 302 mFlags.setBit(FLAG_SEEN);
303 break; 303 break;
304 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 304 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
305 mFlags.setBit(FLAG_DRAFT); 305 mFlags.setBit(FLAG_DRAFT);
306 break; 306 break;
307 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 307 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
308 break; 308 break;
309 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 309 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
310 break; 310 break;
311 default: 311 default:
312 break; 312 break;
313 } 313 }
314 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 314 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
315 mFlags.setBit(FLAG_RECENT); 315 mFlags.setBit(FLAG_RECENT);
316 } 316 }
317 } 317 }
318 continue; 318 continue;
319 } 319 }
320 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 320 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
321 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 321 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
322 m->setDate(head->env_date); 322 m->setDate(head->env_date);
323 m->setSubject(convert_String((const char*)head->env_subject)); 323 m->setSubject(convert_String((const char*)head->env_subject));
324 //m->setSubject(head->env_subject); 324 //m->setSubject(head->env_subject);
325 if (head->env_from!=NULL) { 325 if (head->env_from!=NULL) {
326 addresslist = address_list_to_stringlist(head->env_from->frm_list); 326 addresslist = address_list_to_stringlist(head->env_from->frm_list);
327 if (addresslist.count()) { 327 if (addresslist.count()) {
328 m->setFrom(addresslist.first()); 328 m->setFrom(addresslist.first());
329 } 329 }
330 } 330 }
331 if (head->env_to!=NULL) { 331 if (head->env_to!=NULL) {
332 addresslist = address_list_to_stringlist(head->env_to->to_list); 332 addresslist = address_list_to_stringlist(head->env_to->to_list);
333 m->setTo(addresslist); 333 m->setTo(addresslist);
334 } 334 }
335 if (head->env_cc!=NULL) { 335 if (head->env_cc!=NULL) {
336 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 336 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
337 m->setCC(addresslist); 337 m->setCC(addresslist);
338 } 338 }
339 if (head->env_bcc!=NULL) { 339 if (head->env_bcc!=NULL) {
340 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 340 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
341 m->setBcc(addresslist); 341 m->setBcc(addresslist);
342 } 342 }
343 if (head->env_reply_to!=NULL) { 343 if (head->env_reply_to!=NULL) {
344 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 344 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
345 if (addresslist.count()) { 345 if (addresslist.count()) {
346 m->setReplyto(addresslist.first()); 346 m->setReplyto(addresslist.first());
347 } 347 }
348 } 348 }
349 m->setMsgid(QString(head->env_message_id)); 349 m->setMsgid(QString(head->env_message_id));
350 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 350 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
351#if 0 351#if 0
352 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 352 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
353 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 353 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
354 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 354 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
355 qDebug(da.toString()); 355 qDebug(da.toString());
356#endif 356#endif
357 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 357 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
358 size = item->att_data.att_static->att_data.att_rfc822_size; 358 size = item->att_data.att_static->att_data.att_rfc822_size;
359 } 359 }
360 } 360 }
361 /* msg is already deleted */ 361 /* msg is already deleted */
362 if (mFlags.testBit(FLAG_DELETED) && m) { 362 if (mFlags.testBit(FLAG_DELETED) && m) {
363 delete m; 363 delete m;
364 m = 0; 364 m = 0;
365 } 365 }
366 if (m) { 366 if (m) {
367 m->setFlags(mFlags); 367 m->setFlags(mFlags);
368 m->setMsgsize(size); 368 m->setMsgsize(size);
369 } 369 }
370 return m; 370 return m;
371} 371}
372 372
373RecBody IMAPwrapper::fetchBody(const RecMail&mail) 373RecBody IMAPwrapper::fetchBody(const RecMail&mail)
374{ 374{
375 RecBody body; 375 RecBody body;
376 const char *mb; 376 const char *mb;
377 int err = MAILIMAP_NO_ERROR; 377 int err = MAILIMAP_NO_ERROR;
378 clist *result = 0; 378 clist *result = 0;
379 clistcell *current; 379 clistcell *current;
380 mailimap_fetch_att *fetchAtt = 0; 380 mailimap_fetch_att *fetchAtt = 0;
381 mailimap_fetch_type *fetchType = 0; 381 mailimap_fetch_type *fetchType = 0;
382 mailimap_set *set = 0; 382 mailimap_set *set = 0;
383 mailimap_body*body_desc = 0; 383 mailimap_body*body_desc = 0;
384 384
385 mb = mail.getMbox().latin1(); 385 mb = mail.getMbox().latin1();
386 386
387 login(); 387 login();
388 if (!m_imap) { 388 if (!m_imap) {
389 return body; 389 return body;
390 } 390 }
391 391
392 err = mailimap_select( m_imap, (char*)mb); 392 err = mailimap_select( m_imap, (char*)mb);
393 if ( err != MAILIMAP_NO_ERROR ) { 393 if ( err != MAILIMAP_NO_ERROR ) {
394 qDebug("error selecting mailbox: %s",m_imap->imap_response); 394 qDebug("error selecting mailbox: %s",m_imap->imap_response);
395 return body; 395 return body;
396 } 396 }
397 397
398 /* the range has to start at 1!!! not with 0!!!! */ 398 /* the range has to start at 1!!! not with 0!!!! */
399 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 399 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
400 fetchAtt = mailimap_fetch_att_new_bodystructure(); 400 fetchAtt = mailimap_fetch_att_new_bodystructure();
401 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 401 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
402 err = mailimap_fetch( m_imap, set, fetchType, &result ); 402 err = mailimap_fetch( m_imap, set, fetchType, &result );
403 mailimap_set_free( set ); 403 mailimap_set_free( set );
404 mailimap_fetch_type_free( fetchType ); 404 mailimap_fetch_type_free( fetchType );
405 405
406 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 406 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
407 mailimap_msg_att * msg_att; 407 mailimap_msg_att * msg_att;
408 msg_att = (mailimap_msg_att*)current->data; 408 msg_att = (mailimap_msg_att*)current->data;
409 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 409 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
410 QValueList<int> path; 410 QValueList<int> path;
411 body_desc = item->att_data.att_static->att_data.att_body; 411 body_desc = item->att_data.att_static->att_data.att_body;
412 traverseBody(mail,body_desc,body,0,path); 412 traverseBody(mail,body_desc,body,0,path);
413 } else { 413 } else {
414 qDebug("error fetching body: %s",m_imap->imap_response); 414 qDebug("error fetching body: %s",m_imap->imap_response);
415 } 415 }
416 if (result) mailimap_fetch_list_free(result); 416 if (result) mailimap_fetch_list_free(result);
417 return body; 417 return body;
418} 418}
419 419
420QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 420QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
421{ 421{
422 QStringList l; 422 QStringList l;
423 QString from; 423 QString from;
424 bool named_from; 424 bool named_from;
425 clistcell *current = NULL; 425 clistcell *current = NULL;
426 mailimap_address * current_address=NULL; 426 mailimap_address * current_address=NULL;
427 if (!list) { 427 if (!list) {
428 return l; 428 return l;
429 } 429 }
430 unsigned int count = 0; 430 unsigned int count = 0;
431 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 431 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
432 from = ""; 432 from = "";
433 named_from = false; 433 named_from = false;
434 current_address=(mailimap_address*)current->data; 434 current_address=(mailimap_address*)current->data;
435 if (current_address->ad_personal_name){ 435 if (current_address->ad_personal_name){
436 from+=convert_String((const char*)current_address->ad_personal_name); 436 from+=convert_String((const char*)current_address->ad_personal_name);
437 from+=" "; 437 from+=" ";
438 named_from = true; 438 named_from = true;
439 } 439 }
440 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 440 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
441 from+="<"; 441 from+="<";
442 } 442 }
443 if (current_address->ad_mailbox_name) { 443 if (current_address->ad_mailbox_name) {
444 from+=QString(current_address->ad_mailbox_name); 444 from+=QString(current_address->ad_mailbox_name);
445 from+="@"; 445 from+="@";
446 } 446 }
447 if (current_address->ad_host_name) { 447 if (current_address->ad_host_name) {
448 from+=QString(current_address->ad_host_name); 448 from+=QString(current_address->ad_host_name);
449 } 449 }
450 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 450 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
451 from+=">"; 451 from+=">";
452 } 452 }
453 l.append(QString(from)); 453 l.append(QString(from));
454 if (++count > 99) { 454 if (++count > 99) {
455 break; 455 break;
456 } 456 }
457 } 457 }
458 return l; 458 return l;
459} 459}
460 460
461encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 461encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
462{ 462{
463 encodedString*res=new encodedString; 463 encodedString*res=new encodedString;
464 const char*mb; 464 const char*mb;
465 int err; 465 int err;
466 mailimap_fetch_type *fetchType; 466 mailimap_fetch_type *fetchType;
467 mailimap_set *set; 467 mailimap_set *set;
468 clistcell*current,*cur; 468 clistcell*current,*cur;
469 469
470 login(); 470 login();
471 if (!m_imap) { 471 if (!m_imap) {
472 return res; 472 return res;
473 } 473 }
474 if (!internal_call) { 474 if (!internal_call) {
475 mb = mail.getMbox().latin1(); 475 mb = mail.getMbox().latin1();
476 err = mailimap_select( m_imap, (char*)mb); 476 err = mailimap_select( m_imap, (char*)mb);
477 if ( err != MAILIMAP_NO_ERROR ) { 477 if ( err != MAILIMAP_NO_ERROR ) {
478 qDebug("error selecting mailbox: %s",m_imap->imap_response); 478 qDebug("error selecting mailbox: %s",m_imap->imap_response);
479 return res; 479 return res;
480 } 480 }
481 } 481 }
482 set = mailimap_set_new_single(mail.getNumber()); 482 set = mailimap_set_new_single(mail.getNumber());
483 clist*id_list=clist_new(); 483 clist*id_list=clist_new();
484 for (unsigned j=0; j < path.count();++j) { 484 for (unsigned j=0; j < path.count();++j) {
485 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 485 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
486 *p_id = path[j]; 486 *p_id = path[j];
487 clist_append(id_list,p_id); 487 clist_append(id_list,p_id);
488 } 488 }
489 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 489 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
490 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 490 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
491 mailimap_section * section = mailimap_section_new(section_spec); 491 mailimap_section * section = mailimap_section_new(section_spec);
492 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 492 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
493 493
494 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 494 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
495 495
496 clist*result = 0; 496 clist*result = 0;
497 497
498 err = mailimap_fetch( m_imap, set, fetchType, &result ); 498 err = mailimap_fetch( m_imap, set, fetchType, &result );
499 mailimap_set_free( set ); 499 mailimap_set_free( set );
500 mailimap_fetch_type_free( fetchType ); 500 mailimap_fetch_type_free( fetchType );
501 501
502 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 502 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
503 mailimap_msg_att * msg_att; 503 mailimap_msg_att * msg_att;
504 msg_att = (mailimap_msg_att*)current->data; 504 msg_att = (mailimap_msg_att*)current->data;
505 mailimap_msg_att_item*msg_att_item; 505 mailimap_msg_att_item*msg_att_item;
506 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 506 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
507 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 507 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
508 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 508 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
509 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 509 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
510 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 510 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
511 /* detach - we take over the content */ 511 /* detach - we take over the content */
512 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 512 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
513 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 513 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
514 } 514 }
515 } 515 }
516 } 516 }
517 } else { 517 } else {
518 qDebug("error fetching text: %s",m_imap->imap_response); 518 qDebug("error fetching text: %s",m_imap->imap_response);
519 } 519 }
520 if (result) mailimap_fetch_list_free(result); 520 if (result) mailimap_fetch_list_free(result);
521 return res; 521 return res;
522} 522}
523 523
524/* current_recursion is for recursive calls. 524/* current_recursion is for recursive calls.
525 current_count means the position inside the internal loop! */ 525 current_count means the position inside the internal loop! */
526void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, 526void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,
527 int current_recursion,QValueList<int>recList,int current_count) 527 int current_recursion,QValueList<int>recList,int current_count)
528{ 528{
529 if (!body || current_recursion>=10) { 529 if (!body || current_recursion>=10) {
530 return; 530 return;
531 } 531 }
532 switch (body->bd_type) { 532 switch (body->bd_type) {
533 case MAILIMAP_BODY_1PART: 533 case MAILIMAP_BODY_1PART:
534 { 534 {
535 QValueList<int>countlist = recList; 535 QValueList<int>countlist = recList;
536 countlist.append(current_count); 536 countlist.append(current_count);
537 RecPart currentPart; 537 RecPart currentPart;
538 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 538 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
539 QString id(""); 539 QString id("");
540 currentPart.setPositionlist(countlist); 540 currentPart.setPositionlist(countlist);
541 for (unsigned int j = 0; j < countlist.count();++j) { 541 for (unsigned int j = 0; j < countlist.count();++j) {
542 id+=(j>0?" ":""); 542 id+=(j>0?" ":"");
543 id+=QString("%1").arg(countlist[j]); 543 id+=QString("%1").arg(countlist[j]);
544 } 544 }
545 qDebug("ID = %s",id.latin1()); 545 qDebug("ID = %s",id.latin1());
546 currentPart.setIdentifier(id); 546 currentPart.setIdentifier(id);
547 fillSinglePart(currentPart,part1); 547 fillSinglePart(currentPart,part1);
548 /* important: Check for is NULL 'cause a body can be empty! 548 /* important: Check for is NULL 'cause a body can be empty!
549 And we put it only into the mail if it is the FIRST part */ 549 And we put it only into the mail if it is the FIRST part */
550 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { 550 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) {
551 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 551 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
552 target_body.setDescription(currentPart); 552 target_body.setDescription(currentPart);
553 target_body.setBodytext(body_text); 553 target_body.setBodytext(body_text);
554 if (countlist.count()>1) { 554 if (countlist.count()>1) {
555 target_body.addPart(currentPart); 555 target_body.addPart(currentPart);
556 } 556 }
557 } else { 557 } else {
558 target_body.addPart(currentPart); 558 target_body.addPart(currentPart);
559 } 559 }
560 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 560 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
561 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 561 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
562 } 562 }
563 } 563 }
564 break; 564 break;
565 case MAILIMAP_BODY_MPART: 565 case MAILIMAP_BODY_MPART:
566 { 566 {
567 QValueList<int>countlist = recList; 567 QValueList<int>countlist = recList;
568 clistcell*current=0; 568 clistcell*current=0;
569 mailimap_body*current_body=0; 569 mailimap_body*current_body=0;
570 unsigned int ccount = 1; 570 unsigned int ccount = 1;
571 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 571 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
572 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 572 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
573 current_body = (mailimap_body*)current->data; 573 current_body = (mailimap_body*)current->data;
574 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 574 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
575 RecPart targetPart; 575 RecPart targetPart;
576 targetPart.setType("multipart"); 576 targetPart.setType("multipart");
577 fillMultiPart(targetPart,mailDescription); 577 fillMultiPart(targetPart,mailDescription);
578 countlist.append(current_count); 578 countlist.append(current_count);
579 targetPart.setPositionlist(countlist); 579 targetPart.setPositionlist(countlist);
580 target_body.addPart(targetPart); 580 target_body.addPart(targetPart);
581 QString id(""); 581 QString id("");
582 for (unsigned int j = 0; j < countlist.count();++j) { 582 for (unsigned int j = 0; j < countlist.count();++j) {
583 id+=(j>0?" ":""); 583 id+=(j>0?" ":"");
584 id+=QString("%1").arg(countlist[j]); 584 id+=QString("%1").arg(countlist[j]);
585 } 585 }
586 qDebug("ID(mpart) = %s",id.latin1()); 586 qDebug("ID(mpart) = %s",id.latin1());
587 } 587 }
588 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 588 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
589 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 589 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
590 countlist = recList; 590 countlist = recList;
591 } 591 }
592 ++ccount; 592 ++ccount;
593 } 593 }
594 } 594 }
595 break; 595 break;
596 default: 596 default:
597 break; 597 break;
598 } 598 }
599} 599}
600 600
601void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 601void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
602{ 602{
603 if (!Description) { 603 if (!Description) {
604 return; 604 return;
605 } 605 }
606 switch (Description->bd_type) { 606 switch (Description->bd_type) {
607 case MAILIMAP_BODY_TYPE_1PART_TEXT: 607 case MAILIMAP_BODY_TYPE_1PART_TEXT:
608 target_part.setType("text"); 608 target_part.setType("text");
609 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 609 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
610 break; 610 break;
611 case MAILIMAP_BODY_TYPE_1PART_BASIC: 611 case MAILIMAP_BODY_TYPE_1PART_BASIC:
612 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 612 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
613 break; 613 break;
614 case MAILIMAP_BODY_TYPE_1PART_MSG: 614 case MAILIMAP_BODY_TYPE_1PART_MSG:
615 target_part.setType("message"); 615 target_part.setType("message");
616 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 616 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
617 break; 617 break;
618 default: 618 default:
619 break; 619 break;
620 } 620 }
621} 621}
622 622
623void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 623void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
624{ 624{
625 if (!which) { 625 if (!which) {
626 return; 626 return;
627 } 627 }
628 QString sub; 628 QString sub;
629 sub = which->bd_media_text; 629 sub = which->bd_media_text;
630 qDebug("Type= text/%s",which->bd_media_text); 630 qDebug("Type= text/%s",which->bd_media_text);
631 target_part.setSubtype(sub.lower()); 631 target_part.setSubtype(sub.lower());
632 target_part.setLines(which->bd_lines); 632 target_part.setLines(which->bd_lines);
633 fillBodyFields(target_part,which->bd_fields); 633 fillBodyFields(target_part,which->bd_fields);
634} 634}
635 635
636void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 636void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
637{ 637{
638 if (!which) { 638 if (!which) {
639 return; 639 return;
640 } 640 }
641 target_part.setSubtype("rfc822"); 641 target_part.setSubtype("rfc822");
642 qDebug("Message part"); 642 qDebug("Message part");
643 /* we set this type to text/plain */ 643 /* we set this type to text/plain */
644 target_part.setLines(which->bd_lines); 644 target_part.setLines(which->bd_lines);
645 fillBodyFields(target_part,which->bd_fields); 645 fillBodyFields(target_part,which->bd_fields);
646} 646}
647 647
648void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) 648void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which)
649{ 649{
650 if (!which) return; 650 if (!which) return;
651 QString sub = which->bd_media_subtype; 651 QString sub = which->bd_media_subtype;
652 target_part.setSubtype(sub.lower()); 652 target_part.setSubtype(sub.lower());
653 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 653 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
654 clistcell*cur = 0; 654 clistcell*cur = 0;
655 mailimap_single_body_fld_param*param=0; 655 mailimap_single_body_fld_param*param=0;
656 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 656 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
657 param = (mailimap_single_body_fld_param*)cur->data; 657 param = (mailimap_single_body_fld_param*)cur->data;
658 if (param) { 658 if (param) {
659 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 659 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
660 } 660 }
661 } 661 }
662 } 662 }
663} 663}
664 664
665void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 665void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
666{ 666{
667 if (!which) { 667 if (!which) {
668 return; 668 return;
669 } 669 }
670 QString type,sub; 670 QString type,sub;
671 switch (which->bd_media_basic->med_type) { 671 switch (which->bd_media_basic->med_type) {
672 case MAILIMAP_MEDIA_BASIC_APPLICATION: 672 case MAILIMAP_MEDIA_BASIC_APPLICATION:
673 type = "application"; 673 type = "application";
674 break; 674 break;
675 case MAILIMAP_MEDIA_BASIC_AUDIO: 675 case MAILIMAP_MEDIA_BASIC_AUDIO:
676 type = "audio"; 676 type = "audio";
677 break; 677 break;
678 case MAILIMAP_MEDIA_BASIC_IMAGE: 678 case MAILIMAP_MEDIA_BASIC_IMAGE:
679 type = "image"; 679 type = "image";
680 break; 680 break;
681 case MAILIMAP_MEDIA_BASIC_MESSAGE: 681 case MAILIMAP_MEDIA_BASIC_MESSAGE:
682 type = "message"; 682 type = "message";
683 break; 683 break;
684 case MAILIMAP_MEDIA_BASIC_VIDEO: 684 case MAILIMAP_MEDIA_BASIC_VIDEO:
685 type = "video"; 685 type = "video";
686 break; 686 break;
687 case MAILIMAP_MEDIA_BASIC_OTHER: 687 case MAILIMAP_MEDIA_BASIC_OTHER:
688 default: 688 default:
689 if (which->bd_media_basic->med_basic_type) { 689 if (which->bd_media_basic->med_basic_type) {
690 type = which->bd_media_basic->med_basic_type; 690 type = which->bd_media_basic->med_basic_type;
691 } else { 691 } else {
692 type = ""; 692 type = "";
693 } 693 }
694 break; 694 break;
695 } 695 }
696 if (which->bd_media_basic->med_subtype) { 696 if (which->bd_media_basic->med_subtype) {
697 sub = which->bd_media_basic->med_subtype; 697 sub = which->bd_media_basic->med_subtype;
698 } else { 698 } else {
699 sub = ""; 699 sub = "";
700 } 700 }
701 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 701 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
702 target_part.setType(type.lower()); 702 target_part.setType(type.lower());
703 target_part.setSubtype(sub.lower()); 703 target_part.setSubtype(sub.lower());
704 fillBodyFields(target_part,which->bd_fields); 704 fillBodyFields(target_part,which->bd_fields);
705} 705}
706 706
707void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 707void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
708{ 708{
709 if (!which) return; 709 if (!which) return;
710 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 710 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
711 clistcell*cur; 711 clistcell*cur;
712 mailimap_single_body_fld_param*param=0; 712 mailimap_single_body_fld_param*param=0;
713 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 713 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
714 param = (mailimap_single_body_fld_param*)cur->data; 714 param = (mailimap_single_body_fld_param*)cur->data;
715 if (param) { 715 if (param) {
716 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 716 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
717 } 717 }
718 } 718 }
719 } 719 }
720 mailimap_body_fld_enc*enc = which->bd_encoding; 720 mailimap_body_fld_enc*enc = which->bd_encoding;
721 QString encoding(""); 721 QString encoding("");
722 switch (enc->enc_type) { 722 switch (enc->enc_type) {
723 case MAILIMAP_BODY_FLD_ENC_7BIT: 723 case MAILIMAP_BODY_FLD_ENC_7BIT:
724 encoding = "7bit"; 724 encoding = "7bit";
725 break; 725 break;
726 case MAILIMAP_BODY_FLD_ENC_8BIT: 726 case MAILIMAP_BODY_FLD_ENC_8BIT:
727 encoding = "8bit"; 727 encoding = "8bit";
728 break; 728 break;
729 case MAILIMAP_BODY_FLD_ENC_BINARY: 729 case MAILIMAP_BODY_FLD_ENC_BINARY:
730 encoding="binary"; 730 encoding="binary";
731 break; 731 break;
732 case MAILIMAP_BODY_FLD_ENC_BASE64: 732 case MAILIMAP_BODY_FLD_ENC_BASE64:
733 encoding="base64"; 733 encoding="base64";
734 break; 734 break;
735 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 735 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
736 encoding="quoted-printable"; 736 encoding="quoted-printable";
737 break; 737 break;
738 case MAILIMAP_BODY_FLD_ENC_OTHER: 738 case MAILIMAP_BODY_FLD_ENC_OTHER:
739 default: 739 default:
740 if (enc->enc_value) { 740 if (enc->enc_value) {
741 char*t=enc->enc_value; 741 char*t=enc->enc_value;
742 encoding=QString(enc->enc_value); 742 encoding=QString(enc->enc_value);
743 enc->enc_value=0L; 743 enc->enc_value=0L;
744 free(t); 744 free(t);
745 } 745 }
746 } 746 }
747 if (which->bd_description) { 747 if (which->bd_description) {
748 target_part.setDescription(QString(which->bd_description)); 748 target_part.setDescription(QString(which->bd_description));
749 } 749 }
750 target_part.setEncoding(encoding); 750 target_part.setEncoding(encoding);
751 target_part.setSize(which->bd_size); 751 target_part.setSize(which->bd_size);
752} 752}
753 753
754void IMAPwrapper::deleteMail(const RecMail&mail) 754void IMAPwrapper::deleteMail(const RecMail&mail)
755{ 755{
756 mailimap_flag_list*flist; 756 mailimap_flag_list*flist;
757 mailimap_set *set; 757 mailimap_set *set;
758 mailimap_store_att_flags * store_flags; 758 mailimap_store_att_flags * store_flags;
759 int err; 759 int err;
760 login(); 760 login();
761 if (!m_imap) { 761 if (!m_imap) {
762 return; 762 return;
763 } 763 }
764 const char *mb = mail.getMbox().latin1(); 764 const char *mb = mail.getMbox().latin1();
765 err = mailimap_select( m_imap, (char*)mb); 765 err = mailimap_select( m_imap, (char*)mb);
766 if ( err != MAILIMAP_NO_ERROR ) { 766 if ( err != MAILIMAP_NO_ERROR ) {
767 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 767 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
768 return; 768 return;
769 } 769 }
770 flist = mailimap_flag_list_new_empty(); 770 flist = mailimap_flag_list_new_empty();
771 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 771 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
772 store_flags = mailimap_store_att_flags_new_set_flags(flist); 772 store_flags = mailimap_store_att_flags_new_set_flags(flist);
773 set = mailimap_set_new_single(mail.getNumber()); 773 set = mailimap_set_new_single(mail.getNumber());
774 err = mailimap_store(m_imap,set,store_flags); 774 err = mailimap_store(m_imap,set,store_flags);
775 mailimap_set_free( set ); 775 mailimap_set_free( set );
776 mailimap_store_att_flags_free(store_flags); 776 mailimap_store_att_flags_free(store_flags);
777 777
778 if (err != MAILIMAP_NO_ERROR) { 778 if (err != MAILIMAP_NO_ERROR) {
779 qDebug("error deleting mail: %s",m_imap->imap_response); 779 qDebug("error deleting mail: %s",m_imap->imap_response);
780 return; 780 return;
781 } 781 }
782 qDebug("deleting mail: %s",m_imap->imap_response); 782 qDebug("deleting mail: %s",m_imap->imap_response);
783 /* should we realy do that at this moment? */ 783 /* should we realy do that at this moment? */
784 err = mailimap_expunge(m_imap); 784 err = mailimap_expunge(m_imap);
785 if (err != MAILIMAP_NO_ERROR) { 785 if (err != MAILIMAP_NO_ERROR) {
786 qDebug("error deleting mail: %s",m_imap->imap_response); 786 qDebug("error deleting mail: %s",m_imap->imap_response);
787 } 787 }
788 qDebug("Delete successfull %s",m_imap->imap_response); 788 qDebug("Delete successfull %s",m_imap->imap_response);
789} 789}
790 790
791void IMAPwrapper::answeredMail(const RecMail&mail) 791void IMAPwrapper::answeredMail(const RecMail&mail)
792{ 792{
793 mailimap_flag_list*flist; 793 mailimap_flag_list*flist;
794 mailimap_set *set; 794 mailimap_set *set;
795 mailimap_store_att_flags * store_flags; 795 mailimap_store_att_flags * store_flags;
796 int err; 796 int err;
797 login(); 797 login();
798 if (!m_imap) { 798 if (!m_imap) {
799 return; 799 return;
800 } 800 }
801 const char *mb = mail.getMbox().latin1(); 801 const char *mb = mail.getMbox().latin1();
802 err = mailimap_select( m_imap, (char*)mb); 802 err = mailimap_select( m_imap, (char*)mb);
803 if ( err != MAILIMAP_NO_ERROR ) { 803 if ( err != MAILIMAP_NO_ERROR ) {
804 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 804 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
805 return; 805 return;
806 } 806 }
807 flist = mailimap_flag_list_new_empty(); 807 flist = mailimap_flag_list_new_empty();
808 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 808 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
809 store_flags = mailimap_store_att_flags_new_add_flags(flist); 809 store_flags = mailimap_store_att_flags_new_add_flags(flist);
810 set = mailimap_set_new_single(mail.getNumber()); 810 set = mailimap_set_new_single(mail.getNumber());
811 err = mailimap_store(m_imap,set,store_flags); 811 err = mailimap_store(m_imap,set,store_flags);
812 mailimap_set_free( set ); 812 mailimap_set_free( set );
813 mailimap_store_att_flags_free(store_flags); 813 mailimap_store_att_flags_free(store_flags);
814 814
815 if (err != MAILIMAP_NO_ERROR) { 815 if (err != MAILIMAP_NO_ERROR) {
816 qDebug("error marking mail: %s",m_imap->imap_response); 816 qDebug("error marking mail: %s",m_imap->imap_response);
817 return; 817 return;
818 } 818 }
819} 819}
820 820
821QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 821QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
822{ 822{
823 QString body(""); 823 QString body("");
824 encodedString*res = fetchRawPart(mail,path,internal_call); 824 encodedString*res = fetchRawPart(mail,path,internal_call);
825 encodedString*r = decode_String(res,enc); 825 encodedString*r = decode_String(res,enc);
826 delete res; 826 delete res;
827 if (r) { 827 if (r) {
828 if (r->Length()>0) { 828 if (r->Length()>0) {
829 body = r->Content(); 829 body = r->Content();
830 } 830 }
831 delete r; 831 delete r;
832 } 832 }
833 return body; 833 return body;
834} 834}
835 835
836QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 836QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
837{ 837{
838 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 838 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
839} 839}
840 840
841encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 841encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
842{ 842{
843 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 843 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
844 encodedString*r = decode_String(res,part.Encoding()); 844 encodedString*r = decode_String(res,part.Encoding());
845 delete res; 845 delete res;
846 return r; 846 return r;
847} 847}
848 848
849encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 849encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
850{ 850{
851 return fetchRawPart(mail,part.Positionlist(),false); 851 return fetchRawPart(mail,part.Positionlist(),false);
852} 852}
853 853
854int IMAPwrapper::deleteAllMail(const Folder*folder) 854int IMAPwrapper::deleteAllMail(const Folder*folder)
855{ 855{
856 login(); 856 login();
857 if (!m_imap) { 857 if (!m_imap) {
858 return 0; 858 return 0;
859 } 859 }
860 mailimap_flag_list*flist; 860 mailimap_flag_list*flist;
861 mailimap_set *set; 861 mailimap_set *set;
862 mailimap_store_att_flags * store_flags; 862 mailimap_store_att_flags * store_flags;
863 int err = mailimap_select( m_imap, folder->getName().latin1()); 863 int err = mailimap_select( m_imap, folder->getName().latin1());
864 if ( err != MAILIMAP_NO_ERROR ) { 864 if ( err != MAILIMAP_NO_ERROR ) {
865 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); 865 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
866 return 0; 866 return 0;
867 } 867 }
868 int last = m_imap->imap_selection_info->sel_exists; 868 int last = m_imap->imap_selection_info->sel_exists;
869 if (last == 0) { 869 if (last == 0) {
870 Global::statusMessage(tr("Mailbox has no mails!")); 870 Global::statusMessage(tr("Mailbox has no mails!"));
871 return 0; 871 return 0;
872 } 872 }
873 flist = mailimap_flag_list_new_empty(); 873 flist = mailimap_flag_list_new_empty();
874 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 874 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
875 store_flags = mailimap_store_att_flags_new_set_flags(flist); 875 store_flags = mailimap_store_att_flags_new_set_flags(flist);
876 set = mailimap_set_new_interval( 1, last ); 876 set = mailimap_set_new_interval( 1, last );
877 err = mailimap_store(m_imap,set,store_flags); 877 err = mailimap_store(m_imap,set,store_flags);
878 mailimap_set_free( set ); 878 mailimap_set_free( set );
879 mailimap_store_att_flags_free(store_flags); 879 mailimap_store_att_flags_free(store_flags);
880 if (err != MAILIMAP_NO_ERROR) { 880 if (err != MAILIMAP_NO_ERROR) {
881 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 881 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
882 return 0; 882 return 0;
883 } 883 }
884 qDebug("deleting mail: %s",m_imap->imap_response); 884 qDebug("deleting mail: %s",m_imap->imap_response);
885 /* should we realy do that at this moment? */ 885 /* should we realy do that at this moment? */
886 err = mailimap_expunge(m_imap); 886 err = mailimap_expunge(m_imap);
887 if (err != MAILIMAP_NO_ERROR) { 887 if (err != MAILIMAP_NO_ERROR) {
888 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 888 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
889 return 0; 889 return 0;
890 } 890 }
891 qDebug("Delete successfull %s",m_imap->imap_response); 891 qDebug("Delete successfull %s",m_imap->imap_response);
892 return 1; 892 return 1;
893} 893}
894 894
895int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) 895int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder)
896{ 896{
897 if (folder.length()==0) return 0; 897 if (folder.length()==0) return 0;
898 login(); 898 login();
899 if (!m_imap) {return 0;} 899 if (!m_imap) {return 0;}
900 QString pre = account->getPrefix(); 900 QString pre = account->getPrefix();
901 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 901 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
902 pre+=delemiter; 902 pre+=delemiter;
903 } 903 }
904 if (parentfolder) { 904 if (parentfolder) {
905 pre += parentfolder->getDisplayName()+delemiter; 905 pre += parentfolder->getDisplayName()+delemiter;
906 } 906 }
907 pre+=folder; 907 pre+=folder;
908 if (getsubfolder) { 908 if (getsubfolder) {
909 if (delemiter.length()>0) { 909 if (delemiter.length()>0) {
910 pre+=delemiter; 910 pre+=delemiter;
911 } else { 911 } else {
912 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 912 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
913 return 0; 913 return 0;
914 } 914 }
915 } 915 }
916 qDebug("Creating %s",pre.latin1()); 916 qDebug("Creating %s",pre.latin1());
917 int res = mailimap_create(m_imap,pre.latin1()); 917 int res = mailimap_create(m_imap,pre.latin1());
918 if (res != MAILIMAP_NO_ERROR) { 918 if (res != MAILIMAP_NO_ERROR) {
919 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 919 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
920 return 0; 920 return 0;
921 } 921 }
922 return 1; 922 return 1;
923} 923}
924 924
925int IMAPwrapper::deleteMbox(const Folder*folder) 925int IMAPwrapper::deleteMbox(const Folder*folder)
926{ 926{
927 if (!folder) return 0; 927 if (!folder) return 0;
928 login(); 928 login();
929 if (!m_imap) {return 0;} 929 if (!m_imap) {return 0;}
930 int res = mailimap_delete(m_imap,folder->getName()); 930 int res = mailimap_delete(m_imap,folder->getName());
931 if (res != MAILIMAP_NO_ERROR) { 931 if (res != MAILIMAP_NO_ERROR) {
932 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 932 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
933 return 0; 933 return 0;
934 } 934 }
935 return 1; 935 return 1;
936} 936}
937 937
938void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 938void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
939{ 939{
940 mailimap_status_att_list * att_list =0; 940 mailimap_status_att_list * att_list =0;
941 mailimap_mailbox_data_status * status=0; 941 mailimap_mailbox_data_status * status=0;
942 clistiter * cur = 0; 942 clistiter * cur = 0;
943 int r = 0; 943 int r = 0;
944 int res = 0; 944 int res = 0;
945 target_stat.message_count = 0; 945 target_stat.message_count = 0;
946 target_stat.message_unseen = 0; 946 target_stat.message_unseen = 0;
947 target_stat.message_recent = 0; 947 target_stat.message_recent = 0;
948 login(); 948 login();
949 if (!m_imap) { 949 if (!m_imap) {
950 return; 950 return;
951 } 951 }
952 att_list = mailimap_status_att_list_new_empty(); 952 att_list = mailimap_status_att_list_new_empty();
953 if (!att_list) return; 953 if (!att_list) return;
954 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 954 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
955 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 955 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
956 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 956 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
957 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 957 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
958 for (cur = clist_begin(status->st_info_list); 958 for (cur = clist_begin(status->st_info_list);
959 cur != NULL ; cur = clist_next(cur)) { 959 cur != NULL ; cur = clist_next(cur)) {
960 mailimap_status_info * status_info; 960 mailimap_status_info * status_info;
961 status_info = (mailimap_status_info *)clist_content(cur); 961 status_info = (mailimap_status_info *)clist_content(cur);
962 switch (status_info->st_att) { 962 switch (status_info->st_att) {
963 case MAILIMAP_STATUS_ATT_MESSAGES: 963 case MAILIMAP_STATUS_ATT_MESSAGES:
964 target_stat.message_count = status_info->st_value; 964 target_stat.message_count = status_info->st_value;
965 break; 965 break;
966 case MAILIMAP_STATUS_ATT_RECENT: 966 case MAILIMAP_STATUS_ATT_RECENT:
967 target_stat.message_recent = status_info->st_value; 967 target_stat.message_recent = status_info->st_value;
968 break; 968 break;
969 case MAILIMAP_STATUS_ATT_UNSEEN: 969 case MAILIMAP_STATUS_ATT_UNSEEN:
970 target_stat.message_unseen = status_info->st_value; 970 target_stat.message_unseen = status_info->st_value;
971 break; 971 break;
972 } 972 }
973 } 973 }
974 mailimap_mailbox_data_status_free(status); 974 mailimap_mailbox_data_status_free(status);
975 mailimap_status_att_list_free(att_list); 975 mailimap_status_att_list_free(att_list);
976} 976}
977 977
978void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 978void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
979{ 979{
980 login(); 980 login();
981 if (!m_imap) return; 981 if (!m_imap) return;
982 if (!msg) return; 982 if (!msg) return;
983 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 983 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
984 if (r != MAILIMAP_NO_ERROR) { 984 if (r != MAILIMAP_NO_ERROR) {
985 Global::statusMessage("Error storing mail!"); 985 Global::statusMessage("Error storing mail!");
986 } 986 }
987} 987}
988
989const QString&IMAPwrapper::getType()const
990{
991 return account->getType();
992}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index a97f12d..6a9c411 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,69 +1,70 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h" 6#include "abstractmail.h"
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9struct mailimap; 9struct mailimap;
10struct mailimap_body; 10struct mailimap_body;
11struct mailimap_body_type_1part; 11struct mailimap_body_type_1part;
12struct mailimap_body_type_text; 12struct mailimap_body_type_text;
13struct mailimap_body_type_basic; 13struct mailimap_body_type_basic;
14struct mailimap_body_type_msg; 14struct mailimap_body_type_msg;
15struct mailimap_body_type_mpart; 15struct mailimap_body_type_mpart;
16struct mailimap_body_fields; 16struct mailimap_body_fields;
17struct mailimap_msg_att; 17struct mailimap_msg_att;
18class encodedString; 18class encodedString;
19 19
20class IMAPwrapper : public AbstractMail 20class IMAPwrapper : public AbstractMail
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23public: 23public:
24 IMAPwrapper( IMAPaccount *a ); 24 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 25 virtual ~IMAPwrapper();
26 virtual QList<Folder>* listFolders(); 26 virtual QList<Folder>* listFolders();
27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
29 29
30 virtual void deleteMail(const RecMail&mail); 30 virtual void deleteMail(const RecMail&mail);
31 virtual void answeredMail(const RecMail&mail); 31 virtual void answeredMail(const RecMail&mail);
32 virtual int deleteAllMail(const Folder*folder); 32 virtual int deleteAllMail(const Folder*folder);
33 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 33 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
34 34
35 virtual RecBody fetchBody(const RecMail&mail); 35 virtual RecBody fetchBody(const RecMail&mail);
36 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 36 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
37 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 37 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
38 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 38 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
39 39
40 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 40 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
41 virtual int deleteMbox(const Folder*folder); 41 virtual int deleteMbox(const Folder*folder);
42 42
43 static void imap_progress( size_t current, size_t maximum ); 43 static void imap_progress( size_t current, size_t maximum );
44 44
45 virtual void logout(); 45 virtual void logout();
46 virtual const QString&getType()const;
46protected: 47protected:
47 RecMail*parse_list_result(mailimap_msg_att*); 48 RecMail*parse_list_result(mailimap_msg_att*);
48 void login(); 49 void login();
49 50
50 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 51 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
51 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); 52 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
52 53
53 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 54 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
54 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 55 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
55 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 56 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
56 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 57 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
57 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); 58 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which);
58 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); 59 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
59 60
60 /* just helpers */ 61 /* just helpers */
61 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 62 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
62 static QStringList address_list_to_stringlist(clist*list); 63 static QStringList address_list_to_stringlist(clist*list);
63 64
64 65
65 IMAPaccount *account; 66 IMAPaccount *account;
66 mailimap *m_imap; 67 mailimap *m_imap;
67}; 68};
68 69
69#endif 70#endif
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
index 540a971..60f7507 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
@@ -1,324 +1,331 @@
1#include "mboxwrapper.h" 1#include "mboxwrapper.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "mailwrapper.h" 3#include "mailwrapper.h"
4#include <libetpan/libetpan.h> 4#include <libetpan/libetpan.h>
5#include <qdir.h> 5#include <qdir.h>
6#include <stdlib.h> 6#include <stdlib.h>
7#include <qpe/global.h> 7#include <qpe/global.h>
8 8
9const QString MBOXwrapper::wrapperType="MBOX";
10
9MBOXwrapper::MBOXwrapper(const QString & mbox_dir) 11MBOXwrapper::MBOXwrapper(const QString & mbox_dir)
10 : Genericwrapper(),MBOXPath(mbox_dir) 12 : Genericwrapper(),MBOXPath(mbox_dir)
11{ 13{
12 QDir dir(MBOXPath); 14 QDir dir(MBOXPath);
13 if (!dir.exists()) { 15 if (!dir.exists()) {
14 dir.mkdir(MBOXPath); 16 dir.mkdir(MBOXPath);
15 } 17 }
16} 18}
17 19
18MBOXwrapper::~MBOXwrapper() 20MBOXwrapper::~MBOXwrapper()
19{ 21{
20} 22}
21 23
22void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) 24void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
23{ 25{
24 mailstorage*storage = mailstorage_new(NULL); 26 mailstorage*storage = mailstorage_new(NULL);
25 QString p = MBOXPath+"/"; 27 QString p = MBOXPath+"/";
26 p+=mailbox; 28 p+=mailbox;
27 29
28 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 30 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
29 mailfolder*folder; 31 mailfolder*folder;
30 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 32 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
31 r = mailfolder_connect(folder); 33 r = mailfolder_connect(folder);
32 if (r != MAIL_NO_ERROR) { 34 if (r != MAIL_NO_ERROR) {
33 qDebug("Error initializing mbox"); 35 qDebug("Error initializing mbox");
34 mailfolder_free(folder); 36 mailfolder_free(folder);
35 mailstorage_free(storage); 37 mailstorage_free(storage);
36 return; 38 return;
37 } 39 }
38 40
39 parseList(target,folder->fld_session,mailbox); 41 parseList(target,folder->fld_session,mailbox);
40 42
41 mailfolder_disconnect(folder); 43 mailfolder_disconnect(folder);
42 mailfolder_free(folder); 44 mailfolder_free(folder);
43 mailstorage_free(storage); 45 mailstorage_free(storage);
44 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); 46 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
45} 47}
46 48
47QList<Folder>* MBOXwrapper::listFolders() 49QList<Folder>* MBOXwrapper::listFolders()
48{ 50{
49 QList<Folder> * folders = new QList<Folder>(); 51 QList<Folder> * folders = new QList<Folder>();
50 folders->setAutoDelete( false ); 52 folders->setAutoDelete( false );
51 QDir dir(MBOXPath); 53 QDir dir(MBOXPath);
52 if (!dir.exists()) return folders; 54 if (!dir.exists()) return folders;
53 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); 55 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable);
54 QStringList entries = dir.entryList(); 56 QStringList entries = dir.entryList();
55 QStringList::ConstIterator it = entries.begin(); 57 QStringList::ConstIterator it = entries.begin();
56 for (;it!=entries.end();++it) { 58 for (;it!=entries.end();++it) {
57 Folder*inb=new Folder(*it,"/"); 59 Folder*inb=new Folder(*it,"/");
58 folders->append(inb); 60 folders->append(inb);
59 } 61 }
60 return folders; 62 return folders;
61} 63}
62 64
63void MBOXwrapper::deleteMail(const RecMail&mail) 65void MBOXwrapper::deleteMail(const RecMail&mail)
64{ 66{
65 mailstorage*storage = mailstorage_new(NULL); 67 mailstorage*storage = mailstorage_new(NULL);
66 QString p = MBOXPath+"/"; 68 QString p = MBOXPath+"/";
67 p+=mail.getMbox(); 69 p+=mail.getMbox();
68 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 70 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
69 mailfolder*folder; 71 mailfolder*folder;
70 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 72 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
71 r = mailfolder_connect(folder); 73 r = mailfolder_connect(folder);
72 if (r != MAIL_NO_ERROR) { 74 if (r != MAIL_NO_ERROR) {
73 qDebug("Error initializing mbox"); 75 qDebug("Error initializing mbox");
74 mailfolder_free(folder); 76 mailfolder_free(folder);
75 mailstorage_free(storage); 77 mailstorage_free(storage);
76 return; 78 return;
77 } 79 }
78 r = mailsession_remove_message(folder->fld_session,mail.getNumber()); 80 r = mailsession_remove_message(folder->fld_session,mail.getNumber());
79 if (r != MAIL_NO_ERROR) { 81 if (r != MAIL_NO_ERROR) {
80 qDebug("error deleting mail"); 82 qDebug("error deleting mail");
81 } 83 }
82 mailfolder_free(folder); 84 mailfolder_free(folder);
83 mailstorage_free(storage); 85 mailstorage_free(storage);
84} 86}
85 87
86void MBOXwrapper::answeredMail(const RecMail&) 88void MBOXwrapper::answeredMail(const RecMail&)
87{ 89{
88} 90}
89 91
90RecBody MBOXwrapper::fetchBody( const RecMail &mail ) 92RecBody MBOXwrapper::fetchBody( const RecMail &mail )
91{ 93{
92 RecBody body; 94 RecBody body;
93 mailstorage*storage = mailstorage_new(NULL); 95 mailstorage*storage = mailstorage_new(NULL);
94 QString p = MBOXPath+"/"; 96 QString p = MBOXPath+"/";
95 p+=mail.getMbox(); 97 p+=mail.getMbox();
96 mailmessage * msg; 98 mailmessage * msg;
97 char*data=0; 99 char*data=0;
98 size_t size; 100 size_t size;
99 101
100 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 102 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
101 mailfolder*folder; 103 mailfolder*folder;
102 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 104 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
103 r = mailfolder_connect(folder); 105 r = mailfolder_connect(folder);
104 if (r != MAIL_NO_ERROR) { 106 if (r != MAIL_NO_ERROR) {
105 qDebug("Error initializing mbox"); 107 qDebug("Error initializing mbox");
106 mailfolder_free(folder); 108 mailfolder_free(folder);
107 mailstorage_free(storage); 109 mailstorage_free(storage);
108 return body; 110 return body;
109 } 111 }
110 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); 112 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
111 if (r != MAIL_NO_ERROR) { 113 if (r != MAIL_NO_ERROR) {
112 qDebug("Error fetching mail %i",mail.getNumber()); 114 qDebug("Error fetching mail %i",mail.getNumber());
113 mailfolder_free(folder); 115 mailfolder_free(folder);
114 mailstorage_free(storage); 116 mailstorage_free(storage);
115 return body; 117 return body;
116 } 118 }
117 r = mailmessage_fetch(msg,&data,&size); 119 r = mailmessage_fetch(msg,&data,&size);
118 if (r != MAIL_NO_ERROR) { 120 if (r != MAIL_NO_ERROR) {
119 qDebug("Error fetching mail %i",mail.getNumber()); 121 qDebug("Error fetching mail %i",mail.getNumber());
120 mailfolder_free(folder); 122 mailfolder_free(folder);
121 mailstorage_free(storage); 123 mailstorage_free(storage);
122 mailmessage_free(msg); 124 mailmessage_free(msg);
123 return body; 125 return body;
124 } 126 }
125 body = parseMail(msg); 127 body = parseMail(msg);
126 mailmessage_fetch_result_free(msg,data); 128 mailmessage_fetch_result_free(msg,data);
127 mailfolder_free(folder); 129 mailfolder_free(folder);
128 mailstorage_free(storage); 130 mailstorage_free(storage);
129 131
130 return body; 132 return body;
131} 133}
132 134
133void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) 135void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
134{ 136{
135 qDebug("MBOX %i von %i",current,maximum); 137 qDebug("MBOX %i von %i",current,maximum);
136} 138}
137 139
138int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) 140int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool )
139{ 141{
140 QString p = MBOXPath+"/"; 142 QString p = MBOXPath+"/";
141 p+=folder; 143 p+=folder;
142 QFileInfo fi(p); 144 QFileInfo fi(p);
143 if (fi.exists()) { 145 if (fi.exists()) {
144 Global::statusMessage(tr("Mailbox exists.")); 146 Global::statusMessage(tr("Mailbox exists."));
145 return 0; 147 return 0;
146 } 148 }
147 mailmbox_folder*f = 0; 149 mailmbox_folder*f = 0;
148 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { 150 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) {
149 Global::statusMessage(tr("Error init folder")); 151 Global::statusMessage(tr("Error init folder"));
150 return 0; 152 return 0;
151 } 153 }
152 if (f) mailmbox_done(f); 154 if (f) mailmbox_done(f);
153 return 1; 155 return 1;
154} 156}
155 157
156void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 158void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
157{ 159{
158 QString p = MBOXPath+"/"; 160 QString p = MBOXPath+"/";
159 p+=folder; 161 p+=folder;
160 mailmbox_folder*f = 0; 162 mailmbox_folder*f = 0;
161 int r = mailmbox_init(p.latin1(),0,1,0,&f); 163 int r = mailmbox_init(p.latin1(),0,1,0,&f);
162 if (r != MAIL_NO_ERROR) { 164 if (r != MAIL_NO_ERROR) {
163 Global::statusMessage(tr("Error init folder")); 165 Global::statusMessage(tr("Error init folder"));
164 return; 166 return;
165 } 167 }
166 r = mailmbox_append_message(f,msg,length); 168 r = mailmbox_append_message(f,msg,length);
167 if (r != MAIL_NO_ERROR) { 169 if (r != MAIL_NO_ERROR) {
168 Global::statusMessage(tr("Error writing to message folder")); 170 Global::statusMessage(tr("Error writing to message folder"));
169 } 171 }
170 mailmbox_done(f); 172 mailmbox_done(f);
171} 173}
172 174
173void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) 175void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length)
174{ 176{
175 RecBody body; 177 RecBody body;
176 mailstorage*storage = mailstorage_new(NULL); 178 mailstorage*storage = mailstorage_new(NULL);
177 QString p = MBOXPath+"/"; 179 QString p = MBOXPath+"/";
178 p+=mail.getMbox(); 180 p+=mail.getMbox();
179 mailmessage * msg; 181 mailmessage * msg;
180 char*data=0; 182 char*data=0;
181 size_t size; 183 size_t size;
182 184
183 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 185 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
184 mailfolder*folder; 186 mailfolder*folder;
185 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 187 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
186 r = mailfolder_connect(folder); 188 r = mailfolder_connect(folder);
187 if (r != MAIL_NO_ERROR) { 189 if (r != MAIL_NO_ERROR) {
188 Global::statusMessage(tr("Error initializing mbox")); 190 Global::statusMessage(tr("Error initializing mbox"));
189 mailfolder_free(folder); 191 mailfolder_free(folder);
190 mailstorage_free(storage); 192 mailstorage_free(storage);
191 return; 193 return;
192 } 194 }
193 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); 195 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
194 if (r != MAIL_NO_ERROR) { 196 if (r != MAIL_NO_ERROR) {
195 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 197 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
196 mailfolder_free(folder); 198 mailfolder_free(folder);
197 mailstorage_free(storage); 199 mailstorage_free(storage);
198 return; 200 return;
199 } 201 }
200 r = mailmessage_fetch(msg,&data,&size); 202 r = mailmessage_fetch(msg,&data,&size);
201 if (r != MAIL_NO_ERROR) { 203 if (r != MAIL_NO_ERROR) {
202 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 204 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
203 mailfolder_free(folder); 205 mailfolder_free(folder);
204 mailstorage_free(storage); 206 mailstorage_free(storage);
205 mailmessage_free(msg); 207 mailmessage_free(msg);
206 return; 208 return;
207 } 209 }
208 *target = data; 210 *target = data;
209 *length = size; 211 *length = size;
210 mailfolder_free(folder); 212 mailfolder_free(folder);
211 mailstorage_free(storage); 213 mailstorage_free(storage);
212 mailmessage_free(msg); 214 mailmessage_free(msg);
213} 215}
214 216
215void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) 217void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target)
216{ 218{
217 QString p = MBOXPath+"/"; 219 QString p = MBOXPath+"/";
218 p+=mailbox; 220 p+=mailbox;
219 mailmbox_folder*f = 0; 221 mailmbox_folder*f = 0;
220 int r = mailmbox_init(p.latin1(),0,1,0,&f); 222 int r = mailmbox_init(p.latin1(),0,1,0,&f);
221 if (r != MAIL_NO_ERROR) { 223 if (r != MAIL_NO_ERROR) {
222 qDebug("Error init folder"); 224 qDebug("Error init folder");
223 return; 225 return;
224 } 226 }
225 deleteMails(f,target); 227 deleteMails(f,target);
226 mailmbox_done(f); 228 mailmbox_done(f);
227} 229}
228 230
229void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) 231void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target)
230{ 232{
231 if (!f) return; 233 if (!f) return;
232 int r; 234 int r;
233 for (unsigned int i=0; i < target.count();++i) { 235 for (unsigned int i=0; i < target.count();++i) {
234 r = mailmbox_delete_msg(f,target.at(i)->getNumber()); 236 r = mailmbox_delete_msg(f,target.at(i)->getNumber());
235 if (r!=MAILMBOX_NO_ERROR) { 237 if (r!=MAILMBOX_NO_ERROR) {
236 qDebug("error delete mail"); 238 qDebug("error delete mail");
237 } 239 }
238 } 240 }
239 r = mailmbox_expunge(f); 241 r = mailmbox_expunge(f);
240 if (r != MAILMBOX_NO_ERROR) { 242 if (r != MAILMBOX_NO_ERROR) {
241 qDebug("error expunge mailbox"); 243 qDebug("error expunge mailbox");
242 } 244 }
243} 245}
244 246
245int MBOXwrapper::deleteAllMail(const Folder*tfolder) 247int MBOXwrapper::deleteAllMail(const Folder*tfolder)
246{ 248{
247 if (!tfolder) return 0; 249 if (!tfolder) return 0;
248 QString p = MBOXPath+tfolder->getDisplayName(); 250 QString p = MBOXPath+tfolder->getDisplayName();
249 int res = 1; 251 int res = 1;
250 252
251 mailfolder*folder = 0; 253 mailfolder*folder = 0;
252 mailmessage_list*l=0; 254 mailmessage_list*l=0;
253 mailstorage*storage = mailstorage_new(NULL); 255 mailstorage*storage = mailstorage_new(NULL);
254 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 256 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
255 if (r != MAIL_NO_ERROR) { 257 if (r != MAIL_NO_ERROR) {
256 Global::statusMessage(tr("Error initializing mbox")); 258 Global::statusMessage(tr("Error initializing mbox"));
257 res = 0; 259 res = 0;
258 } 260 }
259 if (res) { 261 if (res) {
260 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 262 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
261 r = mailfolder_connect(folder); 263 r = mailfolder_connect(folder);
262 if (r != MAIL_NO_ERROR) { 264 if (r != MAIL_NO_ERROR) {
263 Global::statusMessage(tr("Error initializing mbox")); 265 Global::statusMessage(tr("Error initializing mbox"));
264 res = 0; 266 res = 0;
265 } 267 }
266 } 268 }
267 if (res) { 269 if (res) {
268 r = mailsession_get_messages_list(folder->fld_session,&l); 270 r = mailsession_get_messages_list(folder->fld_session,&l);
269 if (r != MAIL_NO_ERROR) { 271 if (r != MAIL_NO_ERROR) {
270 qDebug("Error message list"); 272 qDebug("Error message list");
271 res=0; 273 res=0;
272 } 274 }
273 } 275 }
274 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 276 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
275 r = mailsession_remove_message(folder->fld_session,i+1); 277 r = mailsession_remove_message(folder->fld_session,i+1);
276 if (r != MAIL_NO_ERROR) { 278 if (r != MAIL_NO_ERROR) {
277 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 279 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
278 res = 0; 280 res = 0;
279 break; 281 break;
280 } 282 }
281 } 283 }
282 if (l) mailmessage_list_free(l); 284 if (l) mailmessage_list_free(l);
283 if (folder) mailfolder_free(folder); 285 if (folder) mailfolder_free(folder);
284 if (storage) mailstorage_free(storage); 286 if (storage) mailstorage_free(storage);
285 return res; 287 return res;
286} 288}
287 289
288int MBOXwrapper::deleteMbox(const Folder*tfolder) 290int MBOXwrapper::deleteMbox(const Folder*tfolder)
289{ 291{
290 if (!tfolder) return 0; 292 if (!tfolder) return 0;
291 QString p = MBOXPath+tfolder->getDisplayName(); 293 QString p = MBOXPath+tfolder->getDisplayName();
292 QFile fi(p); 294 QFile fi(p);
293 if (!fi.exists()) { 295 if (!fi.exists()) {
294 Global::statusMessage(tr("Mailbox doesn't exist.")); 296 Global::statusMessage(tr("Mailbox doesn't exist."));
295 return 0; 297 return 0;
296 } 298 }
297 if (!fi.remove()) { 299 if (!fi.remove()) {
298 Global::statusMessage(tr("Error deleting Mailbox.")); 300 Global::statusMessage(tr("Error deleting Mailbox."));
299 return 0; 301 return 0;
300 } 302 }
301 return 1; 303 return 1;
302} 304}
303 305
304void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 306void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
305{ 307{
306 mailfolder*folder = 0; 308 mailfolder*folder = 0;
307 mailstorage*storage = mailstorage_new(NULL); 309 mailstorage*storage = mailstorage_new(NULL);
308 target_stat.message_count = 0; 310 target_stat.message_count = 0;
309 target_stat.message_unseen = 0; 311 target_stat.message_unseen = 0;
310 target_stat.message_recent = 0; 312 target_stat.message_recent = 0;
311 QString p = MBOXPath+"/"+mailbox; 313 QString p = MBOXPath+"/"+mailbox;
312 QFile fi(p); 314 QFile fi(p);
313 if (!fi.exists()) { 315 if (!fi.exists()) {
314 Global::statusMessage(tr("Mailbox doesn't exist.")); 316 Global::statusMessage(tr("Mailbox doesn't exist."));
315 return; 317 return;
316 } 318 }
317 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 319 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
318 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 320 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
319 r = mailfolder_connect(folder); 321 r = mailfolder_connect(folder);
320 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, 322 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count,
321 &target_stat.message_recent,&target_stat.message_unseen); 323 &target_stat.message_recent,&target_stat.message_unseen);
322 if (folder) mailfolder_free(folder); 324 if (folder) mailfolder_free(folder);
323 if (storage) mailstorage_free(storage); 325 if (storage) mailstorage_free(storage);
324} 326}
327
328const QString&MBOXwrapper::getType()const
329{
330 return wrapperType;
331}
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h
index f822997..f97fce2 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h
@@ -1,42 +1,44 @@
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 RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9struct mailmbox_folder; 9struct mailmbox_folder;
10 10
11class MBOXwrapper : public Genericwrapper 11class MBOXwrapper : public Genericwrapper
12{ 12{
13 Q_OBJECT 13 Q_OBJECT
14public: 14public:
15 MBOXwrapper(const QString & dir); 15 MBOXwrapper(const QString & dir);
16 virtual ~MBOXwrapper(); 16 virtual ~MBOXwrapper();
17 17
18 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 18 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
19 virtual QList<Folder>* listFolders(); 19 virtual QList<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 RecMail&mail); 22 virtual void deleteMail(const RecMail&mail);
23 virtual void answeredMail(const RecMail&mail); 23 virtual void answeredMail(const RecMail&mail);
24 24
25 virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); 25 virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false);
26 virtual int deleteMbox(const Folder*); 26 virtual int deleteMbox(const Folder*);
27 27
28 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 28 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
29 29
30 virtual RecBody fetchBody( const RecMail &mail ); 30 virtual RecBody fetchBody( const RecMail &mail );
31 static void mbox_progress( size_t current, size_t maximum ); 31 static void mbox_progress( size_t current, size_t maximum );
32 32
33 virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); 33 virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length);
34 virtual void deleteMails(const QString & mailbox,QList<RecMail> &target); 34 virtual void deleteMails(const QString & mailbox,QList<RecMail> &target);
35 virtual int deleteAllMail(const Folder*); 35 virtual int deleteAllMail(const Folder*);
36 virtual const QString&getType()const;
36 37
37protected: 38protected:
38 static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); 39 static void deleteMails(mailmbox_folder*f,QList<RecMail> &target);
39 QString MBOXPath; 40 QString MBOXPath;
41 static const QString wrapperType;
40}; 42};
41 43
42#endif 44#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index b4eca6f..45408dd 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,237 +1,242 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
6#include <qpe/global.h> 6#include <qpe/global.h>
7#include <qfile.h> 7#include <qfile.h>
8#include <qstring.h> 8#include <qstring.h>
9 9
10/* we don't fetch messages larger than 5 MB */ 10/* we don't fetch messages larger than 5 MB */
11#define HARD_MSG_SIZE_LIMIT 5242880 11#define HARD_MSG_SIZE_LIMIT 5242880
12 12
13POP3wrapper::POP3wrapper( POP3account *a ) 13POP3wrapper::POP3wrapper( POP3account *a )
14 : Genericwrapper() 14 : Genericwrapper()
15{ 15{
16 account = a; 16 account = a;
17 m_pop3 = NULL; 17 m_pop3 = NULL;
18 m_folder = NULL; 18 m_folder = NULL;
19 msgTempName = a->getFileName()+"_msg_cache"; 19 msgTempName = a->getFileName()+"_msg_cache";
20 last_msg_id = 0; 20 last_msg_id = 0;
21} 21}
22 22
23POP3wrapper::~POP3wrapper() 23POP3wrapper::~POP3wrapper()
24{ 24{
25 logout(); 25 logout();
26 QFile msg_cache(msgTempName); 26 QFile msg_cache(msgTempName);
27 if (msg_cache.exists()) { 27 if (msg_cache.exists()) {
28 msg_cache.remove(); 28 msg_cache.remove();
29 } 29 }
30} 30}
31 31
32void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 32void POP3wrapper::pop3_progress( size_t current, size_t maximum )
33{ 33{
34 qDebug( "POP3: %i of %i", current, maximum ); 34 qDebug( "POP3: %i of %i", current, maximum );
35} 35}
36 36
37RecBody POP3wrapper::fetchBody( const RecMail &mail ) 37RecBody POP3wrapper::fetchBody( const RecMail &mail )
38{ 38{
39 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
40 char *message = 0; 40 char *message = 0;
41 size_t length = 0; 41 size_t length = 0;
42 42
43 login(); 43 login();
44 if ( !m_pop3 ) { 44 if ( !m_pop3 ) {
45 return RecBody(); 45 return RecBody();
46 } 46 }
47 47
48 RecBody body; 48 RecBody body;
49 mailmessage * mailmsg; 49 mailmessage * mailmsg;
50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
51 qDebug("Message to large: %i",mail.Msgsize()); 51 qDebug("Message to large: %i",mail.Msgsize());
52 return body; 52 return body;
53 } 53 }
54 54
55 QFile msg_cache(msgTempName); 55 QFile msg_cache(msgTempName);
56 56
57 cleanMimeCache(); 57 cleanMimeCache();
58 58
59 if (mail.getNumber()!=last_msg_id) { 59 if (mail.getNumber()!=last_msg_id) {
60 if (msg_cache.exists()) { 60 if (msg_cache.exists()) {
61 msg_cache.remove(); 61 msg_cache.remove();
62 } 62 }
63 msg_cache.open(IO_ReadWrite|IO_Truncate); 63 msg_cache.open(IO_ReadWrite|IO_Truncate);
64 last_msg_id = mail.getNumber(); 64 last_msg_id = mail.getNumber();
65 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); 65 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
66 err = mailmessage_fetch(mailmsg,&message,&length); 66 err = mailmessage_fetch(mailmsg,&message,&length);
67 msg_cache.writeBlock(message,length); 67 msg_cache.writeBlock(message,length);
68 } else { 68 } else {
69 QString msg=""; 69 QString msg="";
70 msg_cache.open(IO_ReadOnly); 70 msg_cache.open(IO_ReadOnly);
71 message = new char[4096]; 71 message = new char[4096];
72 memset(message,0,4096); 72 memset(message,0,4096);
73 while (msg_cache.readBlock(message,4095)>0) { 73 while (msg_cache.readBlock(message,4095)>0) {
74 msg+=message; 74 msg+=message;
75 memset(message,0,4096); 75 memset(message,0,4096);
76 } 76 }
77 delete message; 77 delete message;
78 message = (char*)malloc(msg.length()+1*sizeof(char)); 78 message = (char*)malloc(msg.length()+1*sizeof(char));
79 memset(message,0,msg.length()+1); 79 memset(message,0,msg.length()+1);
80 memcpy(message,msg.latin1(),msg.length()); 80 memcpy(message,msg.latin1(),msg.length());
81 /* transform to libetpan stuff */ 81 /* transform to libetpan stuff */
82 mailmsg = mailmessage_new(); 82 mailmsg = mailmessage_new();
83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
84 generic_message_t * msg_data; 84 generic_message_t * msg_data;
85 msg_data = (generic_message_t *)mailmsg->msg_data; 85 msg_data = (generic_message_t *)mailmsg->msg_data;
86 msg_data->msg_fetched = 1; 86 msg_data->msg_fetched = 1;
87 msg_data->msg_message = message; 87 msg_data->msg_message = message;
88 msg_data->msg_length = strlen(message); 88 msg_data->msg_length = strlen(message);
89 } 89 }
90 body = parseMail(mailmsg); 90 body = parseMail(mailmsg);
91 91
92 /* clean up */ 92 /* clean up */
93 if (mailmsg) mailmessage_free(mailmsg); 93 if (mailmsg) mailmessage_free(mailmsg);
94 if (message) free(message); 94 if (message) free(message);
95 95
96 return body; 96 return body;
97} 97}
98 98
99void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 99void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
100{ 100{
101 login(); 101 login();
102 if (!m_pop3) return; 102 if (!m_pop3) return;
103 uint32_t res_messages,res_recent,res_unseen; 103 uint32_t res_messages,res_recent,res_unseen;
104 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); 104 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen);
105 parseList(target,m_folder->fld_session,"INBOX"); 105 parseList(target,m_folder->fld_session,"INBOX");
106 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 106 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
107} 107}
108 108
109void POP3wrapper::login() 109void POP3wrapper::login()
110{ 110{
111 /* we'll hold the line */ 111 /* we'll hold the line */
112 if ( m_pop3 != NULL ) return; 112 if ( m_pop3 != NULL ) return;
113 113
114 const char *server, *user, *pass; 114 const char *server, *user, *pass;
115 uint16_t port; 115 uint16_t port;
116 int err = MAILPOP3_NO_ERROR; 116 int err = MAILPOP3_NO_ERROR;
117 117
118 server = account->getServer().latin1(); 118 server = account->getServer().latin1();
119 port = account->getPort().toUInt(); 119 port = account->getPort().toUInt();
120 120
121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
123 login.show(); 123 login.show();
124 if ( QDialog::Accepted == login.exec() ) { 124 if ( QDialog::Accepted == login.exec() ) {
125 // ok 125 // ok
126 user = login.getUser().latin1(); 126 user = login.getUser().latin1();
127 pass = login.getPassword().latin1(); 127 pass = login.getPassword().latin1();
128 } else { 128 } else {
129 // cancel 129 // cancel
130 qDebug( "POP3: Login canceled" ); 130 qDebug( "POP3: Login canceled" );
131 return; 131 return;
132 } 132 }
133 } else { 133 } else {
134 user = account->getUser().latin1(); 134 user = account->getUser().latin1();
135 pass = account->getPassword().latin1(); 135 pass = account->getPassword().latin1();
136 } 136 }
137 137
138 bool ssl = account->getSSL(); 138 bool ssl = account->getSSL();
139 139
140 m_pop3=mailstorage_new(NULL); 140 m_pop3=mailstorage_new(NULL);
141 pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP, 141 pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP,
142 (char*)user,(char*)pass,0,0,0); 142 (char*)user,(char*)pass,0,0,0);
143 143
144 m_folder = mailfolder_new(m_pop3, NULL, NULL); 144 m_folder = mailfolder_new(m_pop3, NULL, NULL);
145 145
146 if (m_folder==0) { 146 if (m_folder==0) {
147 Global::statusMessage(tr("Error initializing folder")); 147 Global::statusMessage(tr("Error initializing folder"));
148 mailstorage_free(m_pop3); 148 mailstorage_free(m_pop3);
149 m_pop3 = NULL; 149 m_pop3 = NULL;
150 return; 150 return;
151 } 151 }
152 err = mailfolder_connect(m_folder); 152 err = mailfolder_connect(m_folder);
153 if (err != MAIL_NO_ERROR) { 153 if (err != MAIL_NO_ERROR) {
154 Global::statusMessage(tr("Error initializing folder")); 154 Global::statusMessage(tr("Error initializing folder"));
155 mailfolder_free(m_folder); 155 mailfolder_free(m_folder);
156 m_folder = 0; 156 m_folder = 0;
157 mailstorage_free(m_pop3); 157 mailstorage_free(m_pop3);
158 m_pop3 = 0; 158 m_pop3 = 0;
159 } 159 }
160 qDebug( "POP3: logged in!" ); 160 qDebug( "POP3: logged in!" );
161} 161}
162 162
163void POP3wrapper::logout() 163void POP3wrapper::logout()
164{ 164{
165 int err = MAILPOP3_NO_ERROR; 165 int err = MAILPOP3_NO_ERROR;
166 if ( m_pop3 == NULL ) return; 166 if ( m_pop3 == NULL ) return;
167 mailfolder_free(m_folder); 167 mailfolder_free(m_folder);
168 m_folder = 0; 168 m_folder = 0;
169 mailstorage_free(m_pop3); 169 mailstorage_free(m_pop3);
170 m_pop3 = 0; 170 m_pop3 = 0;
171} 171}
172 172
173 173
174QList<Folder>* POP3wrapper::listFolders() 174QList<Folder>* POP3wrapper::listFolders()
175{ 175{
176 QList<Folder> * folders = new QList<Folder>(); 176 QList<Folder> * folders = new QList<Folder>();
177 folders->setAutoDelete( false ); 177 folders->setAutoDelete( false );
178 Folder*inb=new Folder("INBOX","/"); 178 Folder*inb=new Folder("INBOX","/");
179 folders->append(inb); 179 folders->append(inb);
180 return folders; 180 return folders;
181} 181}
182 182
183void POP3wrapper::deleteMail(const RecMail&mail) 183void POP3wrapper::deleteMail(const RecMail&mail)
184{ 184{
185 login(); 185 login();
186 if (!m_pop3) return; 186 if (!m_pop3) return;
187 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); 187 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber());
188 if (err != MAIL_NO_ERROR) { 188 if (err != MAIL_NO_ERROR) {
189 Global::statusMessage(tr("error deleting mail")); 189 Global::statusMessage(tr("error deleting mail"));
190 } 190 }
191} 191}
192 192
193void POP3wrapper::answeredMail(const RecMail&) 193void POP3wrapper::answeredMail(const RecMail&)
194{ 194{
195} 195}
196 196
197int POP3wrapper::deleteAllMail(const Folder*) 197int POP3wrapper::deleteAllMail(const Folder*)
198{ 198{
199 login(); 199 login();
200 if (!m_pop3) return 0; 200 if (!m_pop3) return 0;
201 int res = 1; 201 int res = 1;
202 202
203 uint32_t result = 0; 203 uint32_t result = 0;
204 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); 204 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result);
205 if (err != MAIL_NO_ERROR) { 205 if (err != MAIL_NO_ERROR) {
206 Global::statusMessage(tr("Error getting folder info")); 206 Global::statusMessage(tr("Error getting folder info"));
207 return 0; 207 return 0;
208 } 208 }
209 for (unsigned int i = 0; i < result; ++i) { 209 for (unsigned int i = 0; i < result; ++i) {
210 err = mailsession_remove_message(m_folder->fld_session,i+1); 210 err = mailsession_remove_message(m_folder->fld_session,i+1);
211 if (err != MAIL_NO_ERROR) { 211 if (err != MAIL_NO_ERROR) {
212 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 212 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
213 res=0; 213 res=0;
214 } 214 }
215 break; 215 break;
216 } 216 }
217 return res; 217 return res;
218} 218}
219 219
220void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) 220void POP3wrapper::statusFolder(folderStat&target_stat,const QString&)
221{ 221{
222 login(); 222 login();
223 target_stat.message_count = 0; 223 target_stat.message_count = 0;
224 target_stat.message_unseen = 0; 224 target_stat.message_unseen = 0;
225 target_stat.message_recent = 0; 225 target_stat.message_recent = 0;
226 if (!m_pop3) return; 226 if (!m_pop3) return;
227 int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, 227 int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count,
228 &target_stat.message_recent,&target_stat.message_unseen); 228 &target_stat.message_recent,&target_stat.message_unseen);
229} 229}
230 230
231void POP3wrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) 231void POP3wrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length)
232{ 232{
233 mailmessage * mailmsg = 0; 233 mailmessage * mailmsg = 0;
234 int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); 234 int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
235 err = mailmessage_fetch(mailmsg,target,length); 235 err = mailmessage_fetch(mailmsg,target,length);
236 if (mailmsg) mailmessage_free(mailmsg); 236 if (mailmsg) mailmessage_free(mailmsg);
237} 237}
238
239const QString&POP3wrapper::getType()const
240{
241 return account->getType();
242}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 9cba101..b7e8f27 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,41 +1,41 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "genericwrapper.h" 5#include "genericwrapper.h"
6#include <qstring.h> 6#include <qstring.h>
7 7
8struct mailstorage; 8struct mailstorage;
9struct mailfolder; 9struct mailfolder;
10 10
11class POP3wrapper : public Genericwrapper 11class POP3wrapper : public Genericwrapper
12{ 12{
13 Q_OBJECT 13 Q_OBJECT
14 14
15public: 15public:
16 POP3wrapper( POP3account *a ); 16 POP3wrapper( POP3account *a );
17 virtual ~POP3wrapper(); 17 virtual ~POP3wrapper();
18 /* mailbox will be ignored */ 18 /* mailbox will be ignored */
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders(); 20 virtual QList<Folder>* listFolders();
21 /* mailbox will be ignored */ 21 /* mailbox will be ignored */
22 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 22 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
23 23
24 virtual void deleteMail(const RecMail&mail); 24 virtual void deleteMail(const RecMail&mail);
25 virtual void answeredMail(const RecMail&mail); 25 virtual void answeredMail(const RecMail&mail);
26 virtual int deleteAllMail(const Folder*); 26 virtual int deleteAllMail(const Folder*);
27 27
28 virtual RecBody fetchBody( const RecMail &mail ); 28 virtual RecBody fetchBody( const RecMail &mail );
29 virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); 29 virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length);
30 virtual void logout(); 30 virtual void logout();
31 31 virtual const QString&getType()const;
32 static void pop3_progress( size_t current, size_t maximum ); 32 static void pop3_progress( size_t current, size_t maximum );
33 33
34protected: 34protected:
35 void login(); 35 void login();
36 POP3account *account; 36 POP3account *account;
37 mailstorage*m_pop3; 37 mailstorage*m_pop3;
38 mailfolder*m_folder; 38 mailfolder*m_folder;
39}; 39};
40 40
41#endif 41#endif