-rw-r--r-- | noncore/net/mail/abstractmail.cpp | 13 | ||||
-rw-r--r-- | noncore/net/mail/abstractmail.h | 30 | ||||
-rw-r--r-- | noncore/net/mail/accountview.cpp | 16 | ||||
-rw-r--r-- | noncore/net/mail/accountview.h | 15 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 5 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.h | 17 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.cpp | 13 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 30 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 5 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 17 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 21 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 11 | ||||
-rw-r--r-- | noncore/net/mail/mail.pro | 6 | ||||
-rw-r--r-- | noncore/net/mail/mainwindow.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/opiemail.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 21 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 11 |
17 files changed, 180 insertions, 56 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp new file mode 100644 index 0000000..7380c31 --- a/dev/null +++ b/noncore/net/mail/abstractmail.cpp @@ -0,0 +1,13 @@ +#include "abstractmail.h" +#include "imapwrapper.h" +#include "pop3wrapper.h" + +AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) +{ + return new IMAPwrapper(a); +} + +AbstractMail* AbstractMail::getWrapper(POP3account *a) +{ + return new POP3wrapper(a); +} diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h new file mode 100644 index 0000000..bc8938f --- a/dev/null +++ b/noncore/net/mail/abstractmail.h @@ -0,0 +1,30 @@ +#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 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 RecBody fetchBody(const RecMail&mail)=0; + virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false)=0; + virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; + + static AbstractMail* getWrapper(IMAPaccount *a); + static AbstractMail* getWrapper(POP3account *a); +}; + +#endif diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp index c7b1eeb..1069b9f 100644 --- a/noncore/net/mail/accountview.cpp +++ b/noncore/net/mail/accountview.cpp @@ -1,160 +1,158 @@ #include "accountview.h" -#include "imapwrapper.h" -#include "pop3wrapper.h" #include "mailtypes.h" #include "defines.h" /** * POP3 Account stuff */ POP3viewItem::POP3viewItem( POP3account *a, QListView *parent ) : AccountViewItem( parent ) { account = a; - wrapper = new POP3wrapper( account ); + wrapper = AbstractMail::getWrapper( account ); setPixmap( 0, PIXMAP_POP3FOLDER ); setText( 0, account->getAccountName() ); } POP3viewItem::~POP3viewItem() { delete wrapper; } void POP3viewItem::refresh( QList<RecMail> &target ) { qDebug( "POP3: refresh" ); - wrapper->listMessages( target ); + wrapper->listMessages("INBOX", target ); } RecBody POP3viewItem::fetchBody( const RecMail &mail ) { qDebug( "POP3 fetchBody" ); return wrapper->fetchBody( mail ); } /** * IMAP Account stuff */ IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) : AccountViewItem( parent ) { account = a; - wrapper = new IMAPwrapper( account ); + wrapper = AbstractMail::getWrapper( account ); setPixmap( 0, PIXMAP_IMAPFOLDER ); setText( 0, account->getAccountName() ); setOpen( true ); } IMAPviewItem::~IMAPviewItem() { delete wrapper; } -IMAPwrapper *IMAPviewItem::getWrapper() +AbstractMail *IMAPviewItem::getWrapper() { return wrapper; } void IMAPviewItem::refresh(QList<RecMail>&) { - QList<IMAPFolder> *folders = wrapper->listFolders(); + QList<Folder> *folders = wrapper->listFolders(); QListViewItem *child = firstChild(); while ( child ) { QListViewItem *tmp = child; child = child->nextSibling(); delete tmp; } - IMAPFolder *it; + Folder *it; for ( it = folders->first(); it; it = folders->next() ) { (void) new IMAPfolderItem( it, this ); } } RecBody IMAPviewItem::fetchBody(const RecMail&) { return RecBody(); } IMAPfolderItem::~IMAPfolderItem() { delete folder; } -IMAPfolderItem::IMAPfolderItem( IMAPFolder *folderInit, IMAPviewItem *parent ) +IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent ) : AccountViewItem( parent ) { folder = folderInit; imap = parent; setPixmap( 0, PIXMAP_IMAPFOLDER ); setText( 0, folder->getDisplayName() ); } void IMAPfolderItem::refresh(QList<RecMail>&target) { imap->getWrapper()->listMessages( folder->getName(),target ); } RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) { return imap->getWrapper()->fetchBody(aMail); } /** * Generic stuff */ AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) : QListView( parent, name, flags ) { connect( this, SIGNAL( clicked( QListViewItem * ) ), SLOT( refresh( QListViewItem * ) ) ); } void AccountView::populate( QList<Account> list ) { clear(); Account *it; for ( it = list.first(); it; it = list.next() ) { if ( it->getType().compare( "IMAP" ) == 0 ) { IMAPaccount *imap = static_cast<IMAPaccount *>(it); qDebug( "added IMAP " + imap->getAccountName() ); (void) new IMAPviewItem( imap, this ); } else if ( it->getType().compare( "POP3" ) == 0 ) { POP3account *pop3 = static_cast<POP3account *>(it); qDebug( "added POP3 " + pop3->getAccountName() ); (void) new POP3viewItem( pop3, this ); } } } void AccountView::refresh(QListViewItem *item) { qDebug("AccountView refresh..."); if ( item ) { QList<RecMail> headerlist; headerlist.setAutoDelete(true); AccountViewItem *view = static_cast<AccountViewItem *>(item); view->refresh(headerlist); emit refreshMailview(&headerlist); } } void AccountView::refreshAll() { } RecBody AccountView::fetchBody(const RecMail&aMail) { QListViewItem*item = selectedItem (); if (!item) return RecBody(); AccountViewItem *view = static_cast<AccountViewItem *>(item); return view->fetchBody(aMail); } diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h index 4cac673..83d49af 100644 --- a/noncore/net/mail/accountview.h +++ b/noncore/net/mail/accountview.h @@ -1,88 +1,85 @@ #ifndef ACCOUNTVIEW_H #define ACCOUNTVIEW_H #include <qlistview.h> #include <qlist.h> #include "settings.h" #include "mailwrapper.h" +#include "abstractmail.h" -class IMAPwrapper; class POP3wrapper; class RecMail; class RecBody; class AccountViewItem : public QListViewItem { public: AccountViewItem( QListView *parent ) : QListViewItem( parent ) {} AccountViewItem( QListViewItem *parent ) : QListViewItem( parent ) {} virtual void refresh(QList<RecMail>&)=0; virtual RecBody fetchBody(const RecMail&)=0; }; class POP3viewItem : public AccountViewItem { public: POP3viewItem( POP3account *a, QListView *parent ); ~POP3viewItem(); virtual void refresh( QList<RecMail> &target ); virtual RecBody fetchBody( const RecMail &mail ); private: POP3account *account; - POP3wrapper *wrapper; + AbstractMail *wrapper; }; class IMAPviewItem : public AccountViewItem { public: IMAPviewItem( IMAPaccount *a, QListView *parent ); ~IMAPviewItem(); virtual void refresh(QList<RecMail>&); virtual RecBody fetchBody(const RecMail&); - IMAPwrapper *getWrapper(); - + AbstractMail *getWrapper(); private: IMAPaccount *account; - IMAPwrapper *wrapper; - + AbstractMail *wrapper; }; class IMAPfolderItem : public AccountViewItem { public: - IMAPfolderItem( IMAPFolder *folder, IMAPviewItem *parent ); + IMAPfolderItem( Folder *folder, IMAPviewItem *parent ); ~IMAPfolderItem(); virtual void refresh(QList<RecMail>&); virtual RecBody fetchBody(const RecMail&); - private: - IMAPFolder *folder; + Folder *folder; IMAPviewItem *imap; }; class AccountView : public QListView { Q_OBJECT public: AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); void populate( QList<Account> list ); RecBody fetchBody(const RecMail&aMail); public slots: void refreshAll(); void refresh(QListViewItem *item); signals: void refreshMailview(QList<RecMail>*); }; #endif diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 48e476b..e5eb335 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp @@ -1,277 +1,278 @@ #include <stdlib.h> #include "imapwrapper.h" #include "mailtypes.h" #include <libetpan/mailimap.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) { mailstream_flush(m_imap->imap_stream); return; } server = account->getServer().latin1(); port = account->getPort().toUInt(); 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 ) { qDebug("error connecting server: %s",m_imap->imap_response); mailimap_free( m_imap ); m_imap = 0; return; } /* login */ err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); if ( err != MAILIMAP_NO_ERROR ) { qDebug("error logging in imap: %s",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; int err = MAILIMAP_NO_ERROR; clist *result; clistcell *current; // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; mailimap_fetch_type *fetchType; mailimap_set *set; 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 ) { qDebug("error selecting mailbox: %s",m_imap->imap_response); return; } int last = m_imap->imap_selection_info->sel_exists; if (last == 0) { qDebug("mailbox has no mails"); return; } result = clist_new(); /* 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); target.append(m); } } } else { qDebug("Error fetching headers: %s",m_imap->imap_response); } mailimap_fetch_list_free(result); } -QList<IMAPFolder>* IMAPwrapper::listFolders() +QList<Folder>* IMAPwrapper::listFolders() { const char *path, *mask; int err = MAILIMAP_NO_ERROR; clist *result; clistcell *current; - QList<IMAPFolder> * folders = new QList<IMAPFolder>(); + QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( true ); 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" ; result = clist_new(); mailimap_mailbox_list *list; err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 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; folders->append( new IMAPFolder(temp)); current = current->next; } } 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 = ""; result = clist_new(); qDebug(path); err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 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; current = current->next; if (temp.lower()=="inbox") continue; folders->append(new IMAPFolder(temp)); } } else { qDebug("error fetching folders %s",m_imap->imap_response); } mailimap_list_result_free( result ); return folders; } RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) { RecMail * m = 0; mailimap_msg_att_item *item=0; clistcell *current,*c,*cf; mailimap_msg_att_dynamic*flist; mailimap_flag_fetch*cflag; int size; QBitArray mFlags(7); QStringList addresslist; if (!m_att) { return m; } m = new RecMail(); for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { current = c; size = 0; item = (mailimap_msg_att_item*)current->data; if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; if (!flist->att_list) { continue; } cf = flist->att_list->first; for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { cflag = (mailimap_flag_fetch*)cf->data; if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { switch (cflag->fl_flag->fl_type) { case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ mFlags.setBit(FLAG_ANSWERED); break; case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ mFlags.setBit(FLAG_FLAGGED); break; case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ mFlags.setBit(FLAG_DELETED); break; case MAILIMAP_FLAG_SEEN: /* \Seen flag */ mFlags.setBit(FLAG_SEEN); break; case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ mFlags.setBit(FLAG_DRAFT); break; case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ break; case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ break; default: break; } } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { mFlags.setBit(FLAG_RECENT); } } continue; } if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { mailimap_envelope * head = item->att_data.att_static->att_data.att_env; m->setDate(head->env_date); m->setSubject(head->env_subject); if (head->env_from!=NULL) { addresslist = address_list_to_stringlist(head->env_from->frm_list); if (addresslist.count()) { m->setFrom(addresslist.first()); } } if (head->env_to!=NULL) { diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h index 95de215..f88457a 100644 --- a/noncore/net/mail/imapwrapper.h +++ b/noncore/net/mail/imapwrapper.h @@ -1,55 +1,52 @@ #ifndef __IMAPWRAPPER #define __IMAPWRAPPER #include <qlist.h> #include "mailwrapper.h" +#include "abstractmail.h" struct mailimap; 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 RecMail; -class RecBody; -class RecPart; -class IMAPwrapper : public QObject +class IMAPwrapper : public AbstractMail { Q_OBJECT - public: IMAPwrapper( IMAPaccount *a ); virtual ~IMAPwrapper(); - QList<IMAPFolder>* listFolders(); - void listMessages(const QString & mailbox,QList<RecMail>&target ); - RecBody fetchBody(const RecMail&mail); - QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); - QString fetchPart(const RecMail&mail,const RecPart&part); + virtual QList<Folder>* listFolders(); + virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); + virtual RecBody fetchBody(const RecMail&mail); + virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); + virtual QString fetchPart(const RecMail&mail,const RecPart&part); static void imap_progress( size_t current, size_t maximum ); protected: RecMail*parse_list_result(mailimap_msg_att*); void login(); void logout(); void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 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); /* just helpers */ static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); static QStringList address_list_to_stringlist(clist*list); private: IMAPaccount *account; mailimap *m_imap; }; #endif diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp new file mode 100644 index 0000000..7380c31 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp @@ -0,0 +1,13 @@ +#include "abstractmail.h" +#include "imapwrapper.h" +#include "pop3wrapper.h" + +AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) +{ + return new IMAPwrapper(a); +} + +AbstractMail* AbstractMail::getWrapper(POP3account *a) +{ + return new POP3wrapper(a); +} diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h new file mode 100644 index 0000000..bc8938f --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/abstractmail.h @@ -0,0 +1,30 @@ +#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 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 RecBody fetchBody(const RecMail&mail)=0; + virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false)=0; + virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; + + static AbstractMail* getWrapper(IMAPaccount *a); + static AbstractMail* getWrapper(POP3account *a); +}; + +#endif diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 48e476b..e5eb335 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp @@ -1,277 +1,278 @@ #include <stdlib.h> #include "imapwrapper.h" #include "mailtypes.h" #include <libetpan/mailimap.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) { mailstream_flush(m_imap->imap_stream); return; } server = account->getServer().latin1(); port = account->getPort().toUInt(); 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 ) { qDebug("error connecting server: %s",m_imap->imap_response); mailimap_free( m_imap ); m_imap = 0; return; } /* login */ err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); if ( err != MAILIMAP_NO_ERROR ) { qDebug("error logging in imap: %s",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; int err = MAILIMAP_NO_ERROR; clist *result; clistcell *current; // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; mailimap_fetch_type *fetchType; mailimap_set *set; 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 ) { qDebug("error selecting mailbox: %s",m_imap->imap_response); return; } int last = m_imap->imap_selection_info->sel_exists; if (last == 0) { qDebug("mailbox has no mails"); return; } result = clist_new(); /* 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); target.append(m); } } } else { qDebug("Error fetching headers: %s",m_imap->imap_response); } mailimap_fetch_list_free(result); } -QList<IMAPFolder>* IMAPwrapper::listFolders() +QList<Folder>* IMAPwrapper::listFolders() { const char *path, *mask; int err = MAILIMAP_NO_ERROR; clist *result; clistcell *current; - QList<IMAPFolder> * folders = new QList<IMAPFolder>(); + QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( true ); 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" ; result = clist_new(); mailimap_mailbox_list *list; err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 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; folders->append( new IMAPFolder(temp)); current = current->next; } } 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 = ""; result = clist_new(); qDebug(path); err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 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; current = current->next; if (temp.lower()=="inbox") continue; folders->append(new IMAPFolder(temp)); } } else { qDebug("error fetching folders %s",m_imap->imap_response); } mailimap_list_result_free( result ); return folders; } RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) { RecMail * m = 0; mailimap_msg_att_item *item=0; clistcell *current,*c,*cf; mailimap_msg_att_dynamic*flist; mailimap_flag_fetch*cflag; int size; QBitArray mFlags(7); QStringList addresslist; if (!m_att) { return m; } m = new RecMail(); for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { current = c; size = 0; item = (mailimap_msg_att_item*)current->data; if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; if (!flist->att_list) { continue; } cf = flist->att_list->first; for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { cflag = (mailimap_flag_fetch*)cf->data; if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { switch (cflag->fl_flag->fl_type) { case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ mFlags.setBit(FLAG_ANSWERED); break; case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ mFlags.setBit(FLAG_FLAGGED); break; case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ mFlags.setBit(FLAG_DELETED); break; case MAILIMAP_FLAG_SEEN: /* \Seen flag */ mFlags.setBit(FLAG_SEEN); break; case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ mFlags.setBit(FLAG_DRAFT); break; case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ break; case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ break; default: break; } } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { mFlags.setBit(FLAG_RECENT); } } continue; } if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { mailimap_envelope * head = item->att_data.att_static->att_data.att_env; m->setDate(head->env_date); m->setSubject(head->env_subject); if (head->env_from!=NULL) { addresslist = address_list_to_stringlist(head->env_from->frm_list); if (addresslist.count()) { m->setFrom(addresslist.first()); } } if (head->env_to!=NULL) { diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index 95de215..f88457a 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h @@ -1,55 +1,52 @@ #ifndef __IMAPWRAPPER #define __IMAPWRAPPER #include <qlist.h> #include "mailwrapper.h" +#include "abstractmail.h" struct mailimap; 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 RecMail; -class RecBody; -class RecPart; -class IMAPwrapper : public QObject +class IMAPwrapper : public AbstractMail { Q_OBJECT - public: IMAPwrapper( IMAPaccount *a ); virtual ~IMAPwrapper(); - QList<IMAPFolder>* listFolders(); - void listMessages(const QString & mailbox,QList<RecMail>&target ); - RecBody fetchBody(const RecMail&mail); - QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); - QString fetchPart(const RecMail&mail,const RecPart&part); + virtual QList<Folder>* listFolders(); + virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); + virtual RecBody fetchBody(const RecMail&mail); + virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); + virtual QString fetchPart(const RecMail&mail,const RecPart&part); static void imap_progress( size_t current, size_t maximum ); protected: RecMail*parse_list_result(mailimap_msg_att*); void login(); void logout(); void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 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); /* just helpers */ static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); static QStringList address_list_to_stringlist(clist*list); private: IMAPaccount *account; mailimap *m_imap; }; #endif diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index abb5a42..49c3b7a 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -1,270 +1,289 @@ #include "pop3wrapper.h" #include "mailtypes.h" #include <libetpan/mailpop3.h> POP3wrapper::POP3wrapper( POP3account *a ) { account = a; m_pop3 = NULL; } POP3wrapper::~POP3wrapper() { logout(); } void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { qDebug( "POP3: %i of %i", current, maximum ); } RecBody POP3wrapper::fetchBody( const RecMail &mail ) { int err = MAILPOP3_NO_ERROR; char *message; size_t length; login(); if ( !m_pop3 ) return RecBody(); err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); if ( err != MAILPOP3_NO_ERROR ) { qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); logout(); return RecBody(); } logout(); return parseBody( message ); } RecBody POP3wrapper::parseBody( const char *message ) { int err = MAILIMF_NO_ERROR; size_t curTok; mailimf_message *result; RecBody body; err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); if ( err != MAILIMF_NO_ERROR ) return body; if ( result && result->msg_body && result->msg_body->bd_text ) { qDebug( "POP3: bodytext found" ); // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. body.setBodytext( QString( result->msg_body->bd_text ) ); } return body; } -void POP3wrapper::listMessages( QList<RecMail> &target ) +void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { int err = MAILPOP3_NO_ERROR; char *header; size_t length; carray *messages; login(); if (!m_pop3) return; mailpop3_list( m_pop3, &messages ); for ( int i = carray_count( messages ); i > 0; i-- ) { mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 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 ); logout(); return; } RecMail *mail = parseHeader( header ); mail->setNumber( info->msg_index ); target.append( mail ); } logout(); } RecMail *POP3wrapper::parseHeader( const char *header ) { int err = MAILIMF_NO_ERROR; size_t curTok; RecMail *mail = new RecMail(); mailimf_fields *fields; err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { mailimf_field *field = (mailimf_field *) current->data; switch ( field->fld_type ) { case MAILIMF_FIELD_FROM: mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); break; case MAILIMF_FIELD_TO: mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); break; case MAILIMF_FIELD_CC: mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); break; case MAILIMF_FIELD_BCC: mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); break; case MAILIMF_FIELD_SUBJECT: mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); break; case MAILIMF_FIELD_ORIG_DATE: mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); break; default: break; } } return mail; } QString POP3wrapper::parseDateTime( mailimf_date_time *date ) { char tmp[23]; snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); return QString( tmp ); } QString POP3wrapper::parseAddressList( mailimf_address_list *list ) { QString result( "" ); bool first = true; for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { mailimf_address *addr = (mailimf_address *) current->data; if ( !first ) { result.append( "," ); } else { first = false; } switch ( addr->ad_type ) { case MAILIMF_ADDRESS_MAILBOX: result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); break; case MAILIMF_ADDRESS_GROUP: result.append( parseGroup( addr->ad_data.ad_group ) ); break; default: qDebug( "POP3: unkown mailimf address type" ); break; } } return result; } QString POP3wrapper::parseGroup( mailimf_group *group ) { QString result( "" ); result.append( group->grp_display_name ); result.append( ": " ); if ( group->grp_mb_list != NULL ) { result.append( parseMailboxList( group->grp_mb_list ) ); } result.append( ";" ); return result; } QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) { QString result( "" ); if ( box->mb_display_name == NULL ) { result.append( box->mb_addr_spec ); } else { result.append( box->mb_display_name ); result.append( " <" ); result.append( box->mb_addr_spec ); result.append( ">" ); } return result; } QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) { QString result( "" ); bool first = true; for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { mailimf_mailbox *box = (mailimf_mailbox *) current->data; if ( !first ) { result.append( "," ); } else { first = false; } result.append( parseMailbox( box ) ); } return result; } void POP3wrapper::login() { if ( m_pop3 != NULL ) logout(); const char *server, *user, *pass; uint16_t port; int err = MAILPOP3_NO_ERROR; server = account->getServer().latin1(); port = account->getPort().toUInt(); user = account->getUser().latin1(); pass = account->getPassword().latin1(); m_pop3 = mailpop3_new( 200, &pop3_progress ); // connect if (account->getSSL()) { err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); } else { err = mailpop3_socket_connect( m_pop3, (char*)server, port ); } if ( err != MAILPOP3_NO_ERROR ) { qDebug( "pop3: error connecting to %s\n reason: %s", server, m_pop3->pop3_response ); mailpop3_free( m_pop3 ); m_pop3 = NULL; return; } 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; } qDebug( "POP3: logged in!" ); } void POP3wrapper::logout() { int err = MAILPOP3_NO_ERROR; if ( m_pop3 == NULL ) return; err = mailpop3_quit( m_pop3 ); mailpop3_free( m_pop3 ); m_pop3 = NULL; } + +QList<Folder>* POP3wrapper::listFolders() +{ + QList<Folder> * folders = new QList<Folder>(); + folders->setAutoDelete( true ); + Folder*inb=new Folder("INBOX"); + folders->append(inb); + return folders; +} + +QString POP3wrapper::fetchPart(const RecMail&,const QValueList<int>&,bool) +{ + return ""; +} + +QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) +{ + return ""; +} diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index 995bed0..3b24564 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h @@ -1,38 +1,43 @@ #ifndef __POP3WRAPPER #define __POP3WRAPPER #include "mailwrapper.h" +#include "abstractmail.h" class RecMail; class RecBody; struct mailpop3; -class POP3wrapper : public QObject +class POP3wrapper : public AbstractMail { Q_OBJECT public: POP3wrapper( POP3account *a ); virtual ~POP3wrapper(); - void listMessages( QList<RecMail> &target ); + /* mailbox will be ignored */ + virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); + virtual QList<Folder>* listFolders(); + virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); + virtual QString fetchPart(const RecMail&mail,const RecPart&part); + RecBody fetchBody( const RecMail &mail ); static void pop3_progress( size_t current, size_t maximum ); protected: void login(); void logout(); private: RecMail *parseHeader( const char *header ); RecBody parseBody( const char *message ); 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 ); POP3account *account; mailpop3 *m_pop3; - }; #endif diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro index 0e7cff6..e7519c6 100644 --- a/noncore/net/mail/mail.pro +++ b/noncore/net/mail/mail.pro @@ -1,49 +1,51 @@ CONFIG += qt warn_on debug quick-app HEADERS = defines.h \ logindialog.h \ settings.h \ editaccounts.h \ mailwrapper.h \ composemail.h \ accountview.h \ mainwindow.h \ viewmail.h \ viewmailbase.h \ opiemail.h \ imapwrapper.h \ mailtypes.h \ mailistviewitem.h \ - pop3wrapper.h + pop3wrapper.h \ + abstractmail.h SOURCES = main.cpp \ opiemail.cpp \ mainwindow.cpp \ accountview.cpp \ composemail.cpp \ mailwrapper.cpp \ imapwrapper.cpp \ addresspicker.cpp \ editaccounts.cpp \ logindialog.cpp \ viewmail.cpp \ viewmailbase.cpp \ settings.cpp \ mailtypes.cpp \ - pop3wrapper.cpp + pop3wrapper.cpp \ + abstractmail.cpp INTERFACES = editaccountsui.ui \ selectmailtypeui.ui \ imapconfigui.ui \ pop3configui.ui \ nntpconfigui.ui \ smtpconfigui.ui \ addresspickerui.ui \ logindialogui.ui \ composemailui.ui INCLUDEPATH += $(OPIEDIR)/include LIBS += -lqpe -letpan -lssl -lcrypto -lopie TARGET = opiemail include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/net/mail/mainwindow.h b/noncore/net/mail/mainwindow.h index 74bce5a..6c1cda0 100644 --- a/noncore/net/mail/mainwindow.h +++ b/noncore/net/mail/mainwindow.h @@ -1,43 +1,42 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <qmainwindow.h> #include <qlistview.h> #include <qaction.h> #include <qtoolbar.h> #include <qmenubar.h> #include "accountview.h" class RecMail; class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); - static QString appName() { return QString::fromLatin1("opiemail"); } public slots: void slotAdjustColumns(); protected slots: virtual void slotShowFolders( bool show ); virtual void refreshMailView(QList<RecMail>*); virtual void displayMail(QListViewItem*); void slotAdjustLayout(); protected: QToolBar *toolBar; QMenuBar *menuBar; QPopupMenu *mailMenu, *settingsMenu; QAction *composeMail, *sendQueued, *showFolders, *searchMails, *editSettings, *editAccounts, *syncFolders; AccountView *folderView; QListView *mailView; QBoxLayout *layout; }; #endif diff --git a/noncore/net/mail/opiemail.h b/noncore/net/mail/opiemail.h index dcab47c..7bcd818 100644 --- a/noncore/net/mail/opiemail.h +++ b/noncore/net/mail/opiemail.h @@ -1,28 +1,26 @@ #ifndef OPIEMAIL_H #define OPIEMAIL_H #include "mainwindow.h" #include "settings.h" class OpieMail : public MainWindow { Q_OBJECT public: OpieMail( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); - - static QString appName() { return QString::fromLatin1("opiemail"); } - + static QString appName() { return QString::fromLatin1("opiemail"); } protected slots: void slotComposeMail(); void slotSendQueued(); void slotSearchMails(); void slotEditSettings(); void slotEditAccounts(); private: Settings *settings; }; #endif diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index abb5a42..49c3b7a 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp @@ -1,270 +1,289 @@ #include "pop3wrapper.h" #include "mailtypes.h" #include <libetpan/mailpop3.h> POP3wrapper::POP3wrapper( POP3account *a ) { account = a; m_pop3 = NULL; } POP3wrapper::~POP3wrapper() { logout(); } void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { qDebug( "POP3: %i of %i", current, maximum ); } RecBody POP3wrapper::fetchBody( const RecMail &mail ) { int err = MAILPOP3_NO_ERROR; char *message; size_t length; login(); if ( !m_pop3 ) return RecBody(); err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); if ( err != MAILPOP3_NO_ERROR ) { qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); logout(); return RecBody(); } logout(); return parseBody( message ); } RecBody POP3wrapper::parseBody( const char *message ) { int err = MAILIMF_NO_ERROR; size_t curTok; mailimf_message *result; RecBody body; err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); if ( err != MAILIMF_NO_ERROR ) return body; if ( result && result->msg_body && result->msg_body->bd_text ) { qDebug( "POP3: bodytext found" ); // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. body.setBodytext( QString( result->msg_body->bd_text ) ); } return body; } -void POP3wrapper::listMessages( QList<RecMail> &target ) +void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { int err = MAILPOP3_NO_ERROR; char *header; size_t length; carray *messages; login(); if (!m_pop3) return; mailpop3_list( m_pop3, &messages ); for ( int i = carray_count( messages ); i > 0; i-- ) { mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 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 ); logout(); return; } RecMail *mail = parseHeader( header ); mail->setNumber( info->msg_index ); target.append( mail ); } logout(); } RecMail *POP3wrapper::parseHeader( const char *header ) { int err = MAILIMF_NO_ERROR; size_t curTok; RecMail *mail = new RecMail(); mailimf_fields *fields; err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { mailimf_field *field = (mailimf_field *) current->data; switch ( field->fld_type ) { case MAILIMF_FIELD_FROM: mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); break; case MAILIMF_FIELD_TO: mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); break; case MAILIMF_FIELD_CC: mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); break; case MAILIMF_FIELD_BCC: mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); break; case MAILIMF_FIELD_SUBJECT: mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); break; case MAILIMF_FIELD_ORIG_DATE: mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); break; default: break; } } return mail; } QString POP3wrapper::parseDateTime( mailimf_date_time *date ) { char tmp[23]; snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); return QString( tmp ); } QString POP3wrapper::parseAddressList( mailimf_address_list *list ) { QString result( "" ); bool first = true; for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { mailimf_address *addr = (mailimf_address *) current->data; if ( !first ) { result.append( "," ); } else { first = false; } switch ( addr->ad_type ) { case MAILIMF_ADDRESS_MAILBOX: result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); break; case MAILIMF_ADDRESS_GROUP: result.append( parseGroup( addr->ad_data.ad_group ) ); break; default: qDebug( "POP3: unkown mailimf address type" ); break; } } return result; } QString POP3wrapper::parseGroup( mailimf_group *group ) { QString result( "" ); result.append( group->grp_display_name ); result.append( ": " ); if ( group->grp_mb_list != NULL ) { result.append( parseMailboxList( group->grp_mb_list ) ); } result.append( ";" ); return result; } QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) { QString result( "" ); if ( box->mb_display_name == NULL ) { result.append( box->mb_addr_spec ); } else { result.append( box->mb_display_name ); result.append( " <" ); result.append( box->mb_addr_spec ); result.append( ">" ); } return result; } QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) { QString result( "" ); bool first = true; for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { mailimf_mailbox *box = (mailimf_mailbox *) current->data; if ( !first ) { result.append( "," ); } else { first = false; } result.append( parseMailbox( box ) ); } return result; } void POP3wrapper::login() { if ( m_pop3 != NULL ) logout(); const char *server, *user, *pass; uint16_t port; int err = MAILPOP3_NO_ERROR; server = account->getServer().latin1(); port = account->getPort().toUInt(); user = account->getUser().latin1(); pass = account->getPassword().latin1(); m_pop3 = mailpop3_new( 200, &pop3_progress ); // connect if (account->getSSL()) { err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); } else { err = mailpop3_socket_connect( m_pop3, (char*)server, port ); } if ( err != MAILPOP3_NO_ERROR ) { qDebug( "pop3: error connecting to %s\n reason: %s", server, m_pop3->pop3_response ); mailpop3_free( m_pop3 ); m_pop3 = NULL; return; } 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; } qDebug( "POP3: logged in!" ); } void POP3wrapper::logout() { int err = MAILPOP3_NO_ERROR; if ( m_pop3 == NULL ) return; err = mailpop3_quit( m_pop3 ); mailpop3_free( m_pop3 ); m_pop3 = NULL; } + +QList<Folder>* POP3wrapper::listFolders() +{ + QList<Folder> * folders = new QList<Folder>(); + folders->setAutoDelete( true ); + Folder*inb=new Folder("INBOX"); + folders->append(inb); + return folders; +} + +QString POP3wrapper::fetchPart(const RecMail&,const QValueList<int>&,bool) +{ + return ""; +} + +QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) +{ + return ""; +} diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index 995bed0..3b24564 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h @@ -1,38 +1,43 @@ #ifndef __POP3WRAPPER #define __POP3WRAPPER #include "mailwrapper.h" +#include "abstractmail.h" class RecMail; class RecBody; struct mailpop3; -class POP3wrapper : public QObject +class POP3wrapper : public AbstractMail { Q_OBJECT public: POP3wrapper( POP3account *a ); virtual ~POP3wrapper(); - void listMessages( QList<RecMail> &target ); + /* mailbox will be ignored */ + virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); + virtual QList<Folder>* listFolders(); + virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false); + virtual QString fetchPart(const RecMail&mail,const RecPart&part); + RecBody fetchBody( const RecMail &mail ); static void pop3_progress( size_t current, size_t maximum ); protected: void login(); void logout(); private: RecMail *parseHeader( const char *header ); RecBody parseBody( const char *message ); 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 ); POP3account *account; mailpop3 *m_pop3; - }; #endif |