author | alwin <alwin> | 2003-12-25 14:23:31 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-25 14:23:31 (UTC) |
commit | 25ee009ceeda1a175c4604bf5afe5434e52ee838 (patch) (side-by-side diff) | |
tree | ccc6b8cfbfac74880e9bebc5be595384ccf731e9 | |
parent | e0b1bc403c2792dff3aa04a00eaf58b9defc6dac (diff) | |
download | opie-25ee009ceeda1a175c4604bf5afe5434e52ee838.zip opie-25ee009ceeda1a175c4604bf5afe5434e52ee838.tar.gz opie-25ee009ceeda1a175c4604bf5afe5434e52ee838.tar.bz2 |
- some memleaks
- content generation will use the libetpan code und not own dumping to a
tmpfile.
- bugfix while creating mails with attachments (message itself could
be corrupted)
- textpart will always encoded quoted-printable
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 114 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 3 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.cpp | 114 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.h | 3 |
4 files changed, 52 insertions, 182 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index 285561c..521cd0a 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp @@ -115,4 +115,3 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) for ( it = list.begin(); it != list.end(); it++ ) { - char *str = strdup( (*it).latin1() ); - int err = mailimf_address_list_add_parse( addresses, str ); + int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); if ( err != MAILIMF_NO_ERROR ) { @@ -120,3 +119,2 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) qDebug( *it ); - free( str ); } else { @@ -198,3 +196,2 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) mailmime_parameter *param; - char *txt = strdup( str.latin1() ); int err; @@ -211,3 +208,3 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) - fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); + fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_QUOTED_PRINTABLE); if ( fields == NULL ) goto err_free_content; @@ -217,3 +214,3 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) - err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); + err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; @@ -231,3 +228,2 @@ err_free_param: err_free: - free( txt ); qDebug( "buildTxtPart - error" ); @@ -254,4 +250,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety } - char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain - + int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; @@ -262,3 +257,2 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety strdup( "iso-8859-1" ) ); - disptype = MAILMIME_DISPOSITION_TYPE_INLINE; mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; @@ -269,3 +263,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety mechanism ); - content = mailmime_content_new_with_str( mime ); + content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); if (content!=0 && fields != 0) { @@ -287,3 +281,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety } else { - err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); + err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); } @@ -302,6 +296,2 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety mailmime_content_free( content ); - } else { - if (mime) { - free( mime ); - } } @@ -361,7 +351,4 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) - if (mail.getAttachments().count()==0) { - txtPart = buildTxtPart( mail.getMessage() ); - } else { - txtPart = buildFilePart("","text/plain",mail.getMessage()); - } + txtPart = buildTxtPart( mail.getMessage() ); + if ( txtPart == NULL ) goto err_free_message; @@ -473,3 +460,2 @@ char *SMTPwrapper::getFrom( mailmime *mail ) mailimf_field *ffrom = 0; - char*f = 0; ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); @@ -498,57 +484,2 @@ SMTPaccount *SMTPwrapper::getAccount(const QString&name ) -QString SMTPwrapper::getTmpFile() { - int num = 0; - QString unique; - - QDir dir( "/tmp" ); - - QStringList list = dir.entryList( "opiemail-tmp-*" ); - - do { - unique.setNum( num++ ); - } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); - - return "/tmp/opiemail-tmp-" + unique; -} - -void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) -{ - FILE *f; - int err, col = 0; - - f = fopen( file.latin1(), "w" ); - if ( f == NULL ) { - qDebug( "writeToFile: error opening file" ); - return; - } - - err = mailmime_write( f, &col, mail ); - if ( err != MAILIMF_NO_ERROR ) { - fclose( f ); - qDebug( "writeToFile: error writing mailmime" ); - return; - } - - fclose( f ); -} - -void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) -{ - - QFile msg_cache(file); - QString msg = ""; - msg_cache.open(IO_ReadOnly); - char*message = new char[4096]; - memset(message,0,4096); - while (msg_cache.readBlock(message,4095)>0) { - msg+=message; - memset(message,0,4096); - } - delete message; - *data = (char*)malloc(msg.length()+1*sizeof(char)); - memset(*data,0,msg.length()+1); - memcpy(*data,msg.ascii(),msg.length()); - *size=msg.length(); -} - void SMTPwrapper::progress( size_t current, size_t maximum ) @@ -580,11 +511,19 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) from = data = 0; - - QString file = getTmpFile(); - writeToFile( file, mail ); - readFromFile( file, &data, &size ); - QFile f( file ); - f.remove(); - + + mailmessage * msg = 0; + msg = mime_message_init(mail); + mime_message_set_tmpdir(msg,getenv( "HOME" )); + int r = mailmessage_fetch(msg,&data,&size); + mime_message_detach_mime(msg); + mailmessage_free(msg); + if (r != MAIL_NO_ERROR || !data) { + if (data) free(data); + qDebug("Error fetching mime..."); + return; + } + QString tmp = data; + tmp.replace(QRegExp("\r+",true,false),""); + msg = 0; if (later) { - storeMail(data,size,"Outgoing"); + storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); if (data) free( data ); @@ -690,3 +629,2 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later ) smtpSend( mimeMail,later,smtp); - mailmime_free( mimeMail ); qDebug("Clean up done"); @@ -695,2 +633,3 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later ) sendProgress = 0; + mailmime_free( mimeMail ); } @@ -749,3 +688,3 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) - QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); + QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); MBOXwrapper*wrap = new MBOXwrapper(localfolders); @@ -772,3 +711,2 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) tr("Error sending queued mail - breaking")); - returnValue = false; diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h index 66180b7..f734fa4 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.h +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h @@ -45,4 +45,2 @@ protected: SMTPaccount *getAccount(const QString&from ); - void writeToFile(const QString&file, mailmime *mail ); - void readFromFile(const QString&file, char **data, size_t *size ); @@ -50,3 +48,2 @@ protected: static QString mailsmtpError( int err ); - static QString getTmpFile(); static void progress( size_t current, size_t maximum ); diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp index 285561c..521cd0a 100644 --- a/noncore/net/mail/smtpwrapper.cpp +++ b/noncore/net/mail/smtpwrapper.cpp @@ -115,4 +115,3 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) for ( it = list.begin(); it != list.end(); it++ ) { - char *str = strdup( (*it).latin1() ); - int err = mailimf_address_list_add_parse( addresses, str ); + int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); if ( err != MAILIMF_NO_ERROR ) { @@ -120,3 +119,2 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) qDebug( *it ); - free( str ); } else { @@ -198,3 +196,2 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) mailmime_parameter *param; - char *txt = strdup( str.latin1() ); int err; @@ -211,3 +208,3 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) - fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); + fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_QUOTED_PRINTABLE); if ( fields == NULL ) goto err_free_content; @@ -217,3 +214,3 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) - err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); + err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; @@ -231,3 +228,2 @@ err_free_param: err_free: - free( txt ); qDebug( "buildTxtPart - error" ); @@ -254,4 +250,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety } - char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain - + int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; @@ -262,3 +257,2 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety strdup( "iso-8859-1" ) ); - disptype = MAILMIME_DISPOSITION_TYPE_INLINE; mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; @@ -269,3 +263,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety mechanism ); - content = mailmime_content_new_with_str( mime ); + content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); if (content!=0 && fields != 0) { @@ -287,3 +281,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety } else { - err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); + err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); } @@ -302,6 +296,2 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety mailmime_content_free( content ); - } else { - if (mime) { - free( mime ); - } } @@ -361,7 +351,4 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) - if (mail.getAttachments().count()==0) { - txtPart = buildTxtPart( mail.getMessage() ); - } else { - txtPart = buildFilePart("","text/plain",mail.getMessage()); - } + txtPart = buildTxtPart( mail.getMessage() ); + if ( txtPart == NULL ) goto err_free_message; @@ -473,3 +460,2 @@ char *SMTPwrapper::getFrom( mailmime *mail ) mailimf_field *ffrom = 0; - char*f = 0; ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); @@ -498,57 +484,2 @@ SMTPaccount *SMTPwrapper::getAccount(const QString&name ) -QString SMTPwrapper::getTmpFile() { - int num = 0; - QString unique; - - QDir dir( "/tmp" ); - - QStringList list = dir.entryList( "opiemail-tmp-*" ); - - do { - unique.setNum( num++ ); - } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); - - return "/tmp/opiemail-tmp-" + unique; -} - -void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) -{ - FILE *f; - int err, col = 0; - - f = fopen( file.latin1(), "w" ); - if ( f == NULL ) { - qDebug( "writeToFile: error opening file" ); - return; - } - - err = mailmime_write( f, &col, mail ); - if ( err != MAILIMF_NO_ERROR ) { - fclose( f ); - qDebug( "writeToFile: error writing mailmime" ); - return; - } - - fclose( f ); -} - -void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) -{ - - QFile msg_cache(file); - QString msg = ""; - msg_cache.open(IO_ReadOnly); - char*message = new char[4096]; - memset(message,0,4096); - while (msg_cache.readBlock(message,4095)>0) { - msg+=message; - memset(message,0,4096); - } - delete message; - *data = (char*)malloc(msg.length()+1*sizeof(char)); - memset(*data,0,msg.length()+1); - memcpy(*data,msg.ascii(),msg.length()); - *size=msg.length(); -} - void SMTPwrapper::progress( size_t current, size_t maximum ) @@ -580,11 +511,19 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) from = data = 0; - - QString file = getTmpFile(); - writeToFile( file, mail ); - readFromFile( file, &data, &size ); - QFile f( file ); - f.remove(); - + + mailmessage * msg = 0; + msg = mime_message_init(mail); + mime_message_set_tmpdir(msg,getenv( "HOME" )); + int r = mailmessage_fetch(msg,&data,&size); + mime_message_detach_mime(msg); + mailmessage_free(msg); + if (r != MAIL_NO_ERROR || !data) { + if (data) free(data); + qDebug("Error fetching mime..."); + return; + } + QString tmp = data; + tmp.replace(QRegExp("\r+",true,false),""); + msg = 0; if (later) { - storeMail(data,size,"Outgoing"); + storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); if (data) free( data ); @@ -690,3 +629,2 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later ) smtpSend( mimeMail,later,smtp); - mailmime_free( mimeMail ); qDebug("Clean up done"); @@ -695,2 +633,3 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later ) sendProgress = 0; + mailmime_free( mimeMail ); } @@ -749,3 +688,3 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) - QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); + QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); MBOXwrapper*wrap = new MBOXwrapper(localfolders); @@ -772,3 +711,2 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) tr("Error sending queued mail - breaking")); - returnValue = false; diff --git a/noncore/net/mail/smtpwrapper.h b/noncore/net/mail/smtpwrapper.h index 66180b7..f734fa4 100644 --- a/noncore/net/mail/smtpwrapper.h +++ b/noncore/net/mail/smtpwrapper.h @@ -45,4 +45,2 @@ protected: SMTPaccount *getAccount(const QString&from ); - void writeToFile(const QString&file, mailmime *mail ); - void readFromFile(const QString&file, char **data, size_t *size ); @@ -50,3 +48,2 @@ protected: static QString mailsmtpError( int err ); - static QString getTmpFile(); static void progress( size_t current, size_t maximum ); |