author | alwin <alwin> | 2003-12-17 21:49:48 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-17 21:49:48 (UTC) |
commit | 0b9db8cd39412de3bdc26e8f451b0475a149c903 (patch) (side-by-side diff) | |
tree | b0c700e8f1bcadfe9c0a75adbaf65514dd6b0441 | |
parent | f3389a1eeedce7be8638ba2f71476240a8a4fe0e (diff) | |
download | opie-0b9db8cd39412de3bdc26e8f451b0475a149c903.zip opie-0b9db8cd39412de3bdc26e8f451b0475a149c903.tar.gz opie-0b9db8cd39412de3bdc26e8f451b0475a149c903.tar.bz2 |
pop3 mails will be cached in a temp-file
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 61 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 5 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 61 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 5 |
4 files changed, 118 insertions, 14 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 @@ -2,16 +2,24 @@ #include "pop3wrapper.h" #include "mailtypes.h" #include <libetpan/mailpop3.h> +#include <libetpan/mailmime.h> +#include <qfile.h> POP3wrapper::POP3wrapper( POP3account *a ) { account = a; m_pop3 = NULL; + msgTempName = a->getFileName()+"_msg_cache"; + last_msg_id = 0; } POP3wrapper::~POP3wrapper() { logout(); + QFile msg_cache(msgTempName); + if (msg_cache.exists()) { + msg_cache.remove(); + } } void POP3wrapper::pop3_progress( size_t current, size_t maximum ) @@ -26,18 +34,46 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) size_t length = 0; login(); - if ( !m_pop3 ) return RecBody(); + if ( !m_pop3 ) { + return RecBody(); + } + RecBody body; + 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(); } - - return parseBody( message ); + 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 ) { int err = MAILIMF_NO_ERROR; /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ @@ -45,18 +81,33 @@ RecBody POP3wrapper::parseBody( const char *message ) mailimf_message *result = 0; RecBody body; + err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); if ( err != MAILIMF_NO_ERROR ) { if (result) mailimf_message_free(result); return body; } + struct mailimf_body * b = 0; + struct mailimf_fields * f = 0; + + if ( result && result->msg_body && result->msg_body->bd_text ) { qDebug( "POP3: bodytext found" ); // when curTok isn't set to 0 this line will fault! 'cause upper line faults! 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; } diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index 8d3adda..a05021c 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h @@ -33,9 +33,8 @@ protected: void login(); void logout(); -private: RecMail *parseHeader( const char *header ); - RecBody parseBody( const char *message ); + RecBody parseMail( char *message ); QString parseMailboxList( mailimf_mailbox_list *list ); QString parseMailbox( mailimf_mailbox *box ); QString parseGroup( mailimf_group *group ); @@ -43,6 +42,8 @@ private: QString parseDateTime( mailimf_date_time *date ); POP3account *account; mailpop3 *m_pop3; + QString msgTempName; + unsigned int last_msg_id; }; #endif diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index 4508a95..30f80ff 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp @@ -2,16 +2,24 @@ #include "pop3wrapper.h" #include "mailtypes.h" #include <libetpan/mailpop3.h> +#include <libetpan/mailmime.h> +#include <qfile.h> POP3wrapper::POP3wrapper( POP3account *a ) { account = a; m_pop3 = NULL; + msgTempName = a->getFileName()+"_msg_cache"; + last_msg_id = 0; } POP3wrapper::~POP3wrapper() { logout(); + QFile msg_cache(msgTempName); + if (msg_cache.exists()) { + msg_cache.remove(); + } } void POP3wrapper::pop3_progress( size_t current, size_t maximum ) @@ -26,18 +34,46 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) size_t length = 0; login(); - if ( !m_pop3 ) return RecBody(); + if ( !m_pop3 ) { + return RecBody(); + } + RecBody body; + 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(); } - - return parseBody( message ); + 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 ) { int err = MAILIMF_NO_ERROR; /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ @@ -45,18 +81,33 @@ RecBody POP3wrapper::parseBody( const char *message ) mailimf_message *result = 0; RecBody body; + err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); if ( err != MAILIMF_NO_ERROR ) { if (result) mailimf_message_free(result); return body; } + struct mailimf_body * b = 0; + struct mailimf_fields * f = 0; + + if ( result && result->msg_body && result->msg_body->bd_text ) { qDebug( "POP3: bodytext found" ); // when curTok isn't set to 0 this line will fault! 'cause upper line faults! 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; } diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index 8d3adda..a05021c 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h @@ -33,9 +33,8 @@ protected: void login(); void logout(); -private: RecMail *parseHeader( const char *header ); - RecBody parseBody( const char *message ); + RecBody parseMail( char *message ); QString parseMailboxList( mailimf_mailbox_list *list ); QString parseMailbox( mailimf_mailbox *box ); QString parseGroup( mailimf_group *group ); @@ -43,6 +42,8 @@ private: QString parseDateTime( mailimf_date_time *date ); POP3account *account; mailpop3 *m_pop3; + QString msgTempName; + unsigned int last_msg_id; }; #endif |