diff options
Diffstat (limited to 'examples/mailtransportresource/mailtransport.cpp')
-rw-r--r-- | examples/mailtransportresource/mailtransport.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/examples/mailtransportresource/mailtransport.cpp b/examples/mailtransportresource/mailtransport.cpp index ce24d7f..c455b7c 100644 --- a/examples/mailtransportresource/mailtransport.cpp +++ b/examples/mailtransportresource/mailtransport.cpp | |||
@@ -83,7 +83,7 @@ CurlVersionInfo getVersionInfo() | |||
83 | bool sendMessageCurl(const char *to[], int numTos, | 83 | bool sendMessageCurl(const char *to[], int numTos, |
84 | const char *cc[], int numCcs, | 84 | const char *cc[], int numCcs, |
85 | const char *msg, | 85 | const char *msg, |
86 | bool useTls, | 86 | bool useStarttls, |
87 | const char* from, | 87 | const char* from, |
88 | const char *username, const char *password, | 88 | const char *username, const char *password, |
89 | const char *server, bool verifyPeer, const QByteArray &cacert, QByteArray &errorMessage, | 89 | const char *server, bool verifyPeer, const QByteArray &cacert, QByteArray &errorMessage, |
@@ -107,7 +107,7 @@ bool sendMessageCurl(const char *to[], int numTos, | |||
107 | 107 | ||
108 | curl_easy_setopt(curl, CURLOPT_URL, server); | 108 | curl_easy_setopt(curl, CURLOPT_URL, server); |
109 | 109 | ||
110 | if (useTls) { | 110 | if (useStarttls) { |
111 | curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); | 111 | curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL); |
112 | } | 112 | } |
113 | 113 | ||
@@ -186,6 +186,7 @@ MailTransport::SendResult MailTransport::sendMessage(const KMime::Message::Ptr & | |||
186 | ccList << mb.address(); | 186 | ccList << mb.address(); |
187 | } | 187 | } |
188 | const bool verifyPeer = options.testFlag(VerifyPeers); | 188 | const bool verifyPeer = options.testFlag(VerifyPeers); |
189 | const bool useStarttls = options.testFlag(UseStarttls); | ||
189 | const bool useTls = options.testFlag(UseTls); | 190 | const bool useTls = options.testFlag(UseTls); |
190 | 191 | ||
191 | const int numTos = toList.size(); | 192 | const int numTos = toList.size(); |
@@ -199,12 +200,21 @@ MailTransport::SendResult MailTransport::sendMessage(const KMime::Message::Ptr & | |||
199 | for (int i = 0; i < numCcs; i++) { | 200 | for (int i = 0; i < numCcs; i++) { |
200 | cc[i] = ccList.at(i); | 201 | cc[i] = ccList.at(i); |
201 | } | 202 | } |
202 | //Because curl will fail with smtps, but it won't tell you why. | ||
203 | auto serverAddress = server; | 203 | auto serverAddress = server; |
204 | serverAddress.replace("smtps://", "smtp://"); | 204 | if (serverAddress.startsWith("smtps://")) { |
205 | serverAddress = serverAddress.mid(8); | ||
206 | } | ||
207 | if (serverAddress.startsWith("smtp://")) { | ||
208 | serverAddress = serverAddress.mid(7); | ||
209 | } | ||
210 | if (useStarttls) { | ||
211 | serverAddress = "smtp://" + serverAddress; | ||
212 | } else if (useTls) { | ||
213 | serverAddress = "smtps://" + serverAddress; | ||
214 | } | ||
205 | 215 | ||
206 | const auto versionInfo = getVersionInfo(); | 216 | const auto versionInfo = getVersionInfo(); |
207 | if (useTls && !versionInfo.supportsSsl) { | 217 | if ((useTls || useStarttls) && !versionInfo.supportsSsl) { |
208 | qCWarning(mailtransportCategory) << "libcurl built without ssl support: " << versionInfo.info; | 218 | qCWarning(mailtransportCategory) << "libcurl built without ssl support: " << versionInfo.info; |
209 | } | 219 | } |
210 | 220 | ||
@@ -212,7 +222,7 @@ MailTransport::SendResult MailTransport::sendMessage(const KMime::Message::Ptr & | |||
212 | QByteArray errorMessage; | 222 | QByteArray errorMessage; |
213 | auto ret = sendMessageCurl(to, numTos, cc, numCcs, | 223 | auto ret = sendMessageCurl(to, numTos, cc, numCcs, |
214 | message->encodedContent(), | 224 | message->encodedContent(), |
215 | useTls, | 225 | useStarttls, |
216 | from.isEmpty() ? nullptr : from, | 226 | from.isEmpty() ? nullptr : from, |
217 | username, password, | 227 | username, password, |
218 | serverAddress, verifyPeer, cacert, | 228 | serverAddress, verifyPeer, cacert, |