summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp60
-rw-r--r--noncore/net/mail/accountview.h16
-rw-r--r--noncore/net/mail/defines.h2
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp57
-rw-r--r--noncore/net/mail/pop3wrapper.cpp57
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
@@ -1,177 +1,227 @@
#include "accountview.h"
#include "mailtypes.h"
#include "defines.h"
/**
* POP3 Account stuff
*/
POP3viewItem::POP3viewItem( POP3account *a, QListView *parent )
: AccountViewItem( parent )
{
account = a;
wrapper = AbstractMail::getWrapper( account );
setPixmap( 0, PIXMAP_POP3FOLDER );
setText( 0, account->getAccountName() );
}
POP3viewItem::~POP3viewItem()
{
delete wrapper;
}
-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 )
{
qDebug( "POP3 fetchBody" );
return wrapper->fetchBody( 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 )
{
account = a;
wrapper = AbstractMail::getWrapper( account );
setPixmap( 0, PIXMAP_IMAPFOLDER );
setText( 0, account->getAccountName() );
setOpen( true );
}
IMAPviewItem::~IMAPviewItem()
{
delete wrapper;
}
AbstractMail *IMAPviewItem::getWrapper()
{
return wrapper;
}
void IMAPviewItem::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 IMAPfolderItem( it, this , item );
item->setSelectable(it->may_select());
}
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
folders->setAutoDelete(false);
delete folders;
}
RecBody IMAPviewItem::fetchBody(const RecMail&)
{
return RecBody();
}
IMAPfolderItem::~IMAPfolderItem()
{
delete folder;
}
IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after )
: AccountViewItem( parent,after )
{
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() );
}
void IMAPfolderItem::refresh(QList<RecMail>&target)
{
if (folder->may_select())
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( selectionChanged( QListViewItem * ) ),
SLOT( refresh( QListViewItem * ) ) );
setSorting(-1);
}
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 ) {
m_currentItem = item;
QList<RecMail> headerlist;
headerlist.setAutoDelete(true);
AccountViewItem *view = static_cast<AccountViewItem *>(item);
view->refresh(headerlist);
emit refreshMailview(&headerlist);
}
}
void AccountView::refreshCurrent()
{
if ( !m_currentItem ) return;
QList<RecMail> headerlist;
headerlist.setAutoDelete(true);
AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
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 04f9b7a..d035af4 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -1,90 +1,102 @@
#ifndef ACCOUNTVIEW_H
#define ACCOUNTVIEW_H
#include <qlistview.h>
#include <qlist.h>
#include "settings.h"
#include "mailwrapper.h"
#include "abstractmail.h"
class POP3wrapper;
class RecMail;
class RecBody;
class AccountViewItem : public QListViewItem
{
public:
AccountViewItem( QListView *parent ) : QListViewItem( parent ) {}
AccountViewItem( QListViewItem *parent) : QListViewItem( parent) {}
AccountViewItem( QListViewItem *parent , QListViewItem*after ) : QListViewItem( parent,after ) {}
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 );
-
+ AbstractMail *getWrapper();
private:
POP3account *account;
AbstractMail *wrapper;
};
+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
{
public:
IMAPviewItem( IMAPaccount *a, QListView *parent );
~IMAPviewItem();
virtual void refresh(QList<RecMail>&);
virtual RecBody fetchBody(const RecMail&);
AbstractMail *getWrapper();
private:
IMAPaccount *account;
AbstractMail *wrapper;
};
class IMAPfolderItem : public AccountViewItem
{
public:
IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after );
~IMAPfolderItem();
virtual void refresh(QList<RecMail>&);
virtual RecBody fetchBody(const RecMail&);
private:
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);
void refreshCurrent();
signals:
void refreshMailview(QList<RecMail>*);
private:
QListViewItem* m_currentItem;
};
#endif
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
@@ -1,38 +1,40 @@
#ifndef DEFINE_CONSTANTS_H
#define DEFINE_CONSTANTS_H
#include <qpe/resource.h>
#define USER_AGENT "OpieMail v0.0.1-alpha"
#define PIC_COMPOSEMAIL "opiemail/composemail"
#define PIC_SENDQUEUED "opiemail/sendqueued"
#define PIC_SHOWFOLDERS "opiemail/showfolders"
#define PIC_SEARCHMAILS "opiemail/searchmails"
#define PIC_EDITSETTINGS "opiemail/editsettings"
#define PIC_EDITACCOUNTS "opiemail/editaccounts"
#define PIC_SYNC "opiemail/sync"
#define PIC_IMAPFOLDER "opiemail/imapfolder"
#define PIC_POP3FOLDER "opiemail/pop3folder"
+#define PIC_INBOXFOLDER "opiemail/inbox"
#define ICON_COMPOSEMAIL QIconSet( Resource::loadPixmap( PIC_COMPOSEMAIL ) )
#define ICON_SENDQUEUED QIconSet( Resource::loadPixmap( PIC_SENDQUEUED ) )
#define ICON_SHOWFOLDERS QIconSet( Resource::loadPixmap( PIC_SHOWFOLDERS ) )
#define ICON_SEARCHMAILS QIconSet( Resource::loadPixmap( PIC_SEARCHMAILS ) )
#define ICON_EDITSETTINGS QIconSet( Resource::loadPixmap( PIC_EDITSETTINGS ) )
#define ICON_EDITACCOUNTS QIconSet( Resource::loadPixmap( PIC_EDITACCOUNTS ) )
#define ICON_SYNC QIconSet( Resource::loadPixmap( PIC_SYNC ) )
#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"
#define IMAP_SSL_PORT "993"
#define SMTP_PORT "25"
#define SMTP_SSL_PORT "465"
#define POP3_PORT "110"
#define POP3_SSL_PORT "995"
#define NNTP_PORT "119"
#define NNTP_SSL_PORT "563"
#endif
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,293 +1,318 @@
-
+#include <stdlib.h>
#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;
+ /* 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;
}
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();
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 );
-
+ //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;
}
RecMail *mail = parseHeader( header );
mail->setNumber( info->msg_index );
mail->setWrapper(this);
target.append( mail );
+ free(header);
}
-
logout();
}
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 ) {
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;
+ 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;
}
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( false );
Folder*inb=new Folder("INBOX");
folders->append(inb);
return folders;
}
QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
{
return "";
}
void POP3wrapper::deleteMail(const RecMail&)
{
}
void POP3wrapper::answeredMail(const RecMail&)
{
}
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,293 +1,318 @@
-
+#include <stdlib.h>
#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;
+ /* 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;
}
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();
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 );
-
+ //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;
}
RecMail *mail = parseHeader( header );
mail->setNumber( info->msg_index );
mail->setWrapper(this);
target.append( mail );
+ free(header);
}
-
logout();
}
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 ) {
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;
+ 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;
}
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( false );
Folder*inb=new Folder("INBOX");
folders->append(inb);
return folders;
}
QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
{
return "";
}
void POP3wrapper::deleteMail(const RecMail&)
{
}
void POP3wrapper::answeredMail(const RecMail&)
{
}