Changeset View
Changeset View
Standalone View
Standalone View
framework/src/domain/composercontroller.cpp
Show First 20 Lines • Show All 266 Lines • ▼ Show 20 Line(s) | 262 | applyAddresses(s, [&](const QByteArray &addrSpec, const QByteArray &displayName) { | |||
---|---|---|---|---|---|
267 | } | 267 | } | ||
268 | }); | 268 | }); | ||
269 | return list; | 269 | return list; | ||
270 | } | 270 | } | ||
271 | 271 | | |||
272 | void ComposerController::addAttachmentPart(KMime::Content *partToAttach) | 272 | void ComposerController::addAttachmentPart(KMime::Content *partToAttach) | ||
273 | { | 273 | { | ||
274 | QVariantMap map; | 274 | QVariantMap map; | ||
275 | if (partToAttach->contentType()->mimeType() == "multipart/digest" || | 275 | // May need special care for the multipart/digest MIME type | ||
276 | partToAttach->contentType()->mimeType() == "message/rfc822") { | | |||
277 | // if it is a digest or a full message, use the encodedContent() of the attachment, | | |||
278 | // which already has the proper headers | | |||
279 | map.insert("content", partToAttach->encodedContent()); | | |||
280 | } else { | | |||
281 | map.insert("content", partToAttach->decodedContent()); | 276 | map.insert("content", partToAttach->decodedContent()); | ||
282 | } | | |||
283 | map.insert("mimetype", partToAttach->contentType()->mimeType()); | 277 | map.insert("mimetype", partToAttach->contentType()->mimeType()); | ||
284 | 278 | | |||
285 | QMimeDatabase db; | 279 | QMimeDatabase db; | ||
286 | auto mimeType = db.mimeTypeForName(partToAttach->contentType()->mimeType()); | 280 | auto mimeType = db.mimeTypeForName(partToAttach->contentType()->mimeType()); | ||
287 | map.insert("iconname", mimeType.iconName()); | 281 | map.insert("iconname", mimeType.iconName()); | ||
288 | 282 | | |||
289 | if (partToAttach->contentDescription(false)) { | 283 | if (partToAttach->contentDescription(false)) { | ||
290 | map.insert("description", partToAttach->contentDescription()->asUnicodeString()); | 284 | map.insert("description", partToAttach->contentDescription()->asUnicodeString()); | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 315 | { | |||
332 | //TODO use ObjecTreeParser to get encrypted attachments as well | 326 | //TODO use ObjecTreeParser to get encrypted attachments as well | ||
333 | foreach (const auto &att, msg->attachments()) { | 327 | foreach (const auto &att, msg->attachments()) { | ||
334 | addAttachmentPart(att); | 328 | addAttachmentPart(att); | ||
335 | } | 329 | } | ||
336 | 330 | | |||
337 | setExistingMessage(msg); | 331 | setExistingMessage(msg); | ||
338 | } | 332 | } | ||
339 | 333 | | |||
340 | void ComposerController::loadMessage(const QVariant &message, bool loadAsDraft) | 334 | void ComposerController::loadDraft(const QVariant &message) { | ||
341 | { | 335 | loadMessage(message, [this] (const KMime::Message::Ptr &mail) { | ||
342 | using namespace Sink; | 336 | mRemoveDraft = true; | ||
343 | using namespace Sink::ApplicationDomain; | | |||
344 | | ||||
345 | auto msg = message.value<Mail::Ptr>(); | | |||
346 | Q_ASSERT(msg); | | |||
347 | Query query(*msg); | | |||
348 | query.request<Mail::MimeMessage>(); | | |||
349 | Store::fetchOne<Mail>(query).then([this, loadAsDraft](const Mail &mail) { | | |||
350 | mRemoveDraft = loadAsDraft; | | |||
351 | setExistingMail(mail); | | |||
352 | | ||||
353 | const auto mailData = KMime::CRLFtoLF(mail.getMimeMessage()); | | |||
354 | if (!mailData.isEmpty()) { | | |||
355 | KMime::Message::Ptr mail(new KMime::Message); | | |||
356 | mail->setContent(mailData); | | |||
357 | mail->parse(); | | |||
358 | if (loadAsDraft) { | | |||
359 | setMessage(mail); | 337 | setMessage(mail); | ||
360 | } else { | 338 | }); | ||
339 | } | ||||
340 | | ||||
341 | void ComposerController::loadReply(const QVariant &message) { | ||||
342 | loadMessage(message, [this] (const KMime::Message::Ptr &mail) { | ||||
361 | //Find all personal email addresses to exclude from reply | 343 | //Find all personal email addresses to exclude from reply | ||
362 | KMime::Types::AddrSpecList me; | 344 | KMime::Types::AddrSpecList me; | ||
363 | auto list = static_cast<IdentitySelector*>(mIdentitySelector.data())->getAllAddresses(); | 345 | auto list = static_cast<IdentitySelector*>(mIdentitySelector.data())->getAllAddresses(); | ||
364 | for (const auto &a : list) { | 346 | for (const auto &a : list) { | ||
365 | KMime::Types::Mailbox mb; | 347 | KMime::Types::Mailbox mb; | ||
366 | mb.setAddress(a); | 348 | mb.setAddress(a); | ||
367 | me << mb.addrSpec(); | 349 | me << mb.addrSpec(); | ||
368 | } | 350 | } | ||
369 | 351 | | |||
370 | MailTemplates::reply(mail, [this] (const KMime::Message::Ptr &reply) { | 352 | MailTemplates::reply(mail, [this] (const KMime::Message::Ptr &reply) { | ||
371 | //We assume reply | 353 | //We assume reply | ||
372 | setMessage(reply); | 354 | setMessage(reply); | ||
373 | }, me); | 355 | }, me); | ||
356 | }); | ||||
357 | } | ||||
358 | | ||||
359 | void ComposerController::loadForward(const QVariant &message) { | ||||
360 | loadMessage(message, [this] (const KMime::Message::Ptr &mail) { | ||||
361 | MailTemplates::forward(mail, [this] (const KMime::Message::Ptr &fwdMessage) { | ||||
362 | setMessage(fwdMessage); | ||||
363 | }); | ||||
364 | }); | ||||
374 | } | 365 | } | ||
366 | | ||||
367 | void ComposerController::loadMessage(const QVariant &message, std::function<void(const KMime::Message::Ptr&)> callback) | ||||
368 | { | ||||
369 | using namespace Sink; | ||||
370 | using namespace Sink::ApplicationDomain; | ||||
371 | | ||||
372 | auto msg = message.value<Mail::Ptr>(); | ||||
373 | Q_ASSERT(msg); | ||||
374 | Query query(*msg); | ||||
375 | query.request<Mail::MimeMessage>(); | ||||
376 | Store::fetchOne<Mail>(query).then([this, callback](const Mail &mail) { | ||||
377 | setExistingMail(mail); | ||||
378 | | ||||
379 | const auto mailData = KMime::CRLFtoLF(mail.getMimeMessage()); | ||||
380 | if (!mailData.isEmpty()) { | ||||
381 | KMime::Message::Ptr mail(new KMime::Message); | ||||
382 | mail->setContent(mailData); | ||||
383 | mail->parse(); | ||||
384 | callback(mail); | ||||
375 | } else { | 385 | } else { | ||
376 | qWarning() << "Retrieved empty message"; | 386 | qWarning() << "Retrieved empty message"; | ||
377 | } | 387 | } | ||
378 | }).exec(); | 388 | }).exec(); | ||
379 | } | 389 | } | ||
380 | 390 | | |||
381 | void ComposerController::recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName) | 391 | void ComposerController::recordForAutocompletion(const QByteArray &addrSpec, const QByteArray &displayName) | ||
382 | { | 392 | { | ||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |