summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp6
-rw-r--r--noncore/net/mail/accountview.h2
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp111
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h13
-rw-r--r--noncore/net/mail/pop3wrapper.cpp111
-rw-r--r--noncore/net/mail/pop3wrapper.h13
6 files changed, 158 insertions, 98 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 6963027..c7b1eeb 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -17,36 +17,36 @@ POP3viewItem::POP3viewItem( POP3account *a, QListView *parent )
setPixmap( 0, PIXMAP_POP3FOLDER );
setText( 0, account->getAccountName() );
}
POP3viewItem::~POP3viewItem()
{
delete wrapper;
}
void POP3viewItem::refresh( QList<RecMail> &target )
{
qDebug( "POP3: refresh" );
wrapper->listMessages( target );
}
-RecBody POP3viewItem::fetchBody( const RecMail & )
+RecBody POP3viewItem::fetchBody( const RecMail &mail )
{
- qDebug( "POP3 fetchBody: IMPLEMENT ME!!" );
- return RecBody();
+ qDebug( "POP3 fetchBody" );
+ return wrapper->fetchBody( mail );
}
/**
* IMAP Account stuff
*/
IMAPviewItem::IMAPviewItem( IMAPaccount *a, QListView *parent )
: AccountViewItem( parent )
{
account = a;
wrapper = new IMAPwrapper( account );
setPixmap( 0, PIXMAP_IMAPFOLDER );
setText( 0, account->getAccountName() );
setOpen( true );
}
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index fe832ec..4cac673 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -16,33 +16,33 @@ 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 & );
+ virtual RecBody fetchBody( const RecMail &mail );
private:
POP3account *account;
POP3wrapper *wrapper;
};
class IMAPviewItem : public AccountViewItem
{
public:
IMAPviewItem( IMAPaccount *a, QListView *parent );
~IMAPviewItem();
virtual void refresh(QList<RecMail>&);
virtual RecBody fetchBody(const RecMail&);
IMAPwrapper *getWrapper();
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 633faf6..abb5a42 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -6,32 +6,72 @@
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 )
{
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 ) {
@@ -46,156 +86,144 @@ void POP3wrapper::listMessages( QList<RecMail> &target )
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 ) );
+ 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 ) );
+ 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 ) );
+ 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 ) );
+ 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 ) );
+ mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
break;
default:
break;
}
}
return mail;
}
-QString *POP3wrapper::parseDateTime( mailimf_date_time *date )
+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 );
- QString *result = new QString( tmp );
-
- return result;
+ return QString( tmp );
}
-QString *POP3wrapper::parseAddressList( mailimf_address_list *list )
+QString POP3wrapper::parseAddressList( mailimf_address_list *list )
{
- QString *result = new QString( "" );
+ 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( "," );
+ result.append( "," );
} else {
first = false;
}
- QString *tmp;
-
switch ( addr->ad_type ) {
case MAILIMF_ADDRESS_MAILBOX:
- tmp = parseMailbox( addr->ad_data.ad_mailbox );
- result->append( *tmp );
- delete tmp;
+ result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
break;
case MAILIMF_ADDRESS_GROUP:
- tmp = parseGroup( addr->ad_data.ad_group );
- result->append( *tmp );
- delete tmp;
+ 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 POP3wrapper::parseGroup( mailimf_group *group )
{
- QString *result = new QString( "" );
+ QString result( "" );
- result->append( group->grp_display_name );
- result->append( ": " );
+ result.append( group->grp_display_name );
+ result.append( ": " );
if ( group->grp_mb_list != NULL ) {
- QString *tmp = parseMailboxList( group->grp_mb_list );
- result->append( *tmp );
- delete tmp;
+ result.append( parseMailboxList( group->grp_mb_list ) );
}
- result->append( ";" );
+ result.append( ";" );
return result;
}
-QString *POP3wrapper::parseMailbox( mailimf_mailbox *box )
+QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
{
- QString *result = new QString( "" );
+ QString result( "" );
if ( box->mb_display_name == NULL ) {
- result->append( box->mb_addr_spec );
+ result.append( box->mb_addr_spec );
} else {
- result->append( box->mb_display_name );
- result->append( " <" );
- result->append( box->mb_addr_spec );
- result->append( ">" );
+ 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 POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
{
- QString *result = new QString( "" );
+ 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( "," );
+ result.append( "," );
} else {
first = false;
}
- QString *tmp = parseMailbox( box );
- result->append( *tmp );
- delete tmp;
+ 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();
@@ -227,17 +255,16 @@ void POP3wrapper::login()
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;
}
-
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 4e4abad..995bed0 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,35 +1,38 @@
#ifndef __POP3WRAPPER
#define __POP3WRAPPER
#include "mailwrapper.h"
class RecMail;
+class RecBody;
struct mailpop3;
class POP3wrapper : public QObject
{
Q_OBJECT
public:
POP3wrapper( POP3account *a );
virtual ~POP3wrapper();
void listMessages( QList<RecMail> &target );
+ 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 );
- 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 );
+ 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/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 633faf6..abb5a42 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -6,32 +6,72 @@
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 )
{
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 ) {
@@ -46,156 +86,144 @@ void POP3wrapper::listMessages( QList<RecMail> &target )
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 ) );
+ 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 ) );
+ 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 ) );
+ 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 ) );
+ 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 ) );
+ mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
break;
default:
break;
}
}
return mail;
}
-QString *POP3wrapper::parseDateTime( mailimf_date_time *date )
+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 );
- QString *result = new QString( tmp );
-
- return result;
+ return QString( tmp );
}
-QString *POP3wrapper::parseAddressList( mailimf_address_list *list )
+QString POP3wrapper::parseAddressList( mailimf_address_list *list )
{
- QString *result = new QString( "" );
+ 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( "," );
+ result.append( "," );
} else {
first = false;
}
- QString *tmp;
-
switch ( addr->ad_type ) {
case MAILIMF_ADDRESS_MAILBOX:
- tmp = parseMailbox( addr->ad_data.ad_mailbox );
- result->append( *tmp );
- delete tmp;
+ result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
break;
case MAILIMF_ADDRESS_GROUP:
- tmp = parseGroup( addr->ad_data.ad_group );
- result->append( *tmp );
- delete tmp;
+ 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 POP3wrapper::parseGroup( mailimf_group *group )
{
- QString *result = new QString( "" );
+ QString result( "" );
- result->append( group->grp_display_name );
- result->append( ": " );
+ result.append( group->grp_display_name );
+ result.append( ": " );
if ( group->grp_mb_list != NULL ) {
- QString *tmp = parseMailboxList( group->grp_mb_list );
- result->append( *tmp );
- delete tmp;
+ result.append( parseMailboxList( group->grp_mb_list ) );
}
- result->append( ";" );
+ result.append( ";" );
return result;
}
-QString *POP3wrapper::parseMailbox( mailimf_mailbox *box )
+QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
{
- QString *result = new QString( "" );
+ QString result( "" );
if ( box->mb_display_name == NULL ) {
- result->append( box->mb_addr_spec );
+ result.append( box->mb_addr_spec );
} else {
- result->append( box->mb_display_name );
- result->append( " <" );
- result->append( box->mb_addr_spec );
- result->append( ">" );
+ 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 POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
{
- QString *result = new QString( "" );
+ 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( "," );
+ result.append( "," );
} else {
first = false;
}
- QString *tmp = parseMailbox( box );
- result->append( *tmp );
- delete tmp;
+ 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();
@@ -227,17 +255,16 @@ void POP3wrapper::login()
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;
}
-
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
index 4e4abad..995bed0 100644
--- a/noncore/net/mail/pop3wrapper.h
+++ b/noncore/net/mail/pop3wrapper.h
@@ -1,35 +1,38 @@
#ifndef __POP3WRAPPER
#define __POP3WRAPPER
#include "mailwrapper.h"
class RecMail;
+class RecBody;
struct mailpop3;
class POP3wrapper : public QObject
{
Q_OBJECT
public:
POP3wrapper( POP3account *a );
virtual ~POP3wrapper();
void listMessages( QList<RecMail> &target );
+ 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 );
- 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 );
+ 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