diff options
Diffstat (limited to 'framework/domain/actions/sinkactions.cpp')
-rw-r--r-- | framework/domain/actions/sinkactions.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
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 @@ | |||
19 | #include <actions/context.h> | 19 | #include <actions/context.h> |
20 | #include <actions/actionhandler.h> | 20 | #include <actions/actionhandler.h> |
21 | 21 | ||
22 | #include <KMime/Message> | ||
23 | #include <QFile> | ||
24 | |||
22 | #include <sink/store.h> | 25 | #include <sink/store.h> |
23 | 26 | ||
24 | using namespace Kube; | 27 | using namespace Kube; |
@@ -70,6 +73,46 @@ static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize" | |||
70 | } | 73 | } |
71 | ); | 74 | ); |
72 | 75 | ||
76 | static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", | ||
77 | [](Context *context) -> bool { | ||
78 | auto accountId = context->property("accountId").value<QByteArray>(); | ||
79 | auto message = context->property("message").value<KMime::Message::Ptr>(); | ||
80 | return !accountId.isEmpty() && message; | ||
81 | }, | ||
82 | [](Context *context) { | ||
83 | auto accountId = context->property("accountId").value<QByteArray>(); | ||
84 | //For ssl use "smtps://mainserver.example.net | ||
85 | // QByteArray cacert; // = "/path/to/certificate.pem"; | ||
86 | auto message = context->property("message").value<KMime::Message::Ptr>(); | ||
87 | auto mimeMessage = Sink::Store::getTemporaryFilePath(); | ||
88 | QFile file(mimeMessage); | ||
89 | if (!file.open(QIODevice::ReadWrite)) { | ||
90 | qWarning() << "Failed to open the file: " << file.errorString() << mimeMessage; | ||
91 | return; | ||
92 | } | ||
93 | file.write(message->encodedContent()); | ||
94 | qWarning() << "Sending a mail: "; | ||
95 | |||
96 | Sink::Query query; | ||
97 | query += Sink::Query::PropertyFilter("type", "org.kde.mailtransport"); | ||
98 | query += Sink::Query::PropertyFilter("account", QVariant::fromValue(accountId)); | ||
99 | Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(query) | ||
100 | .then<void, QList<Sink::ApplicationDomain::SinkResource::Ptr>>([=](const QList<Sink::ApplicationDomain::SinkResource::Ptr> &resources) { | ||
101 | if (resources.isEmpty()) { | ||
102 | qWarning() << "Failed to find a mailtransport resource"; | ||
103 | } else { | ||
104 | auto resourceId = resources[0]->identifier(); | ||
105 | qDebug() << "Sending message via resource: " << resourceId; | ||
106 | Sink::ApplicationDomain::Mail mail(resourceId); | ||
107 | mail.setProperty("mimeMessage", mimeMessage); | ||
108 | Sink::Store::create(mail).exec(); | ||
109 | // return Sink::Store::create(mail); | ||
110 | } | ||
111 | return KAsync::error<void>(0, "Failed to find a MailTransport resource."); | ||
112 | }).exec(); | ||
113 | } | ||
114 | ); | ||
115 | |||
73 | // static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", | 116 | // static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", |
74 | // [](Context *context) -> bool { | 117 | // [](Context *context) -> bool { |
75 | // return context->property("mail").isValid(); | 118 | // return context->property("mail").isValid(); |