author | alwin <alwin> | 2004-01-03 18:39:24 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-03 18:39:24 (UTC) |
commit | 8dd96feb25472a8c4f8e6b3f9b0553f83c6e3000 (patch) (unidiff) | |
tree | f4f6b9eee00e1b687bfb90bd58949319cf46ec88 | |
parent | 27b84ed363fd7fc52092e3c2d1e49dca079b7ffd (diff) | |
download | opie-8dd96feb25472a8c4f8e6b3f9b0553f83c6e3000.zip opie-8dd96feb25472a8c4f8e6b3f9b0553f83c6e3000.tar.gz opie-8dd96feb25472a8c4f8e6b3f9b0553f83c6e3000.tar.bz2 |
status methods for mailfolder implemented
-rw-r--r-- | noncore/net/mail/abstractmail.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/abstractmail.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 40 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 40 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailtypes.h | 7 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 21 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 11 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/mailtypes.h | 7 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.cpp | 21 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 11 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 2 |
18 files changed, 180 insertions, 2 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp index 416795b..f303d72 100644 --- a/noncore/net/mail/abstractmail.cpp +++ b/noncore/net/mail/abstractmail.cpp | |||
@@ -1,90 +1,94 @@ | |||
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 "mboxwrapper.h" | 4 | #include "mboxwrapper.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | 6 | ||
7 | #include <qstring.h> | 7 | #include <qstring.h> |
8 | #include <qfile.h> | 8 | #include <qfile.h> |
9 | #include <qtextstream.h> | 9 | #include <qtextstream.h> |
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
11 | #include <libetpan/mailmime_content.h> | 11 | #include <libetpan/mailmime_content.h> |
12 | #include <libetpan/mailmime.h> | 12 | #include <libetpan/mailmime.h> |
13 | 13 | ||
14 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 14 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
15 | { | 15 | { |
16 | return new IMAPwrapper(a); | 16 | return new IMAPwrapper(a); |
17 | } | 17 | } |
18 | 18 | ||
19 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 19 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
20 | { | 20 | { |
21 | return new POP3wrapper(a); | 21 | return new POP3wrapper(a); |
22 | } | 22 | } |
23 | 23 | ||
24 | AbstractMail* AbstractMail::getWrapper(const QString&a) | 24 | AbstractMail* AbstractMail::getWrapper(const QString&a) |
25 | { | 25 | { |
26 | return new MBOXwrapper(a); | 26 | return new MBOXwrapper(a); |
27 | } | 27 | } |
28 | 28 | ||
29 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) | 29 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
30 | { | 30 | { |
31 | qDebug("Decode string start"); | 31 | qDebug("Decode string start"); |
32 | char*result_text; | 32 | char*result_text; |
33 | size_t index = 0; | 33 | size_t index = 0; |
34 | /* reset for recursive use! */ | 34 | /* reset for recursive use! */ |
35 | size_t target_length = 0; | 35 | size_t target_length = 0; |
36 | result_text = 0; | 36 | result_text = 0; |
37 | int mimetype = MAILMIME_MECHANISM_7BIT; | 37 | int mimetype = MAILMIME_MECHANISM_7BIT; |
38 | if (enc.lower()=="quoted-printable") { | 38 | if (enc.lower()=="quoted-printable") { |
39 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 39 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
40 | } else if (enc.lower()=="base64") { | 40 | } else if (enc.lower()=="base64") { |
41 | mimetype = MAILMIME_MECHANISM_BASE64; | 41 | mimetype = MAILMIME_MECHANISM_BASE64; |
42 | } else if (enc.lower()=="8bit") { | 42 | } else if (enc.lower()=="8bit") { |
43 | mimetype = MAILMIME_MECHANISM_8BIT; | 43 | mimetype = MAILMIME_MECHANISM_8BIT; |
44 | } else if (enc.lower()=="binary") { | 44 | } else if (enc.lower()=="binary") { |
45 | mimetype = MAILMIME_MECHANISM_BINARY; | 45 | mimetype = MAILMIME_MECHANISM_BINARY; |
46 | } | 46 | } |
47 | 47 | ||
48 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | 48 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, |
49 | &result_text,&target_length); | 49 | &result_text,&target_length); |
50 | 50 | ||
51 | encodedString* result = new encodedString(); | 51 | encodedString* result = new encodedString(); |
52 | if (err == MAILIMF_NO_ERROR) { | 52 | if (err == MAILIMF_NO_ERROR) { |
53 | result->setContent(result_text,target_length); | 53 | result->setContent(result_text,target_length); |
54 | } | 54 | } |
55 | qDebug("Decode string finished"); | 55 | qDebug("Decode string finished"); |
56 | return result; | 56 | return result; |
57 | } | 57 | } |
58 | 58 | ||
59 | QString AbstractMail::convert_String(const char*text) | 59 | QString AbstractMail::convert_String(const char*text) |
60 | { | 60 | { |
61 | size_t index = 0; | 61 | size_t index = 0; |
62 | char*res = 0; | 62 | char*res = 0; |
63 | 63 | ||
64 | /* attention - doesn't work with arm systems! */ | 64 | /* attention - doesn't work with arm systems! */ |
65 | int err = mailmime_encoded_phrase_parse("iso-8859-1", | 65 | int err = mailmime_encoded_phrase_parse("iso-8859-1", |
66 | text, strlen(text),&index, "iso-8859-1",&res); | 66 | text, strlen(text),&index, "iso-8859-1",&res); |
67 | if (err != MAILIMF_NO_ERROR) { | 67 | if (err != MAILIMF_NO_ERROR) { |
68 | if (res) free(res); | 68 | if (res) free(res); |
69 | return QString(text); | 69 | return QString(text); |
70 | } | 70 | } |
71 | if (res) { | 71 | if (res) { |
72 | QString result(res); | 72 | QString result(res); |
73 | free(res); | 73 | free(res); |
74 | return result; | 74 | return result; |
75 | } | 75 | } |
76 | return QString(text); | 76 | return QString(text); |
77 | } | 77 | } |
78 | 78 | ||
79 | /* cp & paste from launcher */ | 79 | /* cp & paste from launcher */ |
80 | QString AbstractMail::gen_attachment_id() | 80 | QString AbstractMail::gen_attachment_id() |
81 | { | 81 | { |
82 | QFile file( "/proc/sys/kernel/random/uuid" ); | 82 | QFile file( "/proc/sys/kernel/random/uuid" ); |
83 | if (!file.open(IO_ReadOnly ) ) | 83 | if (!file.open(IO_ReadOnly ) ) |
84 | return QString::null; | 84 | return QString::null; |
85 | 85 | ||
86 | QTextStream stream(&file); | 86 | QTextStream stream(&file); |
87 | 87 | ||
88 | return "{" + stream.read().stripWhiteSpace() + "}"; | 88 | return "{" + stream.read().stripWhiteSpace() + "}"; |
89 | } | 89 | } |
90 | 90 | ||
91 | int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool) | ||
92 | { | ||
93 | return 0; | ||
94 | } | ||
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h index 5dc4cab..dab9e10 100644 --- a/noncore/net/mail/abstractmail.h +++ b/noncore/net/mail/abstractmail.h | |||
@@ -1,51 +1,53 @@ | |||
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 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class RecPart; | 9 | class RecPart; |
10 | class IMAPwrapper; | 10 | class IMAPwrapper; |
11 | class POP3wrapper; | 11 | class POP3wrapper; |
12 | class Folder; | 12 | class Folder; |
13 | class encodedString; | 13 | class encodedString; |
14 | struct folderStat; | ||
14 | 15 | ||
15 | class AbstractMail:public QObject | 16 | class AbstractMail:public QObject |
16 | { | 17 | { |
17 | Q_OBJECT | 18 | Q_OBJECT |
18 | public: | 19 | public: |
19 | AbstractMail(){}; | 20 | AbstractMail(){}; |
20 | virtual ~AbstractMail(){} | 21 | virtual ~AbstractMail(){} |
21 | virtual QList<Folder>* listFolders()=0; | 22 | virtual QList<Folder>* listFolders()=0; |
22 | 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; | ||
23 | virtual RecBody fetchBody(const RecMail&mail)=0; | 25 | virtual RecBody fetchBody(const RecMail&mail)=0; |
24 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; | 26 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; |
25 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; | 27 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; |
26 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; | 28 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; |
27 | 29 | ||
28 | virtual void deleteMail(const RecMail&mail)=0; | 30 | virtual void deleteMail(const RecMail&mail)=0; |
29 | virtual void answeredMail(const RecMail&mail)=0; | 31 | virtual void answeredMail(const RecMail&mail)=0; |
30 | virtual void cleanMimeCache(){}; | 32 | virtual void cleanMimeCache(){}; |
31 | virtual int deleteAllMail(const Folder*){return 1;} | 33 | virtual int deleteAllMail(const Folder*){return 1;} |
32 | virtual int deleteMbox(const Folder*){return 1;} | 34 | virtual int deleteMbox(const Folder*){return 1;} |
33 | 35 | ||
34 | /* mail box methods */ | 36 | /* mail box methods */ |
35 | /* parameter is the box to create. | 37 | /* parameter is the box to create. |
36 | * if the implementing subclass has prefixes, | 38 | * if the implementing subclass has prefixes, |
37 | * them has to be appended automatic. | 39 | * them has to be appended automatic. |
38 | */ | 40 | */ |
39 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;} | 41 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); |
40 | 42 | ||
41 | static AbstractMail* getWrapper(IMAPaccount *a); | 43 | static AbstractMail* getWrapper(IMAPaccount *a); |
42 | static AbstractMail* getWrapper(POP3account *a); | 44 | static AbstractMail* getWrapper(POP3account *a); |
43 | /* mbox only! */ | 45 | /* mbox only! */ |
44 | static AbstractMail* getWrapper(const QString&a); | 46 | static AbstractMail* getWrapper(const QString&a); |
45 | 47 | ||
46 | protected: | 48 | protected: |
47 | static encodedString*decode_String(const encodedString*text,const QString&enc); | 49 | static encodedString*decode_String(const encodedString*text,const QString&enc); |
48 | static QString convert_String(const char*text); | 50 | static QString convert_String(const char*text); |
49 | static QString gen_attachment_id(); | 51 | static QString gen_attachment_id(); |
50 | }; | 52 | }; |
51 | #endif | 53 | #endif |
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index b437df0..f1d42c2 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -553,384 +553,424 @@ void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&tar | |||
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 | ||
601 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 601 | void 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 | ||
623 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 623 | void 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 | ||
636 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 636 | void 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 | ||
648 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) | 648 | void 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 | ||
665 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 665 | void 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 | ||
707 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 707 | void 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 | ||
754 | void IMAPwrapper::deleteMail(const RecMail&mail) | 754 | void 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 | ||
791 | void IMAPwrapper::answeredMail(const RecMail&mail) | 791 | void 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 | ||
821 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 821 | QString 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 | ||
836 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 836 | QString 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 | ||
841 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | 841 | encodedString* 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 | ||
849 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 849 | encodedString* 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 | ||
854 | int IMAPwrapper::deleteAllMail(const Folder*folder) | 854 | int 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 | ||
895 | int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) | 895 | int 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 | ||
925 | int IMAPwrapper::deleteMbox(const Folder*folder) | 925 | int 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 | |||
938 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | ||
939 | { | ||
940 | mailimap_status_att_list * att_list =0; | ||
941 | mailimap_mailbox_data_status * status=0; | ||
942 | clistiter * cur = 0; | ||
943 | int r = 0; | ||
944 | int res = 0; | ||
945 | target_stat.message_count = 0; | ||
946 | target_stat.message_unseen = 0; | ||
947 | target_stat.message_recent = 0; | ||
948 | login(); | ||
949 | if (!m_imap) { | ||
950 | return; | ||
951 | } | ||
952 | att_list = mailimap_status_att_list_new_empty(); | ||
953 | if (!att_list) return; | ||
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); | ||
956 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); | ||
957 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); | ||
958 | for (cur = clist_begin(status->st_info_list); | ||
959 | cur != NULL ; cur = clist_next(cur)) { | ||
960 | mailimap_status_info * status_info; | ||
961 | status_info = (mailimap_status_info *)clist_content(cur); | ||
962 | switch (status_info->st_att) { | ||
963 | case MAILIMAP_STATUS_ATT_MESSAGES: | ||
964 | target_stat.message_count = status_info->st_value; | ||
965 | break; | ||
966 | case MAILIMAP_STATUS_ATT_RECENT: | ||
967 | target_stat.message_recent = status_info->st_value; | ||
968 | break; | ||
969 | case MAILIMAP_STATUS_ATT_UNSEEN: | ||
970 | target_stat.message_unseen = status_info->st_value; | ||
971 | break; | ||
972 | } | ||
973 | } | ||
974 | mailimap_mailbox_data_status_free(status); | ||
975 | mailimap_status_att_list_free(att_list); | ||
976 | } | ||
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h index 7941046..8f5a2b5 100644 --- a/noncore/net/mail/imapwrapper.h +++ b/noncore/net/mail/imapwrapper.h | |||
@@ -1,67 +1,68 @@ | |||
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 | ||
9 | struct mailimap; | 9 | struct mailimap; |
10 | struct mailimap_body; | 10 | struct mailimap_body; |
11 | struct mailimap_body_type_1part; | 11 | struct mailimap_body_type_1part; |
12 | struct mailimap_body_type_text; | 12 | struct mailimap_body_type_text; |
13 | struct mailimap_body_type_basic; | 13 | struct mailimap_body_type_basic; |
14 | struct mailimap_body_type_msg; | 14 | struct mailimap_body_type_msg; |
15 | struct mailimap_body_type_mpart; | 15 | struct mailimap_body_type_mpart; |
16 | struct mailimap_body_fields; | 16 | struct mailimap_body_fields; |
17 | struct mailimap_msg_att; | 17 | struct mailimap_msg_att; |
18 | class encodedString; | 18 | class encodedString; |
19 | 19 | ||
20 | class IMAPwrapper : public AbstractMail | 20 | class IMAPwrapper : public AbstractMail |
21 | { | 21 | { |
22 | Q_OBJECT | 22 | Q_OBJECT |
23 | public: | 23 | public: |
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 | 29 | ||
29 | virtual void deleteMail(const RecMail&mail); | 30 | virtual void deleteMail(const RecMail&mail); |
30 | virtual void answeredMail(const RecMail&mail); | 31 | virtual void answeredMail(const RecMail&mail); |
31 | virtual int deleteAllMail(const Folder*folder); | 32 | virtual int deleteAllMail(const Folder*folder); |
32 | 33 | ||
33 | virtual RecBody fetchBody(const RecMail&mail); | 34 | virtual RecBody fetchBody(const RecMail&mail); |
34 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | 35 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); |
35 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | 36 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); |
36 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | 37 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); |
37 | 38 | ||
38 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); | 39 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); |
39 | virtual int deleteMbox(const Folder*folder); | 40 | virtual int deleteMbox(const Folder*folder); |
40 | 41 | ||
41 | static void imap_progress( size_t current, size_t maximum ); | 42 | static void imap_progress( size_t current, size_t maximum ); |
42 | 43 | ||
43 | protected: | 44 | protected: |
44 | RecMail*parse_list_result(mailimap_msg_att*); | 45 | RecMail*parse_list_result(mailimap_msg_att*); |
45 | void login(); | 46 | void login(); |
46 | void logout(); | 47 | void logout(); |
47 | 48 | ||
48 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 49 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
49 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); | 50 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); |
50 | 51 | ||
51 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); | 52 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); |
52 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); | 53 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); |
53 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); | 54 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); |
54 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); | 55 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); |
55 | void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); | 56 | void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); |
56 | void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); | 57 | void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); |
57 | 58 | ||
58 | /* just helpers */ | 59 | /* just helpers */ |
59 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); | 60 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); |
60 | static QStringList address_list_to_stringlist(clist*list); | 61 | static QStringList address_list_to_stringlist(clist*list); |
61 | 62 | ||
62 | 63 | ||
63 | IMAPaccount *account; | 64 | IMAPaccount *account; |
64 | mailimap *m_imap; | 65 | mailimap *m_imap; |
65 | }; | 66 | }; |
66 | 67 | ||
67 | #endif | 68 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp index 416795b..f303d72 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.cpp +++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp | |||
@@ -1,90 +1,94 @@ | |||
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 "mboxwrapper.h" | 4 | #include "mboxwrapper.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | 6 | ||
7 | #include <qstring.h> | 7 | #include <qstring.h> |
8 | #include <qfile.h> | 8 | #include <qfile.h> |
9 | #include <qtextstream.h> | 9 | #include <qtextstream.h> |
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
11 | #include <libetpan/mailmime_content.h> | 11 | #include <libetpan/mailmime_content.h> |
12 | #include <libetpan/mailmime.h> | 12 | #include <libetpan/mailmime.h> |
13 | 13 | ||
14 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 14 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
15 | { | 15 | { |
16 | return new IMAPwrapper(a); | 16 | return new IMAPwrapper(a); |
17 | } | 17 | } |
18 | 18 | ||
19 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 19 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
20 | { | 20 | { |
21 | return new POP3wrapper(a); | 21 | return new POP3wrapper(a); |
22 | } | 22 | } |
23 | 23 | ||
24 | AbstractMail* AbstractMail::getWrapper(const QString&a) | 24 | AbstractMail* AbstractMail::getWrapper(const QString&a) |
25 | { | 25 | { |
26 | return new MBOXwrapper(a); | 26 | return new MBOXwrapper(a); |
27 | } | 27 | } |
28 | 28 | ||
29 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) | 29 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
30 | { | 30 | { |
31 | qDebug("Decode string start"); | 31 | qDebug("Decode string start"); |
32 | char*result_text; | 32 | char*result_text; |
33 | size_t index = 0; | 33 | size_t index = 0; |
34 | /* reset for recursive use! */ | 34 | /* reset for recursive use! */ |
35 | size_t target_length = 0; | 35 | size_t target_length = 0; |
36 | result_text = 0; | 36 | result_text = 0; |
37 | int mimetype = MAILMIME_MECHANISM_7BIT; | 37 | int mimetype = MAILMIME_MECHANISM_7BIT; |
38 | if (enc.lower()=="quoted-printable") { | 38 | if (enc.lower()=="quoted-printable") { |
39 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 39 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
40 | } else if (enc.lower()=="base64") { | 40 | } else if (enc.lower()=="base64") { |
41 | mimetype = MAILMIME_MECHANISM_BASE64; | 41 | mimetype = MAILMIME_MECHANISM_BASE64; |
42 | } else if (enc.lower()=="8bit") { | 42 | } else if (enc.lower()=="8bit") { |
43 | mimetype = MAILMIME_MECHANISM_8BIT; | 43 | mimetype = MAILMIME_MECHANISM_8BIT; |
44 | } else if (enc.lower()=="binary") { | 44 | } else if (enc.lower()=="binary") { |
45 | mimetype = MAILMIME_MECHANISM_BINARY; | 45 | mimetype = MAILMIME_MECHANISM_BINARY; |
46 | } | 46 | } |
47 | 47 | ||
48 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | 48 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, |
49 | &result_text,&target_length); | 49 | &result_text,&target_length); |
50 | 50 | ||
51 | encodedString* result = new encodedString(); | 51 | encodedString* result = new encodedString(); |
52 | if (err == MAILIMF_NO_ERROR) { | 52 | if (err == MAILIMF_NO_ERROR) { |
53 | result->setContent(result_text,target_length); | 53 | result->setContent(result_text,target_length); |
54 | } | 54 | } |
55 | qDebug("Decode string finished"); | 55 | qDebug("Decode string finished"); |
56 | return result; | 56 | return result; |
57 | } | 57 | } |
58 | 58 | ||
59 | QString AbstractMail::convert_String(const char*text) | 59 | QString AbstractMail::convert_String(const char*text) |
60 | { | 60 | { |
61 | size_t index = 0; | 61 | size_t index = 0; |
62 | char*res = 0; | 62 | char*res = 0; |
63 | 63 | ||
64 | /* attention - doesn't work with arm systems! */ | 64 | /* attention - doesn't work with arm systems! */ |
65 | int err = mailmime_encoded_phrase_parse("iso-8859-1", | 65 | int err = mailmime_encoded_phrase_parse("iso-8859-1", |
66 | text, strlen(text),&index, "iso-8859-1",&res); | 66 | text, strlen(text),&index, "iso-8859-1",&res); |
67 | if (err != MAILIMF_NO_ERROR) { | 67 | if (err != MAILIMF_NO_ERROR) { |
68 | if (res) free(res); | 68 | if (res) free(res); |
69 | return QString(text); | 69 | return QString(text); |
70 | } | 70 | } |
71 | if (res) { | 71 | if (res) { |
72 | QString result(res); | 72 | QString result(res); |
73 | free(res); | 73 | free(res); |
74 | return result; | 74 | return result; |
75 | } | 75 | } |
76 | return QString(text); | 76 | return QString(text); |
77 | } | 77 | } |
78 | 78 | ||
79 | /* cp & paste from launcher */ | 79 | /* cp & paste from launcher */ |
80 | QString AbstractMail::gen_attachment_id() | 80 | QString AbstractMail::gen_attachment_id() |
81 | { | 81 | { |
82 | QFile file( "/proc/sys/kernel/random/uuid" ); | 82 | QFile file( "/proc/sys/kernel/random/uuid" ); |
83 | if (!file.open(IO_ReadOnly ) ) | 83 | if (!file.open(IO_ReadOnly ) ) |
84 | return QString::null; | 84 | return QString::null; |
85 | 85 | ||
86 | QTextStream stream(&file); | 86 | QTextStream stream(&file); |
87 | 87 | ||
88 | return "{" + stream.read().stripWhiteSpace() + "}"; | 88 | return "{" + stream.read().stripWhiteSpace() + "}"; |
89 | } | 89 | } |
90 | 90 | ||
91 | int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool) | ||
92 | { | ||
93 | return 0; | ||
94 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h index 5dc4cab..dab9e10 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.h +++ b/noncore/net/mail/libmailwrapper/abstractmail.h | |||
@@ -1,51 +1,53 @@ | |||
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 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | class RecPart; | 9 | class RecPart; |
10 | class IMAPwrapper; | 10 | class IMAPwrapper; |
11 | class POP3wrapper; | 11 | class POP3wrapper; |
12 | class Folder; | 12 | class Folder; |
13 | class encodedString; | 13 | class encodedString; |
14 | struct folderStat; | ||
14 | 15 | ||
15 | class AbstractMail:public QObject | 16 | class AbstractMail:public QObject |
16 | { | 17 | { |
17 | Q_OBJECT | 18 | Q_OBJECT |
18 | public: | 19 | public: |
19 | AbstractMail(){}; | 20 | AbstractMail(){}; |
20 | virtual ~AbstractMail(){} | 21 | virtual ~AbstractMail(){} |
21 | virtual QList<Folder>* listFolders()=0; | 22 | virtual QList<Folder>* listFolders()=0; |
22 | 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; | ||
23 | virtual RecBody fetchBody(const RecMail&mail)=0; | 25 | virtual RecBody fetchBody(const RecMail&mail)=0; |
24 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; | 26 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; |
25 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; | 27 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; |
26 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; | 28 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; |
27 | 29 | ||
28 | virtual void deleteMail(const RecMail&mail)=0; | 30 | virtual void deleteMail(const RecMail&mail)=0; |
29 | virtual void answeredMail(const RecMail&mail)=0; | 31 | virtual void answeredMail(const RecMail&mail)=0; |
30 | virtual void cleanMimeCache(){}; | 32 | virtual void cleanMimeCache(){}; |
31 | virtual int deleteAllMail(const Folder*){return 1;} | 33 | virtual int deleteAllMail(const Folder*){return 1;} |
32 | virtual int deleteMbox(const Folder*){return 1;} | 34 | virtual int deleteMbox(const Folder*){return 1;} |
33 | 35 | ||
34 | /* mail box methods */ | 36 | /* mail box methods */ |
35 | /* parameter is the box to create. | 37 | /* parameter is the box to create. |
36 | * if the implementing subclass has prefixes, | 38 | * if the implementing subclass has prefixes, |
37 | * them has to be appended automatic. | 39 | * them has to be appended automatic. |
38 | */ | 40 | */ |
39 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;} | 41 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); |
40 | 42 | ||
41 | static AbstractMail* getWrapper(IMAPaccount *a); | 43 | static AbstractMail* getWrapper(IMAPaccount *a); |
42 | static AbstractMail* getWrapper(POP3account *a); | 44 | static AbstractMail* getWrapper(POP3account *a); |
43 | /* mbox only! */ | 45 | /* mbox only! */ |
44 | static AbstractMail* getWrapper(const QString&a); | 46 | static AbstractMail* getWrapper(const QString&a); |
45 | 47 | ||
46 | protected: | 48 | protected: |
47 | static encodedString*decode_String(const encodedString*text,const QString&enc); | 49 | static encodedString*decode_String(const encodedString*text,const QString&enc); |
48 | static QString convert_String(const char*text); | 50 | static QString convert_String(const char*text); |
49 | static QString gen_attachment_id(); | 51 | static QString gen_attachment_id(); |
50 | }; | 52 | }; |
51 | #endif | 53 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index b437df0..f1d42c2 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -553,384 +553,424 @@ void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&tar | |||
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 | ||
601 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 601 | void 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 | ||
623 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 623 | void 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 | ||
636 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 636 | void 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 | ||
648 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) | 648 | void 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 | ||
665 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 665 | void 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 | ||
707 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 707 | void 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 | ||
754 | void IMAPwrapper::deleteMail(const RecMail&mail) | 754 | void 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 | ||
791 | void IMAPwrapper::answeredMail(const RecMail&mail) | 791 | void 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 | ||
821 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 821 | QString 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 | ||
836 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 836 | QString 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 | ||
841 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | 841 | encodedString* 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 | ||
849 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 849 | encodedString* 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 | ||
854 | int IMAPwrapper::deleteAllMail(const Folder*folder) | 854 | int 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 | ||
895 | int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) | 895 | int 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 | ||
925 | int IMAPwrapper::deleteMbox(const Folder*folder) | 925 | int 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 | |||
938 | void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | ||
939 | { | ||
940 | mailimap_status_att_list * att_list =0; | ||
941 | mailimap_mailbox_data_status * status=0; | ||
942 | clistiter * cur = 0; | ||
943 | int r = 0; | ||
944 | int res = 0; | ||
945 | target_stat.message_count = 0; | ||
946 | target_stat.message_unseen = 0; | ||
947 | target_stat.message_recent = 0; | ||
948 | login(); | ||
949 | if (!m_imap) { | ||
950 | return; | ||
951 | } | ||
952 | att_list = mailimap_status_att_list_new_empty(); | ||
953 | if (!att_list) return; | ||
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); | ||
956 | r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); | ||
957 | r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); | ||
958 | for (cur = clist_begin(status->st_info_list); | ||
959 | cur != NULL ; cur = clist_next(cur)) { | ||
960 | mailimap_status_info * status_info; | ||
961 | status_info = (mailimap_status_info *)clist_content(cur); | ||
962 | switch (status_info->st_att) { | ||
963 | case MAILIMAP_STATUS_ATT_MESSAGES: | ||
964 | target_stat.message_count = status_info->st_value; | ||
965 | break; | ||
966 | case MAILIMAP_STATUS_ATT_RECENT: | ||
967 | target_stat.message_recent = status_info->st_value; | ||
968 | break; | ||
969 | case MAILIMAP_STATUS_ATT_UNSEEN: | ||
970 | target_stat.message_unseen = status_info->st_value; | ||
971 | break; | ||
972 | } | ||
973 | } | ||
974 | mailimap_mailbox_data_status_free(status); | ||
975 | mailimap_status_att_list_free(att_list); | ||
976 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index 7941046..8f5a2b5 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h | |||
@@ -1,67 +1,68 @@ | |||
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 | ||
9 | struct mailimap; | 9 | struct mailimap; |
10 | struct mailimap_body; | 10 | struct mailimap_body; |
11 | struct mailimap_body_type_1part; | 11 | struct mailimap_body_type_1part; |
12 | struct mailimap_body_type_text; | 12 | struct mailimap_body_type_text; |
13 | struct mailimap_body_type_basic; | 13 | struct mailimap_body_type_basic; |
14 | struct mailimap_body_type_msg; | 14 | struct mailimap_body_type_msg; |
15 | struct mailimap_body_type_mpart; | 15 | struct mailimap_body_type_mpart; |
16 | struct mailimap_body_fields; | 16 | struct mailimap_body_fields; |
17 | struct mailimap_msg_att; | 17 | struct mailimap_msg_att; |
18 | class encodedString; | 18 | class encodedString; |
19 | 19 | ||
20 | class IMAPwrapper : public AbstractMail | 20 | class IMAPwrapper : public AbstractMail |
21 | { | 21 | { |
22 | Q_OBJECT | 22 | Q_OBJECT |
23 | public: | 23 | public: |
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 | 29 | ||
29 | virtual void deleteMail(const RecMail&mail); | 30 | virtual void deleteMail(const RecMail&mail); |
30 | virtual void answeredMail(const RecMail&mail); | 31 | virtual void answeredMail(const RecMail&mail); |
31 | virtual int deleteAllMail(const Folder*folder); | 32 | virtual int deleteAllMail(const Folder*folder); |
32 | 33 | ||
33 | virtual RecBody fetchBody(const RecMail&mail); | 34 | virtual RecBody fetchBody(const RecMail&mail); |
34 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | 35 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); |
35 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | 36 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); |
36 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | 37 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); |
37 | 38 | ||
38 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); | 39 | virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); |
39 | virtual int deleteMbox(const Folder*folder); | 40 | virtual int deleteMbox(const Folder*folder); |
40 | 41 | ||
41 | static void imap_progress( size_t current, size_t maximum ); | 42 | static void imap_progress( size_t current, size_t maximum ); |
42 | 43 | ||
43 | protected: | 44 | protected: |
44 | RecMail*parse_list_result(mailimap_msg_att*); | 45 | RecMail*parse_list_result(mailimap_msg_att*); |
45 | void login(); | 46 | void login(); |
46 | void logout(); | 47 | void logout(); |
47 | 48 | ||
48 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 49 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
49 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); | 50 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); |
50 | 51 | ||
51 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); | 52 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); |
52 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); | 53 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); |
53 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); | 54 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); |
54 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); | 55 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); |
55 | void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); | 56 | void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); |
56 | void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); | 57 | void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); |
57 | 58 | ||
58 | /* just helpers */ | 59 | /* just helpers */ |
59 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); | 60 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); |
60 | static QStringList address_list_to_stringlist(clist*list); | 61 | static QStringList address_list_to_stringlist(clist*list); |
61 | 62 | ||
62 | 63 | ||
63 | IMAPaccount *account; | 64 | IMAPaccount *account; |
64 | mailimap *m_imap; | 65 | mailimap *m_imap; |
65 | }; | 66 | }; |
66 | 67 | ||
67 | #endif | 68 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h index abfbe65..05c4816 100644 --- a/noncore/net/mail/libmailwrapper/mailtypes.h +++ b/noncore/net/mail/libmailwrapper/mailtypes.h | |||
@@ -1,185 +1,192 @@ | |||
1 | #ifndef __MAIL_TYPES_H | 1 | #ifndef __MAIL_TYPES_H |
2 | #define __MAIL_TYPES_H | 2 | #define __MAIL_TYPES_H |
3 | 3 | ||
4 | #define FLAG_ANSWERED 0 | 4 | #define FLAG_ANSWERED 0 |
5 | #define FLAG_FLAGGED 1 | 5 | #define FLAG_FLAGGED 1 |
6 | #define FLAG_DELETED 2 | 6 | #define FLAG_DELETED 2 |
7 | #define FLAG_SEEN 3 | 7 | #define FLAG_SEEN 3 |
8 | #define FLAG_DRAFT 4 | 8 | #define FLAG_DRAFT 4 |
9 | #define FLAG_RECENT 5 | 9 | #define FLAG_RECENT 5 |
10 | 10 | ||
11 | #include <qlist.h> | 11 | #include <qlist.h> |
12 | #include <qbitarray.h> | 12 | #include <qbitarray.h> |
13 | #include <qstring.h> | 13 | #include <qstring.h> |
14 | #include <qstringlist.h> | 14 | #include <qstringlist.h> |
15 | #include <qmap.h> | 15 | #include <qmap.h> |
16 | #include <qvaluelist.h> | 16 | #include <qvaluelist.h> |
17 | 17 | ||
18 | class AbstractMail; | 18 | class AbstractMail; |
19 | /* a class to describe mails in a mailbox */ | 19 | /* a class to describe mails in a mailbox */ |
20 | /* Attention! | 20 | /* Attention! |
21 | From programmers point of view it would make sense to | 21 | From programmers point of view it would make sense to |
22 | store the mail body into this class, too. | 22 | store the mail body into this class, too. |
23 | But: not from the point of view of the device. | 23 | But: not from the point of view of the device. |
24 | Mailbodies can be real large. So we request them when | 24 | Mailbodies can be real large. So we request them when |
25 | needed from the mail-wrapper class direct from the server itself | 25 | needed from the mail-wrapper class direct from the server itself |
26 | (imap) or from a file-based cache (pop3?) | 26 | (imap) or from a file-based cache (pop3?) |
27 | So there is no interface "const QString&body()" but you should | 27 | So there is no interface "const QString&body()" but you should |
28 | make a request to the mailwrapper with this class as parameter to | 28 | make a request to the mailwrapper with this class as parameter to |
29 | get the body. Same words for the attachments. | 29 | get the body. Same words for the attachments. |
30 | */ | 30 | */ |
31 | class RecMail | 31 | class RecMail |
32 | { | 32 | { |
33 | public: | 33 | public: |
34 | RecMail(); | 34 | RecMail(); |
35 | RecMail(const RecMail&old); | 35 | RecMail(const RecMail&old); |
36 | virtual ~RecMail(); | 36 | virtual ~RecMail(); |
37 | 37 | ||
38 | const int getNumber()const{return msg_number;} | 38 | const int getNumber()const{return msg_number;} |
39 | void setNumber(int number){msg_number=number;} | 39 | void setNumber(int number){msg_number=number;} |
40 | const QString&getDate()const{ return date; } | 40 | const QString&getDate()const{ return date; } |
41 | void setDate( const QString&a ) { date = a; } | 41 | void setDate( const QString&a ) { date = a; } |
42 | const QString&getFrom()const{ return from; } | 42 | const QString&getFrom()const{ return from; } |
43 | void setFrom( const QString&a ) { from = a; } | 43 | void setFrom( const QString&a ) { from = a; } |
44 | const QString&getSubject()const { return subject; } | 44 | const QString&getSubject()const { return subject; } |
45 | void setSubject( const QString&s ) { subject = s; } | 45 | void setSubject( const QString&s ) { subject = s; } |
46 | const QString&getMbox()const{return mbox;} | 46 | const QString&getMbox()const{return mbox;} |
47 | void setMbox(const QString&box){mbox = box;} | 47 | void setMbox(const QString&box){mbox = box;} |
48 | void setMsgid(const QString&id){msg_id=id;} | 48 | void setMsgid(const QString&id){msg_id=id;} |
49 | const QString&Msgid()const{return msg_id;} | 49 | const QString&Msgid()const{return msg_id;} |
50 | void setReplyto(const QString&reply){replyto=reply;} | 50 | void setReplyto(const QString&reply){replyto=reply;} |
51 | const QString&Replyto()const{return replyto;} | 51 | const QString&Replyto()const{return replyto;} |
52 | void setMsgsize(int size){msg_size = size;} | 52 | void setMsgsize(int size){msg_size = size;} |
53 | const int Msgsize()const{return msg_size;} | 53 | const int Msgsize()const{return msg_size;} |
54 | 54 | ||
55 | 55 | ||
56 | void setTo(const QStringList&list); | 56 | void setTo(const QStringList&list); |
57 | const QStringList&To()const; | 57 | const QStringList&To()const; |
58 | void setCC(const QStringList&list); | 58 | void setCC(const QStringList&list); |
59 | const QStringList&CC()const; | 59 | const QStringList&CC()const; |
60 | void setBcc(const QStringList&list); | 60 | void setBcc(const QStringList&list); |
61 | const QStringList&Bcc()const; | 61 | const QStringList&Bcc()const; |
62 | const QBitArray&getFlags()const{return msg_flags;} | 62 | const QBitArray&getFlags()const{return msg_flags;} |
63 | void setFlags(const QBitArray&flags){msg_flags = flags;} | 63 | void setFlags(const QBitArray&flags){msg_flags = flags;} |
64 | 64 | ||
65 | void setWrapper(AbstractMail*wrapper); | 65 | void setWrapper(AbstractMail*wrapper); |
66 | AbstractMail* Wrapper(); | 66 | AbstractMail* Wrapper(); |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | QString subject,date,from,mbox,msg_id,replyto; | 69 | QString subject,date,from,mbox,msg_id,replyto; |
70 | int msg_number,msg_size; | 70 | int msg_number,msg_size; |
71 | QBitArray msg_flags; | 71 | QBitArray msg_flags; |
72 | QStringList to,cc,bcc; | 72 | QStringList to,cc,bcc; |
73 | AbstractMail*wrapper; | 73 | AbstractMail*wrapper; |
74 | void init(); | 74 | void init(); |
75 | void copy_old(const RecMail&old); | 75 | void copy_old(const RecMail&old); |
76 | }; | 76 | }; |
77 | 77 | ||
78 | typedef QMap<QString,QString> part_plist_t; | 78 | typedef QMap<QString,QString> part_plist_t; |
79 | 79 | ||
80 | class RecPart | 80 | class RecPart |
81 | { | 81 | { |
82 | protected: | 82 | protected: |
83 | QString m_type,m_subtype,m_identifier,m_encoding,m_description; | 83 | QString m_type,m_subtype,m_identifier,m_encoding,m_description; |
84 | unsigned int m_lines,m_size; | 84 | unsigned int m_lines,m_size; |
85 | part_plist_t m_Parameters; | 85 | part_plist_t m_Parameters; |
86 | /* describes the position in the mail */ | 86 | /* describes the position in the mail */ |
87 | QValueList<int> m_poslist; | 87 | QValueList<int> m_poslist; |
88 | 88 | ||
89 | public: | 89 | public: |
90 | RecPart(); | 90 | RecPart(); |
91 | virtual ~RecPart(); | 91 | virtual ~RecPart(); |
92 | 92 | ||
93 | const QString&Type()const; | 93 | const QString&Type()const; |
94 | void setType(const QString&type); | 94 | void setType(const QString&type); |
95 | const QString&Subtype()const; | 95 | const QString&Subtype()const; |
96 | void setSubtype(const QString&subtype); | 96 | void setSubtype(const QString&subtype); |
97 | const QString&Identifier()const; | 97 | const QString&Identifier()const; |
98 | void setIdentifier(const QString&identifier); | 98 | void setIdentifier(const QString&identifier); |
99 | const QString&Encoding()const; | 99 | const QString&Encoding()const; |
100 | void setEncoding(const QString&encoding); | 100 | void setEncoding(const QString&encoding); |
101 | const QString&Description()const; | 101 | const QString&Description()const; |
102 | void setDescription(const QString&desc); | 102 | void setDescription(const QString&desc); |
103 | void setLines(unsigned int lines); | 103 | void setLines(unsigned int lines); |
104 | const unsigned int Lines()const; | 104 | const unsigned int Lines()const; |
105 | void setSize(unsigned int size); | 105 | void setSize(unsigned int size); |
106 | const unsigned int Size()const; | 106 | const unsigned int Size()const; |
107 | 107 | ||
108 | 108 | ||
109 | void setParameters(const part_plist_t&list); | 109 | void setParameters(const part_plist_t&list); |
110 | const part_plist_t&Parameters()const; | 110 | const part_plist_t&Parameters()const; |
111 | void addParameter(const QString&key,const QString&value); | 111 | void addParameter(const QString&key,const QString&value); |
112 | const QString searchParamter(const QString&key)const; | 112 | const QString searchParamter(const QString&key)const; |
113 | void setPositionlist(const QValueList<int>&poslist); | 113 | void setPositionlist(const QValueList<int>&poslist); |
114 | const QValueList<int>& Positionlist()const; | 114 | const QValueList<int>& Positionlist()const; |
115 | }; | 115 | }; |
116 | 116 | ||
117 | class RecBody | 117 | class RecBody |
118 | { | 118 | { |
119 | protected: | 119 | protected: |
120 | QString m_BodyText; | 120 | QString m_BodyText; |
121 | QValueList<RecPart> m_PartsList; | 121 | QValueList<RecPart> m_PartsList; |
122 | RecPart m_description; | 122 | RecPart m_description; |
123 | 123 | ||
124 | public: | 124 | public: |
125 | RecBody(); | 125 | RecBody(); |
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 | ||
138 | class encodedString | 138 | class encodedString |
139 | { | 139 | { |
140 | public: | 140 | public: |
141 | encodedString(); | 141 | encodedString(); |
142 | /* | 142 | /* |
143 | creates an new content string. | 143 | creates an new content string. |
144 | it makes a deep copy of it! | 144 | it makes a deep copy of it! |
145 | */ | 145 | */ |
146 | encodedString(const char*nContent,unsigned int length); | 146 | encodedString(const char*nContent,unsigned int length); |
147 | /* | 147 | /* |
148 | Take over the nContent. Means: it will just copy the pointer, not the content. | 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 | 149 | so make sure: No one else frees the string, the string has allocated with |
150 | malloc for compatibility with c-based libs | 150 | malloc for compatibility with c-based libs |
151 | */ | 151 | */ |
152 | encodedString(char*nContent,unsigned int nSize); | 152 | encodedString(char*nContent,unsigned int nSize); |
153 | /* copy construkor - makes ALWAYS a deep copy!!!! */ | 153 | /* copy construkor - makes ALWAYS a deep copy!!!! */ |
154 | encodedString(const encodedString&old); | 154 | encodedString(const encodedString&old); |
155 | /* assign operator - makes ALWAYS a deep copy!!!! */ | 155 | /* assign operator - makes ALWAYS a deep copy!!!! */ |
156 | encodedString& operator=(const encodedString&old); | 156 | encodedString& operator=(const encodedString&old); |
157 | /* destructor - cleans the content */ | 157 | /* destructor - cleans the content */ |
158 | virtual ~encodedString(); | 158 | virtual ~encodedString(); |
159 | 159 | ||
160 | /* returns a pointer to the content - do not delete yoursel! */ | 160 | /* returns a pointer to the content - do not delete yoursel! */ |
161 | const char*Content()const; | 161 | const char*Content()const; |
162 | /* returns the lengths of the content 'cause it must not be a null-terminated string! */ | 162 | /* returns the lengths of the content 'cause it must not be a null-terminated string! */ |
163 | const int Length()const; | 163 | const int Length()const; |
164 | 164 | ||
165 | /* | 165 | /* |
166 | makes a deep copy of nContent! | 166 | makes a deep copy of nContent! |
167 | */ | 167 | */ |
168 | void setContent(const char*nContent,int nSize); | 168 | void setContent(const char*nContent,int nSize); |
169 | /* | 169 | /* |
170 | Take over the nContent. Means: it will just copy the pointer, not the content. | 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 | 171 | so make sure: No one else frees the string, the string has allocated with |
172 | malloc for compatibility with c-based libs | 172 | malloc for compatibility with c-based libs |
173 | */ | 173 | */ |
174 | void setContent(char*nContent,int nSize); | 174 | void setContent(char*nContent,int nSize); |
175 | 175 | ||
176 | protected: | 176 | protected: |
177 | char * content; | 177 | char * content; |
178 | unsigned int size; | 178 | unsigned int size; |
179 | 179 | ||
180 | void init(); | 180 | void init(); |
181 | void copy_old(const encodedString&old); | 181 | void copy_old(const encodedString&old); |
182 | void clean(); | 182 | void clean(); |
183 | }; | 183 | }; |
184 | 184 | ||
185 | struct folderStat | ||
186 | { | ||
187 | unsigned int message_count; | ||
188 | unsigned int message_unseen; | ||
189 | unsigned int message_recent; | ||
190 | }; | ||
191 | |||
185 | #endif | 192 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index 0aa33dd..540a971 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp | |||
@@ -1,303 +1,324 @@ | |||
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 | ||
9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) | 9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) |
10 | : Genericwrapper(),MBOXPath(mbox_dir) | 10 | : Genericwrapper(),MBOXPath(mbox_dir) |
11 | { | 11 | { |
12 | QDir dir(MBOXPath); | 12 | QDir dir(MBOXPath); |
13 | if (!dir.exists()) { | 13 | if (!dir.exists()) { |
14 | dir.mkdir(MBOXPath); | 14 | dir.mkdir(MBOXPath); |
15 | } | 15 | } |
16 | } | 16 | } |
17 | 17 | ||
18 | MBOXwrapper::~MBOXwrapper() | 18 | MBOXwrapper::~MBOXwrapper() |
19 | { | 19 | { |
20 | } | 20 | } |
21 | 21 | ||
22 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 22 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
23 | { | 23 | { |
24 | mailstorage*storage = mailstorage_new(NULL); | 24 | mailstorage*storage = mailstorage_new(NULL); |
25 | QString p = MBOXPath+"/"; | 25 | QString p = MBOXPath+"/"; |
26 | p+=mailbox; | 26 | p+=mailbox; |
27 | 27 | ||
28 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 28 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
29 | mailfolder*folder; | 29 | mailfolder*folder; |
30 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 30 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
31 | r = mailfolder_connect(folder); | 31 | r = mailfolder_connect(folder); |
32 | if (r != MAIL_NO_ERROR) { | 32 | if (r != MAIL_NO_ERROR) { |
33 | qDebug("Error initializing mbox"); | 33 | qDebug("Error initializing mbox"); |
34 | mailfolder_free(folder); | 34 | mailfolder_free(folder); |
35 | mailstorage_free(storage); | 35 | mailstorage_free(storage); |
36 | return; | 36 | return; |
37 | } | 37 | } |
38 | 38 | ||
39 | parseList(target,folder->fld_session,mailbox); | 39 | parseList(target,folder->fld_session,mailbox); |
40 | 40 | ||
41 | mailfolder_disconnect(folder); | 41 | mailfolder_disconnect(folder); |
42 | mailfolder_free(folder); | 42 | mailfolder_free(folder); |
43 | mailstorage_free(storage); | 43 | mailstorage_free(storage); |
44 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | 44 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
45 | } | 45 | } |
46 | 46 | ||
47 | QList<Folder>* MBOXwrapper::listFolders() | 47 | QList<Folder>* MBOXwrapper::listFolders() |
48 | { | 48 | { |
49 | QList<Folder> * folders = new QList<Folder>(); | 49 | QList<Folder> * folders = new QList<Folder>(); |
50 | folders->setAutoDelete( false ); | 50 | folders->setAutoDelete( false ); |
51 | QDir dir(MBOXPath); | 51 | QDir dir(MBOXPath); |
52 | if (!dir.exists()) return folders; | 52 | if (!dir.exists()) return folders; |
53 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | 53 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); |
54 | QStringList entries = dir.entryList(); | 54 | QStringList entries = dir.entryList(); |
55 | QStringList::ConstIterator it = entries.begin(); | 55 | QStringList::ConstIterator it = entries.begin(); |
56 | for (;it!=entries.end();++it) { | 56 | for (;it!=entries.end();++it) { |
57 | Folder*inb=new Folder(*it,"/"); | 57 | Folder*inb=new Folder(*it,"/"); |
58 | folders->append(inb); | 58 | folders->append(inb); |
59 | } | 59 | } |
60 | return folders; | 60 | return folders; |
61 | } | 61 | } |
62 | 62 | ||
63 | void MBOXwrapper::deleteMail(const RecMail&mail) | 63 | void MBOXwrapper::deleteMail(const RecMail&mail) |
64 | { | 64 | { |
65 | mailstorage*storage = mailstorage_new(NULL); | 65 | mailstorage*storage = mailstorage_new(NULL); |
66 | QString p = MBOXPath+"/"; | 66 | QString p = MBOXPath+"/"; |
67 | p+=mail.getMbox(); | 67 | p+=mail.getMbox(); |
68 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 68 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
69 | mailfolder*folder; | 69 | mailfolder*folder; |
70 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 70 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
71 | r = mailfolder_connect(folder); | 71 | r = mailfolder_connect(folder); |
72 | if (r != MAIL_NO_ERROR) { | 72 | if (r != MAIL_NO_ERROR) { |
73 | qDebug("Error initializing mbox"); | 73 | qDebug("Error initializing mbox"); |
74 | mailfolder_free(folder); | 74 | mailfolder_free(folder); |
75 | mailstorage_free(storage); | 75 | mailstorage_free(storage); |
76 | return; | 76 | return; |
77 | } | 77 | } |
78 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); | 78 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); |
79 | if (r != MAIL_NO_ERROR) { | 79 | if (r != MAIL_NO_ERROR) { |
80 | qDebug("error deleting mail"); | 80 | qDebug("error deleting mail"); |
81 | } | 81 | } |
82 | mailfolder_free(folder); | 82 | mailfolder_free(folder); |
83 | mailstorage_free(storage); | 83 | mailstorage_free(storage); |
84 | } | 84 | } |
85 | 85 | ||
86 | void MBOXwrapper::answeredMail(const RecMail&) | 86 | void MBOXwrapper::answeredMail(const RecMail&) |
87 | { | 87 | { |
88 | } | 88 | } |
89 | 89 | ||
90 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | 90 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) |
91 | { | 91 | { |
92 | RecBody body; | 92 | RecBody body; |
93 | mailstorage*storage = mailstorage_new(NULL); | 93 | mailstorage*storage = mailstorage_new(NULL); |
94 | QString p = MBOXPath+"/"; | 94 | QString p = MBOXPath+"/"; |
95 | p+=mail.getMbox(); | 95 | p+=mail.getMbox(); |
96 | mailmessage * msg; | 96 | mailmessage * msg; |
97 | char*data=0; | 97 | char*data=0; |
98 | size_t size; | 98 | size_t size; |
99 | 99 | ||
100 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 100 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
101 | mailfolder*folder; | 101 | mailfolder*folder; |
102 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 102 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
103 | r = mailfolder_connect(folder); | 103 | r = mailfolder_connect(folder); |
104 | if (r != MAIL_NO_ERROR) { | 104 | if (r != MAIL_NO_ERROR) { |
105 | qDebug("Error initializing mbox"); | 105 | qDebug("Error initializing mbox"); |
106 | mailfolder_free(folder); | 106 | mailfolder_free(folder); |
107 | mailstorage_free(storage); | 107 | mailstorage_free(storage); |
108 | return body; | 108 | return body; |
109 | } | 109 | } |
110 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 110 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
111 | if (r != MAIL_NO_ERROR) { | 111 | if (r != MAIL_NO_ERROR) { |
112 | qDebug("Error fetching mail %i",mail.getNumber()); | 112 | qDebug("Error fetching mail %i",mail.getNumber()); |
113 | mailfolder_free(folder); | 113 | mailfolder_free(folder); |
114 | mailstorage_free(storage); | 114 | mailstorage_free(storage); |
115 | return body; | 115 | return body; |
116 | } | 116 | } |
117 | r = mailmessage_fetch(msg,&data,&size); | 117 | r = mailmessage_fetch(msg,&data,&size); |
118 | if (r != MAIL_NO_ERROR) { | 118 | if (r != MAIL_NO_ERROR) { |
119 | qDebug("Error fetching mail %i",mail.getNumber()); | 119 | qDebug("Error fetching mail %i",mail.getNumber()); |
120 | mailfolder_free(folder); | 120 | mailfolder_free(folder); |
121 | mailstorage_free(storage); | 121 | mailstorage_free(storage); |
122 | mailmessage_free(msg); | 122 | mailmessage_free(msg); |
123 | return body; | 123 | return body; |
124 | } | 124 | } |
125 | body = parseMail(msg); | 125 | body = parseMail(msg); |
126 | mailmessage_fetch_result_free(msg,data); | 126 | mailmessage_fetch_result_free(msg,data); |
127 | mailfolder_free(folder); | 127 | mailfolder_free(folder); |
128 | mailstorage_free(storage); | 128 | mailstorage_free(storage); |
129 | 129 | ||
130 | return body; | 130 | return body; |
131 | } | 131 | } |
132 | 132 | ||
133 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 133 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
134 | { | 134 | { |
135 | qDebug("MBOX %i von %i",current,maximum); | 135 | qDebug("MBOX %i von %i",current,maximum); |
136 | } | 136 | } |
137 | 137 | ||
138 | int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) | 138 | int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) |
139 | { | 139 | { |
140 | QString p = MBOXPath+"/"; | 140 | QString p = MBOXPath+"/"; |
141 | p+=folder; | 141 | p+=folder; |
142 | QFileInfo fi(p); | 142 | QFileInfo fi(p); |
143 | if (fi.exists()) { | 143 | if (fi.exists()) { |
144 | Global::statusMessage(tr("Mailbox exists.")); | 144 | Global::statusMessage(tr("Mailbox exists.")); |
145 | return 0; | 145 | return 0; |
146 | } | 146 | } |
147 | mailmbox_folder*f = 0; | 147 | mailmbox_folder*f = 0; |
148 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { | 148 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { |
149 | Global::statusMessage(tr("Error init folder")); | 149 | Global::statusMessage(tr("Error init folder")); |
150 | return 0; | 150 | return 0; |
151 | } | 151 | } |
152 | if (f) mailmbox_done(f); | 152 | if (f) mailmbox_done(f); |
153 | return 1; | 153 | return 1; |
154 | } | 154 | } |
155 | 155 | ||
156 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 156 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
157 | { | 157 | { |
158 | QString p = MBOXPath+"/"; | 158 | QString p = MBOXPath+"/"; |
159 | p+=folder; | 159 | p+=folder; |
160 | mailmbox_folder*f = 0; | 160 | mailmbox_folder*f = 0; |
161 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 161 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
162 | if (r != MAIL_NO_ERROR) { | 162 | if (r != MAIL_NO_ERROR) { |
163 | Global::statusMessage(tr("Error init folder")); | 163 | Global::statusMessage(tr("Error init folder")); |
164 | return; | 164 | return; |
165 | } | 165 | } |
166 | r = mailmbox_append_message(f,msg,length); | 166 | r = mailmbox_append_message(f,msg,length); |
167 | if (r != MAIL_NO_ERROR) { | 167 | if (r != MAIL_NO_ERROR) { |
168 | Global::statusMessage(tr("Error writing to message folder")); | 168 | Global::statusMessage(tr("Error writing to message folder")); |
169 | } | 169 | } |
170 | mailmbox_done(f); | 170 | mailmbox_done(f); |
171 | } | 171 | } |
172 | 172 | ||
173 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) | 173 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) |
174 | { | 174 | { |
175 | RecBody body; | 175 | RecBody body; |
176 | mailstorage*storage = mailstorage_new(NULL); | 176 | mailstorage*storage = mailstorage_new(NULL); |
177 | QString p = MBOXPath+"/"; | 177 | QString p = MBOXPath+"/"; |
178 | p+=mail.getMbox(); | 178 | p+=mail.getMbox(); |
179 | mailmessage * msg; | 179 | mailmessage * msg; |
180 | char*data=0; | 180 | char*data=0; |
181 | size_t size; | 181 | size_t size; |
182 | 182 | ||
183 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 183 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
184 | mailfolder*folder; | 184 | mailfolder*folder; |
185 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 185 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
186 | r = mailfolder_connect(folder); | 186 | r = mailfolder_connect(folder); |
187 | if (r != MAIL_NO_ERROR) { | 187 | if (r != MAIL_NO_ERROR) { |
188 | Global::statusMessage(tr("Error initializing mbox")); | 188 | Global::statusMessage(tr("Error initializing mbox")); |
189 | mailfolder_free(folder); | 189 | mailfolder_free(folder); |
190 | mailstorage_free(storage); | 190 | mailstorage_free(storage); |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 193 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
194 | if (r != MAIL_NO_ERROR) { | 194 | if (r != MAIL_NO_ERROR) { |
195 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 195 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
196 | mailfolder_free(folder); | 196 | mailfolder_free(folder); |
197 | mailstorage_free(storage); | 197 | mailstorage_free(storage); |
198 | return; | 198 | return; |
199 | } | 199 | } |
200 | r = mailmessage_fetch(msg,&data,&size); | 200 | r = mailmessage_fetch(msg,&data,&size); |
201 | if (r != MAIL_NO_ERROR) { | 201 | if (r != MAIL_NO_ERROR) { |
202 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 202 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
203 | mailfolder_free(folder); | 203 | mailfolder_free(folder); |
204 | mailstorage_free(storage); | 204 | mailstorage_free(storage); |
205 | mailmessage_free(msg); | 205 | mailmessage_free(msg); |
206 | return; | 206 | return; |
207 | } | 207 | } |
208 | *target = data; | 208 | *target = data; |
209 | *length = size; | 209 | *length = size; |
210 | mailfolder_free(folder); | 210 | mailfolder_free(folder); |
211 | mailstorage_free(storage); | 211 | mailstorage_free(storage); |
212 | mailmessage_free(msg); | 212 | mailmessage_free(msg); |
213 | } | 213 | } |
214 | 214 | ||
215 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | 215 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) |
216 | { | 216 | { |
217 | QString p = MBOXPath+"/"; | 217 | QString p = MBOXPath+"/"; |
218 | p+=mailbox; | 218 | p+=mailbox; |
219 | mailmbox_folder*f = 0; | 219 | mailmbox_folder*f = 0; |
220 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 220 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
221 | if (r != MAIL_NO_ERROR) { | 221 | if (r != MAIL_NO_ERROR) { |
222 | qDebug("Error init folder"); | 222 | qDebug("Error init folder"); |
223 | return; | 223 | return; |
224 | } | 224 | } |
225 | deleteMails(f,target); | 225 | deleteMails(f,target); |
226 | mailmbox_done(f); | 226 | mailmbox_done(f); |
227 | } | 227 | } |
228 | 228 | ||
229 | void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) | 229 | void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) |
230 | { | 230 | { |
231 | if (!f) return; | 231 | if (!f) return; |
232 | int r; | 232 | int r; |
233 | for (unsigned int i=0; i < target.count();++i) { | 233 | for (unsigned int i=0; i < target.count();++i) { |
234 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); | 234 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); |
235 | if (r!=MAILMBOX_NO_ERROR) { | 235 | if (r!=MAILMBOX_NO_ERROR) { |
236 | qDebug("error delete mail"); | 236 | qDebug("error delete mail"); |
237 | } | 237 | } |
238 | } | 238 | } |
239 | r = mailmbox_expunge(f); | 239 | r = mailmbox_expunge(f); |
240 | if (r != MAILMBOX_NO_ERROR) { | 240 | if (r != MAILMBOX_NO_ERROR) { |
241 | qDebug("error expunge mailbox"); | 241 | qDebug("error expunge mailbox"); |
242 | } | 242 | } |
243 | } | 243 | } |
244 | 244 | ||
245 | int MBOXwrapper::deleteAllMail(const Folder*tfolder) | 245 | int MBOXwrapper::deleteAllMail(const Folder*tfolder) |
246 | { | 246 | { |
247 | if (!tfolder) return 0; | 247 | if (!tfolder) return 0; |
248 | QString p = MBOXPath+tfolder->getDisplayName(); | 248 | QString p = MBOXPath+tfolder->getDisplayName(); |
249 | int res = 1; | 249 | int res = 1; |
250 | 250 | ||
251 | mailfolder*folder = 0; | 251 | mailfolder*folder = 0; |
252 | mailmessage_list*l=0; | 252 | mailmessage_list*l=0; |
253 | mailstorage*storage = mailstorage_new(NULL); | 253 | mailstorage*storage = mailstorage_new(NULL); |
254 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 254 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
255 | if (r != MAIL_NO_ERROR) { | 255 | if (r != MAIL_NO_ERROR) { |
256 | Global::statusMessage(tr("Error initializing mbox")); | 256 | Global::statusMessage(tr("Error initializing mbox")); |
257 | res = 0; | 257 | res = 0; |
258 | } | 258 | } |
259 | if (res) { | 259 | if (res) { |
260 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 260 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
261 | r = mailfolder_connect(folder); | 261 | r = mailfolder_connect(folder); |
262 | if (r != MAIL_NO_ERROR) { | 262 | if (r != MAIL_NO_ERROR) { |
263 | Global::statusMessage(tr("Error initializing mbox")); | 263 | Global::statusMessage(tr("Error initializing mbox")); |
264 | res = 0; | 264 | res = 0; |
265 | } | 265 | } |
266 | } | 266 | } |
267 | if (res) { | 267 | if (res) { |
268 | r = mailsession_get_messages_list(folder->fld_session,&l); | 268 | r = mailsession_get_messages_list(folder->fld_session,&l); |
269 | if (r != MAIL_NO_ERROR) { | 269 | if (r != MAIL_NO_ERROR) { |
270 | qDebug("Error message list"); | 270 | qDebug("Error message list"); |
271 | res=0; | 271 | res=0; |
272 | } | 272 | } |
273 | } | 273 | } |
274 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 274 | 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); | 275 | r = mailsession_remove_message(folder->fld_session,i+1); |
276 | if (r != MAIL_NO_ERROR) { | 276 | if (r != MAIL_NO_ERROR) { |
277 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 277 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
278 | res = 0; | 278 | res = 0; |
279 | break; | 279 | break; |
280 | } | 280 | } |
281 | } | 281 | } |
282 | if (l) mailmessage_list_free(l); | 282 | if (l) mailmessage_list_free(l); |
283 | if (folder) mailfolder_free(folder); | 283 | if (folder) mailfolder_free(folder); |
284 | if (storage) mailstorage_free(storage); | 284 | if (storage) mailstorage_free(storage); |
285 | return res; | 285 | return res; |
286 | } | 286 | } |
287 | 287 | ||
288 | int MBOXwrapper::deleteMbox(const Folder*tfolder) | 288 | int MBOXwrapper::deleteMbox(const Folder*tfolder) |
289 | { | 289 | { |
290 | if (!tfolder) return 0; | 290 | if (!tfolder) return 0; |
291 | QString p = MBOXPath+tfolder->getDisplayName(); | 291 | QString p = MBOXPath+tfolder->getDisplayName(); |
292 | QFile fi(p); | 292 | QFile fi(p); |
293 | if (!fi.exists()) { | 293 | if (!fi.exists()) { |
294 | Global::statusMessage(tr("Mailbox doesn't exist.")); | 294 | Global::statusMessage(tr("Mailbox doesn't exist.")); |
295 | return 0; | 295 | return 0; |
296 | } | 296 | } |
297 | if (!fi.remove()) { | 297 | if (!fi.remove()) { |
298 | Global::statusMessage(tr("Error deleting Mailbox.")); | 298 | Global::statusMessage(tr("Error deleting Mailbox.")); |
299 | return 0; | 299 | return 0; |
300 | } | 300 | } |
301 | return 1; | 301 | return 1; |
302 | } | 302 | } |
303 | 303 | ||
304 | void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | ||
305 | { | ||
306 | mailfolder*folder = 0; | ||
307 | mailstorage*storage = mailstorage_new(NULL); | ||
308 | target_stat.message_count = 0; | ||
309 | target_stat.message_unseen = 0; | ||
310 | target_stat.message_recent = 0; | ||
311 | QString p = MBOXPath+"/"+mailbox; | ||
312 | QFile fi(p); | ||
313 | if (!fi.exists()) { | ||
314 | Global::statusMessage(tr("Mailbox doesn't exist.")); | ||
315 | return; | ||
316 | } | ||
317 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
318 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
319 | r = mailfolder_connect(folder); | ||
320 | r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, | ||
321 | &target_stat.message_recent,&target_stat.message_unseen); | ||
322 | if (folder) mailfolder_free(folder); | ||
323 | if (storage) mailstorage_free(storage); | ||
324 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h index 226a544..f822997 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.h +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h | |||
@@ -1,41 +1,42 @@ | |||
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 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | struct mailmbox_folder; | 9 | struct mailmbox_folder; |
10 | 10 | ||
11 | class MBOXwrapper : public Genericwrapper | 11 | class MBOXwrapper : public Genericwrapper |
12 | { | 12 | { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | public: | 14 | public: |
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 | 21 | ||
21 | virtual void deleteMail(const RecMail&mail); | 22 | virtual void deleteMail(const RecMail&mail); |
22 | virtual void answeredMail(const RecMail&mail); | 23 | virtual void answeredMail(const RecMail&mail); |
23 | 24 | ||
24 | 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); |
25 | virtual int deleteMbox(const Folder*); | 26 | virtual int deleteMbox(const Folder*); |
26 | 27 | ||
27 | 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); |
28 | 29 | ||
29 | virtual RecBody fetchBody( const RecMail &mail ); | 30 | virtual RecBody fetchBody( const RecMail &mail ); |
30 | static void mbox_progress( size_t current, size_t maximum ); | 31 | static void mbox_progress( size_t current, size_t maximum ); |
31 | 32 | ||
32 | virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); | 33 | virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); |
33 | virtual void deleteMails(const QString & mailbox,QList<RecMail> &target); | 34 | virtual void deleteMails(const QString & mailbox,QList<RecMail> &target); |
34 | virtual int deleteAllMail(const Folder*); | 35 | virtual int deleteAllMail(const Folder*); |
35 | 36 | ||
36 | protected: | 37 | protected: |
37 | static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); | 38 | static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); |
38 | QString MBOXPath; | 39 | QString MBOXPath; |
39 | }; | 40 | }; |
40 | 41 | ||
41 | #endif | 42 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index de90dd1..d76d82a 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,218 +1,229 @@ | |||
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 | ||
13 | POP3wrapper::POP3wrapper( POP3account *a ) | 13 | POP3wrapper::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 | ||
23 | POP3wrapper::~POP3wrapper() | 23 | POP3wrapper::~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 | ||
32 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 32 | void 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 | ||
37 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) | 37 | RecBody 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 | ||
99 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 99 | void 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 | ||
109 | void POP3wrapper::login() | 109 | void 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 | ||
163 | void POP3wrapper::logout() | 163 | void 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 | ||
174 | QList<Folder>* POP3wrapper::listFolders() | 174 | QList<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 | ||
183 | void POP3wrapper::deleteMail(const RecMail&mail) | 183 | void 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 | ||
193 | void POP3wrapper::answeredMail(const RecMail&) | 193 | void POP3wrapper::answeredMail(const RecMail&) |
194 | { | 194 | { |
195 | } | 195 | } |
196 | 196 | ||
197 | int POP3wrapper::deleteAllMail(const Folder*) | 197 | int 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 | |||
220 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) | ||
221 | { | ||
222 | login(); | ||
223 | target_stat.message_count = 0; | ||
224 | target_stat.message_unseen = 0; | ||
225 | target_stat.message_recent = 0; | ||
226 | if (!m_pop3) return; | ||
227 | int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, | ||
228 | &target_stat.message_recent,&target_stat.message_unseen); | ||
229 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index b3a42be..536cadc 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h | |||
@@ -1,37 +1,39 @@ | |||
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 | ||
8 | struct mailstorage; | 8 | struct mailstorage; |
9 | struct mailfolder; | 9 | struct mailfolder; |
10 | 10 | ||
11 | class POP3wrapper : public Genericwrapper | 11 | class POP3wrapper : public Genericwrapper |
12 | { | 12 | { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
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 */ | ||
22 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | ||
21 | 23 | ||
22 | virtual void deleteMail(const RecMail&mail); | 24 | virtual void deleteMail(const RecMail&mail); |
23 | virtual void answeredMail(const RecMail&mail); | 25 | virtual void answeredMail(const RecMail&mail); |
24 | virtual int deleteAllMail(const Folder*); | 26 | virtual int deleteAllMail(const Folder*); |
25 | 27 | ||
26 | virtual RecBody fetchBody( const RecMail &mail ); | 28 | virtual RecBody fetchBody( const RecMail &mail ); |
27 | static void pop3_progress( size_t current, size_t maximum ); | 29 | static void pop3_progress( size_t current, size_t maximum ); |
28 | 30 | ||
29 | protected: | 31 | protected: |
30 | void login(); | 32 | void login(); |
31 | void logout(); | 33 | void logout(); |
32 | POP3account *account; | 34 | POP3account *account; |
33 | mailstorage*m_pop3; | 35 | mailstorage*m_pop3; |
34 | mailfolder*m_folder; | 36 | mailfolder*m_folder; |
35 | }; | 37 | }; |
36 | 38 | ||
37 | #endif | 39 | #endif |
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h index abfbe65..05c4816 100644 --- a/noncore/net/mail/mailtypes.h +++ b/noncore/net/mail/mailtypes.h | |||
@@ -1,185 +1,192 @@ | |||
1 | #ifndef __MAIL_TYPES_H | 1 | #ifndef __MAIL_TYPES_H |
2 | #define __MAIL_TYPES_H | 2 | #define __MAIL_TYPES_H |
3 | 3 | ||
4 | #define FLAG_ANSWERED 0 | 4 | #define FLAG_ANSWERED 0 |
5 | #define FLAG_FLAGGED 1 | 5 | #define FLAG_FLAGGED 1 |
6 | #define FLAG_DELETED 2 | 6 | #define FLAG_DELETED 2 |
7 | #define FLAG_SEEN 3 | 7 | #define FLAG_SEEN 3 |
8 | #define FLAG_DRAFT 4 | 8 | #define FLAG_DRAFT 4 |
9 | #define FLAG_RECENT 5 | 9 | #define FLAG_RECENT 5 |
10 | 10 | ||
11 | #include <qlist.h> | 11 | #include <qlist.h> |
12 | #include <qbitarray.h> | 12 | #include <qbitarray.h> |
13 | #include <qstring.h> | 13 | #include <qstring.h> |
14 | #include <qstringlist.h> | 14 | #include <qstringlist.h> |
15 | #include <qmap.h> | 15 | #include <qmap.h> |
16 | #include <qvaluelist.h> | 16 | #include <qvaluelist.h> |
17 | 17 | ||
18 | class AbstractMail; | 18 | class AbstractMail; |
19 | /* a class to describe mails in a mailbox */ | 19 | /* a class to describe mails in a mailbox */ |
20 | /* Attention! | 20 | /* Attention! |
21 | From programmers point of view it would make sense to | 21 | From programmers point of view it would make sense to |
22 | store the mail body into this class, too. | 22 | store the mail body into this class, too. |
23 | But: not from the point of view of the device. | 23 | But: not from the point of view of the device. |
24 | Mailbodies can be real large. So we request them when | 24 | Mailbodies can be real large. So we request them when |
25 | needed from the mail-wrapper class direct from the server itself | 25 | needed from the mail-wrapper class direct from the server itself |
26 | (imap) or from a file-based cache (pop3?) | 26 | (imap) or from a file-based cache (pop3?) |
27 | So there is no interface "const QString&body()" but you should | 27 | So there is no interface "const QString&body()" but you should |
28 | make a request to the mailwrapper with this class as parameter to | 28 | make a request to the mailwrapper with this class as parameter to |
29 | get the body. Same words for the attachments. | 29 | get the body. Same words for the attachments. |
30 | */ | 30 | */ |
31 | class RecMail | 31 | class RecMail |
32 | { | 32 | { |
33 | public: | 33 | public: |
34 | RecMail(); | 34 | RecMail(); |
35 | RecMail(const RecMail&old); | 35 | RecMail(const RecMail&old); |
36 | virtual ~RecMail(); | 36 | virtual ~RecMail(); |
37 | 37 | ||
38 | const int getNumber()const{return msg_number;} | 38 | const int getNumber()const{return msg_number;} |
39 | void setNumber(int number){msg_number=number;} | 39 | void setNumber(int number){msg_number=number;} |
40 | const QString&getDate()const{ return date; } | 40 | const QString&getDate()const{ return date; } |
41 | void setDate( const QString&a ) { date = a; } | 41 | void setDate( const QString&a ) { date = a; } |
42 | const QString&getFrom()const{ return from; } | 42 | const QString&getFrom()const{ return from; } |
43 | void setFrom( const QString&a ) { from = a; } | 43 | void setFrom( const QString&a ) { from = a; } |
44 | const QString&getSubject()const { return subject; } | 44 | const QString&getSubject()const { return subject; } |
45 | void setSubject( const QString&s ) { subject = s; } | 45 | void setSubject( const QString&s ) { subject = s; } |
46 | const QString&getMbox()const{return mbox;} | 46 | const QString&getMbox()const{return mbox;} |
47 | void setMbox(const QString&box){mbox = box;} | 47 | void setMbox(const QString&box){mbox = box;} |
48 | void setMsgid(const QString&id){msg_id=id;} | 48 | void setMsgid(const QString&id){msg_id=id;} |
49 | const QString&Msgid()const{return msg_id;} | 49 | const QString&Msgid()const{return msg_id;} |
50 | void setReplyto(const QString&reply){replyto=reply;} | 50 | void setReplyto(const QString&reply){replyto=reply;} |
51 | const QString&Replyto()const{return replyto;} | 51 | const QString&Replyto()const{return replyto;} |
52 | void setMsgsize(int size){msg_size = size;} | 52 | void setMsgsize(int size){msg_size = size;} |
53 | const int Msgsize()const{return msg_size;} | 53 | const int Msgsize()const{return msg_size;} |
54 | 54 | ||
55 | 55 | ||
56 | void setTo(const QStringList&list); | 56 | void setTo(const QStringList&list); |
57 | const QStringList&To()const; | 57 | const QStringList&To()const; |
58 | void setCC(const QStringList&list); | 58 | void setCC(const QStringList&list); |
59 | const QStringList&CC()const; | 59 | const QStringList&CC()const; |
60 | void setBcc(const QStringList&list); | 60 | void setBcc(const QStringList&list); |
61 | const QStringList&Bcc()const; | 61 | const QStringList&Bcc()const; |
62 | const QBitArray&getFlags()const{return msg_flags;} | 62 | const QBitArray&getFlags()const{return msg_flags;} |
63 | void setFlags(const QBitArray&flags){msg_flags = flags;} | 63 | void setFlags(const QBitArray&flags){msg_flags = flags;} |
64 | 64 | ||
65 | void setWrapper(AbstractMail*wrapper); | 65 | void setWrapper(AbstractMail*wrapper); |
66 | AbstractMail* Wrapper(); | 66 | AbstractMail* Wrapper(); |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | QString subject,date,from,mbox,msg_id,replyto; | 69 | QString subject,date,from,mbox,msg_id,replyto; |
70 | int msg_number,msg_size; | 70 | int msg_number,msg_size; |
71 | QBitArray msg_flags; | 71 | QBitArray msg_flags; |
72 | QStringList to,cc,bcc; | 72 | QStringList to,cc,bcc; |
73 | AbstractMail*wrapper; | 73 | AbstractMail*wrapper; |
74 | void init(); | 74 | void init(); |
75 | void copy_old(const RecMail&old); | 75 | void copy_old(const RecMail&old); |
76 | }; | 76 | }; |
77 | 77 | ||
78 | typedef QMap<QString,QString> part_plist_t; | 78 | typedef QMap<QString,QString> part_plist_t; |
79 | 79 | ||
80 | class RecPart | 80 | class RecPart |
81 | { | 81 | { |
82 | protected: | 82 | protected: |
83 | QString m_type,m_subtype,m_identifier,m_encoding,m_description; | 83 | QString m_type,m_subtype,m_identifier,m_encoding,m_description; |
84 | unsigned int m_lines,m_size; | 84 | unsigned int m_lines,m_size; |
85 | part_plist_t m_Parameters; | 85 | part_plist_t m_Parameters; |
86 | /* describes the position in the mail */ | 86 | /* describes the position in the mail */ |
87 | QValueList<int> m_poslist; | 87 | QValueList<int> m_poslist; |
88 | 88 | ||
89 | public: | 89 | public: |
90 | RecPart(); | 90 | RecPart(); |
91 | virtual ~RecPart(); | 91 | virtual ~RecPart(); |
92 | 92 | ||
93 | const QString&Type()const; | 93 | const QString&Type()const; |
94 | void setType(const QString&type); | 94 | void setType(const QString&type); |
95 | const QString&Subtype()const; | 95 | const QString&Subtype()const; |
96 | void setSubtype(const QString&subtype); | 96 | void setSubtype(const QString&subtype); |
97 | const QString&Identifier()const; | 97 | const QString&Identifier()const; |
98 | void setIdentifier(const QString&identifier); | 98 | void setIdentifier(const QString&identifier); |
99 | const QString&Encoding()const; | 99 | const QString&Encoding()const; |
100 | void setEncoding(const QString&encoding); | 100 | void setEncoding(const QString&encoding); |
101 | const QString&Description()const; | 101 | const QString&Description()const; |
102 | void setDescription(const QString&desc); | 102 | void setDescription(const QString&desc); |
103 | void setLines(unsigned int lines); | 103 | void setLines(unsigned int lines); |
104 | const unsigned int Lines()const; | 104 | const unsigned int Lines()const; |
105 | void setSize(unsigned int size); | 105 | void setSize(unsigned int size); |
106 | const unsigned int Size()const; | 106 | const unsigned int Size()const; |
107 | 107 | ||
108 | 108 | ||
109 | void setParameters(const part_plist_t&list); | 109 | void setParameters(const part_plist_t&list); |
110 | const part_plist_t&Parameters()const; | 110 | const part_plist_t&Parameters()const; |
111 | void addParameter(const QString&key,const QString&value); | 111 | void addParameter(const QString&key,const QString&value); |
112 | const QString searchParamter(const QString&key)const; | 112 | const QString searchParamter(const QString&key)const; |
113 | void setPositionlist(const QValueList<int>&poslist); | 113 | void setPositionlist(const QValueList<int>&poslist); |
114 | const QValueList<int>& Positionlist()const; | 114 | const QValueList<int>& Positionlist()const; |
115 | }; | 115 | }; |
116 | 116 | ||
117 | class RecBody | 117 | class RecBody |
118 | { | 118 | { |
119 | protected: | 119 | protected: |
120 | QString m_BodyText; | 120 | QString m_BodyText; |
121 | QValueList<RecPart> m_PartsList; | 121 | QValueList<RecPart> m_PartsList; |
122 | RecPart m_description; | 122 | RecPart m_description; |
123 | 123 | ||
124 | public: | 124 | public: |
125 | RecBody(); | 125 | RecBody(); |
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 | ||
138 | class encodedString | 138 | class encodedString |
139 | { | 139 | { |
140 | public: | 140 | public: |
141 | encodedString(); | 141 | encodedString(); |
142 | /* | 142 | /* |
143 | creates an new content string. | 143 | creates an new content string. |
144 | it makes a deep copy of it! | 144 | it makes a deep copy of it! |
145 | */ | 145 | */ |
146 | encodedString(const char*nContent,unsigned int length); | 146 | encodedString(const char*nContent,unsigned int length); |
147 | /* | 147 | /* |
148 | Take over the nContent. Means: it will just copy the pointer, not the content. | 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 | 149 | so make sure: No one else frees the string, the string has allocated with |
150 | malloc for compatibility with c-based libs | 150 | malloc for compatibility with c-based libs |
151 | */ | 151 | */ |
152 | encodedString(char*nContent,unsigned int nSize); | 152 | encodedString(char*nContent,unsigned int nSize); |
153 | /* copy construkor - makes ALWAYS a deep copy!!!! */ | 153 | /* copy construkor - makes ALWAYS a deep copy!!!! */ |
154 | encodedString(const encodedString&old); | 154 | encodedString(const encodedString&old); |
155 | /* assign operator - makes ALWAYS a deep copy!!!! */ | 155 | /* assign operator - makes ALWAYS a deep copy!!!! */ |
156 | encodedString& operator=(const encodedString&old); | 156 | encodedString& operator=(const encodedString&old); |
157 | /* destructor - cleans the content */ | 157 | /* destructor - cleans the content */ |
158 | virtual ~encodedString(); | 158 | virtual ~encodedString(); |
159 | 159 | ||
160 | /* returns a pointer to the content - do not delete yoursel! */ | 160 | /* returns a pointer to the content - do not delete yoursel! */ |
161 | const char*Content()const; | 161 | const char*Content()const; |
162 | /* returns the lengths of the content 'cause it must not be a null-terminated string! */ | 162 | /* returns the lengths of the content 'cause it must not be a null-terminated string! */ |
163 | const int Length()const; | 163 | const int Length()const; |
164 | 164 | ||
165 | /* | 165 | /* |
166 | makes a deep copy of nContent! | 166 | makes a deep copy of nContent! |
167 | */ | 167 | */ |
168 | void setContent(const char*nContent,int nSize); | 168 | void setContent(const char*nContent,int nSize); |
169 | /* | 169 | /* |
170 | Take over the nContent. Means: it will just copy the pointer, not the content. | 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 | 171 | so make sure: No one else frees the string, the string has allocated with |
172 | malloc for compatibility with c-based libs | 172 | malloc for compatibility with c-based libs |
173 | */ | 173 | */ |
174 | void setContent(char*nContent,int nSize); | 174 | void setContent(char*nContent,int nSize); |
175 | 175 | ||
176 | protected: | 176 | protected: |
177 | char * content; | 177 | char * content; |
178 | unsigned int size; | 178 | unsigned int size; |
179 | 179 | ||
180 | void init(); | 180 | void init(); |
181 | void copy_old(const encodedString&old); | 181 | void copy_old(const encodedString&old); |
182 | void clean(); | 182 | void clean(); |
183 | }; | 183 | }; |
184 | 184 | ||
185 | struct folderStat | ||
186 | { | ||
187 | unsigned int message_count; | ||
188 | unsigned int message_unseen; | ||
189 | unsigned int message_recent; | ||
190 | }; | ||
191 | |||
185 | #endif | 192 | #endif |
diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp index 0aa33dd..540a971 100644 --- a/noncore/net/mail/mboxwrapper.cpp +++ b/noncore/net/mail/mboxwrapper.cpp | |||
@@ -1,303 +1,324 @@ | |||
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 | ||
9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) | 9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) |
10 | : Genericwrapper(),MBOXPath(mbox_dir) | 10 | : Genericwrapper(),MBOXPath(mbox_dir) |
11 | { | 11 | { |
12 | QDir dir(MBOXPath); | 12 | QDir dir(MBOXPath); |
13 | if (!dir.exists()) { | 13 | if (!dir.exists()) { |
14 | dir.mkdir(MBOXPath); | 14 | dir.mkdir(MBOXPath); |
15 | } | 15 | } |
16 | } | 16 | } |
17 | 17 | ||
18 | MBOXwrapper::~MBOXwrapper() | 18 | MBOXwrapper::~MBOXwrapper() |
19 | { | 19 | { |
20 | } | 20 | } |
21 | 21 | ||
22 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | 22 | void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) |
23 | { | 23 | { |
24 | mailstorage*storage = mailstorage_new(NULL); | 24 | mailstorage*storage = mailstorage_new(NULL); |
25 | QString p = MBOXPath+"/"; | 25 | QString p = MBOXPath+"/"; |
26 | p+=mailbox; | 26 | p+=mailbox; |
27 | 27 | ||
28 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 28 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
29 | mailfolder*folder; | 29 | mailfolder*folder; |
30 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 30 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
31 | r = mailfolder_connect(folder); | 31 | r = mailfolder_connect(folder); |
32 | if (r != MAIL_NO_ERROR) { | 32 | if (r != MAIL_NO_ERROR) { |
33 | qDebug("Error initializing mbox"); | 33 | qDebug("Error initializing mbox"); |
34 | mailfolder_free(folder); | 34 | mailfolder_free(folder); |
35 | mailstorage_free(storage); | 35 | mailstorage_free(storage); |
36 | return; | 36 | return; |
37 | } | 37 | } |
38 | 38 | ||
39 | parseList(target,folder->fld_session,mailbox); | 39 | parseList(target,folder->fld_session,mailbox); |
40 | 40 | ||
41 | mailfolder_disconnect(folder); | 41 | mailfolder_disconnect(folder); |
42 | mailfolder_free(folder); | 42 | mailfolder_free(folder); |
43 | mailstorage_free(storage); | 43 | mailstorage_free(storage); |
44 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); | 44 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
45 | } | 45 | } |
46 | 46 | ||
47 | QList<Folder>* MBOXwrapper::listFolders() | 47 | QList<Folder>* MBOXwrapper::listFolders() |
48 | { | 48 | { |
49 | QList<Folder> * folders = new QList<Folder>(); | 49 | QList<Folder> * folders = new QList<Folder>(); |
50 | folders->setAutoDelete( false ); | 50 | folders->setAutoDelete( false ); |
51 | QDir dir(MBOXPath); | 51 | QDir dir(MBOXPath); |
52 | if (!dir.exists()) return folders; | 52 | if (!dir.exists()) return folders; |
53 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | 53 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); |
54 | QStringList entries = dir.entryList(); | 54 | QStringList entries = dir.entryList(); |
55 | QStringList::ConstIterator it = entries.begin(); | 55 | QStringList::ConstIterator it = entries.begin(); |
56 | for (;it!=entries.end();++it) { | 56 | for (;it!=entries.end();++it) { |
57 | Folder*inb=new Folder(*it,"/"); | 57 | Folder*inb=new Folder(*it,"/"); |
58 | folders->append(inb); | 58 | folders->append(inb); |
59 | } | 59 | } |
60 | return folders; | 60 | return folders; |
61 | } | 61 | } |
62 | 62 | ||
63 | void MBOXwrapper::deleteMail(const RecMail&mail) | 63 | void MBOXwrapper::deleteMail(const RecMail&mail) |
64 | { | 64 | { |
65 | mailstorage*storage = mailstorage_new(NULL); | 65 | mailstorage*storage = mailstorage_new(NULL); |
66 | QString p = MBOXPath+"/"; | 66 | QString p = MBOXPath+"/"; |
67 | p+=mail.getMbox(); | 67 | p+=mail.getMbox(); |
68 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 68 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
69 | mailfolder*folder; | 69 | mailfolder*folder; |
70 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 70 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
71 | r = mailfolder_connect(folder); | 71 | r = mailfolder_connect(folder); |
72 | if (r != MAIL_NO_ERROR) { | 72 | if (r != MAIL_NO_ERROR) { |
73 | qDebug("Error initializing mbox"); | 73 | qDebug("Error initializing mbox"); |
74 | mailfolder_free(folder); | 74 | mailfolder_free(folder); |
75 | mailstorage_free(storage); | 75 | mailstorage_free(storage); |
76 | return; | 76 | return; |
77 | } | 77 | } |
78 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); | 78 | r = mailsession_remove_message(folder->fld_session,mail.getNumber()); |
79 | if (r != MAIL_NO_ERROR) { | 79 | if (r != MAIL_NO_ERROR) { |
80 | qDebug("error deleting mail"); | 80 | qDebug("error deleting mail"); |
81 | } | 81 | } |
82 | mailfolder_free(folder); | 82 | mailfolder_free(folder); |
83 | mailstorage_free(storage); | 83 | mailstorage_free(storage); |
84 | } | 84 | } |
85 | 85 | ||
86 | void MBOXwrapper::answeredMail(const RecMail&) | 86 | void MBOXwrapper::answeredMail(const RecMail&) |
87 | { | 87 | { |
88 | } | 88 | } |
89 | 89 | ||
90 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | 90 | RecBody MBOXwrapper::fetchBody( const RecMail &mail ) |
91 | { | 91 | { |
92 | RecBody body; | 92 | RecBody body; |
93 | mailstorage*storage = mailstorage_new(NULL); | 93 | mailstorage*storage = mailstorage_new(NULL); |
94 | QString p = MBOXPath+"/"; | 94 | QString p = MBOXPath+"/"; |
95 | p+=mail.getMbox(); | 95 | p+=mail.getMbox(); |
96 | mailmessage * msg; | 96 | mailmessage * msg; |
97 | char*data=0; | 97 | char*data=0; |
98 | size_t size; | 98 | size_t size; |
99 | 99 | ||
100 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 100 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
101 | mailfolder*folder; | 101 | mailfolder*folder; |
102 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 102 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
103 | r = mailfolder_connect(folder); | 103 | r = mailfolder_connect(folder); |
104 | if (r != MAIL_NO_ERROR) { | 104 | if (r != MAIL_NO_ERROR) { |
105 | qDebug("Error initializing mbox"); | 105 | qDebug("Error initializing mbox"); |
106 | mailfolder_free(folder); | 106 | mailfolder_free(folder); |
107 | mailstorage_free(storage); | 107 | mailstorage_free(storage); |
108 | return body; | 108 | return body; |
109 | } | 109 | } |
110 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 110 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
111 | if (r != MAIL_NO_ERROR) { | 111 | if (r != MAIL_NO_ERROR) { |
112 | qDebug("Error fetching mail %i",mail.getNumber()); | 112 | qDebug("Error fetching mail %i",mail.getNumber()); |
113 | mailfolder_free(folder); | 113 | mailfolder_free(folder); |
114 | mailstorage_free(storage); | 114 | mailstorage_free(storage); |
115 | return body; | 115 | return body; |
116 | } | 116 | } |
117 | r = mailmessage_fetch(msg,&data,&size); | 117 | r = mailmessage_fetch(msg,&data,&size); |
118 | if (r != MAIL_NO_ERROR) { | 118 | if (r != MAIL_NO_ERROR) { |
119 | qDebug("Error fetching mail %i",mail.getNumber()); | 119 | qDebug("Error fetching mail %i",mail.getNumber()); |
120 | mailfolder_free(folder); | 120 | mailfolder_free(folder); |
121 | mailstorage_free(storage); | 121 | mailstorage_free(storage); |
122 | mailmessage_free(msg); | 122 | mailmessage_free(msg); |
123 | return body; | 123 | return body; |
124 | } | 124 | } |
125 | body = parseMail(msg); | 125 | body = parseMail(msg); |
126 | mailmessage_fetch_result_free(msg,data); | 126 | mailmessage_fetch_result_free(msg,data); |
127 | mailfolder_free(folder); | 127 | mailfolder_free(folder); |
128 | mailstorage_free(storage); | 128 | mailstorage_free(storage); |
129 | 129 | ||
130 | return body; | 130 | return body; |
131 | } | 131 | } |
132 | 132 | ||
133 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | 133 | void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) |
134 | { | 134 | { |
135 | qDebug("MBOX %i von %i",current,maximum); | 135 | qDebug("MBOX %i von %i",current,maximum); |
136 | } | 136 | } |
137 | 137 | ||
138 | int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) | 138 | int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) |
139 | { | 139 | { |
140 | QString p = MBOXPath+"/"; | 140 | QString p = MBOXPath+"/"; |
141 | p+=folder; | 141 | p+=folder; |
142 | QFileInfo fi(p); | 142 | QFileInfo fi(p); |
143 | if (fi.exists()) { | 143 | if (fi.exists()) { |
144 | Global::statusMessage(tr("Mailbox exists.")); | 144 | Global::statusMessage(tr("Mailbox exists.")); |
145 | return 0; | 145 | return 0; |
146 | } | 146 | } |
147 | mailmbox_folder*f = 0; | 147 | mailmbox_folder*f = 0; |
148 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { | 148 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { |
149 | Global::statusMessage(tr("Error init folder")); | 149 | Global::statusMessage(tr("Error init folder")); |
150 | return 0; | 150 | return 0; |
151 | } | 151 | } |
152 | if (f) mailmbox_done(f); | 152 | if (f) mailmbox_done(f); |
153 | return 1; | 153 | return 1; |
154 | } | 154 | } |
155 | 155 | ||
156 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) | 156 | void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) |
157 | { | 157 | { |
158 | QString p = MBOXPath+"/"; | 158 | QString p = MBOXPath+"/"; |
159 | p+=folder; | 159 | p+=folder; |
160 | mailmbox_folder*f = 0; | 160 | mailmbox_folder*f = 0; |
161 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 161 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
162 | if (r != MAIL_NO_ERROR) { | 162 | if (r != MAIL_NO_ERROR) { |
163 | Global::statusMessage(tr("Error init folder")); | 163 | Global::statusMessage(tr("Error init folder")); |
164 | return; | 164 | return; |
165 | } | 165 | } |
166 | r = mailmbox_append_message(f,msg,length); | 166 | r = mailmbox_append_message(f,msg,length); |
167 | if (r != MAIL_NO_ERROR) { | 167 | if (r != MAIL_NO_ERROR) { |
168 | Global::statusMessage(tr("Error writing to message folder")); | 168 | Global::statusMessage(tr("Error writing to message folder")); |
169 | } | 169 | } |
170 | mailmbox_done(f); | 170 | mailmbox_done(f); |
171 | } | 171 | } |
172 | 172 | ||
173 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) | 173 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) |
174 | { | 174 | { |
175 | RecBody body; | 175 | RecBody body; |
176 | mailstorage*storage = mailstorage_new(NULL); | 176 | mailstorage*storage = mailstorage_new(NULL); |
177 | QString p = MBOXPath+"/"; | 177 | QString p = MBOXPath+"/"; |
178 | p+=mail.getMbox(); | 178 | p+=mail.getMbox(); |
179 | mailmessage * msg; | 179 | mailmessage * msg; |
180 | char*data=0; | 180 | char*data=0; |
181 | size_t size; | 181 | size_t size; |
182 | 182 | ||
183 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 183 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
184 | mailfolder*folder; | 184 | mailfolder*folder; |
185 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 185 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
186 | r = mailfolder_connect(folder); | 186 | r = mailfolder_connect(folder); |
187 | if (r != MAIL_NO_ERROR) { | 187 | if (r != MAIL_NO_ERROR) { |
188 | Global::statusMessage(tr("Error initializing mbox")); | 188 | Global::statusMessage(tr("Error initializing mbox")); |
189 | mailfolder_free(folder); | 189 | mailfolder_free(folder); |
190 | mailstorage_free(storage); | 190 | mailstorage_free(storage); |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 193 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
194 | if (r != MAIL_NO_ERROR) { | 194 | if (r != MAIL_NO_ERROR) { |
195 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 195 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
196 | mailfolder_free(folder); | 196 | mailfolder_free(folder); |
197 | mailstorage_free(storage); | 197 | mailstorage_free(storage); |
198 | return; | 198 | return; |
199 | } | 199 | } |
200 | r = mailmessage_fetch(msg,&data,&size); | 200 | r = mailmessage_fetch(msg,&data,&size); |
201 | if (r != MAIL_NO_ERROR) { | 201 | if (r != MAIL_NO_ERROR) { |
202 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); | 202 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
203 | mailfolder_free(folder); | 203 | mailfolder_free(folder); |
204 | mailstorage_free(storage); | 204 | mailstorage_free(storage); |
205 | mailmessage_free(msg); | 205 | mailmessage_free(msg); |
206 | return; | 206 | return; |
207 | } | 207 | } |
208 | *target = data; | 208 | *target = data; |
209 | *length = size; | 209 | *length = size; |
210 | mailfolder_free(folder); | 210 | mailfolder_free(folder); |
211 | mailstorage_free(storage); | 211 | mailstorage_free(storage); |
212 | mailmessage_free(msg); | 212 | mailmessage_free(msg); |
213 | } | 213 | } |
214 | 214 | ||
215 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | 215 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) |
216 | { | 216 | { |
217 | QString p = MBOXPath+"/"; | 217 | QString p = MBOXPath+"/"; |
218 | p+=mailbox; | 218 | p+=mailbox; |
219 | mailmbox_folder*f = 0; | 219 | mailmbox_folder*f = 0; |
220 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 220 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
221 | if (r != MAIL_NO_ERROR) { | 221 | if (r != MAIL_NO_ERROR) { |
222 | qDebug("Error init folder"); | 222 | qDebug("Error init folder"); |
223 | return; | 223 | return; |
224 | } | 224 | } |
225 | deleteMails(f,target); | 225 | deleteMails(f,target); |
226 | mailmbox_done(f); | 226 | mailmbox_done(f); |
227 | } | 227 | } |
228 | 228 | ||
229 | void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) | 229 | void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) |
230 | { | 230 | { |
231 | if (!f) return; | 231 | if (!f) return; |
232 | int r; | 232 | int r; |
233 | for (unsigned int i=0; i < target.count();++i) { | 233 | for (unsigned int i=0; i < target.count();++i) { |
234 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); | 234 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); |
235 | if (r!=MAILMBOX_NO_ERROR) { | 235 | if (r!=MAILMBOX_NO_ERROR) { |
236 | qDebug("error delete mail"); | 236 | qDebug("error delete mail"); |
237 | } | 237 | } |
238 | } | 238 | } |
239 | r = mailmbox_expunge(f); | 239 | r = mailmbox_expunge(f); |
240 | if (r != MAILMBOX_NO_ERROR) { | 240 | if (r != MAILMBOX_NO_ERROR) { |
241 | qDebug("error expunge mailbox"); | 241 | qDebug("error expunge mailbox"); |
242 | } | 242 | } |
243 | } | 243 | } |
244 | 244 | ||
245 | int MBOXwrapper::deleteAllMail(const Folder*tfolder) | 245 | int MBOXwrapper::deleteAllMail(const Folder*tfolder) |
246 | { | 246 | { |
247 | if (!tfolder) return 0; | 247 | if (!tfolder) return 0; |
248 | QString p = MBOXPath+tfolder->getDisplayName(); | 248 | QString p = MBOXPath+tfolder->getDisplayName(); |
249 | int res = 1; | 249 | int res = 1; |
250 | 250 | ||
251 | mailfolder*folder = 0; | 251 | mailfolder*folder = 0; |
252 | mailmessage_list*l=0; | 252 | mailmessage_list*l=0; |
253 | mailstorage*storage = mailstorage_new(NULL); | 253 | mailstorage*storage = mailstorage_new(NULL); |
254 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 254 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
255 | if (r != MAIL_NO_ERROR) { | 255 | if (r != MAIL_NO_ERROR) { |
256 | Global::statusMessage(tr("Error initializing mbox")); | 256 | Global::statusMessage(tr("Error initializing mbox")); |
257 | res = 0; | 257 | res = 0; |
258 | } | 258 | } |
259 | if (res) { | 259 | if (res) { |
260 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 260 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
261 | r = mailfolder_connect(folder); | 261 | r = mailfolder_connect(folder); |
262 | if (r != MAIL_NO_ERROR) { | 262 | if (r != MAIL_NO_ERROR) { |
263 | Global::statusMessage(tr("Error initializing mbox")); | 263 | Global::statusMessage(tr("Error initializing mbox")); |
264 | res = 0; | 264 | res = 0; |
265 | } | 265 | } |
266 | } | 266 | } |
267 | if (res) { | 267 | if (res) { |
268 | r = mailsession_get_messages_list(folder->fld_session,&l); | 268 | r = mailsession_get_messages_list(folder->fld_session,&l); |
269 | if (r != MAIL_NO_ERROR) { | 269 | if (r != MAIL_NO_ERROR) { |
270 | qDebug("Error message list"); | 270 | qDebug("Error message list"); |
271 | res=0; | 271 | res=0; |
272 | } | 272 | } |
273 | } | 273 | } |
274 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 274 | 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); | 275 | r = mailsession_remove_message(folder->fld_session,i+1); |
276 | if (r != MAIL_NO_ERROR) { | 276 | if (r != MAIL_NO_ERROR) { |
277 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 277 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
278 | res = 0; | 278 | res = 0; |
279 | break; | 279 | break; |
280 | } | 280 | } |
281 | } | 281 | } |
282 | if (l) mailmessage_list_free(l); | 282 | if (l) mailmessage_list_free(l); |
283 | if (folder) mailfolder_free(folder); | 283 | if (folder) mailfolder_free(folder); |
284 | if (storage) mailstorage_free(storage); | 284 | if (storage) mailstorage_free(storage); |
285 | return res; | 285 | return res; |
286 | } | 286 | } |
287 | 287 | ||
288 | int MBOXwrapper::deleteMbox(const Folder*tfolder) | 288 | int MBOXwrapper::deleteMbox(const Folder*tfolder) |
289 | { | 289 | { |
290 | if (!tfolder) return 0; | 290 | if (!tfolder) return 0; |
291 | QString p = MBOXPath+tfolder->getDisplayName(); | 291 | QString p = MBOXPath+tfolder->getDisplayName(); |
292 | QFile fi(p); | 292 | QFile fi(p); |
293 | if (!fi.exists()) { | 293 | if (!fi.exists()) { |
294 | Global::statusMessage(tr("Mailbox doesn't exist.")); | 294 | Global::statusMessage(tr("Mailbox doesn't exist.")); |
295 | return 0; | 295 | return 0; |
296 | } | 296 | } |
297 | if (!fi.remove()) { | 297 | if (!fi.remove()) { |
298 | Global::statusMessage(tr("Error deleting Mailbox.")); | 298 | Global::statusMessage(tr("Error deleting Mailbox.")); |
299 | return 0; | 299 | return 0; |
300 | } | 300 | } |
301 | return 1; | 301 | return 1; |
302 | } | 302 | } |
303 | 303 | ||
304 | void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | ||
305 | { | ||
306 | mailfolder*folder = 0; | ||
307 | mailstorage*storage = mailstorage_new(NULL); | ||
308 | target_stat.message_count = 0; | ||
309 | target_stat.message_unseen = 0; | ||
310 | target_stat.message_recent = 0; | ||
311 | QString p = MBOXPath+"/"+mailbox; | ||
312 | QFile fi(p); | ||
313 | if (!fi.exists()) { | ||
314 | Global::statusMessage(tr("Mailbox doesn't exist.")); | ||
315 | return; | ||
316 | } | ||
317 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
318 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
319 | r = mailfolder_connect(folder); | ||
320 | r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, | ||
321 | &target_stat.message_recent,&target_stat.message_unseen); | ||
322 | if (folder) mailfolder_free(folder); | ||
323 | if (storage) mailstorage_free(storage); | ||
324 | } | ||
diff --git a/noncore/net/mail/mboxwrapper.h b/noncore/net/mail/mboxwrapper.h index 226a544..f822997 100644 --- a/noncore/net/mail/mboxwrapper.h +++ b/noncore/net/mail/mboxwrapper.h | |||
@@ -1,41 +1,42 @@ | |||
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 | ||
7 | class RecMail; | 7 | class RecMail; |
8 | class RecBody; | 8 | class RecBody; |
9 | struct mailmbox_folder; | 9 | struct mailmbox_folder; |
10 | 10 | ||
11 | class MBOXwrapper : public Genericwrapper | 11 | class MBOXwrapper : public Genericwrapper |
12 | { | 12 | { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | public: | 14 | public: |
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 | 21 | ||
21 | virtual void deleteMail(const RecMail&mail); | 22 | virtual void deleteMail(const RecMail&mail); |
22 | virtual void answeredMail(const RecMail&mail); | 23 | virtual void answeredMail(const RecMail&mail); |
23 | 24 | ||
24 | 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); |
25 | virtual int deleteMbox(const Folder*); | 26 | virtual int deleteMbox(const Folder*); |
26 | 27 | ||
27 | 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); |
28 | 29 | ||
29 | virtual RecBody fetchBody( const RecMail &mail ); | 30 | virtual RecBody fetchBody( const RecMail &mail ); |
30 | static void mbox_progress( size_t current, size_t maximum ); | 31 | static void mbox_progress( size_t current, size_t maximum ); |
31 | 32 | ||
32 | virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); | 33 | virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); |
33 | virtual void deleteMails(const QString & mailbox,QList<RecMail> &target); | 34 | virtual void deleteMails(const QString & mailbox,QList<RecMail> &target); |
34 | virtual int deleteAllMail(const Folder*); | 35 | virtual int deleteAllMail(const Folder*); |
35 | 36 | ||
36 | protected: | 37 | protected: |
37 | static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); | 38 | static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); |
38 | QString MBOXPath; | 39 | QString MBOXPath; |
39 | }; | 40 | }; |
40 | 41 | ||
41 | #endif | 42 | #endif |
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index de90dd1..d76d82a 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp | |||
@@ -1,218 +1,229 @@ | |||
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 | ||
13 | POP3wrapper::POP3wrapper( POP3account *a ) | 13 | POP3wrapper::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 | ||
23 | POP3wrapper::~POP3wrapper() | 23 | POP3wrapper::~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 | ||
32 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 32 | void 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 | ||
37 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) | 37 | RecBody 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 | ||
99 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 99 | void 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 | ||
109 | void POP3wrapper::login() | 109 | void 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 | ||
163 | void POP3wrapper::logout() | 163 | void 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 | ||
174 | QList<Folder>* POP3wrapper::listFolders() | 174 | QList<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 | ||
183 | void POP3wrapper::deleteMail(const RecMail&mail) | 183 | void 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 | ||
193 | void POP3wrapper::answeredMail(const RecMail&) | 193 | void POP3wrapper::answeredMail(const RecMail&) |
194 | { | 194 | { |
195 | } | 195 | } |
196 | 196 | ||
197 | int POP3wrapper::deleteAllMail(const Folder*) | 197 | int 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 | |||
220 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) | ||
221 | { | ||
222 | login(); | ||
223 | target_stat.message_count = 0; | ||
224 | target_stat.message_unseen = 0; | ||
225 | target_stat.message_recent = 0; | ||
226 | if (!m_pop3) return; | ||
227 | int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, | ||
228 | &target_stat.message_recent,&target_stat.message_unseen); | ||
229 | } | ||
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index b3a42be..536cadc 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h | |||
@@ -1,37 +1,39 @@ | |||
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 | ||
8 | struct mailstorage; | 8 | struct mailstorage; |
9 | struct mailfolder; | 9 | struct mailfolder; |
10 | 10 | ||
11 | class POP3wrapper : public Genericwrapper | 11 | class POP3wrapper : public Genericwrapper |
12 | { | 12 | { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
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 */ | ||
22 | virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); | ||
21 | 23 | ||
22 | virtual void deleteMail(const RecMail&mail); | 24 | virtual void deleteMail(const RecMail&mail); |
23 | virtual void answeredMail(const RecMail&mail); | 25 | virtual void answeredMail(const RecMail&mail); |
24 | virtual int deleteAllMail(const Folder*); | 26 | virtual int deleteAllMail(const Folder*); |
25 | 27 | ||
26 | virtual RecBody fetchBody( const RecMail &mail ); | 28 | virtual RecBody fetchBody( const RecMail &mail ); |
27 | static void pop3_progress( size_t current, size_t maximum ); | 29 | static void pop3_progress( size_t current, size_t maximum ); |
28 | 30 | ||
29 | protected: | 31 | protected: |
30 | void login(); | 32 | void login(); |
31 | void logout(); | 33 | void logout(); |
32 | POP3account *account; | 34 | POP3account *account; |
33 | mailstorage*m_pop3; | 35 | mailstorage*m_pop3; |
34 | mailfolder*m_folder; | 36 | mailfolder*m_folder; |
35 | }; | 37 | }; |
36 | 38 | ||
37 | #endif | 39 | #endif |