summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.cpp15
-rw-r--r--noncore/net/mail/abstractmail.h3
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp15
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h3
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp40
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h7
-rw-r--r--noncore/net/mail/pop3wrapper.cpp40
-rw-r--r--noncore/net/mail/pop3wrapper.h7
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,14 +1,16 @@
#include "abstractmail.h"
#include "imapwrapper.h"
#include "pop3wrapper.h"
#include "mailtypes.h"
#include <qstring.h>
+#include <qfile.h>
+#include <qtextstream.h>
#include <stdlib.h>
#include <libetpan/mailmime_content.h>
AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
{
return new IMAPwrapper(a);
}
@@ -61,8 +63,21 @@ QString AbstractMail::convert_String(const char*text)
}
if (res) {
QString result(res);
free(res);
return result;
}
return QString(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
@@ -25,12 +25,15 @@ public:
virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
virtual void deleteMail(const RecMail&mail)=0;
virtual void answeredMail(const RecMail&mail)=0;
static AbstractMail* getWrapper(IMAPaccount *a);
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();
};
#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,14 +1,16 @@
#include "abstractmail.h"
#include "imapwrapper.h"
#include "pop3wrapper.h"
#include "mailtypes.h"
#include <qstring.h>
+#include <qfile.h>
+#include <qtextstream.h>
#include <stdlib.h>
#include <libetpan/mailmime_content.h>
AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
{
return new IMAPwrapper(a);
}
@@ -61,8 +63,21 @@ QString AbstractMail::convert_String(const char*text)
}
if (res) {
QString result(res);
free(res);
return result;
}
return QString(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
@@ -25,12 +25,15 @@ public:
virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
virtual void deleteMail(const RecMail&mail)=0;
virtual void answeredMail(const RecMail&mail)=0;
static AbstractMail* getWrapper(IMAPaccount *a);
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();
};
#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
@@ -11,25 +11,38 @@
#define HARD_MSG_SIZE_LIMIT 5242880
POP3wrapper::POP3wrapper( POP3account *a )
{
account = a;
m_pop3 = NULL;
msgTempName = a->getFileName()+"_msg_cache";
last_msg_id = 0;
+ bodyCache.clear();
}
POP3wrapper::~POP3wrapper()
{
logout();
QFile msg_cache(msgTempName);
if (msg_cache.exists()) {
msg_cache.remove();
}
+ 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();
}
void POP3wrapper::pop3_progress( size_t current, size_t maximum )
{
//qDebug( "POP3: %i of %i", current, maximum );
}
RecBody POP3wrapper::fetchBody( const RecMail &mail )
@@ -46,16 +59,17 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail )
RecBody body;
QFile msg_cache(msgTempName);
if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
qDebug("Message to large: %i",mail.Msgsize());
return body;
}
+ cleanUpCache();
if (mail.getNumber()!=last_msg_id) {
if (msg_cache.exists()) {
msg_cache.remove();
}
msg_cache.open(IO_ReadWrite|IO_Truncate);
last_msg_id = mail.getNumber();
err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
if ( err != MAILPOP3_NO_ERROR ) {
@@ -400,43 +414,52 @@ QList<Folder>* POP3wrapper::listFolders()
*/
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
Folder*inb=new Folder("INBOX","/");
folders->append(inb);
return folders;
}
-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;
}
void POP3wrapper::deleteMail(const RecMail&mail)
{
login();
if (!m_pop3) return;
int err = mailpop3_dele(m_pop3,mail.getNumber());
if (err != MAILPOP3_NO_ERROR) {
qDebug("error deleting mail");
}
}
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;
}
void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec)
{
if (current_rec >= 10) {
qDebug("too deep recursion!");
}
if (!message || !mime) {
@@ -460,18 +483,19 @@ void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,
r->setContent(data,len);
encodedString*res = decode_String(r,part.Encoding());
b = QString(res->Content());
delete r;
delete res;
target.setBodytext(b);
target.setDescription(part);
} 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);
}
break;
case MAILMIME_MULTIPLE:
for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1);
}
break;
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,13 +1,15 @@
#ifndef __POP3WRAPPER
#define __POP3WRAPPER
#include "mailwrapper.h"
#include "abstractmail.h"
+#include <qmap.h>
+#include <qstring.h>
class RecMail;
class RecBody;
class encodedString;
struct mailpop3;
struct mailmessage;
struct mailmime;
struct mailmime_mechanism;
@@ -39,20 +41,23 @@ protected:
RecMail *parseHeader( const char *header );
RecBody parseMail( char *message );
QString parseMailboxList( mailimf_mailbox_list *list );
QString parseMailbox( mailimf_mailbox *box );
QString parseGroup( mailimf_group *group );
QString parseAddressList( mailimf_address_list *list );
QString parseDateTime( mailimf_date_time *date );
- 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);
static void fillParameters(RecPart&target,clist*parameters);
static QString POP3wrapper::getencoding(mailmime_mechanism*aEnc);
POP3account *account;
mailpop3 *m_pop3;
QString msgTempName;
unsigned int last_msg_id;
+ QMap<QString,encodedString*> bodyCache;
};
#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
@@ -11,25 +11,38 @@
#define HARD_MSG_SIZE_LIMIT 5242880
POP3wrapper::POP3wrapper( POP3account *a )
{
account = a;
m_pop3 = NULL;
msgTempName = a->getFileName()+"_msg_cache";
last_msg_id = 0;
+ bodyCache.clear();
}
POP3wrapper::~POP3wrapper()
{
logout();
QFile msg_cache(msgTempName);
if (msg_cache.exists()) {
msg_cache.remove();
}
+ 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();
}
void POP3wrapper::pop3_progress( size_t current, size_t maximum )
{
//qDebug( "POP3: %i of %i", current, maximum );
}
RecBody POP3wrapper::fetchBody( const RecMail &mail )
@@ -46,16 +59,17 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail )
RecBody body;
QFile msg_cache(msgTempName);
if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
qDebug("Message to large: %i",mail.Msgsize());
return body;
}
+ cleanUpCache();
if (mail.getNumber()!=last_msg_id) {
if (msg_cache.exists()) {
msg_cache.remove();
}
msg_cache.open(IO_ReadWrite|IO_Truncate);
last_msg_id = mail.getNumber();
err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
if ( err != MAILPOP3_NO_ERROR ) {
@@ -400,43 +414,52 @@ QList<Folder>* POP3wrapper::listFolders()
*/
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
Folder*inb=new Folder("INBOX","/");
folders->append(inb);
return folders;
}
-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;
}
void POP3wrapper::deleteMail(const RecMail&mail)
{
login();
if (!m_pop3) return;
int err = mailpop3_dele(m_pop3,mail.getNumber());
if (err != MAILPOP3_NO_ERROR) {
qDebug("error deleting mail");
}
}
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;
}
void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec)
{
if (current_rec >= 10) {
qDebug("too deep recursion!");
}
if (!message || !mime) {
@@ -460,18 +483,19 @@ void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,
r->setContent(data,len);
encodedString*res = decode_String(r,part.Encoding());
b = QString(res->Content());
delete r;
delete res;
target.setBodytext(b);
target.setDescription(part);
} 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);
}
break;
case MAILMIME_MULTIPLE:
for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1);
}
break;
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,13 +1,15 @@
#ifndef __POP3WRAPPER
#define __POP3WRAPPER
#include "mailwrapper.h"
#include "abstractmail.h"
+#include <qmap.h>
+#include <qstring.h>
class RecMail;
class RecBody;
class encodedString;
struct mailpop3;
struct mailmessage;
struct mailmime;
struct mailmime_mechanism;
@@ -39,20 +41,23 @@ protected:
RecMail *parseHeader( const char *header );
RecBody parseMail( char *message );
QString parseMailboxList( mailimf_mailbox_list *list );
QString parseMailbox( mailimf_mailbox *box );
QString parseGroup( mailimf_group *group );
QString parseAddressList( mailimf_address_list *list );
QString parseDateTime( mailimf_date_time *date );
- 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);
static void fillParameters(RecPart&target,clist*parameters);
static QString POP3wrapper::getencoding(mailmime_mechanism*aEnc);
POP3account *account;
mailpop3 *m_pop3;
QString msgTempName;
unsigned int last_msg_id;
+ QMap<QString,encodedString*> bodyCache;
};
#endif