summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.cpp23
-rw-r--r--noncore/net/mail/abstractmail.h1
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp23
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h1
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp49
-rw-r--r--noncore/net/mail/pop3wrapper.cpp49
6 files changed, 130 insertions, 16 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp
index 92a46f1..b7e5eaa 100644
--- a/noncore/net/mail/abstractmail.cpp
+++ b/noncore/net/mail/abstractmail.cpp
@@ -1,48 +1,71 @@
1#include "abstractmail.h" 1#include "abstractmail.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mailtypes.h" 4#include "mailtypes.h"
5 5
6#include <qstring.h> 6#include <qstring.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <libetpan/mailmime_content.h> 8#include <libetpan/mailmime_content.h>
9 9
10AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 10AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
11{ 11{
12 return new IMAPwrapper(a); 12 return new IMAPwrapper(a);
13} 13}
14 14
15AbstractMail* AbstractMail::getWrapper(POP3account *a) 15AbstractMail* AbstractMail::getWrapper(POP3account *a)
16{ 16{
17 return new POP3wrapper(a); 17 return new POP3wrapper(a);
18} 18}
19 19
20encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 20encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
21{ 21{
22 qDebug("Decode string start"); 22 qDebug("Decode string start");
23 char*result_text; 23 char*result_text;
24 size_t index = 0; 24 size_t index = 0;
25 /* reset for recursive use! */ 25 /* reset for recursive use! */
26 size_t target_length = 0; 26 size_t target_length = 0;
27 result_text = 0; 27 result_text = 0;
28 int mimetype = MAILMIME_MECHANISM_7BIT; 28 int mimetype = MAILMIME_MECHANISM_7BIT;
29 if (enc.lower()=="quoted-printable") { 29 if (enc.lower()=="quoted-printable") {
30 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 30 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
31 } else if (enc.lower()=="base64") { 31 } else if (enc.lower()=="base64") {
32 mimetype = MAILMIME_MECHANISM_BASE64; 32 mimetype = MAILMIME_MECHANISM_BASE64;
33 } else if (enc.lower()=="8bit") { 33 } else if (enc.lower()=="8bit") {
34 mimetype = MAILMIME_MECHANISM_8BIT; 34 mimetype = MAILMIME_MECHANISM_8BIT;
35 } else if (enc.lower()=="binary") { 35 } else if (enc.lower()=="binary") {
36 mimetype = MAILMIME_MECHANISM_BINARY; 36 mimetype = MAILMIME_MECHANISM_BINARY;
37 } 37 }
38 38
39 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 39 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
40 &result_text,&target_length); 40 &result_text,&target_length);
41 41
42 encodedString* result = new encodedString(); 42 encodedString* result = new encodedString();
43 if (err == MAILIMF_NO_ERROR) { 43 if (err == MAILIMF_NO_ERROR) {
44 result->setContent(result_text,target_length); 44 result->setContent(result_text,target_length);
45 } 45 }
46 qDebug("Decode string finished"); 46 qDebug("Decode string finished");
47 return result; 47 return result;
48} 48}
49
50QString AbstractMail::convert_String(const char*text)
51{
52#if 0
53 size_t index = 0;
54 char*res = 0;
55
56 qDebug("encode start %s",text);
57 /* attention - doesn't work with arm systems! */
58 int err = mailmime_encoded_phrase_parse("iso-8859-1",
59 text, strlen(text),&index, "iso-8859-1",&res);
60 qDebug("encode end");
61 if (err != MAILIMF_NO_ERROR) {
62 if (res) free(res);
63 return QString(text);
64 }
65 QString result(res);
66 free(res);
67 return result;
68#else
69 return QString(text);
70#endif
71}
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h
index f1a8468..c16e9c0 100644
--- a/noncore/net/mail/abstractmail.h
+++ b/noncore/net/mail/abstractmail.h
@@ -1,35 +1,36 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include "settings.h" 5#include "settings.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class RecPart; 9class RecPart;
10class IMAPwrapper; 10class IMAPwrapper;
11class POP3wrapper; 11class POP3wrapper;
12class Folder; 12class Folder;
13class encodedString; 13class encodedString;
14 14
15class AbstractMail:public QObject 15class AbstractMail:public QObject
16{ 16{
17 Q_OBJECT 17 Q_OBJECT
18public: 18public:
19 AbstractMail(){}; 19 AbstractMail(){};
20 virtual ~AbstractMail(){} 20 virtual ~AbstractMail(){}
21 virtual QList<Folder>* listFolders()=0; 21 virtual QList<Folder>* listFolders()=0;
22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
23 virtual RecBody fetchBody(const RecMail&mail)=0; 23 virtual RecBody fetchBody(const RecMail&mail)=0;
24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
27 27
28 virtual void deleteMail(const RecMail&mail)=0; 28 virtual void deleteMail(const RecMail&mail)=0;
29 virtual void answeredMail(const RecMail&mail)=0; 29 virtual void answeredMail(const RecMail&mail)=0;
30 30
31 static AbstractMail* getWrapper(IMAPaccount *a); 31 static AbstractMail* getWrapper(IMAPaccount *a);
32 static AbstractMail* getWrapper(POP3account *a); 32 static AbstractMail* getWrapper(POP3account *a);
33 static encodedString*decode_String(const encodedString*text,const QString&enc); 33 static encodedString*decode_String(const encodedString*text,const QString&enc);
34 static QString convert_String(const char*text);
34}; 35};
35#endif 36#endif
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
index 92a46f1..b7e5eaa 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.cpp
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -1,48 +1,71 @@
1#include "abstractmail.h" 1#include "abstractmail.h"
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mailtypes.h" 4#include "mailtypes.h"
5 5
6#include <qstring.h> 6#include <qstring.h>
7#include <stdlib.h> 7#include <stdlib.h>
8#include <libetpan/mailmime_content.h> 8#include <libetpan/mailmime_content.h>
9 9
10AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 10AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
11{ 11{
12 return new IMAPwrapper(a); 12 return new IMAPwrapper(a);
13} 13}
14 14
15AbstractMail* AbstractMail::getWrapper(POP3account *a) 15AbstractMail* AbstractMail::getWrapper(POP3account *a)
16{ 16{
17 return new POP3wrapper(a); 17 return new POP3wrapper(a);
18} 18}
19 19
20encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 20encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
21{ 21{
22 qDebug("Decode string start"); 22 qDebug("Decode string start");
23 char*result_text; 23 char*result_text;
24 size_t index = 0; 24 size_t index = 0;
25 /* reset for recursive use! */ 25 /* reset for recursive use! */
26 size_t target_length = 0; 26 size_t target_length = 0;
27 result_text = 0; 27 result_text = 0;
28 int mimetype = MAILMIME_MECHANISM_7BIT; 28 int mimetype = MAILMIME_MECHANISM_7BIT;
29 if (enc.lower()=="quoted-printable") { 29 if (enc.lower()=="quoted-printable") {
30 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 30 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
31 } else if (enc.lower()=="base64") { 31 } else if (enc.lower()=="base64") {
32 mimetype = MAILMIME_MECHANISM_BASE64; 32 mimetype = MAILMIME_MECHANISM_BASE64;
33 } else if (enc.lower()=="8bit") { 33 } else if (enc.lower()=="8bit") {
34 mimetype = MAILMIME_MECHANISM_8BIT; 34 mimetype = MAILMIME_MECHANISM_8BIT;
35 } else if (enc.lower()=="binary") { 35 } else if (enc.lower()=="binary") {
36 mimetype = MAILMIME_MECHANISM_BINARY; 36 mimetype = MAILMIME_MECHANISM_BINARY;
37 } 37 }
38 38
39 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 39 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
40 &result_text,&target_length); 40 &result_text,&target_length);
41 41
42 encodedString* result = new encodedString(); 42 encodedString* result = new encodedString();
43 if (err == MAILIMF_NO_ERROR) { 43 if (err == MAILIMF_NO_ERROR) {
44 result->setContent(result_text,target_length); 44 result->setContent(result_text,target_length);
45 } 45 }
46 qDebug("Decode string finished"); 46 qDebug("Decode string finished");
47 return result; 47 return result;
48} 48}
49
50QString AbstractMail::convert_String(const char*text)
51{
52#if 0
53 size_t index = 0;
54 char*res = 0;
55
56 qDebug("encode start %s",text);
57 /* attention - doesn't work with arm systems! */
58 int err = mailmime_encoded_phrase_parse("iso-8859-1",
59 text, strlen(text),&index, "iso-8859-1",&res);
60 qDebug("encode end");
61 if (err != MAILIMF_NO_ERROR) {
62 if (res) free(res);
63 return QString(text);
64 }
65 QString result(res);
66 free(res);
67 return result;
68#else
69 return QString(text);
70#endif
71}
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index f1a8468..c16e9c0 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -1,35 +1,36 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include "settings.h" 5#include "settings.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class RecPart; 9class RecPart;
10class IMAPwrapper; 10class IMAPwrapper;
11class POP3wrapper; 11class POP3wrapper;
12class Folder; 12class Folder;
13class encodedString; 13class encodedString;
14 14
15class AbstractMail:public QObject 15class AbstractMail:public QObject
16{ 16{
17 Q_OBJECT 17 Q_OBJECT
18public: 18public:
19 AbstractMail(){}; 19 AbstractMail(){};
20 virtual ~AbstractMail(){} 20 virtual ~AbstractMail(){}
21 virtual QList<Folder>* listFolders()=0; 21 virtual QList<Folder>* listFolders()=0;
22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 22 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
23 virtual RecBody fetchBody(const RecMail&mail)=0; 23 virtual RecBody fetchBody(const RecMail&mail)=0;
24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; 24 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; 25 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; 26 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
27 27
28 virtual void deleteMail(const RecMail&mail)=0; 28 virtual void deleteMail(const RecMail&mail)=0;
29 virtual void answeredMail(const RecMail&mail)=0; 29 virtual void answeredMail(const RecMail&mail)=0;
30 30
31 static AbstractMail* getWrapper(IMAPaccount *a); 31 static AbstractMail* getWrapper(IMAPaccount *a);
32 static AbstractMail* getWrapper(POP3account *a); 32 static AbstractMail* getWrapper(POP3account *a);
33 static encodedString*decode_String(const encodedString*text,const QString&enc); 33 static encodedString*decode_String(const encodedString*text,const QString&enc);
34 static QString convert_String(const char*text);
34}; 35};
35#endif 36#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 30f80ff..22a4c70 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,351 +1,384 @@
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> 5#include <libetpan/mailmime.h>
6#include <libetpan/data_message_driver.h>
6#include <qfile.h> 7#include <qfile.h>
7 8
9/* we don't fetch messages larger than 5 MB */
10#define HARD_MSG_SIZE_LIMIT 5242880
11
8POP3wrapper::POP3wrapper( POP3account *a ) 12POP3wrapper::POP3wrapper( POP3account *a )
9{ 13{
10 account = a; 14 account = a;
11 m_pop3 = NULL; 15 m_pop3 = NULL;
12 msgTempName = a->getFileName()+"_msg_cache"; 16 msgTempName = a->getFileName()+"_msg_cache";
13 last_msg_id = 0; 17 last_msg_id = 0;
14} 18}
15 19
16POP3wrapper::~POP3wrapper() 20POP3wrapper::~POP3wrapper()
17{ 21{
18 logout(); 22 logout();
19 QFile msg_cache(msgTempName); 23 QFile msg_cache(msgTempName);
20 if (msg_cache.exists()) { 24 if (msg_cache.exists()) {
21 msg_cache.remove(); 25 msg_cache.remove();
22 } 26 }
23} 27}
24 28
25void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 29void POP3wrapper::pop3_progress( size_t current, size_t maximum )
26{ 30{
27 //qDebug( "POP3: %i of %i", current, maximum ); 31 //qDebug( "POP3: %i of %i", current, maximum );
28} 32}
29 33
30RecBody POP3wrapper::fetchBody( const RecMail &mail ) 34RecBody POP3wrapper::fetchBody( const RecMail &mail )
31{ 35{
32 int err = MAILPOP3_NO_ERROR; 36 int err = MAILPOP3_NO_ERROR;
33 char *message; 37 char *message;
34 size_t length = 0; 38 size_t length = 0;
35 39
36 login(); 40 login();
37 if ( !m_pop3 ) { 41 if ( !m_pop3 ) {
38 return RecBody(); 42 return RecBody();
39 } 43 }
44
40 RecBody body; 45 RecBody body;
41 46
42 QFile msg_cache(msgTempName); 47 QFile msg_cache(msgTempName);
43 48
49 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
50 qDebug("Message to large: %i",mail.Msgsize());
51 return body;
52 }
44 if (mail.getNumber()!=last_msg_id) { 53 if (mail.getNumber()!=last_msg_id) {
45 if (msg_cache.exists()) { 54 if (msg_cache.exists()) {
46 msg_cache.remove(); 55 msg_cache.remove();
47 } 56 }
48 msg_cache.open(IO_ReadWrite|IO_Truncate); 57 msg_cache.open(IO_ReadWrite|IO_Truncate);
49 last_msg_id = mail.getNumber(); 58 last_msg_id = mail.getNumber();
50 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 59 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
51 if ( err != MAILPOP3_NO_ERROR ) { 60 if ( err != MAILPOP3_NO_ERROR ) {
52 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 61 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
53 last_msg_id = 0; 62 last_msg_id = 0;
54 return RecBody(); 63 return RecBody();
55 } 64 }
56 msg_cache.writeBlock(message,length); 65 msg_cache.writeBlock(message,length);
57 } else { 66 } else {
58 QString msg=""; 67 QString msg="";
59 msg_cache.open(IO_ReadOnly); 68 msg_cache.open(IO_ReadOnly);
60 message = new char[4096]; 69 message = new char[4096];
61 memset(message,0,4096); 70 memset(message,0,4096);
62 while (msg_cache.readBlock(message,4095)>0) { 71 while (msg_cache.readBlock(message,4095)>0) {
63 msg+=message; 72 msg+=message;
64 memset(message,0,4096); 73 memset(message,0,4096);
65 } 74 }
66 delete message; 75 delete message;
67 message = (char*)malloc(msg.length()+1*sizeof(char)); 76 message = (char*)malloc(msg.length()+1*sizeof(char));
68 memset(message,0,msg.length()+1); 77 memset(message,0,msg.length()+1);
69 memcpy(message,msg.latin1(),msg.length()); 78 memcpy(message,msg.latin1(),msg.length());
70 } 79 }
71 body = parseMail(message); 80 body = parseMail(message);
72 free(message); 81 free(message);
73 return body; 82 return body;
74} 83}
75 84
76RecBody POP3wrapper::parseMail( char *message ) 85RecBody POP3wrapper::parseMail( char *message )
77{ 86{
78 int err = MAILIMF_NO_ERROR; 87 int err = MAILIMF_NO_ERROR;
79 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 88 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
80 size_t curTok = 0; 89 size_t curTok = 0;
81 mailimf_message *result = 0; 90 mailimf_message *result = 0;
91 mailmessage * msg=0;
92 struct mailmime * mime=0;
93 struct mailmime_single_fields fields;
94
82 RecBody body; 95 RecBody body;
83 96
84 97
85 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 98 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
86 if ( err != MAILIMF_NO_ERROR ) { 99 if ( err != MAILIMF_NO_ERROR ) {
87 if (result) mailimf_message_free(result); 100 if (result) mailimf_message_free(result);
88 return body; 101 return body;
89 } 102 }
90 103
91 struct mailimf_body * b = 0; 104#if 0
92 struct mailimf_fields * f = 0; 105 char*body_msg = message;
93 106 if ( result && result->msg_body && result->msg_body->bd_text ) {
94 107 body_msg = (char*)result->msg_body->bd_text;
108 result->msg_body->bd_text = 0;
109 }
110
111 msg = mailmessage_new();
112 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg));
113 generic_message_t * msg_data;
114 msg_data = (generic_message_t *)msg->msg_data;
115 msg_data->msg_fetched = 1;
116 msg_data->msg_message = body_msg;
117 msg_data->msg_length = strlen(body_msg);
118 memset(&fields, 0, sizeof(struct mailmime_single_fields));
119 err = mailmessage_get_bodystructure(msg,&mime);
120
121 if (mime->mm_mime_fields != NULL) {
122 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
123 mime->mm_content_type);
124 }
125#endif
126
127#if 1
95 if ( result && result->msg_body && result->msg_body->bd_text ) { 128 if ( result && result->msg_body && result->msg_body->bd_text ) {
96 qDebug( "POP3: bodytext found" ); 129 qDebug( "POP3: bodytext found" );
97 // when curTok isn't set to 0 this line will fault! 'cause upper line faults! 130 // when curTok isn't set to 0 this line will fault! 'cause upper line faults!
98 body.setBodytext( QString( result->msg_body->bd_text ) ); 131 body.setBodytext( QString( result->msg_body->bd_text ) );
99#if 0 132#if 0
100 curTok = 0; 133 curTok = 0;
101 mailmime_content*mresult = 0; 134 mailmime_content*mresult = 0;
102 size_t index = 0; 135 size_t index = 0;
103 mailmime_content_parse(result->msg_body->bd_text, 136 mailmime_content_parse(result->msg_body->bd_text,
104 strlen(result->msg_body->bd_text),&index,&mresult); 137 strlen(result->msg_body->bd_text),&index,&mresult);
105 if (mresult) { 138 if (mresult) {
106 mailmime_content_free(mresult); 139 mailmime_content_free(mresult);
107 } 140 }
108#endif 141#endif
109 mailimf_message_free(result); 142 mailimf_message_free(result);
110 } 143 }
144#endif
111 return body; 145 return body;
112} 146}
113 147
114void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 148void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
115{ 149{
116 int err = MAILPOP3_NO_ERROR; 150 int err = MAILPOP3_NO_ERROR;
117 char * header = 0; 151 char * header = 0;
118 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 152 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
119 size_t length = 0; 153 size_t length = 0;
120 carray * messages = 0; 154 carray * messages = 0;
121 155
122 login(); 156 login();
123 if (!m_pop3) return; 157 if (!m_pop3) return;
124 mailpop3_list( m_pop3, &messages ); 158 mailpop3_list( m_pop3, &messages );
125 159
126 for (unsigned int i = 0; i < carray_count(messages);++i) { 160 for (unsigned int i = 0; i < carray_count(messages);++i) {
127 mailpop3_msg_info *info; 161 mailpop3_msg_info *info;
128 err = mailpop3_get_msg_info(m_pop3,i+1,&info); 162 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
129 if (info->msg_deleted) 163 if (info->msg_deleted)
130 continue; 164 continue;
131 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 165 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
132 if ( err != MAILPOP3_NO_ERROR ) { 166 if ( err != MAILPOP3_NO_ERROR ) {
133 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 167 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
134 free(header); 168 free(header);
135 return; 169 return;
136 } 170 }
137 RecMail *mail = parseHeader( header ); 171 RecMail *mail = parseHeader( header );
138 mail->setNumber( info->msg_index ); 172 mail->setNumber( info->msg_index );
139 mail->setWrapper(this); 173 mail->setWrapper(this);
140 mail->setMsgsize(info->msg_size); 174 mail->setMsgsize(info->msg_size);
141 target.append( mail ); 175 target.append( mail );
142 free(header); 176 free(header);
143 } 177 }
144} 178}
145 179
146RecMail *POP3wrapper::parseHeader( const char *header ) 180RecMail *POP3wrapper::parseHeader( const char *header )
147{ 181{
148 int err = MAILIMF_NO_ERROR; 182 int err = MAILIMF_NO_ERROR;
149 size_t curTok = 0; 183 size_t curTok = 0;
150 RecMail *mail = new RecMail(); 184 RecMail *mail = new RecMail();
151 mailimf_fields *fields; 185 mailimf_fields *fields;
152 mailimf_references * refs; 186 mailimf_references * refs;
153 mailimf_keywords*keys; 187 mailimf_keywords*keys;
154 QString status; 188 QString status;
155 QString value; 189 QString value;
156 QBitArray mFlags(7); 190 QBitArray mFlags(7);
157 191
158 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 192 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
159 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 193 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
160 mailimf_field *field = (mailimf_field *) current->data; 194 mailimf_field *field = (mailimf_field *) current->data;
161 switch ( field->fld_type ) { 195 switch ( field->fld_type ) {
162 case MAILIMF_FIELD_FROM: 196 case MAILIMF_FIELD_FROM:
163 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 197 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
164 break; 198 break;
165 case MAILIMF_FIELD_TO: 199 case MAILIMF_FIELD_TO:
166 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 200 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
167 break; 201 break;
168 case MAILIMF_FIELD_CC: 202 case MAILIMF_FIELD_CC:
169 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 203 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
170 break; 204 break;
171 case MAILIMF_FIELD_BCC: 205 case MAILIMF_FIELD_BCC:
172 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 206 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
173 break; 207 break;
174 case MAILIMF_FIELD_SUBJECT: 208 case MAILIMF_FIELD_SUBJECT:
175 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 209 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
176 break; 210 break;
177 case MAILIMF_FIELD_ORIG_DATE: 211 case MAILIMF_FIELD_ORIG_DATE:
178 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 212 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
179 break; 213 break;
180 case MAILIMF_FIELD_MESSAGE_ID: 214 case MAILIMF_FIELD_MESSAGE_ID:
181 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 215 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
182 break; 216 break;
183 case MAILIMF_FIELD_REFERENCES: 217 case MAILIMF_FIELD_REFERENCES:
184 refs = field->fld_data.fld_references; 218 refs = field->fld_data.fld_references;
185 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 219 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
186 char * text = (char*)refs->mid_list->first->data; 220 char * text = (char*)refs->mid_list->first->data;
187 mail->setReplyto(QString(text)); 221 mail->setReplyto(QString(text));
188 } 222 }
189 break; 223 break;
190 case MAILIMF_FIELD_KEYWORDS: 224 case MAILIMF_FIELD_KEYWORDS:
191 keys = field->fld_data.fld_keywords; 225 keys = field->fld_data.fld_keywords;
192 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 226 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
193 qDebug("Keyword: %s",(char*)cur->data); 227 qDebug("Keyword: %s",(char*)cur->data);
194 } 228 }
195 break; 229 break;
196 case MAILIMF_FIELD_OPTIONAL_FIELD: 230 case MAILIMF_FIELD_OPTIONAL_FIELD:
197 status = field->fld_data.fld_optional_field->fld_name; 231 status = field->fld_data.fld_optional_field->fld_name;
198 value = field->fld_data.fld_optional_field->fld_value; 232 value = field->fld_data.fld_optional_field->fld_value;
199 if (status.lower()=="status") { 233 if (status.lower()=="status") {
200 if (value.lower()=="ro") { 234 if (value.lower()=="ro") {
201 mFlags.setBit(FLAG_SEEN); 235 mFlags.setBit(FLAG_SEEN);
202 } 236 }
203 } else if (status.lower()=="x-status") { 237 } else if (status.lower()=="x-status") {
204 qDebug("X-Status: %s",value.latin1()); 238 qDebug("X-Status: %s",value.latin1());
205 if (value.lower()=="a") { 239 if (value.lower()=="a") {
206
207 mFlags.setBit(FLAG_ANSWERED); 240 mFlags.setBit(FLAG_ANSWERED);
208 } 241 }
209 } else { 242 } else {
210// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 243// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
211// field->fld_data.fld_optional_field->fld_value); 244// field->fld_data.fld_optional_field->fld_value);
212 } 245 }
213 break; 246 break;
214 default: 247 default:
215 qDebug("Non parsed field"); 248 qDebug("Non parsed field");
216 break; 249 break;
217 } 250 }
218 } 251 }
219 if (fields) mailimf_fields_free(fields); 252 if (fields) mailimf_fields_free(fields);
220 mail->setFlags(mFlags); 253 mail->setFlags(mFlags);
221 return mail; 254 return mail;
222} 255}
223 256
224QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 257QString POP3wrapper::parseDateTime( mailimf_date_time *date )
225{ 258{
226 char tmp[23]; 259 char tmp[23];
227 260
228 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 261 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
229 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 262 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
230 263
231 return QString( tmp ); 264 return QString( tmp );
232} 265}
233 266
234QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 267QString POP3wrapper::parseAddressList( mailimf_address_list *list )
235{ 268{
236 QString result( "" ); 269 QString result( "" );
237 270
238 bool first = true; 271 bool first = true;
239 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 272 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
240 mailimf_address *addr = (mailimf_address *) current->data; 273 mailimf_address *addr = (mailimf_address *) current->data;
241 274
242 if ( !first ) { 275 if ( !first ) {
243 result.append( "," ); 276 result.append( "," );
244 } else { 277 } else {
245 first = false; 278 first = false;
246 } 279 }
247 280
248 switch ( addr->ad_type ) { 281 switch ( addr->ad_type ) {
249 case MAILIMF_ADDRESS_MAILBOX: 282 case MAILIMF_ADDRESS_MAILBOX:
250 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 283 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
251 break; 284 break;
252 case MAILIMF_ADDRESS_GROUP: 285 case MAILIMF_ADDRESS_GROUP:
253 result.append( parseGroup( addr->ad_data.ad_group ) ); 286 result.append( parseGroup( addr->ad_data.ad_group ) );
254 break; 287 break;
255 default: 288 default:
256 qDebug( "POP3: unkown mailimf address type" ); 289 qDebug( "POP3: unkown mailimf address type" );
257 break; 290 break;
258 } 291 }
259 } 292 }
260 293
261 return result; 294 return result;
262} 295}
263 296
264QString POP3wrapper::parseGroup( mailimf_group *group ) 297QString POP3wrapper::parseGroup( mailimf_group *group )
265{ 298{
266 QString result( "" ); 299 QString result( "" );
267 300
268 result.append( group->grp_display_name ); 301 result.append( group->grp_display_name );
269 result.append( ": " ); 302 result.append( ": " );
270 303
271 if ( group->grp_mb_list != NULL ) { 304 if ( group->grp_mb_list != NULL ) {
272 result.append( parseMailboxList( group->grp_mb_list ) ); 305 result.append( parseMailboxList( group->grp_mb_list ) );
273 } 306 }
274 307
275 result.append( ";" ); 308 result.append( ";" );
276 309
277 return result; 310 return result;
278} 311}
279 312
280QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 313QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
281{ 314{
282 QString result( "" ); 315 QString result( "" );
283 316
284 if ( box->mb_display_name == NULL ) { 317 if ( box->mb_display_name == NULL ) {
285 result.append( box->mb_addr_spec ); 318 result.append( box->mb_addr_spec );
286 } else { 319 } else {
287 result.append( box->mb_display_name ); 320 result.append( convert_String(box->mb_display_name).latin1() );
288 result.append( " <" ); 321 result.append( " <" );
289 result.append( box->mb_addr_spec ); 322 result.append( box->mb_addr_spec );
290 result.append( ">" ); 323 result.append( ">" );
291 } 324 }
292 325
293 return result; 326 return result;
294} 327}
295 328
296QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 329QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
297{ 330{
298 QString result( "" ); 331 QString result( "" );
299 332
300 bool first = true; 333 bool first = true;
301 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 334 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
302 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 335 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
303 336
304 if ( !first ) { 337 if ( !first ) {
305 result.append( "," ); 338 result.append( "," );
306 } else { 339 } else {
307 first = false; 340 first = false;
308 } 341 }
309 342
310 result.append( parseMailbox( box ) ); 343 result.append( parseMailbox( box ) );
311 } 344 }
312 345
313 return result; 346 return result;
314} 347}
315 348
316void POP3wrapper::login() 349void POP3wrapper::login()
317{ 350{
318 /* we'll hold the line */ 351 /* we'll hold the line */
319 if ( m_pop3 != NULL ) return; 352 if ( m_pop3 != NULL ) return;
320 353
321 const char *server, *user, *pass; 354 const char *server, *user, *pass;
322 uint16_t port; 355 uint16_t port;
323 int err = MAILPOP3_NO_ERROR; 356 int err = MAILPOP3_NO_ERROR;
324 357
325 server = account->getServer().latin1(); 358 server = account->getServer().latin1();
326 port = account->getPort().toUInt(); 359 port = account->getPort().toUInt();
327 user = account->getUser().latin1(); 360 user = account->getUser().latin1();
328 pass = account->getPassword().latin1(); 361 pass = account->getPassword().latin1();
329 362
330 m_pop3 = mailpop3_new( 200, &pop3_progress ); 363 m_pop3 = mailpop3_new( 200, &pop3_progress );
331 364
332 // connect 365 // connect
333 if (account->getSSL()) { 366 if (account->getSSL()) {
334 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 367 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
335 } else { 368 } else {
336 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 369 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
337 } 370 }
338 371
339 if ( err != MAILPOP3_NO_ERROR ) { 372 if ( err != MAILPOP3_NO_ERROR ) {
340 qDebug( "pop3: error connecting to %s\n reason: %s", server, 373 qDebug( "pop3: error connecting to %s\n reason: %s", server,
341 m_pop3->pop3_response ); 374 m_pop3->pop3_response );
342 mailpop3_free( m_pop3 ); 375 mailpop3_free( m_pop3 );
343 m_pop3 = NULL; 376 m_pop3 = NULL;
344 return; 377 return;
345 } 378 }
346 qDebug( "POP3: connected!" ); 379 qDebug( "POP3: connected!" );
347 380
348 // login 381 // login
349 // TODO: decide if apop or plain login should be used 382 // TODO: decide if apop or plain login should be used
350 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 383 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
351 if ( err != MAILPOP3_NO_ERROR ) { 384 if ( err != MAILPOP3_NO_ERROR ) {
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 30f80ff..22a4c70 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -1,351 +1,384 @@
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> 5#include <libetpan/mailmime.h>
6#include <libetpan/data_message_driver.h>
6#include <qfile.h> 7#include <qfile.h>
7 8
9/* we don't fetch messages larger than 5 MB */
10#define HARD_MSG_SIZE_LIMIT 5242880
11
8POP3wrapper::POP3wrapper( POP3account *a ) 12POP3wrapper::POP3wrapper( POP3account *a )
9{ 13{
10 account = a; 14 account = a;
11 m_pop3 = NULL; 15 m_pop3 = NULL;
12 msgTempName = a->getFileName()+"_msg_cache"; 16 msgTempName = a->getFileName()+"_msg_cache";
13 last_msg_id = 0; 17 last_msg_id = 0;
14} 18}
15 19
16POP3wrapper::~POP3wrapper() 20POP3wrapper::~POP3wrapper()
17{ 21{
18 logout(); 22 logout();
19 QFile msg_cache(msgTempName); 23 QFile msg_cache(msgTempName);
20 if (msg_cache.exists()) { 24 if (msg_cache.exists()) {
21 msg_cache.remove(); 25 msg_cache.remove();
22 } 26 }
23} 27}
24 28
25void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 29void POP3wrapper::pop3_progress( size_t current, size_t maximum )
26{ 30{
27 //qDebug( "POP3: %i of %i", current, maximum ); 31 //qDebug( "POP3: %i of %i", current, maximum );
28} 32}
29 33
30RecBody POP3wrapper::fetchBody( const RecMail &mail ) 34RecBody POP3wrapper::fetchBody( const RecMail &mail )
31{ 35{
32 int err = MAILPOP3_NO_ERROR; 36 int err = MAILPOP3_NO_ERROR;
33 char *message; 37 char *message;
34 size_t length = 0; 38 size_t length = 0;
35 39
36 login(); 40 login();
37 if ( !m_pop3 ) { 41 if ( !m_pop3 ) {
38 return RecBody(); 42 return RecBody();
39 } 43 }
44
40 RecBody body; 45 RecBody body;
41 46
42 QFile msg_cache(msgTempName); 47 QFile msg_cache(msgTempName);
43 48
49 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
50 qDebug("Message to large: %i",mail.Msgsize());
51 return body;
52 }
44 if (mail.getNumber()!=last_msg_id) { 53 if (mail.getNumber()!=last_msg_id) {
45 if (msg_cache.exists()) { 54 if (msg_cache.exists()) {
46 msg_cache.remove(); 55 msg_cache.remove();
47 } 56 }
48 msg_cache.open(IO_ReadWrite|IO_Truncate); 57 msg_cache.open(IO_ReadWrite|IO_Truncate);
49 last_msg_id = mail.getNumber(); 58 last_msg_id = mail.getNumber();
50 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 59 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
51 if ( err != MAILPOP3_NO_ERROR ) { 60 if ( err != MAILPOP3_NO_ERROR ) {
52 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 61 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
53 last_msg_id = 0; 62 last_msg_id = 0;
54 return RecBody(); 63 return RecBody();
55 } 64 }
56 msg_cache.writeBlock(message,length); 65 msg_cache.writeBlock(message,length);
57 } else { 66 } else {
58 QString msg=""; 67 QString msg="";
59 msg_cache.open(IO_ReadOnly); 68 msg_cache.open(IO_ReadOnly);
60 message = new char[4096]; 69 message = new char[4096];
61 memset(message,0,4096); 70 memset(message,0,4096);
62 while (msg_cache.readBlock(message,4095)>0) { 71 while (msg_cache.readBlock(message,4095)>0) {
63 msg+=message; 72 msg+=message;
64 memset(message,0,4096); 73 memset(message,0,4096);
65 } 74 }
66 delete message; 75 delete message;
67 message = (char*)malloc(msg.length()+1*sizeof(char)); 76 message = (char*)malloc(msg.length()+1*sizeof(char));
68 memset(message,0,msg.length()+1); 77 memset(message,0,msg.length()+1);
69 memcpy(message,msg.latin1(),msg.length()); 78 memcpy(message,msg.latin1(),msg.length());
70 } 79 }
71 body = parseMail(message); 80 body = parseMail(message);
72 free(message); 81 free(message);
73 return body; 82 return body;
74} 83}
75 84
76RecBody POP3wrapper::parseMail( char *message ) 85RecBody POP3wrapper::parseMail( char *message )
77{ 86{
78 int err = MAILIMF_NO_ERROR; 87 int err = MAILIMF_NO_ERROR;
79 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 88 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
80 size_t curTok = 0; 89 size_t curTok = 0;
81 mailimf_message *result = 0; 90 mailimf_message *result = 0;
91 mailmessage * msg=0;
92 struct mailmime * mime=0;
93 struct mailmime_single_fields fields;
94
82 RecBody body; 95 RecBody body;
83 96
84 97
85 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 98 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
86 if ( err != MAILIMF_NO_ERROR ) { 99 if ( err != MAILIMF_NO_ERROR ) {
87 if (result) mailimf_message_free(result); 100 if (result) mailimf_message_free(result);
88 return body; 101 return body;
89 } 102 }
90 103
91 struct mailimf_body * b = 0; 104#if 0
92 struct mailimf_fields * f = 0; 105 char*body_msg = message;
93 106 if ( result && result->msg_body && result->msg_body->bd_text ) {
94 107 body_msg = (char*)result->msg_body->bd_text;
108 result->msg_body->bd_text = 0;
109 }
110
111 msg = mailmessage_new();
112 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg));
113 generic_message_t * msg_data;
114 msg_data = (generic_message_t *)msg->msg_data;
115 msg_data->msg_fetched = 1;
116 msg_data->msg_message = body_msg;
117 msg_data->msg_length = strlen(body_msg);
118 memset(&fields, 0, sizeof(struct mailmime_single_fields));
119 err = mailmessage_get_bodystructure(msg,&mime);
120
121 if (mime->mm_mime_fields != NULL) {
122 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
123 mime->mm_content_type);
124 }
125#endif
126
127#if 1
95 if ( result && result->msg_body && result->msg_body->bd_text ) { 128 if ( result && result->msg_body && result->msg_body->bd_text ) {
96 qDebug( "POP3: bodytext found" ); 129 qDebug( "POP3: bodytext found" );
97 // when curTok isn't set to 0 this line will fault! 'cause upper line faults! 130 // when curTok isn't set to 0 this line will fault! 'cause upper line faults!
98 body.setBodytext( QString( result->msg_body->bd_text ) ); 131 body.setBodytext( QString( result->msg_body->bd_text ) );
99#if 0 132#if 0
100 curTok = 0; 133 curTok = 0;
101 mailmime_content*mresult = 0; 134 mailmime_content*mresult = 0;
102 size_t index = 0; 135 size_t index = 0;
103 mailmime_content_parse(result->msg_body->bd_text, 136 mailmime_content_parse(result->msg_body->bd_text,
104 strlen(result->msg_body->bd_text),&index,&mresult); 137 strlen(result->msg_body->bd_text),&index,&mresult);
105 if (mresult) { 138 if (mresult) {
106 mailmime_content_free(mresult); 139 mailmime_content_free(mresult);
107 } 140 }
108#endif 141#endif
109 mailimf_message_free(result); 142 mailimf_message_free(result);
110 } 143 }
144#endif
111 return body; 145 return body;
112} 146}
113 147
114void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 148void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
115{ 149{
116 int err = MAILPOP3_NO_ERROR; 150 int err = MAILPOP3_NO_ERROR;
117 char * header = 0; 151 char * header = 0;
118 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 152 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
119 size_t length = 0; 153 size_t length = 0;
120 carray * messages = 0; 154 carray * messages = 0;
121 155
122 login(); 156 login();
123 if (!m_pop3) return; 157 if (!m_pop3) return;
124 mailpop3_list( m_pop3, &messages ); 158 mailpop3_list( m_pop3, &messages );
125 159
126 for (unsigned int i = 0; i < carray_count(messages);++i) { 160 for (unsigned int i = 0; i < carray_count(messages);++i) {
127 mailpop3_msg_info *info; 161 mailpop3_msg_info *info;
128 err = mailpop3_get_msg_info(m_pop3,i+1,&info); 162 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
129 if (info->msg_deleted) 163 if (info->msg_deleted)
130 continue; 164 continue;
131 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 165 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
132 if ( err != MAILPOP3_NO_ERROR ) { 166 if ( err != MAILPOP3_NO_ERROR ) {
133 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 167 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
134 free(header); 168 free(header);
135 return; 169 return;
136 } 170 }
137 RecMail *mail = parseHeader( header ); 171 RecMail *mail = parseHeader( header );
138 mail->setNumber( info->msg_index ); 172 mail->setNumber( info->msg_index );
139 mail->setWrapper(this); 173 mail->setWrapper(this);
140 mail->setMsgsize(info->msg_size); 174 mail->setMsgsize(info->msg_size);
141 target.append( mail ); 175 target.append( mail );
142 free(header); 176 free(header);
143 } 177 }
144} 178}
145 179
146RecMail *POP3wrapper::parseHeader( const char *header ) 180RecMail *POP3wrapper::parseHeader( const char *header )
147{ 181{
148 int err = MAILIMF_NO_ERROR; 182 int err = MAILIMF_NO_ERROR;
149 size_t curTok = 0; 183 size_t curTok = 0;
150 RecMail *mail = new RecMail(); 184 RecMail *mail = new RecMail();
151 mailimf_fields *fields; 185 mailimf_fields *fields;
152 mailimf_references * refs; 186 mailimf_references * refs;
153 mailimf_keywords*keys; 187 mailimf_keywords*keys;
154 QString status; 188 QString status;
155 QString value; 189 QString value;
156 QBitArray mFlags(7); 190 QBitArray mFlags(7);
157 191
158 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 192 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
159 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 193 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
160 mailimf_field *field = (mailimf_field *) current->data; 194 mailimf_field *field = (mailimf_field *) current->data;
161 switch ( field->fld_type ) { 195 switch ( field->fld_type ) {
162 case MAILIMF_FIELD_FROM: 196 case MAILIMF_FIELD_FROM:
163 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 197 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
164 break; 198 break;
165 case MAILIMF_FIELD_TO: 199 case MAILIMF_FIELD_TO:
166 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 200 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
167 break; 201 break;
168 case MAILIMF_FIELD_CC: 202 case MAILIMF_FIELD_CC:
169 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 203 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
170 break; 204 break;
171 case MAILIMF_FIELD_BCC: 205 case MAILIMF_FIELD_BCC:
172 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 206 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
173 break; 207 break;
174 case MAILIMF_FIELD_SUBJECT: 208 case MAILIMF_FIELD_SUBJECT:
175 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 209 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
176 break; 210 break;
177 case MAILIMF_FIELD_ORIG_DATE: 211 case MAILIMF_FIELD_ORIG_DATE:
178 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 212 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
179 break; 213 break;
180 case MAILIMF_FIELD_MESSAGE_ID: 214 case MAILIMF_FIELD_MESSAGE_ID:
181 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 215 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
182 break; 216 break;
183 case MAILIMF_FIELD_REFERENCES: 217 case MAILIMF_FIELD_REFERENCES:
184 refs = field->fld_data.fld_references; 218 refs = field->fld_data.fld_references;
185 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 219 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
186 char * text = (char*)refs->mid_list->first->data; 220 char * text = (char*)refs->mid_list->first->data;
187 mail->setReplyto(QString(text)); 221 mail->setReplyto(QString(text));
188 } 222 }
189 break; 223 break;
190 case MAILIMF_FIELD_KEYWORDS: 224 case MAILIMF_FIELD_KEYWORDS:
191 keys = field->fld_data.fld_keywords; 225 keys = field->fld_data.fld_keywords;
192 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 226 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
193 qDebug("Keyword: %s",(char*)cur->data); 227 qDebug("Keyword: %s",(char*)cur->data);
194 } 228 }
195 break; 229 break;
196 case MAILIMF_FIELD_OPTIONAL_FIELD: 230 case MAILIMF_FIELD_OPTIONAL_FIELD:
197 status = field->fld_data.fld_optional_field->fld_name; 231 status = field->fld_data.fld_optional_field->fld_name;
198 value = field->fld_data.fld_optional_field->fld_value; 232 value = field->fld_data.fld_optional_field->fld_value;
199 if (status.lower()=="status") { 233 if (status.lower()=="status") {
200 if (value.lower()=="ro") { 234 if (value.lower()=="ro") {
201 mFlags.setBit(FLAG_SEEN); 235 mFlags.setBit(FLAG_SEEN);
202 } 236 }
203 } else if (status.lower()=="x-status") { 237 } else if (status.lower()=="x-status") {
204 qDebug("X-Status: %s",value.latin1()); 238 qDebug("X-Status: %s",value.latin1());
205 if (value.lower()=="a") { 239 if (value.lower()=="a") {
206
207 mFlags.setBit(FLAG_ANSWERED); 240 mFlags.setBit(FLAG_ANSWERED);
208 } 241 }
209 } else { 242 } else {
210// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 243// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
211// field->fld_data.fld_optional_field->fld_value); 244// field->fld_data.fld_optional_field->fld_value);
212 } 245 }
213 break; 246 break;
214 default: 247 default:
215 qDebug("Non parsed field"); 248 qDebug("Non parsed field");
216 break; 249 break;
217 } 250 }
218 } 251 }
219 if (fields) mailimf_fields_free(fields); 252 if (fields) mailimf_fields_free(fields);
220 mail->setFlags(mFlags); 253 mail->setFlags(mFlags);
221 return mail; 254 return mail;
222} 255}
223 256
224QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 257QString POP3wrapper::parseDateTime( mailimf_date_time *date )
225{ 258{
226 char tmp[23]; 259 char tmp[23];
227 260
228 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 261 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
229 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 262 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
230 263
231 return QString( tmp ); 264 return QString( tmp );
232} 265}
233 266
234QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 267QString POP3wrapper::parseAddressList( mailimf_address_list *list )
235{ 268{
236 QString result( "" ); 269 QString result( "" );
237 270
238 bool first = true; 271 bool first = true;
239 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 272 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
240 mailimf_address *addr = (mailimf_address *) current->data; 273 mailimf_address *addr = (mailimf_address *) current->data;
241 274
242 if ( !first ) { 275 if ( !first ) {
243 result.append( "," ); 276 result.append( "," );
244 } else { 277 } else {
245 first = false; 278 first = false;
246 } 279 }
247 280
248 switch ( addr->ad_type ) { 281 switch ( addr->ad_type ) {
249 case MAILIMF_ADDRESS_MAILBOX: 282 case MAILIMF_ADDRESS_MAILBOX:
250 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 283 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
251 break; 284 break;
252 case MAILIMF_ADDRESS_GROUP: 285 case MAILIMF_ADDRESS_GROUP:
253 result.append( parseGroup( addr->ad_data.ad_group ) ); 286 result.append( parseGroup( addr->ad_data.ad_group ) );
254 break; 287 break;
255 default: 288 default:
256 qDebug( "POP3: unkown mailimf address type" ); 289 qDebug( "POP3: unkown mailimf address type" );
257 break; 290 break;
258 } 291 }
259 } 292 }
260 293
261 return result; 294 return result;
262} 295}
263 296
264QString POP3wrapper::parseGroup( mailimf_group *group ) 297QString POP3wrapper::parseGroup( mailimf_group *group )
265{ 298{
266 QString result( "" ); 299 QString result( "" );
267 300
268 result.append( group->grp_display_name ); 301 result.append( group->grp_display_name );
269 result.append( ": " ); 302 result.append( ": " );
270 303
271 if ( group->grp_mb_list != NULL ) { 304 if ( group->grp_mb_list != NULL ) {
272 result.append( parseMailboxList( group->grp_mb_list ) ); 305 result.append( parseMailboxList( group->grp_mb_list ) );
273 } 306 }
274 307
275 result.append( ";" ); 308 result.append( ";" );
276 309
277 return result; 310 return result;
278} 311}
279 312
280QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 313QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
281{ 314{
282 QString result( "" ); 315 QString result( "" );
283 316
284 if ( box->mb_display_name == NULL ) { 317 if ( box->mb_display_name == NULL ) {
285 result.append( box->mb_addr_spec ); 318 result.append( box->mb_addr_spec );
286 } else { 319 } else {
287 result.append( box->mb_display_name ); 320 result.append( convert_String(box->mb_display_name).latin1() );
288 result.append( " <" ); 321 result.append( " <" );
289 result.append( box->mb_addr_spec ); 322 result.append( box->mb_addr_spec );
290 result.append( ">" ); 323 result.append( ">" );
291 } 324 }
292 325
293 return result; 326 return result;
294} 327}
295 328
296QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 329QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
297{ 330{
298 QString result( "" ); 331 QString result( "" );
299 332
300 bool first = true; 333 bool first = true;
301 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 334 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
302 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 335 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
303 336
304 if ( !first ) { 337 if ( !first ) {
305 result.append( "," ); 338 result.append( "," );
306 } else { 339 } else {
307 first = false; 340 first = false;
308 } 341 }
309 342
310 result.append( parseMailbox( box ) ); 343 result.append( parseMailbox( box ) );
311 } 344 }
312 345
313 return result; 346 return result;
314} 347}
315 348
316void POP3wrapper::login() 349void POP3wrapper::login()
317{ 350{
318 /* we'll hold the line */ 351 /* we'll hold the line */
319 if ( m_pop3 != NULL ) return; 352 if ( m_pop3 != NULL ) return;
320 353
321 const char *server, *user, *pass; 354 const char *server, *user, *pass;
322 uint16_t port; 355 uint16_t port;
323 int err = MAILPOP3_NO_ERROR; 356 int err = MAILPOP3_NO_ERROR;
324 357
325 server = account->getServer().latin1(); 358 server = account->getServer().latin1();
326 port = account->getPort().toUInt(); 359 port = account->getPort().toUInt();
327 user = account->getUser().latin1(); 360 user = account->getUser().latin1();
328 pass = account->getPassword().latin1(); 361 pass = account->getPassword().latin1();
329 362
330 m_pop3 = mailpop3_new( 200, &pop3_progress ); 363 m_pop3 = mailpop3_new( 200, &pop3_progress );
331 364
332 // connect 365 // connect
333 if (account->getSSL()) { 366 if (account->getSSL()) {
334 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 367 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
335 } else { 368 } else {
336 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 369 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
337 } 370 }
338 371
339 if ( err != MAILPOP3_NO_ERROR ) { 372 if ( err != MAILPOP3_NO_ERROR ) {
340 qDebug( "pop3: error connecting to %s\n reason: %s", server, 373 qDebug( "pop3: error connecting to %s\n reason: %s", server,
341 m_pop3->pop3_response ); 374 m_pop3->pop3_response );
342 mailpop3_free( m_pop3 ); 375 mailpop3_free( m_pop3 );
343 m_pop3 = NULL; 376 m_pop3 = NULL;
344 return; 377 return;
345 } 378 }
346 qDebug( "POP3: connected!" ); 379 qDebug( "POP3: connected!" );
347 380
348 // login 381 // login
349 // TODO: decide if apop or plain login should be used 382 // TODO: decide if apop or plain login should be used
350 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 383 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
351 if ( err != MAILPOP3_NO_ERROR ) { 384 if ( err != MAILPOP3_NO_ERROR ) {