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
@@ -1,83 +1,134 @@
1#include <stdlib.h> 1#include <stdlib.h>
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 )
18{ 26{
19 //qDebug( "POP3: %i of %i", current, maximum ); 27 //qDebug( "POP3: %i of %i", current, maximum );
20} 28}
21 29
22RecBody POP3wrapper::fetchBody( const RecMail &mail ) 30RecBody POP3wrapper::fetchBody( const RecMail &mail )
23{ 31{
24 int err = MAILPOP3_NO_ERROR; 32 int err = MAILPOP3_NO_ERROR;
25 char *message; 33 char *message;
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
63void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 114void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
64{ 115{
65 int err = MAILPOP3_NO_ERROR; 116 int err = MAILPOP3_NO_ERROR;
66 char * header = 0; 117 char * header = 0;
67 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 118 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
68 size_t length = 0; 119 size_t length = 0;
69 carray * messages = 0; 120 carray * messages = 0;
70 121
71 login(); 122 login();
72 if (!m_pop3) return; 123 if (!m_pop3) return;
73 mailpop3_list( m_pop3, &messages ); 124 mailpop3_list( m_pop3, &messages );
74 125
75 for (unsigned int i = 0; i < carray_count(messages);++i) { 126 for (unsigned int i = 0; i < carray_count(messages);++i) {
76 mailpop3_msg_info *info; 127 mailpop3_msg_info *info;
77 err = mailpop3_get_msg_info(m_pop3,i+1,&info); 128 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
78 if (info->msg_deleted) 129 if (info->msg_deleted)
79 continue; 130 continue;
80 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 131 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
81 if ( err != MAILPOP3_NO_ERROR ) { 132 if ( err != MAILPOP3_NO_ERROR ) {
82 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 133 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
83 free(header); 134 free(header);
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
@@ -11,38 +11,39 @@ struct mailpop3;
11 11
12class POP3wrapper : public AbstractMail 12class POP3wrapper : public AbstractMail
13{ 13{
14 Q_OBJECT 14 Q_OBJECT
15 15
16public: 16public:
17 POP3wrapper( POP3account *a ); 17 POP3wrapper( POP3account *a );
18 virtual ~POP3wrapper(); 18 virtual ~POP3wrapper();
19 /* mailbox will be ignored */ 19 /* mailbox will be ignored */
20 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 20 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
21 virtual QList<Folder>* listFolders(); 21 virtual QList<Folder>* listFolders();
22 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 22 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
23 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 23 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
24 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 24 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
25 25
26 virtual void deleteMail(const RecMail&mail); 26 virtual void deleteMail(const RecMail&mail);
27 virtual void answeredMail(const RecMail&mail); 27 virtual void answeredMail(const RecMail&mail);
28 28
29 RecBody fetchBody( const RecMail &mail ); 29 RecBody fetchBody( const RecMail &mail );
30 static void pop3_progress( size_t current, size_t maximum ); 30 static void pop3_progress( size_t current, size_t maximum );
31 31
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 );
42 QString parseAddressList( mailimf_address_list *list ); 41 QString parseAddressList( mailimf_address_list *list );
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
@@ -1,83 +1,134 @@
1#include <stdlib.h> 1#include <stdlib.h>
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 )
18{ 26{
19 //qDebug( "POP3: %i of %i", current, maximum ); 27 //qDebug( "POP3: %i of %i", current, maximum );
20} 28}
21 29
22RecBody POP3wrapper::fetchBody( const RecMail &mail ) 30RecBody POP3wrapper::fetchBody( const RecMail &mail )
23{ 31{
24 int err = MAILPOP3_NO_ERROR; 32 int err = MAILPOP3_NO_ERROR;
25 char *message; 33 char *message;
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
63void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 114void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
64{ 115{
65 int err = MAILPOP3_NO_ERROR; 116 int err = MAILPOP3_NO_ERROR;
66 char * header = 0; 117 char * header = 0;
67 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 118 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
68 size_t length = 0; 119 size_t length = 0;
69 carray * messages = 0; 120 carray * messages = 0;
70 121
71 login(); 122 login();
72 if (!m_pop3) return; 123 if (!m_pop3) return;
73 mailpop3_list( m_pop3, &messages ); 124 mailpop3_list( m_pop3, &messages );
74 125
75 for (unsigned int i = 0; i < carray_count(messages);++i) { 126 for (unsigned int i = 0; i < carray_count(messages);++i) {
76 mailpop3_msg_info *info; 127 mailpop3_msg_info *info;
77 err = mailpop3_get_msg_info(m_pop3,i+1,&info); 128 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
78 if (info->msg_deleted) 129 if (info->msg_deleted)
79 continue; 130 continue;
80 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 131 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
81 if ( err != MAILPOP3_NO_ERROR ) { 132 if ( err != MAILPOP3_NO_ERROR ) {
82 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 133 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
83 free(header); 134 free(header);
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
@@ -11,38 +11,39 @@ struct mailpop3;
11 11
12class POP3wrapper : public AbstractMail 12class POP3wrapper : public AbstractMail
13{ 13{
14 Q_OBJECT 14 Q_OBJECT
15 15
16public: 16public:
17 POP3wrapper( POP3account *a ); 17 POP3wrapper( POP3account *a );
18 virtual ~POP3wrapper(); 18 virtual ~POP3wrapper();
19 /* mailbox will be ignored */ 19 /* mailbox will be ignored */
20 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 20 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
21 virtual QList<Folder>* listFolders(); 21 virtual QList<Folder>* listFolders();
22 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 22 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
23 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 23 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
24 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 24 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
25 25
26 virtual void deleteMail(const RecMail&mail); 26 virtual void deleteMail(const RecMail&mail);
27 virtual void answeredMail(const RecMail&mail); 27 virtual void answeredMail(const RecMail&mail);
28 28
29 RecBody fetchBody( const RecMail &mail ); 29 RecBody fetchBody( const RecMail &mail );
30 static void pop3_progress( size_t current, size_t maximum ); 30 static void pop3_progress( size_t current, size_t maximum );
31 31
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 );
42 QString parseAddressList( mailimf_address_list *list ); 41 QString parseAddressList( mailimf_address_list *list );
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