author | alwin <alwin> | 2004-03-10 21:21:32 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-03-10 21:21:32 (UTC) |
commit | a72855867dedd2b4c16f703fa104b5c6175ce484 (patch) (side-by-side diff) | |
tree | ef38ab8d70f15ce8921cf8c587e77b1b460dfe88 /noncore/net/mail | |
parent | dd34b866c0f3e5041696dd97cf356d86a8d6d212 (diff) | |
download | opie-a72855867dedd2b4c16f703fa104b5c6175ce484.zip opie-a72855867dedd2b4c16f703fa104b5c6175ce484.tar.gz opie-a72855867dedd2b4c16f703fa104b5c6175ce484.tar.bz2 |
fixed a problem with corrupted memory
-rw-r--r-- | noncore/net/mail/libmailwrapper/generatemail.cpp | 107 |
1 files changed, 60 insertions, 47 deletions
diff --git a/noncore/net/mail/libmailwrapper/generatemail.cpp b/noncore/net/mail/libmailwrapper/generatemail.cpp index 9272d0c..48fa02e 100644 --- a/noncore/net/mail/libmailwrapper/generatemail.cpp +++ b/noncore/net/mail/libmailwrapper/generatemail.cpp @@ -281,5 +281,6 @@ mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail -mailimf_fields *Generatemail::createImfFields(const Mail&mail ) { - mailimf_fields *fields; - mailimf_field *xmailer; +mailimf_fields *Generatemail::createImfFields(const Mail&mail ) +{ + mailimf_fields *fields = NULL; + mailimf_field *xmailer = NULL; mailimf_mailbox *sender=0,*fromBox=0; @@ -290,28 +291,36 @@ mailimf_fields *Generatemail::createImfFields(const Mail&mail ) { int err; + int res = 1; sender = newMailbox( mail.getName(), mail.getMail() ); - if ( sender == NULL ) - goto err_free; + if ( sender == NULL ) { + res = 0; + } + if (res) { fromBox = newMailbox( mail.getName(), mail.getMail() ); - if ( fromBox == NULL ) - goto err_free_sender; + } + if ( fromBox == NULL ) { + res = 0; + } + if (res) { from = mailimf_mailbox_list_new_empty(); - if ( from == NULL ) - goto err_free_fromBox; + } + if ( from == NULL ) { + res = 0; + } + if (res && from) { err = mailimf_mailbox_list_add( from, fromBox ); - if ( err != MAILIMF_NO_ERROR ) - goto err_free_from; - - to = parseAddresses( mail.getTo() ); - if ( to == NULL ) - goto err_free_from; + if ( err != MAILIMF_NO_ERROR ) { + res = 0; + } + } - cc = parseAddresses( mail.getCC() ); - bcc = parseAddresses( mail.getBCC() ); - reply = parseAddresses( mail.getReply() ); + if (res) to = parseAddresses( mail.getTo() ); + if (res) cc = parseAddresses( mail.getCC() ); + if (res) bcc = parseAddresses( mail.getBCC() ); + if (res) reply = parseAddresses( mail.getReply() ); - if (mail.Inreply().count()>0) { + if (res && mail.Inreply().count()>0) { in_reply_to = clist_new(); @@ -341,25 +350,29 @@ mailimf_fields *Generatemail::createImfFields(const Mail&mail ) { + if (res) { fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, in_reply_to, NULL, subject ); - if ( fields == NULL ) - goto err_free_reply; - - xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), + if ( fields == NULL ) { + qDebug("Error creating mailimf fields"); + res = 0; + } + } + if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), strdup( USER_AGENT ) ); - if ( xmailer == NULL ) - goto err_free_fields; - + if ( xmailer == NULL ) { + res = 0; + } else { err = mailimf_fields_add( fields, xmailer ); - if ( err != MAILIMF_NO_ERROR ) - goto err_free_xmailer; - - return fields; // Success :) - -err_free_xmailer: - if (xmailer) + if ( err != MAILIMF_NO_ERROR ) { + res = 0; + } + } + if (!res ) { + if (xmailer) { mailimf_field_free( xmailer ); -err_free_fields: - if (fields) + xmailer = NULL; + } + if (fields) { mailimf_fields_free( fields ); -err_free_reply: + fields = NULL; + } else { if (reply) @@ -372,16 +385,16 @@ err_free_reply: mailimf_address_list_free( to ); -err_free_from: - if (from) - mailimf_mailbox_list_free( from ); -err_free_fromBox: + if (fromBox) { mailimf_mailbox_free( fromBox ); -err_free_sender: - if (sender) + } else if (from) { + mailimf_mailbox_list_free( from ); + } + if (sender) { mailimf_mailbox_free( sender ); -err_free: - if (subject) + } + if (subject) { free( subject ); - qDebug( "createImfFields - error" ); - - return NULL; // Error :( + } + } + } + return fields; } |