-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 55 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 13 |
2 files changed, 60 insertions, 8 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 | |||
@@ -60,4 +60,6 @@ QString SMTPwrapper::mailsmtpError( int errnum ) { | |||
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" ); |
@@ -566,4 +568,27 @@ void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char* | |||
566 | } | 568 | } |
567 | 569 | ||
570 | int 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 | |||
568 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) { | 593 | int 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; |
@@ -581,7 +606,12 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT | |||
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 | ||
@@ -609,4 +639,5 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT | |||
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 ); |
@@ -617,4 +648,18 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT | |||
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"); |
@@ -738,6 +783,9 @@ bool 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; |
@@ -755,7 +803,8 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { | |||
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 | ||
760 | oldPw = smtp->getPassword(); | 809 | oldPw = smtp->getPassword(); |
761 | oldUser = smtp->getUser(); | 810 | oldUser = smtp->getUser(); |
@@ -777,5 +826,5 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { | |||
777 | } | 826 | } |
778 | 827 | ||
779 | 828 | ||
780 | mailsToSend.setAutoDelete(false); | 829 | mailsToSend.setAutoDelete(false); |
781 | sendProgress = new progressMailSend(); | 830 | sendProgress = new progressMailSend(); |
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 | |||
@@ -20,4 +20,5 @@ struct mailmime; | |||
20 | struct mailimf_address_list; | 20 | struct mailimf_address_list; |
21 | class progressMailSend; | 21 | class progressMailSend; |
22 | struct mailsmtp; | ||
22 | 23 | ||
23 | class SMTPwrapper : public QObject | 24 | class SMTPwrapper : public QObject |
@@ -26,5 +27,5 @@ class SMTPwrapper : public QObject | |||
26 | 27 | ||
27 | public: | 28 | public: |
28 | SMTPwrapper( Settings *s ); | 29 | SMTPwrapper( Settings *s ); |
29 | virtual ~SMTPwrapper(){} | 30 | virtual ~SMTPwrapper(){} |
30 | void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); | 31 | void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); |
@@ -34,5 +35,5 @@ public: | |||
34 | 35 | ||
35 | signals: | 36 | signals: |
36 | void queuedMails( int ); | 37 | void queuedMails( int ); |
37 | 38 | ||
38 | protected: | 39 | protected: |
@@ -40,5 +41,5 @@ protected: | |||
40 | mailimf_fields *createImfFields(const Mail &mail ); | 41 | mailimf_fields *createImfFields(const Mail &mail ); |
41 | mailmime *createMimeMail(const Mail&mail ); | 42 | mailmime *createMimeMail(const Mail&mail ); |
42 | 43 | ||
43 | mailimf_address_list *parseAddresses(const QString&addr ); | 44 | mailimf_address_list *parseAddresses(const QString&addr ); |
44 | void addFileParts( mailmime *message,const QList<Attachment>&files ); | 45 | void addFileParts( mailmime *message,const QList<Attachment>&files ); |
@@ -47,5 +48,5 @@ protected: | |||
47 | void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); | 48 | void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); |
48 | clist *createRcptList( mailimf_fields *fields ); | 49 | clist *createRcptList( mailimf_fields *fields ); |
49 | 50 | ||
50 | static void storeMail(const char*mail, size_t length, const QString&box); | 51 | static void storeMail(const char*mail, size_t length, const QString&box); |
51 | static QString mailsmtpError( int err ); | 52 | static QString mailsmtpError( int err ); |
@@ -55,9 +56,11 @@ protected: | |||
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); |
60 | Settings *settings; | 63 | Settings *settings; |
61 | 64 | ||
62 | int sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which); | 65 | int sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which); |
63 | void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); | 66 | void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); |