summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (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 ) {
return tr( "Data exceeds storage allocation" );
case MAILSMTP_ERROR_IN_PROCESSING:
return tr( "Error in processing" );
+ case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED:
+ return tr( "Starttls not supported" );
// case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
// return tr( "Insufficient system storage" );
case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
@@ -565,6 +567,29 @@ 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 ) {
const char *server, *user, *pass;
bool ssl;
@@ -580,9 +605,14 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
// FIXME: currently only TLS and Plain work.
ssl = false;
+ bool try_tls = true;
+ bool force_tls=false;
if ( smtp->ConnectionType() == 2 ) {
ssl = true;
+ try_tls = false;
+ } else if (smtp->ConnectionType() == 1) {
+ force_tls = true;
}
port = smtp->getPort().toUInt();
@@ -608,6 +638,7 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
result = 0;
}
+ /* switch to tls after init 'cause there it will send the ehlo */
if (result) {
err = mailsmtp_init( session );
if (err != MAILSMTP_NO_ERROR) {
@@ -616,6 +647,20 @@ 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() ) {
qDebug("smtp with auth");
if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
@@ -737,8 +782,11 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which
bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
bool returnValue = true;
- if (!smtp)
+ qDebug("Sending the queue");
+ if (!smtp) {
+ qDebug("No smtp account given");
return false;
+ }
bool reset_user_value = false;
QString localfolders = AbstractMail::defaultLocalfolder();
@@ -754,6 +802,7 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
wrap->listMessages(mbox,mailsToSend);
if (mailsToSend.count()==0) {
delete wrap;
+ qDebug("No mails to send");
return 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
@@ -19,6 +19,7 @@ struct mailimf_mailbox;
struct mailmime;
struct mailimf_address_list;
class progressMailSend;
+struct mailsmtp;
class SMTPwrapper : public QObject
{
@@ -54,6 +55,8 @@ protected:
static char *getFrom( mailmime *mail );
static char *getFrom( mailimf_field *ffrom);
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 );
void storeMail(mailmime*mail, const QString&box);