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 | |||
@@ -5,4 +5,6 @@ | |||
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> |
@@ -67,2 +69,15 @@ QString AbstractMail::convert_String(const char*text) | |||
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 | |||
@@ -31,6 +31,9 @@ public: | |||
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 | |||
@@ -5,4 +5,6 @@ | |||
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> |
@@ -67,2 +69,15 @@ QString AbstractMail::convert_String(const char*text) | |||
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 | |||
@@ -31,6 +31,9 @@ public: | |||
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 | |||
@@ -17,4 +17,5 @@ POP3wrapper::POP3wrapper( POP3account *a ) | |||
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 | ||
@@ -26,4 +27,16 @@ POP3wrapper::~POP3wrapper() | |||
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 | ||
@@ -52,4 +65,5 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
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()) { |
@@ -406,7 +420,10 @@ QList<Folder>* POP3wrapper::listFolders() | |||
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 | ||
@@ -425,12 +442,18 @@ void POP3wrapper::answeredMail(const RecMail&) | |||
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 | ||
@@ -466,6 +489,7 @@ void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime, | |||
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 | } |
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 | |||
@@ -4,4 +4,6 @@ | |||
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; |
@@ -45,5 +47,7 @@ protected: | |||
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); |
@@ -54,4 +58,5 @@ protected: | |||
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 | ||
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 | |||
@@ -17,4 +17,5 @@ POP3wrapper::POP3wrapper( POP3account *a ) | |||
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 | ||
@@ -26,4 +27,16 @@ POP3wrapper::~POP3wrapper() | |||
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 | ||
@@ -52,4 +65,5 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
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()) { |
@@ -406,7 +420,10 @@ QList<Folder>* POP3wrapper::listFolders() | |||
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 | ||
@@ -425,12 +442,18 @@ void POP3wrapper::answeredMail(const RecMail&) | |||
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 | ||
@@ -466,6 +489,7 @@ void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime, | |||
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 | } |
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 | |||
@@ -4,4 +4,6 @@ | |||
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; |
@@ -45,5 +47,7 @@ protected: | |||
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); |
@@ -54,4 +58,5 @@ protected: | |||
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 | ||