-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 @@ #include "genericwrapper.h" -#include <libetpan/mailmime.h> -#include <libetpan/data_message_driver.h> +#include <libetpan/libetpan.h> #include "mailtypes.h" @@ -393 +392,67 @@ void Genericwrapper::cleanMimeCache() } + +void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox) +{ + int r; + mailmessage_list * env_list = 0; + r = mailsession_get_messages_list(session,&env_list); + if (r != MAIL_NO_ERROR) { + qDebug("Error message list"); + return; + } + r = mailsession_get_envelopes_list(session, env_list); + if (r != MAIL_NO_ERROR) { + qDebug("Error filling message list"); + if (env_list) { + mailmessage_list_free(env_list); + } + return; + } + mailimf_references * refs; + uint32_t i = 0; + for(; i < carray_count(env_list->msg_tab) ; ++i) { + mailmessage * msg; + QBitArray mFlags(7); + msg = (mailmessage*)carray_get(env_list->msg_tab, i); + if (msg->msg_fields == NULL) { + qDebug("could not fetch envelope of message %i", i); + continue; + } + RecMail * mail = new RecMail(); + mail->setWrapper(this); + mail_flags * flag_result = 0; + r = mailmessage_get_flags(msg,&flag_result); + if (r == MAIL_ERROR_NOT_IMPLEMENTED) { + mFlags.setBit(FLAG_SEEN); + } + mailimf_single_fields single_fields; + mailimf_single_fields_init(&single_fields, msg->msg_fields); + mail->setMsgsize(msg->msg_size); + mail->setFlags(mFlags); + mail->setMbox(mailbox); + mail->setNumber(i+1); + if (single_fields.fld_subject) + mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); + if (single_fields.fld_from) + mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); + if (single_fields.fld_to) + mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); + if (single_fields.fld_cc) + mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); + if (single_fields.fld_bcc) + mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); + if (single_fields.fld_orig_date) + mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); + if (single_fields.fld_message_id->mid_value) + mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); + refs = single_fields.fld_references; + if (refs && refs->mid_list && clist_count(refs->mid_list)) { + char * text = (char*)refs->mid_list->first->data; + mail->setReplyto(QString(text)); + } + target.append(mail); + } + if (env_list) { + mailmessage_list_free(env_list); + } +} 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; struct mailimf_address_list; +struct mailsession; @@ -50,2 +51,3 @@ protected: static QString getencoding(mailmime_mechanism*aEnc); + virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox); 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 @@ #include "genericwrapper.h" -#include <libetpan/mailmime.h> -#include <libetpan/data_message_driver.h> +#include <libetpan/libetpan.h> #include "mailtypes.h" @@ -393 +392,67 @@ void Genericwrapper::cleanMimeCache() } + +void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox) +{ + int r; + mailmessage_list * env_list = 0; + r = mailsession_get_messages_list(session,&env_list); + if (r != MAIL_NO_ERROR) { + qDebug("Error message list"); + return; + } + r = mailsession_get_envelopes_list(session, env_list); + if (r != MAIL_NO_ERROR) { + qDebug("Error filling message list"); + if (env_list) { + mailmessage_list_free(env_list); + } + return; + } + mailimf_references * refs; + uint32_t i = 0; + for(; i < carray_count(env_list->msg_tab) ; ++i) { + mailmessage * msg; + QBitArray mFlags(7); + msg = (mailmessage*)carray_get(env_list->msg_tab, i); + if (msg->msg_fields == NULL) { + qDebug("could not fetch envelope of message %i", i); + continue; + } + RecMail * mail = new RecMail(); + mail->setWrapper(this); + mail_flags * flag_result = 0; + r = mailmessage_get_flags(msg,&flag_result); + if (r == MAIL_ERROR_NOT_IMPLEMENTED) { + mFlags.setBit(FLAG_SEEN); + } + mailimf_single_fields single_fields; + mailimf_single_fields_init(&single_fields, msg->msg_fields); + mail->setMsgsize(msg->msg_size); + mail->setFlags(mFlags); + mail->setMbox(mailbox); + mail->setNumber(i+1); + if (single_fields.fld_subject) + mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); + if (single_fields.fld_from) + mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); + if (single_fields.fld_to) + mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); + if (single_fields.fld_cc) + mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); + if (single_fields.fld_bcc) + mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); + if (single_fields.fld_orig_date) + mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); + if (single_fields.fld_message_id->mid_value) + mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); + refs = single_fields.fld_references; + if (refs && refs->mid_list && clist_count(refs->mid_list)) { + char * text = (char*)refs->mid_list->first->data; + mail->setReplyto(QString(text)); + } + target.append(mail); + } + if (env_list) { + mailmessage_list_free(env_list); + } +} 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; struct mailimf_address_list; +struct mailsession; @@ -50,2 +51,3 @@ protected: static QString getencoding(mailmime_mechanism*aEnc); + virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox); 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 ) } - mailmessage_list * env_list = 0; - r = mailsession_get_messages_list(folder->fld_session,&env_list); - if (r != MAIL_NO_ERROR) { - qDebug("Error message list"); - mailfolder_free(folder); - mailstorage_free(storage); - return; - } - r = mailsession_get_envelopes_list(folder->fld_session, env_list); - if (r != MAIL_NO_ERROR) { - qDebug("Error filling message list"); - if (env_list) { - mailmessage_list_free(env_list); - } - mailfolder_free(folder); - mailstorage_free(storage); - return; - } - mailimf_references * refs; - - uint32_t i = 0; - for(; i < carray_count(env_list->msg_tab) ; ++i) { - mailmessage * msg; - QBitArray mFlags(7); - msg = (mailmessage*)carray_get(env_list->msg_tab, i); - if (msg->msg_fields == NULL) { - qDebug("could not fetch envelope of message %i", i); - continue; - } - RecMail * mail = new RecMail(); - mail->setWrapper(this); - mail_flags * flag_result = 0; - r = mailmessage_get_flags(msg,&flag_result); - if (r == MAIL_ERROR_NOT_IMPLEMENTED) { - mFlags.setBit(FLAG_SEEN); - } - mailimf_single_fields single_fields; - mailimf_single_fields_init(&single_fields, msg->msg_fields); - mail->setMsgsize(msg->msg_size); - mail->setFlags(mFlags); - mail->setMbox(mailbox); - mail->setNumber(i+1); - if (single_fields.fld_subject) - mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); - if (single_fields.fld_from) - mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); - if (single_fields.fld_to) - mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); - if (single_fields.fld_cc) - mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); - if (single_fields.fld_bcc) - mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); - if (single_fields.fld_orig_date) - mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); - if (single_fields.fld_message_id->mid_value) - mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); - refs = single_fields.fld_references; - if (refs && refs->mid_list && clist_count(refs->mid_list)) { - char * text = (char*)refs->mid_list->first->data; - mail->setReplyto(QString(text)); - } - - target.append(mail); - } - if (env_list) { - mailmessage_list_free(env_list); - } + + parseList(target,folder->fld_session,mailbox); + mailfolder_disconnect(folder); @@ -107,3 +43,3 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) mailstorage_free(storage); - Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(i)); + Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); } 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 @@ #include <qfile.h> +#include <qstring.h> @@ -16,2 +17,3 @@ POP3wrapper::POP3wrapper( POP3account *a ) m_pop3 = NULL; + m_folder = NULL; msgTempName = a->getFileName()+"_msg_cache"; @@ -31,3 +33,3 @@ void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { - //qDebug( "POP3: %i of %i", current, maximum ); + qDebug( "POP3: %i of %i", current, maximum ); } @@ -37,3 +39,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) int err = MAILPOP3_NO_ERROR; - char *message; + char *message = 0; size_t length = 0; @@ -46,6 +48,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) RecBody body; - mailmessage * msg = 0; - - QFile msg_cache(msgTempName); - + mailmessage * mailmsg; if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { @@ -54,3 +53,7 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) } + + QFile msg_cache(msgTempName); + cleanMimeCache(); + if (mail.getNumber()!=last_msg_id) { @@ -61,10 +64,6 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) last_msg_id = mail.getNumber(); - err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); - if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); - last_msg_id = 0; - return RecBody(); - } + err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); + err = mailmessage_fetch(mailmsg,&message,&length); msg_cache.writeBlock(message,length); - } else { + } else { QString msg=""; @@ -81,21 +80,17 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) memcpy(message,msg.latin1(),msg.length()); + /* transform to libetpan stuff */ + mailmsg = mailmessage_new(); + mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); + generic_message_t * msg_data; + msg_data = (generic_message_t *)mailmsg->msg_data; + msg_data->msg_fetched = 1; + msg_data->msg_message = message; + msg_data->msg_length = strlen(message); } + body = parseMail(mailmsg); - /* transform to libetpan stuff */ - msg = mailmessage_new(); - mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message)); - generic_message_t * msg_data; - msg_data = (generic_message_t *)msg->msg_data; - msg_data->msg_fetched = 1; - msg_data->msg_message = message; - msg_data->msg_length = strlen(message); - - /* parse the mail */ - body = parseMail(msg); - /* clean up */ - mailmessage_free(msg); - free(message); - - /* finish */ + if (mailmsg) mailmessage_free(mailmsg); + if (message) free(message); + return body; @@ -105,32 +100,8 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { - int err = MAILPOP3_NO_ERROR; - char * header = 0; - /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ - size_t length = 0; - carray * messages = 0; - login(); if (!m_pop3) return; - - mailpop3_list( m_pop3, &messages ); - - for (unsigned int i = 0; i < carray_count(messages);++i) { - mailpop3_msg_info *info; - err = mailpop3_get_msg_info(m_pop3,i+1,&info); - if (info->msg_deleted) - continue; - err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); - if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); - free(header); - return; - } - RecMail *mail = parseHeader( header ); - mail->setNumber( info->msg_index ); - mail->setWrapper(this); - mail->setMsgsize(info->msg_size); - target.append( mail ); - free(header); - } - Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(carray_count(messages)-m_pop3->pop3_deleted_count)); + uint32_t res_messages,res_recent,res_unseen; + mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); + parseList(target,m_folder->fld_session,"INBOX"); + Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); } @@ -154,4 +125,4 @@ void POP3wrapper::login() // ok - user = strdup( login.getUser().latin1() ); - pass = strdup( login.getPassword().latin1() ); + user = login.getUser().latin1(); + pass = login.getPassword().latin1(); } else { @@ -166,15 +137,13 @@ void POP3wrapper::login() - m_pop3 = mailpop3_new( 200, &pop3_progress ); + bool ssl = account->getSSL(); - // connect - if (account->getSSL()) { - err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); - } else { - err = mailpop3_socket_connect( m_pop3, (char*)server, port ); - } + m_pop3=mailstorage_new(NULL); + pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP, + (char*)user,(char*)pass,0,0,0); + + m_folder = mailfolder_new(m_pop3, NULL, NULL); - if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "pop3: error connecting to %s\n reason: %s", server, - m_pop3->pop3_response ); - mailpop3_free( m_pop3 ); + if (m_folder==0) { + Global::statusMessage(tr("Error initializing folder")); + mailstorage_free(m_pop3); m_pop3 = NULL; @@ -182,13 +151,10 @@ void POP3wrapper::login() } - qDebug( "POP3: connected!" ); - - // login - // TODO: decide if apop or plain login should be used - err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); - if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); - logout(); - return; + err = mailfolder_connect(m_folder); + if (err != MAIL_NO_ERROR) { + Global::statusMessage(tr("Error initializing folder")); + mailfolder_free(m_folder); + m_folder = 0; + mailstorage_free(m_pop3); + m_pop3 = 0; } - qDebug( "POP3: logged in!" ); @@ -200,5 +166,6 @@ void POP3wrapper::logout() if ( m_pop3 == NULL ) return; - err = mailpop3_quit( m_pop3 ); - mailpop3_free( m_pop3 ); - m_pop3 = NULL; + mailfolder_free(m_folder); + m_folder = 0; + mailstorage_free(m_pop3); + m_pop3 = 0; } @@ -219,4 +186,4 @@ void POP3wrapper::deleteMail(const RecMail&mail) if (!m_pop3) return; - int err = mailpop3_dele(m_pop3,mail.getNumber()); - if (err != MAILPOP3_NO_ERROR) { + int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); + if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("error deleting mail")); @@ -233,21 +200,18 @@ int POP3wrapper::deleteAllMail(const Folder*) if (!m_pop3) return 0; - carray * messages = 0; - - /* if connected this info is cached! */ - int err = 0; - mailpop3_list( m_pop3, &messages ); - int res = 1; - for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) { - mailpop3_msg_info *info; - err = mailpop3_get_msg_info(m_pop3,i+1,&info); - if (info->msg_deleted) - continue; - err = mailpop3_dele(m_pop3,i+1); - if (err != MAILPOP3_NO_ERROR) { + + uint32_t result = 0; + int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); + if (err != MAIL_NO_ERROR) { + Global::statusMessage(tr("Error getting folder info")); + return 0; + } + for (unsigned int i = 0; i < result; ++i) { + err = mailsession_remove_message(m_folder->fld_session,i+1); + if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); - res = 0; - break; + res=0; } - } + break; + } 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 @@ +struct mailstorage; +struct mailfolder; @@ -30,3 +32,4 @@ protected: POP3account *account; - mailpop3 *m_pop3; + mailstorage*m_pop3; + mailfolder*m_folder; }; 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 ) } - mailmessage_list * env_list = 0; - r = mailsession_get_messages_list(folder->fld_session,&env_list); - if (r != MAIL_NO_ERROR) { - qDebug("Error message list"); - mailfolder_free(folder); - mailstorage_free(storage); - return; - } - r = mailsession_get_envelopes_list(folder->fld_session, env_list); - if (r != MAIL_NO_ERROR) { - qDebug("Error filling message list"); - if (env_list) { - mailmessage_list_free(env_list); - } - mailfolder_free(folder); - mailstorage_free(storage); - return; - } - mailimf_references * refs; - - uint32_t i = 0; - for(; i < carray_count(env_list->msg_tab) ; ++i) { - mailmessage * msg; - QBitArray mFlags(7); - msg = (mailmessage*)carray_get(env_list->msg_tab, i); - if (msg->msg_fields == NULL) { - qDebug("could not fetch envelope of message %i", i); - continue; - } - RecMail * mail = new RecMail(); - mail->setWrapper(this); - mail_flags * flag_result = 0; - r = mailmessage_get_flags(msg,&flag_result); - if (r == MAIL_ERROR_NOT_IMPLEMENTED) { - mFlags.setBit(FLAG_SEEN); - } - mailimf_single_fields single_fields; - mailimf_single_fields_init(&single_fields, msg->msg_fields); - mail->setMsgsize(msg->msg_size); - mail->setFlags(mFlags); - mail->setMbox(mailbox); - mail->setNumber(i+1); - if (single_fields.fld_subject) - mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); - if (single_fields.fld_from) - mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); - if (single_fields.fld_to) - mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); - if (single_fields.fld_cc) - mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); - if (single_fields.fld_bcc) - mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); - if (single_fields.fld_orig_date) - mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); - if (single_fields.fld_message_id->mid_value) - mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); - refs = single_fields.fld_references; - if (refs && refs->mid_list && clist_count(refs->mid_list)) { - char * text = (char*)refs->mid_list->first->data; - mail->setReplyto(QString(text)); - } - - target.append(mail); - } - if (env_list) { - mailmessage_list_free(env_list); - } + + parseList(target,folder->fld_session,mailbox); + mailfolder_disconnect(folder); @@ -107,3 +43,3 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) mailstorage_free(storage); - Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(i)); + Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); } 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 @@ #include <qfile.h> +#include <qstring.h> @@ -16,2 +17,3 @@ POP3wrapper::POP3wrapper( POP3account *a ) m_pop3 = NULL; + m_folder = NULL; msgTempName = a->getFileName()+"_msg_cache"; @@ -31,3 +33,3 @@ void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { - //qDebug( "POP3: %i of %i", current, maximum ); + qDebug( "POP3: %i of %i", current, maximum ); } @@ -37,3 +39,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) int err = MAILPOP3_NO_ERROR; - char *message; + char *message = 0; size_t length = 0; @@ -46,6 +48,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) RecBody body; - mailmessage * msg = 0; - - QFile msg_cache(msgTempName); - + mailmessage * mailmsg; if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { @@ -54,3 +53,7 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) } + + QFile msg_cache(msgTempName); + cleanMimeCache(); + if (mail.getNumber()!=last_msg_id) { @@ -61,10 +64,6 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) last_msg_id = mail.getNumber(); - err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); - if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); - last_msg_id = 0; - return RecBody(); - } + err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); + err = mailmessage_fetch(mailmsg,&message,&length); msg_cache.writeBlock(message,length); - } else { + } else { QString msg=""; @@ -81,21 +80,17 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) memcpy(message,msg.latin1(),msg.length()); + /* transform to libetpan stuff */ + mailmsg = mailmessage_new(); + mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); + generic_message_t * msg_data; + msg_data = (generic_message_t *)mailmsg->msg_data; + msg_data->msg_fetched = 1; + msg_data->msg_message = message; + msg_data->msg_length = strlen(message); } + body = parseMail(mailmsg); - /* transform to libetpan stuff */ - msg = mailmessage_new(); - mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message)); - generic_message_t * msg_data; - msg_data = (generic_message_t *)msg->msg_data; - msg_data->msg_fetched = 1; - msg_data->msg_message = message; - msg_data->msg_length = strlen(message); - - /* parse the mail */ - body = parseMail(msg); - /* clean up */ - mailmessage_free(msg); - free(message); - - /* finish */ + if (mailmsg) mailmessage_free(mailmsg); + if (message) free(message); + return body; @@ -105,32 +100,8 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { - int err = MAILPOP3_NO_ERROR; - char * header = 0; - /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ - size_t length = 0; - carray * messages = 0; - login(); if (!m_pop3) return; - - mailpop3_list( m_pop3, &messages ); - - for (unsigned int i = 0; i < carray_count(messages);++i) { - mailpop3_msg_info *info; - err = mailpop3_get_msg_info(m_pop3,i+1,&info); - if (info->msg_deleted) - continue; - err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); - if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); - free(header); - return; - } - RecMail *mail = parseHeader( header ); - mail->setNumber( info->msg_index ); - mail->setWrapper(this); - mail->setMsgsize(info->msg_size); - target.append( mail ); - free(header); - } - Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(carray_count(messages)-m_pop3->pop3_deleted_count)); + uint32_t res_messages,res_recent,res_unseen; + mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); + parseList(target,m_folder->fld_session,"INBOX"); + Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); } @@ -154,4 +125,4 @@ void POP3wrapper::login() // ok - user = strdup( login.getUser().latin1() ); - pass = strdup( login.getPassword().latin1() ); + user = login.getUser().latin1(); + pass = login.getPassword().latin1(); } else { @@ -166,15 +137,13 @@ void POP3wrapper::login() - m_pop3 = mailpop3_new( 200, &pop3_progress ); + bool ssl = account->getSSL(); - // connect - if (account->getSSL()) { - err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); - } else { - err = mailpop3_socket_connect( m_pop3, (char*)server, port ); - } + m_pop3=mailstorage_new(NULL); + pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP, + (char*)user,(char*)pass,0,0,0); + + m_folder = mailfolder_new(m_pop3, NULL, NULL); - if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "pop3: error connecting to %s\n reason: %s", server, - m_pop3->pop3_response ); - mailpop3_free( m_pop3 ); + if (m_folder==0) { + Global::statusMessage(tr("Error initializing folder")); + mailstorage_free(m_pop3); m_pop3 = NULL; @@ -182,13 +151,10 @@ void POP3wrapper::login() } - qDebug( "POP3: connected!" ); - - // login - // TODO: decide if apop or plain login should be used - err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); - if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); - logout(); - return; + err = mailfolder_connect(m_folder); + if (err != MAIL_NO_ERROR) { + Global::statusMessage(tr("Error initializing folder")); + mailfolder_free(m_folder); + m_folder = 0; + mailstorage_free(m_pop3); + m_pop3 = 0; } - qDebug( "POP3: logged in!" ); @@ -200,5 +166,6 @@ void POP3wrapper::logout() if ( m_pop3 == NULL ) return; - err = mailpop3_quit( m_pop3 ); - mailpop3_free( m_pop3 ); - m_pop3 = NULL; + mailfolder_free(m_folder); + m_folder = 0; + mailstorage_free(m_pop3); + m_pop3 = 0; } @@ -219,4 +186,4 @@ void POP3wrapper::deleteMail(const RecMail&mail) if (!m_pop3) return; - int err = mailpop3_dele(m_pop3,mail.getNumber()); - if (err != MAILPOP3_NO_ERROR) { + int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); + if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("error deleting mail")); @@ -233,21 +200,18 @@ int POP3wrapper::deleteAllMail(const Folder*) if (!m_pop3) return 0; - carray * messages = 0; - - /* if connected this info is cached! */ - int err = 0; - mailpop3_list( m_pop3, &messages ); - int res = 1; - for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) { - mailpop3_msg_info *info; - err = mailpop3_get_msg_info(m_pop3,i+1,&info); - if (info->msg_deleted) - continue; - err = mailpop3_dele(m_pop3,i+1); - if (err != MAILPOP3_NO_ERROR) { + + uint32_t result = 0; + int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); + if (err != MAIL_NO_ERROR) { + Global::statusMessage(tr("Error getting folder info")); + return 0; + } + for (unsigned int i = 0; i < result; ++i) { + err = mailsession_remove_message(m_folder->fld_session,i+1); + if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); - res = 0; - break; + res=0; } - } + break; + } 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 @@ +struct mailstorage; +struct mailfolder; @@ -30,3 +32,4 @@ protected: POP3account *account; - mailpop3 *m_pop3; + mailstorage*m_pop3; + mailfolder*m_folder; }; |