author | alwin <alwin> | 2003-12-15 02:28:22 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-15 02:28:22 (UTC) |
commit | 07590207a8306d0184e3c331a71f41a58ccbc96f (patch) (side-by-side diff) | |
tree | 0735d5bf28615f407c2b17f68a7acda078649312 /noncore | |
parent | 1413ec0f3f1ed40fad087dfa413585f9fdf03400 (diff) | |
download | opie-07590207a8306d0184e3c331a71f41a58ccbc96f.zip opie-07590207a8306d0184e3c331a71f41a58ccbc96f.tar.gz opie-07590207a8306d0184e3c331a71f41a58ccbc96f.tar.bz2 |
pop3wrapper now works in first stage and doesn't segfault anymore
Display an INBOX folder for pop3 accounts to get an more monoton
mail interface for different types of mail server.
Inbox - Folder get another icon than the other.
-rw-r--r-- | noncore/net/mail/accountview.cpp | 60 | ||||
-rw-r--r-- | noncore/net/mail/accountview.h | 16 | ||||
-rw-r--r-- | noncore/net/mail/defines.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 57 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 57 |
5 files changed, 153 insertions, 39 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp index d725b87..8e21d39 100644 --- a/noncore/net/mail/accountview.cpp +++ b/noncore/net/mail/accountview.cpp @@ -22,10 +22,28 @@ POP3viewItem::~POP3viewItem() } -void POP3viewItem::refresh( QList<RecMail> &target ) +AbstractMail *POP3viewItem::getWrapper() { - qDebug( "POP3: refresh" ); - wrapper->listMessages("INBOX", target ); + return wrapper; } +void POP3viewItem::refresh( QList<RecMail> & ) +{ + QList<Folder> *folders = wrapper->listFolders(); + QListViewItem *child = firstChild(); + while ( child ) { + QListViewItem *tmp = child; + child = child->nextSibling(); + delete tmp; + } + Folder *it; + QListViewItem*item = 0; + for ( it = folders->first(); it; it = folders->next() ) { + item = new POP3folderItem( it, this , item ); + item->setSelectable(it->may_select()); + } + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + folders->setAutoDelete(false); + delete folders; +} RecBody POP3viewItem::fetchBody( const RecMail &mail ) @@ -35,8 +53,36 @@ RecBody POP3viewItem::fetchBody( const RecMail &mail ) } +POP3folderItem::~POP3folderItem() +{ + delete folder; +} + +POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after ) + : AccountViewItem( parent,after ) +{ + folder = folderInit; + pop3 = parent; + if (folder->getDisplayName().lower()!="inbox") { + setPixmap( 0, PIXMAP_POP3FOLDER ); + } else { + setPixmap( 0, PIXMAP_INBOXFOLDER); + } + setText( 0, folder->getDisplayName() ); +} + +void POP3folderItem::refresh(QList<RecMail>&target) +{ + if (folder->may_select()) + pop3->getWrapper()->listMessages( folder->getName(),target ); +} + +RecBody POP3folderItem::fetchBody(const RecMail&aMail) +{ + return pop3->getWrapper()->fetchBody(aMail); +} + /** * IMAP Account stuff */ - IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent ) : AccountViewItem( parent ) @@ -96,5 +142,9 @@ IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QList folder = folderInit; imap = parent; - setPixmap( 0, PIXMAP_IMAPFOLDER ); + if (folder->getDisplayName().lower()!="inbox") { + setPixmap( 0, PIXMAP_IMAPFOLDER ); + } else { + setPixmap( 0, PIXMAP_INBOXFOLDER); + } setText( 0, folder->getDisplayName() ); } diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h index 04f9b7a..d035af4 100644 --- a/noncore/net/mail/accountview.h +++ b/noncore/net/mail/accountview.h @@ -32,5 +32,5 @@ public: virtual void refresh( QList<RecMail> &target ); virtual RecBody fetchBody( const RecMail &mail ); - + AbstractMail *getWrapper(); private: POP3account *account; @@ -39,4 +39,17 @@ private: }; +class POP3folderItem : public AccountViewItem +{ + +public: + POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after ); + ~POP3folderItem(); + virtual void refresh(QList<RecMail>&); + virtual RecBody fetchBody(const RecMail&); +private: + Folder *folder; + POP3viewItem *pop3; +}; + class IMAPviewItem : public AccountViewItem { @@ -64,5 +77,4 @@ private: Folder *folder; IMAPviewItem *imap; - }; diff --git a/noncore/net/mail/defines.h b/noncore/net/mail/defines.h index 679459d..c849f1a 100644 --- a/noncore/net/mail/defines.h +++ b/noncore/net/mail/defines.h @@ -15,4 +15,5 @@ #define PIC_IMAPFOLDER "opiemail/imapfolder" #define PIC_POP3FOLDER "opiemail/pop3folder" +#define PIC_INBOXFOLDER "opiemail/inbox" #define ICON_COMPOSEMAIL QIconSet( Resource::loadPixmap( PIC_COMPOSEMAIL ) ) @@ -26,4 +27,5 @@ #define PIXMAP_IMAPFOLDER QPixmap( Resource::loadPixmap( PIC_IMAPFOLDER ) ) #define PIXMAP_POP3FOLDER QPixmap( Resource::loadPixmap( PIC_POP3FOLDER ) ) +#define PIXMAP_INBOXFOLDER QPixmap( Resource::loadPixmap( PIC_INBOXFOLDER) ) #define IMAP_PORT "143" diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 46c854b..2411399 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -1,3 +1,3 @@ - +#include <stdlib.h> #include "pop3wrapper.h" #include "mailtypes.h" @@ -44,17 +44,21 @@ RecBody POP3wrapper::parseBody( const char *message ) { int err = MAILIMF_NO_ERROR; - size_t curTok; - mailimf_message *result; + /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ + size_t curTok = 0; + mailimf_message *result = 0; RecBody body; err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); - if ( err != MAILIMF_NO_ERROR ) return body; + if ( err != MAILIMF_NO_ERROR ) { + if (result) mailimf_message_free(result); + 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. + // when curTok isn't set to 0 this line will fault! 'cause upper line faults! body.setBodytext( QString( result->msg_body->bd_text ) ); } - + if (result) mailimf_message_free(result); return body; } @@ -63,7 +67,8 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { int err = MAILPOP3_NO_ERROR; - char *header; - size_t length; - carray *messages; + char * header = 0; + /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ + size_t length = 0; + carray * messages = 0; login(); @@ -71,10 +76,12 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 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 ); - + //for ( int i = carray_count( messages ); i > 0; i-- ) { + for (unsigned int i = 0; i < carray_count(messages);++i) { + mailpop3_msg_info *info; + int r = mailpop3_get_msg_info(m_pop3,i+1,&info); err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); if ( err != MAILPOP3_NO_ERROR ) { qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); + free(header); logout(); return; @@ -84,6 +91,6 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) mail->setWrapper(this); target.append( mail ); + free(header); } - logout(); } @@ -92,8 +99,10 @@ RecMail *POP3wrapper::parseHeader( const char *header ) { int err = MAILIMF_NO_ERROR; - size_t curTok; + size_t curTok = 0; RecMail *mail = new RecMail(); mailimf_fields *fields; - + mailimf_references * refs; + mailimf_keywords*keys; + err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { @@ -118,9 +127,25 @@ RecMail *POP3wrapper::parseHeader( const char *header ) mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); break; + case MAILIMF_FIELD_MESSAGE_ID: + mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); + break; + case MAILIMF_FIELD_REFERENCES: + refs = field->fld_data.fld_references; + if (refs && refs->mid_list && clist_count(refs->mid_list)) { + char * text = (char*)refs->mid_list->first->data; + mail->setReplyto(QString(text)); + } + break; + case MAILIMF_FIELD_KEYWORDS: + keys = field->fld_data.fld_keywords; + for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { + qDebug("Keyword: %s",(char*)cur->data); + } + break; default: break; } } - + if (fields) mailimf_fields_free(fields); return mail; } diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index 46c854b..2411399 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp @@ -1,3 +1,3 @@ - +#include <stdlib.h> #include "pop3wrapper.h" #include "mailtypes.h" @@ -44,17 +44,21 @@ RecBody POP3wrapper::parseBody( const char *message ) { int err = MAILIMF_NO_ERROR; - size_t curTok; - mailimf_message *result; + /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ + size_t curTok = 0; + mailimf_message *result = 0; RecBody body; err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); - if ( err != MAILIMF_NO_ERROR ) return body; + if ( err != MAILIMF_NO_ERROR ) { + if (result) mailimf_message_free(result); + 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. + // when curTok isn't set to 0 this line will fault! 'cause upper line faults! body.setBodytext( QString( result->msg_body->bd_text ) ); } - + if (result) mailimf_message_free(result); return body; } @@ -63,7 +67,8 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { int err = MAILPOP3_NO_ERROR; - char *header; - size_t length; - carray *messages; + char * header = 0; + /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ + size_t length = 0; + carray * messages = 0; login(); @@ -71,10 +76,12 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 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 ); - + //for ( int i = carray_count( messages ); i > 0; i-- ) { + for (unsigned int i = 0; i < carray_count(messages);++i) { + mailpop3_msg_info *info; + int r = mailpop3_get_msg_info(m_pop3,i+1,&info); err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); if ( err != MAILPOP3_NO_ERROR ) { qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); + free(header); logout(); return; @@ -84,6 +91,6 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) mail->setWrapper(this); target.append( mail ); + free(header); } - logout(); } @@ -92,8 +99,10 @@ RecMail *POP3wrapper::parseHeader( const char *header ) { int err = MAILIMF_NO_ERROR; - size_t curTok; + size_t curTok = 0; RecMail *mail = new RecMail(); mailimf_fields *fields; - + mailimf_references * refs; + mailimf_keywords*keys; + err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { @@ -118,9 +127,25 @@ RecMail *POP3wrapper::parseHeader( const char *header ) mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); break; + case MAILIMF_FIELD_MESSAGE_ID: + mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); + break; + case MAILIMF_FIELD_REFERENCES: + refs = field->fld_data.fld_references; + if (refs && refs->mid_list && clist_count(refs->mid_list)) { + char * text = (char*)refs->mid_list->first->data; + mail->setReplyto(QString(text)); + } + break; + case MAILIMF_FIELD_KEYWORDS: + keys = field->fld_data.fld_keywords; + for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { + qDebug("Keyword: %s",(char*)cur->data); + } + break; default: break; } } - + if (fields) mailimf_fields_free(fields); return mail; } |