author | alwin <alwin> | 2003-12-20 13:36:34 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-20 13:36:34 (UTC) |
commit | adb369c28cac7600b3912d6a3fdb645f1b1d571d (patch) (unidiff) | |
tree | 554fc2f00a3ea97aad6ef0382e4cc1aec3def070 | |
parent | d9ffcee06ec97f4a9e00ff0a9071d7a58e5075a1 (diff) | |
download | opie-adb369c28cac7600b3912d6a3fdb645f1b1d571d.zip opie-adb369c28cac7600b3912d6a3fdb645f1b1d571d.tar.gz opie-adb369c28cac7600b3912d6a3fdb645f1b1d571d.tar.bz2 |
fetching attachments from a pop3mail works.
this moment the whole message will be hold in memory until
I have an idea for a clean(!) filebased cache which will not get to
large.
Thats why the biggest pop3 mail we can fetch is 5MB, this should be
enough.
-rw-r--r-- | noncore/net/mail/abstractmail.cpp | 15 | ||||
-rw-r--r-- | noncore/net/mail/abstractmail.h | 3 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.cpp | 15 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 3 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 40 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 7 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 40 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 7 |
8 files changed, 112 insertions, 18 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp index 3d76c96..626b9aa 100644 --- a/noncore/net/mail/abstractmail.cpp +++ b/noncore/net/mail/abstractmail.cpp | |||
@@ -1,68 +1,83 @@ | |||
1 | #include "abstractmail.h" | 1 | #include "abstractmail.h" |
2 | #include "imapwrapper.h" | 2 | #include "imapwrapper.h" |
3 | #include "pop3wrapper.h" | 3 | #include "pop3wrapper.h" |
4 | #include "mailtypes.h" | 4 | #include "mailtypes.h" |
5 | 5 | ||
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qfile.h> | ||
8 | #include <qtextstream.h> | ||
7 | #include <stdlib.h> | 9 | #include <stdlib.h> |
8 | #include <libetpan/mailmime_content.h> | 10 | #include <libetpan/mailmime_content.h> |
9 | 11 | ||
10 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 12 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
11 | { | 13 | { |
12 | return new IMAPwrapper(a); | 14 | return new IMAPwrapper(a); |
13 | } | 15 | } |
14 | 16 | ||
15 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 17 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
16 | { | 18 | { |
17 | return new POP3wrapper(a); | 19 | return new POP3wrapper(a); |
18 | } | 20 | } |
19 | 21 | ||
20 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) | 22 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
21 | { | 23 | { |
22 | qDebug("Decode string start"); | 24 | qDebug("Decode string start"); |
23 | char*result_text; | 25 | char*result_text; |
24 | size_t index = 0; | 26 | size_t index = 0; |
25 | /* reset for recursive use! */ | 27 | /* reset for recursive use! */ |
26 | size_t target_length = 0; | 28 | size_t target_length = 0; |
27 | result_text = 0; | 29 | result_text = 0; |
28 | int mimetype = MAILMIME_MECHANISM_7BIT; | 30 | int mimetype = MAILMIME_MECHANISM_7BIT; |
29 | if (enc.lower()=="quoted-printable") { | 31 | if (enc.lower()=="quoted-printable") { |
30 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 32 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
31 | } else if (enc.lower()=="base64") { | 33 | } else if (enc.lower()=="base64") { |
32 | mimetype = MAILMIME_MECHANISM_BASE64; | 34 | mimetype = MAILMIME_MECHANISM_BASE64; |
33 | } else if (enc.lower()=="8bit") { | 35 | } else if (enc.lower()=="8bit") { |
34 | mimetype = MAILMIME_MECHANISM_8BIT; | 36 | mimetype = MAILMIME_MECHANISM_8BIT; |
35 | } else if (enc.lower()=="binary") { | 37 | } else if (enc.lower()=="binary") { |
36 | mimetype = MAILMIME_MECHANISM_BINARY; | 38 | mimetype = MAILMIME_MECHANISM_BINARY; |
37 | } | 39 | } |
38 | 40 | ||
39 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | 41 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, |
40 | &result_text,&target_length); | 42 | &result_text,&target_length); |
41 | 43 | ||
42 | encodedString* result = new encodedString(); | 44 | encodedString* result = new encodedString(); |
43 | if (err == MAILIMF_NO_ERROR) { | 45 | if (err == MAILIMF_NO_ERROR) { |
44 | result->setContent(result_text,target_length); | 46 | result->setContent(result_text,target_length); |
45 | } | 47 | } |
46 | qDebug("Decode string finished"); | 48 | qDebug("Decode string finished"); |
47 | return result; | 49 | return result; |
48 | } | 50 | } |
49 | 51 | ||
50 | QString AbstractMail::convert_String(const char*text) | 52 | QString AbstractMail::convert_String(const char*text) |
51 | { | 53 | { |
52 | size_t index = 0; | 54 | size_t index = 0; |
53 | char*res = 0; | 55 | char*res = 0; |
54 | 56 | ||
55 | /* attention - doesn't work with arm systems! */ | 57 | /* attention - doesn't work with arm systems! */ |
56 | int err = mailmime_encoded_phrase_parse("iso-8859-1", | 58 | int err = mailmime_encoded_phrase_parse("iso-8859-1", |
57 | text, strlen(text),&index, "iso-8859-1",&res); | 59 | text, strlen(text),&index, "iso-8859-1",&res); |
58 | if (err != MAILIMF_NO_ERROR) { | 60 | if (err != MAILIMF_NO_ERROR) { |
59 | if (res) free(res); | 61 | if (res) free(res); |
60 | return QString(text); | 62 | return QString(text); |
61 | } | 63 | } |
62 | if (res) { | 64 | if (res) { |
63 | QString result(res); | 65 | QString result(res); |
64 | free(res); | 66 | free(res); |
65 | return result; | 67 | return result; |
66 | } | 68 | } |
67 | return QString(text); | 69 | return QString(text); |
68 | } | 70 | } |
71 | |||
72 | /* cp & paste from launcher */ | ||
73 | QString AbstractMail::gen_attachment_id() | ||
74 | { | ||
75 | QFile file( "/proc/sys/kernel/random/uuid" ); | ||
76 | if (!file.open(IO_ReadOnly ) ) | ||
77 | return QString::null; | ||
78 | |||
79 | QTextStream stream(&file); | ||
80 | |||
81 | return "{" + stream.read().stripWhiteSpace() + "}"; | ||
82 | } | ||
83 | |||
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h index c16e9c0..8dd2e12 100644 --- a/noncore/net/mail/abstractmail.h +++ b/noncore/net/mail/abstractmail.h | |||
@@ -1,36 +1,39 @@ | |||
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 | 14 | ||
15 | class AbstractMail:public QObject | 15 | class AbstractMail:public QObject |
16 | { | 16 | { |
17 | Q_OBJECT | 17 | Q_OBJECT |
18 | public: | 18 | public: |
19 | AbstractMail(){}; | 19 | AbstractMail(){}; |
20 | virtual ~AbstractMail(){} | 20 | virtual ~AbstractMail(){} |
21 | virtual QList<Folder>* listFolders()=0; | 21 | virtual QList<Folder>* listFolders()=0; |
22 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; | 22 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; |
23 | virtual RecBody fetchBody(const RecMail&mail)=0; | 23 | virtual RecBody fetchBody(const RecMail&mail)=0; |
24 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; | 24 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; |
25 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; | 25 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; |
26 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; | 26 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; |
27 | 27 | ||
28 | virtual void deleteMail(const RecMail&mail)=0; | 28 | virtual void deleteMail(const RecMail&mail)=0; |
29 | virtual void answeredMail(const RecMail&mail)=0; | 29 | virtual void answeredMail(const RecMail&mail)=0; |
30 | 30 | ||
31 | static AbstractMail* getWrapper(IMAPaccount *a); | 31 | static AbstractMail* getWrapper(IMAPaccount *a); |
32 | static AbstractMail* getWrapper(POP3account *a); | 32 | static AbstractMail* getWrapper(POP3account *a); |
33 | |||
34 | protected: | ||
33 | static encodedString*decode_String(const encodedString*text,const QString&enc); | 35 | static encodedString*decode_String(const encodedString*text,const QString&enc); |
34 | static QString convert_String(const char*text); | 36 | static QString convert_String(const char*text); |
37 | static QString gen_attachment_id(); | ||
35 | }; | 38 | }; |
36 | #endif | 39 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp index 3d76c96..626b9aa 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.cpp +++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp | |||
@@ -1,68 +1,83 @@ | |||
1 | #include "abstractmail.h" | 1 | #include "abstractmail.h" |
2 | #include "imapwrapper.h" | 2 | #include "imapwrapper.h" |
3 | #include "pop3wrapper.h" | 3 | #include "pop3wrapper.h" |
4 | #include "mailtypes.h" | 4 | #include "mailtypes.h" |
5 | 5 | ||
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qfile.h> | ||
8 | #include <qtextstream.h> | ||
7 | #include <stdlib.h> | 9 | #include <stdlib.h> |
8 | #include <libetpan/mailmime_content.h> | 10 | #include <libetpan/mailmime_content.h> |
9 | 11 | ||
10 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) | 12 | AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) |
11 | { | 13 | { |
12 | return new IMAPwrapper(a); | 14 | return new IMAPwrapper(a); |
13 | } | 15 | } |
14 | 16 | ||
15 | AbstractMail* AbstractMail::getWrapper(POP3account *a) | 17 | AbstractMail* AbstractMail::getWrapper(POP3account *a) |
16 | { | 18 | { |
17 | return new POP3wrapper(a); | 19 | return new POP3wrapper(a); |
18 | } | 20 | } |
19 | 21 | ||
20 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) | 22 | encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) |
21 | { | 23 | { |
22 | qDebug("Decode string start"); | 24 | qDebug("Decode string start"); |
23 | char*result_text; | 25 | char*result_text; |
24 | size_t index = 0; | 26 | size_t index = 0; |
25 | /* reset for recursive use! */ | 27 | /* reset for recursive use! */ |
26 | size_t target_length = 0; | 28 | size_t target_length = 0; |
27 | result_text = 0; | 29 | result_text = 0; |
28 | int mimetype = MAILMIME_MECHANISM_7BIT; | 30 | int mimetype = MAILMIME_MECHANISM_7BIT; |
29 | if (enc.lower()=="quoted-printable") { | 31 | if (enc.lower()=="quoted-printable") { |
30 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 32 | mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
31 | } else if (enc.lower()=="base64") { | 33 | } else if (enc.lower()=="base64") { |
32 | mimetype = MAILMIME_MECHANISM_BASE64; | 34 | mimetype = MAILMIME_MECHANISM_BASE64; |
33 | } else if (enc.lower()=="8bit") { | 35 | } else if (enc.lower()=="8bit") { |
34 | mimetype = MAILMIME_MECHANISM_8BIT; | 36 | mimetype = MAILMIME_MECHANISM_8BIT; |
35 | } else if (enc.lower()=="binary") { | 37 | } else if (enc.lower()=="binary") { |
36 | mimetype = MAILMIME_MECHANISM_BINARY; | 38 | mimetype = MAILMIME_MECHANISM_BINARY; |
37 | } | 39 | } |
38 | 40 | ||
39 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, | 41 | int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, |
40 | &result_text,&target_length); | 42 | &result_text,&target_length); |
41 | 43 | ||
42 | encodedString* result = new encodedString(); | 44 | encodedString* result = new encodedString(); |
43 | if (err == MAILIMF_NO_ERROR) { | 45 | if (err == MAILIMF_NO_ERROR) { |
44 | result->setContent(result_text,target_length); | 46 | result->setContent(result_text,target_length); |
45 | } | 47 | } |
46 | qDebug("Decode string finished"); | 48 | qDebug("Decode string finished"); |
47 | return result; | 49 | return result; |
48 | } | 50 | } |
49 | 51 | ||
50 | QString AbstractMail::convert_String(const char*text) | 52 | QString AbstractMail::convert_String(const char*text) |
51 | { | 53 | { |
52 | size_t index = 0; | 54 | size_t index = 0; |
53 | char*res = 0; | 55 | char*res = 0; |
54 | 56 | ||
55 | /* attention - doesn't work with arm systems! */ | 57 | /* attention - doesn't work with arm systems! */ |
56 | int err = mailmime_encoded_phrase_parse("iso-8859-1", | 58 | int err = mailmime_encoded_phrase_parse("iso-8859-1", |
57 | text, strlen(text),&index, "iso-8859-1",&res); | 59 | text, strlen(text),&index, "iso-8859-1",&res); |
58 | if (err != MAILIMF_NO_ERROR) { | 60 | if (err != MAILIMF_NO_ERROR) { |
59 | if (res) free(res); | 61 | if (res) free(res); |
60 | return QString(text); | 62 | return QString(text); |
61 | } | 63 | } |
62 | if (res) { | 64 | if (res) { |
63 | QString result(res); | 65 | QString result(res); |
64 | free(res); | 66 | free(res); |
65 | return result; | 67 | return result; |
66 | } | 68 | } |
67 | return QString(text); | 69 | return QString(text); |
68 | } | 70 | } |
71 | |||
72 | /* cp & paste from launcher */ | ||
73 | QString AbstractMail::gen_attachment_id() | ||
74 | { | ||
75 | QFile file( "/proc/sys/kernel/random/uuid" ); | ||
76 | if (!file.open(IO_ReadOnly ) ) | ||
77 | return QString::null; | ||
78 | |||
79 | QTextStream stream(&file); | ||
80 | |||
81 | return "{" + stream.read().stripWhiteSpace() + "}"; | ||
82 | } | ||
83 | |||
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h index c16e9c0..8dd2e12 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.h +++ b/noncore/net/mail/libmailwrapper/abstractmail.h | |||
@@ -1,36 +1,39 @@ | |||
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 | 14 | ||
15 | class AbstractMail:public QObject | 15 | class AbstractMail:public QObject |
16 | { | 16 | { |
17 | Q_OBJECT | 17 | Q_OBJECT |
18 | public: | 18 | public: |
19 | AbstractMail(){}; | 19 | AbstractMail(){}; |
20 | virtual ~AbstractMail(){} | 20 | virtual ~AbstractMail(){} |
21 | virtual QList<Folder>* listFolders()=0; | 21 | virtual QList<Folder>* listFolders()=0; |
22 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; | 22 | virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; |
23 | virtual RecBody fetchBody(const RecMail&mail)=0; | 23 | virtual RecBody fetchBody(const RecMail&mail)=0; |
24 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; | 24 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; |
25 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; | 25 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; |
26 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; | 26 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; |
27 | 27 | ||
28 | virtual void deleteMail(const RecMail&mail)=0; | 28 | virtual void deleteMail(const RecMail&mail)=0; |
29 | virtual void answeredMail(const RecMail&mail)=0; | 29 | virtual void answeredMail(const RecMail&mail)=0; |
30 | 30 | ||
31 | static AbstractMail* getWrapper(IMAPaccount *a); | 31 | static AbstractMail* getWrapper(IMAPaccount *a); |
32 | static AbstractMail* getWrapper(POP3account *a); | 32 | static AbstractMail* getWrapper(POP3account *a); |
33 | |||
34 | protected: | ||
33 | static encodedString*decode_String(const encodedString*text,const QString&enc); | 35 | static encodedString*decode_String(const encodedString*text,const QString&enc); |
34 | static QString convert_String(const char*text); | 36 | static QString convert_String(const char*text); |
37 | static QString gen_attachment_id(); | ||
35 | }; | 38 | }; |
36 | #endif | 39 | #endif |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 65cd4ba..d3447f4 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,594 +1,618 @@ | |||
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/mailpop3.h> | 5 | #include <libetpan/mailpop3.h> |
6 | #include <libetpan/mailmime.h> | 6 | #include <libetpan/mailmime.h> |
7 | #include <libetpan/data_message_driver.h> | 7 | #include <libetpan/data_message_driver.h> |
8 | #include <qfile.h> | 8 | #include <qfile.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 | { | 14 | { |
15 | account = a; | 15 | account = a; |
16 | m_pop3 = NULL; | 16 | m_pop3 = NULL; |
17 | msgTempName = a->getFileName()+"_msg_cache"; | 17 | msgTempName = a->getFileName()+"_msg_cache"; |
18 | last_msg_id = 0; | 18 | last_msg_id = 0; |
19 | bodyCache.clear(); | ||
19 | } | 20 | } |
20 | 21 | ||
21 | POP3wrapper::~POP3wrapper() | 22 | POP3wrapper::~POP3wrapper() |
22 | { | 23 | { |
23 | logout(); | 24 | logout(); |
24 | QFile msg_cache(msgTempName); | 25 | QFile msg_cache(msgTempName); |
25 | if (msg_cache.exists()) { | 26 | if (msg_cache.exists()) { |
26 | msg_cache.remove(); | 27 | msg_cache.remove(); |
27 | } | 28 | } |
29 | cleanUpCache(); | ||
30 | } | ||
31 | |||
32 | void POP3wrapper::cleanUpCache() | ||
33 | { | ||
34 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | ||
35 | for (;it!=bodyCache.end();++it) { | ||
36 | encodedString*t = it.data(); | ||
37 | //it.setValue(0); | ||
38 | if (t) delete t; | ||
39 | } | ||
40 | bodyCache.clear(); | ||
28 | } | 41 | } |
29 | 42 | ||
30 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 43 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) |
31 | { | 44 | { |
32 | //qDebug( "POP3: %i of %i", current, maximum ); | 45 | //qDebug( "POP3: %i of %i", current, maximum ); |
33 | } | 46 | } |
34 | 47 | ||
35 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) | 48 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) |
36 | { | 49 | { |
37 | int err = MAILPOP3_NO_ERROR; | 50 | int err = MAILPOP3_NO_ERROR; |
38 | char *message; | 51 | char *message; |
39 | size_t length = 0; | 52 | size_t length = 0; |
40 | 53 | ||
41 | login(); | 54 | login(); |
42 | if ( !m_pop3 ) { | 55 | if ( !m_pop3 ) { |
43 | return RecBody(); | 56 | return RecBody(); |
44 | } | 57 | } |
45 | 58 | ||
46 | RecBody body; | 59 | RecBody body; |
47 | 60 | ||
48 | QFile msg_cache(msgTempName); | 61 | QFile msg_cache(msgTempName); |
49 | 62 | ||
50 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { | 63 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { |
51 | qDebug("Message to large: %i",mail.Msgsize()); | 64 | qDebug("Message to large: %i",mail.Msgsize()); |
52 | return body; | 65 | return body; |
53 | } | 66 | } |
67 | cleanUpCache(); | ||
54 | if (mail.getNumber()!=last_msg_id) { | 68 | if (mail.getNumber()!=last_msg_id) { |
55 | if (msg_cache.exists()) { | 69 | if (msg_cache.exists()) { |
56 | msg_cache.remove(); | 70 | msg_cache.remove(); |
57 | } | 71 | } |
58 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 72 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
59 | last_msg_id = mail.getNumber(); | 73 | last_msg_id = mail.getNumber(); |
60 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | 74 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); |
61 | if ( err != MAILPOP3_NO_ERROR ) { | 75 | if ( err != MAILPOP3_NO_ERROR ) { |
62 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | 76 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); |
63 | last_msg_id = 0; | 77 | last_msg_id = 0; |
64 | return RecBody(); | 78 | return RecBody(); |
65 | } | 79 | } |
66 | msg_cache.writeBlock(message,length); | 80 | msg_cache.writeBlock(message,length); |
67 | } else { | 81 | } else { |
68 | QString msg=""; | 82 | QString msg=""; |
69 | msg_cache.open(IO_ReadOnly); | 83 | msg_cache.open(IO_ReadOnly); |
70 | message = new char[4096]; | 84 | message = new char[4096]; |
71 | memset(message,0,4096); | 85 | memset(message,0,4096); |
72 | while (msg_cache.readBlock(message,4095)>0) { | 86 | while (msg_cache.readBlock(message,4095)>0) { |
73 | msg+=message; | 87 | msg+=message; |
74 | memset(message,0,4096); | 88 | memset(message,0,4096); |
75 | } | 89 | } |
76 | delete message; | 90 | delete message; |
77 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 91 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
78 | memset(message,0,msg.length()+1); | 92 | memset(message,0,msg.length()+1); |
79 | memcpy(message,msg.latin1(),msg.length()); | 93 | memcpy(message,msg.latin1(),msg.length()); |
80 | } | 94 | } |
81 | body = parseMail(message); | 95 | body = parseMail(message); |
82 | free(message); | 96 | free(message); |
83 | return body; | 97 | return body; |
84 | } | 98 | } |
85 | 99 | ||
86 | RecBody POP3wrapper::parseMail( char *message ) | 100 | RecBody POP3wrapper::parseMail( char *message ) |
87 | { | 101 | { |
88 | int err = MAILIMF_NO_ERROR; | 102 | int err = MAILIMF_NO_ERROR; |
89 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 103 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
90 | size_t curTok = 0; | 104 | size_t curTok = 0; |
91 | mailimf_message *result = 0; | 105 | mailimf_message *result = 0; |
92 | mailmessage * msg=0; | 106 | mailmessage * msg=0; |
93 | mailmime_single_fields fields; | 107 | mailmime_single_fields fields; |
94 | 108 | ||
95 | /* is bound to msg and will be freed there */ | 109 | /* is bound to msg and will be freed there */ |
96 | struct mailmime * mime=0; | 110 | struct mailmime * mime=0; |
97 | 111 | ||
98 | RecBody body; | 112 | RecBody body; |
99 | 113 | ||
100 | 114 | ||
101 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 115 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
102 | if ( err != MAILIMF_NO_ERROR ) { | 116 | if ( err != MAILIMF_NO_ERROR ) { |
103 | if (result) mailimf_message_free(result); | 117 | if (result) mailimf_message_free(result); |
104 | return body; | 118 | return body; |
105 | } | 119 | } |
106 | 120 | ||
107 | char*body_msg = message; | 121 | char*body_msg = message; |
108 | msg = mailmessage_new(); | 122 | msg = mailmessage_new(); |
109 | mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); | 123 | mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); |
110 | generic_message_t * msg_data; | 124 | generic_message_t * msg_data; |
111 | msg_data = (generic_message_t *)msg->msg_data; | 125 | msg_data = (generic_message_t *)msg->msg_data; |
112 | msg_data->msg_fetched = 1; | 126 | msg_data->msg_fetched = 1; |
113 | msg_data->msg_message = body_msg; | 127 | msg_data->msg_message = body_msg; |
114 | msg_data->msg_length = strlen(body_msg); | 128 | msg_data->msg_length = strlen(body_msg); |
115 | 129 | ||
116 | 130 | ||
117 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 131 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
118 | err = mailmessage_get_bodystructure(msg,&mime); | 132 | err = mailmessage_get_bodystructure(msg,&mime); |
119 | traverseBody(body,msg,mime); | 133 | traverseBody(body,msg,mime); |
120 | 134 | ||
121 | mailmessage_free(msg); | 135 | mailmessage_free(msg); |
122 | 136 | ||
123 | return body; | 137 | return body; |
124 | } | 138 | } |
125 | 139 | ||
126 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 140 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
127 | { | 141 | { |
128 | int err = MAILPOP3_NO_ERROR; | 142 | int err = MAILPOP3_NO_ERROR; |
129 | char * header = 0; | 143 | char * header = 0; |
130 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 144 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
131 | size_t length = 0; | 145 | size_t length = 0; |
132 | carray * messages = 0; | 146 | carray * messages = 0; |
133 | 147 | ||
134 | login(); | 148 | login(); |
135 | if (!m_pop3) return; | 149 | if (!m_pop3) return; |
136 | mailpop3_list( m_pop3, &messages ); | 150 | mailpop3_list( m_pop3, &messages ); |
137 | 151 | ||
138 | for (unsigned int i = 0; i < carray_count(messages);++i) { | 152 | for (unsigned int i = 0; i < carray_count(messages);++i) { |
139 | mailpop3_msg_info *info; | 153 | mailpop3_msg_info *info; |
140 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); | 154 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); |
141 | if (info->msg_deleted) | 155 | if (info->msg_deleted) |
142 | continue; | 156 | continue; |
143 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); | 157 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); |
144 | if ( err != MAILPOP3_NO_ERROR ) { | 158 | if ( err != MAILPOP3_NO_ERROR ) { |
145 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); | 159 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); |
146 | free(header); | 160 | free(header); |
147 | return; | 161 | return; |
148 | } | 162 | } |
149 | RecMail *mail = parseHeader( header ); | 163 | RecMail *mail = parseHeader( header ); |
150 | mail->setNumber( info->msg_index ); | 164 | mail->setNumber( info->msg_index ); |
151 | mail->setWrapper(this); | 165 | mail->setWrapper(this); |
152 | mail->setMsgsize(info->msg_size); | 166 | mail->setMsgsize(info->msg_size); |
153 | target.append( mail ); | 167 | target.append( mail ); |
154 | free(header); | 168 | free(header); |
155 | } | 169 | } |
156 | } | 170 | } |
157 | 171 | ||
158 | RecMail *POP3wrapper::parseHeader( const char *header ) | 172 | RecMail *POP3wrapper::parseHeader( const char *header ) |
159 | { | 173 | { |
160 | int err = MAILIMF_NO_ERROR; | 174 | int err = MAILIMF_NO_ERROR; |
161 | size_t curTok = 0; | 175 | size_t curTok = 0; |
162 | RecMail *mail = new RecMail(); | 176 | RecMail *mail = new RecMail(); |
163 | mailimf_fields *fields; | 177 | mailimf_fields *fields; |
164 | mailimf_references * refs; | 178 | mailimf_references * refs; |
165 | mailimf_keywords*keys; | 179 | mailimf_keywords*keys; |
166 | QString status; | 180 | QString status; |
167 | QString value; | 181 | QString value; |
168 | QBitArray mFlags(7); | 182 | QBitArray mFlags(7); |
169 | 183 | ||
170 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 184 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
171 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | 185 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { |
172 | mailimf_field *field = (mailimf_field *) current->data; | 186 | mailimf_field *field = (mailimf_field *) current->data; |
173 | switch ( field->fld_type ) { | 187 | switch ( field->fld_type ) { |
174 | case MAILIMF_FIELD_FROM: | 188 | case MAILIMF_FIELD_FROM: |
175 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | 189 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); |
176 | break; | 190 | break; |
177 | case MAILIMF_FIELD_TO: | 191 | case MAILIMF_FIELD_TO: |
178 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | 192 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); |
179 | break; | 193 | break; |
180 | case MAILIMF_FIELD_CC: | 194 | case MAILIMF_FIELD_CC: |
181 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 195 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
182 | break; | 196 | break; |
183 | case MAILIMF_FIELD_BCC: | 197 | case MAILIMF_FIELD_BCC: |
184 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 198 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
185 | break; | 199 | break; |
186 | case MAILIMF_FIELD_SUBJECT: | 200 | case MAILIMF_FIELD_SUBJECT: |
187 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); | 201 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); |
188 | break; | 202 | break; |
189 | case MAILIMF_FIELD_ORIG_DATE: | 203 | case MAILIMF_FIELD_ORIG_DATE: |
190 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 204 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
191 | break; | 205 | break; |
192 | case MAILIMF_FIELD_MESSAGE_ID: | 206 | case MAILIMF_FIELD_MESSAGE_ID: |
193 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); | 207 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); |
194 | break; | 208 | break; |
195 | case MAILIMF_FIELD_REFERENCES: | 209 | case MAILIMF_FIELD_REFERENCES: |
196 | refs = field->fld_data.fld_references; | 210 | refs = field->fld_data.fld_references; |
197 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 211 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
198 | char * text = (char*)refs->mid_list->first->data; | 212 | char * text = (char*)refs->mid_list->first->data; |
199 | mail->setReplyto(QString(text)); | 213 | mail->setReplyto(QString(text)); |
200 | } | 214 | } |
201 | break; | 215 | break; |
202 | case MAILIMF_FIELD_KEYWORDS: | 216 | case MAILIMF_FIELD_KEYWORDS: |
203 | keys = field->fld_data.fld_keywords; | 217 | keys = field->fld_data.fld_keywords; |
204 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { | 218 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { |
205 | qDebug("Keyword: %s",(char*)cur->data); | 219 | qDebug("Keyword: %s",(char*)cur->data); |
206 | } | 220 | } |
207 | break; | 221 | break; |
208 | case MAILIMF_FIELD_OPTIONAL_FIELD: | 222 | case MAILIMF_FIELD_OPTIONAL_FIELD: |
209 | status = field->fld_data.fld_optional_field->fld_name; | 223 | status = field->fld_data.fld_optional_field->fld_name; |
210 | value = field->fld_data.fld_optional_field->fld_value; | 224 | value = field->fld_data.fld_optional_field->fld_value; |
211 | if (status.lower()=="status") { | 225 | if (status.lower()=="status") { |
212 | if (value.lower()=="ro") { | 226 | if (value.lower()=="ro") { |
213 | mFlags.setBit(FLAG_SEEN); | 227 | mFlags.setBit(FLAG_SEEN); |
214 | } | 228 | } |
215 | } else if (status.lower()=="x-status") { | 229 | } else if (status.lower()=="x-status") { |
216 | qDebug("X-Status: %s",value.latin1()); | 230 | qDebug("X-Status: %s",value.latin1()); |
217 | if (value.lower()=="a") { | 231 | if (value.lower()=="a") { |
218 | mFlags.setBit(FLAG_ANSWERED); | 232 | mFlags.setBit(FLAG_ANSWERED); |
219 | } | 233 | } |
220 | } else { | 234 | } else { |
221 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, | 235 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, |
222 | // field->fld_data.fld_optional_field->fld_value); | 236 | // field->fld_data.fld_optional_field->fld_value); |
223 | } | 237 | } |
224 | break; | 238 | break; |
225 | default: | 239 | default: |
226 | qDebug("Non parsed field"); | 240 | qDebug("Non parsed field"); |
227 | break; | 241 | break; |
228 | } | 242 | } |
229 | } | 243 | } |
230 | if (fields) mailimf_fields_free(fields); | 244 | if (fields) mailimf_fields_free(fields); |
231 | mail->setFlags(mFlags); | 245 | mail->setFlags(mFlags); |
232 | return mail; | 246 | return mail; |
233 | } | 247 | } |
234 | 248 | ||
235 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) | 249 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) |
236 | { | 250 | { |
237 | char tmp[23]; | 251 | char tmp[23]; |
238 | 252 | ||
239 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 253 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
240 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 254 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
241 | 255 | ||
242 | return QString( tmp ); | 256 | return QString( tmp ); |
243 | } | 257 | } |
244 | 258 | ||
245 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) | 259 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) |
246 | { | 260 | { |
247 | QString result( "" ); | 261 | QString result( "" ); |
248 | 262 | ||
249 | bool first = true; | 263 | bool first = true; |
250 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 264 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
251 | mailimf_address *addr = (mailimf_address *) current->data; | 265 | mailimf_address *addr = (mailimf_address *) current->data; |
252 | 266 | ||
253 | if ( !first ) { | 267 | if ( !first ) { |
254 | result.append( "," ); | 268 | result.append( "," ); |
255 | } else { | 269 | } else { |
256 | first = false; | 270 | first = false; |
257 | } | 271 | } |
258 | 272 | ||
259 | switch ( addr->ad_type ) { | 273 | switch ( addr->ad_type ) { |
260 | case MAILIMF_ADDRESS_MAILBOX: | 274 | case MAILIMF_ADDRESS_MAILBOX: |
261 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 275 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
262 | break; | 276 | break; |
263 | case MAILIMF_ADDRESS_GROUP: | 277 | case MAILIMF_ADDRESS_GROUP: |
264 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 278 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
265 | break; | 279 | break; |
266 | default: | 280 | default: |
267 | qDebug( "POP3: unkown mailimf address type" ); | 281 | qDebug( "POP3: unkown mailimf address type" ); |
268 | break; | 282 | break; |
269 | } | 283 | } |
270 | } | 284 | } |
271 | 285 | ||
272 | return result; | 286 | return result; |
273 | } | 287 | } |
274 | 288 | ||
275 | QString POP3wrapper::parseGroup( mailimf_group *group ) | 289 | QString POP3wrapper::parseGroup( mailimf_group *group ) |
276 | { | 290 | { |
277 | QString result( "" ); | 291 | QString result( "" ); |
278 | 292 | ||
279 | result.append( group->grp_display_name ); | 293 | result.append( group->grp_display_name ); |
280 | result.append( ": " ); | 294 | result.append( ": " ); |
281 | 295 | ||
282 | if ( group->grp_mb_list != NULL ) { | 296 | if ( group->grp_mb_list != NULL ) { |
283 | result.append( parseMailboxList( group->grp_mb_list ) ); | 297 | result.append( parseMailboxList( group->grp_mb_list ) ); |
284 | } | 298 | } |
285 | 299 | ||
286 | result.append( ";" ); | 300 | result.append( ";" ); |
287 | 301 | ||
288 | return result; | 302 | return result; |
289 | } | 303 | } |
290 | 304 | ||
291 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) | 305 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) |
292 | { | 306 | { |
293 | QString result( "" ); | 307 | QString result( "" ); |
294 | 308 | ||
295 | if ( box->mb_display_name == NULL ) { | 309 | if ( box->mb_display_name == NULL ) { |
296 | result.append( box->mb_addr_spec ); | 310 | result.append( box->mb_addr_spec ); |
297 | } else { | 311 | } else { |
298 | result.append( convert_String(box->mb_display_name).latin1() ); | 312 | result.append( convert_String(box->mb_display_name).latin1() ); |
299 | result.append( " <" ); | 313 | result.append( " <" ); |
300 | result.append( box->mb_addr_spec ); | 314 | result.append( box->mb_addr_spec ); |
301 | result.append( ">" ); | 315 | result.append( ">" ); |
302 | } | 316 | } |
303 | 317 | ||
304 | return result; | 318 | return result; |
305 | } | 319 | } |
306 | 320 | ||
307 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) | 321 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) |
308 | { | 322 | { |
309 | QString result( "" ); | 323 | QString result( "" ); |
310 | 324 | ||
311 | bool first = true; | 325 | bool first = true; |
312 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 326 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
313 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 327 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
314 | 328 | ||
315 | if ( !first ) { | 329 | if ( !first ) { |
316 | result.append( "," ); | 330 | result.append( "," ); |
317 | } else { | 331 | } else { |
318 | first = false; | 332 | first = false; |
319 | } | 333 | } |
320 | 334 | ||
321 | result.append( parseMailbox( box ) ); | 335 | result.append( parseMailbox( box ) ); |
322 | } | 336 | } |
323 | 337 | ||
324 | return result; | 338 | return result; |
325 | } | 339 | } |
326 | 340 | ||
327 | void POP3wrapper::login() | 341 | void POP3wrapper::login() |
328 | { | 342 | { |
329 | /* we'll hold the line */ | 343 | /* we'll hold the line */ |
330 | if ( m_pop3 != NULL ) return; | 344 | if ( m_pop3 != NULL ) return; |
331 | 345 | ||
332 | const char *server, *user, *pass; | 346 | const char *server, *user, *pass; |
333 | uint16_t port; | 347 | uint16_t port; |
334 | int err = MAILPOP3_NO_ERROR; | 348 | int err = MAILPOP3_NO_ERROR; |
335 | 349 | ||
336 | server = account->getServer().latin1(); | 350 | server = account->getServer().latin1(); |
337 | port = account->getPort().toUInt(); | 351 | port = account->getPort().toUInt(); |
338 | 352 | ||
339 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 353 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
340 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 354 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
341 | login.show(); | 355 | login.show(); |
342 | if ( QDialog::Accepted == login.exec() ) { | 356 | if ( QDialog::Accepted == login.exec() ) { |
343 | // ok | 357 | // ok |
344 | user = strdup( login.getUser().latin1() ); | 358 | user = strdup( login.getUser().latin1() ); |
345 | pass = strdup( login.getPassword().latin1() ); | 359 | pass = strdup( login.getPassword().latin1() ); |
346 | } else { | 360 | } else { |
347 | // cancel | 361 | // cancel |
348 | qDebug( "POP3: Login canceled" ); | 362 | qDebug( "POP3: Login canceled" ); |
349 | return; | 363 | return; |
350 | } | 364 | } |
351 | } else { | 365 | } else { |
352 | user = account->getUser().latin1(); | 366 | user = account->getUser().latin1(); |
353 | pass = account->getPassword().latin1(); | 367 | pass = account->getPassword().latin1(); |
354 | } | 368 | } |
355 | 369 | ||
356 | m_pop3 = mailpop3_new( 200, &pop3_progress ); | 370 | m_pop3 = mailpop3_new( 200, &pop3_progress ); |
357 | 371 | ||
358 | // connect | 372 | // connect |
359 | if (account->getSSL()) { | 373 | if (account->getSSL()) { |
360 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); | 374 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); |
361 | } else { | 375 | } else { |
362 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); | 376 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); |
363 | } | 377 | } |
364 | 378 | ||
365 | if ( err != MAILPOP3_NO_ERROR ) { | 379 | if ( err != MAILPOP3_NO_ERROR ) { |
366 | qDebug( "pop3: error connecting to %s\n reason: %s", server, | 380 | qDebug( "pop3: error connecting to %s\n reason: %s", server, |
367 | m_pop3->pop3_response ); | 381 | m_pop3->pop3_response ); |
368 | mailpop3_free( m_pop3 ); | 382 | mailpop3_free( m_pop3 ); |
369 | m_pop3 = NULL; | 383 | m_pop3 = NULL; |
370 | return; | 384 | return; |
371 | } | 385 | } |
372 | qDebug( "POP3: connected!" ); | 386 | qDebug( "POP3: connected!" ); |
373 | 387 | ||
374 | // login | 388 | // login |
375 | // TODO: decide if apop or plain login should be used | 389 | // TODO: decide if apop or plain login should be used |
376 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); | 390 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); |
377 | if ( err != MAILPOP3_NO_ERROR ) { | 391 | if ( err != MAILPOP3_NO_ERROR ) { |
378 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); | 392 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); |
379 | logout(); | 393 | logout(); |
380 | return; | 394 | return; |
381 | } | 395 | } |
382 | 396 | ||
383 | qDebug( "POP3: logged in!" ); | 397 | qDebug( "POP3: logged in!" ); |
384 | } | 398 | } |
385 | 399 | ||
386 | void POP3wrapper::logout() | 400 | void POP3wrapper::logout() |
387 | { | 401 | { |
388 | int err = MAILPOP3_NO_ERROR; | 402 | int err = MAILPOP3_NO_ERROR; |
389 | if ( m_pop3 == NULL ) return; | 403 | if ( m_pop3 == NULL ) return; |
390 | err = mailpop3_quit( m_pop3 ); | 404 | err = mailpop3_quit( m_pop3 ); |
391 | mailpop3_free( m_pop3 ); | 405 | mailpop3_free( m_pop3 ); |
392 | m_pop3 = NULL; | 406 | m_pop3 = NULL; |
393 | } | 407 | } |
394 | 408 | ||
395 | 409 | ||
396 | QList<Folder>* POP3wrapper::listFolders() | 410 | QList<Folder>* POP3wrapper::listFolders() |
397 | { | 411 | { |
398 | /* TODO: integrate MH directories | 412 | /* TODO: integrate MH directories |
399 | but not before version 0.1 ;) | 413 | but not before version 0.1 ;) |
400 | */ | 414 | */ |
401 | QList<Folder> * folders = new QList<Folder>(); | 415 | QList<Folder> * folders = new QList<Folder>(); |
402 | folders->setAutoDelete( false ); | 416 | folders->setAutoDelete( false ); |
403 | Folder*inb=new Folder("INBOX","/"); | 417 | Folder*inb=new Folder("INBOX","/"); |
404 | folders->append(inb); | 418 | folders->append(inb); |
405 | return folders; | 419 | return folders; |
406 | } | 420 | } |
407 | 421 | ||
408 | QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) | 422 | QString POP3wrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
409 | { | 423 | { |
410 | return ""; | 424 | encodedString*t = fetchDecodedPart(mail,part); |
425 | QString text=t->Content(); | ||
426 | delete t; | ||
427 | return text; | ||
411 | } | 428 | } |
412 | 429 | ||
413 | void POP3wrapper::deleteMail(const RecMail&mail) | 430 | void POP3wrapper::deleteMail(const RecMail&mail) |
414 | { | 431 | { |
415 | login(); | 432 | login(); |
416 | if (!m_pop3) return; | 433 | if (!m_pop3) return; |
417 | int err = mailpop3_dele(m_pop3,mail.getNumber()); | 434 | int err = mailpop3_dele(m_pop3,mail.getNumber()); |
418 | if (err != MAILPOP3_NO_ERROR) { | 435 | if (err != MAILPOP3_NO_ERROR) { |
419 | qDebug("error deleting mail"); | 436 | qDebug("error deleting mail"); |
420 | } | 437 | } |
421 | } | 438 | } |
422 | 439 | ||
423 | void POP3wrapper::answeredMail(const RecMail&) | 440 | void POP3wrapper::answeredMail(const RecMail&) |
424 | { | 441 | { |
425 | } | 442 | } |
426 | 443 | ||
427 | encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) | 444 | encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&part) |
428 | { | 445 | { |
429 | return new encodedString(); | 446 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
447 | if (it==bodyCache.end()) return new encodedString(); | ||
448 | encodedString*t = decode_String(it.data(),part.Encoding()); | ||
449 | return t; | ||
430 | } | 450 | } |
431 | 451 | ||
432 | encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) | 452 | encodedString* POP3wrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
433 | { | 453 | { |
434 | return new encodedString(); | 454 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
455 | if (it==bodyCache.end()) return new encodedString(); | ||
456 | encodedString*t = it.data(); | ||
457 | return t; | ||
435 | } | 458 | } |
436 | 459 | ||
437 | void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) | 460 | void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) |
438 | { | 461 | { |
439 | if (current_rec >= 10) { | 462 | if (current_rec >= 10) { |
440 | qDebug("too deep recursion!"); | 463 | qDebug("too deep recursion!"); |
441 | } | 464 | } |
442 | if (!message || !mime) { | 465 | if (!message || !mime) { |
443 | return; | 466 | return; |
444 | } | 467 | } |
445 | int r; | 468 | int r; |
446 | char*data = 0; | 469 | char*data = 0; |
447 | size_t len; | 470 | size_t len; |
448 | clistiter * cur = 0; | 471 | clistiter * cur = 0; |
449 | int res; | 472 | int res; |
450 | QString b; | 473 | QString b; |
451 | RecPart part; | 474 | RecPart part; |
452 | 475 | ||
453 | switch (mime->mm_type) { | 476 | switch (mime->mm_type) { |
454 | case MAILMIME_SINGLE: | 477 | case MAILMIME_SINGLE: |
455 | r = mailmessage_fetch_section(message,mime,&data,&len); | 478 | r = mailmessage_fetch_section(message,mime,&data,&len); |
456 | part.setSize(len); | 479 | part.setSize(len); |
457 | fillSingleBody(part,message,mime); | 480 | fillSingleBody(part,message,mime); |
458 | if (part.Type()=="text" && target.Bodytext().isNull()) { | 481 | if (part.Type()=="text" && target.Bodytext().isNull()) { |
459 | encodedString*r = new encodedString(); | 482 | encodedString*r = new encodedString(); |
460 | r->setContent(data,len); | 483 | r->setContent(data,len); |
461 | encodedString*res = decode_String(r,part.Encoding()); | 484 | encodedString*res = decode_String(r,part.Encoding()); |
462 | b = QString(res->Content()); | 485 | b = QString(res->Content()); |
463 | delete r; | 486 | delete r; |
464 | delete res; | 487 | delete res; |
465 | target.setBodytext(b); | 488 | target.setBodytext(b); |
466 | target.setDescription(part); | 489 | target.setDescription(part); |
467 | } else { | 490 | } else { |
468 | /* TODO: Add the content to a list and store it for later use */ | 491 | b = gen_attachment_id(); |
469 | if (data) free(data); | 492 | part.setIdentifier(b); |
493 | bodyCache[b]=new encodedString(data,len); | ||
470 | target.addPart(part); | 494 | target.addPart(part); |
471 | } | 495 | } |
472 | break; | 496 | break; |
473 | case MAILMIME_MULTIPLE: | 497 | case MAILMIME_MULTIPLE: |
474 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 498 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
475 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); | 499 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); |
476 | } | 500 | } |
477 | break; | 501 | break; |
478 | case MAILMIME_MESSAGE: | 502 | case MAILMIME_MESSAGE: |
479 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | 503 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { |
480 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); | 504 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); |
481 | } | 505 | } |
482 | break; | 506 | break; |
483 | } | 507 | } |
484 | } | 508 | } |
485 | 509 | ||
486 | QString POP3wrapper::getencoding(mailmime_mechanism*aEnc) | 510 | QString POP3wrapper::getencoding(mailmime_mechanism*aEnc) |
487 | { | 511 | { |
488 | QString enc="7bit"; | 512 | QString enc="7bit"; |
489 | if (!aEnc) return enc; | 513 | if (!aEnc) return enc; |
490 | switch(aEnc->enc_type) { | 514 | switch(aEnc->enc_type) { |
491 | case MAILMIME_MECHANISM_7BIT: | 515 | case MAILMIME_MECHANISM_7BIT: |
492 | enc = "7bit"; | 516 | enc = "7bit"; |
493 | break; | 517 | break; |
494 | case MAILMIME_MECHANISM_8BIT: | 518 | case MAILMIME_MECHANISM_8BIT: |
495 | enc = "8bit"; | 519 | enc = "8bit"; |
496 | break; | 520 | break; |
497 | case MAILMIME_MECHANISM_BINARY: | 521 | case MAILMIME_MECHANISM_BINARY: |
498 | enc = "binary"; | 522 | enc = "binary"; |
499 | break; | 523 | break; |
500 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | 524 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: |
501 | enc = "quoted-printable"; | 525 | enc = "quoted-printable"; |
502 | break; | 526 | break; |
503 | case MAILMIME_MECHANISM_BASE64: | 527 | case MAILMIME_MECHANISM_BASE64: |
504 | enc = "base64"; | 528 | enc = "base64"; |
505 | break; | 529 | break; |
506 | case MAILMIME_MECHANISM_TOKEN: | 530 | case MAILMIME_MECHANISM_TOKEN: |
507 | default: | 531 | default: |
508 | if (aEnc->enc_token) { | 532 | if (aEnc->enc_token) { |
509 | enc = QString(aEnc->enc_token); | 533 | enc = QString(aEnc->enc_token); |
510 | } | 534 | } |
511 | break; | 535 | break; |
512 | } | 536 | } |
513 | return enc; | 537 | return enc; |
514 | } | 538 | } |
515 | 539 | ||
516 | void POP3wrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) | 540 | void POP3wrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) |
517 | { | 541 | { |
518 | if (!mime) { | 542 | if (!mime) { |
519 | return; | 543 | return; |
520 | } | 544 | } |
521 | mailmime_field*field = 0; | 545 | mailmime_field*field = 0; |
522 | mailmime_single_fields fields; | 546 | mailmime_single_fields fields; |
523 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 547 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
524 | if (mime->mm_mime_fields != NULL) { | 548 | if (mime->mm_mime_fields != NULL) { |
525 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | 549 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, |
526 | mime->mm_content_type); | 550 | mime->mm_content_type); |
527 | } | 551 | } |
528 | 552 | ||
529 | mailmime_content*type = fields.fld_content; | 553 | mailmime_content*type = fields.fld_content; |
530 | clistcell*current; | 554 | clistcell*current; |
531 | if (!type) { | 555 | if (!type) { |
532 | target.setType("text"); | 556 | target.setType("text"); |
533 | target.setSubtype("plain"); | 557 | target.setSubtype("plain"); |
534 | } else { | 558 | } else { |
535 | target.setSubtype(type->ct_subtype); | 559 | target.setSubtype(type->ct_subtype); |
536 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | 560 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { |
537 | case MAILMIME_DISCRETE_TYPE_TEXT: | 561 | case MAILMIME_DISCRETE_TYPE_TEXT: |
538 | target.setType("text"); | 562 | target.setType("text"); |
539 | break; | 563 | break; |
540 | case MAILMIME_DISCRETE_TYPE_IMAGE: | 564 | case MAILMIME_DISCRETE_TYPE_IMAGE: |
541 | target.setType("image"); | 565 | target.setType("image"); |
542 | break; | 566 | break; |
543 | case MAILMIME_DISCRETE_TYPE_AUDIO: | 567 | case MAILMIME_DISCRETE_TYPE_AUDIO: |
544 | target.setType("audio"); | 568 | target.setType("audio"); |
545 | break; | 569 | break; |
546 | case MAILMIME_DISCRETE_TYPE_VIDEO: | 570 | case MAILMIME_DISCRETE_TYPE_VIDEO: |
547 | target.setType("video"); | 571 | target.setType("video"); |
548 | break; | 572 | break; |
549 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | 573 | case MAILMIME_DISCRETE_TYPE_APPLICATION: |
550 | target.setType("application"); | 574 | target.setType("application"); |
551 | break; | 575 | break; |
552 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | 576 | case MAILMIME_DISCRETE_TYPE_EXTENSION: |
553 | default: | 577 | default: |
554 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | 578 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { |
555 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | 579 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); |
556 | } | 580 | } |
557 | break; | 581 | break; |
558 | } | 582 | } |
559 | if (type->ct_parameters) { | 583 | if (type->ct_parameters) { |
560 | fillParameters(target,type->ct_parameters); | 584 | fillParameters(target,type->ct_parameters); |
561 | } | 585 | } |
562 | } | 586 | } |
563 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | 587 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { |
564 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | 588 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { |
565 | field = (mailmime_field*)current->data; | 589 | field = (mailmime_field*)current->data; |
566 | switch(field->fld_type) { | 590 | switch(field->fld_type) { |
567 | case MAILMIME_FIELD_TRANSFER_ENCODING: | 591 | case MAILMIME_FIELD_TRANSFER_ENCODING: |
568 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); | 592 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); |
569 | break; | 593 | break; |
570 | case MAILMIME_FIELD_ID: | 594 | case MAILMIME_FIELD_ID: |
571 | target.setIdentifier(field->fld_data.fld_id); | 595 | target.setIdentifier(field->fld_data.fld_id); |
572 | break; | 596 | break; |
573 | case MAILMIME_FIELD_DESCRIPTION: | 597 | case MAILMIME_FIELD_DESCRIPTION: |
574 | target.setDescription(field->fld_data.fld_description); | 598 | target.setDescription(field->fld_data.fld_description); |
575 | break; | 599 | break; |
576 | default: | 600 | default: |
577 | break; | 601 | break; |
578 | } | 602 | } |
579 | } | 603 | } |
580 | } | 604 | } |
581 | } | 605 | } |
582 | 606 | ||
583 | void POP3wrapper::fillParameters(RecPart&target,clist*parameters) | 607 | void POP3wrapper::fillParameters(RecPart&target,clist*parameters) |
584 | { | 608 | { |
585 | if (!parameters) {return;} | 609 | if (!parameters) {return;} |
586 | clistcell*current=0; | 610 | clistcell*current=0; |
587 | mailmime_parameter*param; | 611 | mailmime_parameter*param; |
588 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | 612 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { |
589 | param = (mailmime_parameter*)current->data; | 613 | param = (mailmime_parameter*)current->data; |
590 | if (param) { | 614 | if (param) { |
591 | target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 615 | target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
592 | } | 616 | } |
593 | } | 617 | } |
594 | } | 618 | } |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index b17928e..a31a145 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h | |||
@@ -1,58 +1,63 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "abstractmail.h" | 5 | #include "abstractmail.h" |
6 | #include <qmap.h> | ||
7 | #include <qstring.h> | ||
6 | 8 | ||
7 | class RecMail; | 9 | class RecMail; |
8 | class RecBody; | 10 | class RecBody; |
9 | class encodedString; | 11 | class encodedString; |
10 | struct mailpop3; | 12 | struct mailpop3; |
11 | struct mailmessage; | 13 | struct mailmessage; |
12 | struct mailmime; | 14 | struct mailmime; |
13 | struct mailmime_mechanism; | 15 | struct mailmime_mechanism; |
14 | 16 | ||
15 | class POP3wrapper : public AbstractMail | 17 | class POP3wrapper : public AbstractMail |
16 | { | 18 | { |
17 | Q_OBJECT | 19 | Q_OBJECT |
18 | 20 | ||
19 | public: | 21 | public: |
20 | POP3wrapper( POP3account *a ); | 22 | POP3wrapper( POP3account *a ); |
21 | virtual ~POP3wrapper(); | 23 | virtual ~POP3wrapper(); |
22 | /* mailbox will be ignored */ | 24 | /* mailbox will be ignored */ |
23 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 25 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
24 | virtual QList<Folder>* listFolders(); | 26 | virtual QList<Folder>* listFolders(); |
25 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | 27 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); |
26 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | 28 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); |
27 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | 29 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); |
28 | 30 | ||
29 | virtual void deleteMail(const RecMail&mail); | 31 | virtual void deleteMail(const RecMail&mail); |
30 | virtual void answeredMail(const RecMail&mail); | 32 | virtual void answeredMail(const RecMail&mail); |
31 | 33 | ||
32 | RecBody fetchBody( const RecMail &mail ); | 34 | RecBody fetchBody( const RecMail &mail ); |
33 | static void pop3_progress( size_t current, size_t maximum ); | 35 | static void pop3_progress( size_t current, size_t maximum ); |
34 | 36 | ||
35 | protected: | 37 | protected: |
36 | void login(); | 38 | void login(); |
37 | void logout(); | 39 | void logout(); |
38 | 40 | ||
39 | RecMail *parseHeader( const char *header ); | 41 | RecMail *parseHeader( const char *header ); |
40 | RecBody parseMail( char *message ); | 42 | RecBody parseMail( char *message ); |
41 | QString parseMailboxList( mailimf_mailbox_list *list ); | 43 | QString parseMailboxList( mailimf_mailbox_list *list ); |
42 | QString parseMailbox( mailimf_mailbox *box ); | 44 | QString parseMailbox( mailimf_mailbox *box ); |
43 | QString parseGroup( mailimf_group *group ); | 45 | QString parseGroup( mailimf_group *group ); |
44 | QString parseAddressList( mailimf_address_list *list ); | 46 | QString parseAddressList( mailimf_address_list *list ); |
45 | QString parseDateTime( mailimf_date_time *date ); | 47 | QString parseDateTime( mailimf_date_time *date ); |
46 | 48 | ||
47 | static void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); | 49 | void cleanUpCache(); |
50 | |||
51 | void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); | ||
48 | static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); | 52 | static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); |
49 | static void fillParameters(RecPart&target,clist*parameters); | 53 | static void fillParameters(RecPart&target,clist*parameters); |
50 | static QString POP3wrapper::getencoding(mailmime_mechanism*aEnc); | 54 | static QString POP3wrapper::getencoding(mailmime_mechanism*aEnc); |
51 | 55 | ||
52 | POP3account *account; | 56 | POP3account *account; |
53 | mailpop3 *m_pop3; | 57 | mailpop3 *m_pop3; |
54 | QString msgTempName; | 58 | QString msgTempName; |
55 | unsigned int last_msg_id; | 59 | unsigned int last_msg_id; |
60 | QMap<QString,encodedString*> bodyCache; | ||
56 | }; | 61 | }; |
57 | 62 | ||
58 | #endif | 63 | #endif |
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index 65cd4ba..d3447f4 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp | |||
@@ -1,594 +1,618 @@ | |||
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/mailpop3.h> | 5 | #include <libetpan/mailpop3.h> |
6 | #include <libetpan/mailmime.h> | 6 | #include <libetpan/mailmime.h> |
7 | #include <libetpan/data_message_driver.h> | 7 | #include <libetpan/data_message_driver.h> |
8 | #include <qfile.h> | 8 | #include <qfile.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 | { | 14 | { |
15 | account = a; | 15 | account = a; |
16 | m_pop3 = NULL; | 16 | m_pop3 = NULL; |
17 | msgTempName = a->getFileName()+"_msg_cache"; | 17 | msgTempName = a->getFileName()+"_msg_cache"; |
18 | last_msg_id = 0; | 18 | last_msg_id = 0; |
19 | bodyCache.clear(); | ||
19 | } | 20 | } |
20 | 21 | ||
21 | POP3wrapper::~POP3wrapper() | 22 | POP3wrapper::~POP3wrapper() |
22 | { | 23 | { |
23 | logout(); | 24 | logout(); |
24 | QFile msg_cache(msgTempName); | 25 | QFile msg_cache(msgTempName); |
25 | if (msg_cache.exists()) { | 26 | if (msg_cache.exists()) { |
26 | msg_cache.remove(); | 27 | msg_cache.remove(); |
27 | } | 28 | } |
29 | cleanUpCache(); | ||
30 | } | ||
31 | |||
32 | void POP3wrapper::cleanUpCache() | ||
33 | { | ||
34 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | ||
35 | for (;it!=bodyCache.end();++it) { | ||
36 | encodedString*t = it.data(); | ||
37 | //it.setValue(0); | ||
38 | if (t) delete t; | ||
39 | } | ||
40 | bodyCache.clear(); | ||
28 | } | 41 | } |
29 | 42 | ||
30 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 43 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) |
31 | { | 44 | { |
32 | //qDebug( "POP3: %i of %i", current, maximum ); | 45 | //qDebug( "POP3: %i of %i", current, maximum ); |
33 | } | 46 | } |
34 | 47 | ||
35 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) | 48 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) |
36 | { | 49 | { |
37 | int err = MAILPOP3_NO_ERROR; | 50 | int err = MAILPOP3_NO_ERROR; |
38 | char *message; | 51 | char *message; |
39 | size_t length = 0; | 52 | size_t length = 0; |
40 | 53 | ||
41 | login(); | 54 | login(); |
42 | if ( !m_pop3 ) { | 55 | if ( !m_pop3 ) { |
43 | return RecBody(); | 56 | return RecBody(); |
44 | } | 57 | } |
45 | 58 | ||
46 | RecBody body; | 59 | RecBody body; |
47 | 60 | ||
48 | QFile msg_cache(msgTempName); | 61 | QFile msg_cache(msgTempName); |
49 | 62 | ||
50 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { | 63 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { |
51 | qDebug("Message to large: %i",mail.Msgsize()); | 64 | qDebug("Message to large: %i",mail.Msgsize()); |
52 | return body; | 65 | return body; |
53 | } | 66 | } |
67 | cleanUpCache(); | ||
54 | if (mail.getNumber()!=last_msg_id) { | 68 | if (mail.getNumber()!=last_msg_id) { |
55 | if (msg_cache.exists()) { | 69 | if (msg_cache.exists()) { |
56 | msg_cache.remove(); | 70 | msg_cache.remove(); |
57 | } | 71 | } |
58 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 72 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
59 | last_msg_id = mail.getNumber(); | 73 | last_msg_id = mail.getNumber(); |
60 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | 74 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); |
61 | if ( err != MAILPOP3_NO_ERROR ) { | 75 | if ( err != MAILPOP3_NO_ERROR ) { |
62 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | 76 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); |
63 | last_msg_id = 0; | 77 | last_msg_id = 0; |
64 | return RecBody(); | 78 | return RecBody(); |
65 | } | 79 | } |
66 | msg_cache.writeBlock(message,length); | 80 | msg_cache.writeBlock(message,length); |
67 | } else { | 81 | } else { |
68 | QString msg=""; | 82 | QString msg=""; |
69 | msg_cache.open(IO_ReadOnly); | 83 | msg_cache.open(IO_ReadOnly); |
70 | message = new char[4096]; | 84 | message = new char[4096]; |
71 | memset(message,0,4096); | 85 | memset(message,0,4096); |
72 | while (msg_cache.readBlock(message,4095)>0) { | 86 | while (msg_cache.readBlock(message,4095)>0) { |
73 | msg+=message; | 87 | msg+=message; |
74 | memset(message,0,4096); | 88 | memset(message,0,4096); |
75 | } | 89 | } |
76 | delete message; | 90 | delete message; |
77 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 91 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
78 | memset(message,0,msg.length()+1); | 92 | memset(message,0,msg.length()+1); |
79 | memcpy(message,msg.latin1(),msg.length()); | 93 | memcpy(message,msg.latin1(),msg.length()); |
80 | } | 94 | } |
81 | body = parseMail(message); | 95 | body = parseMail(message); |
82 | free(message); | 96 | free(message); |
83 | return body; | 97 | return body; |
84 | } | 98 | } |
85 | 99 | ||
86 | RecBody POP3wrapper::parseMail( char *message ) | 100 | RecBody POP3wrapper::parseMail( char *message ) |
87 | { | 101 | { |
88 | int err = MAILIMF_NO_ERROR; | 102 | int err = MAILIMF_NO_ERROR; |
89 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 103 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
90 | size_t curTok = 0; | 104 | size_t curTok = 0; |
91 | mailimf_message *result = 0; | 105 | mailimf_message *result = 0; |
92 | mailmessage * msg=0; | 106 | mailmessage * msg=0; |
93 | mailmime_single_fields fields; | 107 | mailmime_single_fields fields; |
94 | 108 | ||
95 | /* is bound to msg and will be freed there */ | 109 | /* is bound to msg and will be freed there */ |
96 | struct mailmime * mime=0; | 110 | struct mailmime * mime=0; |
97 | 111 | ||
98 | RecBody body; | 112 | RecBody body; |
99 | 113 | ||
100 | 114 | ||
101 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 115 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
102 | if ( err != MAILIMF_NO_ERROR ) { | 116 | if ( err != MAILIMF_NO_ERROR ) { |
103 | if (result) mailimf_message_free(result); | 117 | if (result) mailimf_message_free(result); |
104 | return body; | 118 | return body; |
105 | } | 119 | } |
106 | 120 | ||
107 | char*body_msg = message; | 121 | char*body_msg = message; |
108 | msg = mailmessage_new(); | 122 | msg = mailmessage_new(); |
109 | mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); | 123 | mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); |
110 | generic_message_t * msg_data; | 124 | generic_message_t * msg_data; |
111 | msg_data = (generic_message_t *)msg->msg_data; | 125 | msg_data = (generic_message_t *)msg->msg_data; |
112 | msg_data->msg_fetched = 1; | 126 | msg_data->msg_fetched = 1; |
113 | msg_data->msg_message = body_msg; | 127 | msg_data->msg_message = body_msg; |
114 | msg_data->msg_length = strlen(body_msg); | 128 | msg_data->msg_length = strlen(body_msg); |
115 | 129 | ||
116 | 130 | ||
117 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 131 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
118 | err = mailmessage_get_bodystructure(msg,&mime); | 132 | err = mailmessage_get_bodystructure(msg,&mime); |
119 | traverseBody(body,msg,mime); | 133 | traverseBody(body,msg,mime); |
120 | 134 | ||
121 | mailmessage_free(msg); | 135 | mailmessage_free(msg); |
122 | 136 | ||
123 | return body; | 137 | return body; |
124 | } | 138 | } |
125 | 139 | ||
126 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 140 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) |
127 | { | 141 | { |
128 | int err = MAILPOP3_NO_ERROR; | 142 | int err = MAILPOP3_NO_ERROR; |
129 | char * header = 0; | 143 | char * header = 0; |
130 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | 144 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ |
131 | size_t length = 0; | 145 | size_t length = 0; |
132 | carray * messages = 0; | 146 | carray * messages = 0; |
133 | 147 | ||
134 | login(); | 148 | login(); |
135 | if (!m_pop3) return; | 149 | if (!m_pop3) return; |
136 | mailpop3_list( m_pop3, &messages ); | 150 | mailpop3_list( m_pop3, &messages ); |
137 | 151 | ||
138 | for (unsigned int i = 0; i < carray_count(messages);++i) { | 152 | for (unsigned int i = 0; i < carray_count(messages);++i) { |
139 | mailpop3_msg_info *info; | 153 | mailpop3_msg_info *info; |
140 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); | 154 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); |
141 | if (info->msg_deleted) | 155 | if (info->msg_deleted) |
142 | continue; | 156 | continue; |
143 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); | 157 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); |
144 | if ( err != MAILPOP3_NO_ERROR ) { | 158 | if ( err != MAILPOP3_NO_ERROR ) { |
145 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); | 159 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); |
146 | free(header); | 160 | free(header); |
147 | return; | 161 | return; |
148 | } | 162 | } |
149 | RecMail *mail = parseHeader( header ); | 163 | RecMail *mail = parseHeader( header ); |
150 | mail->setNumber( info->msg_index ); | 164 | mail->setNumber( info->msg_index ); |
151 | mail->setWrapper(this); | 165 | mail->setWrapper(this); |
152 | mail->setMsgsize(info->msg_size); | 166 | mail->setMsgsize(info->msg_size); |
153 | target.append( mail ); | 167 | target.append( mail ); |
154 | free(header); | 168 | free(header); |
155 | } | 169 | } |
156 | } | 170 | } |
157 | 171 | ||
158 | RecMail *POP3wrapper::parseHeader( const char *header ) | 172 | RecMail *POP3wrapper::parseHeader( const char *header ) |
159 | { | 173 | { |
160 | int err = MAILIMF_NO_ERROR; | 174 | int err = MAILIMF_NO_ERROR; |
161 | size_t curTok = 0; | 175 | size_t curTok = 0; |
162 | RecMail *mail = new RecMail(); | 176 | RecMail *mail = new RecMail(); |
163 | mailimf_fields *fields; | 177 | mailimf_fields *fields; |
164 | mailimf_references * refs; | 178 | mailimf_references * refs; |
165 | mailimf_keywords*keys; | 179 | mailimf_keywords*keys; |
166 | QString status; | 180 | QString status; |
167 | QString value; | 181 | QString value; |
168 | QBitArray mFlags(7); | 182 | QBitArray mFlags(7); |
169 | 183 | ||
170 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 184 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
171 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | 185 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { |
172 | mailimf_field *field = (mailimf_field *) current->data; | 186 | mailimf_field *field = (mailimf_field *) current->data; |
173 | switch ( field->fld_type ) { | 187 | switch ( field->fld_type ) { |
174 | case MAILIMF_FIELD_FROM: | 188 | case MAILIMF_FIELD_FROM: |
175 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | 189 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); |
176 | break; | 190 | break; |
177 | case MAILIMF_FIELD_TO: | 191 | case MAILIMF_FIELD_TO: |
178 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | 192 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); |
179 | break; | 193 | break; |
180 | case MAILIMF_FIELD_CC: | 194 | case MAILIMF_FIELD_CC: |
181 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 195 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
182 | break; | 196 | break; |
183 | case MAILIMF_FIELD_BCC: | 197 | case MAILIMF_FIELD_BCC: |
184 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 198 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
185 | break; | 199 | break; |
186 | case MAILIMF_FIELD_SUBJECT: | 200 | case MAILIMF_FIELD_SUBJECT: |
187 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); | 201 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); |
188 | break; | 202 | break; |
189 | case MAILIMF_FIELD_ORIG_DATE: | 203 | case MAILIMF_FIELD_ORIG_DATE: |
190 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 204 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
191 | break; | 205 | break; |
192 | case MAILIMF_FIELD_MESSAGE_ID: | 206 | case MAILIMF_FIELD_MESSAGE_ID: |
193 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); | 207 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); |
194 | break; | 208 | break; |
195 | case MAILIMF_FIELD_REFERENCES: | 209 | case MAILIMF_FIELD_REFERENCES: |
196 | refs = field->fld_data.fld_references; | 210 | refs = field->fld_data.fld_references; |
197 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 211 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
198 | char * text = (char*)refs->mid_list->first->data; | 212 | char * text = (char*)refs->mid_list->first->data; |
199 | mail->setReplyto(QString(text)); | 213 | mail->setReplyto(QString(text)); |
200 | } | 214 | } |
201 | break; | 215 | break; |
202 | case MAILIMF_FIELD_KEYWORDS: | 216 | case MAILIMF_FIELD_KEYWORDS: |
203 | keys = field->fld_data.fld_keywords; | 217 | keys = field->fld_data.fld_keywords; |
204 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { | 218 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { |
205 | qDebug("Keyword: %s",(char*)cur->data); | 219 | qDebug("Keyword: %s",(char*)cur->data); |
206 | } | 220 | } |
207 | break; | 221 | break; |
208 | case MAILIMF_FIELD_OPTIONAL_FIELD: | 222 | case MAILIMF_FIELD_OPTIONAL_FIELD: |
209 | status = field->fld_data.fld_optional_field->fld_name; | 223 | status = field->fld_data.fld_optional_field->fld_name; |
210 | value = field->fld_data.fld_optional_field->fld_value; | 224 | value = field->fld_data.fld_optional_field->fld_value; |
211 | if (status.lower()=="status") { | 225 | if (status.lower()=="status") { |
212 | if (value.lower()=="ro") { | 226 | if (value.lower()=="ro") { |
213 | mFlags.setBit(FLAG_SEEN); | 227 | mFlags.setBit(FLAG_SEEN); |
214 | } | 228 | } |
215 | } else if (status.lower()=="x-status") { | 229 | } else if (status.lower()=="x-status") { |
216 | qDebug("X-Status: %s",value.latin1()); | 230 | qDebug("X-Status: %s",value.latin1()); |
217 | if (value.lower()=="a") { | 231 | if (value.lower()=="a") { |
218 | mFlags.setBit(FLAG_ANSWERED); | 232 | mFlags.setBit(FLAG_ANSWERED); |
219 | } | 233 | } |
220 | } else { | 234 | } else { |
221 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, | 235 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, |
222 | // field->fld_data.fld_optional_field->fld_value); | 236 | // field->fld_data.fld_optional_field->fld_value); |
223 | } | 237 | } |
224 | break; | 238 | break; |
225 | default: | 239 | default: |
226 | qDebug("Non parsed field"); | 240 | qDebug("Non parsed field"); |
227 | break; | 241 | break; |
228 | } | 242 | } |
229 | } | 243 | } |
230 | if (fields) mailimf_fields_free(fields); | 244 | if (fields) mailimf_fields_free(fields); |
231 | mail->setFlags(mFlags); | 245 | mail->setFlags(mFlags); |
232 | return mail; | 246 | return mail; |
233 | } | 247 | } |
234 | 248 | ||
235 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) | 249 | QString POP3wrapper::parseDateTime( mailimf_date_time *date ) |
236 | { | 250 | { |
237 | char tmp[23]; | 251 | char tmp[23]; |
238 | 252 | ||
239 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 253 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
240 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 254 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
241 | 255 | ||
242 | return QString( tmp ); | 256 | return QString( tmp ); |
243 | } | 257 | } |
244 | 258 | ||
245 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) | 259 | QString POP3wrapper::parseAddressList( mailimf_address_list *list ) |
246 | { | 260 | { |
247 | QString result( "" ); | 261 | QString result( "" ); |
248 | 262 | ||
249 | bool first = true; | 263 | bool first = true; |
250 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 264 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
251 | mailimf_address *addr = (mailimf_address *) current->data; | 265 | mailimf_address *addr = (mailimf_address *) current->data; |
252 | 266 | ||
253 | if ( !first ) { | 267 | if ( !first ) { |
254 | result.append( "," ); | 268 | result.append( "," ); |
255 | } else { | 269 | } else { |
256 | first = false; | 270 | first = false; |
257 | } | 271 | } |
258 | 272 | ||
259 | switch ( addr->ad_type ) { | 273 | switch ( addr->ad_type ) { |
260 | case MAILIMF_ADDRESS_MAILBOX: | 274 | case MAILIMF_ADDRESS_MAILBOX: |
261 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 275 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
262 | break; | 276 | break; |
263 | case MAILIMF_ADDRESS_GROUP: | 277 | case MAILIMF_ADDRESS_GROUP: |
264 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 278 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
265 | break; | 279 | break; |
266 | default: | 280 | default: |
267 | qDebug( "POP3: unkown mailimf address type" ); | 281 | qDebug( "POP3: unkown mailimf address type" ); |
268 | break; | 282 | break; |
269 | } | 283 | } |
270 | } | 284 | } |
271 | 285 | ||
272 | return result; | 286 | return result; |
273 | } | 287 | } |
274 | 288 | ||
275 | QString POP3wrapper::parseGroup( mailimf_group *group ) | 289 | QString POP3wrapper::parseGroup( mailimf_group *group ) |
276 | { | 290 | { |
277 | QString result( "" ); | 291 | QString result( "" ); |
278 | 292 | ||
279 | result.append( group->grp_display_name ); | 293 | result.append( group->grp_display_name ); |
280 | result.append( ": " ); | 294 | result.append( ": " ); |
281 | 295 | ||
282 | if ( group->grp_mb_list != NULL ) { | 296 | if ( group->grp_mb_list != NULL ) { |
283 | result.append( parseMailboxList( group->grp_mb_list ) ); | 297 | result.append( parseMailboxList( group->grp_mb_list ) ); |
284 | } | 298 | } |
285 | 299 | ||
286 | result.append( ";" ); | 300 | result.append( ";" ); |
287 | 301 | ||
288 | return result; | 302 | return result; |
289 | } | 303 | } |
290 | 304 | ||
291 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) | 305 | QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) |
292 | { | 306 | { |
293 | QString result( "" ); | 307 | QString result( "" ); |
294 | 308 | ||
295 | if ( box->mb_display_name == NULL ) { | 309 | if ( box->mb_display_name == NULL ) { |
296 | result.append( box->mb_addr_spec ); | 310 | result.append( box->mb_addr_spec ); |
297 | } else { | 311 | } else { |
298 | result.append( convert_String(box->mb_display_name).latin1() ); | 312 | result.append( convert_String(box->mb_display_name).latin1() ); |
299 | result.append( " <" ); | 313 | result.append( " <" ); |
300 | result.append( box->mb_addr_spec ); | 314 | result.append( box->mb_addr_spec ); |
301 | result.append( ">" ); | 315 | result.append( ">" ); |
302 | } | 316 | } |
303 | 317 | ||
304 | return result; | 318 | return result; |
305 | } | 319 | } |
306 | 320 | ||
307 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) | 321 | QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) |
308 | { | 322 | { |
309 | QString result( "" ); | 323 | QString result( "" ); |
310 | 324 | ||
311 | bool first = true; | 325 | bool first = true; |
312 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 326 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
313 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 327 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
314 | 328 | ||
315 | if ( !first ) { | 329 | if ( !first ) { |
316 | result.append( "," ); | 330 | result.append( "," ); |
317 | } else { | 331 | } else { |
318 | first = false; | 332 | first = false; |
319 | } | 333 | } |
320 | 334 | ||
321 | result.append( parseMailbox( box ) ); | 335 | result.append( parseMailbox( box ) ); |
322 | } | 336 | } |
323 | 337 | ||
324 | return result; | 338 | return result; |
325 | } | 339 | } |
326 | 340 | ||
327 | void POP3wrapper::login() | 341 | void POP3wrapper::login() |
328 | { | 342 | { |
329 | /* we'll hold the line */ | 343 | /* we'll hold the line */ |
330 | if ( m_pop3 != NULL ) return; | 344 | if ( m_pop3 != NULL ) return; |
331 | 345 | ||
332 | const char *server, *user, *pass; | 346 | const char *server, *user, *pass; |
333 | uint16_t port; | 347 | uint16_t port; |
334 | int err = MAILPOP3_NO_ERROR; | 348 | int err = MAILPOP3_NO_ERROR; |
335 | 349 | ||
336 | server = account->getServer().latin1(); | 350 | server = account->getServer().latin1(); |
337 | port = account->getPort().toUInt(); | 351 | port = account->getPort().toUInt(); |
338 | 352 | ||
339 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 353 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
340 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 354 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
341 | login.show(); | 355 | login.show(); |
342 | if ( QDialog::Accepted == login.exec() ) { | 356 | if ( QDialog::Accepted == login.exec() ) { |
343 | // ok | 357 | // ok |
344 | user = strdup( login.getUser().latin1() ); | 358 | user = strdup( login.getUser().latin1() ); |
345 | pass = strdup( login.getPassword().latin1() ); | 359 | pass = strdup( login.getPassword().latin1() ); |
346 | } else { | 360 | } else { |
347 | // cancel | 361 | // cancel |
348 | qDebug( "POP3: Login canceled" ); | 362 | qDebug( "POP3: Login canceled" ); |
349 | return; | 363 | return; |
350 | } | 364 | } |
351 | } else { | 365 | } else { |
352 | user = account->getUser().latin1(); | 366 | user = account->getUser().latin1(); |
353 | pass = account->getPassword().latin1(); | 367 | pass = account->getPassword().latin1(); |
354 | } | 368 | } |
355 | 369 | ||
356 | m_pop3 = mailpop3_new( 200, &pop3_progress ); | 370 | m_pop3 = mailpop3_new( 200, &pop3_progress ); |
357 | 371 | ||
358 | // connect | 372 | // connect |
359 | if (account->getSSL()) { | 373 | if (account->getSSL()) { |
360 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); | 374 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); |
361 | } else { | 375 | } else { |
362 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); | 376 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); |
363 | } | 377 | } |
364 | 378 | ||
365 | if ( err != MAILPOP3_NO_ERROR ) { | 379 | if ( err != MAILPOP3_NO_ERROR ) { |
366 | qDebug( "pop3: error connecting to %s\n reason: %s", server, | 380 | qDebug( "pop3: error connecting to %s\n reason: %s", server, |
367 | m_pop3->pop3_response ); | 381 | m_pop3->pop3_response ); |
368 | mailpop3_free( m_pop3 ); | 382 | mailpop3_free( m_pop3 ); |
369 | m_pop3 = NULL; | 383 | m_pop3 = NULL; |
370 | return; | 384 | return; |
371 | } | 385 | } |
372 | qDebug( "POP3: connected!" ); | 386 | qDebug( "POP3: connected!" ); |
373 | 387 | ||
374 | // login | 388 | // login |
375 | // TODO: decide if apop or plain login should be used | 389 | // TODO: decide if apop or plain login should be used |
376 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); | 390 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); |
377 | if ( err != MAILPOP3_NO_ERROR ) { | 391 | if ( err != MAILPOP3_NO_ERROR ) { |
378 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); | 392 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); |
379 | logout(); | 393 | logout(); |
380 | return; | 394 | return; |
381 | } | 395 | } |
382 | 396 | ||
383 | qDebug( "POP3: logged in!" ); | 397 | qDebug( "POP3: logged in!" ); |
384 | } | 398 | } |
385 | 399 | ||
386 | void POP3wrapper::logout() | 400 | void POP3wrapper::logout() |
387 | { | 401 | { |
388 | int err = MAILPOP3_NO_ERROR; | 402 | int err = MAILPOP3_NO_ERROR; |
389 | if ( m_pop3 == NULL ) return; | 403 | if ( m_pop3 == NULL ) return; |
390 | err = mailpop3_quit( m_pop3 ); | 404 | err = mailpop3_quit( m_pop3 ); |
391 | mailpop3_free( m_pop3 ); | 405 | mailpop3_free( m_pop3 ); |
392 | m_pop3 = NULL; | 406 | m_pop3 = NULL; |
393 | } | 407 | } |
394 | 408 | ||
395 | 409 | ||
396 | QList<Folder>* POP3wrapper::listFolders() | 410 | QList<Folder>* POP3wrapper::listFolders() |
397 | { | 411 | { |
398 | /* TODO: integrate MH directories | 412 | /* TODO: integrate MH directories |
399 | but not before version 0.1 ;) | 413 | but not before version 0.1 ;) |
400 | */ | 414 | */ |
401 | QList<Folder> * folders = new QList<Folder>(); | 415 | QList<Folder> * folders = new QList<Folder>(); |
402 | folders->setAutoDelete( false ); | 416 | folders->setAutoDelete( false ); |
403 | Folder*inb=new Folder("INBOX","/"); | 417 | Folder*inb=new Folder("INBOX","/"); |
404 | folders->append(inb); | 418 | folders->append(inb); |
405 | return folders; | 419 | return folders; |
406 | } | 420 | } |
407 | 421 | ||
408 | QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) | 422 | QString POP3wrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
409 | { | 423 | { |
410 | return ""; | 424 | encodedString*t = fetchDecodedPart(mail,part); |
425 | QString text=t->Content(); | ||
426 | delete t; | ||
427 | return text; | ||
411 | } | 428 | } |
412 | 429 | ||
413 | void POP3wrapper::deleteMail(const RecMail&mail) | 430 | void POP3wrapper::deleteMail(const RecMail&mail) |
414 | { | 431 | { |
415 | login(); | 432 | login(); |
416 | if (!m_pop3) return; | 433 | if (!m_pop3) return; |
417 | int err = mailpop3_dele(m_pop3,mail.getNumber()); | 434 | int err = mailpop3_dele(m_pop3,mail.getNumber()); |
418 | if (err != MAILPOP3_NO_ERROR) { | 435 | if (err != MAILPOP3_NO_ERROR) { |
419 | qDebug("error deleting mail"); | 436 | qDebug("error deleting mail"); |
420 | } | 437 | } |
421 | } | 438 | } |
422 | 439 | ||
423 | void POP3wrapper::answeredMail(const RecMail&) | 440 | void POP3wrapper::answeredMail(const RecMail&) |
424 | { | 441 | { |
425 | } | 442 | } |
426 | 443 | ||
427 | encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) | 444 | encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&part) |
428 | { | 445 | { |
429 | return new encodedString(); | 446 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
447 | if (it==bodyCache.end()) return new encodedString(); | ||
448 | encodedString*t = decode_String(it.data(),part.Encoding()); | ||
449 | return t; | ||
430 | } | 450 | } |
431 | 451 | ||
432 | encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) | 452 | encodedString* POP3wrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
433 | { | 453 | { |
434 | return new encodedString(); | 454 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
455 | if (it==bodyCache.end()) return new encodedString(); | ||
456 | encodedString*t = it.data(); | ||
457 | return t; | ||
435 | } | 458 | } |
436 | 459 | ||
437 | void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) | 460 | void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) |
438 | { | 461 | { |
439 | if (current_rec >= 10) { | 462 | if (current_rec >= 10) { |
440 | qDebug("too deep recursion!"); | 463 | qDebug("too deep recursion!"); |
441 | } | 464 | } |
442 | if (!message || !mime) { | 465 | if (!message || !mime) { |
443 | return; | 466 | return; |
444 | } | 467 | } |
445 | int r; | 468 | int r; |
446 | char*data = 0; | 469 | char*data = 0; |
447 | size_t len; | 470 | size_t len; |
448 | clistiter * cur = 0; | 471 | clistiter * cur = 0; |
449 | int res; | 472 | int res; |
450 | QString b; | 473 | QString b; |
451 | RecPart part; | 474 | RecPart part; |
452 | 475 | ||
453 | switch (mime->mm_type) { | 476 | switch (mime->mm_type) { |
454 | case MAILMIME_SINGLE: | 477 | case MAILMIME_SINGLE: |
455 | r = mailmessage_fetch_section(message,mime,&data,&len); | 478 | r = mailmessage_fetch_section(message,mime,&data,&len); |
456 | part.setSize(len); | 479 | part.setSize(len); |
457 | fillSingleBody(part,message,mime); | 480 | fillSingleBody(part,message,mime); |
458 | if (part.Type()=="text" && target.Bodytext().isNull()) { | 481 | if (part.Type()=="text" && target.Bodytext().isNull()) { |
459 | encodedString*r = new encodedString(); | 482 | encodedString*r = new encodedString(); |
460 | r->setContent(data,len); | 483 | r->setContent(data,len); |
461 | encodedString*res = decode_String(r,part.Encoding()); | 484 | encodedString*res = decode_String(r,part.Encoding()); |
462 | b = QString(res->Content()); | 485 | b = QString(res->Content()); |
463 | delete r; | 486 | delete r; |
464 | delete res; | 487 | delete res; |
465 | target.setBodytext(b); | 488 | target.setBodytext(b); |
466 | target.setDescription(part); | 489 | target.setDescription(part); |
467 | } else { | 490 | } else { |
468 | /* TODO: Add the content to a list and store it for later use */ | 491 | b = gen_attachment_id(); |
469 | if (data) free(data); | 492 | part.setIdentifier(b); |
493 | bodyCache[b]=new encodedString(data,len); | ||
470 | target.addPart(part); | 494 | target.addPart(part); |
471 | } | 495 | } |
472 | break; | 496 | break; |
473 | case MAILMIME_MULTIPLE: | 497 | case MAILMIME_MULTIPLE: |
474 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 498 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
475 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); | 499 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); |
476 | } | 500 | } |
477 | break; | 501 | break; |
478 | case MAILMIME_MESSAGE: | 502 | case MAILMIME_MESSAGE: |
479 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | 503 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { |
480 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); | 504 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); |
481 | } | 505 | } |
482 | break; | 506 | break; |
483 | } | 507 | } |
484 | } | 508 | } |
485 | 509 | ||
486 | QString POP3wrapper::getencoding(mailmime_mechanism*aEnc) | 510 | QString POP3wrapper::getencoding(mailmime_mechanism*aEnc) |
487 | { | 511 | { |
488 | QString enc="7bit"; | 512 | QString enc="7bit"; |
489 | if (!aEnc) return enc; | 513 | if (!aEnc) return enc; |
490 | switch(aEnc->enc_type) { | 514 | switch(aEnc->enc_type) { |
491 | case MAILMIME_MECHANISM_7BIT: | 515 | case MAILMIME_MECHANISM_7BIT: |
492 | enc = "7bit"; | 516 | enc = "7bit"; |
493 | break; | 517 | break; |
494 | case MAILMIME_MECHANISM_8BIT: | 518 | case MAILMIME_MECHANISM_8BIT: |
495 | enc = "8bit"; | 519 | enc = "8bit"; |
496 | break; | 520 | break; |
497 | case MAILMIME_MECHANISM_BINARY: | 521 | case MAILMIME_MECHANISM_BINARY: |
498 | enc = "binary"; | 522 | enc = "binary"; |
499 | break; | 523 | break; |
500 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | 524 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: |
501 | enc = "quoted-printable"; | 525 | enc = "quoted-printable"; |
502 | break; | 526 | break; |
503 | case MAILMIME_MECHANISM_BASE64: | 527 | case MAILMIME_MECHANISM_BASE64: |
504 | enc = "base64"; | 528 | enc = "base64"; |
505 | break; | 529 | break; |
506 | case MAILMIME_MECHANISM_TOKEN: | 530 | case MAILMIME_MECHANISM_TOKEN: |
507 | default: | 531 | default: |
508 | if (aEnc->enc_token) { | 532 | if (aEnc->enc_token) { |
509 | enc = QString(aEnc->enc_token); | 533 | enc = QString(aEnc->enc_token); |
510 | } | 534 | } |
511 | break; | 535 | break; |
512 | } | 536 | } |
513 | return enc; | 537 | return enc; |
514 | } | 538 | } |
515 | 539 | ||
516 | void POP3wrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) | 540 | void POP3wrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) |
517 | { | 541 | { |
518 | if (!mime) { | 542 | if (!mime) { |
519 | return; | 543 | return; |
520 | } | 544 | } |
521 | mailmime_field*field = 0; | 545 | mailmime_field*field = 0; |
522 | mailmime_single_fields fields; | 546 | mailmime_single_fields fields; |
523 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 547 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
524 | if (mime->mm_mime_fields != NULL) { | 548 | if (mime->mm_mime_fields != NULL) { |
525 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | 549 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, |
526 | mime->mm_content_type); | 550 | mime->mm_content_type); |
527 | } | 551 | } |
528 | 552 | ||
529 | mailmime_content*type = fields.fld_content; | 553 | mailmime_content*type = fields.fld_content; |
530 | clistcell*current; | 554 | clistcell*current; |
531 | if (!type) { | 555 | if (!type) { |
532 | target.setType("text"); | 556 | target.setType("text"); |
533 | target.setSubtype("plain"); | 557 | target.setSubtype("plain"); |
534 | } else { | 558 | } else { |
535 | target.setSubtype(type->ct_subtype); | 559 | target.setSubtype(type->ct_subtype); |
536 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | 560 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { |
537 | case MAILMIME_DISCRETE_TYPE_TEXT: | 561 | case MAILMIME_DISCRETE_TYPE_TEXT: |
538 | target.setType("text"); | 562 | target.setType("text"); |
539 | break; | 563 | break; |
540 | case MAILMIME_DISCRETE_TYPE_IMAGE: | 564 | case MAILMIME_DISCRETE_TYPE_IMAGE: |
541 | target.setType("image"); | 565 | target.setType("image"); |
542 | break; | 566 | break; |
543 | case MAILMIME_DISCRETE_TYPE_AUDIO: | 567 | case MAILMIME_DISCRETE_TYPE_AUDIO: |
544 | target.setType("audio"); | 568 | target.setType("audio"); |
545 | break; | 569 | break; |
546 | case MAILMIME_DISCRETE_TYPE_VIDEO: | 570 | case MAILMIME_DISCRETE_TYPE_VIDEO: |
547 | target.setType("video"); | 571 | target.setType("video"); |
548 | break; | 572 | break; |
549 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | 573 | case MAILMIME_DISCRETE_TYPE_APPLICATION: |
550 | target.setType("application"); | 574 | target.setType("application"); |
551 | break; | 575 | break; |
552 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | 576 | case MAILMIME_DISCRETE_TYPE_EXTENSION: |
553 | default: | 577 | default: |
554 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | 578 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { |
555 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | 579 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); |
556 | } | 580 | } |
557 | break; | 581 | break; |
558 | } | 582 | } |
559 | if (type->ct_parameters) { | 583 | if (type->ct_parameters) { |
560 | fillParameters(target,type->ct_parameters); | 584 | fillParameters(target,type->ct_parameters); |
561 | } | 585 | } |
562 | } | 586 | } |
563 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | 587 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { |
564 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | 588 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { |
565 | field = (mailmime_field*)current->data; | 589 | field = (mailmime_field*)current->data; |
566 | switch(field->fld_type) { | 590 | switch(field->fld_type) { |
567 | case MAILMIME_FIELD_TRANSFER_ENCODING: | 591 | case MAILMIME_FIELD_TRANSFER_ENCODING: |
568 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); | 592 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); |
569 | break; | 593 | break; |
570 | case MAILMIME_FIELD_ID: | 594 | case MAILMIME_FIELD_ID: |
571 | target.setIdentifier(field->fld_data.fld_id); | 595 | target.setIdentifier(field->fld_data.fld_id); |
572 | break; | 596 | break; |
573 | case MAILMIME_FIELD_DESCRIPTION: | 597 | case MAILMIME_FIELD_DESCRIPTION: |
574 | target.setDescription(field->fld_data.fld_description); | 598 | target.setDescription(field->fld_data.fld_description); |
575 | break; | 599 | break; |
576 | default: | 600 | default: |
577 | break; | 601 | break; |
578 | } | 602 | } |
579 | } | 603 | } |
580 | } | 604 | } |
581 | } | 605 | } |
582 | 606 | ||
583 | void POP3wrapper::fillParameters(RecPart&target,clist*parameters) | 607 | void POP3wrapper::fillParameters(RecPart&target,clist*parameters) |
584 | { | 608 | { |
585 | if (!parameters) {return;} | 609 | if (!parameters) {return;} |
586 | clistcell*current=0; | 610 | clistcell*current=0; |
587 | mailmime_parameter*param; | 611 | mailmime_parameter*param; |
588 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { | 612 | for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { |
589 | param = (mailmime_parameter*)current->data; | 613 | param = (mailmime_parameter*)current->data; |
590 | if (param) { | 614 | if (param) { |
591 | target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 615 | target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
592 | } | 616 | } |
593 | } | 617 | } |
594 | } | 618 | } |
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index b17928e..a31a145 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h | |||
@@ -1,58 +1,63 @@ | |||
1 | #ifndef __POP3WRAPPER | 1 | #ifndef __POP3WRAPPER |
2 | #define __POP3WRAPPER | 2 | #define __POP3WRAPPER |
3 | 3 | ||
4 | #include "mailwrapper.h" | 4 | #include "mailwrapper.h" |
5 | #include "abstractmail.h" | 5 | #include "abstractmail.h" |
6 | #include <qmap.h> | ||
7 | #include <qstring.h> | ||
6 | 8 | ||
7 | class RecMail; | 9 | class RecMail; |
8 | class RecBody; | 10 | class RecBody; |
9 | class encodedString; | 11 | class encodedString; |
10 | struct mailpop3; | 12 | struct mailpop3; |
11 | struct mailmessage; | 13 | struct mailmessage; |
12 | struct mailmime; | 14 | struct mailmime; |
13 | struct mailmime_mechanism; | 15 | struct mailmime_mechanism; |
14 | 16 | ||
15 | class POP3wrapper : public AbstractMail | 17 | class POP3wrapper : public AbstractMail |
16 | { | 18 | { |
17 | Q_OBJECT | 19 | Q_OBJECT |
18 | 20 | ||
19 | public: | 21 | public: |
20 | POP3wrapper( POP3account *a ); | 22 | POP3wrapper( POP3account *a ); |
21 | virtual ~POP3wrapper(); | 23 | virtual ~POP3wrapper(); |
22 | /* mailbox will be ignored */ | 24 | /* mailbox will be ignored */ |
23 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); | 25 | virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); |
24 | virtual QList<Folder>* listFolders(); | 26 | virtual QList<Folder>* listFolders(); |
25 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); | 27 | virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); |
26 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); | 28 | virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); |
27 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); | 29 | virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); |
28 | 30 | ||
29 | virtual void deleteMail(const RecMail&mail); | 31 | virtual void deleteMail(const RecMail&mail); |
30 | virtual void answeredMail(const RecMail&mail); | 32 | virtual void answeredMail(const RecMail&mail); |
31 | 33 | ||
32 | RecBody fetchBody( const RecMail &mail ); | 34 | RecBody fetchBody( const RecMail &mail ); |
33 | static void pop3_progress( size_t current, size_t maximum ); | 35 | static void pop3_progress( size_t current, size_t maximum ); |
34 | 36 | ||
35 | protected: | 37 | protected: |
36 | void login(); | 38 | void login(); |
37 | void logout(); | 39 | void logout(); |
38 | 40 | ||
39 | RecMail *parseHeader( const char *header ); | 41 | RecMail *parseHeader( const char *header ); |
40 | RecBody parseMail( char *message ); | 42 | RecBody parseMail( char *message ); |
41 | QString parseMailboxList( mailimf_mailbox_list *list ); | 43 | QString parseMailboxList( mailimf_mailbox_list *list ); |
42 | QString parseMailbox( mailimf_mailbox *box ); | 44 | QString parseMailbox( mailimf_mailbox *box ); |
43 | QString parseGroup( mailimf_group *group ); | 45 | QString parseGroup( mailimf_group *group ); |
44 | QString parseAddressList( mailimf_address_list *list ); | 46 | QString parseAddressList( mailimf_address_list *list ); |
45 | QString parseDateTime( mailimf_date_time *date ); | 47 | QString parseDateTime( mailimf_date_time *date ); |
46 | 48 | ||
47 | static void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); | 49 | void cleanUpCache(); |
50 | |||
51 | void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); | ||
48 | static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); | 52 | static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); |
49 | static void fillParameters(RecPart&target,clist*parameters); | 53 | static void fillParameters(RecPart&target,clist*parameters); |
50 | static QString POP3wrapper::getencoding(mailmime_mechanism*aEnc); | 54 | static QString POP3wrapper::getencoding(mailmime_mechanism*aEnc); |
51 | 55 | ||
52 | POP3account *account; | 56 | POP3account *account; |
53 | mailpop3 *m_pop3; | 57 | mailpop3 *m_pop3; |
54 | QString msgTempName; | 58 | QString msgTempName; |
55 | unsigned int last_msg_id; | 59 | unsigned int last_msg_id; |
60 | QMap<QString,encodedString*> bodyCache; | ||
56 | }; | 61 | }; |
57 | 62 | ||
58 | #endif | 63 | #endif |