diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-25 14:43:07 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-25 14:43:07 +0100 |
commit | 31dbe72afb5e04cd86d4f107e7257fb60aaa087b (patch) | |
tree | 9df6ad125f80d74fb720a1994415c0c279c5f902 /examples/mailtransportresource/mailtransport.cpp | |
parent | 102bb38ed89da2295a01d707db954e47a6cb8d7d (diff) | |
download | sink-31dbe72afb5e04cd86d4f107e7257fb60aaa087b.tar.gz sink-31dbe72afb5e04cd86d4f107e7257fb60aaa087b.zip |
Do the logging in the resource code.
Diffstat (limited to 'examples/mailtransportresource/mailtransport.cpp')
-rw-r--r-- | examples/mailtransportresource/mailtransport.cpp | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/examples/mailtransportresource/mailtransport.cpp b/examples/mailtransportresource/mailtransport.cpp index afe0257..65299a2 100644 --- a/examples/mailtransportresource/mailtransport.cpp +++ b/examples/mailtransportresource/mailtransport.cpp | |||
@@ -21,7 +21,6 @@ | |||
21 | #include <QByteArray> | 21 | #include <QByteArray> |
22 | #include <QList> | 22 | #include <QList> |
23 | #include <QDebug> | 23 | #include <QDebug> |
24 | #include <common/log.h> | ||
25 | 24 | ||
26 | extern "C" { | 25 | extern "C" { |
27 | 26 | ||
@@ -142,13 +141,14 @@ bool sendMessageCurl(const char *to[], int numTos, const char *cc[], int numCcs, | |||
142 | 141 | ||
143 | res = curl_easy_perform(curl); | 142 | res = curl_easy_perform(curl); |
144 | if(res != CURLE_OK) { | 143 | if(res != CURLE_OK) { |
144 | errorMessage += "Error code: " + QByteArray::number(res) + ", "; | ||
145 | errorMessage += curl_easy_strerror(res); | 145 | errorMessage += curl_easy_strerror(res); |
146 | errorMessage += "; "; | 146 | errorMessage += "; "; |
147 | } | 147 | } |
148 | long http_code = 0; | 148 | long http_code = 0; |
149 | curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code); | 149 | curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code); |
150 | if (http_code == 200 && res != CURLE_ABORTED_BY_CALLBACK) { | 150 | if (http_code == 200 && res != CURLE_ABORTED_BY_CALLBACK) { |
151 | //Succeeded | 151 | //Succeeded |
152 | } else { | 152 | } else { |
153 | errorMessage += errorBuffer; | 153 | errorMessage += errorBuffer; |
154 | } | 154 | } |
@@ -161,10 +161,8 @@ bool sendMessageCurl(const char *to[], int numTos, const char *cc[], int numCcs, | |||
161 | 161 | ||
162 | }; | 162 | }; |
163 | 163 | ||
164 | bool MailTransport::sendMessage(const KMime::Message::Ptr &message, const QByteArray &server, const QByteArray &username, const QByteArray &password, const QByteArray &cacert, MailTransport::Options options) | 164 | MailTransport::SendResult MailTransport::sendMessage(const KMime::Message::Ptr &message, const QByteArray &server, const QByteArray &username, const QByteArray &password, const QByteArray &cacert, MailTransport::Options options) |
165 | { | 165 | { |
166 | QByteArray msg = message->encodedContent(); | ||
167 | |||
168 | QByteArray from(message->from(true)->mailboxes().isEmpty() ? QByteArray() : message->from(true)->mailboxes().first().address()); | 166 | QByteArray from(message->from(true)->mailboxes().isEmpty() ? QByteArray() : message->from(true)->mailboxes().first().address()); |
169 | QList<QByteArray> toList; | 167 | QList<QByteArray> toList; |
170 | for (const auto &mb : message->to(true)->mailboxes()) { | 168 | for (const auto &mb : message->to(true)->mailboxes()) { |
@@ -177,9 +175,6 @@ bool MailTransport::sendMessage(const KMime::Message::Ptr &message, const QByteA | |||
177 | const bool verifyPeer = options.testFlag(VerifyPeers); | 175 | const bool verifyPeer = options.testFlag(VerifyPeers); |
178 | const bool useTls = options.testFlag(UseTls); | 176 | const bool useTls = options.testFlag(UseTls); |
179 | 177 | ||
180 | SinkLog() << "Sending message " << server << username << password << "CaCert: " << cacert << "Use tls: " << useTls << " Verify peer: " << verifyPeer; | ||
181 | SinkTrace() << "Sending message " << msg; | ||
182 | |||
183 | const int numTos = toList.size(); | 178 | const int numTos = toList.size(); |
184 | const char* to[numTos]; | 179 | const char* to[numTos]; |
185 | for (int i = 0; i < numTos; i++) { | 180 | for (int i = 0; i < numTos; i++) { |
@@ -196,9 +191,6 @@ bool MailTransport::sendMessage(const KMime::Message::Ptr &message, const QByteA | |||
196 | serverAddress.replace("smtps://", "smtp://"); | 191 | serverAddress.replace("smtps://", "smtp://"); |
197 | 192 | ||
198 | QByteArray errorMessage; | 193 | QByteArray errorMessage; |
199 | auto ret = sendMessageCurl(to, numTos, cc, numCcs, msg, useTls, from.isEmpty() ? nullptr : from, username, password, serverAddress, verifyPeer, cacert, errorMessage); | 194 | auto ret = sendMessageCurl(to, numTos, cc, numCcs, message->encodedContent(), useTls, from.isEmpty() ? nullptr : from, username, password, serverAddress, verifyPeer, cacert, errorMessage); |
200 | if (!ret) { | 195 | return {ret, errorMessage}; |
201 | SinkWarning() << "Failed to send message: " << errorMessage; | ||
202 | } | ||
203 | return ret; | ||
204 | } | 196 | } |