-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 @@ -6,2 +6,4 @@ #include <qstring.h> +#include <qfile.h> +#include <qtextstream.h> #include <stdlib.h> @@ -68 +70,14 @@ QString AbstractMail::convert_String(const char*text) } + +/* cp & paste from launcher */ +QString AbstractMail::gen_attachment_id() +{ + QFile file( "/proc/sys/kernel/random/uuid" ); + if (!file.open(IO_ReadOnly ) ) + return QString::null; + + QTextStream stream(&file); + + return "{" + stream.read().stripWhiteSpace() + "}"; +} + 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 @@ -32,4 +32,7 @@ public: static AbstractMail* getWrapper(POP3account *a); + +protected: static encodedString*decode_String(const encodedString*text,const QString&enc); static QString convert_String(const char*text); + static QString gen_attachment_id(); }; 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 @@ -6,2 +6,4 @@ #include <qstring.h> +#include <qfile.h> +#include <qtextstream.h> #include <stdlib.h> @@ -68 +70,14 @@ QString AbstractMail::convert_String(const char*text) } + +/* cp & paste from launcher */ +QString AbstractMail::gen_attachment_id() +{ + QFile file( "/proc/sys/kernel/random/uuid" ); + if (!file.open(IO_ReadOnly ) ) + return QString::null; + + QTextStream stream(&file); + + return "{" + stream.read().stripWhiteSpace() + "}"; +} + 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 @@ -32,4 +32,7 @@ public: static AbstractMail* getWrapper(POP3account *a); + +protected: static encodedString*decode_String(const encodedString*text,const QString&enc); static QString convert_String(const char*text); + static QString gen_attachment_id(); }; 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 @@ -18,2 +18,3 @@ POP3wrapper::POP3wrapper( POP3account *a ) last_msg_id = 0; + bodyCache.clear(); } @@ -27,2 +28,14 @@ POP3wrapper::~POP3wrapper() } + cleanUpCache(); +} + +void POP3wrapper::cleanUpCache() +{ + QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); + for (;it!=bodyCache.end();++it) { + encodedString*t = it.data(); + //it.setValue(0); + if (t) delete t; + } + bodyCache.clear(); } @@ -53,2 +66,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) } + cleanUpCache(); if (mail.getNumber()!=last_msg_id) { @@ -407,5 +421,8 @@ QList<Folder>* POP3wrapper::listFolders() -QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) +QString POP3wrapper::fetchTextPart(const RecMail&mail,const RecPart&part) { - return ""; + encodedString*t = fetchDecodedPart(mail,part); + QString text=t->Content(); + delete t; + return text; } @@ -426,10 +443,16 @@ void POP3wrapper::answeredMail(const RecMail&) -encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) +encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&part) { - return new encodedString(); + QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); + if (it==bodyCache.end()) return new encodedString(); + encodedString*t = decode_String(it.data(),part.Encoding()); + return t; } -encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) +encodedString* POP3wrapper::fetchRawPart(const RecMail&mail,const RecPart&part) { - return new encodedString(); + QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); + if (it==bodyCache.end()) return new encodedString(); + encodedString*t = it.data(); + return t; } @@ -467,4 +490,5 @@ void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime, } else { - /* TODO: Add the content to a list and store it for later use */ - if (data) free(data); + b = gen_attachment_id(); + part.setIdentifier(b); + bodyCache[b]=new encodedString(data,len); target.addPart(part); 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 @@ -5,2 +5,4 @@ #include "abstractmail.h" +#include <qmap.h> +#include <qstring.h> @@ -46,3 +48,5 @@ protected: - static void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); + void cleanUpCache(); + + void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); @@ -55,2 +59,3 @@ protected: unsigned int last_msg_id; + QMap<QString,encodedString*> bodyCache; }; 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 @@ -18,2 +18,3 @@ POP3wrapper::POP3wrapper( POP3account *a ) last_msg_id = 0; + bodyCache.clear(); } @@ -27,2 +28,14 @@ POP3wrapper::~POP3wrapper() } + cleanUpCache(); +} + +void POP3wrapper::cleanUpCache() +{ + QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); + for (;it!=bodyCache.end();++it) { + encodedString*t = it.data(); + //it.setValue(0); + if (t) delete t; + } + bodyCache.clear(); } @@ -53,2 +66,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) } + cleanUpCache(); if (mail.getNumber()!=last_msg_id) { @@ -407,5 +421,8 @@ QList<Folder>* POP3wrapper::listFolders() -QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) +QString POP3wrapper::fetchTextPart(const RecMail&mail,const RecPart&part) { - return ""; + encodedString*t = fetchDecodedPart(mail,part); + QString text=t->Content(); + delete t; + return text; } @@ -426,10 +443,16 @@ void POP3wrapper::answeredMail(const RecMail&) -encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) +encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&part) { - return new encodedString(); + QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); + if (it==bodyCache.end()) return new encodedString(); + encodedString*t = decode_String(it.data(),part.Encoding()); + return t; } -encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) +encodedString* POP3wrapper::fetchRawPart(const RecMail&mail,const RecPart&part) { - return new encodedString(); + QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); + if (it==bodyCache.end()) return new encodedString(); + encodedString*t = it.data(); + return t; } @@ -467,4 +490,5 @@ void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime, } else { - /* TODO: Add the content to a list and store it for later use */ - if (data) free(data); + b = gen_attachment_id(); + part.setIdentifier(b); + bodyCache[b]=new encodedString(data,len); target.addPart(part); 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 @@ -5,2 +5,4 @@ #include "abstractmail.h" +#include <qmap.h> +#include <qstring.h> @@ -46,3 +48,5 @@ protected: - static void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); + void cleanUpCache(); + + void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); @@ -55,2 +59,3 @@ protected: unsigned int last_msg_id; + QMap<QString,encodedString*> bodyCache; }; |