summaryrefslogtreecommitdiffstats
path: root/framework/domain
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-01 09:56:27 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-01 09:56:27 +0200
commite5dfbf1d8121a5b50ffd13b8c2f8d8ad7e3cf270 (patch)
treed23e9a75e179ff105f8962af8709a922dc742499 /framework/domain
parent2427b9a3fe02724071800092046ce4f33610d169 (diff)
downloadkube-e5dfbf1d8121a5b50ffd13b8c2f8d8ad7e3cf270.tar.gz
kube-e5dfbf1d8121a5b50ffd13b8c2f8d8ad7e3cf270.zip
Removed mailtransport that lives in Sink now.
Diffstat (limited to 'framework/domain')
-rw-r--r--framework/domain/CMakeLists.txt7
-rw-r--r--framework/domain/actions/mailactions.cpp29
-rw-r--r--framework/domain/mailtransport.cpp160
-rw-r--r--framework/domain/mailtransport.h28
4 files changed, 1 insertions, 223 deletions
diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt
index 8b58296d..114b054d 100644
--- a/framework/domain/CMakeLists.txt
+++ b/framework/domain/CMakeLists.txt
@@ -3,13 +3,11 @@ set(mailplugin_SRCS
3 maillistmodel.cpp 3 maillistmodel.cpp
4 folderlistmodel.cpp 4 folderlistmodel.cpp
5 actions/sinkactions.cpp 5 actions/sinkactions.cpp
6 actions/mailactions.cpp
7 objecttreesource.cpp 6 objecttreesource.cpp
8 stringhtmlwriter.cpp 7 stringhtmlwriter.cpp
9 csshelper.cpp 8 csshelper.cpp
10 composercontroller.cpp 9 composercontroller.cpp
11 messageparser.cpp 10 messageparser.cpp
12 mailtransport.cpp
13 mailtemplates.cpp 11 mailtemplates.cpp
14 retriever.cpp 12 retriever.cpp
15 accountfactory.cpp 13 accountfactory.cpp
@@ -19,15 +17,12 @@ set(mailplugin_SRCS
19) 17)
20add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") 18add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data")
21 19
22find_package(CURL 7.20.0 REQUIRED)
23find_package(KF5 REQUIRED COMPONENTS Package) 20find_package(KF5 REQUIRED COMPONENTS Package)
24 21
25include_directories(${CURL_INCLUDE_DIRS})
26
27add_library(mailplugin SHARED ${mailplugin_SRCS}) 22add_library(mailplugin SHARED ${mailplugin_SRCS})
28 23
29qt5_use_modules(mailplugin Core Quick Qml WebKitWidgets) 24qt5_use_modules(mailplugin Core Quick Qml WebKitWidgets)
30target_link_libraries(mailplugin actionplugin settingsplugin sink KF5::MimeTreeParser KF5::Codecs KF5::Package KF5::Async KF5::IconThemes ${CURL_LIBRARIES}) 25target_link_libraries(mailplugin actionplugin settingsplugin sink KF5::MimeTreeParser KF5::Codecs KF5::Package KF5::Async KF5::IconThemes)
31 26
32add_subdirectory(actions/tests) 27add_subdirectory(actions/tests)
33 28
diff --git a/framework/domain/actions/mailactions.cpp b/framework/domain/actions/mailactions.cpp
deleted file mode 100644
index fde98c85..00000000
--- a/framework/domain/actions/mailactions.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
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
diff --git a/framework/domain/mailtransport.cpp b/framework/domain/mailtransport.cpp
deleted file mode 100644
index 49d858e1..00000000
--- a/framework/domain/mailtransport.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
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 "mailtransport.h"
20
21#include <QByteArray>
22#include <QList>
23#include <QDebug>
24
25extern "C" {
26
27#include <stdio.h>
28#include <string.h>
29#include <curl/curl.h>
30
31struct upload_status {
32 int offset;
33 const char *data;
34};
35
36static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp)
37{
38 struct upload_status *upload_ctx = (struct upload_status *)userp;
39 const char *data;
40
41 if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
42 return 0;
43 }
44
45 data = &upload_ctx->data[upload_ctx->offset];
46 if(data) {
47 size_t len = strlen(data);
48 if (len > size * nmemb) {
49 len = size * nmemb;
50 }
51 fprintf(stderr, "read n bytes: %d\n",len);
52 memcpy(ptr, data, len);
53 upload_ctx->offset += len;
54 return len;
55 }
56
57 return 0;
58}
59
60
61void sendMessageCurl(const char *to[], int numTos, const char *cc[], int numCcs, const char *msg, bool useTls, const char* from, const char *username, const char *password, const char *server, bool verifyPeer)
62{
63 //For ssl use "smtps://mainserver.example.net
64 const char* cacert = 0; // = "/path/to/certificate.pem";
65
66 CURL *curl;
67 CURLcode res = CURLE_OK;
68 struct curl_slist *recipients = NULL;
69 struct upload_status upload_ctx;
70
71 upload_ctx.offset = 0;
72 upload_ctx.data = msg;
73
74 curl = curl_easy_init();
75 if(curl) {
76 curl_easy_setopt(curl, CURLOPT_USERNAME, username);
77 curl_easy_setopt(curl, CURLOPT_PASSWORD, password);
78
79 curl_easy_setopt(curl, CURLOPT_URL, server);
80
81 if (useTls) {
82 curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_TRY);
83 }
84
85 if (!verifyPeer) {
86 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
87 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
88 }
89 if (cacert) {
90 curl_easy_setopt(curl, CURLOPT_CAINFO, cacert);
91 }
92
93 if (from) {
94 curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from);
95 }
96
97 for (int i = 0; i < numTos; i++) {
98 recipients = curl_slist_append(recipients, to[i]);
99 }
100 for (int i = 0; i < numCcs; i++) {
101 recipients = curl_slist_append(recipients, cc[i]);
102 }
103 curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
104
105 /* We're using a callback function to specify the payload (the headers and
106 * body of the message). You could just use the CURLOPT_READDATA option to
107 * specify a FILE pointer to read from. */
108 curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
109 curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
110 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
111
112 /* Since the traffic will be encrypted, it is very useful to turn on debug
113 * information within libcurl to see what is happening during the transfer.
114 */
115 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
116
117 res = curl_easy_perform(curl);
118 if(res != CURLE_OK) {
119 fprintf(stderr, "curl_easy_perform() failed: %s\n",
120 curl_easy_strerror(res));
121 }
122 curl_slist_free_all(recipients);
123 curl_easy_cleanup(curl);
124 }
125}
126
127};
128
129void MailTransport::sendMessage(const KMime::Message::Ptr &message, const QByteArray &server, const QByteArray &username, const QByteArray &password, const QByteArray &cacert)
130{
131 QByteArray msg = message->encodedContent();
132 qWarning() << "Sending message " << msg;
133
134 QByteArray from(message->from(true)->mailboxes().isEmpty() ? QByteArray() : message->from(true)->mailboxes().first().address());
135 QList<QByteArray> toList;
136 for (const auto &mb : message->to(true)->mailboxes()) {
137 toList << mb.address();
138 }
139 QList<QByteArray> ccList;
140 for (const auto &mb : message->cc(true)->mailboxes()) {
141 ccList << mb.address();
142 }
143 bool useTls = true;
144 bool verifyPeer = false;
145
146 const int numTos = toList.size();
147 const char* to[numTos];
148 for (int i = 0; i < numTos; i++) {
149 to[i] = toList.at(i);
150 }
151
152 const int numCcs = ccList.size();
153 const char* cc[numCcs];
154 for (int i = 0; i < numCcs; i++) {
155 cc[i] = ccList.at(i);
156 }
157
158 sendMessageCurl(to, numTos, cc, numCcs, msg, useTls, from.isEmpty() ? nullptr : from, username, password, server, verifyPeer);
159 qWarning() << "Message sent";
160}
diff --git a/framework/domain/mailtransport.h b/framework/domain/mailtransport.h
deleted file mode 100644
index 2eb30a03..00000000
--- a/framework/domain/mailtransport.h
+++ /dev/null
@@ -1,28 +0,0 @@
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
20#pragma once
21
22#include <QByteArray>
23#include <KMime/Message>
24
25namespace MailTransport
26{
27 void sendMessage(const KMime::Message::Ptr &message, const QByteArray &server, const QByteArray &username, const QByteArray &password, const QByteArray &cacert);
28};