summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index 00181ff..4764b77 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -445,263 +445,261 @@ clist *SMTPwrapper::createRcptList( mailimf_fields *fields )
445 } 445 }
446 446
447 field = getField( fields, MAILIMF_FIELD_BCC ); 447 field = getField( fields, MAILIMF_FIELD_BCC );
448 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 448 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
449 && field->fld_data.fld_bcc->bcc_addr_list ) { 449 && field->fld_data.fld_bcc->bcc_addr_list ) {
450 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 450 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
451 } 451 }
452 452
453 return rcptList; 453 return rcptList;
454} 454}
455 455
456char *SMTPwrapper::getFrom( mailimf_field *ffrom) 456char *SMTPwrapper::getFrom( mailimf_field *ffrom)
457{ 457{
458 char *from = NULL; 458 char *from = NULL;
459 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 459 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
460 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 460 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
461 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 461 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
462 clistiter *it; 462 clistiter *it;
463 for ( it = clist_begin( cl ); it; it = it->next ) { 463 for ( it = clist_begin( cl ); it; it = it->next ) {
464 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 464 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
465 from = strdup( mb->mb_addr_spec ); 465 from = strdup( mb->mb_addr_spec );
466 } 466 }
467 } 467 }
468 468
469 return from; 469 return from;
470} 470}
471 471
472char *SMTPwrapper::getFrom( mailmime *mail ) 472char *SMTPwrapper::getFrom( mailmime *mail )
473{ 473{
474 /* no need to delete - its just a pointer to structure content */ 474 /* no need to delete - its just a pointer to structure content */
475 mailimf_field *ffrom = 0; 475 mailimf_field *ffrom = 0;
476 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 476 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
477 return getFrom(ffrom); 477 return getFrom(ffrom);
478} 478}
479 479
480void SMTPwrapper::progress( size_t current, size_t maximum ) 480void SMTPwrapper::progress( size_t current, size_t maximum )
481{ 481{
482 if (SMTPwrapper::sendProgress) { 482 if (SMTPwrapper::sendProgress) {
483 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 483 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
484 qApp->processEvents(); 484 qApp->processEvents();
485 } 485 }
486} 486}
487 487
488void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) 488void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box)
489{ 489{
490 if (!mail) return; 490 if (!mail) return;
491 QString localfolders = AbstractMail::defaultLocalfolder(); 491 QString localfolders = AbstractMail::defaultLocalfolder();
492 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 492 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
493 wrap->storeMessage(mail,length,box); 493 wrap->storeMessage(mail,length,box);
494 delete wrap; 494 delete wrap;
495} 495}
496 496
497void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 497void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
498{ 498{
499 clist *rcpts = 0; 499 clist *rcpts = 0;
500 char *from, *data; 500 char *from, *data;
501 size_t size; 501 size_t size;
502 502
503 if ( smtp == NULL ) { 503 if ( smtp == NULL ) {
504 return; 504 return;
505 } 505 }
506 from = data = 0; 506 from = data = 0;
507 507
508 mailmessage * msg = 0; 508 mailmessage * msg = 0;
509 msg = mime_message_init(mail); 509 msg = mime_message_init(mail);
510 mime_message_set_tmpdir(msg,getenv( "HOME" )); 510 mime_message_set_tmpdir(msg,getenv( "HOME" ));
511 int r = mailmessage_fetch(msg,&data,&size); 511 int r = mailmessage_fetch(msg,&data,&size);
512 mime_message_detach_mime(msg); 512 mime_message_detach_mime(msg);
513 mailmessage_free(msg); 513 mailmessage_free(msg);
514 if (r != MAIL_NO_ERROR || !data) { 514 if (r != MAIL_NO_ERROR || !data) {
515 if (data) free(data); 515 if (data) free(data);
516 qDebug("Error fetching mime..."); 516 qDebug("Error fetching mime...");
517 return; 517 return;
518 } 518 }
519 QString tmp = data; 519 QString tmp = data;
520 tmp.replace(QRegExp("\r+",true,false),""); 520 tmp.replace(QRegExp("\r+",true,false),"");
521 msg = 0; 521 msg = 0;
522 if (later) { 522 if (later) {
523 storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); 523 storeMail((char*)tmp.data(),tmp.length(),"Outgoing");
524 if (data) free( data ); 524 if (data) free( data );
525 Config cfg( "mail" ); 525 Config cfg( "mail" );
526 cfg.setGroup( "Status" ); 526 cfg.setGroup( "Status" );
527 cfg.writeEntry( "outgoing", ++m_queuedMail ); 527 cfg.writeEntry( "outgoing", ++m_queuedMail );
528 emit queuedMails( m_queuedMail ); 528 emit queuedMails( m_queuedMail );
529 return; 529 return;
530 } 530 }
531 from = getFrom( mail ); 531 from = getFrom( mail );
532 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 532 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
533 smtpSend(from,rcpts,data,size,smtp); 533 smtpSend(from,rcpts,data,size,smtp);
534 if (data) {free(data);} 534 if (data) {free(data);}
535 if (from) {free(from);} 535 if (from) {free(from);}
536 if (rcpts) smtp_address_list_free( rcpts ); 536 if (rcpts) smtp_address_list_free( rcpts );
537} 537}
538 538
539int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) 539int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp )
540{ 540{
541 char *server, *user, *pass; 541 const char *server, *user, *pass;
542 bool ssl; 542 bool ssl;
543 uint16_t port; 543 uint16_t port;
544 mailsmtp *session; 544 mailsmtp *session;
545 int err,result; 545 int err,result;
546 546
547 result = 1; 547 result = 1;
548 server = user = pass = 0; 548 server = user = pass = 0;
549 server = strdup( smtp->getServer().latin1() ); 549 server = smtp->getServer().latin1();
550 ssl = smtp->getSSL(); 550 ssl = smtp->getSSL();
551 port = smtp->getPort().toUInt(); 551 port = smtp->getPort().toUInt();
552 552
553 session = mailsmtp_new( 20, &progress ); 553 session = mailsmtp_new( 20, &progress );
554 if ( session == NULL ) goto free_mem; 554 if ( session == NULL ) goto free_mem;
555 555
556 qDebug( "Servername %s at port %i", server, port ); 556 qDebug( "Servername %s at port %i", server, port );
557 if ( ssl ) { 557 if ( ssl ) {
558 qDebug( "SSL session" ); 558 qDebug( "SSL session" );
559 err = mailsmtp_ssl_connect( session, server, port ); 559 err = mailsmtp_ssl_connect( session, server, port );
560 } else { 560 } else {
561 qDebug( "No SSL session" ); 561 qDebug( "No SSL session" );
562 err = mailsmtp_socket_connect( session, server, port ); 562 err = mailsmtp_socket_connect( session, server, port );
563 } 563 }
564 if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} 564 if ( err != MAILSMTP_NO_ERROR ) {qDebug("Error init connection");result = 0;goto free_mem_session;}
565 565
566 err = mailsmtp_init( session ); 566 err = mailsmtp_init( session );
567 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} 567 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
568 568
569 qDebug( "INIT OK" ); 569 qDebug( "INIT OK" );
570 570
571 if ( smtp->getLogin() ) { 571 if ( smtp->getLogin() ) {
572 qDebug("smtp with auth");
572 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 573 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
573 // get'em 574 // get'em
574 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 575 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
575 login.show(); 576 login.show();
576 if ( QDialog::Accepted == login.exec() ) { 577 if ( QDialog::Accepted == login.exec() ) {
577 // ok 578 // ok
578 user = strdup( login.getUser().latin1() ); 579 user = login.getUser().latin1();
579 pass = strdup( login.getPassword().latin1() ); 580 pass = login.getPassword().latin1();
580 } else { 581 } else {
581 result = 0; goto free_con_session; 582 result = 0; goto free_con_session;
582 } 583 }
583 } else { 584 } else {
584 user = strdup( smtp->getUser().latin1() ); 585 user = smtp->getUser().latin1();
585 pass = strdup( smtp->getPassword().latin1() ); 586 pass = smtp->getPassword().latin1();
586 } 587 }
587 qDebug( "session->auth: %i", session->auth); 588 qDebug( "session->auth: %i", session->auth);
588 err = mailsmtp_auth( session, user, pass ); 589 err = mailsmtp_auth( session, (char*)user, (char*)pass );
589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 590 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
590 qDebug( "Done auth!" ); 591 qDebug( "Done auth!" );
592 } else {
593 qDebug("SMTP without auth");
591 } 594 }
592 595
593 err = mailsmtp_send( session, from, rcpts, data, size ); 596 err = mailsmtp_send( session, from, rcpts, data, size );
594 if ( err != MAILSMTP_NO_ERROR ) { 597 if ( err != MAILSMTP_NO_ERROR ) {
595 qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); 598 qDebug("Error sending mail: %s",mailsmtpError(err).latin1());
596 result = 0; goto free_con_session; 599 result = 0; goto free_con_session;
597 } 600 }
598 601
599 qDebug( "Mail sent." ); 602 qDebug( "Mail sent." );
600 storeMail(data,size,"Sent"); 603 storeMail(data,size,"Sent");
601 604
602free_con_session: 605free_con_session:
603 mailsmtp_quit( session ); 606 mailsmtp_quit( session );
604free_mem_session: 607free_mem_session:
605 mailsmtp_free( session ); 608 mailsmtp_free( session );
606free_mem: 609free_mem:
607 if (server) free( server );
608 if ( smtp->getLogin() ) {
609 free( user );
610 free( pass );
611 }
612 return result; 610 return result;
613} 611}
614 612
615void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) 613void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later )
616{ 614{
617 mailmime * mimeMail; 615 mailmime * mimeMail;
618 616
619 SMTPaccount *smtp = aSmtp; 617 SMTPaccount *smtp = aSmtp;
620 618
621 if (!later && !smtp) { 619 if (!later && !smtp) {
622 qDebug("Didn't get any send method - giving up"); 620 qDebug("Didn't get any send method - giving up");
623 return; 621 return;
624 } 622 }
625 mimeMail = createMimeMail(mail ); 623 mimeMail = createMimeMail(mail );
626 if ( mimeMail == NULL ) { 624 if ( mimeMail == NULL ) {
627 qDebug( "sendMail: error creating mime mail" ); 625 qDebug( "sendMail: error creating mime mail" );
628 } else { 626 } else {
629 sendProgress = new progressMailSend(); 627 sendProgress = new progressMailSend();
630 sendProgress->show(); 628 sendProgress->show();
631 sendProgress->setMaxMails(1); 629 sendProgress->setMaxMails(1);
632 smtpSend( mimeMail,later,smtp); 630 smtpSend( mimeMail,later,smtp);
633 qDebug("Clean up done"); 631 qDebug("Clean up done");
634 sendProgress->hide(); 632 sendProgress->hide();
635 delete sendProgress; 633 delete sendProgress;
636 sendProgress = 0; 634 sendProgress = 0;
637 mailmime_free( mimeMail ); 635 mailmime_free( mimeMail );
638 } 636 }
639} 637}
640 638
641int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) 639int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
642{ 640{
643 size_t curTok = 0; 641 size_t curTok = 0;
644 mailimf_fields *fields = 0; 642 mailimf_fields *fields = 0;
645 mailimf_field*ffrom = 0; 643 mailimf_field*ffrom = 0;
646 clist *rcpts = 0; 644 clist *rcpts = 0;
647 char*from = 0; 645 char*from = 0;
648 int res = 0; 646 int res = 0;
649 647
650 encodedString * data = wrap->fetchRawBody(*which); 648 encodedString * data = wrap->fetchRawBody(*which);
651 if (!data) return 0; 649 if (!data) return 0;
652 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); 650 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
653 if (err != MAILIMF_NO_ERROR) { 651 if (err != MAILIMF_NO_ERROR) {
654 delete data; 652 delete data;
655 delete wrap; 653 delete wrap;
656 return 0; 654 return 0;
657 } 655 }
658 656
659 rcpts = createRcptList( fields ); 657 rcpts = createRcptList( fields );
660 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 658 ffrom = getField(fields, MAILIMF_FIELD_FROM );
661 from = getFrom(ffrom); 659 from = getFrom(ffrom);
662 660
663 if (rcpts && from) { 661 if (rcpts && from) {
664 res = smtpSend(from,rcpts,data->Content(),data->Length(),smtp ); 662 res = smtpSend(from,rcpts,data->Content(),data->Length(),smtp );
665 } 663 }
666 if (fields) { 664 if (fields) {
667 mailimf_fields_free(fields); 665 mailimf_fields_free(fields);
668 fields = 0; 666 fields = 0;
669 } 667 }
670 if (data) { 668 if (data) {
671 delete data; 669 delete data;
672 } 670 }
673 if (from) { 671 if (from) {
674 free(from); 672 free(from);
675 } 673 }
676 if (rcpts) { 674 if (rcpts) {
677 smtp_address_list_free( rcpts ); 675 smtp_address_list_free( rcpts );
678 } 676 }
679 return res; 677 return res;
680} 678}
681 679
682/* this is a special fun */ 680/* this is a special fun */
683bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) 681bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
684{ 682{
685 bool returnValue = true; 683 bool returnValue = true;
686 684
687 if (!smtp) return false; 685 if (!smtp) return false;
688 686
689 QString localfolders = AbstractMail::defaultLocalfolder(); 687 QString localfolders = AbstractMail::defaultLocalfolder();
690 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 688 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
691 if (!wrap) { 689 if (!wrap) {
692 qDebug("memory error"); 690 qDebug("memory error");
693 return false; 691 return false;
694 } 692 }
695 QList<RecMail> mailsToSend; 693 QList<RecMail> mailsToSend;
696 QList<RecMail> mailsToRemove; 694 QList<RecMail> mailsToRemove;
697 QString mbox("Outgoing"); 695 QString mbox("Outgoing");
698 wrap->listMessages(mbox,mailsToSend); 696 wrap->listMessages(mbox,mailsToSend);
699 if (mailsToSend.count()==0) { 697 if (mailsToSend.count()==0) {
700 delete wrap; 698 delete wrap;
701 return false; 699 return false;
702 } 700 }
703 mailsToSend.setAutoDelete(false); 701 mailsToSend.setAutoDelete(false);
704 sendProgress = new progressMailSend(); 702 sendProgress = new progressMailSend();
705 sendProgress->show(); 703 sendProgress->show();
706 sendProgress->setMaxMails(mailsToSend.count()); 704 sendProgress->setMaxMails(mailsToSend.count());
707 705