From 48cb4a237e92ead33fa32b120c503bcbb1dafce5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 13 Jan 2017 11:23:50 +0100 Subject: Avoid sending the mail twice --- examples/mailtransportresource/mailtransportresource.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index a49d62b..4dc9567 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp @@ -53,8 +53,12 @@ public: } - KAsync::Jobsend(const ApplicationDomain::Mail &mail, const MailtransportResource::Settings &settings) + KAsync::Job send(const ApplicationDomain::Mail &mail, const MailtransportResource::Settings &settings) { + if (!syncStore().readValue(mail.identifier()).isEmpty()) { + SinkLog() << "Mail is already sent: " << mail.identifier(); + return KAsync::null(); + } const auto data = mail.getMimeMessage(); auto msg = KMime::Message::Ptr::create(); msg->setHead(KMime::CRLFtoLF(data)); @@ -81,6 +85,7 @@ public: return KAsync::error(1, "Failed to send the message."); } } + syncStore().writeValue(mail.identifier(), "sent"); return KAsync::start([=] { SinkLog() << "Sent mail, and triggering move to sent mail folder: " << mail.identifier(); auto modifiedMail = ApplicationDomain::Mail(mResourceInstanceIdentifier, mail.identifier(), mail.revision(), QSharedPointer::create()); @@ -132,6 +137,7 @@ public: SinkTrace() << "Dispatching message."; // return send(mail, mSettings); } else if (operation == Sink::Operation_Removal) { + syncStore().removeValue(mail.identifier(), ""); } else if (operation == Sink::Operation_Modification) { } return KAsync::null(); -- cgit v1.2.3