summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-17 21:49:48 (UTC)
committer alwin <alwin>2003-12-17 21:49:48 (UTC)
commit0b9db8cd39412de3bdc26e8f451b0475a149c903 (patch) (unidiff)
treeb0c700e8f1bcadfe9c0a75adbaf65514dd6b0441
parentf3389a1eeedce7be8638ba2f71476240a8a4fe0e (diff)
downloadopie-0b9db8cd39412de3bdc26e8f451b0475a149c903.zip
opie-0b9db8cd39412de3bdc26e8f451b0475a149c903.tar.gz
opie-0b9db8cd39412de3bdc26e8f451b0475a149c903.tar.bz2
pop3 mails will be cached in a temp-file
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp69
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h7
-rw-r--r--noncore/net/mail/pop3wrapper.cpp69
-rw-r--r--noncore/net/mail/pop3wrapper.h7
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
@@ -2,16 +2,24 @@
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include <libetpan/mailpop3.h> 4#include <libetpan/mailpop3.h>
5#include <libetpan/mailmime.h>
6#include <qfile.h>
5 7
6POP3wrapper::POP3wrapper( POP3account *a ) 8POP3wrapper::POP3wrapper( POP3account *a )
7{ 9{
8 account = a; 10 account = a;
9 m_pop3 = NULL; 11 m_pop3 = NULL;
12 msgTempName = a->getFileName()+"_msg_cache";
13 last_msg_id = 0;
10} 14}
11 15
12POP3wrapper::~POP3wrapper() 16POP3wrapper::~POP3wrapper()
13{ 17{
14 logout(); 18 logout();
19 QFile msg_cache(msgTempName);
20 if (msg_cache.exists()) {
21 msg_cache.remove();
22 }
15} 23}
16 24
17void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 25void POP3wrapper::pop3_progress( size_t current, size_t maximum )
@@ -26,37 +34,80 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail )
26 size_t length = 0; 34 size_t length = 0;
27 35
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
40RecBody POP3wrapper::parseBody( const char *message ) 76RecBody POP3wrapper::parseMail( char *message )
41{ 77{
42 int err = MAILIMF_NO_ERROR; 78 int err = MAILIMF_NO_ERROR;
43 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 79 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
44 size_t curTok = 0; 80 size_t curTok = 0;
45 mailimf_message *result = 0; 81 mailimf_message *result = 0;
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 );
49 if ( err != MAILIMF_NO_ERROR ) { 86 if ( err != MAILIMF_NO_ERROR ) {
50 if (result) mailimf_message_free(result); 87 if (result) mailimf_message_free(result);
51 return body; 88 return body;
52 } 89 }
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 ) {
55 qDebug( "POP3: bodytext found" ); 96 qDebug( "POP3: bodytext found" );
56 // when curTok isn't set to 0 this line will fault! 'cause upper line faults! 97 // when curTok isn't set to 0 this line will fault! 'cause upper line faults!
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;
61} 112}
62 113
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
@@ -32,10 +32,9 @@ public:
32protected: 32protected:
33 void login(); 33 void login();
34 void logout(); 34 void logout();
35 35
36private:
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 );
40 QString parseMailbox( mailimf_mailbox *box ); 39 QString parseMailbox( mailimf_mailbox *box );
41 QString parseGroup( mailimf_group *group ); 40 QString parseGroup( mailimf_group *group );
@@ -43,6 +42,8 @@ private:
43 QString parseDateTime( mailimf_date_time *date ); 42 QString parseDateTime( mailimf_date_time *date );
44 POP3account *account; 43 POP3account *account;
45 mailpop3 *m_pop3; 44 mailpop3 *m_pop3;
45 QString msgTempName;
46 unsigned int last_msg_id;
46}; 47};
47 48
48#endif 49#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 @@
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include <libetpan/mailpop3.h> 4#include <libetpan/mailpop3.h>
5#include <libetpan/mailmime.h>
6#include <qfile.h>
5 7
6POP3wrapper::POP3wrapper( POP3account *a ) 8POP3wrapper::POP3wrapper( POP3account *a )
7{ 9{
8 account = a; 10 account = a;
9 m_pop3 = NULL; 11 m_pop3 = NULL;
12 msgTempName = a->getFileName()+"_msg_cache";
13 last_msg_id = 0;
10} 14}
11 15
12POP3wrapper::~POP3wrapper() 16POP3wrapper::~POP3wrapper()
13{ 17{
14 logout(); 18 logout();
19 QFile msg_cache(msgTempName);
20 if (msg_cache.exists()) {
21 msg_cache.remove();
22 }
15} 23}
16 24
17void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 25void POP3wrapper::pop3_progress( size_t current, size_t maximum )
@@ -26,37 +34,80 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail )
26 size_t length = 0; 34 size_t length = 0;
27 35
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
40RecBody POP3wrapper::parseBody( const char *message ) 76RecBody POP3wrapper::parseMail( char *message )
41{ 77{
42 int err = MAILIMF_NO_ERROR; 78 int err = MAILIMF_NO_ERROR;
43 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 79 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
44 size_t curTok = 0; 80 size_t curTok = 0;
45 mailimf_message *result = 0; 81 mailimf_message *result = 0;
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 );
49 if ( err != MAILIMF_NO_ERROR ) { 86 if ( err != MAILIMF_NO_ERROR ) {
50 if (result) mailimf_message_free(result); 87 if (result) mailimf_message_free(result);
51 return body; 88 return body;
52 } 89 }
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 ) {
55 qDebug( "POP3: bodytext found" ); 96 qDebug( "POP3: bodytext found" );
56 // when curTok isn't set to 0 this line will fault! 'cause upper line faults! 97 // when curTok isn't set to 0 this line will fault! 'cause upper line faults!
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;
61} 112}
62 113
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
@@ -32,10 +32,9 @@ public:
32protected: 32protected:
33 void login(); 33 void login();
34 void logout(); 34 void logout();
35 35
36private:
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 );
40 QString parseMailbox( mailimf_mailbox *box ); 39 QString parseMailbox( mailimf_mailbox *box );
41 QString parseGroup( mailimf_group *group ); 40 QString parseGroup( mailimf_group *group );
@@ -43,6 +42,8 @@ private:
43 QString parseDateTime( mailimf_date_time *date ); 42 QString parseDateTime( mailimf_date_time *date );
44 POP3account *account; 43 POP3account *account;
45 mailpop3 *m_pop3; 44 mailpop3 *m_pop3;
45 QString msgTempName;
46 unsigned int last_msg_id;
46}; 47};
47 48
48#endif 49#endif