From bd1622c27e744971b8fc70b90e9c9d175acec2f2 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 10 Apr 2016 11:00:57 +0200 Subject: Use the MailtransportResource for mailtransport. --- framework/domain/actions/sinkactions.cpp | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'framework/domain/actions/sinkactions.cpp') diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index 57d63752..dea6fc72 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp @@ -19,6 +19,9 @@ #include #include +#include +#include + #include using namespace Kube; @@ -70,6 +73,46 @@ static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize" } ); +static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", + [](Context *context) -> bool { + auto accountId = context->property("accountId").value(); + auto message = context->property("message").value(); + return !accountId.isEmpty() && message; + }, + [](Context *context) { + auto accountId = context->property("accountId").value(); + //For ssl use "smtps://mainserver.example.net + // QByteArray cacert; // = "/path/to/certificate.pem"; + auto message = context->property("message").value(); + auto mimeMessage = Sink::Store::getTemporaryFilePath(); + QFile file(mimeMessage); + if (!file.open(QIODevice::ReadWrite)) { + qWarning() << "Failed to open the file: " << file.errorString() << mimeMessage; + return; + } + file.write(message->encodedContent()); + qWarning() << "Sending a mail: "; + + Sink::Query query; + query += Sink::Query::PropertyFilter("type", "org.kde.mailtransport"); + query += Sink::Query::PropertyFilter("account", QVariant::fromValue(accountId)); + Sink::Store::fetchAll(query) + .then>([=](const QList &resources) { + if (resources.isEmpty()) { + qWarning() << "Failed to find a mailtransport resource"; + } else { + auto resourceId = resources[0]->identifier(); + qDebug() << "Sending message via resource: " << resourceId; + Sink::ApplicationDomain::Mail mail(resourceId); + mail.setProperty("mimeMessage", mimeMessage); + Sink::Store::create(mail).exec(); + // return Sink::Store::create(mail); + } + return KAsync::error(0, "Failed to find a MailTransport resource."); + }).exec(); + } +); + // static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", // [](Context *context) -> bool { // return context->property("mail").isValid(); -- cgit v1.2.3