diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-06-29 18:09:51 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-06-29 18:09:51 +0200 |
commit | 93859a60f6254154502db56f3629c4c87367da1c (patch) | |
tree | fa4631a685f616fad3ddd5b35af311352592a3e5 /framework/src/domain/mime/mimetreeparser/messagepart.cpp | |
parent | d81eea635c2151c2c9c62a53c08e427c38ad0acd (diff) | |
download | kube-93859a60f6254154502db56f3629c4c87367da1c.tar.gz kube-93859a60f6254154502db56f3629c4c87367da1c.zip |
The tests pass
Diffstat (limited to 'framework/src/domain/mime/mimetreeparser/messagepart.cpp')
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/messagepart.cpp | 62 |
1 files changed, 17 insertions, 45 deletions
diff --git a/framework/src/domain/mime/mimetreeparser/messagepart.cpp b/framework/src/domain/mime/mimetreeparser/messagepart.cpp index 9c17aafc..3ab43990 100644 --- a/framework/src/domain/mime/mimetreeparser/messagepart.cpp +++ b/framework/src/domain/mime/mimetreeparser/messagepart.cpp | |||
@@ -558,64 +558,36 @@ QString MimeMessagePart::htmlContent() const | |||
558 | AlternativeMessagePart::AlternativeMessagePart(ObjectTreeParser *otp, KMime::Content *node) | 558 | AlternativeMessagePart::AlternativeMessagePart(ObjectTreeParser *otp, KMime::Content *node) |
559 | : MessagePart(otp, QString(), node) | 559 | : MessagePart(otp, QString(), node) |
560 | { | 560 | { |
561 | KMime::Content *dataIcal = findTypeInDirectChilds(mNode, "text/calendar"); | 561 | if (auto dataIcal = findTypeInDirectChilds(mNode, "text/calendar")) { |
562 | KMime::Content *dataHtml = findTypeInDirectChilds(mNode, "text/html"); | 562 | mChildParts[Util::MultipartIcal] = MimeMessagePart::Ptr(new MimeMessagePart(mOtp, dataIcal, true)); |
563 | KMime::Content *dataText = findTypeInDirectChilds(mNode, "text/plain"); | 563 | } |
564 | |||
565 | if (auto dataText = findTypeInDirectChilds(mNode, "text/plain")) { | ||
566 | mChildParts[Util::MultipartPlain] = MimeMessagePart::Ptr(new MimeMessagePart(mOtp, dataText, true)); | ||
567 | } | ||
564 | 568 | ||
565 | if (!dataHtml) { | 569 | if (auto dataHtml = findTypeInDirectChilds(mNode, "text/html")) { |
570 | mChildParts[Util::MultipartHtml] = MimeMessagePart::Ptr(new MimeMessagePart(mOtp, dataHtml, true)); | ||
571 | } else { | ||
566 | // If we didn't find the HTML part as the first child of the multipart/alternative, it might | 572 | // If we didn't find the HTML part as the first child of the multipart/alternative, it might |
567 | // be that this is a HTML message with images, and text/plain and multipart/related are the | 573 | // be that this is a HTML message with images, and text/plain and multipart/related are the |
568 | // immediate children of this multipart/alternative node. | 574 | // immediate children of this multipart/alternative node. |
569 | // In this case, the HTML node is a child of multipart/related. | 575 | // In this case, the HTML node is a child of multipart/related. |
570 | dataHtml = findTypeInDirectChilds(mNode, "multipart/related"); | 576 | if (auto data = findTypeInDirectChilds(mNode, "multipart/related")) { |
571 | if (dataHtml) { | 577 | const auto parts = data->contents(); |
572 | const auto parts = dataHtml->contents(); | ||
573 | for (int i = 0; i < parts.size(); i++) { | 578 | for (int i = 0; i < parts.size(); i++) { |
574 | const auto p = parts.at(i); | 579 | const auto p = parts.at(i); |
575 | if (i == 0 ) { | 580 | if (i == 0 ) { |
576 | dataHtml = p; | 581 | mChildParts[Util::MultipartHtml] = MimeMessagePart::Ptr(new MimeMessagePart(mOtp, p, true)); |
577 | } else if (KMime::isAttachment(p)) { | 582 | } else if (KMime::isAttachment(p)) { |
578 | appendSubPart(MimeMessagePart::Ptr(new MimeMessagePart(otp, p, true))); | 583 | appendSubPart(MimeMessagePart::Ptr(new MimeMessagePart(otp, p, true))); |
579 | } | 584 | } |
580 | } | 585 | } |
586 | //Same for multipart/mixed | ||
587 | } else if (auto data = findTypeInDirectChilds(mNode, "multipart/mixed")) { | ||
588 | //FIXME: This doesn't populate mChildParts but instead attaches subparts. That way we at least process all parts as we should. | ||
589 | parseInternal(data); | ||
581 | } | 590 | } |
582 | |||
583 | // Still not found? Stupid apple mail actually puts the attachments inside of the | ||
584 | // multipart/alternative, which is wrong. Therefore we also have to look for multipart/mixed | ||
585 | // here. | ||
586 | // Do this only when prefering HTML mail, though, since otherwise the attachments are hidden | ||
587 | // when displaying plain text. | ||
588 | if (!dataHtml) { | ||
589 | dataHtml = findTypeInDirectChilds(mNode, "multipart/mixed"); | ||
590 | if (dataHtml) { | ||
591 | const auto parts = dataHtml->contents(); | ||
592 | for (int i = 0; i < parts.size(); i++) { | ||
593 | const auto p = parts.at(i); | ||
594 | if (i == 0 ) { | ||
595 | // FIXME multipart/mixed should display all types serially, not just one | ||
596 | dataHtml = p; | ||
597 | } else if (KMime::isAttachment(p)) { | ||
598 | appendSubPart(MimeMessagePart::Ptr(new MimeMessagePart(otp, p, true))); | ||
599 | } | ||
600 | } | ||
601 | } | ||
602 | } | ||
603 | } | ||
604 | |||
605 | if (dataIcal) { | ||
606 | mChildParts[Util::MultipartIcal] = MimeMessagePart::Ptr(new MimeMessagePart(mOtp, dataIcal, true)); | ||
607 | } | ||
608 | |||
609 | if (dataText) { | ||
610 | mChildParts[Util::MultipartPlain] = MimeMessagePart::Ptr(new MimeMessagePart(mOtp, dataText, true)); | ||
611 | } | ||
612 | |||
613 | if (dataHtml) { | ||
614 | mChildParts[Util::MultipartHtml] = MimeMessagePart::Ptr(new MimeMessagePart(mOtp, dataHtml, true)); | ||
615 | } | ||
616 | |||
617 | if (mChildParts.isEmpty()) { | ||
618 | qCWarning(MIMETREEPARSER_LOG) << "no valid nodes"; | ||
619 | } | 591 | } |
620 | } | 592 | } |
621 | 593 | ||