summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp51
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h3
2 files changed, 53 insertions, 1 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index e8db9ca..3ab6b77 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -59,6 +59,8 @@ QString SMTPwrapper::mailsmtpError( int errnum ) {
59 return tr( "Data exceeds storage allocation" ); 59 return tr( "Data exceeds storage allocation" );
60 case MAILSMTP_ERROR_IN_PROCESSING: 60 case MAILSMTP_ERROR_IN_PROCESSING:
61 return tr( "Error in processing" ); 61 return tr( "Error in processing" );
62 case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED:
63 return tr( "Starttls not supported" );
62 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 64 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
63 // return tr( "Insufficient system storage" ); 65 // return tr( "Insufficient system storage" );
64 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 66 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
@@ -565,6 +567,29 @@ void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*
565 } 567 }
566} 568}
567 569
570int SMTPwrapper::start_smtp_tls(mailsmtp *session)
571{
572 if (!session) {
573 return MAILSMTP_ERROR_IN_PROCESSING;
574 }
575 int err = mailesmtp_starttls(session);
576 if (err != MAILSMTP_NO_ERROR) return err;
577 mailstream_low * low;
578 mailstream_low * new_low;
579 low = mailstream_get_low(session->stream);
580 if (!low) {
581 return MAILSMTP_ERROR_IN_PROCESSING;
582 }
583 int fd = mailstream_low_get_fd(low);
584 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
585 mailstream_low_free(low);
586 mailstream_set_low(session->stream, new_low);
587 } else {
588 return MAILSMTP_ERROR_IN_PROCESSING;
589 }
590 return err;
591}
592
568int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) { 593int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) {
569 const char *server, *user, *pass; 594 const char *server, *user, *pass;
570 bool ssl; 595 bool ssl;
@@ -580,9 +605,14 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
580 // FIXME: currently only TLS and Plain work. 605 // FIXME: currently only TLS and Plain work.
581 606
582 ssl = false; 607 ssl = false;
608 bool try_tls = true;
609 bool force_tls=false;
583 610
584 if ( smtp->ConnectionType() == 2 ) { 611 if ( smtp->ConnectionType() == 2 ) {
585 ssl = true; 612 ssl = true;
613 try_tls = false;
614 } else if (smtp->ConnectionType() == 1) {
615 force_tls = true;
586 } 616 }
587 617
588 port = smtp->getPort().toUInt(); 618 port = smtp->getPort().toUInt();
@@ -608,6 +638,7 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
608 result = 0; 638 result = 0;
609 } 639 }
610 640
641 /* switch to tls after init 'cause there it will send the ehlo */
611 if (result) { 642 if (result) {
612 err = mailsmtp_init( session ); 643 err = mailsmtp_init( session );
613 if (err != MAILSMTP_NO_ERROR) { 644 if (err != MAILSMTP_NO_ERROR) {
@@ -616,6 +647,20 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
616 } 647 }
617 } 648 }
618 649
650 if (try_tls) {
651 err = start_smtp_tls(session);
652 if (err != MAILSMTP_NO_ERROR) {
653 try_tls = false;
654 } else {
655 err = mailesmtp_ehlo(session);
656 }
657 }
658
659 if (!try_tls && force_tls) {
660 result = 0;
661 failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err));
662 }
663
619 if (result==1 && smtp->getLogin() ) { 664 if (result==1 && smtp->getLogin() ) {
620 qDebug("smtp with auth"); 665 qDebug("smtp with auth");
621 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 666 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
@@ -737,8 +782,11 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which
737bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { 782bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
738 bool returnValue = true; 783 bool returnValue = true;
739 784
740 if (!smtp) 785 qDebug("Sending the queue");
786 if (!smtp) {
787 qDebug("No smtp account given");
741 return false; 788 return false;
789 }
742 790
743 bool reset_user_value = false; 791 bool reset_user_value = false;
744 QString localfolders = AbstractMail::defaultLocalfolder(); 792 QString localfolders = AbstractMail::defaultLocalfolder();
@@ -754,6 +802,7 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
754 wrap->listMessages(mbox,mailsToSend); 802 wrap->listMessages(mbox,mailsToSend);
755 if (mailsToSend.count()==0) { 803 if (mailsToSend.count()==0) {
756 delete wrap; 804 delete wrap;
805 qDebug("No mails to send");
757 return false; 806 return false;
758 } 807 }
759 808
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h
index 89826d9..75e4891 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h
@@ -19,6 +19,7 @@ struct mailimf_mailbox;
19struct mailmime; 19struct mailmime;
20struct mailimf_address_list; 20struct mailimf_address_list;
21class progressMailSend; 21class progressMailSend;
22struct mailsmtp;
22 23
23class SMTPwrapper : public QObject 24class SMTPwrapper : public QObject
24{ 25{
@@ -54,6 +55,8 @@ protected:
54 static char *getFrom( mailmime *mail ); 55 static char *getFrom( mailmime *mail );
55 static char *getFrom( mailimf_field *ffrom); 56 static char *getFrom( mailimf_field *ffrom);
56 static mailimf_field *getField( mailimf_fields *fields, int type ); 57 static mailimf_field *getField( mailimf_fields *fields, int type );
58 static int start_smtp_tls(mailsmtp *session);
59
57 int smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ); 60 int smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp );
58 61
59 void storeMail(mailmime*mail, const QString&box); 62 void storeMail(mailmime*mail, const QString&box);