author | jgf <jgf> | 2003-12-11 17:21:41 (UTC) |
---|---|---|
committer | jgf <jgf> | 2003-12-11 17:21:41 (UTC) |
commit | efa09eadddc16220cc1e8a55da93115538b091bb (patch) (side-by-side diff) | |
tree | f8186f84bd107c388507cc6a69ce5f6ce1aaccc9 | |
parent | a54fcb766991ed3d813be5f0b066998082378933 (diff) | |
download | opie-efa09eadddc16220cc1e8a55da93115538b091bb.zip opie-efa09eadddc16220cc1e8a55da93115538b091bb.tar.gz opie-efa09eadddc16220cc1e8a55da93115538b091bb.tar.bz2 |
fetchBody in POP3 & weird segfault
-rw-r--r-- | noncore/net/mail/accountview.cpp | 6 | ||||
-rw-r--r-- | noncore/net/mail/accountview.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 111 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 13 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 111 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 13 |
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 @@ -31,8 +31,8 @@ void POP3viewItem::refresh( QList<RecMail> &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 ); } 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 @@ -30,5 +30,5 @@ public: ~POP3viewItem(); virtual void refresh( QList<RecMail> &target ); - virtual RecBody fetchBody(const RecMail & ); + virtual RecBody fetchBody( const RecMail &mail ); private: 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 @@ -20,4 +20,44 @@ 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 ) { @@ -60,14 +100,14 @@ RecMail *POP3wrapper::parseHeader( const char *header ) 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: @@ -75,5 +115,5 @@ RecMail *POP3wrapper::parseHeader( const char *header ) 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: @@ -85,5 +125,5 @@ RecMail *POP3wrapper::parseHeader( const char *header ) } -QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) +QString POP3wrapper::parseDateTime( mailimf_date_time *date ) { char tmp[23]; @@ -92,12 +132,10 @@ QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) 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; @@ -106,21 +144,15 @@ QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) 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: @@ -133,33 +165,31 @@ 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( ";" ); 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( ">" ); } @@ -167,7 +197,7 @@ 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( "" ); bool first = true; @@ -176,12 +206,10 @@ QString *POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) if ( !first ) { - result->append( "," ); + result.append( "," ); } else { first = false; } - QString *tmp = parseMailbox( box ); - result->append( *tmp ); - delete tmp; + result.append( parseMailbox( box ) ); } @@ -241,3 +269,2 @@ void POP3wrapper::logout() } - 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 @@ -5,4 +5,5 @@ class RecMail; +class RecBody; struct mailpop3; @@ -15,4 +16,5 @@ public: virtual ~POP3wrapper(); void listMessages( QList<RecMail> &target ); + RecBody fetchBody( const RecMail &mail ); static void pop3_progress( size_t current, size_t maximum ); @@ -23,9 +25,10 @@ protected: 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; 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 @@ -20,4 +20,44 @@ 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 ) { @@ -60,14 +100,14 @@ RecMail *POP3wrapper::parseHeader( const char *header ) 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: @@ -75,5 +115,5 @@ RecMail *POP3wrapper::parseHeader( const char *header ) 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: @@ -85,5 +125,5 @@ RecMail *POP3wrapper::parseHeader( const char *header ) } -QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) +QString POP3wrapper::parseDateTime( mailimf_date_time *date ) { char tmp[23]; @@ -92,12 +132,10 @@ QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) 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; @@ -106,21 +144,15 @@ QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) 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: @@ -133,33 +165,31 @@ 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( ";" ); 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( ">" ); } @@ -167,7 +197,7 @@ 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( "" ); bool first = true; @@ -176,12 +206,10 @@ QString *POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) if ( !first ) { - result->append( "," ); + result.append( "," ); } else { first = false; } - QString *tmp = parseMailbox( box ); - result->append( *tmp ); - delete tmp; + result.append( parseMailbox( box ) ); } @@ -241,3 +269,2 @@ void POP3wrapper::logout() } - 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 @@ -5,4 +5,5 @@ class RecMail; +class RecBody; struct mailpop3; @@ -15,4 +16,5 @@ public: virtual ~POP3wrapper(); void listMessages( QList<RecMail> &target ); + RecBody fetchBody( const RecMail &mail ); static void pop3_progress( size_t current, size_t maximum ); @@ -23,9 +25,10 @@ protected: 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; |