Diffstat (limited to 'noncore/net/mail/libmailwrapper/pop3wrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 69 |
1 files changed, 60 insertions, 9 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 4508a95..30f80ff 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -4,2 +4,4 @@ #include <libetpan/mailpop3.h> +#include <libetpan/mailmime.h> +#include <qfile.h> @@ -9,2 +11,4 @@ POP3wrapper::POP3wrapper( POP3account *a ) m_pop3 = NULL; + msgTempName = a->getFileName()+"_msg_cache"; + last_msg_id = 0; } @@ -14,2 +18,6 @@ POP3wrapper::~POP3wrapper() logout(); + QFile msg_cache(msgTempName); + if (msg_cache.exists()) { + msg_cache.remove(); + } } @@ -28,14 +36,42 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) login(); - if ( !m_pop3 ) return RecBody(); - - err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); - if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); + if ( !m_pop3 ) { return RecBody(); } + RecBody body; - return parseBody( message ); + QFile msg_cache(msgTempName); + + 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 ) { + qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); + last_msg_id = 0; + return RecBody(); + } + msg_cache.writeBlock(message,length); + } else { + QString msg=""; + msg_cache.open(IO_ReadOnly); + message = new char[4096]; + memset(message,0,4096); + while (msg_cache.readBlock(message,4095)>0) { + msg+=message; + memset(message,0,4096); + } + delete message; + message = (char*)malloc(msg.length()+1*sizeof(char)); + memset(message,0,msg.length()+1); + memcpy(message,msg.latin1(),msg.length()); + } + body = parseMail(message); + free(message); + return body; } -RecBody POP3wrapper::parseBody( const char *message ) +RecBody POP3wrapper::parseMail( char *message ) { @@ -46,3 +82,4 @@ RecBody POP3wrapper::parseBody( const char *message ) RecBody body; - + + err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); @@ -53,2 +90,6 @@ RecBody POP3wrapper::parseBody( const char *message ) + struct mailimf_body * b = 0; + struct mailimf_fields * f = 0; + + if ( result && result->msg_body && result->msg_body->bd_text ) { @@ -57,4 +98,14 @@ RecBody POP3wrapper::parseBody( const char *message ) body.setBodytext( QString( result->msg_body->bd_text ) ); +#if 0 + curTok = 0; + mailmime_content*mresult = 0; + size_t index = 0; + mailmime_content_parse(result->msg_body->bd_text, + strlen(result->msg_body->bd_text),&index,&mresult); + if (mresult) { + mailmime_content_free(mresult); + } +#endif + mailimf_message_free(result); } - if (result) mailimf_message_free(result); return body; |