-rw-r--r-- | noncore/net/mail/genericwrapper.cpp | 69 | ||||
-rw-r--r-- | noncore/net/mail/genericwrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.cpp | 69 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 72 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 166 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 5 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.cpp | 72 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 166 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 5 |
10 files changed, 284 insertions, 344 deletions
diff --git a/noncore/net/mail/genericwrapper.cpp b/noncore/net/mail/genericwrapper.cpp index c1b6e48..bef6ae5 100644 --- a/noncore/net/mail/genericwrapper.cpp +++ b/noncore/net/mail/genericwrapper.cpp | |||
@@ -1,4 +1,3 @@ | |||
1 | #include "genericwrapper.h" | 1 | #include "genericwrapper.h" |
2 | #include <libetpan/mailmime.h> | 2 | #include <libetpan/libetpan.h> |
3 | #include <libetpan/data_message_driver.h> | ||
4 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
@@ -393 +392,67 @@ void Genericwrapper::cleanMimeCache() | |||
393 | } | 392 | } |
393 | |||
394 | void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox) | ||
395 | { | ||
396 | int r; | ||
397 | mailmessage_list * env_list = 0; | ||
398 | r = mailsession_get_messages_list(session,&env_list); | ||
399 | if (r != MAIL_NO_ERROR) { | ||
400 | qDebug("Error message list"); | ||
401 | return; | ||
402 | } | ||
403 | r = mailsession_get_envelopes_list(session, env_list); | ||
404 | if (r != MAIL_NO_ERROR) { | ||
405 | qDebug("Error filling message list"); | ||
406 | if (env_list) { | ||
407 | mailmessage_list_free(env_list); | ||
408 | } | ||
409 | return; | ||
410 | } | ||
411 | mailimf_references * refs; | ||
412 | uint32_t i = 0; | ||
413 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | ||
414 | mailmessage * msg; | ||
415 | QBitArray mFlags(7); | ||
416 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | ||
417 | if (msg->msg_fields == NULL) { | ||
418 | qDebug("could not fetch envelope of message %i", i); | ||
419 | continue; | ||
420 | } | ||
421 | RecMail * mail = new RecMail(); | ||
422 | mail->setWrapper(this); | ||
423 | mail_flags * flag_result = 0; | ||
424 | r = mailmessage_get_flags(msg,&flag_result); | ||
425 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | ||
426 | mFlags.setBit(FLAG_SEEN); | ||
427 | } | ||
428 | mailimf_single_fields single_fields; | ||
429 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | ||
430 | mail->setMsgsize(msg->msg_size); | ||
431 | mail->setFlags(mFlags); | ||
432 | mail->setMbox(mailbox); | ||
433 | mail->setNumber(i+1); | ||
434 | if (single_fields.fld_subject) | ||
435 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | ||
436 | if (single_fields.fld_from) | ||
437 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | ||
438 | if (single_fields.fld_to) | ||
439 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | ||
440 | if (single_fields.fld_cc) | ||
441 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | ||
442 | if (single_fields.fld_bcc) | ||
443 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | ||
444 | if (single_fields.fld_orig_date) | ||
445 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | ||
446 | if (single_fields.fld_message_id->mid_value) | ||
447 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | ||
448 | refs = single_fields.fld_references; | ||
449 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | ||
450 | char * text = (char*)refs->mid_list->first->data; | ||
451 | mail->setReplyto(QString(text)); | ||
452 | } | ||
453 | target.append(mail); | ||
454 | } | ||
455 | if (env_list) { | ||
456 | mailmessage_list_free(env_list); | ||
457 | } | ||
458 | } | ||
diff --git a/noncore/net/mail/genericwrapper.h b/noncore/net/mail/genericwrapper.h index 90c4b50..54d6ea9 100644 --- a/noncore/net/mail/genericwrapper.h +++ b/noncore/net/mail/genericwrapper.h | |||
@@ -20,2 +20,3 @@ struct mailimf_group; | |||
20 | struct mailimf_address_list; | 20 | struct mailimf_address_list; |
21 | struct mailsession; | ||
21 | 22 | ||
@@ -50,2 +51,3 @@ protected: | |||
50 | static QString getencoding(mailmime_mechanism*aEnc); | 51 | static QString getencoding(mailmime_mechanism*aEnc); |
52 | virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox); | ||
51 | 53 | ||
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp index c1b6e48..bef6ae5 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp | |||
@@ -1,4 +1,3 @@ | |||
1 | #include "genericwrapper.h" | 1 | #include "genericwrapper.h" |
2 | #include <libetpan/mailmime.h> | 2 | #include <libetpan/libetpan.h> |
3 | #include <libetpan/data_message_driver.h> | ||
4 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
@@ -393 +392,67 @@ void Genericwrapper::cleanMimeCache() | |||
393 | } | 392 | } |
393 | |||
394 | void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox) | ||
395 | { | ||
396 | int r; | ||
397 | mailmessage_list * env_list = 0; | ||
398 | r = mailsession_get_messages_list(session,&env_list); | ||
399 | if (r != MAIL_NO_ERROR) { | ||
400 | qDebug("Error message list"); | ||
401 | return; | ||
402 | } | ||
403 | r = mailsession_get_envelopes_list(session, env_list); | ||
404 | if (r != MAIL_NO_ERROR) { | ||
405 | qDebug("Error filling message list"); | ||
406 | if (env_list) { | ||
407 | mailmessage_list_free(env_list); | ||
408 | } | ||
409 | return; | ||
410 | } | ||
411 | mailimf_references * refs; | ||
412 | uint32_t i = 0; | ||
413 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | ||
414 | mailmessage * msg; | ||
415 | QBitArray mFlags(7); | ||
416 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | ||
417 | if (msg->msg_fields == NULL) { | ||
418 | qDebug("could not fetch envelope of message %i", i); | ||
419 | continue; | ||
420 | } | ||
421 | RecMail * mail = new RecMail(); | ||
422 | mail->setWrapper(this); | ||
423 | mail_flags * flag_result = 0; | ||
424 | r = mailmessage_get_flags(msg,&flag_result); | ||
425 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | ||
426 | mFlags.setBit(FLAG_SEEN); | ||
427 | } | ||
428 | mailimf_single_fields single_fields; | ||
429 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | ||
430 | mail->setMsgsize(msg->msg_size); | ||
431 | mail->setFlags(mFlags); | ||
432 | mail->setMbox(mailbox); | ||
433 | mail->setNumber(i+1); | ||
434 | if (single_fields.fld_subject) | ||
435 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | ||
436 | if (single_fields.fld_from) | ||
437 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | ||
438 | if (single_fields.fld_to) | ||
439 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | ||
440 | if (single_fields.fld_cc) | ||
441 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | ||
442 | if (single_fields.fld_bcc) | ||
443 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | ||
444 | if (single_fields.fld_orig_date) | ||
445 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | ||
446 | if (single_fields.fld_message_id->mid_value) | ||
447 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | ||
448 | refs = single_fields.fld_references; | ||
449 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | ||
450 | char * text = (char*)refs->mid_list->first->data; | ||
451 | mail->setReplyto(QString(text)); | ||
452 | } | ||
453 | target.append(mail); | ||
454 | } | ||
455 | if (env_list) { | ||
456 | mailmessage_list_free(env_list); | ||
457 | } | ||
458 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h index 90c4b50..54d6ea9 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.h +++ b/noncore/net/mail/libmailwrapper/genericwrapper.h | |||
@@ -20,2 +20,3 @@ struct mailimf_group; | |||
20 | struct mailimf_address_list; | 20 | struct mailimf_address_list; |
21 | struct mailsession; | ||
21 | 22 | ||
@@ -50,2 +51,3 @@ protected: | |||
50 | static QString getencoding(mailmime_mechanism*aEnc); | 51 | static QString getencoding(mailmime_mechanism*aEnc); |
52 | virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox); | ||
51 | 53 | ||
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index 162a0c9..0aa33dd 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp | |||
@@ -37,69 +37,5 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | |||
37 | } | 37 | } |
38 | mailmessage_list * env_list = 0; | 38 | |
39 | r = mailsession_get_messages_list(folder->fld_session,&env_list); | 39 | parseList(target,folder->fld_session,mailbox); |
40 | if (r != MAIL_NO_ERROR) { | 40 | |
41 | qDebug("Error message list"); | ||
42 | mailfolder_free(folder); | ||
43 | mailstorage_free(storage); | ||
44 | return; | ||
45 | } | ||
46 | r = mailsession_get_envelopes_list(folder->fld_session, env_list); | ||
47 | if (r != MAIL_NO_ERROR) { | ||
48 | qDebug("Error filling message list"); | ||
49 | if (env_list) { | ||
50 | mailmessage_list_free(env_list); | ||
51 | } | ||
52 | mailfolder_free(folder); | ||
53 | mailstorage_free(storage); | ||
54 | return; | ||
55 | } | ||
56 | mailimf_references * refs; | ||
57 | |||
58 | uint32_t i = 0; | ||
59 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | ||
60 | mailmessage * msg; | ||
61 | QBitArray mFlags(7); | ||
62 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | ||
63 | if (msg->msg_fields == NULL) { | ||
64 | qDebug("could not fetch envelope of message %i", i); | ||
65 | continue; | ||
66 | } | ||
67 | RecMail * mail = new RecMail(); | ||
68 | mail->setWrapper(this); | ||
69 | mail_flags * flag_result = 0; | ||
70 | r = mailmessage_get_flags(msg,&flag_result); | ||
71 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | ||
72 | mFlags.setBit(FLAG_SEEN); | ||
73 | } | ||
74 | mailimf_single_fields single_fields; | ||
75 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | ||
76 | mail->setMsgsize(msg->msg_size); | ||
77 | mail->setFlags(mFlags); | ||
78 | mail->setMbox(mailbox); | ||
79 | mail->setNumber(i+1); | ||
80 | if (single_fields.fld_subject) | ||
81 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | ||
82 | if (single_fields.fld_from) | ||
83 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | ||
84 | if (single_fields.fld_to) | ||
85 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | ||
86 | if (single_fields.fld_cc) | ||
87 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | ||
88 | if (single_fields.fld_bcc) | ||
89 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | ||
90 | if (single_fields.fld_orig_date) | ||
91 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | ||
92 | if (single_fields.fld_message_id->mid_value) | ||
93 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | ||
94 | refs = single_fields.fld_references; | ||
95 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | ||
96 | char * text = (char*)refs->mid_list->first->data; | ||
97 | mail->setReplyto(QString(text)); | ||
98 | } | ||
99 | |||
100 | target.append(mail); | ||
101 | } | ||
102 | if (env_list) { | ||
103 | mailmessage_list_free(env_list); | ||
104 | } | ||
105 | mailfolder_disconnect(folder); | 41 | mailfolder_disconnect(folder); |
@@ -107,3 +43,3 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | |||
107 | mailstorage_free(storage); | 43 | mailstorage_free(storage); |
108 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(i)); | 44 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
109 | } | 45 | } |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 2e70dee..de90dd1 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -7,2 +7,3 @@ | |||
7 | #include <qfile.h> | 7 | #include <qfile.h> |
8 | #include <qstring.h> | ||
8 | 9 | ||
@@ -16,2 +17,3 @@ POP3wrapper::POP3wrapper( POP3account *a ) | |||
16 | m_pop3 = NULL; | 17 | m_pop3 = NULL; |
18 | m_folder = NULL; | ||
17 | msgTempName = a->getFileName()+"_msg_cache"; | 19 | msgTempName = a->getFileName()+"_msg_cache"; |
@@ -31,3 +33,3 @@ void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | |||
31 | { | 33 | { |
32 | //qDebug( "POP3: %i of %i", current, maximum ); | 34 | qDebug( "POP3: %i of %i", current, maximum ); |
33 | } | 35 | } |
@@ -37,3 +39,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
37 | int err = MAILPOP3_NO_ERROR; | 39 | int err = MAILPOP3_NO_ERROR; |
38 | char *message; | 40 | char *message = 0; |
39 | size_t length = 0; | 41 | size_t length = 0; |
@@ -46,6 +48,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
46 | RecBody body; | 48 | RecBody body; |
47 | mailmessage * msg = 0; | 49 | mailmessage * mailmsg; |
48 | |||
49 | QFile msg_cache(msgTempName); | ||
50 | |||
51 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { | 50 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { |
@@ -54,3 +53,7 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
54 | } | 53 | } |
54 | |||
55 | QFile msg_cache(msgTempName); | ||
56 | |||
55 | cleanMimeCache(); | 57 | cleanMimeCache(); |
58 | |||
56 | if (mail.getNumber()!=last_msg_id) { | 59 | if (mail.getNumber()!=last_msg_id) { |
@@ -61,10 +64,6 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
61 | last_msg_id = mail.getNumber(); | 64 | last_msg_id = mail.getNumber(); |
62 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | 65 | err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); |
63 | if ( err != MAILPOP3_NO_ERROR ) { | 66 | err = mailmessage_fetch(mailmsg,&message,&length); |
64 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | ||
65 | last_msg_id = 0; | ||
66 | return RecBody(); | ||
67 | } | ||
68 | msg_cache.writeBlock(message,length); | 67 | msg_cache.writeBlock(message,length); |
69 | } else { | 68 | } else { |
70 | QString msg=""; | 69 | QString msg=""; |
@@ -81,21 +80,17 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
81 | memcpy(message,msg.latin1(),msg.length()); | 80 | memcpy(message,msg.latin1(),msg.length()); |
81 | /* transform to libetpan stuff */ | ||
82 | mailmsg = mailmessage_new(); | ||
83 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | ||
84 | generic_message_t * msg_data; | ||
85 | msg_data = (generic_message_t *)mailmsg->msg_data; | ||
86 | msg_data->msg_fetched = 1; | ||
87 | msg_data->msg_message = message; | ||
88 | msg_data->msg_length = strlen(message); | ||
82 | } | 89 | } |
90 | body = parseMail(mailmsg); | ||
83 | 91 | ||
84 | /* transform to libetpan stuff */ | ||
85 | msg = mailmessage_new(); | ||
86 | mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message)); | ||
87 | generic_message_t * msg_data; | ||
88 | msg_data = (generic_message_t *)msg->msg_data; | ||
89 | msg_data->msg_fetched = 1; | ||
90 | msg_data->msg_message = message; | ||
91 | msg_data->msg_length = strlen(message); | ||
92 | |||
93 | /* parse the mail */ | ||
94 | body = parseMail(msg); | ||
95 | |||
96 | /* clean up */ | 92 | /* clean up */ |
97 | mailmessage_free(msg); | 93 | if (mailmsg) mailmessage_free(mailmsg); |
98 | free(message); | 94 | if (message) free(message); |
99 | 95 | ||
100 | /* finish */ | ||
101 | return body; | 96 | return body; |
@@ -105,32 +100,8 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | |||
105 | { | 100 | { |
106 | int err = MAILPOP3_NO_ERROR; | ||
107 | char * header = 0; | ||
108 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | ||
109 | size_t length = 0; | ||
110 | carray * messages = 0; | ||
111 | |||
112 | login(); | 101 | login(); |
113 | if (!m_pop3) return; | 102 | if (!m_pop3) return; |
114 | 103 | uint32_t res_messages,res_recent,res_unseen; | |
115 | mailpop3_list( m_pop3, &messages ); | 104 | mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); |
116 | 105 | parseList(target,m_folder->fld_session,"INBOX"); | |
117 | for (unsigned int i = 0; i < carray_count(messages);++i) { | 106 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); |
118 | mailpop3_msg_info *info; | ||
119 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); | ||
120 | if (info->msg_deleted) | ||
121 | continue; | ||
122 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); | ||
123 | if ( err != MAILPOP3_NO_ERROR ) { | ||
124 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); | ||
125 | free(header); | ||
126 | return; | ||
127 | } | ||
128 | RecMail *mail = parseHeader( header ); | ||
129 | mail->setNumber( info->msg_index ); | ||
130 | mail->setWrapper(this); | ||
131 | mail->setMsgsize(info->msg_size); | ||
132 | target.append( mail ); | ||
133 | free(header); | ||
134 | } | ||
135 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(carray_count(messages)-m_pop3->pop3_deleted_count)); | ||
136 | } | 107 | } |
@@ -154,4 +125,4 @@ void POP3wrapper::login() | |||
154 | // ok | 125 | // ok |
155 | user = strdup( login.getUser().latin1() ); | 126 | user = login.getUser().latin1(); |
156 | pass = strdup( login.getPassword().latin1() ); | 127 | pass = login.getPassword().latin1(); |
157 | } else { | 128 | } else { |
@@ -166,15 +137,13 @@ void POP3wrapper::login() | |||
166 | 137 | ||
167 | m_pop3 = mailpop3_new( 200, &pop3_progress ); | 138 | bool ssl = account->getSSL(); |
168 | 139 | ||
169 | // connect | 140 | m_pop3=mailstorage_new(NULL); |
170 | if (account->getSSL()) { | 141 | pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP, |
171 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); | 142 | (char*)user,(char*)pass,0,0,0); |
172 | } else { | 143 | |
173 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); | 144 | m_folder = mailfolder_new(m_pop3, NULL, NULL); |
174 | } | ||
175 | 145 | ||
176 | if ( err != MAILPOP3_NO_ERROR ) { | 146 | if (m_folder==0) { |
177 | qDebug( "pop3: error connecting to %s\n reason: %s", server, | 147 | Global::statusMessage(tr("Error initializing folder")); |
178 | m_pop3->pop3_response ); | 148 | mailstorage_free(m_pop3); |
179 | mailpop3_free( m_pop3 ); | ||
180 | m_pop3 = NULL; | 149 | m_pop3 = NULL; |
@@ -182,13 +151,10 @@ void POP3wrapper::login() | |||
182 | } | 151 | } |
183 | qDebug( "POP3: connected!" ); | 152 | err = mailfolder_connect(m_folder); |
184 | 153 | if (err != MAIL_NO_ERROR) { | |
185 | // login | 154 | Global::statusMessage(tr("Error initializing folder")); |
186 | // TODO: decide if apop or plain login should be used | 155 | mailfolder_free(m_folder); |
187 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); | 156 | m_folder = 0; |
188 | if ( err != MAILPOP3_NO_ERROR ) { | 157 | mailstorage_free(m_pop3); |
189 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); | 158 | m_pop3 = 0; |
190 | logout(); | ||
191 | return; | ||
192 | } | 159 | } |
193 | |||
194 | qDebug( "POP3: logged in!" ); | 160 | qDebug( "POP3: logged in!" ); |
@@ -200,5 +166,6 @@ void POP3wrapper::logout() | |||
200 | if ( m_pop3 == NULL ) return; | 166 | if ( m_pop3 == NULL ) return; |
201 | err = mailpop3_quit( m_pop3 ); | 167 | mailfolder_free(m_folder); |
202 | mailpop3_free( m_pop3 ); | 168 | m_folder = 0; |
203 | m_pop3 = NULL; | 169 | mailstorage_free(m_pop3); |
170 | m_pop3 = 0; | ||
204 | } | 171 | } |
@@ -219,4 +186,4 @@ void POP3wrapper::deleteMail(const RecMail&mail) | |||
219 | if (!m_pop3) return; | 186 | if (!m_pop3) return; |
220 | int err = mailpop3_dele(m_pop3,mail.getNumber()); | 187 | int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); |
221 | if (err != MAILPOP3_NO_ERROR) { | 188 | if (err != MAIL_NO_ERROR) { |
222 | Global::statusMessage(tr("error deleting mail")); | 189 | Global::statusMessage(tr("error deleting mail")); |
@@ -233,21 +200,18 @@ int POP3wrapper::deleteAllMail(const Folder*) | |||
233 | if (!m_pop3) return 0; | 200 | if (!m_pop3) return 0; |
234 | carray * messages = 0; | ||
235 | |||
236 | /* if connected this info is cached! */ | ||
237 | int err = 0; | ||
238 | mailpop3_list( m_pop3, &messages ); | ||
239 | |||
240 | int res = 1; | 201 | int res = 1; |
241 | for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) { | 202 | |
242 | mailpop3_msg_info *info; | 203 | uint32_t result = 0; |
243 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); | 204 | int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); |
244 | if (info->msg_deleted) | 205 | if (err != MAIL_NO_ERROR) { |
245 | continue; | 206 | Global::statusMessage(tr("Error getting folder info")); |
246 | err = mailpop3_dele(m_pop3,i+1); | 207 | return 0; |
247 | if (err != MAILPOP3_NO_ERROR) { | 208 | } |
209 | for (unsigned int i = 0; i < result; ++i) { | ||
210 | err = mailsession_remove_message(m_folder->fld_session,i+1); | ||
211 | if (err != MAIL_NO_ERROR) { | ||
248 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 212 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
249 | res = 0; | 213 | res=0; |
250 | break; | ||
251 | } | 214 | } |
252 | } | 215 | break; |
216 | } | ||
253 | return res; | 217 | return res; |
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index 2efffdd..b3a42be 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h | |||
@@ -7,2 +7,4 @@ | |||
7 | 7 | ||
8 | struct mailstorage; | ||
9 | struct mailfolder; | ||
8 | 10 | ||
@@ -30,3 +32,4 @@ protected: | |||
30 | POP3account *account; | 32 | POP3account *account; |
31 | mailpop3 *m_pop3; | 33 | mailstorage*m_pop3; |
34 | mailfolder*m_folder; | ||
32 | }; | 35 | }; |
diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp index 162a0c9..0aa33dd 100644 --- a/noncore/net/mail/mboxwrapper.cpp +++ b/noncore/net/mail/mboxwrapper.cpp | |||
@@ -37,69 +37,5 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | |||
37 | } | 37 | } |
38 | mailmessage_list * env_list = 0; | 38 | |
39 | r = mailsession_get_messages_list(folder->fld_session,&env_list); | 39 | parseList(target,folder->fld_session,mailbox); |
40 | if (r != MAIL_NO_ERROR) { | 40 | |
41 | qDebug("Error message list"); | ||
42 | mailfolder_free(folder); | ||
43 | mailstorage_free(storage); | ||
44 | return; | ||
45 | } | ||
46 | r = mailsession_get_envelopes_list(folder->fld_session, env_list); | ||
47 | if (r != MAIL_NO_ERROR) { | ||
48 | qDebug("Error filling message list"); | ||
49 | if (env_list) { | ||
50 | mailmessage_list_free(env_list); | ||
51 | } | ||
52 | mailfolder_free(folder); | ||
53 | mailstorage_free(storage); | ||
54 | return; | ||
55 | } | ||
56 | mailimf_references * refs; | ||
57 | |||
58 | uint32_t i = 0; | ||
59 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | ||
60 | mailmessage * msg; | ||
61 | QBitArray mFlags(7); | ||
62 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | ||
63 | if (msg->msg_fields == NULL) { | ||
64 | qDebug("could not fetch envelope of message %i", i); | ||
65 | continue; | ||
66 | } | ||
67 | RecMail * mail = new RecMail(); | ||
68 | mail->setWrapper(this); | ||
69 | mail_flags * flag_result = 0; | ||
70 | r = mailmessage_get_flags(msg,&flag_result); | ||
71 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | ||
72 | mFlags.setBit(FLAG_SEEN); | ||
73 | } | ||
74 | mailimf_single_fields single_fields; | ||
75 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | ||
76 | mail->setMsgsize(msg->msg_size); | ||
77 | mail->setFlags(mFlags); | ||
78 | mail->setMbox(mailbox); | ||
79 | mail->setNumber(i+1); | ||
80 | if (single_fields.fld_subject) | ||
81 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | ||
82 | if (single_fields.fld_from) | ||
83 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | ||
84 | if (single_fields.fld_to) | ||
85 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | ||
86 | if (single_fields.fld_cc) | ||
87 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | ||
88 | if (single_fields.fld_bcc) | ||
89 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | ||
90 | if (single_fields.fld_orig_date) | ||
91 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | ||
92 | if (single_fields.fld_message_id->mid_value) | ||
93 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | ||
94 | refs = single_fields.fld_references; | ||
95 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | ||
96 | char * text = (char*)refs->mid_list->first->data; | ||
97 | mail->setReplyto(QString(text)); | ||
98 | } | ||
99 | |||
100 | target.append(mail); | ||
101 | } | ||
102 | if (env_list) { | ||
103 | mailmessage_list_free(env_list); | ||
104 | } | ||
105 | mailfolder_disconnect(folder); | 41 | mailfolder_disconnect(folder); |
@@ -107,3 +43,3 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | |||
107 | mailstorage_free(storage); | 43 | mailstorage_free(storage); |
108 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(i)); | 44 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); |
109 | } | 45 | } |
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index 2e70dee..de90dd1 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp | |||
@@ -7,2 +7,3 @@ | |||
7 | #include <qfile.h> | 7 | #include <qfile.h> |
8 | #include <qstring.h> | ||
8 | 9 | ||
@@ -16,2 +17,3 @@ POP3wrapper::POP3wrapper( POP3account *a ) | |||
16 | m_pop3 = NULL; | 17 | m_pop3 = NULL; |
18 | m_folder = NULL; | ||
17 | msgTempName = a->getFileName()+"_msg_cache"; | 19 | msgTempName = a->getFileName()+"_msg_cache"; |
@@ -31,3 +33,3 @@ void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | |||
31 | { | 33 | { |
32 | //qDebug( "POP3: %i of %i", current, maximum ); | 34 | qDebug( "POP3: %i of %i", current, maximum ); |
33 | } | 35 | } |
@@ -37,3 +39,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
37 | int err = MAILPOP3_NO_ERROR; | 39 | int err = MAILPOP3_NO_ERROR; |
38 | char *message; | 40 | char *message = 0; |
39 | size_t length = 0; | 41 | size_t length = 0; |
@@ -46,6 +48,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
46 | RecBody body; | 48 | RecBody body; |
47 | mailmessage * msg = 0; | 49 | mailmessage * mailmsg; |
48 | |||
49 | QFile msg_cache(msgTempName); | ||
50 | |||
51 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { | 50 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { |
@@ -54,3 +53,7 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
54 | } | 53 | } |
54 | |||
55 | QFile msg_cache(msgTempName); | ||
56 | |||
55 | cleanMimeCache(); | 57 | cleanMimeCache(); |
58 | |||
56 | if (mail.getNumber()!=last_msg_id) { | 59 | if (mail.getNumber()!=last_msg_id) { |
@@ -61,10 +64,6 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
61 | last_msg_id = mail.getNumber(); | 64 | last_msg_id = mail.getNumber(); |
62 | err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); | 65 | err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); |
63 | if ( err != MAILPOP3_NO_ERROR ) { | 66 | err = mailmessage_fetch(mailmsg,&message,&length); |
64 | qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); | ||
65 | last_msg_id = 0; | ||
66 | return RecBody(); | ||
67 | } | ||
68 | msg_cache.writeBlock(message,length); | 67 | msg_cache.writeBlock(message,length); |
69 | } else { | 68 | } else { |
70 | QString msg=""; | 69 | QString msg=""; |
@@ -81,21 +80,17 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
81 | memcpy(message,msg.latin1(),msg.length()); | 80 | memcpy(message,msg.latin1(),msg.length()); |
81 | /* transform to libetpan stuff */ | ||
82 | mailmsg = mailmessage_new(); | ||
83 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | ||
84 | generic_message_t * msg_data; | ||
85 | msg_data = (generic_message_t *)mailmsg->msg_data; | ||
86 | msg_data->msg_fetched = 1; | ||
87 | msg_data->msg_message = message; | ||
88 | msg_data->msg_length = strlen(message); | ||
82 | } | 89 | } |
90 | body = parseMail(mailmsg); | ||
83 | 91 | ||
84 | /* transform to libetpan stuff */ | ||
85 | msg = mailmessage_new(); | ||
86 | mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message)); | ||
87 | generic_message_t * msg_data; | ||
88 | msg_data = (generic_message_t *)msg->msg_data; | ||
89 | msg_data->msg_fetched = 1; | ||
90 | msg_data->msg_message = message; | ||
91 | msg_data->msg_length = strlen(message); | ||
92 | |||
93 | /* parse the mail */ | ||
94 | body = parseMail(msg); | ||
95 | |||
96 | /* clean up */ | 92 | /* clean up */ |
97 | mailmessage_free(msg); | 93 | if (mailmsg) mailmessage_free(mailmsg); |
98 | free(message); | 94 | if (message) free(message); |
99 | 95 | ||
100 | /* finish */ | ||
101 | return body; | 96 | return body; |
@@ -105,32 +100,8 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | |||
105 | { | 100 | { |
106 | int err = MAILPOP3_NO_ERROR; | ||
107 | char * header = 0; | ||
108 | /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ | ||
109 | size_t length = 0; | ||
110 | carray * messages = 0; | ||
111 | |||
112 | login(); | 101 | login(); |
113 | if (!m_pop3) return; | 102 | if (!m_pop3) return; |
114 | 103 | uint32_t res_messages,res_recent,res_unseen; | |
115 | mailpop3_list( m_pop3, &messages ); | 104 | mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); |
116 | 105 | parseList(target,m_folder->fld_session,"INBOX"); | |
117 | for (unsigned int i = 0; i < carray_count(messages);++i) { | 106 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); |
118 | mailpop3_msg_info *info; | ||
119 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); | ||
120 | if (info->msg_deleted) | ||
121 | continue; | ||
122 | err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); | ||
123 | if ( err != MAILPOP3_NO_ERROR ) { | ||
124 | qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); | ||
125 | free(header); | ||
126 | return; | ||
127 | } | ||
128 | RecMail *mail = parseHeader( header ); | ||
129 | mail->setNumber( info->msg_index ); | ||
130 | mail->setWrapper(this); | ||
131 | mail->setMsgsize(info->msg_size); | ||
132 | target.append( mail ); | ||
133 | free(header); | ||
134 | } | ||
135 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(carray_count(messages)-m_pop3->pop3_deleted_count)); | ||
136 | } | 107 | } |
@@ -154,4 +125,4 @@ void POP3wrapper::login() | |||
154 | // ok | 125 | // ok |
155 | user = strdup( login.getUser().latin1() ); | 126 | user = login.getUser().latin1(); |
156 | pass = strdup( login.getPassword().latin1() ); | 127 | pass = login.getPassword().latin1(); |
157 | } else { | 128 | } else { |
@@ -166,15 +137,13 @@ void POP3wrapper::login() | |||
166 | 137 | ||
167 | m_pop3 = mailpop3_new( 200, &pop3_progress ); | 138 | bool ssl = account->getSSL(); |
168 | 139 | ||
169 | // connect | 140 | m_pop3=mailstorage_new(NULL); |
170 | if (account->getSSL()) { | 141 | pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP, |
171 | err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); | 142 | (char*)user,(char*)pass,0,0,0); |
172 | } else { | 143 | |
173 | err = mailpop3_socket_connect( m_pop3, (char*)server, port ); | 144 | m_folder = mailfolder_new(m_pop3, NULL, NULL); |
174 | } | ||
175 | 145 | ||
176 | if ( err != MAILPOP3_NO_ERROR ) { | 146 | if (m_folder==0) { |
177 | qDebug( "pop3: error connecting to %s\n reason: %s", server, | 147 | Global::statusMessage(tr("Error initializing folder")); |
178 | m_pop3->pop3_response ); | 148 | mailstorage_free(m_pop3); |
179 | mailpop3_free( m_pop3 ); | ||
180 | m_pop3 = NULL; | 149 | m_pop3 = NULL; |
@@ -182,13 +151,10 @@ void POP3wrapper::login() | |||
182 | } | 151 | } |
183 | qDebug( "POP3: connected!" ); | 152 | err = mailfolder_connect(m_folder); |
184 | 153 | if (err != MAIL_NO_ERROR) { | |
185 | // login | 154 | Global::statusMessage(tr("Error initializing folder")); |
186 | // TODO: decide if apop or plain login should be used | 155 | mailfolder_free(m_folder); |
187 | err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); | 156 | m_folder = 0; |
188 | if ( err != MAILPOP3_NO_ERROR ) { | 157 | mailstorage_free(m_pop3); |
189 | qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); | 158 | m_pop3 = 0; |
190 | logout(); | ||
191 | return; | ||
192 | } | 159 | } |
193 | |||
194 | qDebug( "POP3: logged in!" ); | 160 | qDebug( "POP3: logged in!" ); |
@@ -200,5 +166,6 @@ void POP3wrapper::logout() | |||
200 | if ( m_pop3 == NULL ) return; | 166 | if ( m_pop3 == NULL ) return; |
201 | err = mailpop3_quit( m_pop3 ); | 167 | mailfolder_free(m_folder); |
202 | mailpop3_free( m_pop3 ); | 168 | m_folder = 0; |
203 | m_pop3 = NULL; | 169 | mailstorage_free(m_pop3); |
170 | m_pop3 = 0; | ||
204 | } | 171 | } |
@@ -219,4 +186,4 @@ void POP3wrapper::deleteMail(const RecMail&mail) | |||
219 | if (!m_pop3) return; | 186 | if (!m_pop3) return; |
220 | int err = mailpop3_dele(m_pop3,mail.getNumber()); | 187 | int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); |
221 | if (err != MAILPOP3_NO_ERROR) { | 188 | if (err != MAIL_NO_ERROR) { |
222 | Global::statusMessage(tr("error deleting mail")); | 189 | Global::statusMessage(tr("error deleting mail")); |
@@ -233,21 +200,18 @@ int POP3wrapper::deleteAllMail(const Folder*) | |||
233 | if (!m_pop3) return 0; | 200 | if (!m_pop3) return 0; |
234 | carray * messages = 0; | ||
235 | |||
236 | /* if connected this info is cached! */ | ||
237 | int err = 0; | ||
238 | mailpop3_list( m_pop3, &messages ); | ||
239 | |||
240 | int res = 1; | 201 | int res = 1; |
241 | for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) { | 202 | |
242 | mailpop3_msg_info *info; | 203 | uint32_t result = 0; |
243 | err = mailpop3_get_msg_info(m_pop3,i+1,&info); | 204 | int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); |
244 | if (info->msg_deleted) | 205 | if (err != MAIL_NO_ERROR) { |
245 | continue; | 206 | Global::statusMessage(tr("Error getting folder info")); |
246 | err = mailpop3_dele(m_pop3,i+1); | 207 | return 0; |
247 | if (err != MAILPOP3_NO_ERROR) { | 208 | } |
209 | for (unsigned int i = 0; i < result; ++i) { | ||
210 | err = mailsession_remove_message(m_folder->fld_session,i+1); | ||
211 | if (err != MAIL_NO_ERROR) { | ||
248 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 212 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
249 | res = 0; | 213 | res=0; |
250 | break; | ||
251 | } | 214 | } |
252 | } | 215 | break; |
216 | } | ||
253 | return res; | 217 | return res; |
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index 2efffdd..b3a42be 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h | |||
@@ -7,2 +7,4 @@ | |||
7 | 7 | ||
8 | struct mailstorage; | ||
9 | struct mailfolder; | ||
8 | 10 | ||
@@ -30,3 +32,4 @@ protected: | |||
30 | POP3account *account; | 32 | POP3account *account; |
31 | mailpop3 *m_pop3; | 33 | mailstorage*m_pop3; |
34 | mailfolder*m_folder; | ||
32 | }; | 35 | }; |