summaryrefslogtreecommitdiffstats
path: root/framework/domain/actions
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain/actions')
-rw-r--r--framework/domain/actions/mailactions.cpp48
-rw-r--r--framework/domain/actions/sinkactions.cpp106
2 files changed, 154 insertions, 0 deletions
diff --git a/framework/domain/actions/mailactions.cpp b/framework/domain/actions/mailactions.cpp
new file mode 100644
index 00000000..dab0533e
--- /dev/null
+++ b/framework/domain/actions/mailactions.cpp
@@ -0,0 +1,48 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#include <actions/context.h>
20#include <actions/actionhandler.h>
21
22#include "../mailtransport.h"
23#include <KMime/Message>
24#include <QByteArray>
25#include <QVariant>
26#include <QDebug>
27
28using namespace Kube;
29
30static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail",
31 [](Context *context) -> bool {
32 auto username = context->property("username").value<QByteArray>();
33 auto password = context->property("password").value<QByteArray>();
34 auto server = context->property("server").value<QByteArray>();
35 auto message = context->property("message").value<KMime::Message::Ptr>();
36 return !username.isEmpty() && !password.isEmpty() && !server.isEmpty() && message;
37 },
38 [](Context *context) {
39 auto username = context->property("username").value<QByteArray>();
40 auto password = context->property("password").value<QByteArray>();
41 auto server = context->property("server").value<QByteArray>();
42 //For ssl use "smtps://mainserver.example.net
43 QByteArray cacert; // = "/path/to/certificate.pem";
44 auto message = context->property("message").value<KMime::Message::Ptr>();
45 qWarning() << "Sending a mail: ";
46 MailTransport::sendMessage(message, server, username, password, cacert);
47 }
48);
diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp
new file mode 100644
index 00000000..a19ab149
--- /dev/null
+++ b/framework/domain/actions/sinkactions.cpp
@@ -0,0 +1,106 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#include <actions/context.h>
20#include <actions/actionhandler.h>
21
22#include <sink/store.h>
23
24using namespace Kube;
25
26static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read",
27 [](Context *context) -> bool {
28 return context->property("mail").isValid();
29 },
30 [](Context *context) {
31 auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>();
32 if (!mail) {
33 qWarning() << "Failed to get the mail mail: " << context->property("mail");
34 return;
35 }
36 mail->setProperty("unread", false);
37 qDebug() << "Mark as read " << mail->identifier();
38 Sink::Store::modify(*mail).exec();
39 }
40);
41
42static ActionHandlerHelper deleteHandler("org.kde.kube.actions.delete",
43 [](Context *context) -> bool {
44 return context->property("mail").isValid();
45 },
46 [](Context *context) {
47 auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>();
48 if (!mail) {
49 qWarning() << "Failed to get the mail mail: " << context->property("mail");
50 return;
51 }
52 mail->setProperty("unread", false);
53 qDebug() << "Remove " << mail->identifier();
54 Sink::Store::remove(*mail).exec();
55 }
56);
57
58static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize",
59 [](Context *context) -> bool {
60 return context->property("folder").isValid();
61 },
62 [](Context *context) {
63 auto folder = context->property("folder").value<Sink::ApplicationDomain::Folder::Ptr>();
64 if (!folder) {
65 qWarning() << "Failed to get the folder: " << context->property("folder");
66 return;
67 }
68 Sink::Store::synchronize(Sink::Query::ResourceFilter(folder->resourceInstanceIdentifier())).exec();
69 }
70);
71
72// static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft",
73// [](Context *context) -> bool {
74// return context->property("mail").isValid();
75// },
76// [](Context *context) {
77// Sink::Query query;
78// query += Sink::Query::RequestedProperties(QByteArrayList() << "name")
79// //FIXME do something like specialuse?
80// query += Sink::Query::PropertyFilter("name", "Drafts");
81// // query += Sink::Query::PropertyContainsFilter("specialuser", "drafts");
82// query += Sink::Query::PropertyFilter("drafts", true);
83// //TODO Use drafts folder of that specific account
84// Sink::Store::fetchAll<Sink::ApplicationDomain::Folder>(query)
85// .then<void, QList<Sink::ApplicationDomain::Folder>>([](const QList<Sink::ApplicationDomain::Folder> folders) {
86// if (folders.isEmpty()) {
87// return KAsync::start([]() {
88// //If message is already existing, modify, otherwise create
89// });
90// }
91// });
92// //TODO
93// // * Find drafts folder
94// // * Store KMime::Message on disk for use in blob property
95// // * Check if message is already existing and either create or update
96// // *
97// // auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>();
98// // if (!mail) {
99// // qWarning() << "Failed to get the mail mail: " << context->property("mail");
100// // return;
101// // }
102// // mail->setProperty("unread", false);
103// // qDebug() << "Mark as read " << mail->identifier();
104// // Sink::Store::modify(*mail).exec();
105// }
106// );