summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.cpp28
-rw-r--r--noncore/net/mail/abstractmail.h8
-rw-r--r--noncore/net/mail/imapwrapper.cpp78
-rw-r--r--noncore/net/mail/imapwrapper.h12
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp28
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h8
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp78
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h12
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.cpp90
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h47
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp11
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h6
-rw-r--r--noncore/net/mail/mailtypes.cpp90
-rw-r--r--noncore/net/mail/mailtypes.h47
-rw-r--r--noncore/net/mail/pop3wrapper.cpp11
-rw-r--r--noncore/net/mail/pop3wrapper.h6
-rw-r--r--noncore/net/mail/viewmail.cpp13
17 files changed, 477 insertions, 96 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp
index 0bb2525..92a46f1 100644
--- a/noncore/net/mail/abstractmail.cpp
+++ b/noncore/net/mail/abstractmail.cpp
@@ -1,34 +1,48 @@
1#include "abstractmail.h" 1#include "abstractmail.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mailtypes.h"
4 5
5#include <qstring.h> 6#include <qstring.h>
6#include <stdlib.h> 7#include <stdlib.h>
7#include <libetpan/mailmime_content.h> 8#include <libetpan/mailmime_content.h>
8 9
9AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 10AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
10{ 11{
11 return new IMAPwrapper(a); 12 return new IMAPwrapper(a);
12} 13}
13 14
14AbstractMail* AbstractMail::getWrapper(POP3account *a) 15AbstractMail* AbstractMail::getWrapper(POP3account *a)
15{ 16{
16 return new POP3wrapper(a); 17 return new POP3wrapper(a);
17} 18}
18 19
19QString AbstractMail::decode_quoted_printable(const char*text) 20encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
20{ 21{
22 qDebug("Decode string start");
21 char*result_text; 23 char*result_text;
22 size_t index = 0; 24 size_t index = 0;
23 QString result = "";
24 /* reset for recursive use! */ 25 /* reset for recursive use! */
25 size_t target_length = 0; 26 size_t target_length = 0;
26 result_text = 0; 27 result_text = 0;
27 int err = mailmime_quoted_printable_body_parse(text,strlen(text), 28 int mimetype = MAILMIME_MECHANISM_7BIT;
28 &index,&result_text,&target_length,0); 29 if (enc.lower()=="quoted-printable") {
29 if (result_text) { 30 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
30 result = result_text; 31 } else if (enc.lower()=="base64") {
31 free(result_text); 32 mimetype = MAILMIME_MECHANISM_BASE64;
33 } else if (enc.lower()=="8bit") {
34 mimetype = MAILMIME_MECHANISM_8BIT;
35 } else if (enc.lower()=="binary") {
36 mimetype = MAILMIME_MECHANISM_BINARY;
32 } 37 }
38
39 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
40 &result_text,&target_length);
41
42 encodedString* result = new encodedString();
43 if (err == MAILIMF_NO_ERROR) {
44 result->setContent(result_text,target_length);
45 }
46 qDebug("Decode string finished");
33 return result; 47 return result;
34} 48}
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h
index 4473ad2..f1a8468 100644
--- a/noncore/net/mail/abstractmail.h
+++ b/noncore/net/mail/abstractmail.h
@@ -1,31 +1,35 @@
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;
13 14
14class AbstractMail:public QObject 15class AbstractMail:public QObject
15{ 16{
16 Q_OBJECT 17 Q_OBJECT
17public: 18public:
18 AbstractMail(){}; 19 AbstractMail(){};
19 virtual ~AbstractMail(){} 20 virtual ~AbstractMail(){}
20 virtual QList<Folder>* listFolders()=0; 21 virtual QList<Folder>* listFolders()=0;
21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
22 virtual RecBody fetchBody(const RecMail&mail)=0; 23 virtual RecBody fetchBody(const RecMail&mail)=0;
23 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; 24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
27
24 virtual void deleteMail(const RecMail&mail)=0; 28 virtual void deleteMail(const RecMail&mail)=0;
25 virtual void answeredMail(const RecMail&mail)=0; 29 virtual void answeredMail(const RecMail&mail)=0;
26 30
27 static AbstractMail* getWrapper(IMAPaccount *a); 31 static AbstractMail* getWrapper(IMAPaccount *a);
28 static AbstractMail* getWrapper(POP3account *a); 32 static AbstractMail* getWrapper(POP3account *a);
29 static QString decode_quoted_printable(const char*text); 33 static encodedString*decode_String(const encodedString*text,const QString&enc);
30}; 34};
31#endif 35#endif
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index a4e6228..d56d7f9 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -293,26 +293,27 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
293 if (head->env_bcc!=NULL) { 293 if (head->env_bcc!=NULL) {
294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
295 m->setBcc(addresslist); 295 m->setBcc(addresslist);
296 } 296 }
297 if (head->env_reply_to!=NULL) { 297 if (head->env_reply_to!=NULL) {
298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
299 if (addresslist.count()) { 299 if (addresslist.count()) {
300 m->setReplyto(addresslist.first()); 300 m->setReplyto(addresslist.first());
301 } 301 }
302 } 302 }
303 m->setMsgid(QString(head->env_message_id)); 303 m->setMsgid(QString(head->env_message_id));
304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
305 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
306#if 0 305#if 0
306
307 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
307 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 308 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
308 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); 309 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);
309 qDebug(da.toString()); 310 qDebug(da.toString());
310#endif 311#endif
311 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 312 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
312 size = item->att_data.att_static->att_data.att_rfc822_size; 313 size = item->att_data.att_static->att_data.att_rfc822_size;
313 } 314 }
314 } 315 }
315 /* msg is already deleted */ 316 /* msg is already deleted */
316 if (mFlags.testBit(FLAG_DELETED) && m) { 317 if (mFlags.testBit(FLAG_DELETED) && m) {
317 delete m; 318 delete m;
318 m = 0; 319 m = 0;
@@ -382,38 +383,32 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
382void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 383void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
383{ 384{
384 if (!mailDescription) { 385 if (!mailDescription) {
385 return; 386 return;
386 } 387 }
387 QString sub,body_text; 388 QString sub,body_text;
388 RecPart singlePart; 389 RecPart singlePart;
389 QValueList<int> path; 390 QValueList<int> path;
390 fillSinglePart(singlePart,mailDescription); 391 fillSinglePart(singlePart,mailDescription);
391 switch (mailDescription->bd_type) { 392 switch (mailDescription->bd_type) {
392 case MAILIMAP_BODY_TYPE_1PART_MSG: 393 case MAILIMAP_BODY_TYPE_1PART_MSG:
393 path.append(1); 394 path.append(1);
394 body_text = fetchPart(mail,path,true); 395 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
395 if (singlePart.Encoding()=="quoted-printable") {
396 body_text = decode_quoted_printable(body_text.latin1());
397 }
398 target_body.setBodytext(body_text); 396 target_body.setBodytext(body_text);
399 target_body.setDescription(singlePart); 397 target_body.setDescription(singlePart);
400 break; 398 break;
401 case MAILIMAP_BODY_TYPE_1PART_TEXT: 399 case MAILIMAP_BODY_TYPE_1PART_TEXT:
402 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 400 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
403 path.append(1); 401 path.append(1);
404 body_text = fetchPart(mail,path,true); 402 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
405 if (singlePart.Encoding()=="quoted-printable") {
406 body_text = decode_quoted_printable(body_text.latin1());
407 }
408 target_body.setBodytext(body_text); 403 target_body.setBodytext(body_text);
409 target_body.setDescription(singlePart); 404 target_body.setDescription(singlePart);
410 break; 405 break;
411 case MAILIMAP_BODY_TYPE_1PART_BASIC: 406 case MAILIMAP_BODY_TYPE_1PART_BASIC:
412 qDebug("Single attachment"); 407 qDebug("Single attachment");
413 target_body.setBodytext(""); 408 target_body.setBodytext("");
414 target_body.addPart(singlePart); 409 target_body.addPart(singlePart);
415 break; 410 break;
416 default: 411 default:
417 break; 412 break;
418 } 413 }
419 414
@@ -452,43 +447,43 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
452 } 447 }
453 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 448 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
454 from+=">"; 449 from+=">";
455 } 450 }
456 l.append(QString(from)); 451 l.append(QString(from));
457 if (++count > 99) { 452 if (++count > 99) {
458 break; 453 break;
459 } 454 }
460 } 455 }
461 return l; 456 return l;
462} 457}
463 458
464QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 459encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
465{ 460{
466 QString body(""); 461 encodedString*res=new encodedString;
467 const char*mb; 462 const char*mb;
468 int err; 463 int err;
469 mailimap_fetch_type *fetchType; 464 mailimap_fetch_type *fetchType;
470 mailimap_set *set; 465 mailimap_set *set;
471 clistcell*current,*cur; 466 clistcell*current,*cur;
472 467
473 login(); 468 login();
474 if (!m_imap) { 469 if (!m_imap) {
475 return body; 470 return res;
476 } 471 }
477 if (!internal_call) { 472 if (!internal_call) {
478 mb = mail.getMbox().latin1(); 473 mb = mail.getMbox().latin1();
479 err = mailimap_select( m_imap, (char*)mb); 474 err = mailimap_select( m_imap, (char*)mb);
480 if ( err != MAILIMAP_NO_ERROR ) { 475 if ( err != MAILIMAP_NO_ERROR ) {
481 qDebug("error selecting mailbox: %s",m_imap->imap_response); 476 qDebug("error selecting mailbox: %s",m_imap->imap_response);
482 return body; 477 return res;
483 } 478 }
484 } 479 }
485 set = mailimap_set_new_single(mail.getNumber()); 480 set = mailimap_set_new_single(mail.getNumber());
486 clist*id_list=clist_new(); 481 clist*id_list=clist_new();
487 for (unsigned j=0; j < path.count();++j) { 482 for (unsigned j=0; j < path.count();++j) {
488 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 483 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
489 *p_id = path[j]; 484 *p_id = path[j];
490 clist_append(id_list,p_id); 485 clist_append(id_list,p_id);
491 } 486 }
492 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 487 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
493 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 488 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
494 mailimap_section * section = mailimap_section_new(section_spec); 489 mailimap_section * section = mailimap_section_new(section_spec);
@@ -502,44 +497,35 @@ QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,boo
502 mailimap_set_free( set ); 497 mailimap_set_free( set );
503 mailimap_fetch_type_free( fetchType ); 498 mailimap_fetch_type_free( fetchType );
504 499
505 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 500 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
506 mailimap_msg_att * msg_att; 501 mailimap_msg_att * msg_att;
507 msg_att = (mailimap_msg_att*)current->data; 502 msg_att = (mailimap_msg_att*)current->data;
508 mailimap_msg_att_item*msg_att_item; 503 mailimap_msg_att_item*msg_att_item;
509 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 504 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
510 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 505 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
511 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 506 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
512 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 507 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
513 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 508 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
509 /* detach - we take over the content */
514 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 510 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
515 if (text) { 511 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
516 if (enc=="quoted-printable") {
517 body = decode_quoted_printable(text);
518 } else {
519 body = QString(text);
520 }
521 free(text);
522 } else {
523 body = "";
524 }
525 } 512 }
526 } 513 }
527 } 514 }
528
529 } else { 515 } else {
530 qDebug("error fetching text: %s",m_imap->imap_response); 516 qDebug("error fetching text: %s",m_imap->imap_response);
531 } 517 }
532 mailimap_fetch_list_free(result); 518 mailimap_fetch_list_free(result);
533 return body; 519 return res;
534} 520}
535 521
536void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 522void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
537{ 523{
538 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 524 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
539 if (!mailDescription||current_recursion==10) { 525 if (!mailDescription||current_recursion==10) {
540 return; 526 return;
541 } 527 }
542 clistcell*current; 528 clistcell*current;
543 mailimap_body*current_body; 529 mailimap_body*current_body;
544 unsigned int count = 0; 530 unsigned int count = 0;
545 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 531 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
@@ -548,25 +534,25 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
548 current_body = (mailimap_body*)current->data; 534 current_body = (mailimap_body*)current->data;
549 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 535 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
550 QValueList<int>clist = recList; 536 QValueList<int>clist = recList;
551 clist.append(count); 537 clist.append(count);
552 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 538 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
553 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 539 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
554 RecPart currentPart; 540 RecPart currentPart;
555 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 541 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
556 QValueList<int>clist = recList; 542 QValueList<int>clist = recList;
557 clist.append(count); 543 clist.append(count);
558 /* important: Check for is NULL 'cause a body can be empty! */ 544 /* important: Check for is NULL 'cause a body can be empty! */
559 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 545 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
560 QString body_text = fetchPart(mail,clist,true,currentPart.Encoding()); 546 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding());
561 target_body.setDescription(currentPart); 547 target_body.setDescription(currentPart);
562 target_body.setBodytext(body_text); 548 target_body.setBodytext(body_text);
563 } else { 549 } else {
564 QString id(""); 550 QString id("");
565 for (unsigned int j = 0; j < clist.count();++j) { 551 for (unsigned int j = 0; j < clist.count();++j) {
566 id+=(j>0?" ":""); 552 id+=(j>0?" ":"");
567 id+=QString("%1").arg(clist[j]); 553 id+=QString("%1").arg(clist[j]);
568 } 554 }
569 qDebug("ID= %s",id.latin1()); 555 qDebug("ID= %s",id.latin1());
570 currentPart.setIdentifier(id); 556 currentPart.setIdentifier(id);
571 currentPart.setPositionlist(clist); 557 currentPart.setPositionlist(clist);
572 target_body.addPart(currentPart); 558 target_body.addPart(currentPart);
@@ -704,29 +690,24 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
704 encoding=QString(enc->enc_value); 690 encoding=QString(enc->enc_value);
705 enc->enc_value=0L; 691 enc->enc_value=0L;
706 free(t); 692 free(t);
707 } 693 }
708 } 694 }
709 if (which->bd_description) { 695 if (which->bd_description) {
710 target_part.setDescription(QString(which->bd_description)); 696 target_part.setDescription(QString(which->bd_description));
711 } 697 }
712 target_part.setEncoding(encoding); 698 target_part.setEncoding(encoding);
713 target_part.setSize(which->bd_size); 699 target_part.setSize(which->bd_size);
714} 700}
715 701
716QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
717{
718 return fetchPart(mail,part.Positionlist(),false,part.Encoding());
719}
720
721void IMAPwrapper::deleteMail(const RecMail&mail) 702void IMAPwrapper::deleteMail(const RecMail&mail)
722{ 703{
723 mailimap_flag_list*flist; 704 mailimap_flag_list*flist;
724 mailimap_set *set; 705 mailimap_set *set;
725 mailimap_store_att_flags * store_flags; 706 mailimap_store_att_flags * store_flags;
726 int err; 707 int err;
727 login(); 708 login();
728 if (!m_imap) { 709 if (!m_imap) {
729 return; 710 return;
730 } 711 }
731 const char *mb = mail.getMbox().latin1(); 712 const char *mb = mail.getMbox().latin1();
732 err = mailimap_select( m_imap, (char*)mb); 713 err = mailimap_select( m_imap, (char*)mb);
@@ -775,12 +756,45 @@ void IMAPwrapper::answeredMail(const RecMail&mail)
775 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 756 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
776 store_flags = mailimap_store_att_flags_new_add_flags(flist); 757 store_flags = mailimap_store_att_flags_new_add_flags(flist);
777 set = mailimap_set_new_single(mail.getNumber()); 758 set = mailimap_set_new_single(mail.getNumber());
778 err = mailimap_store(m_imap,set,store_flags); 759 err = mailimap_store(m_imap,set,store_flags);
779 mailimap_set_free( set ); 760 mailimap_set_free( set );
780 mailimap_store_att_flags_free(store_flags); 761 mailimap_store_att_flags_free(store_flags);
781 762
782 if (err != MAILIMAP_NO_ERROR) { 763 if (err != MAILIMAP_NO_ERROR) {
783 qDebug("error marking mail: %s",m_imap->imap_response); 764 qDebug("error marking mail: %s",m_imap->imap_response);
784 return; 765 return;
785 } 766 }
786} 767}
768
769QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
770{
771 QString body("");
772 encodedString*res = fetchRawPart(mail,path,internal_call);
773 encodedString*r = decode_String(res,enc);
774 delete res;
775 if (r) {
776 if (r->Length()>0) {
777 body = r->Content();
778 }
779 delete r;
780 }
781 return body;
782}
783
784QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
785{
786 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
787}
788
789encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
790{
791 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
792 encodedString*r = decode_String(res,part.Encoding());
793 delete res;
794 return r;
795}
796
797encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
798{
799 return fetchRawPart(mail,part.Positionlist(),false);
800}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index 768a517..aeebda8 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -4,46 +4,52 @@
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 7
8struct mailimap; 8struct mailimap;
9struct mailimap_body_type_1part; 9struct mailimap_body_type_1part;
10struct mailimap_body_type_text; 10struct mailimap_body_type_text;
11struct mailimap_body_type_basic; 11struct mailimap_body_type_basic;
12struct mailimap_body_type_msg; 12struct mailimap_body_type_msg;
13struct mailimap_body_type_mpart; 13struct mailimap_body_type_mpart;
14struct mailimap_body_fields; 14struct mailimap_body_fields;
15struct mailimap_msg_att; 15struct mailimap_msg_att;
16class encodedString;
16 17
17class IMAPwrapper : public AbstractMail 18class IMAPwrapper : public AbstractMail
18{ 19{
19 Q_OBJECT 20 Q_OBJECT
20public: 21public:
21 IMAPwrapper( IMAPaccount *a ); 22 IMAPwrapper( IMAPaccount *a );
22 virtual ~IMAPwrapper(); 23 virtual ~IMAPwrapper();
23 virtual QList<Folder>* listFolders(); 24 virtual QList<Folder>* listFolders();
24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 25 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
25 virtual RecBody fetchBody(const RecMail&mail); 26
26 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
27 virtual void deleteMail(const RecMail&mail); 27 virtual void deleteMail(const RecMail&mail);
28 virtual void answeredMail(const RecMail&mail); 28 virtual void answeredMail(const RecMail&mail);
29 29
30 virtual RecBody fetchBody(const RecMail&mail);
31 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
32 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
33 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
34
30 static void imap_progress( size_t current, size_t maximum ); 35 static void imap_progress( size_t current, size_t maximum );
31 36
32protected: 37protected:
33 RecMail*parse_list_result(mailimap_msg_att*); 38 RecMail*parse_list_result(mailimap_msg_att*);
34 void login(); 39 void login();
35 void logout(); 40 void logout();
36 41
37 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 42 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
43 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
38 44
39 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 45 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
40 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 46 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
41 47
42 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 48 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
43 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 49 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
44 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 50 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
45 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 51 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
46 52
47 /* just helpers */ 53 /* just helpers */
48 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 54 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
49 static QStringList address_list_to_stringlist(clist*list); 55 static QStringList address_list_to_stringlist(clist*list);
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
index 0bb2525..92a46f1 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.cpp
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -1,34 +1,48 @@
1#include "abstractmail.h" 1#include "abstractmail.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mailtypes.h"
4 5
5#include <qstring.h> 6#include <qstring.h>
6#include <stdlib.h> 7#include <stdlib.h>
7#include <libetpan/mailmime_content.h> 8#include <libetpan/mailmime_content.h>
8 9
9AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 10AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
10{ 11{
11 return new IMAPwrapper(a); 12 return new IMAPwrapper(a);
12} 13}
13 14
14AbstractMail* AbstractMail::getWrapper(POP3account *a) 15AbstractMail* AbstractMail::getWrapper(POP3account *a)
15{ 16{
16 return new POP3wrapper(a); 17 return new POP3wrapper(a);
17} 18}
18 19
19QString AbstractMail::decode_quoted_printable(const char*text) 20encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
20{ 21{
22 qDebug("Decode string start");
21 char*result_text; 23 char*result_text;
22 size_t index = 0; 24 size_t index = 0;
23 QString result = "";
24 /* reset for recursive use! */ 25 /* reset for recursive use! */
25 size_t target_length = 0; 26 size_t target_length = 0;
26 result_text = 0; 27 result_text = 0;
27 int err = mailmime_quoted_printable_body_parse(text,strlen(text), 28 int mimetype = MAILMIME_MECHANISM_7BIT;
28 &index,&result_text,&target_length,0); 29 if (enc.lower()=="quoted-printable") {
29 if (result_text) { 30 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
30 result = result_text; 31 } else if (enc.lower()=="base64") {
31 free(result_text); 32 mimetype = MAILMIME_MECHANISM_BASE64;
33 } else if (enc.lower()=="8bit") {
34 mimetype = MAILMIME_MECHANISM_8BIT;
35 } else if (enc.lower()=="binary") {
36 mimetype = MAILMIME_MECHANISM_BINARY;
32 } 37 }
38
39 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
40 &result_text,&target_length);
41
42 encodedString* result = new encodedString();
43 if (err == MAILIMF_NO_ERROR) {
44 result->setContent(result_text,target_length);
45 }
46 qDebug("Decode string finished");
33 return result; 47 return result;
34} 48}
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index 4473ad2..f1a8468 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -1,31 +1,35 @@
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;
13 14
14class AbstractMail:public QObject 15class AbstractMail:public QObject
15{ 16{
16 Q_OBJECT 17 Q_OBJECT
17public: 18public:
18 AbstractMail(){}; 19 AbstractMail(){};
19 virtual ~AbstractMail(){} 20 virtual ~AbstractMail(){}
20 virtual QList<Folder>* listFolders()=0; 21 virtual QList<Folder>* listFolders()=0;
21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
22 virtual RecBody fetchBody(const RecMail&mail)=0; 23 virtual RecBody fetchBody(const RecMail&mail)=0;
23 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; 24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
27
24 virtual void deleteMail(const RecMail&mail)=0; 28 virtual void deleteMail(const RecMail&mail)=0;
25 virtual void answeredMail(const RecMail&mail)=0; 29 virtual void answeredMail(const RecMail&mail)=0;
26 30
27 static AbstractMail* getWrapper(IMAPaccount *a); 31 static AbstractMail* getWrapper(IMAPaccount *a);
28 static AbstractMail* getWrapper(POP3account *a); 32 static AbstractMail* getWrapper(POP3account *a);
29 static QString decode_quoted_printable(const char*text); 33 static encodedString*decode_String(const encodedString*text,const QString&enc);
30}; 34};
31#endif 35#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index a4e6228..d56d7f9 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -293,26 +293,27 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
293 if (head->env_bcc!=NULL) { 293 if (head->env_bcc!=NULL) {
294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 294 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
295 m->setBcc(addresslist); 295 m->setBcc(addresslist);
296 } 296 }
297 if (head->env_reply_to!=NULL) { 297 if (head->env_reply_to!=NULL) {
298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 298 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
299 if (addresslist.count()) { 299 if (addresslist.count()) {
300 m->setReplyto(addresslist.first()); 300 m->setReplyto(addresslist.first());
301 } 301 }
302 } 302 }
303 m->setMsgid(QString(head->env_message_id)); 303 m->setMsgid(QString(head->env_message_id));
304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 304 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
305 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
306#if 0 305#if 0
306
307 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
307 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 308 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
308 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); 309 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);
309 qDebug(da.toString()); 310 qDebug(da.toString());
310#endif 311#endif
311 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 312 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
312 size = item->att_data.att_static->att_data.att_rfc822_size; 313 size = item->att_data.att_static->att_data.att_rfc822_size;
313 } 314 }
314 } 315 }
315 /* msg is already deleted */ 316 /* msg is already deleted */
316 if (mFlags.testBit(FLAG_DELETED) && m) { 317 if (mFlags.testBit(FLAG_DELETED) && m) {
317 delete m; 318 delete m;
318 m = 0; 319 m = 0;
@@ -382,38 +383,32 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
382void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 383void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
383{ 384{
384 if (!mailDescription) { 385 if (!mailDescription) {
385 return; 386 return;
386 } 387 }
387 QString sub,body_text; 388 QString sub,body_text;
388 RecPart singlePart; 389 RecPart singlePart;
389 QValueList<int> path; 390 QValueList<int> path;
390 fillSinglePart(singlePart,mailDescription); 391 fillSinglePart(singlePart,mailDescription);
391 switch (mailDescription->bd_type) { 392 switch (mailDescription->bd_type) {
392 case MAILIMAP_BODY_TYPE_1PART_MSG: 393 case MAILIMAP_BODY_TYPE_1PART_MSG:
393 path.append(1); 394 path.append(1);
394 body_text = fetchPart(mail,path,true); 395 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
395 if (singlePart.Encoding()=="quoted-printable") {
396 body_text = decode_quoted_printable(body_text.latin1());
397 }
398 target_body.setBodytext(body_text); 396 target_body.setBodytext(body_text);
399 target_body.setDescription(singlePart); 397 target_body.setDescription(singlePart);
400 break; 398 break;
401 case MAILIMAP_BODY_TYPE_1PART_TEXT: 399 case MAILIMAP_BODY_TYPE_1PART_TEXT:
402 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 400 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
403 path.append(1); 401 path.append(1);
404 body_text = fetchPart(mail,path,true); 402 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
405 if (singlePart.Encoding()=="quoted-printable") {
406 body_text = decode_quoted_printable(body_text.latin1());
407 }
408 target_body.setBodytext(body_text); 403 target_body.setBodytext(body_text);
409 target_body.setDescription(singlePart); 404 target_body.setDescription(singlePart);
410 break; 405 break;
411 case MAILIMAP_BODY_TYPE_1PART_BASIC: 406 case MAILIMAP_BODY_TYPE_1PART_BASIC:
412 qDebug("Single attachment"); 407 qDebug("Single attachment");
413 target_body.setBodytext(""); 408 target_body.setBodytext("");
414 target_body.addPart(singlePart); 409 target_body.addPart(singlePart);
415 break; 410 break;
416 default: 411 default:
417 break; 412 break;
418 } 413 }
419 414
@@ -452,43 +447,43 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
452 } 447 }
453 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 448 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
454 from+=">"; 449 from+=">";
455 } 450 }
456 l.append(QString(from)); 451 l.append(QString(from));
457 if (++count > 99) { 452 if (++count > 99) {
458 break; 453 break;
459 } 454 }
460 } 455 }
461 return l; 456 return l;
462} 457}
463 458
464QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 459encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
465{ 460{
466 QString body(""); 461 encodedString*res=new encodedString;
467 const char*mb; 462 const char*mb;
468 int err; 463 int err;
469 mailimap_fetch_type *fetchType; 464 mailimap_fetch_type *fetchType;
470 mailimap_set *set; 465 mailimap_set *set;
471 clistcell*current,*cur; 466 clistcell*current,*cur;
472 467
473 login(); 468 login();
474 if (!m_imap) { 469 if (!m_imap) {
475 return body; 470 return res;
476 } 471 }
477 if (!internal_call) { 472 if (!internal_call) {
478 mb = mail.getMbox().latin1(); 473 mb = mail.getMbox().latin1();
479 err = mailimap_select( m_imap, (char*)mb); 474 err = mailimap_select( m_imap, (char*)mb);
480 if ( err != MAILIMAP_NO_ERROR ) { 475 if ( err != MAILIMAP_NO_ERROR ) {
481 qDebug("error selecting mailbox: %s",m_imap->imap_response); 476 qDebug("error selecting mailbox: %s",m_imap->imap_response);
482 return body; 477 return res;
483 } 478 }
484 } 479 }
485 set = mailimap_set_new_single(mail.getNumber()); 480 set = mailimap_set_new_single(mail.getNumber());
486 clist*id_list=clist_new(); 481 clist*id_list=clist_new();
487 for (unsigned j=0; j < path.count();++j) { 482 for (unsigned j=0; j < path.count();++j) {
488 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 483 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
489 *p_id = path[j]; 484 *p_id = path[j];
490 clist_append(id_list,p_id); 485 clist_append(id_list,p_id);
491 } 486 }
492 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 487 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
493 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 488 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
494 mailimap_section * section = mailimap_section_new(section_spec); 489 mailimap_section * section = mailimap_section_new(section_spec);
@@ -502,44 +497,35 @@ QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,boo
502 mailimap_set_free( set ); 497 mailimap_set_free( set );
503 mailimap_fetch_type_free( fetchType ); 498 mailimap_fetch_type_free( fetchType );
504 499
505 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 500 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
506 mailimap_msg_att * msg_att; 501 mailimap_msg_att * msg_att;
507 msg_att = (mailimap_msg_att*)current->data; 502 msg_att = (mailimap_msg_att*)current->data;
508 mailimap_msg_att_item*msg_att_item; 503 mailimap_msg_att_item*msg_att_item;
509 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 504 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
510 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 505 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
511 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 506 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
512 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 507 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
513 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 508 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
509 /* detach - we take over the content */
514 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 510 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
515 if (text) { 511 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
516 if (enc=="quoted-printable") {
517 body = decode_quoted_printable(text);
518 } else {
519 body = QString(text);
520 }
521 free(text);
522 } else {
523 body = "";
524 }
525 } 512 }
526 } 513 }
527 } 514 }
528
529 } else { 515 } else {
530 qDebug("error fetching text: %s",m_imap->imap_response); 516 qDebug("error fetching text: %s",m_imap->imap_response);
531 } 517 }
532 mailimap_fetch_list_free(result); 518 mailimap_fetch_list_free(result);
533 return body; 519 return res;
534} 520}
535 521
536void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 522void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
537{ 523{
538 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 524 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
539 if (!mailDescription||current_recursion==10) { 525 if (!mailDescription||current_recursion==10) {
540 return; 526 return;
541 } 527 }
542 clistcell*current; 528 clistcell*current;
543 mailimap_body*current_body; 529 mailimap_body*current_body;
544 unsigned int count = 0; 530 unsigned int count = 0;
545 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 531 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
@@ -548,25 +534,25 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
548 current_body = (mailimap_body*)current->data; 534 current_body = (mailimap_body*)current->data;
549 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 535 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
550 QValueList<int>clist = recList; 536 QValueList<int>clist = recList;
551 clist.append(count); 537 clist.append(count);
552 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 538 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
553 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 539 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
554 RecPart currentPart; 540 RecPart currentPart;
555 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 541 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
556 QValueList<int>clist = recList; 542 QValueList<int>clist = recList;
557 clist.append(count); 543 clist.append(count);
558 /* important: Check for is NULL 'cause a body can be empty! */ 544 /* important: Check for is NULL 'cause a body can be empty! */
559 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 545 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
560 QString body_text = fetchPart(mail,clist,true,currentPart.Encoding()); 546 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding());
561 target_body.setDescription(currentPart); 547 target_body.setDescription(currentPart);
562 target_body.setBodytext(body_text); 548 target_body.setBodytext(body_text);
563 } else { 549 } else {
564 QString id(""); 550 QString id("");
565 for (unsigned int j = 0; j < clist.count();++j) { 551 for (unsigned int j = 0; j < clist.count();++j) {
566 id+=(j>0?" ":""); 552 id+=(j>0?" ":"");
567 id+=QString("%1").arg(clist[j]); 553 id+=QString("%1").arg(clist[j]);
568 } 554 }
569 qDebug("ID= %s",id.latin1()); 555 qDebug("ID= %s",id.latin1());
570 currentPart.setIdentifier(id); 556 currentPart.setIdentifier(id);
571 currentPart.setPositionlist(clist); 557 currentPart.setPositionlist(clist);
572 target_body.addPart(currentPart); 558 target_body.addPart(currentPart);
@@ -704,29 +690,24 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
704 encoding=QString(enc->enc_value); 690 encoding=QString(enc->enc_value);
705 enc->enc_value=0L; 691 enc->enc_value=0L;
706 free(t); 692 free(t);
707 } 693 }
708 } 694 }
709 if (which->bd_description) { 695 if (which->bd_description) {
710 target_part.setDescription(QString(which->bd_description)); 696 target_part.setDescription(QString(which->bd_description));
711 } 697 }
712 target_part.setEncoding(encoding); 698 target_part.setEncoding(encoding);
713 target_part.setSize(which->bd_size); 699 target_part.setSize(which->bd_size);
714} 700}
715 701
716QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
717{
718 return fetchPart(mail,part.Positionlist(),false,part.Encoding());
719}
720
721void IMAPwrapper::deleteMail(const RecMail&mail) 702void IMAPwrapper::deleteMail(const RecMail&mail)
722{ 703{
723 mailimap_flag_list*flist; 704 mailimap_flag_list*flist;
724 mailimap_set *set; 705 mailimap_set *set;
725 mailimap_store_att_flags * store_flags; 706 mailimap_store_att_flags * store_flags;
726 int err; 707 int err;
727 login(); 708 login();
728 if (!m_imap) { 709 if (!m_imap) {
729 return; 710 return;
730 } 711 }
731 const char *mb = mail.getMbox().latin1(); 712 const char *mb = mail.getMbox().latin1();
732 err = mailimap_select( m_imap, (char*)mb); 713 err = mailimap_select( m_imap, (char*)mb);
@@ -775,12 +756,45 @@ void IMAPwrapper::answeredMail(const RecMail&mail)
775 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 756 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
776 store_flags = mailimap_store_att_flags_new_add_flags(flist); 757 store_flags = mailimap_store_att_flags_new_add_flags(flist);
777 set = mailimap_set_new_single(mail.getNumber()); 758 set = mailimap_set_new_single(mail.getNumber());
778 err = mailimap_store(m_imap,set,store_flags); 759 err = mailimap_store(m_imap,set,store_flags);
779 mailimap_set_free( set ); 760 mailimap_set_free( set );
780 mailimap_store_att_flags_free(store_flags); 761 mailimap_store_att_flags_free(store_flags);
781 762
782 if (err != MAILIMAP_NO_ERROR) { 763 if (err != MAILIMAP_NO_ERROR) {
783 qDebug("error marking mail: %s",m_imap->imap_response); 764 qDebug("error marking mail: %s",m_imap->imap_response);
784 return; 765 return;
785 } 766 }
786} 767}
768
769QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
770{
771 QString body("");
772 encodedString*res = fetchRawPart(mail,path,internal_call);
773 encodedString*r = decode_String(res,enc);
774 delete res;
775 if (r) {
776 if (r->Length()>0) {
777 body = r->Content();
778 }
779 delete r;
780 }
781 return body;
782}
783
784QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
785{
786 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
787}
788
789encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
790{
791 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
792 encodedString*r = decode_String(res,part.Encoding());
793 delete res;
794 return r;
795}
796
797encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
798{
799 return fetchRawPart(mail,part.Positionlist(),false);
800}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 768a517..aeebda8 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -4,46 +4,52 @@
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 7
8struct mailimap; 8struct mailimap;
9struct mailimap_body_type_1part; 9struct mailimap_body_type_1part;
10struct mailimap_body_type_text; 10struct mailimap_body_type_text;
11struct mailimap_body_type_basic; 11struct mailimap_body_type_basic;
12struct mailimap_body_type_msg; 12struct mailimap_body_type_msg;
13struct mailimap_body_type_mpart; 13struct mailimap_body_type_mpart;
14struct mailimap_body_fields; 14struct mailimap_body_fields;
15struct mailimap_msg_att; 15struct mailimap_msg_att;
16class encodedString;
16 17
17class IMAPwrapper : public AbstractMail 18class IMAPwrapper : public AbstractMail
18{ 19{
19 Q_OBJECT 20 Q_OBJECT
20public: 21public:
21 IMAPwrapper( IMAPaccount *a ); 22 IMAPwrapper( IMAPaccount *a );
22 virtual ~IMAPwrapper(); 23 virtual ~IMAPwrapper();
23 virtual QList<Folder>* listFolders(); 24 virtual QList<Folder>* listFolders();
24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 25 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
25 virtual RecBody fetchBody(const RecMail&mail); 26
26 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
27 virtual void deleteMail(const RecMail&mail); 27 virtual void deleteMail(const RecMail&mail);
28 virtual void answeredMail(const RecMail&mail); 28 virtual void answeredMail(const RecMail&mail);
29 29
30 virtual RecBody fetchBody(const RecMail&mail);
31 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
32 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
33 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
34
30 static void imap_progress( size_t current, size_t maximum ); 35 static void imap_progress( size_t current, size_t maximum );
31 36
32protected: 37protected:
33 RecMail*parse_list_result(mailimap_msg_att*); 38 RecMail*parse_list_result(mailimap_msg_att*);
34 void login(); 39 void login();
35 void logout(); 40 void logout();
36 41
37 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 42 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
43 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
38 44
39 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 45 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
40 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 46 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
41 47
42 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 48 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
43 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 49 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
44 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 50 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
45 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 51 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
46 52
47 /* just helpers */ 53 /* just helpers */
48 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 54 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
49 static QStringList address_list_to_stringlist(clist*list); 55 static QStringList address_list_to_stringlist(clist*list);
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp
index 8d9b247..d8a36e7 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.cpp
+++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp
@@ -1,14 +1,14 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2 2#include <stdlib.h>
3 3
4RecMail::RecMail() 4RecMail::RecMail()
5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) 5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
6{ 6{
7 init(); 7 init();
8} 8}
9 9
10RecMail::RecMail(const RecMail&old) 10RecMail::RecMail(const RecMail&old)
11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) 11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
12{ 12{
13 init(); 13 init();
14 copy_old(old); 14 copy_old(old);
@@ -236,12 +236,100 @@ void RecBody::addPart(const RecPart& part)
236 m_PartsList.append(part); 236 m_PartsList.append(part);
237} 237}
238 238
239void RecBody::setDescription(const RecPart&des) 239void RecBody::setDescription(const RecPart&des)
240{ 240{
241 m_description = des; 241 m_description = des;
242} 242}
243 243
244const RecPart& RecBody::Description()const 244const RecPart& RecBody::Description()const
245{ 245{
246 return m_description; 246 return m_description;
247} 247}
248
249/* handling encoded content */
250encodedString::encodedString()
251{
252 init();
253}
254
255encodedString::encodedString(const char*nContent,unsigned int nSize)
256{
257 init();
258 setContent(nContent,nSize);
259}
260
261encodedString::encodedString(char*nContent,unsigned int nSize)
262{
263 init();
264 setContent(nContent,nSize);
265}
266
267encodedString::encodedString(const encodedString&old)
268{
269 init();
270 copy_old(old);
271 qDebug("encodedeString: copy constructor!");
272}
273
274encodedString& encodedString::operator=(const encodedString&old)
275{
276 init();
277 copy_old(old);
278 qDebug("encodedString: assign operator!");
279 return *this;
280}
281
282encodedString::~encodedString()
283{
284 clean();
285}
286
287void encodedString::init()
288{
289 content = 0;
290 size = 0;
291}
292
293void encodedString::clean()
294{
295 if (content) {
296 free(content);
297 }
298 content = 0;
299 size = 0;
300}
301
302void encodedString::copy_old(const encodedString&old)
303{
304 clean();
305 if (old.size>0 && old.content) {
306 content = (char*)malloc(old.size*sizeof(char));
307 memcpy(content,old.content,size);
308 size = old.size;
309 }
310}
311
312const char*encodedString::Content()const
313{
314 return content;
315}
316
317const int encodedString::Length()const
318{
319 return size;
320}
321
322void encodedString::setContent(const char*nContent,int nSize)
323{
324 if (nSize>0 && nContent) {
325 content = (char*)malloc(nSize*sizeof(char));
326 memcpy(content,nContent,nSize);
327 size = nSize;
328 }
329}
330
331void encodedString::setContent(char*nContent,int nSize)
332{
333 content = nContent;
334 size = nSize;
335}
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
index 7d7bebc..abfbe65 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.h
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -126,13 +126,60 @@ public:
126 virtual ~RecBody(); 126 virtual ~RecBody();
127 void setBodytext(const QString&); 127 void setBodytext(const QString&);
128 const QString& Bodytext()const; 128 const QString& Bodytext()const;
129 129
130 void setDescription(const RecPart&des); 130 void setDescription(const RecPart&des);
131 const RecPart& Description()const; 131 const RecPart& Description()const;
132 132
133 void setParts(const QValueList<RecPart>&parts); 133 void setParts(const QValueList<RecPart>&parts);
134 const QValueList<RecPart>& Parts()const; 134 const QValueList<RecPart>& Parts()const;
135 void addPart(const RecPart&part); 135 void addPart(const RecPart&part);
136}; 136};
137 137
138class encodedString
139{
140public:
141 encodedString();
142 /*
143 creates an new content string.
144 it makes a deep copy of it!
145 */
146 encodedString(const char*nContent,unsigned int length);
147 /*
148 Take over the nContent. Means: it will just copy the pointer, not the content.
149 so make sure: No one else frees the string, the string has allocated with
150 malloc for compatibility with c-based libs
151 */
152 encodedString(char*nContent,unsigned int nSize);
153 /* copy construkor - makes ALWAYS a deep copy!!!! */
154 encodedString(const encodedString&old);
155 /* assign operator - makes ALWAYS a deep copy!!!! */
156 encodedString& operator=(const encodedString&old);
157 /* destructor - cleans the content */
158 virtual ~encodedString();
159
160 /* returns a pointer to the content - do not delete yoursel! */
161 const char*Content()const;
162 /* returns the lengths of the content 'cause it must not be a null-terminated string! */
163 const int Length()const;
164
165 /*
166 makes a deep copy of nContent!
167 */
168 void setContent(const char*nContent,int nSize);
169 /*
170 Take over the nContent. Means: it will just copy the pointer, not the content.
171 so make sure: No one else frees the string, the string has allocated with
172 malloc for compatibility with c-based libs
173 */
174 void setContent(char*nContent,int nSize);
175
176protected:
177 char * content;
178 unsigned int size;
179
180 void init();
181 void copy_old(const encodedString&old);
182 void clean();
183};
184
138#endif 185#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index a33a16b..075d8c7 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -319,31 +319,40 @@ void POP3wrapper::logout()
319QList<Folder>* POP3wrapper::listFolders() 319QList<Folder>* POP3wrapper::listFolders()
320{ 320{
321 /* TODO: integrate MH directories 321 /* TODO: integrate MH directories
322 but not before version 0.1 ;) 322 but not before version 0.1 ;)
323 */ 323 */
324 QList<Folder> * folders = new QList<Folder>(); 324 QList<Folder> * folders = new QList<Folder>();
325 folders->setAutoDelete( false ); 325 folders->setAutoDelete( false );
326 Folder*inb=new Folder("INBOX"); 326 Folder*inb=new Folder("INBOX");
327 folders->append(inb); 327 folders->append(inb);
328 return folders; 328 return folders;
329} 329}
330 330
331QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) 331QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
332{ 332{
333 return ""; 333 return "";
334} 334}
335 335
336void POP3wrapper::deleteMail(const RecMail&mail) 336void POP3wrapper::deleteMail(const RecMail&mail)
337{ 337{
338 login(); 338 login();
339 if (!m_pop3) return; 339 if (!m_pop3) return;
340 int err = mailpop3_dele(m_pop3,mail.getNumber()); 340 int err = mailpop3_dele(m_pop3,mail.getNumber());
341 if (err != MAILPOP3_NO_ERROR) { 341 if (err != MAILPOP3_NO_ERROR) {
342 qDebug("error deleting mail"); 342 qDebug("error deleting mail");
343 } 343 }
344} 344}
345 345
346void POP3wrapper::answeredMail(const RecMail&) 346void POP3wrapper::answeredMail(const RecMail&)
347{ 347{
348} 348}
349 349
350encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&)
351{
352 return new encodedString();
353}
354
355encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&)
356{
357 return new encodedString();
358}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 6ff8d62..8d3adda 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,33 +1,37 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "abstractmail.h" 5#include "abstractmail.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class encodedString;
9struct mailpop3; 10struct mailpop3;
10 11
11class POP3wrapper : public AbstractMail 12class POP3wrapper : public AbstractMail
12{ 13{
13 Q_OBJECT 14 Q_OBJECT
14 15
15public: 16public:
16 POP3wrapper( POP3account *a ); 17 POP3wrapper( POP3account *a );
17 virtual ~POP3wrapper(); 18 virtual ~POP3wrapper();
18 /* mailbox will be ignored */ 19 /* mailbox will be ignored */
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 20 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders(); 21 virtual QList<Folder>* listFolders();
21 virtual QString fetchPart(const RecMail&mail,const RecPart&part); 22 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
23 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
24 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
25
22 virtual void deleteMail(const RecMail&mail); 26 virtual void deleteMail(const RecMail&mail);
23 virtual void answeredMail(const RecMail&mail); 27 virtual void answeredMail(const RecMail&mail);
24 28
25 RecBody fetchBody( const RecMail &mail ); 29 RecBody fetchBody( const RecMail &mail );
26 static void pop3_progress( size_t current, size_t maximum ); 30 static void pop3_progress( size_t current, size_t maximum );
27 31
28protected: 32protected:
29 void login(); 33 void login();
30 void logout(); 34 void logout();
31 35
32private: 36private:
33 RecMail *parseHeader( const char *header ); 37 RecMail *parseHeader( const char *header );
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp
index 8d9b247..d8a36e7 100644
--- a/noncore/net/mail/mailtypes.cpp
+++ b/noncore/net/mail/mailtypes.cpp
@@ -1,14 +1,14 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2 2#include <stdlib.h>
3 3
4RecMail::RecMail() 4RecMail::RecMail()
5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) 5 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
6{ 6{
7 init(); 7 init();
8} 8}
9 9
10RecMail::RecMail(const RecMail&old) 10RecMail::RecMail(const RecMail&old)
11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) 11 :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
12{ 12{
13 init(); 13 init();
14 copy_old(old); 14 copy_old(old);
@@ -236,12 +236,100 @@ void RecBody::addPart(const RecPart& part)
236 m_PartsList.append(part); 236 m_PartsList.append(part);
237} 237}
238 238
239void RecBody::setDescription(const RecPart&des) 239void RecBody::setDescription(const RecPart&des)
240{ 240{
241 m_description = des; 241 m_description = des;
242} 242}
243 243
244const RecPart& RecBody::Description()const 244const RecPart& RecBody::Description()const
245{ 245{
246 return m_description; 246 return m_description;
247} 247}
248
249/* handling encoded content */
250encodedString::encodedString()
251{
252 init();
253}
254
255encodedString::encodedString(const char*nContent,unsigned int nSize)
256{
257 init();
258 setContent(nContent,nSize);
259}
260
261encodedString::encodedString(char*nContent,unsigned int nSize)
262{
263 init();
264 setContent(nContent,nSize);
265}
266
267encodedString::encodedString(const encodedString&old)
268{
269 init();
270 copy_old(old);
271 qDebug("encodedeString: copy constructor!");
272}
273
274encodedString& encodedString::operator=(const encodedString&old)
275{
276 init();
277 copy_old(old);
278 qDebug("encodedString: assign operator!");
279 return *this;
280}
281
282encodedString::~encodedString()
283{
284 clean();
285}
286
287void encodedString::init()
288{
289 content = 0;
290 size = 0;
291}
292
293void encodedString::clean()
294{
295 if (content) {
296 free(content);
297 }
298 content = 0;
299 size = 0;
300}
301
302void encodedString::copy_old(const encodedString&old)
303{
304 clean();
305 if (old.size>0 && old.content) {
306 content = (char*)malloc(old.size*sizeof(char));
307 memcpy(content,old.content,size);
308 size = old.size;
309 }
310}
311
312const char*encodedString::Content()const
313{
314 return content;
315}
316
317const int encodedString::Length()const
318{
319 return size;
320}
321
322void encodedString::setContent(const char*nContent,int nSize)
323{
324 if (nSize>0 && nContent) {
325 content = (char*)malloc(nSize*sizeof(char));
326 memcpy(content,nContent,nSize);
327 size = nSize;
328 }
329}
330
331void encodedString::setContent(char*nContent,int nSize)
332{
333 content = nContent;
334 size = nSize;
335}
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h
index 7d7bebc..abfbe65 100644
--- a/noncore/net/mail/mailtypes.h
+++ b/noncore/net/mail/mailtypes.h
@@ -126,13 +126,60 @@ public:
126 virtual ~RecBody(); 126 virtual ~RecBody();
127 void setBodytext(const QString&); 127 void setBodytext(const QString&);
128 const QString& Bodytext()const; 128 const QString& Bodytext()const;
129 129
130 void setDescription(const RecPart&des); 130 void setDescription(const RecPart&des);
131 const RecPart& Description()const; 131 const RecPart& Description()const;
132 132
133 void setParts(const QValueList<RecPart>&parts); 133 void setParts(const QValueList<RecPart>&parts);
134 const QValueList<RecPart>& Parts()const; 134 const QValueList<RecPart>& Parts()const;
135 void addPart(const RecPart&part); 135 void addPart(const RecPart&part);
136}; 136};
137 137
138class encodedString
139{
140public:
141 encodedString();
142 /*
143 creates an new content string.
144 it makes a deep copy of it!
145 */
146 encodedString(const char*nContent,unsigned int length);
147 /*
148 Take over the nContent. Means: it will just copy the pointer, not the content.
149 so make sure: No one else frees the string, the string has allocated with
150 malloc for compatibility with c-based libs
151 */
152 encodedString(char*nContent,unsigned int nSize);
153 /* copy construkor - makes ALWAYS a deep copy!!!! */
154 encodedString(const encodedString&old);
155 /* assign operator - makes ALWAYS a deep copy!!!! */
156 encodedString& operator=(const encodedString&old);
157 /* destructor - cleans the content */
158 virtual ~encodedString();
159
160 /* returns a pointer to the content - do not delete yoursel! */
161 const char*Content()const;
162 /* returns the lengths of the content 'cause it must not be a null-terminated string! */
163 const int Length()const;
164
165 /*
166 makes a deep copy of nContent!
167 */
168 void setContent(const char*nContent,int nSize);
169 /*
170 Take over the nContent. Means: it will just copy the pointer, not the content.
171 so make sure: No one else frees the string, the string has allocated with
172 malloc for compatibility with c-based libs
173 */
174 void setContent(char*nContent,int nSize);
175
176protected:
177 char * content;
178 unsigned int size;
179
180 void init();
181 void copy_old(const encodedString&old);
182 void clean();
183};
184
138#endif 185#endif
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index a33a16b..075d8c7 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -319,31 +319,40 @@ void POP3wrapper::logout()
319QList<Folder>* POP3wrapper::listFolders() 319QList<Folder>* POP3wrapper::listFolders()
320{ 320{
321 /* TODO: integrate MH directories 321 /* TODO: integrate MH directories
322 but not before version 0.1 ;) 322 but not before version 0.1 ;)
323 */ 323 */
324 QList<Folder> * folders = new QList<Folder>(); 324 QList<Folder> * folders = new QList<Folder>();
325 folders->setAutoDelete( false ); 325 folders->setAutoDelete( false );
326 Folder*inb=new Folder("INBOX"); 326 Folder*inb=new Folder("INBOX");
327 folders->append(inb); 327 folders->append(inb);
328 return folders; 328 return folders;
329} 329}
330 330
331QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) 331QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
332{ 332{
333 return ""; 333 return "";
334} 334}
335 335
336void POP3wrapper::deleteMail(const RecMail&mail) 336void POP3wrapper::deleteMail(const RecMail&mail)
337{ 337{
338 login(); 338 login();
339 if (!m_pop3) return; 339 if (!m_pop3) return;
340 int err = mailpop3_dele(m_pop3,mail.getNumber()); 340 int err = mailpop3_dele(m_pop3,mail.getNumber());
341 if (err != MAILPOP3_NO_ERROR) { 341 if (err != MAILPOP3_NO_ERROR) {
342 qDebug("error deleting mail"); 342 qDebug("error deleting mail");
343 } 343 }
344} 344}
345 345
346void POP3wrapper::answeredMail(const RecMail&) 346void POP3wrapper::answeredMail(const RecMail&)
347{ 347{
348} 348}
349 349
350encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&)
351{
352 return new encodedString();
353}
354
355encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&)
356{
357 return new encodedString();
358}
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
index 6ff8d62..8d3adda 100644
--- a/noncore/net/mail/pop3wrapper.h
+++ b/noncore/net/mail/pop3wrapper.h
@@ -1,33 +1,37 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "abstractmail.h" 5#include "abstractmail.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class encodedString;
9struct mailpop3; 10struct mailpop3;
10 11
11class POP3wrapper : public AbstractMail 12class POP3wrapper : public AbstractMail
12{ 13{
13 Q_OBJECT 14 Q_OBJECT
14 15
15public: 16public:
16 POP3wrapper( POP3account *a ); 17 POP3wrapper( POP3account *a );
17 virtual ~POP3wrapper(); 18 virtual ~POP3wrapper();
18 /* mailbox will be ignored */ 19 /* mailbox will be ignored */
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 20 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders(); 21 virtual QList<Folder>* listFolders();
21 virtual QString fetchPart(const RecMail&mail,const RecPart&part); 22 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
23 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
24 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
25
22 virtual void deleteMail(const RecMail&mail); 26 virtual void deleteMail(const RecMail&mail);
23 virtual void answeredMail(const RecMail&mail); 27 virtual void answeredMail(const RecMail&mail);
24 28
25 RecBody fetchBody( const RecMail &mail ); 29 RecBody fetchBody( const RecMail &mail );
26 static void pop3_progress( size_t current, size_t maximum ); 30 static void pop3_progress( size_t current, size_t maximum );
27 31
28protected: 32protected:
29 void login(); 33 void login();
30 void logout(); 34 void logout();
31 35
32private: 36private:
33 RecMail *parseHeader( const char *header ); 37 RecMail *parseHeader( const char *header );
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
index 48b71eb..0947879 100644
--- a/noncore/net/mail/viewmail.cpp
+++ b/noncore/net/mail/viewmail.cpp
@@ -1,26 +1,28 @@
1#include <qtextbrowser.h> 1#include <qtextbrowser.h>
2#include <qmessagebox.h> 2#include <qmessagebox.h>
3#include <qtextstream.h> 3#include <qtextstream.h>
4#include <qaction.h> 4#include <qaction.h>
5#include <qpopupmenu.h> 5#include <qpopupmenu.h>
6#include <qfile.h>
6#include <qapplication.h> 7#include <qapplication.h>
7 8
8#include <opie/ofiledialog.h> 9#include <opie/ofiledialog.h>
9 10
10#include "settings.h" 11#include "settings.h"
11#include "composemail.h" 12#include "composemail.h"
12#include "viewmail.h" 13#include "viewmail.h"
13#include "abstractmail.h" 14#include "abstractmail.h"
14#include "accountview.h" 15#include "accountview.h"
16#include "mailtypes.h"
15 17
16AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file, 18AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
17 const QString&fsize,int num) 19 const QString&fsize,int num)
18 : QListViewItem(parent,after),_partNum(num) 20 : QListViewItem(parent,after),_partNum(num)
19{ 21{
20 setText(0, mime); 22 setText(0, mime);
21 setText(1, desc); 23 setText(1, desc);
22 setText(2, file); 24 setText(2, file);
23 setText(3, fsize); 25 setText(3, fsize);
24} 26}
25 27
26void ViewMail::setBody( RecBody body ) { 28void ViewMail::setBody( RecBody body ) {
@@ -125,35 +127,42 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int
125 menu->insertSeparator(1); 127 menu->insertSeparator(1);
126 128
127 ret = menu->exec( point, 0 ); 129 ret = menu->exec( point, 0 );
128 130
129 switch(ret) { 131 switch(ret) {
130 case 0: 132 case 0:
131 { MimeTypes types; 133 { MimeTypes types;
132 types.insert( "all", "*" ); 134 types.insert( "all", "*" );
133 QString str = OFileDialog::getSaveFileName( 1, 135 QString str = OFileDialog::getSaveFileName( 1,
134 "/", item->text( 2 ) , types, 0 ); 136 "/", item->text( 2 ) , types, 0 );
135 137
136 if( !str.isEmpty() ) { 138 if( !str.isEmpty() ) {
137 qDebug( "first we will need a MIME wrapper" ); 139 encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
140 if (content) {
141 QFile output(str);
142 output.open(IO_WriteOnly);
143 output.writeBlock(content->Content(),content->Length());
144 output.close();
145 delete content;
146 }
138 } 147 }
139 } 148 }
140 break ; 149 break ;
141 150
142 case 1: 151 case 1:
143 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { 152 if ( ( ( AttachItem* )item )->Partnumber() == -1 ) {
144 setText(); 153 setText();
145 } else { 154 } else {
146 if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions 155 if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions
147 browser->setText( m_recMail.Wrapper()->fetchPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) ); 156 browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) );
148 } 157 }
149 } 158 }
150 break; 159 break;
151 } 160 }
152 delete menu; 161 delete menu;
153} 162}
154 163
155 164
156void ViewMail::setMail( RecMail mail ) { 165void ViewMail::setMail( RecMail mail ) {
157 166
158m_recMail = mail; 167m_recMail = mail;
159 168