diff options
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/messagepart.cpp | 62 | ||||
-rw-r--r-- | framework/src/domain/mime/mimetreeparser/tests/mimetreeparsertest.cpp | 4 |
2 files changed, 18 insertions, 48 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 | ||
diff --git a/framework/src/domain/mime/mimetreeparser/tests/mimetreeparsertest.cpp b/framework/src/domain/mime/mimetreeparser/tests/mimetreeparsertest.cpp index 7fa651bc..a4b347e7 100644 --- a/framework/src/domain/mime/mimetreeparser/tests/mimetreeparsertest.cpp +++ b/framework/src/domain/mime/mimetreeparser/tests/mimetreeparsertest.cpp | |||
@@ -426,12 +426,10 @@ private slots: | |||
426 | otp.decryptParts(); | 426 | otp.decryptParts(); |
427 | otp.print(); | 427 | otp.print(); |
428 | auto partList = otp.collectContentParts(); | 428 | auto partList = otp.collectContentParts(); |
429 | QCOMPARE(partList.size(), 1); | 429 | QCOMPARE(partList.size(), 2); |
430 | auto part = partList[0].dynamicCast<MimeTreeParser::MessagePart>(); | 430 | auto part = partList[0].dynamicCast<MimeTreeParser::MessagePart>(); |
431 | QCOMPARE(part->encryptions().size(), 0); | 431 | QCOMPARE(part->encryptions().size(), 0); |
432 | QCOMPARE(part->signatures().size(), 0); | 432 | QCOMPARE(part->signatures().size(), 0); |
433 | qWarning() << otp.plainTextContent(); | ||
434 | qWarning() << otp.htmlContent(); | ||
435 | QCOMPARE(otp.plainTextContent(), QString::fromUtf8("Hello\n\n\n\nRegards\n\nFsdfsdf")); | 433 | QCOMPARE(otp.plainTextContent(), QString::fromUtf8("Hello\n\n\n\nRegards\n\nFsdfsdf")); |
436 | QCOMPARE(otp.htmlContent(), QString::fromUtf8("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=us-ascii\"></head><body style=\"word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;\" class=\"\"><strike class=\"\">Hello</strike><div class=\"\"><br class=\"\"></div><div class=\"\"></div></body></html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=us-ascii\"></head><body style=\"word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;\" class=\"\"><div class=\"\"></div><div class=\"\"><br class=\"\"></div><div class=\"\"><b class=\"\">Regards</b></div><div class=\"\"><b class=\"\"><br class=\"\"></b></div><div class=\"\">Fsdfsdf</div></body></html>")); | 434 | QCOMPARE(otp.htmlContent(), QString::fromUtf8("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=us-ascii\"></head><body style=\"word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;\" class=\"\"><strike class=\"\">Hello</strike><div class=\"\"><br class=\"\"></div><div class=\"\"></div></body></html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=us-ascii\"></head><body style=\"word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;\" class=\"\"><div class=\"\"></div><div class=\"\"><br class=\"\"></div><div class=\"\"><b class=\"\">Regards</b></div><div class=\"\"><b class=\"\"><br class=\"\"></b></div><div class=\"\">Fsdfsdf</div></body></html>")); |
437 | 435 | ||