author | alwin <alwin> | 2004-01-04 16:33:39 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-04 16:33:39 (UTC) |
commit | 6ee1d5d35243f611e0a848d454bfa309b8de0fc9 (patch) (side-by-side diff) | |
tree | a07cc2d85da3df79904f363da262834f64b64736 | |
parent | 59fee003137f5fd7782e3a42159e53424d100e67 (diff) | |
download | opie-6ee1d5d35243f611e0a848d454bfa309b8de0fc9.zip opie-6ee1d5d35243f611e0a848d454bfa309b8de0fc9.tar.gz opie-6ee1d5d35243f611e0a848d454bfa309b8de0fc9.tar.bz2 |
- added start of status class
- unification of (public) mailwrapper interfaces
- preparition for message store/transfer
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 12 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.h | 3 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 15 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 5 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/libmailwrapper.pro | 16 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 8 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 4 |
7 files changed, 46 insertions, 17 deletions
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h index ca9caed..a070fb0 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.h +++ b/noncore/net/mail/libmailwrapper/abstractmail.h @@ -1,55 +1,57 @@ #ifndef __abstract_mail_ #define __abstract_mail_ #include <qobject.h> #include "settings.h" class RecMail; class RecBody; class RecPart; class IMAPwrapper; class POP3wrapper; class Folder; class encodedString; struct folderStat; class AbstractMail:public QObject { Q_OBJECT public: AbstractMail(){}; virtual ~AbstractMail(){} virtual QList<Folder>* listFolders()=0; virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; virtual RecBody fetchBody(const RecMail&mail)=0; virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; virtual void deleteMail(const RecMail&mail)=0; virtual void answeredMail(const RecMail&mail)=0; - virtual void cleanMimeCache(){}; - virtual int deleteAllMail(const Folder*){return 1;} - virtual int deleteMbox(const Folder*){return 1;} - + virtual int deleteAllMail(const Folder*)=0; + virtual int deleteMbox(const Folder*)=0; + virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; + + virtual void cleanMimeCache(){}; /* mail box methods */ /* parameter is the box to create. * if the implementing subclass has prefixes, * them has to be appended automatic. */ virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); - + virtual void logout()=0; + static AbstractMail* getWrapper(IMAPaccount *a); static AbstractMail* getWrapper(POP3account *a); /* mbox only! */ static AbstractMail* getWrapper(const QString&a); static QString defaultLocalfolder(); protected: static encodedString*decode_String(const encodedString*text,const QString&enc); static QString convert_String(const char*text); static QString gen_attachment_id(); }; #endif diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h index 32b75c8..1d65c0a 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.h +++ b/noncore/net/mail/libmailwrapper/genericwrapper.h @@ -1,59 +1,62 @@ #ifndef __GENERIC_WRAPPER_H #define __GENERIC_WRAPPER_H #include "abstractmail.h" #include <qmap.h> #include <qstring.h> #include <libetpan/clist.h> class RecMail; class RecBody; class encodedString; struct mailpop3; struct mailmessage; struct mailmime; struct mailmime_mechanism; struct mailimf_mailbox_list; struct mailimf_mailbox; struct mailimf_date_time; struct mailimf_group; struct mailimf_address_list; struct mailsession; /* this class hold just the funs shared between * mbox and pop3 (later mh, too) mail access. * it is not desigend to make a instance of it! */ class Genericwrapper : public AbstractMail { Q_OBJECT public: Genericwrapper(); virtual ~Genericwrapper(); virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); virtual void cleanMimeCache(); + virtual int deleteMbox(const Folder*){return 1;} + virtual void logout(){}; + virtual void storeMessage(const char*msg,size_t length, const QString&folder){}; protected: RecMail *parseHeader( const char *header ); RecBody parseMail( mailmessage * msg ); QString parseMailboxList( mailimf_mailbox_list *list ); QString parseMailbox( mailimf_mailbox *box ); QString parseGroup( mailimf_group *group ); QString parseAddressList( mailimf_address_list *list ); QString parseDateTime( mailimf_date_time *date ); void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1); static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); static void fillParameters(RecPart&target,clist*parameters); static QString getencoding(mailmime_mechanism*aEnc); virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox); QString msgTempName; unsigned int last_msg_id; QMap<QString,encodedString*> bodyCache; }; #endif diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index f1d42c2..0c1e05e 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp @@ -1,243 +1,243 @@ #include <stdlib.h> #include <libetpan/libetpan.h> #include <qpe/global.h> #include "imapwrapper.h" #include "mailtypes.h" #include "logindialog.h" IMAPwrapper::IMAPwrapper( IMAPaccount *a ) : AbstractMail() { account = a; m_imap = 0; } IMAPwrapper::~IMAPwrapper() { logout(); } void IMAPwrapper::imap_progress( size_t current, size_t maximum ) { qDebug( "IMAP: %i of %i", current, maximum ); } void IMAPwrapper::login() { const char *server, *user, *pass; uint16_t port; int err = MAILIMAP_NO_ERROR; /* we are connected this moment */ /* TODO: setup a timer holding the line or if connection closed - delete the value */ if (m_imap) { err = mailimap_noop(m_imap); if (err!=MAILIMAP_NO_ERROR) { logout(); } else { mailstream_flush(m_imap->imap_stream); return; } } server = account->getServer().latin1(); port = account->getPort().toUInt(); if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); login.show(); if ( QDialog::Accepted == login.exec() ) { // ok - user = strdup( login.getUser().latin1() ); - pass = strdup( login.getPassword().latin1() ); + user = login.getUser().latin1(); + pass = login.getPassword().latin1(); } else { // cancel qDebug( "IMAP: Login canceled" ); return; } } else { user = account->getUser().latin1(); pass = account->getPassword().latin1(); } m_imap = mailimap_new( 20, &imap_progress ); /* connect */ if (account->getSSL()) { err = mailimap_ssl_connect( m_imap, (char*)server, port ); } else { err = mailimap_socket_connect( m_imap, (char*)server, port ); } if ( err != MAILIMAP_NO_ERROR && err != MAILIMAP_NO_ERROR_AUTHENTICATED && err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { QString failure = ""; if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { failure="Connection refused"; } else { failure="Unknown failure"; } Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); mailimap_free( m_imap ); m_imap = 0; return; } /* login */ err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); if ( err != MAILIMAP_NO_ERROR ) { Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); err = mailimap_close( m_imap ); mailimap_free( m_imap ); m_imap = 0; } } void IMAPwrapper::logout() { int err = MAILIMAP_NO_ERROR; if (!m_imap) return; err = mailimap_logout( m_imap ); err = mailimap_close( m_imap ); mailimap_free( m_imap ); m_imap = 0; } void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) { const char *mb = 0; int err = MAILIMAP_NO_ERROR; clist *result = 0; clistcell *current; // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; mailimap_fetch_type *fetchType = 0; mailimap_set *set = 0; mb = mailbox.latin1(); login(); if (!m_imap) { return; } /* select mailbox READONLY for operations */ err = mailimap_examine( m_imap, (char*)mb); if ( err != MAILIMAP_NO_ERROR ) { Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); return; } int last = m_imap->imap_selection_info->sel_exists; if (last == 0) { Global::statusMessage(tr("Mailbox has no mails")); return; } else { Global::statusMessage(tr("Mailbox has %1 mails").arg(last)); } /* the range has to start at 1!!! not with 0!!!! */ set = mailimap_set_new_interval( 1, last ); fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); err = mailimap_fetch( m_imap, set, fetchType, &result ); mailimap_set_free( set ); mailimap_fetch_type_free( fetchType ); QString date,subject,from; if ( err == MAILIMAP_NO_ERROR ) { mailimap_msg_att * msg_att; int i = 0; for (current = clist_begin(result); current != 0; current=clist_next(current)) { ++i; msg_att = (mailimap_msg_att*)current->data; RecMail*m = parse_list_result(msg_att); if (m) { m->setNumber(i); m->setMbox(mailbox); m->setWrapper(this); target.append(m); } } } else { Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); } if (result) mailimap_fetch_list_free(result); } QList<Folder>* IMAPwrapper::listFolders() { const char *path, *mask; int err = MAILIMAP_NO_ERROR; clist *result = 0; clistcell *current = 0; clistcell*cur_flag = 0; mailimap_mbx_list_flags*bflags = 0; QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( false ); login(); if (!m_imap) { return folders; } /* * First we have to check for INBOX 'cause it sometimes it's not inside the path. * We must not forget to filter them out in next loop! * it seems like ugly code. and yes - it is ugly code. but the best way. */ QString temp; mask = "INBOX" ; mailimap_mailbox_list *list; err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); QString del; bool selectable = true; bool no_inferiors = false; if ( err == MAILIMAP_NO_ERROR ) { current = result->first; for ( int i = result->count; i > 0; i-- ) { list = (mailimap_mailbox_list *) current->data; // it is better use the deep copy mechanism of qt itself // instead of using strdup! temp = list->mb_name; del = list->mb_delimiter; current = current->next; if ( (bflags = list->mb_flag) ) { selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { no_inferiors = true; } } } folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); } } else { qDebug("error fetching folders: %s",m_imap->imap_response); } mailimap_list_result_free( result ); /* * second stage - get the other then inbox folders */ mask = "*" ; path = account->getPrefix().latin1(); if (!path) path = ""; qDebug(path); err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); if ( err == MAILIMAP_NO_ERROR ) { current = result->first; for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { no_inferiors = false; list = (mailimap_mailbox_list *) current->data; // it is better use the deep copy mechanism of qt itself // instead of using strdup! temp = list->mb_name; if (temp.lower()=="inbox") continue; if (temp.lower()==account->getPrefix().lower()) continue; @@ -785,192 +785,203 @@ void IMAPwrapper::deleteMail(const RecMail&mail) if (err != MAILIMAP_NO_ERROR) { qDebug("error deleting mail: %s",m_imap->imap_response); } qDebug("Delete successfull %s",m_imap->imap_response); } void IMAPwrapper::answeredMail(const RecMail&mail) { mailimap_flag_list*flist; mailimap_set *set; mailimap_store_att_flags * store_flags; int err; login(); if (!m_imap) { return; } const char *mb = mail.getMbox().latin1(); err = mailimap_select( m_imap, (char*)mb); if ( err != MAILIMAP_NO_ERROR ) { qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); return; } flist = mailimap_flag_list_new_empty(); mailimap_flag_list_add(flist,mailimap_flag_new_answered()); store_flags = mailimap_store_att_flags_new_add_flags(flist); set = mailimap_set_new_single(mail.getNumber()); err = mailimap_store(m_imap,set,store_flags); mailimap_set_free( set ); mailimap_store_att_flags_free(store_flags); if (err != MAILIMAP_NO_ERROR) { qDebug("error marking mail: %s",m_imap->imap_response); return; } } QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) { QString body(""); encodedString*res = fetchRawPart(mail,path,internal_call); encodedString*r = decode_String(res,enc); delete res; if (r) { if (r->Length()>0) { body = r->Content(); } delete r; } return body; } QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) { return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); } encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) { encodedString*res = fetchRawPart(mail,part.Positionlist(),false); encodedString*r = decode_String(res,part.Encoding()); delete res; return r; } encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) { return fetchRawPart(mail,part.Positionlist(),false); } int IMAPwrapper::deleteAllMail(const Folder*folder) { login(); if (!m_imap) { return 0; } mailimap_flag_list*flist; mailimap_set *set; mailimap_store_att_flags * store_flags; int err = mailimap_select( m_imap, folder->getName().latin1()); if ( err != MAILIMAP_NO_ERROR ) { Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); return 0; } int last = m_imap->imap_selection_info->sel_exists; if (last == 0) { Global::statusMessage(tr("Mailbox has no mails!")); return 0; } flist = mailimap_flag_list_new_empty(); mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); store_flags = mailimap_store_att_flags_new_set_flags(flist); set = mailimap_set_new_interval( 1, last ); err = mailimap_store(m_imap,set,store_flags); mailimap_set_free( set ); mailimap_store_att_flags_free(store_flags); if (err != MAILIMAP_NO_ERROR) { Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); return 0; } qDebug("deleting mail: %s",m_imap->imap_response); /* should we realy do that at this moment? */ err = mailimap_expunge(m_imap); if (err != MAILIMAP_NO_ERROR) { Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); return 0; } qDebug("Delete successfull %s",m_imap->imap_response); return 1; } int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) { if (folder.length()==0) return 0; login(); if (!m_imap) {return 0;} QString pre = account->getPrefix(); if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { pre+=delemiter; } if (parentfolder) { pre += parentfolder->getDisplayName()+delemiter; } pre+=folder; if (getsubfolder) { if (delemiter.length()>0) { pre+=delemiter; } else { Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); return 0; } } qDebug("Creating %s",pre.latin1()); int res = mailimap_create(m_imap,pre.latin1()); if (res != MAILIMAP_NO_ERROR) { Global::statusMessage(tr("%1").arg(m_imap->imap_response)); return 0; } return 1; } int IMAPwrapper::deleteMbox(const Folder*folder) { if (!folder) return 0; login(); if (!m_imap) {return 0;} int res = mailimap_delete(m_imap,folder->getName()); if (res != MAILIMAP_NO_ERROR) { Global::statusMessage(tr("%1").arg(m_imap->imap_response)); return 0; } return 1; } void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) { mailimap_status_att_list * att_list =0; mailimap_mailbox_data_status * status=0; clistiter * cur = 0; int r = 0; int res = 0; target_stat.message_count = 0; target_stat.message_unseen = 0; target_stat.message_recent = 0; login(); if (!m_imap) { return; } att_list = mailimap_status_att_list_new_empty(); if (!att_list) return; r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); for (cur = clist_begin(status->st_info_list); cur != NULL ; cur = clist_next(cur)) { mailimap_status_info * status_info; status_info = (mailimap_status_info *)clist_content(cur); switch (status_info->st_att) { case MAILIMAP_STATUS_ATT_MESSAGES: target_stat.message_count = status_info->st_value; break; case MAILIMAP_STATUS_ATT_RECENT: target_stat.message_recent = status_info->st_value; break; case MAILIMAP_STATUS_ATT_UNSEEN: target_stat.message_unseen = status_info->st_value; break; } } mailimap_mailbox_data_status_free(status); mailimap_status_att_list_free(att_list); } + +void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) +{ + login(); + if (!m_imap) return; + if (!msg) return; + int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); + if (r != MAILIMAP_NO_ERROR) { + Global::statusMessage("Error storing mail!"); + } +} diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index 8f5a2b5..a97f12d 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h @@ -1,68 +1,69 @@ #ifndef __IMAPWRAPPER #define __IMAPWRAPPER #include <qlist.h> #include "mailwrapper.h" #include "abstractmail.h" #include <libetpan/clist.h> struct mailimap; struct mailimap_body; struct mailimap_body_type_1part; struct mailimap_body_type_text; struct mailimap_body_type_basic; struct mailimap_body_type_msg; struct mailimap_body_type_mpart; struct mailimap_body_fields; struct mailimap_msg_att; class encodedString; class IMAPwrapper : public AbstractMail { Q_OBJECT public: IMAPwrapper( IMAPaccount *a ); virtual ~IMAPwrapper(); virtual QList<Folder>* listFolders(); virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); virtual void deleteMail(const RecMail&mail); virtual void answeredMail(const RecMail&mail); virtual int deleteAllMail(const Folder*folder); + virtual void storeMessage(const char*msg,size_t length, const QString&folder); virtual RecBody fetchBody(const RecMail&mail); virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); virtual int deleteMbox(const Folder*folder); static void imap_progress( size_t current, size_t maximum ); - + + virtual void logout(); protected: RecMail*parse_list_result(mailimap_msg_att*); void login(); - void logout(); virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); /* just helpers */ static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); static QStringList address_list_to_stringlist(clist*list); IMAPaccount *account; mailimap *m_imap; }; #endif diff --git a/noncore/net/mail/libmailwrapper/libmailwrapper.pro b/noncore/net/mail/libmailwrapper/libmailwrapper.pro index 4b4a4f1..18583bb 100644 --- a/noncore/net/mail/libmailwrapper/libmailwrapper.pro +++ b/noncore/net/mail/libmailwrapper/libmailwrapper.pro @@ -1,44 +1,46 @@ TEMPLATE = lib CONFIG += qt warn_on debug HEADERS = mailwrapper.h \ imapwrapper.h \ mailtypes.h \ pop3wrapper.h \ abstractmail.h \ smtpwrapper.h \ genericwrapper.h \ mboxwrapper.h \ - settings.h \ - logindialog.h \ - sendmailprogress.h + settings.h \ + logindialog.h \ + sendmailprogress.h \ + statusmail.h SOURCES = imapwrapper.cpp \ mailwrapper.cpp \ mailtypes.cpp \ pop3wrapper.cpp \ abstractmail.cpp \ smtpwrapper.cpp \ genericwrapper.cpp \ mboxwrapper.cpp \ - settings.cpp \ - logindialog.cpp \ - sendmailprogress.cpp + settings.cpp \ + logindialog.cpp \ + sendmailprogress.cpp \ + statusmail.cpp INTERFACES = logindialogui.ui \ - sendmailprogressui.ui + sendmailprogressui.ui INCLUDEPATH += $(OPIEDIR)/include CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) contains( CONFTEST, y ){ LIBS += -lqpe -letpan -lssl -lcrypto -liconv }else{ LIBS += -lqpe -letpan -lssl -lcrypto } DESTDIR = $(OPIEDIR)/lib$(PROJMAK) TARGET = mailwrapper include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index d76d82a..b4eca6f 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -38,192 +38,200 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) { int err = MAILPOP3_NO_ERROR; char *message = 0; size_t length = 0; login(); if ( !m_pop3 ) { return RecBody(); } RecBody body; mailmessage * mailmsg; if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { qDebug("Message to large: %i",mail.Msgsize()); return body; } QFile msg_cache(msgTempName); cleanMimeCache(); if (mail.getNumber()!=last_msg_id) { if (msg_cache.exists()) { msg_cache.remove(); } msg_cache.open(IO_ReadWrite|IO_Truncate); last_msg_id = mail.getNumber(); err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); err = mailmessage_fetch(mailmsg,&message,&length); msg_cache.writeBlock(message,length); } else { QString msg=""; msg_cache.open(IO_ReadOnly); message = new char[4096]; memset(message,0,4096); while (msg_cache.readBlock(message,4095)>0) { msg+=message; memset(message,0,4096); } delete message; message = (char*)malloc(msg.length()+1*sizeof(char)); memset(message,0,msg.length()+1); 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); /* clean up */ if (mailmsg) mailmessage_free(mailmsg); if (message) free(message); return body; } void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { login(); if (!m_pop3) return; 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)); } void POP3wrapper::login() { /* we'll hold the line */ if ( m_pop3 != NULL ) return; const char *server, *user, *pass; uint16_t port; int err = MAILPOP3_NO_ERROR; server = account->getServer().latin1(); port = account->getPort().toUInt(); if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); login.show(); if ( QDialog::Accepted == login.exec() ) { // ok user = login.getUser().latin1(); pass = login.getPassword().latin1(); } else { // cancel qDebug( "POP3: Login canceled" ); return; } } else { user = account->getUser().latin1(); pass = account->getPassword().latin1(); } bool ssl = account->getSSL(); 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 (m_folder==0) { Global::statusMessage(tr("Error initializing folder")); mailstorage_free(m_pop3); m_pop3 = NULL; 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!" ); } void POP3wrapper::logout() { int err = MAILPOP3_NO_ERROR; if ( m_pop3 == NULL ) return; mailfolder_free(m_folder); m_folder = 0; mailstorage_free(m_pop3); m_pop3 = 0; } QList<Folder>* POP3wrapper::listFolders() { QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( false ); Folder*inb=new Folder("INBOX","/"); folders->append(inb); return folders; } void POP3wrapper::deleteMail(const RecMail&mail) { login(); if (!m_pop3) return; int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("error deleting mail")); } } void POP3wrapper::answeredMail(const RecMail&) { } int POP3wrapper::deleteAllMail(const Folder*) { login(); if (!m_pop3) return 0; int res = 1; 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; } return res; } void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { login(); target_stat.message_count = 0; target_stat.message_unseen = 0; target_stat.message_recent = 0; if (!m_pop3) return; int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, &target_stat.message_recent,&target_stat.message_unseen); } + +void POP3wrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) +{ + mailmessage * mailmsg = 0; + int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); + err = mailmessage_fetch(mailmsg,target,length); + if (mailmsg) mailmessage_free(mailmsg); +} diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index 536cadc..9cba101 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h @@ -1,39 +1,41 @@ #ifndef __POP3WRAPPER #define __POP3WRAPPER #include "mailwrapper.h" #include "genericwrapper.h" #include <qstring.h> struct mailstorage; struct mailfolder; class POP3wrapper : public Genericwrapper { Q_OBJECT public: POP3wrapper( POP3account *a ); virtual ~POP3wrapper(); /* mailbox will be ignored */ virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); virtual QList<Folder>* listFolders(); /* mailbox will be ignored */ virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); virtual void deleteMail(const RecMail&mail); virtual void answeredMail(const RecMail&mail); virtual int deleteAllMail(const Folder*); virtual RecBody fetchBody( const RecMail &mail ); + virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); + virtual void logout(); + static void pop3_progress( size_t current, size_t maximum ); protected: void login(); - void logout(); POP3account *account; mailstorage*m_pop3; mailfolder*m_folder; }; #endif |