diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-17 20:22:02 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-17 20:22:02 +0100 |
commit | f1821355a7c034b201e454e2bfd7da5ac6b64579 (patch) | |
tree | 9c7dc75f967cec86d9d92c0baa93eeacb908a20f /examples | |
parent | f83893e4a840cbe77b08bdf09a384b6d22ed1d1c (diff) | |
download | sink-f1821355a7c034b201e454e2bfd7da5ac6b64579.tar.gz sink-f1821355a7c034b201e454e2bfd7da5ac6b64579.zip |
Also try to send the mail on changereplay.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/mailtransportresource/mailtransportresource.cpp | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index 4dc9567..0118140 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp | |||
@@ -55,38 +55,37 @@ public: | |||
55 | 55 | ||
56 | KAsync::Job<void> send(const ApplicationDomain::Mail &mail, const MailtransportResource::Settings &settings) | 56 | KAsync::Job<void> send(const ApplicationDomain::Mail &mail, const MailtransportResource::Settings &settings) |
57 | { | 57 | { |
58 | if (!syncStore().readValue(mail.identifier()).isEmpty()) { | 58 | return KAsync::start<void>([=] { |
59 | SinkLog() << "Mail is already sent: " << mail.identifier(); | 59 | if (!syncStore().readValue(mail.identifier()).isEmpty()) { |
60 | return KAsync::null(); | 60 | SinkLog() << "Mail is already sent: " << mail.identifier(); |
61 | } | 61 | return KAsync::null(); |
62 | const auto data = mail.getMimeMessage(); | ||
63 | auto msg = KMime::Message::Ptr::create(); | ||
64 | msg->setHead(KMime::CRLFtoLF(data)); | ||
65 | msg->parse(); | ||
66 | if (settings.testMode) { | ||
67 | SinkLog() << "I would totally send that mail, but I'm in test mode." << mail.identifier(); | ||
68 | auto path = resourceStorageLocation(mResourceInstanceIdentifier) + "/test/"; | ||
69 | SinkTrace() << path; | ||
70 | QDir dir; | ||
71 | dir.mkpath(path); | ||
72 | QFile f(path+ mail.identifier()); | ||
73 | f.open(QIODevice::ReadWrite); | ||
74 | f.write("foo"); | ||
75 | f.close(); | ||
76 | } else { | ||
77 | MailTransport::Options options; | ||
78 | if (settings.server.contains("smtps")) { | ||
79 | options &= MailTransport::UseTls; | ||
80 | } | 62 | } |
81 | if (MailTransport::sendMessage(msg, settings.server.toUtf8(), settings.username.toUtf8(), settings.password.toUtf8(), settings.cacert.toUtf8(), options)) { | 63 | const auto data = mail.getMimeMessage(); |
82 | SinkLog() << "Sent message successfully"; | 64 | auto msg = KMime::Message::Ptr::create(); |
65 | msg->setHead(KMime::CRLFtoLF(data)); | ||
66 | msg->parse(); | ||
67 | if (settings.testMode) { | ||
68 | SinkLog() << "I would totally send that mail, but I'm in test mode." << mail.identifier(); | ||
69 | auto path = resourceStorageLocation(mResourceInstanceIdentifier) + "/test/"; | ||
70 | SinkTrace() << path; | ||
71 | QDir dir; | ||
72 | dir.mkpath(path); | ||
73 | QFile f(path+ mail.identifier()); | ||
74 | f.open(QIODevice::ReadWrite); | ||
75 | f.write("foo"); | ||
76 | f.close(); | ||
83 | } else { | 77 | } else { |
84 | SinkLog() << "Failed to send message"; | 78 | MailTransport::Options options; |
85 | return KAsync::error<void>(1, "Failed to send the message."); | 79 | if (settings.server.contains("smtps")) { |
80 | options &= MailTransport::UseTls; | ||
81 | } | ||
82 | if (!MailTransport::sendMessage(msg, settings.server.toUtf8(), settings.username.toUtf8(), settings.password.toUtf8(), settings.cacert.toUtf8(), options)) { | ||
83 | SinkWarning() << "Failed to send message: " << mail; | ||
84 | return KAsync::error("Failed to send the message."); | ||
85 | } | ||
86 | } | 86 | } |
87 | } | 87 | syncStore().writeValue(mail.identifier(), "sent"); |
88 | syncStore().writeValue(mail.identifier(), "sent"); | 88 | |
89 | return KAsync::start<void>([=] { | ||
90 | SinkLog() << "Sent mail, and triggering move to sent mail folder: " << mail.identifier(); | 89 | SinkLog() << "Sent mail, and triggering move to sent mail folder: " << mail.identifier(); |
91 | auto modifiedMail = ApplicationDomain::Mail(mResourceInstanceIdentifier, mail.identifier(), mail.revision(), QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 90 | auto modifiedMail = ApplicationDomain::Mail(mResourceInstanceIdentifier, mail.identifier(), mail.revision(), QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); |
92 | modifiedMail.setSent(true); | 91 | modifiedMail.setSent(true); |
@@ -128,14 +127,15 @@ public: | |||
128 | 127 | ||
129 | bool canReplay(const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE | 128 | bool canReplay(const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE |
130 | { | 129 | { |
131 | return false; | 130 | return true; |
132 | } | 131 | } |
133 | 132 | ||
134 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE | 133 | KAsync::Job<QByteArray> replay(const ApplicationDomain::Mail &mail, Sink::Operation operation, const QByteArray &oldRemoteId, const QList<QByteArray> &changedProperties) Q_DECL_OVERRIDE |
135 | { | 134 | { |
136 | if (operation == Sink::Operation_Creation) { | 135 | if (operation == Sink::Operation_Creation) { |
137 | SinkTrace() << "Dispatching message."; | 136 | SinkTrace() << "Dispatching message."; |
138 | // return send(mail, mSettings); | 137 | return send(mail, mSettings) |
138 | .then(KAsync::value(QByteArray{})); | ||
139 | } else if (operation == Sink::Operation_Removal) { | 139 | } else if (operation == Sink::Operation_Removal) { |
140 | syncStore().removeValue(mail.identifier(), ""); | 140 | syncStore().removeValue(mail.identifier(), ""); |
141 | } else if (operation == Sink::Operation_Modification) { | 141 | } else if (operation == Sink::Operation_Modification) { |