-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,122 +1,120 @@ #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(); 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,40 +1,41 @@ #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(); @@ -110,72 +111,72 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 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 ); /* 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,40 +1,41 @@ #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(); @@ -110,72 +111,72 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 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 ); /* 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 @@ -30,65 +30,65 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) 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(); @@ -239,32 +239,51 @@ void POP3wrapper::login() } 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 @@ -30,65 +30,65 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) 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(); @@ -239,32 +239,51 @@ void POP3wrapper::login() } 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 |