diff options
Diffstat (limited to 'framework/domain')
-rw-r--r-- | framework/domain/actions/mailactions.cpp | 19 | ||||
-rw-r--r-- | framework/domain/actions/sinkactions.cpp | 43 | ||||
-rw-r--r-- | framework/domain/composercontroller.cpp | 35 | ||||
-rw-r--r-- | framework/domain/composercontroller.h | 13 |
4 files changed, 59 insertions, 51 deletions
diff --git a/framework/domain/actions/mailactions.cpp b/framework/domain/actions/mailactions.cpp index dab0533e..fde98c85 100644 --- a/framework/domain/actions/mailactions.cpp +++ b/framework/domain/actions/mailactions.cpp | |||
@@ -27,22 +27,3 @@ | |||
27 | 27 | ||
28 | using namespace Kube; | 28 | using namespace Kube; |
29 | 29 | ||
30 | static 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 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(); |
diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp index 4ab4ac21..a383de26 100644 --- a/framework/domain/composercontroller.cpp +++ b/framework/domain/composercontroller.cpp | |||
@@ -26,12 +26,13 @@ | |||
26 | #include <KCodecs/KEmailAddress> | 26 | #include <KCodecs/KEmailAddress> |
27 | #include <QVariant> | 27 | #include <QVariant> |
28 | #include <QDebug> | 28 | #include <QDebug> |
29 | #include <QQmlEngine> | ||
29 | 30 | ||
31 | #include "accountsmodel.h" | ||
30 | #include "mailtemplates.h" | 32 | #include "mailtemplates.h" |
31 | 33 | ||
32 | ComposerController::ComposerController(QObject *parent) : QObject(parent) | 34 | ComposerController::ComposerController(QObject *parent) : QObject(parent) |
33 | { | 35 | { |
34 | m_identityModel << "Kuberich <kuberich@kolabnow.com>" << "Uni <kuberich@university.edu>" << "Spam <hello.spam@spam.to>"; | ||
35 | } | 36 | } |
36 | 37 | ||
37 | QString ComposerController::to() const | 38 | QString ComposerController::to() const |
@@ -99,22 +100,11 @@ void ComposerController::setBody(const QString &body) | |||
99 | } | 100 | } |
100 | } | 101 | } |
101 | 102 | ||
102 | QStringList ComposerController::identityModel() const | 103 | QAbstractItemModel *ComposerController::identityModel() const |
103 | { | 104 | { |
104 | return m_identityModel; | 105 | static auto accountsModel = new AccountsModel(); |
105 | } | 106 | QQmlEngine::setObjectOwnership(accountsModel, QQmlEngine::CppOwnership); |
106 | 107 | return accountsModel;; | |
107 | int ComposerController::fromIndex() const | ||
108 | { | ||
109 | return m_fromIndex; | ||
110 | } | ||
111 | |||
112 | void ComposerController::setFromIndex(int fromIndex) | ||
113 | { | ||
114 | if(m_fromIndex != fromIndex) { | ||
115 | m_fromIndex = fromIndex; | ||
116 | emit fromIndexChanged(); | ||
117 | } | ||
118 | } | 108 | } |
119 | 109 | ||
120 | QStringList ComposerController::attachemts() const | 110 | QStringList ComposerController::attachemts() const |
@@ -165,6 +155,8 @@ KMime::Message::Ptr ComposerController::assembleMessage() | |||
165 | KEmailAddress::splitAddress(to.toUtf8(), displayName, addrSpec, comment); | 155 | KEmailAddress::splitAddress(to.toUtf8(), displayName, addrSpec, comment); |
166 | mail->to(true)->addAddress(addrSpec, displayName); | 156 | mail->to(true)->addAddress(addrSpec, displayName); |
167 | } | 157 | } |
158 | //FIXME set "from" from identity (or do that in the action directly?) | ||
159 | // mail->from(true)->addAddress("test@example.com", "John Doe"); | ||
168 | mail->subject(true)->fromUnicodeString(m_subject, "utf-8"); | 160 | mail->subject(true)->fromUnicodeString(m_subject, "utf-8"); |
169 | mail->setBody(m_body.toUtf8()); | 161 | mail->setBody(m_body.toUtf8()); |
170 | mail->assemble(); | 162 | mail->assemble(); |
@@ -174,17 +166,13 @@ KMime::Message::Ptr ComposerController::assembleMessage() | |||
174 | void ComposerController::send() | 166 | void ComposerController::send() |
175 | { | 167 | { |
176 | auto mail = assembleMessage(); | 168 | auto mail = assembleMessage(); |
177 | Kube::ApplicationContext settings; | 169 | auto currentAccountId = identityModel()->index(m_currentAccountIndex, 0).data(AccountsModel::AccountId).toByteArray(); |
178 | auto account = settings.currentAccount(); | ||
179 | auto identity = account.primaryIdentity(); | ||
180 | auto transport = identity.transport(); | ||
181 | 170 | ||
182 | Kube::Context context; | 171 | Kube::Context context; |
183 | context.setProperty("message", QVariant::fromValue(mail)); | 172 | context.setProperty("message", QVariant::fromValue(mail)); |
173 | context.setProperty("accountId", QVariant::fromValue(currentAccountId)); | ||
184 | 174 | ||
185 | context.setProperty("username", transport.username()); | 175 | qDebug() << "Current account " << currentAccountId; |
186 | context.setProperty("password", transport.password()); | ||
187 | context.setProperty("server", transport.server()); | ||
188 | 176 | ||
189 | Kube::Action("org.kde.kube.actions.sendmail", context).execute(); | 177 | Kube::Action("org.kde.kube.actions.sendmail", context).execute(); |
190 | clear(); | 178 | clear(); |
@@ -206,5 +194,4 @@ void ComposerController::clear() | |||
206 | setTo(""); | 194 | setTo(""); |
207 | setCc(""); | 195 | setCc(""); |
208 | setBcc(""); | 196 | setBcc(""); |
209 | setFromIndex(-1); | ||
210 | } | 197 | } |
diff --git a/framework/domain/composercontroller.h b/framework/domain/composercontroller.h index b410ce9b..4ad505d8 100644 --- a/framework/domain/composercontroller.h +++ b/framework/domain/composercontroller.h | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <QString> | 23 | #include <QString> |
24 | #include <QStringList> | 24 | #include <QStringList> |
25 | #include <QVariant> | 25 | #include <QVariant> |
26 | #include <QAbstractItemModel> | ||
26 | 27 | ||
27 | namespace KMime { | 28 | namespace KMime { |
28 | class Message; | 29 | class Message; |
@@ -37,8 +38,8 @@ class ComposerController : public QObject | |||
37 | Q_PROPERTY (QString bcc READ bcc WRITE setBcc NOTIFY bccChanged) | 38 | Q_PROPERTY (QString bcc READ bcc WRITE setBcc NOTIFY bccChanged) |
38 | Q_PROPERTY (QString subject READ subject WRITE setSubject NOTIFY subjectChanged) | 39 | Q_PROPERTY (QString subject READ subject WRITE setSubject NOTIFY subjectChanged) |
39 | Q_PROPERTY (QString body READ body WRITE setBody NOTIFY bodyChanged) | 40 | Q_PROPERTY (QString body READ body WRITE setBody NOTIFY bodyChanged) |
40 | Q_PROPERTY (QStringList identityModel READ identityModel) | 41 | Q_PROPERTY (QAbstractItemModel* identityModel READ identityModel CONSTANT) |
41 | Q_PROPERTY (int fromIndex READ fromIndex WRITE setFromIndex NOTIFY fromIndexChanged) | 42 | Q_PROPERTY (int currentIdentityIndex MEMBER m_currentAccountIndex) |
42 | Q_PROPERTY (QStringList attachments READ attachemts NOTIFY attachmentsChanged) | 43 | Q_PROPERTY (QStringList attachments READ attachemts NOTIFY attachmentsChanged) |
43 | 44 | ||
44 | public: | 45 | public: |
@@ -59,10 +60,7 @@ public: | |||
59 | QString body() const; | 60 | QString body() const; |
60 | void setBody(const QString &body); | 61 | void setBody(const QString &body); |
61 | 62 | ||
62 | QStringList identityModel() const; | 63 | QAbstractItemModel *identityModel() const; |
63 | |||
64 | int fromIndex() const; | ||
65 | void setFromIndex(int fromIndex); | ||
66 | 64 | ||
67 | QStringList attachemts() const; | 65 | QStringList attachemts() const; |
68 | 66 | ||
@@ -91,9 +89,8 @@ private: | |||
91 | QString m_bcc; | 89 | QString m_bcc; |
92 | QString m_subject; | 90 | QString m_subject; |
93 | QString m_body; | 91 | QString m_body; |
94 | QStringList m_identityModel; | ||
95 | int m_fromIndex; | ||
96 | QStringList m_attachments; | 92 | QStringList m_attachments; |
97 | QVariant m_originalMessage; | 93 | QVariant m_originalMessage; |
98 | QVariant m_msg; | 94 | QVariant m_msg; |
95 | int m_currentAccountIndex; | ||
99 | }; | 96 | }; |