diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-07-31 22:37:12 -0600 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-07-31 22:37:12 -0600 |
commit | 50caf4febe623743ba7c03453adf08af2e9a1dbc (patch) | |
tree | 8ce7ff0218bec9cf2cef7aa130122b4b2d4560b2 /framework/src/domain/composercontroller.cpp | |
parent | c44641a13aca0138ea331f04025b16dd9dc6c953 (diff) | |
download | kube-50caf4febe623743ba7c03453adf08af2e9a1dbc.tar.gz kube-50caf4febe623743ba7c03453adf08af2e9a1dbc.zip |
Slight composer code refactoring
Diffstat (limited to 'framework/src/domain/composercontroller.cpp')
-rw-r--r-- | framework/src/domain/composercontroller.cpp | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/framework/src/domain/composercontroller.cpp b/framework/src/domain/composercontroller.cpp index c55df1e7..bcfc1a9a 100644 --- a/framework/src/domain/composercontroller.cpp +++ b/framework/src/domain/composercontroller.cpp | |||
@@ -383,6 +383,24 @@ void ComposerController::recordForAutocompletion(const QByteArray &addrSpec, con | |||
383 | } | 383 | } |
384 | } | 384 | } |
385 | 385 | ||
386 | static KMime::Content *createAttachmentPart(const QByteArray &content, const QString &filename, bool isInline, const QByteArray &mimeType, const QString &name) | ||
387 | { | ||
388 | |||
389 | KMime::Content *part = new KMime::Content; | ||
390 | part->contentDisposition(true)->setFilename(filename); | ||
391 | if (isInline) { | ||
392 | part->contentDisposition(true)->setDisposition(KMime::Headers::CDinline); | ||
393 | } else { | ||
394 | part->contentDisposition(true)->setDisposition(KMime::Headers::CDattachment); | ||
395 | } | ||
396 | part->contentType(true)->setMimeType(mimeType); | ||
397 | part->contentType(true)->setName(name, "utf-8"); | ||
398 | //Just always encode attachments base64 so it's safe for binary data | ||
399 | part->contentTransferEncoding(true)->setEncoding(KMime::Headers::CEbase64); | ||
400 | part->setBody(content); | ||
401 | return part; | ||
402 | } | ||
403 | |||
386 | KMime::Message::Ptr ComposerController::assembleMessage() | 404 | KMime::Message::Ptr ComposerController::assembleMessage() |
387 | { | 405 | { |
388 | auto mail = mExistingMessage; | 406 | auto mail = mExistingMessage; |
@@ -428,27 +446,12 @@ KMime::Message::Ptr ComposerController::assembleMessage() | |||
428 | const auto mimeType = item->data(MimeTypeRole).toByteArray(); | 446 | const auto mimeType = item->data(MimeTypeRole).toByteArray(); |
429 | const auto isInline = item->data(InlineRole).toBool(); | 447 | const auto isInline = item->data(InlineRole).toBool(); |
430 | const auto content = item->data(ContentRole).toByteArray(); | 448 | const auto content = item->data(ContentRole).toByteArray(); |
431 | 449 | mail->addContent(createAttachmentPart(content, filename, isInline, mimeType, name)); | |
432 | KMime::Content *part = new KMime::Content; | ||
433 | part->contentDisposition(true)->setFilename(filename); | ||
434 | if (isInline) { | ||
435 | part->contentDisposition(true)->setDisposition(KMime::Headers::CDinline); | ||
436 | } else { | ||
437 | part->contentDisposition(true)->setDisposition(KMime::Headers::CDattachment); | ||
438 | } | ||
439 | part->contentType(true)->setMimeType(mimeType); | ||
440 | part->contentType(true)->setName(name, "utf-8"); | ||
441 | //Just always encode attachments base64 so it's safe for binary data | ||
442 | part->contentTransferEncoding(true)->setEncoding(KMime::Headers::CEbase64); | ||
443 | part->setBody(content); | ||
444 | |||
445 | mail->addContent(part); | ||
446 | |||
447 | auto mainMessage = new KMime::Content; | ||
448 | mainMessage->setBody(getBody().toUtf8()); | ||
449 | mainMessage->contentType(true)->setMimeType("text/plain"); | ||
450 | mail->addContent(mainMessage); | ||
451 | } | 450 | } |
451 | auto mainMessage = new KMime::Content; | ||
452 | mainMessage->setBody(getBody().toUtf8()); | ||
453 | mainMessage->contentType(true)->setMimeType("text/plain"); | ||
454 | mail->addContent(mainMessage); | ||
452 | } else { | 455 | } else { |
453 | //FIXME same implementation as above for attachments | 456 | //FIXME same implementation as above for attachments |
454 | mail->setBody(getBody().toUtf8()); | 457 | mail->setBody(getBody().toUtf8()); |