summaryrefslogtreecommitdiff
path: root/noncore
authoralwin <alwin>2003-12-25 14:23:31 (UTC)
committer alwin <alwin>2003-12-25 14:23:31 (UTC)
commit25ee009ceeda1a175c4604bf5afe5434e52ee838 (patch) (unidiff)
treeccc6b8cfbfac74880e9bebc5be595384ccf731e9 /noncore
parente0b1bc403c2792dff3aa04a00eaf58b9defc6dac (diff)
downloadopie-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
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp114
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h3
-rw-r--r--noncore/net/mail/smtpwrapper.cpp114
-rw-r--r--noncore/net/mail/smtpwrapper.h3
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 )
115 for ( it = list.begin(); it != list.end(); it++ ) { 115 for ( it = list.begin(); it != list.end(); it++ ) {
116 char *str = strdup( (*it).latin1() ); 116 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
117 int err = mailimf_address_list_add_parse( addresses, str );
118 if ( err != MAILIMF_NO_ERROR ) { 117 if ( err != MAILIMF_NO_ERROR ) {
@@ -120,3 +119,2 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr )
120 qDebug( *it ); 119 qDebug( *it );
121 free( str );
122 } else { 120 } else {
@@ -198,3 +196,2 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str )
198 mailmime_parameter *param; 196 mailmime_parameter *param;
199 char *txt = strdup( str.latin1() );
200 int err; 197 int err;
@@ -211,3 +208,3 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str )
211 208
212 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); 209 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_QUOTED_PRINTABLE);
213 if ( fields == NULL ) goto err_free_content; 210 if ( fields == NULL ) goto err_free_content;
@@ -217,3 +214,3 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str )
217 214
218 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); 215 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
219 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 216 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
@@ -231,3 +228,2 @@ err_free_param:
231err_free: 228err_free:
232 free( txt );
233 qDebug( "buildTxtPart - error" ); 229 qDebug( "buildTxtPart - error" );
@@ -254,4 +250,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
254 } 250 }
255 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain 251
256
257 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 252 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
@@ -262,3 +257,2 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
262 strdup( "iso-8859-1" ) ); 257 strdup( "iso-8859-1" ) );
263 disptype = MAILMIME_DISPOSITION_TYPE_INLINE;
264 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 258 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
@@ -269,3 +263,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
269 mechanism ); 263 mechanism );
270 content = mailmime_content_new_with_str( mime ); 264 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
271 if (content!=0 && fields != 0) { 265 if (content!=0 && fields != 0) {
@@ -287,3 +281,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
287 } else { 281 } else {
288 err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); 282 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
289 } 283 }
@@ -302,6 +296,2 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
302 mailmime_content_free( content ); 296 mailmime_content_free( content );
303 } else {
304 if (mime) {
305 free( mime );
306 }
307 } 297 }
@@ -361,7 +351,4 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
361 351
362 if (mail.getAttachments().count()==0) { 352 txtPart = buildTxtPart( mail.getMessage() );
363 txtPart = buildTxtPart( mail.getMessage() ); 353
364 } else {
365 txtPart = buildFilePart("","text/plain",mail.getMessage());
366 }
367 if ( txtPart == NULL ) goto err_free_message; 354 if ( txtPart == NULL ) goto err_free_message;
@@ -473,3 +460,2 @@ char *SMTPwrapper::getFrom( mailmime *mail )
473 mailimf_field *ffrom = 0; 460 mailimf_field *ffrom = 0;
474 char*f = 0;
475 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 461 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
@@ -498,57 +484,2 @@ SMTPaccount *SMTPwrapper::getAccount(const QString&name )
498 484
499QString SMTPwrapper::getTmpFile() {
500 int num = 0;
501 QString unique;
502
503 QDir dir( "/tmp" );
504
505 QStringList list = dir.entryList( "opiemail-tmp-*" );
506
507 do {
508 unique.setNum( num++ );
509 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
510
511 return "/tmp/opiemail-tmp-" + unique;
512}
513
514void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
515{
516 FILE *f;
517 int err, col = 0;
518
519 f = fopen( file.latin1(), "w" );
520 if ( f == NULL ) {
521 qDebug( "writeToFile: error opening file" );
522 return;
523 }
524
525 err = mailmime_write( f, &col, mail );
526 if ( err != MAILIMF_NO_ERROR ) {
527 fclose( f );
528 qDebug( "writeToFile: error writing mailmime" );
529 return;
530 }
531
532 fclose( f );
533}
534
535void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
536{
537
538 QFile msg_cache(file);
539 QString msg = "";
540 msg_cache.open(IO_ReadOnly);
541 char*message = new char[4096];
542 memset(message,0,4096);
543 while (msg_cache.readBlock(message,4095)>0) {
544 msg+=message;
545 memset(message,0,4096);
546 }
547 delete message;
548 *data = (char*)malloc(msg.length()+1*sizeof(char));
549 memset(*data,0,msg.length()+1);
550 memcpy(*data,msg.ascii(),msg.length());
551 *size=msg.length();
552}
553
554void SMTPwrapper::progress( size_t current, size_t maximum ) 485void SMTPwrapper::progress( size_t current, size_t maximum )
@@ -580,11 +511,19 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
580 from = data = 0; 511 from = data = 0;
581 512
582 QString file = getTmpFile(); 513 mailmessage * msg = 0;
583 writeToFile( file, mail ); 514 msg = mime_message_init(mail);
584 readFromFile( file, &data, &size ); 515 mime_message_set_tmpdir(msg,getenv( "HOME" ));
585 QFile f( file ); 516 int r = mailmessage_fetch(msg,&data,&size);
586 f.remove(); 517 mime_message_detach_mime(msg);
587 518 mailmessage_free(msg);
519 if (r != MAIL_NO_ERROR || !data) {
520 if (data) free(data);
521 qDebug("Error fetching mime...");
522 return;
523 }
524 QString tmp = data;
525 tmp.replace(QRegExp("\r+",true,false),"");
526 msg = 0;
588 if (later) { 527 if (later) {
589 storeMail(data,size,"Outgoing"); 528 storeMail((char*)tmp.data(),tmp.length(),"Outgoing");
590 if (data) free( data ); 529 if (data) free( data );
@@ -690,3 +629,2 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later )
690 smtpSend( mimeMail,later,smtp); 629 smtpSend( mimeMail,later,smtp);
691 mailmime_free( mimeMail );
692 qDebug("Clean up done"); 630 qDebug("Clean up done");
@@ -695,2 +633,3 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later )
695 sendProgress = 0; 633 sendProgress = 0;
634 mailmime_free( mimeMail );
696 } 635 }
@@ -749,3 +688,3 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
749 688
750 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 689 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
751 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 690 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
@@ -772,3 +711,2 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
772 tr("Error sending queued mail - breaking")); 711 tr("Error sending queued mail - breaking"));
773
774 returnValue = false; 712 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:
45 SMTPaccount *getAccount(const QString&from ); 45 SMTPaccount *getAccount(const QString&from );
46 void writeToFile(const QString&file, mailmime *mail );
47 void readFromFile(const QString&file, char **data, size_t *size );
48 46
@@ -50,3 +48,2 @@ protected:
50 static QString mailsmtpError( int err ); 48 static QString mailsmtpError( int err );
51 static QString getTmpFile();
52 static void progress( size_t current, size_t maximum ); 49 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 )
115 for ( it = list.begin(); it != list.end(); it++ ) { 115 for ( it = list.begin(); it != list.end(); it++ ) {
116 char *str = strdup( (*it).latin1() ); 116 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
117 int err = mailimf_address_list_add_parse( addresses, str );
118 if ( err != MAILIMF_NO_ERROR ) { 117 if ( err != MAILIMF_NO_ERROR ) {
@@ -120,3 +119,2 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr )
120 qDebug( *it ); 119 qDebug( *it );
121 free( str );
122 } else { 120 } else {
@@ -198,3 +196,2 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str )
198 mailmime_parameter *param; 196 mailmime_parameter *param;
199 char *txt = strdup( str.latin1() );
200 int err; 197 int err;
@@ -211,3 +208,3 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str )
211 208
212 fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); 209 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_QUOTED_PRINTABLE);
213 if ( fields == NULL ) goto err_free_content; 210 if ( fields == NULL ) goto err_free_content;
@@ -217,3 +214,3 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str )
217 214
218 err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); 215 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
219 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 216 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
@@ -231,3 +228,2 @@ err_free_param:
231err_free: 228err_free:
232 free( txt );
233 qDebug( "buildTxtPart - error" ); 229 qDebug( "buildTxtPart - error" );
@@ -254,4 +250,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
254 } 250 }
255 char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain 251
256
257 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 252 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
@@ -262,3 +257,2 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
262 strdup( "iso-8859-1" ) ); 257 strdup( "iso-8859-1" ) );
263 disptype = MAILMIME_DISPOSITION_TYPE_INLINE;
264 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 258 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
@@ -269,3 +263,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
269 mechanism ); 263 mechanism );
270 content = mailmime_content_new_with_str( mime ); 264 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
271 if (content!=0 && fields != 0) { 265 if (content!=0 && fields != 0) {
@@ -287,3 +281,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
287 } else { 281 } else {
288 err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); 282 err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
289 } 283 }
@@ -302,6 +296,2 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
302 mailmime_content_free( content ); 296 mailmime_content_free( content );
303 } else {
304 if (mime) {
305 free( mime );
306 }
307 } 297 }
@@ -361,7 +351,4 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
361 351
362 if (mail.getAttachments().count()==0) { 352 txtPart = buildTxtPart( mail.getMessage() );
363 txtPart = buildTxtPart( mail.getMessage() ); 353
364 } else {
365 txtPart = buildFilePart("","text/plain",mail.getMessage());
366 }
367 if ( txtPart == NULL ) goto err_free_message; 354 if ( txtPart == NULL ) goto err_free_message;
@@ -473,3 +460,2 @@ char *SMTPwrapper::getFrom( mailmime *mail )
473 mailimf_field *ffrom = 0; 460 mailimf_field *ffrom = 0;
474 char*f = 0;
475 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 461 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
@@ -498,57 +484,2 @@ SMTPaccount *SMTPwrapper::getAccount(const QString&name )
498 484
499QString SMTPwrapper::getTmpFile() {
500 int num = 0;
501 QString unique;
502
503 QDir dir( "/tmp" );
504
505 QStringList list = dir.entryList( "opiemail-tmp-*" );
506
507 do {
508 unique.setNum( num++ );
509 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
510
511 return "/tmp/opiemail-tmp-" + unique;
512}
513
514void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
515{
516 FILE *f;
517 int err, col = 0;
518
519 f = fopen( file.latin1(), "w" );
520 if ( f == NULL ) {
521 qDebug( "writeToFile: error opening file" );
522 return;
523 }
524
525 err = mailmime_write( f, &col, mail );
526 if ( err != MAILIMF_NO_ERROR ) {
527 fclose( f );
528 qDebug( "writeToFile: error writing mailmime" );
529 return;
530 }
531
532 fclose( f );
533}
534
535void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
536{
537
538 QFile msg_cache(file);
539 QString msg = "";
540 msg_cache.open(IO_ReadOnly);
541 char*message = new char[4096];
542 memset(message,0,4096);
543 while (msg_cache.readBlock(message,4095)>0) {
544 msg+=message;
545 memset(message,0,4096);
546 }
547 delete message;
548 *data = (char*)malloc(msg.length()+1*sizeof(char));
549 memset(*data,0,msg.length()+1);
550 memcpy(*data,msg.ascii(),msg.length());
551 *size=msg.length();
552}
553
554void SMTPwrapper::progress( size_t current, size_t maximum ) 485void SMTPwrapper::progress( size_t current, size_t maximum )
@@ -580,11 +511,19 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
580 from = data = 0; 511 from = data = 0;
581 512
582 QString file = getTmpFile(); 513 mailmessage * msg = 0;
583 writeToFile( file, mail ); 514 msg = mime_message_init(mail);
584 readFromFile( file, &data, &size ); 515 mime_message_set_tmpdir(msg,getenv( "HOME" ));
585 QFile f( file ); 516 int r = mailmessage_fetch(msg,&data,&size);
586 f.remove(); 517 mime_message_detach_mime(msg);
587 518 mailmessage_free(msg);
519 if (r != MAIL_NO_ERROR || !data) {
520 if (data) free(data);
521 qDebug("Error fetching mime...");
522 return;
523 }
524 QString tmp = data;
525 tmp.replace(QRegExp("\r+",true,false),"");
526 msg = 0;
588 if (later) { 527 if (later) {
589 storeMail(data,size,"Outgoing"); 528 storeMail((char*)tmp.data(),tmp.length(),"Outgoing");
590 if (data) free( data ); 529 if (data) free( data );
@@ -690,3 +629,2 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later )
690 smtpSend( mimeMail,later,smtp); 629 smtpSend( mimeMail,later,smtp);
691 mailmime_free( mimeMail );
692 qDebug("Clean up done"); 630 qDebug("Clean up done");
@@ -695,2 +633,3 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later )
695 sendProgress = 0; 633 sendProgress = 0;
634 mailmime_free( mimeMail );
696 } 635 }
@@ -749,3 +688,3 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
749 688
750 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 689 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
751 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 690 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
@@ -772,3 +711,2 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
772 tr("Error sending queued mail - breaking")); 711 tr("Error sending queued mail - breaking"));
773
774 returnValue = false; 712 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:
45 SMTPaccount *getAccount(const QString&from ); 45 SMTPaccount *getAccount(const QString&from );
46 void writeToFile(const QString&file, mailmime *mail );
47 void readFromFile(const QString&file, char **data, size_t *size );
48 46
@@ -50,3 +48,2 @@ protected:
50 static QString mailsmtpError( int err ); 48 static QString mailsmtpError( int err );
51 static QString getTmpFile();
52 static void progress( size_t current, size_t maximum ); 49 static void progress( size_t current, size_t maximum );