summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp55
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h13
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
@@ -61,2 +61,4 @@ QString SMTPwrapper::mailsmtpError( int errnum ) {
return tr( "Error in processing" );
+ case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED:
+ return tr( "Starttls not supported" );
// case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
@@ -567,2 +569,25 @@ void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*
+int SMTPwrapper::start_smtp_tls(mailsmtp *session)
+{
+ if (!session) {
+ return MAILSMTP_ERROR_IN_PROCESSING;
+ }
+ int err = mailesmtp_starttls(session);
+ if (err != MAILSMTP_NO_ERROR) return err;
+ mailstream_low * low;
+ mailstream_low * new_low;
+ low = mailstream_get_low(session->stream);
+ if (!low) {
+ return MAILSMTP_ERROR_IN_PROCESSING;
+ }
+ int fd = mailstream_low_get_fd(low);
+ if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
+ mailstream_low_free(low);
+ mailstream_set_low(session->stream, new_low);
+ } else {
+ return MAILSMTP_ERROR_IN_PROCESSING;
+ }
+ return err;
+}
+
int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) {
@@ -582,2 +607,4 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
ssl = false;
+ bool try_tls = true;
+ bool force_tls=false;
@@ -585,2 +612,5 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
ssl = true;
+ try_tls = false;
+ } else if (smtp->ConnectionType() == 1) {
+ force_tls = true;
}
@@ -610,2 +640,3 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
+ /* switch to tls after init 'cause there it will send the ehlo */
if (result) {
@@ -618,2 +649,16 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
+ if (try_tls) {
+ err = start_smtp_tls(session);
+ if (err != MAILSMTP_NO_ERROR) {
+ try_tls = false;
+ } else {
+ err = mailesmtp_ehlo(session);
+ }
+ }
+
+ if (!try_tls && force_tls) {
+ result = 0;
+ failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err));
+ }
+
if (result==1 && smtp->getLogin() ) {
@@ -739,4 +784,7 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
- if (!smtp)
+ qDebug("Sending the queue");
+ if (!smtp) {
+ qDebug("No smtp account given");
return false;
+ }
@@ -756,5 +804,6 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
delete wrap;
+ qDebug("No mails to send");
return false;
}
-
+
oldPw = smtp->getPassword();
@@ -778,3 +827,3 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
-
+
mailsToSend.setAutoDelete(false);
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
@@ -21,2 +21,3 @@ struct mailimf_address_list;
class progressMailSend;
+struct mailsmtp;
@@ -27,3 +28,3 @@ class SMTPwrapper : public QObject
public:
- SMTPwrapper( Settings *s );
+ SMTPwrapper( Settings *s );
virtual ~SMTPwrapper(){}
@@ -35,3 +36,3 @@ public:
signals:
- void queuedMails( int );
+ void queuedMails( int );
@@ -41,3 +42,3 @@ protected:
mailmime *createMimeMail(const Mail&mail );
-
+
mailimf_address_list *parseAddresses(const QString&addr );
@@ -48,3 +49,3 @@ protected:
clist *createRcptList( mailimf_fields *fields );
-
+
static void storeMail(const char*mail, size_t length, const QString&box);
@@ -56,2 +57,4 @@ protected:
static mailimf_field *getField( mailimf_fields *fields, int type );
+ static int start_smtp_tls(mailsmtp *session);
+
int smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp );
@@ -60,3 +63,3 @@ protected:
Settings *settings;
-
+
int sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which);