diff options
Diffstat (limited to 'extensions/api')
-rw-r--r-- | extensions/api/CMakeLists.txt | 12 | ||||
-rw-r--r-- | extensions/api/qmldir | 4 | ||||
-rw-r--r-- | extensions/api/src/CMakeLists.txt | 25 | ||||
-rw-r--r-- | extensions/api/src/extensionapi.cpp | 89 | ||||
-rw-r--r-- | extensions/api/src/extensionapi.h | 30 | ||||
-rw-r--r-- | extensions/api/src/extensionapiplugin.cpp | 42 | ||||
-rw-r--r-- | extensions/api/src/extensionapiplugin.h | 33 |
7 files changed, 235 insertions, 0 deletions
diff --git a/extensions/api/CMakeLists.txt b/extensions/api/CMakeLists.txt new file mode 100644 index 00000000..82a5c7b0 --- /dev/null +++ b/extensions/api/CMakeLists.txt | |||
@@ -0,0 +1,12 @@ | |||
1 | include(GenerateExportHeader) | ||
2 | include(ECMGenerateHeaders) | ||
3 | include(CMakePackageConfigHelpers) | ||
4 | |||
5 | set(EXTENSIONAPI_INSTALL_DIR ${QML_INSTALL_DIR}/org/kube/extensionapi) | ||
6 | |||
7 | install(DIRECTORY qml/ DESTINATION ${EXTENSIONAPI_INSTALL_DIR}) | ||
8 | install(FILES qmldir DESTINATION ${EXTENSIONAPI_INSTALL_DIR}) | ||
9 | |||
10 | add_subdirectory(src) | ||
11 | |||
12 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) | ||
diff --git a/extensions/api/qmldir b/extensions/api/qmldir new file mode 100644 index 00000000..405785e5 --- /dev/null +++ b/extensions/api/qmldir | |||
@@ -0,0 +1,4 @@ | |||
1 | module org.kube.extensionapi | ||
2 | depends org.kube.framework 1.0 | ||
3 | |||
4 | plugin extensionapiplugin | ||
diff --git a/extensions/api/src/CMakeLists.txt b/extensions/api/src/CMakeLists.txt new file mode 100644 index 00000000..f7e543dc --- /dev/null +++ b/extensions/api/src/CMakeLists.txt | |||
@@ -0,0 +1,25 @@ | |||
1 | add_definitions("-Wall -std=c++14 -g") | ||
2 | set(CMAKE_CXX_VISIBILITY_PRESET default) | ||
3 | |||
4 | find_package(Qt5 COMPONENTS REQUIRED Core Concurrent Quick Qml WebEngineWidgets Test WebEngine Gui) | ||
5 | find_package(KF5Mime 4.87.0 CONFIG REQUIRED) | ||
6 | find_package(Sink 0.6.0 CONFIG REQUIRED) | ||
7 | |||
8 | include_directories(../../../framework/src/domain/mime ${KMIME_INCLUDES}) | ||
9 | |||
10 | add_library(extensionapiplugin SHARED extensionapiplugin.cpp extensionapi.cpp) | ||
11 | target_link_libraries(extensionapiplugin | ||
12 | kubeframework | ||
13 | KF5::Mime | ||
14 | sink | ||
15 | Qt5::Core | ||
16 | Qt5::Quick | ||
17 | Qt5::Qml | ||
18 | Qt5::WebEngineWidgets | ||
19 | Qt5::Test | ||
20 | Qt5::WebEngine | ||
21 | Qt5::Gui | ||
22 | ) | ||
23 | install(TARGETS extensionapiplugin DESTINATION ${EXTENSIONAPI_INSTALL_DIR}) | ||
24 | |||
25 | feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) | ||
diff --git a/extensions/api/src/extensionapi.cpp b/extensions/api/src/extensionapi.cpp new file mode 100644 index 00000000..3e6689b9 --- /dev/null +++ b/extensions/api/src/extensionapi.cpp | |||
@@ -0,0 +1,89 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 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 "extensionapi.h" | ||
20 | |||
21 | #include <mailtemplates.h> | ||
22 | #include <KMime/KMimeMessage> | ||
23 | #include <sink/store.h> | ||
24 | #include <sink/log.h> | ||
25 | |||
26 | #include <QDebug> | ||
27 | |||
28 | static void send(const QByteArray &message, const QByteArray &accountId) | ||
29 | { | ||
30 | using namespace Sink; | ||
31 | using namespace Sink::ApplicationDomain; | ||
32 | |||
33 | Q_ASSERT(!accountId.isEmpty()); | ||
34 | Query query; | ||
35 | query.containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::transport); | ||
36 | query.filter<SinkResource::Account>(accountId); | ||
37 | auto job = Store::fetchAll<SinkResource>(query) | ||
38 | .then([=](const QList<SinkResource::Ptr> &resources) { | ||
39 | if (!resources.isEmpty()) { | ||
40 | auto resourceId = resources[0]->identifier(); | ||
41 | SinkLog() << "Sending message via resource: " << resourceId; | ||
42 | Mail mail(resourceId); | ||
43 | mail.setMimeMessage(message); | ||
44 | return Store::create(mail) | ||
45 | .then<void>([=] { | ||
46 | //Trigger a sync, but don't wait for it. | ||
47 | Store::synchronize(Sink::SyncScope{}.resourceFilter(resourceId)).exec(); | ||
48 | }); | ||
49 | } | ||
50 | SinkWarning() << "Failed to find a mailtransport resource"; | ||
51 | return KAsync::error<void>(0, "Failed to find a MailTransport resource."); | ||
52 | }) | ||
53 | .then([&] (const KAsync::Error &) { | ||
54 | SinkLog() << "Message was sent: "; | ||
55 | }); | ||
56 | job.exec(); | ||
57 | } | ||
58 | |||
59 | static QStringList toStringList(const QVariantList &list) | ||
60 | { | ||
61 | QStringList s; | ||
62 | for (const auto &e : list) { | ||
63 | s << e.toString(); | ||
64 | } | ||
65 | return s; | ||
66 | } | ||
67 | |||
68 | Q_INVOKABLE void ExtensionApi::forwardMail(const QVariantMap &map) | ||
69 | { | ||
70 | SinkLog() << "Forwarding mail " << map; | ||
71 | auto mailObject = map.value("mail").value<Sink::ApplicationDomain::Mail::Ptr>(); | ||
72 | Q_ASSERT(mailObject); | ||
73 | KMime::Message::Ptr msg(new KMime::Message); | ||
74 | msg->setContent(KMime::CRLFtoLF(mailObject->getMimeMessage())); | ||
75 | msg->parse(); | ||
76 | |||
77 | MailTemplates::forward(msg, [map] (const KMime::Message::Ptr &fwdMessage) { | ||
78 | auto msg = fwdMessage; | ||
79 | msg->subject()->fromUnicodeString(map.value("subject").toString(), "utf8"); | ||
80 | auto list = toStringList(map.value("to").toList()); | ||
81 | for (const auto &address : list) { | ||
82 | KMime::Types::Mailbox mb; | ||
83 | mb.fromUnicodeString(address); | ||
84 | msg->to()->addAddress(mb); | ||
85 | } | ||
86 | msg->assemble(); | ||
87 | send(msg->encodedContent(true), map.value("accountId").toByteArray()); | ||
88 | }); | ||
89 | } | ||
diff --git a/extensions/api/src/extensionapi.h b/extensions/api/src/extensionapi.h new file mode 100644 index 00000000..305d1206 --- /dev/null +++ b/extensions/api/src/extensionapi.h | |||
@@ -0,0 +1,30 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 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 | |||
20 | #pragma once | ||
21 | |||
22 | #include <QObject> | ||
23 | |||
24 | class ExtensionApi : public QObject | ||
25 | { | ||
26 | Q_OBJECT | ||
27 | |||
28 | public: | ||
29 | Q_INVOKABLE void forwardMail(const QVariantMap &map); | ||
30 | }; | ||
diff --git a/extensions/api/src/extensionapiplugin.cpp b/extensions/api/src/extensionapiplugin.cpp new file mode 100644 index 00000000..3f399e36 --- /dev/null +++ b/extensions/api/src/extensionapiplugin.cpp | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 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 | |||
20 | #include "extensionapiplugin.h" | ||
21 | |||
22 | #include "extensionapi.h" | ||
23 | |||
24 | #include <QtQml> | ||
25 | |||
26 | void ExtensionApiPlugin::initializeEngine(QQmlEngine *engine, const char *uri) | ||
27 | { | ||
28 | Q_UNUSED(uri); | ||
29 | Q_UNUSED(engine); | ||
30 | } | ||
31 | |||
32 | static QObject *extensionApiSingleton(QQmlEngine *engine, QJSEngine *scriptEngine) | ||
33 | { | ||
34 | Q_UNUSED(engine) | ||
35 | Q_UNUSED(scriptEngine) | ||
36 | return new ExtensionApi; | ||
37 | } | ||
38 | |||
39 | void ExtensionApiPlugin::registerTypes (const char *uri) | ||
40 | { | ||
41 | qmlRegisterSingletonType<ExtensionApi>(uri, 1, 0, "ExtensionApi", extensionApiSingleton); | ||
42 | } | ||
diff --git a/extensions/api/src/extensionapiplugin.h b/extensions/api/src/extensionapiplugin.h new file mode 100644 index 00000000..e23e5cc4 --- /dev/null +++ b/extensions/api/src/extensionapiplugin.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | Copyright (c) 2018 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 | |||
20 | #pragma once | ||
21 | |||
22 | #include <QQmlEngine> | ||
23 | #include <QQmlExtensionPlugin> | ||
24 | |||
25 | class ExtensionApiPlugin : public QQmlExtensionPlugin | ||
26 | { | ||
27 | Q_OBJECT | ||
28 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") | ||
29 | |||
30 | public: | ||
31 | void registerTypes(const char *uri) Q_DECL_OVERRIDE; | ||
32 | void initializeEngine(QQmlEngine *engine, const char *uri) Q_DECL_OVERRIDE; | ||
33 | }; | ||