Diffstat (limited to 'noncore/net/mail/smtpwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/smtpwrapper.cpp | 114 |
1 files changed, 26 insertions, 88 deletions
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 | |||
@@ -113,12 +113,10 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) | |||
113 | } | 113 | } |
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()); |
124 | } | 122 | } |
@@ -196,7 +194,6 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | |||
196 | mailmime_fields *fields; | 194 | mailmime_fields *fields; |
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 | ||
202 | param = mailmime_parameter_new( strdup( "charset" ), | 199 | param = mailmime_parameter_new( strdup( "charset" ), |
@@ -209,13 +206,13 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | |||
209 | err = clist_append( content->ct_parameters, param ); | 206 | err = clist_append( content->ct_parameters, param ); |
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 | ||
215 | txtPart = mailmime_new_empty( content, fields ); | 212 | txtPart = mailmime_new_empty( content, fields ); |
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 | ||
221 | return txtPart; // Success :) | 218 | return txtPart; // Success :) |
@@ -229,7 +226,6 @@ err_free_content: | |||
229 | err_free_param: | 226 | 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 | ||
235 | return NULL; // Error :( | 231 | return NULL; // Error :( |
@@ -252,22 +248,20 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
252 | name = strdup( tmp.latin1() ); // just filename | 248 | name = strdup( tmp.latin1() ); // just filename |
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; |
259 | 254 | ||
260 | if ( mimetype.startsWith( "text/" ) ) { | 255 | if ( mimetype.startsWith( "text/" ) ) { |
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 | } |
266 | 260 | ||
267 | fields = mailmime_fields_new_filename( | 261 | fields = mailmime_fields_new_filename( |
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) { |
273 | clist_append(content->ct_parameters,param); | 267 | clist_append(content->ct_parameters,param); |
@@ -285,7 +279,7 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
285 | if (filename.length()>0) { | 279 | if (filename.length()>0) { |
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) { |
291 | qDebug("Error setting body with file %s",file); | 285 | qDebug("Error setting body with file %s",file); |
@@ -300,10 +294,6 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
300 | } | 294 | } |
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) { |
309 | mailmime_fields_free( fields ); | 299 | mailmime_fields_free( fields ); |
@@ -359,11 +349,8 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | |||
359 | 349 | ||
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 | ||
369 | err = mailmime_smart_add_part( message, txtPart ); | 356 | err = mailmime_smart_add_part( message, txtPart ); |
@@ -471,7 +458,6 @@ char *SMTPwrapper::getFrom( mailmime *mail ) | |||
471 | { | 458 | { |
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); |
477 | } | 463 | } |
@@ -496,61 +482,6 @@ SMTPaccount *SMTPwrapper::getAccount(const QString&name ) | |||
496 | return NULL; | 482 | return NULL; |
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 | { |
556 | if (SMTPwrapper::sendProgress) { | 487 | if (SMTPwrapper::sendProgress) { |
@@ -578,15 +509,23 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) | |||
578 | return; | 509 | return; |
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; |
592 | } | 531 | } |
@@ -688,11 +627,11 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later ) | |||
688 | sendProgress->show(); | 627 | sendProgress->show(); |
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 | } |
698 | 637 | ||
@@ -747,7 +686,7 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) | |||
747 | 686 | ||
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) { |
753 | qDebug("memory error"); | 692 | qDebug("memory error"); |
@@ -770,7 +709,6 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) | |||
770 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { | 709 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { |
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; |
776 | } | 714 | } |