-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 | |||
@@ -114,10 +114,8 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) | |||
114 | QStringList::Iterator it; | 114 | QStringList::Iterator it; |
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 ) { |
119 | qDebug( "Error parsing" ); | 118 | qDebug( "Error parsing" ); |
120 | qDebug( *it ); | 119 | qDebug( *it ); |
121 | free( str ); | ||
122 | } else { | 120 | } else { |
123 | qDebug( "Parse success! %s",(*it).latin1()); | 121 | qDebug( "Parse success! %s",(*it).latin1()); |
@@ -197,5 +195,4 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | |||
197 | mailmime_content *content; | 195 | mailmime_content *content; |
198 | mailmime_parameter *param; | 196 | mailmime_parameter *param; |
199 | char *txt = strdup( str.latin1() ); | ||
200 | int err; | 197 | int err; |
201 | 198 | ||
@@ -210,5 +207,5 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | |||
210 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 207 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
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; |
214 | 211 | ||
@@ -216,5 +213,5 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | |||
216 | if ( txtPart == NULL ) goto err_free_fields; | 213 | if ( txtPart == NULL ) goto err_free_fields; |
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; |
220 | 217 | ||
@@ -230,5 +227,4 @@ err_free_param: | |||
230 | mailmime_parameter_free( param ); | 227 | mailmime_parameter_free( param ); |
231 | err_free: | 228 | err_free: |
232 | free( txt ); | ||
233 | qDebug( "buildTxtPart - error" ); | 229 | qDebug( "buildTxtPart - error" ); |
234 | 230 | ||
@@ -253,6 +249,5 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
253 | file = strdup( filename.latin1() ); // full name with path | 249 | file = strdup( filename.latin1() ); // full name with path |
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; |
258 | int mechanism = MAILMIME_MECHANISM_BASE64; | 253 | int mechanism = MAILMIME_MECHANISM_BASE64; |
@@ -261,5 +256,4 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
261 | param = mailmime_parameter_new( strdup( "charset" ), | 256 | param = mailmime_parameter_new( strdup( "charset" ), |
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; |
265 | } | 259 | } |
@@ -268,5 +262,5 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
268 | disptype, name, | 262 | disptype, name, |
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) { |
272 | if (param) { | 266 | if (param) { |
@@ -286,5 +280,5 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
286 | err = mailmime_set_body_file( filePart, file ); | 280 | err = mailmime_set_body_file( filePart, file ); |
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 | } |
290 | if (err != MAILIMF_NO_ERROR) { | 284 | if (err != MAILIMF_NO_ERROR) { |
@@ -301,8 +295,4 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
301 | if (content) { | 295 | if (content) { |
302 | mailmime_content_free( content ); | 296 | mailmime_content_free( content ); |
303 | } else { | ||
304 | if (mime) { | ||
305 | free( mime ); | ||
306 | } | ||
307 | } | 297 | } |
308 | if (fields) { | 298 | if (fields) { |
@@ -360,9 +350,6 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | |||
360 | mailmime_set_imf_fields( message, fields ); | 350 | mailmime_set_imf_fields( message, fields ); |
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; |
368 | 355 | ||
@@ -472,5 +459,4 @@ char *SMTPwrapper::getFrom( mailmime *mail ) | |||
472 | /* no need to delete - its just a pointer to structure content */ | 459 | /* no need to delete - its just a pointer to structure content */ |
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 ); |
476 | return getFrom(ffrom); | 462 | return getFrom(ffrom); |
@@ -497,59 +483,4 @@ SMTPaccount *SMTPwrapper::getAccount(const QString&name ) | |||
497 | } | 483 | } |
498 | 484 | ||
499 | QString 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 | |||
514 | void 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 | |||
535 | void 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 | |||
554 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 485 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
555 | { | 486 | { |
@@ -579,13 +510,21 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) | |||
579 | } | 510 | } |
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 ); |
591 | return; | 530 | return; |
@@ -689,9 +628,9 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later ) | |||
689 | sendProgress->setMaxMails(1); | 628 | sendProgress->setMaxMails(1); |
690 | smtpSend( mimeMail,later,smtp); | 629 | smtpSend( mimeMail,later,smtp); |
691 | mailmime_free( mimeMail ); | ||
692 | qDebug("Clean up done"); | 630 | qDebug("Clean up done"); |
693 | sendProgress->hide(); | 631 | sendProgress->hide(); |
694 | delete sendProgress; | 632 | delete sendProgress; |
695 | sendProgress = 0; | 633 | sendProgress = 0; |
634 | mailmime_free( mimeMail ); | ||
696 | } | 635 | } |
697 | } | 636 | } |
@@ -748,5 +687,5 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) | |||
748 | if (!smtp) return false; | 687 | if (!smtp) return false; |
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); |
752 | if (!wrap) { | 691 | if (!wrap) { |
@@ -771,5 +710,4 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) | |||
771 | QMessageBox::critical(0,tr("Error sending mail"), | 710 | QMessageBox::critical(0,tr("Error sending mail"), |
772 | tr("Error sending queued mail - breaking")); | 711 | tr("Error sending queued mail - breaking")); |
773 | |||
774 | returnValue = false; | 712 | returnValue = false; |
775 | break; | 713 | break; |
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 | |||
@@ -44,10 +44,7 @@ protected: | |||
44 | clist *createRcptList( mailimf_fields *fields ); | 44 | clist *createRcptList( mailimf_fields *fields ); |
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 | ||
49 | static void storeMail(char*mail, size_t length, const QString&box); | 47 | static void storeMail(char*mail, size_t length, const QString&box); |
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 ); |
53 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 50 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |
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 | |||
@@ -114,10 +114,8 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) | |||
114 | QStringList::Iterator it; | 114 | QStringList::Iterator it; |
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 ) { |
119 | qDebug( "Error parsing" ); | 118 | qDebug( "Error parsing" ); |
120 | qDebug( *it ); | 119 | qDebug( *it ); |
121 | free( str ); | ||
122 | } else { | 120 | } else { |
123 | qDebug( "Parse success! %s",(*it).latin1()); | 121 | qDebug( "Parse success! %s",(*it).latin1()); |
@@ -197,5 +195,4 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | |||
197 | mailmime_content *content; | 195 | mailmime_content *content; |
198 | mailmime_parameter *param; | 196 | mailmime_parameter *param; |
199 | char *txt = strdup( str.latin1() ); | ||
200 | int err; | 197 | int err; |
201 | 198 | ||
@@ -210,5 +207,5 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | |||
210 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 207 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
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; |
214 | 211 | ||
@@ -216,5 +213,5 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | |||
216 | if ( txtPart == NULL ) goto err_free_fields; | 213 | if ( txtPart == NULL ) goto err_free_fields; |
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; |
220 | 217 | ||
@@ -230,5 +227,4 @@ err_free_param: | |||
230 | mailmime_parameter_free( param ); | 227 | mailmime_parameter_free( param ); |
231 | err_free: | 228 | err_free: |
232 | free( txt ); | ||
233 | qDebug( "buildTxtPart - error" ); | 229 | qDebug( "buildTxtPart - error" ); |
234 | 230 | ||
@@ -253,6 +249,5 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
253 | file = strdup( filename.latin1() ); // full name with path | 249 | file = strdup( filename.latin1() ); // full name with path |
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; |
258 | int mechanism = MAILMIME_MECHANISM_BASE64; | 253 | int mechanism = MAILMIME_MECHANISM_BASE64; |
@@ -261,5 +256,4 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
261 | param = mailmime_parameter_new( strdup( "charset" ), | 256 | param = mailmime_parameter_new( strdup( "charset" ), |
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; |
265 | } | 259 | } |
@@ -268,5 +262,5 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
268 | disptype, name, | 262 | disptype, name, |
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) { |
272 | if (param) { | 266 | if (param) { |
@@ -286,5 +280,5 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
286 | err = mailmime_set_body_file( filePart, file ); | 280 | err = mailmime_set_body_file( filePart, file ); |
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 | } |
290 | if (err != MAILIMF_NO_ERROR) { | 284 | if (err != MAILIMF_NO_ERROR) { |
@@ -301,8 +295,4 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
301 | if (content) { | 295 | if (content) { |
302 | mailmime_content_free( content ); | 296 | mailmime_content_free( content ); |
303 | } else { | ||
304 | if (mime) { | ||
305 | free( mime ); | ||
306 | } | ||
307 | } | 297 | } |
308 | if (fields) { | 298 | if (fields) { |
@@ -360,9 +350,6 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | |||
360 | mailmime_set_imf_fields( message, fields ); | 350 | mailmime_set_imf_fields( message, fields ); |
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; |
368 | 355 | ||
@@ -472,5 +459,4 @@ char *SMTPwrapper::getFrom( mailmime *mail ) | |||
472 | /* no need to delete - its just a pointer to structure content */ | 459 | /* no need to delete - its just a pointer to structure content */ |
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 ); |
476 | return getFrom(ffrom); | 462 | return getFrom(ffrom); |
@@ -497,59 +483,4 @@ SMTPaccount *SMTPwrapper::getAccount(const QString&name ) | |||
497 | } | 483 | } |
498 | 484 | ||
499 | QString 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 | |||
514 | void 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 | |||
535 | void 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 | |||
554 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 485 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
555 | { | 486 | { |
@@ -579,13 +510,21 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) | |||
579 | } | 510 | } |
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 ); |
591 | return; | 530 | return; |
@@ -689,9 +628,9 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later ) | |||
689 | sendProgress->setMaxMails(1); | 628 | sendProgress->setMaxMails(1); |
690 | smtpSend( mimeMail,later,smtp); | 629 | smtpSend( mimeMail,later,smtp); |
691 | mailmime_free( mimeMail ); | ||
692 | qDebug("Clean up done"); | 630 | qDebug("Clean up done"); |
693 | sendProgress->hide(); | 631 | sendProgress->hide(); |
694 | delete sendProgress; | 632 | delete sendProgress; |
695 | sendProgress = 0; | 633 | sendProgress = 0; |
634 | mailmime_free( mimeMail ); | ||
696 | } | 635 | } |
697 | } | 636 | } |
@@ -748,5 +687,5 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) | |||
748 | if (!smtp) return false; | 687 | if (!smtp) return false; |
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); |
752 | if (!wrap) { | 691 | if (!wrap) { |
@@ -771,5 +710,4 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) | |||
771 | QMessageBox::critical(0,tr("Error sending mail"), | 710 | QMessageBox::critical(0,tr("Error sending mail"), |
772 | tr("Error sending queued mail - breaking")); | 711 | tr("Error sending queued mail - breaking")); |
773 | |||
774 | returnValue = false; | 712 | returnValue = false; |
775 | break; | 713 | break; |
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 | |||
@@ -44,10 +44,7 @@ protected: | |||
44 | clist *createRcptList( mailimf_fields *fields ); | 44 | clist *createRcptList( mailimf_fields *fields ); |
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 | ||
49 | static void storeMail(char*mail, size_t length, const QString&box); | 47 | static void storeMail(char*mail, size_t length, const QString&box); |
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 ); |
53 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 50 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |