-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 69 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 7 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 69 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 7 |
4 files changed, 128 insertions, 24 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 @@ | |||
4 | #include <libetpan/mailpop3.h> | 4 | #include <libetpan/mailpop3.h> |
5 | #include <libetpan/mailmime.h> | ||
6 | #include <qfile.h> | ||
5 | 7 | ||
@@ -9,2 +11,4 @@ POP3wrapper::POP3wrapper( POP3account *a ) | |||
9 | m_pop3 = NULL; | 11 | m_pop3 = NULL; |
12 | msgTempName = a->getFileName()+"_msg_cache"; | ||
13 | last_msg_id = 0; | ||
10 | } | 14 | } |
@@ -14,2 +18,6 @@ POP3wrapper::~POP3wrapper() | |||
14 | logout(); | 18 | logout(); |
19 | QFile msg_cache(msgTempName); | ||
20 | if (msg_cache.exists()) { | ||
21 | msg_cache.remove(); | ||
22 | } | ||
15 | } | 23 | } |
@@ -28,14 +36,42 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
28 | login(); | 36 | login(); |
29 | if ( !m_pop3 ) return RecBody(); | 37 | if ( !m_pop3 ) { |
30 | |||
31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | ||
32 | if ( err != MAILPOP3_NO_ERROR ) { | ||
33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | ||
34 | return RecBody(); | 38 | return RecBody(); |
35 | } | 39 | } |
40 | RecBody body; | ||
36 | 41 | ||
37 | return parseBody( message ); | 42 | QFile msg_cache(msgTempName); |
43 | |||
44 | if (mail.getNumber()!=last_msg_id) { | ||
45 | if (msg_cache.exists()) { | ||
46 | msg_cache.remove(); | ||
47 | } | ||
48 | msg_cache.open(IO_ReadWrite|IO_Truncate); | ||
49 | last_msg_id = mail.getNumber(); | ||
50 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | ||
51 | if ( err != MAILPOP3_NO_ERROR ) { | ||
52 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | ||
53 | last_msg_id = 0; | ||
54 | return RecBody(); | ||
55 | } | ||
56 | msg_cache.writeBlock(message,length); | ||
57 | } else { | ||
58 | QString msg=""; | ||
59 | msg_cache.open(IO_ReadOnly); | ||
60 | message = new char[4096]; | ||
61 | memset(message,0,4096); | ||
62 | while (msg_cache.readBlock(message,4095)>0) { | ||
63 | msg+=message; | ||
64 | memset(message,0,4096); | ||
65 | } | ||
66 | delete message; | ||
67 | message = (char*)malloc(msg.length()+1*sizeof(char)); | ||
68 | memset(message,0,msg.length()+1); | ||
69 | memcpy(message,msg.latin1(),msg.length()); | ||
70 | } | ||
71 | body = parseMail(message); | ||
72 | free(message); | ||
73 | return body; | ||
38 | } | 74 | } |
39 | 75 | ||
40 | RecBody POP3wrapper::parseBody( const char *message ) | 76 | RecBody POP3wrapper::parseMail( char *message ) |
41 | { | 77 | { |
@@ -46,3 +82,4 @@ RecBody POP3wrapper::parseBody( const char *message ) | |||
46 | RecBody body; | 82 | RecBody body; |
47 | 83 | ||
84 | |||
48 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 85 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
@@ -53,2 +90,6 @@ RecBody POP3wrapper::parseBody( const char *message ) | |||
53 | 90 | ||
91 | struct mailimf_body * b = 0; | ||
92 | struct mailimf_fields * f = 0; | ||
93 | |||
94 | |||
54 | if ( result && result->msg_body && result->msg_body->bd_text ) { | 95 | if ( result && result->msg_body && result->msg_body->bd_text ) { |
@@ -57,4 +98,14 @@ RecBody POP3wrapper::parseBody( const char *message ) | |||
57 | body.setBodytext( QString( result->msg_body->bd_text ) ); | 98 | body.setBodytext( QString( result->msg_body->bd_text ) ); |
99 | #if 0 | ||
100 | curTok = 0; | ||
101 | mailmime_content*mresult = 0; | ||
102 | size_t index = 0; | ||
103 | mailmime_content_parse(result->msg_body->bd_text, | ||
104 | strlen(result->msg_body->bd_text),&index,&mresult); | ||
105 | if (mresult) { | ||
106 | mailmime_content_free(mresult); | ||
107 | } | ||
108 | #endif | ||
109 | mailimf_message_free(result); | ||
58 | } | 110 | } |
59 | if (result) mailimf_message_free(result); | ||
60 | return body; | 111 | 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 | |||
@@ -34,6 +34,5 @@ protected: | |||
34 | void logout(); | 34 | void logout(); |
35 | 35 | ||
36 | private: | ||
37 | RecMail *parseHeader( const char *header ); | 36 | RecMail *parseHeader( const char *header ); |
38 | RecBody parseBody( const char *message ); | 37 | RecBody parseMail( char *message ); |
39 | QString parseMailboxList( mailimf_mailbox_list *list ); | 38 | QString parseMailboxList( mailimf_mailbox_list *list ); |
@@ -45,2 +44,4 @@ private: | |||
45 | mailpop3 *m_pop3; | 44 | mailpop3 *m_pop3; |
45 | QString msgTempName; | ||
46 | unsigned int last_msg_id; | ||
46 | }; | 47 | }; |
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 | |||
@@ -4,2 +4,4 @@ | |||
4 | #include <libetpan/mailpop3.h> | 4 | #include <libetpan/mailpop3.h> |
5 | #include <libetpan/mailmime.h> | ||
6 | #include <qfile.h> | ||
5 | 7 | ||
@@ -9,2 +11,4 @@ POP3wrapper::POP3wrapper( POP3account *a ) | |||
9 | m_pop3 = NULL; | 11 | m_pop3 = NULL; |
12 | msgTempName = a->getFileName()+"_msg_cache"; | ||
13 | last_msg_id = 0; | ||
10 | } | 14 | } |
@@ -14,2 +18,6 @@ POP3wrapper::~POP3wrapper() | |||
14 | logout(); | 18 | logout(); |
19 | QFile msg_cache(msgTempName); | ||
20 | if (msg_cache.exists()) { | ||
21 | msg_cache.remove(); | ||
22 | } | ||
15 | } | 23 | } |
@@ -28,14 +36,42 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
28 | login(); | 36 | login(); |
29 | if ( !m_pop3 ) return RecBody(); | 37 | if ( !m_pop3 ) { |
30 | |||
31 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | ||
32 | if ( err != MAILPOP3_NO_ERROR ) { | ||
33 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | ||
34 | return RecBody(); | 38 | return RecBody(); |
35 | } | 39 | } |
40 | RecBody body; | ||
36 | 41 | ||
37 | return parseBody( message ); | 42 | QFile msg_cache(msgTempName); |
43 | |||
44 | if (mail.getNumber()!=last_msg_id) { | ||
45 | if (msg_cache.exists()) { | ||
46 | msg_cache.remove(); | ||
47 | } | ||
48 | msg_cache.open(IO_ReadWrite|IO_Truncate); | ||
49 | last_msg_id = mail.getNumber(); | ||
50 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | ||
51 | if ( err != MAILPOP3_NO_ERROR ) { | ||
52 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | ||
53 | last_msg_id = 0; | ||
54 | return RecBody(); | ||
55 | } | ||
56 | msg_cache.writeBlock(message,length); | ||
57 | } else { | ||
58 | QString msg=""; | ||
59 | msg_cache.open(IO_ReadOnly); | ||
60 | message = new char[4096]; | ||
61 | memset(message,0,4096); | ||
62 | while (msg_cache.readBlock(message,4095)>0) { | ||
63 | msg+=message; | ||
64 | memset(message,0,4096); | ||
65 | } | ||
66 | delete message; | ||
67 | message = (char*)malloc(msg.length()+1*sizeof(char)); | ||
68 | memset(message,0,msg.length()+1); | ||
69 | memcpy(message,msg.latin1(),msg.length()); | ||
70 | } | ||
71 | body = parseMail(message); | ||
72 | free(message); | ||
73 | return body; | ||
38 | } | 74 | } |
39 | 75 | ||
40 | RecBody POP3wrapper::parseBody( const char *message ) | 76 | RecBody POP3wrapper::parseMail( char *message ) |
41 | { | 77 | { |
@@ -46,3 +82,4 @@ RecBody POP3wrapper::parseBody( const char *message ) | |||
46 | RecBody body; | 82 | RecBody body; |
47 | 83 | ||
84 | |||
48 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); | 85 | err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); |
@@ -53,2 +90,6 @@ RecBody POP3wrapper::parseBody( const char *message ) | |||
53 | 90 | ||
91 | struct mailimf_body * b = 0; | ||
92 | struct mailimf_fields * f = 0; | ||
93 | |||
94 | |||
54 | if ( result && result->msg_body && result->msg_body->bd_text ) { | 95 | if ( result && result->msg_body && result->msg_body->bd_text ) { |
@@ -57,4 +98,14 @@ RecBody POP3wrapper::parseBody( const char *message ) | |||
57 | body.setBodytext( QString( result->msg_body->bd_text ) ); | 98 | body.setBodytext( QString( result->msg_body->bd_text ) ); |
99 | #if 0 | ||
100 | curTok = 0; | ||
101 | mailmime_content*mresult = 0; | ||
102 | size_t index = 0; | ||
103 | mailmime_content_parse(result->msg_body->bd_text, | ||
104 | strlen(result->msg_body->bd_text),&index,&mresult); | ||
105 | if (mresult) { | ||
106 | mailmime_content_free(mresult); | ||
107 | } | ||
108 | #endif | ||
109 | mailimf_message_free(result); | ||
58 | } | 110 | } |
59 | if (result) mailimf_message_free(result); | ||
60 | return body; | 111 | 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 | |||
@@ -34,6 +34,5 @@ protected: | |||
34 | void logout(); | 34 | void logout(); |
35 | 35 | ||
36 | private: | ||
37 | RecMail *parseHeader( const char *header ); | 36 | RecMail *parseHeader( const char *header ); |
38 | RecBody parseBody( const char *message ); | 37 | RecBody parseMail( char *message ); |
39 | QString parseMailboxList( mailimf_mailbox_list *list ); | 38 | QString parseMailboxList( mailimf_mailbox_list *list ); |
@@ -45,2 +44,4 @@ private: | |||
45 | mailpop3 *m_pop3; | 44 | mailpop3 *m_pop3; |
45 | QString msgTempName; | ||
46 | unsigned int last_msg_id; | ||
46 | }; | 47 | }; |