diff options
Diffstat (limited to 'framework/domain/actions/sinkactions.cpp')
-rw-r--r-- | framework/domain/actions/sinkactions.cpp | 101 |
1 files changed, 51 insertions, 50 deletions
diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index dea6fc72..5dbe623c 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp | |||
@@ -81,16 +81,7 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", | |||
81 | }, | 81 | }, |
82 | [](Context *context) { | 82 | [](Context *context) { |
83 | auto accountId = context->property("accountId").value<QByteArray>(); | 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>(); | 84 | 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: "; | 85 | qWarning() << "Sending a mail: "; |
95 | 86 | ||
96 | Sink::Query query; | 87 | Sink::Query query; |
@@ -98,53 +89,63 @@ static ActionHandlerHelper sendMailHandler("org.kde.kube.actions.sendmail", | |||
98 | query += Sink::Query::PropertyFilter("account", QVariant::fromValue(accountId)); | 89 | query += Sink::Query::PropertyFilter("account", QVariant::fromValue(accountId)); |
99 | Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(query) | 90 | Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(query) |
100 | .then<void, QList<Sink::ApplicationDomain::SinkResource::Ptr>>([=](const QList<Sink::ApplicationDomain::SinkResource::Ptr> &resources) { | 91 | .then<void, QList<Sink::ApplicationDomain::SinkResource::Ptr>>([=](const QList<Sink::ApplicationDomain::SinkResource::Ptr> &resources) { |
101 | if (resources.isEmpty()) { | 92 | if (!resources.isEmpty()) { |
102 | qWarning() << "Failed to find a mailtransport resource"; | ||
103 | } else { | ||
104 | auto resourceId = resources[0]->identifier(); | 93 | auto resourceId = resources[0]->identifier(); |
105 | qDebug() << "Sending message via resource: " << resourceId; | 94 | qDebug() << "Sending message via resource: " << resourceId; |
106 | Sink::ApplicationDomain::Mail mail(resourceId); | 95 | Sink::ApplicationDomain::Mail mail(resourceId); |
107 | mail.setProperty("mimeMessage", mimeMessage); | 96 | mail.setBlobProperty("mimeMessage", message->encodedContent()); |
108 | Sink::Store::create(mail).exec(); | 97 | return Sink::Store::create(mail); |
109 | // return Sink::Store::create(mail); | ||
110 | } | 98 | } |
99 | qWarning() << "Failed to find a mailtransport resource"; | ||
111 | return KAsync::error<void>(0, "Failed to find a MailTransport resource."); | 100 | return KAsync::error<void>(0, "Failed to find a MailTransport resource."); |
112 | }).exec(); | 101 | }).exec(); |
113 | } | 102 | } |
114 | ); | 103 | ); |
115 | 104 | ||
116 | // static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", | 105 | static ActionHandlerHelper saveAsDraft("org.kde.kube.actions.save-as-draft", |
117 | // [](Context *context) -> bool { | 106 | [](Context *context) -> bool { |
118 | // return context->property("mail").isValid(); | 107 | auto accountId = context->property("accountId").value<QByteArray>(); |
119 | // }, | 108 | auto message = context->property("message").value<KMime::Message::Ptr>(); |
120 | // [](Context *context) { | 109 | return !accountId.isEmpty() && message; |
121 | // Sink::Query query; | 110 | }, |
122 | // query += Sink::Query::RequestedProperties(QByteArrayList() << "name") | 111 | ActionHandlerHelper::JobHandler([](Context *context) -> KAsync::Job<void> { |
123 | // //FIXME do something like specialuse? | 112 | qWarning() << "executing save as draft"; |
124 | // query += Sink::Query::PropertyFilter("name", "Drafts"); | 113 | const auto accountId = context->property("accountId").value<QByteArray>(); |
125 | // // query += Sink::Query::PropertyContainsFilter("specialuser", "drafts"); | 114 | const auto message = context->property("message").value<KMime::Message::Ptr>(); |
126 | // query += Sink::Query::PropertyFilter("drafts", true); | 115 | auto existingMail = context->property("existingMail").value<Sink::ApplicationDomain::Mail>(); |
127 | // //TODO Use drafts folder of that specific account | 116 | if (!message) { |
128 | // Sink::Store::fetchAll<Sink::ApplicationDomain::Folder>(query) | 117 | qWarning() << "Failed to get the mail: " << context->property("mail"); |
129 | // .then<void, QList<Sink::ApplicationDomain::Folder>>([](const QList<Sink::ApplicationDomain::Folder> folders) { | 118 | return KAsync::error<void>(1, "Failed to get the mail: " + context->property("mail").toString()); |
130 | // if (folders.isEmpty()) { | 119 | } |
131 | // return KAsync::start([]() { | 120 | |
132 | // //If message is already existing, modify, otherwise create | 121 | if (existingMail.identifier().isEmpty()) { |
133 | // }); | 122 | Sink::Query query; |
134 | // } | 123 | query += Sink::Query::RequestedProperties(QByteArrayList() << "name"); |
135 | // }); | 124 | query += Sink::Query::PropertyContainsFilter("specialpurpose", "drafts"); |
136 | // //TODO | 125 | query += Sink::Query::AccountFilter(accountId); |
137 | // // * Find drafts folder | 126 | qWarning() << "fetching the drafts folder"; |
138 | // // * Store KMime::Message on disk for use in blob property | 127 | return Sink::Store::fetchAll<Sink::ApplicationDomain::Folder>(query) |
139 | // // * Check if message is already existing and either create or update | 128 | .then<void, QList<Sink::ApplicationDomain::Folder::Ptr>>([=](const QList<Sink::ApplicationDomain::Folder::Ptr> folders) { |
140 | // // * | 129 | qWarning() << "fetched a drafts folder" << folders.size(); |
141 | // // auto mail = context->property("mail").value<Sink::ApplicationDomain::Mail::Ptr>(); | 130 | if (folders.isEmpty()) { |
142 | // // if (!mail) { | 131 | return KAsync::error<void>(1, "Failed to find a drafts folder."); |
143 | // // qWarning() << "Failed to get the mail mail: " << context->property("mail"); | 132 | } |
144 | // // return; | 133 | if (folders.size() > 1) { |
145 | // // } | 134 | qWarning() << "Found too many draft folders (taking the first): " << folders; |
146 | // // mail->setProperty("unread", false); | 135 | } |
147 | // // qDebug() << "Mark as read " << mail->identifier(); | 136 | const auto folder = folders.first(); |
148 | // // Sink::Store::modify(*mail).exec(); | 137 | Sink::ApplicationDomain::Mail mail(folder->resourceInstanceIdentifier()); |
149 | // } | 138 | mail.setProperty("folder", folder->identifier()); |
150 | // ); | 139 | mail.setBlobProperty("mimeMessage", message->encodedContent()); |
140 | return Sink::Store::create(mail); | ||
141 | }) | ||
142 | .then<void>([](){ | ||
143 | qWarning() << "done"; | ||
144 | }); | ||
145 | } else { | ||
146 | qWarning() << "Modifying an existing mail"; | ||
147 | existingMail.setBlobProperty("mimeMessage", message->encodedContent()); | ||
148 | return Sink::Store::modify(existingMail); | ||
149 | } | ||
150 | }) | ||
151 | ); | ||