summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-25 14:23:31 (UTC)
committer alwin <alwin>2003-12-25 14:23:31 (UTC)
commit25ee009ceeda1a175c4604bf5afe5434e52ee838 (patch) (unidiff)
treeccc6b8cfbfac74880e9bebc5be595384ccf731e9
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 (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
@@ -104,30 +104,28 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr )
104 break; 104 break;
105 default: 105 default:
106 break; 106 break;
107 } 107 }
108 } 108 }
109 s = addr.mid(startpos,i-startpos); 109 s = addr.mid(startpos,i-startpos);
110 if (!s.isEmpty()) { 110 if (!s.isEmpty()) {
111 list.append(s); 111 list.append(s);
112 qDebug("Appended %s",s.latin1()); 112 qDebug("Appended %s",s.latin1());
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 }
125 } 123 }
126 return addresses; 124 return addresses;
127} 125}
128 126
129mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) 127mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
130{ 128{
131 mailimf_fields *fields; 129 mailimf_fields *fields;
132 mailimf_field *xmailer; 130 mailimf_field *xmailer;
133 mailimf_mailbox *sender, *fromBox; 131 mailimf_mailbox *sender, *fromBox;
@@ -187,132 +185,124 @@ err_free:
187 free( subject ); 185 free( subject );
188 qDebug( "createImfFields - error" ); 186 qDebug( "createImfFields - error" );
189 187
190 return NULL; // Error :( 188 return NULL; // Error :(
191} 189}
192 190
193mailmime *SMTPwrapper::buildTxtPart(const QString&str ) 191mailmime *SMTPwrapper::buildTxtPart(const QString&str )
194{ 192{
195 mailmime *txtPart; 193 mailmime *txtPart;
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" ),
203 strdup( "iso-8859-1" ) ); 200 strdup( "iso-8859-1" ) );
204 if ( param == NULL ) goto err_free; 201 if ( param == NULL ) goto err_free;
205 202
206 content = mailmime_content_new_with_str( "text/plain" ); 203 content = mailmime_content_new_with_str( "text/plain" );
207 if ( content == NULL ) goto err_free_param; 204 if ( content == NULL ) goto err_free_param;
208 205
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 :)
222 219
223err_free_txtPart: 220err_free_txtPart:
224 mailmime_free( txtPart ); 221 mailmime_free( txtPart );
225err_free_fields: 222err_free_fields:
226 mailmime_fields_free( fields ); 223 mailmime_fields_free( fields );
227err_free_content: 224err_free_content:
228 mailmime_content_free( content ); 225 mailmime_content_free( content );
229err_free_param: 226err_free_param:
230 mailmime_parameter_free( param ); 227 mailmime_parameter_free( param );
231err_free: 228err_free:
232 free( txt );
233 qDebug( "buildTxtPart - error" ); 229 qDebug( "buildTxtPart - error" );
234 230
235 return NULL; // Error :( 231 return NULL; // Error :(
236} 232}
237 233
238mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) 234mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent )
239{ 235{
240 mailmime * filePart = 0; 236 mailmime * filePart = 0;
241 mailmime_fields * fields = 0; 237 mailmime_fields * fields = 0;
242 mailmime_content * content = 0; 238 mailmime_content * content = 0;
243 mailmime_parameter * param = 0; 239 mailmime_parameter * param = 0;
244 char*name = 0; 240 char*name = 0;
245 char*file = 0; 241 char*file = 0;
246 int err; 242 int err;
247 243
248 int pos = filename.findRev( '/' ); 244 int pos = filename.findRev( '/' );
249 245
250 if (filename.length()>0) { 246 if (filename.length()>0) {
251 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 247 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
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);
274 param = 0; 268 param = 0;
275 } 269 }
276 if (filename.length()>0) { 270 if (filename.length()>0) {
277 QFileInfo f(filename); 271 QFileInfo f(filename);
278 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 272 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
279 clist_append(content->ct_parameters,param); 273 clist_append(content->ct_parameters,param);
280 param = 0; 274 param = 0;
281 } 275 }
282 filePart = mailmime_new_empty( content, fields ); 276 filePart = mailmime_new_empty( content, fields );
283 } 277 }
284 if (filePart) { 278 if (filePart) {
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);
292 mailmime_free( filePart ); 286 mailmime_free( filePart );
293 filePart = 0; 287 filePart = 0;
294 } 288 }
295 } 289 }
296 290
297 if (!filePart) { 291 if (!filePart) {
298 if ( param != NULL ) { 292 if ( param != NULL ) {
299 mailmime_parameter_free( param ); 293 mailmime_parameter_free( param );
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 );
310 } else { 300 } else {
311 if (name) { 301 if (name) {
312 free( name ); 302 free( name );
313 } 303 }
314 if (file) { 304 if (file) {
315 free( file ); 305 free( file );
316 } 306 }
317 } 307 }
318 } 308 }
@@ -350,29 +340,26 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
350 mailmime *message, *txtPart; 340 mailmime *message, *txtPart;
351 mailimf_fields *fields; 341 mailimf_fields *fields;
352 int err; 342 int err;
353 343
354 fields = createImfFields( mail ); 344 fields = createImfFields( mail );
355 if ( fields == NULL ) goto err_free; 345 if ( fields == NULL ) goto err_free;
356 346
357 message = mailmime_new_message_data( NULL ); 347 message = mailmime_new_message_data( NULL );
358 if ( message == NULL ) goto err_free_fields; 348 if ( message == NULL ) goto err_free_fields;
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 );
370 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 357 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
371 358
372 addFileParts( message, mail.getAttachments() ); 359 addFileParts( message, mail.getAttachments() );
373 360
374 return message; // Success :) 361 return message; // Success :)
375 362
376err_free_txtPart: 363err_free_txtPart:
377 mailmime_free( txtPart ); 364 mailmime_free( txtPart );
378err_free_message: 365err_free_message:
@@ -462,104 +449,48 @@ char *SMTPwrapper::getFrom( mailimf_field *ffrom)
462 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 449 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
463 from = strdup( mb->mb_addr_spec ); 450 from = strdup( mb->mb_addr_spec );
464 } 451 }
465 } 452 }
466 453
467 return from; 454 return from;
468} 455}
469 456
470char *SMTPwrapper::getFrom( mailmime *mail ) 457char *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}
478 464
479SMTPaccount *SMTPwrapper::getAccount(const QString&name ) 465SMTPaccount *SMTPwrapper::getAccount(const QString&name )
480{ 466{
481 SMTPaccount *smtp; 467 SMTPaccount *smtp;
482 468
483 QList<Account> list = settings->getAccounts(); 469 QList<Account> list = settings->getAccounts();
484 Account *it; 470 Account *it;
485 for ( it = list.first(); it; it = list.next() ) { 471 for ( it = list.first(); it; it = list.next() ) {
486 if ( it->getType().compare( "SMTP" ) == 0 ) { 472 if ( it->getType().compare( "SMTP" ) == 0 ) {
487 smtp = static_cast<SMTPaccount *>(it); 473 smtp = static_cast<SMTPaccount *>(it);
488 if ( smtp->getName()== name ) { 474 if ( smtp->getName()== name ) {
489 qDebug( "SMTPaccount found for" ); 475 qDebug( "SMTPaccount found for" );
490 qDebug( name ); 476 qDebug( name );
491 return smtp; 477 return smtp;
492 } 478 }
493 } 479 }
494 } 480 }
495 481
496 return NULL; 482 return NULL;
497} 483}
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 )
555{ 486{
556 if (SMTPwrapper::sendProgress) { 487 if (SMTPwrapper::sendProgress) {
557 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 488 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
558 qApp->processEvents(); 489 qApp->processEvents();
559 } 490 }
560} 491}
561 492
562void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) 493void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
563{ 494{
564 if (!mail) return; 495 if (!mail) return;
565 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 496 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
@@ -569,33 +500,41 @@ void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
569} 500}
570 501
571void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 502void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
572{ 503{
573 clist *rcpts = 0; 504 clist *rcpts = 0;
574 char *from, *data; 505 char *from, *data;
575 size_t size; 506 size_t size;
576 507
577 if ( smtp == NULL ) { 508 if ( smtp == NULL ) {
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 }
593 from = getFrom( mail ); 532 from = getFrom( mail );
594 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 533 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
595 smtpSend(from,rcpts,data,size,smtp); 534 smtpSend(from,rcpts,data,size,smtp);
596 if (data) {free(data);} 535 if (data) {free(data);}
597 if (from) {free(from);} 536 if (from) {free(from);}
598 if (rcpts) smtp_address_list_free( rcpts ); 537 if (rcpts) smtp_address_list_free( rcpts );
599} 538}
600 539
601int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) 540int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
@@ -679,29 +618,29 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later )
679 mailmime * mimeMail; 618 mailmime * mimeMail;
680 619
681 SMTPaccount *smtp = getAccount(mail.getName()); 620 SMTPaccount *smtp = getAccount(mail.getName());
682 621
683 mimeMail = createMimeMail(mail ); 622 mimeMail = createMimeMail(mail );
684 if ( mimeMail == NULL ) { 623 if ( mimeMail == NULL ) {
685 qDebug( "sendMail: error creating mime mail" ); 624 qDebug( "sendMail: error creating mime mail" );
686 } else { 625 } else {
687 sendProgress = new progressMailSend(); 626 sendProgress = new progressMailSend();
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
699int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) 638int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
700{ 639{
701 char*data = 0; 640 char*data = 0;
702 size_t length = 0; 641 size_t length = 0;
703 size_t curTok = 0; 642 size_t curTok = 0;
704 mailimf_fields *fields = 0; 643 mailimf_fields *fields = 0;
705 mailimf_field*ffrom = 0; 644 mailimf_field*ffrom = 0;
706 clist *rcpts = 0; 645 clist *rcpts = 0;
707 char*from = 0; 646 char*from = 0;
@@ -738,48 +677,47 @@ int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
738 smtp_address_list_free( rcpts ); 677 smtp_address_list_free( rcpts );
739 } 678 }
740 return res; 679 return res;
741} 680}
742 681
743/* this is a special fun */ 682/* this is a special fun */
744bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) 683bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
745{ 684{
746 bool returnValue = true; 685 bool returnValue = true;
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");
754 return false; 693 return false;
755 } 694 }
756 QList<RecMail> mailsToSend; 695 QList<RecMail> mailsToSend;
757 QList<RecMail> mailsToRemove; 696 QList<RecMail> mailsToRemove;
758 QString mbox("Outgoing"); 697 QString mbox("Outgoing");
759 wrap->listMessages(mbox,mailsToSend); 698 wrap->listMessages(mbox,mailsToSend);
760 if (mailsToSend.count()==0) { 699 if (mailsToSend.count()==0) {
761 delete wrap; 700 delete wrap;
762 return false; 701 return false;
763 } 702 }
764 mailsToSend.setAutoDelete(false); 703 mailsToSend.setAutoDelete(false);
765 sendProgress = new progressMailSend(); 704 sendProgress = new progressMailSend();
766 sendProgress->show(); 705 sendProgress->show();
767 sendProgress->setMaxMails(mailsToSend.count()); 706 sendProgress->setMaxMails(mailsToSend.count());
768 707
769 while (mailsToSend.count()>0) { 708 while (mailsToSend.count()>0) {
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 }
777 mailsToRemove.append(mailsToSend.at(0)); 715 mailsToRemove.append(mailsToSend.at(0));
778 mailsToSend.removeFirst(); 716 mailsToSend.removeFirst();
779 sendProgress->setCurrentMails(mailsToRemove.count()); 717 sendProgress->setCurrentMails(mailsToRemove.count());
780 } 718 }
781 sendProgress->hide(); 719 sendProgress->hide();
782 delete sendProgress; 720 delete sendProgress;
783 sendProgress = 0; 721 sendProgress = 0;
784 wrap->deleteMails(mbox,mailsToRemove); 722 wrap->deleteMails(mbox,mailsToRemove);
785 mailsToSend.setAutoDelete(true); 723 mailsToSend.setAutoDelete(true);
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
@@ -34,30 +34,27 @@ public:
34protected: 34protected:
35 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 35 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
36 mailimf_fields *createImfFields(const Mail &mail ); 36 mailimf_fields *createImfFields(const Mail &mail );
37 mailmime *createMimeMail(const Mail&mail ); 37 mailmime *createMimeMail(const Mail&mail );
38 38
39 mailimf_address_list *parseAddresses(const QString&addr ); 39 mailimf_address_list *parseAddresses(const QString&addr );
40 void addFileParts( mailmime *message,const QList<Attachment>&files ); 40 void addFileParts( mailmime *message,const QList<Attachment>&files );
41 mailmime *buildTxtPart(const QString&str ); 41 mailmime *buildTxtPart(const QString&str );
42 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); 42 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
43 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); 43 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp );
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 );
54 static char *getFrom( mailmime *mail ); 51 static char *getFrom( mailmime *mail );
55 static char *getFrom( mailimf_field *ffrom); 52 static char *getFrom( mailimf_field *ffrom);
56 static mailimf_field *getField( mailimf_fields *fields, int type ); 53 static mailimf_field *getField( mailimf_fields *fields, int type );
57 int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); 54 int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp );
58 55
59 void storeMail(mailmime*mail, const QString&box); 56 void storeMail(mailmime*mail, const QString&box);
60 Settings *settings; 57 Settings *settings;
61 58
62 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); 59 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which);
63}; 60};
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
@@ -104,30 +104,28 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr )
104 break; 104 break;
105 default: 105 default:
106 break; 106 break;
107 } 107 }
108 } 108 }
109 s = addr.mid(startpos,i-startpos); 109 s = addr.mid(startpos,i-startpos);
110 if (!s.isEmpty()) { 110 if (!s.isEmpty()) {
111 list.append(s); 111 list.append(s);
112 qDebug("Appended %s",s.latin1()); 112 qDebug("Appended %s",s.latin1());
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 }
125 } 123 }
126 return addresses; 124 return addresses;
127} 125}
128 126
129mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) 127mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
130{ 128{
131 mailimf_fields *fields; 129 mailimf_fields *fields;
132 mailimf_field *xmailer; 130 mailimf_field *xmailer;
133 mailimf_mailbox *sender, *fromBox; 131 mailimf_mailbox *sender, *fromBox;
@@ -187,132 +185,124 @@ err_free:
187 free( subject ); 185 free( subject );
188 qDebug( "createImfFields - error" ); 186 qDebug( "createImfFields - error" );
189 187
190 return NULL; // Error :( 188 return NULL; // Error :(
191} 189}
192 190
193mailmime *SMTPwrapper::buildTxtPart(const QString&str ) 191mailmime *SMTPwrapper::buildTxtPart(const QString&str )
194{ 192{
195 mailmime *txtPart; 193 mailmime *txtPart;
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" ),
203 strdup( "iso-8859-1" ) ); 200 strdup( "iso-8859-1" ) );
204 if ( param == NULL ) goto err_free; 201 if ( param == NULL ) goto err_free;
205 202
206 content = mailmime_content_new_with_str( "text/plain" ); 203 content = mailmime_content_new_with_str( "text/plain" );
207 if ( content == NULL ) goto err_free_param; 204 if ( content == NULL ) goto err_free_param;
208 205
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 :)
222 219
223err_free_txtPart: 220err_free_txtPart:
224 mailmime_free( txtPart ); 221 mailmime_free( txtPart );
225err_free_fields: 222err_free_fields:
226 mailmime_fields_free( fields ); 223 mailmime_fields_free( fields );
227err_free_content: 224err_free_content:
228 mailmime_content_free( content ); 225 mailmime_content_free( content );
229err_free_param: 226err_free_param:
230 mailmime_parameter_free( param ); 227 mailmime_parameter_free( param );
231err_free: 228err_free:
232 free( txt );
233 qDebug( "buildTxtPart - error" ); 229 qDebug( "buildTxtPart - error" );
234 230
235 return NULL; // Error :( 231 return NULL; // Error :(
236} 232}
237 233
238mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) 234mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent )
239{ 235{
240 mailmime * filePart = 0; 236 mailmime * filePart = 0;
241 mailmime_fields * fields = 0; 237 mailmime_fields * fields = 0;
242 mailmime_content * content = 0; 238 mailmime_content * content = 0;
243 mailmime_parameter * param = 0; 239 mailmime_parameter * param = 0;
244 char*name = 0; 240 char*name = 0;
245 char*file = 0; 241 char*file = 0;
246 int err; 242 int err;
247 243
248 int pos = filename.findRev( '/' ); 244 int pos = filename.findRev( '/' );
249 245
250 if (filename.length()>0) { 246 if (filename.length()>0) {
251 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 247 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
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);
274 param = 0; 268 param = 0;
275 } 269 }
276 if (filename.length()>0) { 270 if (filename.length()>0) {
277 QFileInfo f(filename); 271 QFileInfo f(filename);
278 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 272 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
279 clist_append(content->ct_parameters,param); 273 clist_append(content->ct_parameters,param);
280 param = 0; 274 param = 0;
281 } 275 }
282 filePart = mailmime_new_empty( content, fields ); 276 filePart = mailmime_new_empty( content, fields );
283 } 277 }
284 if (filePart) { 278 if (filePart) {
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);
292 mailmime_free( filePart ); 286 mailmime_free( filePart );
293 filePart = 0; 287 filePart = 0;
294 } 288 }
295 } 289 }
296 290
297 if (!filePart) { 291 if (!filePart) {
298 if ( param != NULL ) { 292 if ( param != NULL ) {
299 mailmime_parameter_free( param ); 293 mailmime_parameter_free( param );
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 );
310 } else { 300 } else {
311 if (name) { 301 if (name) {
312 free( name ); 302 free( name );
313 } 303 }
314 if (file) { 304 if (file) {
315 free( file ); 305 free( file );
316 } 306 }
317 } 307 }
318 } 308 }
@@ -350,29 +340,26 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
350 mailmime *message, *txtPart; 340 mailmime *message, *txtPart;
351 mailimf_fields *fields; 341 mailimf_fields *fields;
352 int err; 342 int err;
353 343
354 fields = createImfFields( mail ); 344 fields = createImfFields( mail );
355 if ( fields == NULL ) goto err_free; 345 if ( fields == NULL ) goto err_free;
356 346
357 message = mailmime_new_message_data( NULL ); 347 message = mailmime_new_message_data( NULL );
358 if ( message == NULL ) goto err_free_fields; 348 if ( message == NULL ) goto err_free_fields;
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 );
370 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 357 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
371 358
372 addFileParts( message, mail.getAttachments() ); 359 addFileParts( message, mail.getAttachments() );
373 360
374 return message; // Success :) 361 return message; // Success :)
375 362
376err_free_txtPart: 363err_free_txtPart:
377 mailmime_free( txtPart ); 364 mailmime_free( txtPart );
378err_free_message: 365err_free_message:
@@ -462,104 +449,48 @@ char *SMTPwrapper::getFrom( mailimf_field *ffrom)
462 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 449 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
463 from = strdup( mb->mb_addr_spec ); 450 from = strdup( mb->mb_addr_spec );
464 } 451 }
465 } 452 }
466 453
467 return from; 454 return from;
468} 455}
469 456
470char *SMTPwrapper::getFrom( mailmime *mail ) 457char *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}
478 464
479SMTPaccount *SMTPwrapper::getAccount(const QString&name ) 465SMTPaccount *SMTPwrapper::getAccount(const QString&name )
480{ 466{
481 SMTPaccount *smtp; 467 SMTPaccount *smtp;
482 468
483 QList<Account> list = settings->getAccounts(); 469 QList<Account> list = settings->getAccounts();
484 Account *it; 470 Account *it;
485 for ( it = list.first(); it; it = list.next() ) { 471 for ( it = list.first(); it; it = list.next() ) {
486 if ( it->getType().compare( "SMTP" ) == 0 ) { 472 if ( it->getType().compare( "SMTP" ) == 0 ) {
487 smtp = static_cast<SMTPaccount *>(it); 473 smtp = static_cast<SMTPaccount *>(it);
488 if ( smtp->getName()== name ) { 474 if ( smtp->getName()== name ) {
489 qDebug( "SMTPaccount found for" ); 475 qDebug( "SMTPaccount found for" );
490 qDebug( name ); 476 qDebug( name );
491 return smtp; 477 return smtp;
492 } 478 }
493 } 479 }
494 } 480 }
495 481
496 return NULL; 482 return NULL;
497} 483}
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 )
555{ 486{
556 if (SMTPwrapper::sendProgress) { 487 if (SMTPwrapper::sendProgress) {
557 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 488 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
558 qApp->processEvents(); 489 qApp->processEvents();
559 } 490 }
560} 491}
561 492
562void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) 493void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
563{ 494{
564 if (!mail) return; 495 if (!mail) return;
565 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 496 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
@@ -569,33 +500,41 @@ void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
569} 500}
570 501
571void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 502void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
572{ 503{
573 clist *rcpts = 0; 504 clist *rcpts = 0;
574 char *from, *data; 505 char *from, *data;
575 size_t size; 506 size_t size;
576 507
577 if ( smtp == NULL ) { 508 if ( smtp == NULL ) {
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 }
593 from = getFrom( mail ); 532 from = getFrom( mail );
594 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 533 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
595 smtpSend(from,rcpts,data,size,smtp); 534 smtpSend(from,rcpts,data,size,smtp);
596 if (data) {free(data);} 535 if (data) {free(data);}
597 if (from) {free(from);} 536 if (from) {free(from);}
598 if (rcpts) smtp_address_list_free( rcpts ); 537 if (rcpts) smtp_address_list_free( rcpts );
599} 538}
600 539
601int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) 540int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
@@ -679,29 +618,29 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later )
679 mailmime * mimeMail; 618 mailmime * mimeMail;
680 619
681 SMTPaccount *smtp = getAccount(mail.getName()); 620 SMTPaccount *smtp = getAccount(mail.getName());
682 621
683 mimeMail = createMimeMail(mail ); 622 mimeMail = createMimeMail(mail );
684 if ( mimeMail == NULL ) { 623 if ( mimeMail == NULL ) {
685 qDebug( "sendMail: error creating mime mail" ); 624 qDebug( "sendMail: error creating mime mail" );
686 } else { 625 } else {
687 sendProgress = new progressMailSend(); 626 sendProgress = new progressMailSend();
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
699int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) 638int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
700{ 639{
701 char*data = 0; 640 char*data = 0;
702 size_t length = 0; 641 size_t length = 0;
703 size_t curTok = 0; 642 size_t curTok = 0;
704 mailimf_fields *fields = 0; 643 mailimf_fields *fields = 0;
705 mailimf_field*ffrom = 0; 644 mailimf_field*ffrom = 0;
706 clist *rcpts = 0; 645 clist *rcpts = 0;
707 char*from = 0; 646 char*from = 0;
@@ -738,48 +677,47 @@ int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
738 smtp_address_list_free( rcpts ); 677 smtp_address_list_free( rcpts );
739 } 678 }
740 return res; 679 return res;
741} 680}
742 681
743/* this is a special fun */ 682/* this is a special fun */
744bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) 683bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
745{ 684{
746 bool returnValue = true; 685 bool returnValue = true;
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");
754 return false; 693 return false;
755 } 694 }
756 QList<RecMail> mailsToSend; 695 QList<RecMail> mailsToSend;
757 QList<RecMail> mailsToRemove; 696 QList<RecMail> mailsToRemove;
758 QString mbox("Outgoing"); 697 QString mbox("Outgoing");
759 wrap->listMessages(mbox,mailsToSend); 698 wrap->listMessages(mbox,mailsToSend);
760 if (mailsToSend.count()==0) { 699 if (mailsToSend.count()==0) {
761 delete wrap; 700 delete wrap;
762 return false; 701 return false;
763 } 702 }
764 mailsToSend.setAutoDelete(false); 703 mailsToSend.setAutoDelete(false);
765 sendProgress = new progressMailSend(); 704 sendProgress = new progressMailSend();
766 sendProgress->show(); 705 sendProgress->show();
767 sendProgress->setMaxMails(mailsToSend.count()); 706 sendProgress->setMaxMails(mailsToSend.count());
768 707
769 while (mailsToSend.count()>0) { 708 while (mailsToSend.count()>0) {
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 }
777 mailsToRemove.append(mailsToSend.at(0)); 715 mailsToRemove.append(mailsToSend.at(0));
778 mailsToSend.removeFirst(); 716 mailsToSend.removeFirst();
779 sendProgress->setCurrentMails(mailsToRemove.count()); 717 sendProgress->setCurrentMails(mailsToRemove.count());
780 } 718 }
781 sendProgress->hide(); 719 sendProgress->hide();
782 delete sendProgress; 720 delete sendProgress;
783 sendProgress = 0; 721 sendProgress = 0;
784 wrap->deleteMails(mbox,mailsToRemove); 722 wrap->deleteMails(mbox,mailsToRemove);
785 mailsToSend.setAutoDelete(true); 723 mailsToSend.setAutoDelete(true);
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
@@ -34,30 +34,27 @@ public:
34protected: 34protected:
35 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 35 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
36 mailimf_fields *createImfFields(const Mail &mail ); 36 mailimf_fields *createImfFields(const Mail &mail );
37 mailmime *createMimeMail(const Mail&mail ); 37 mailmime *createMimeMail(const Mail&mail );
38 38
39 mailimf_address_list *parseAddresses(const QString&addr ); 39 mailimf_address_list *parseAddresses(const QString&addr );
40 void addFileParts( mailmime *message,const QList<Attachment>&files ); 40 void addFileParts( mailmime *message,const QList<Attachment>&files );
41 mailmime *buildTxtPart(const QString&str ); 41 mailmime *buildTxtPart(const QString&str );
42 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); 42 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
43 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); 43 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp );
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 );
54 static char *getFrom( mailmime *mail ); 51 static char *getFrom( mailmime *mail );
55 static char *getFrom( mailimf_field *ffrom); 52 static char *getFrom( mailimf_field *ffrom);
56 static mailimf_field *getField( mailimf_fields *fields, int type ); 53 static mailimf_field *getField( mailimf_fields *fields, int type );
57 int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); 54 int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp );
58 55
59 void storeMail(mailmime*mail, const QString&box); 56 void storeMail(mailmime*mail, const QString&box);
60 Settings *settings; 57 Settings *settings;
61 58
62 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); 59 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which);
63}; 60};