Diffstat (limited to 'noncore/net/mail/libmailwrapper/pop3wrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 111 |
1 files changed, 69 insertions, 42 deletions
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 @@ -21,2 +21,42 @@ void POP3wrapper::pop3_progress( size_t current, size_t 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 ) @@ -61,12 +101,12 @@ RecMail *POP3wrapper::parseHeader( const char *header ) 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; @@ -76,3 +116,3 @@ RecMail *POP3wrapper::parseHeader( const char *header ) 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; @@ -86,3 +126,3 @@ RecMail *POP3wrapper::parseHeader( const char *header ) -QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) +QString POP3wrapper::parseDateTime( mailimf_date_time *date ) { @@ -93,10 +133,8 @@ QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) - 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( "" ); @@ -107,3 +145,3 @@ QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) if ( !first ) { - result->append( "," ); + result.append( "," ); } else { @@ -112,14 +150,8 @@ QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) - 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; @@ -134,16 +166,14 @@ QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) -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( ";" ); @@ -152,13 +182,13 @@ QString *POP3wrapper::parseGroup( mailimf_group *group ) -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( ">" ); } @@ -168,5 +198,5 @@ QString *POP3wrapper::parseMailbox( mailimf_mailbox *box ) -QString *POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) +QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) { - QString *result = new QString( "" ); + QString result( "" ); @@ -177,3 +207,3 @@ QString *POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) if ( !first ) { - result->append( "," ); + result.append( "," ); } else { @@ -182,5 +212,3 @@ QString *POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) - QString *tmp = parseMailbox( box ); - result->append( *tmp ); - delete tmp; + result.append( parseMailbox( box ) ); } @@ -242,2 +270 @@ void POP3wrapper::logout() - |