diff options
-rw-r--r-- | framework/domain/mimetreeparser/interface.cpp | 47 | ||||
-rw-r--r-- | framework/domain/mimetreeparser/tests/interfacetest.cpp | 16 |
2 files changed, 62 insertions, 1 deletions
diff --git a/framework/domain/mimetreeparser/interface.cpp b/framework/domain/mimetreeparser/interface.cpp index 4f45b883..04f0fdf2 100644 --- a/framework/domain/mimetreeparser/interface.cpp +++ b/framework/domain/mimetreeparser/interface.cpp | |||
@@ -433,6 +433,9 @@ void SinglePartPrivate::fillFrom(MimeTreeParser::HtmlMessagePart::Ptr part) | |||
433 | void SinglePartPrivate::fillFrom(MimeTreeParser::AttachmentMessagePart::Ptr part) | 433 | void SinglePartPrivate::fillFrom(MimeTreeParser::AttachmentMessagePart::Ptr part) |
434 | { | 434 | { |
435 | q->reachParentD()->createMailMime(part.staticCast<MimeTreeParser::TextMessagePart>()); | 435 | q->reachParentD()->createMailMime(part.staticCast<MimeTreeParser::TextMessagePart>()); |
436 | mType = q->mailMime()->mimetype().name().toUtf8(); | ||
437 | mContent.clear(); | ||
438 | mContent.append(std::make_shared<Content>(part->text().toLocal8Bit(), q)); | ||
436 | } | 439 | } |
437 | 440 | ||
438 | SinglePart::SinglePart() | 441 | SinglePart::SinglePart() |
@@ -582,6 +585,49 @@ QVector<Part::Ptr> Parser::collectContentParts() const | |||
582 | }); | 585 | }); |
583 | } | 586 | } |
584 | 587 | ||
588 | |||
589 | QVector<Part::Ptr> Parser::collectAttachmentParts() const | ||
590 | { | ||
591 | return collect(d->mTree, [](const Part::Ptr &p){return p->type() != "EncapsulatedPart";}, | ||
592 | [](const Content::Ptr &content){ | ||
593 | const auto mime = content->mailMime(); | ||
594 | |||
595 | if (!mime) { | ||
596 | return false; | ||
597 | } | ||
598 | |||
599 | if (mime->isFirstTextPart()) { | ||
600 | return false; | ||
601 | } | ||
602 | |||
603 | { | ||
604 | const auto parent = content->parent(); | ||
605 | if (parent) { | ||
606 | const auto _mime = parent->mailMime(); | ||
607 | if (_mime && (_mime->isTopLevelPart() || _mime->isFirstTextPart())) { | ||
608 | return false; | ||
609 | } | ||
610 | } | ||
611 | } | ||
612 | const auto cd = mime->disposition(); | ||
613 | if (cd && cd == MailMime::Inline) { | ||
614 | // explict "inline" disposition: | ||
615 | return false; | ||
616 | } | ||
617 | if (cd && cd == MailMime::Attachment) { | ||
618 | // explicit "attachment" disposition: | ||
619 | return true; | ||
620 | } | ||
621 | |||
622 | const auto ct = mime->mimetype(); | ||
623 | if (ct.name().trimmed().toLower() == "text" && ct.name().trimmed().isEmpty() && | ||
624 | (!mime || mime->filename().trimmed().isEmpty())) { | ||
625 | // text/* w/o filename parameter: | ||
626 | return false; | ||
627 | } | ||
628 | return true; | ||
629 | }); | ||
630 | } | ||
585 | QVector<Part::Ptr> Parser::collect(const Part::Ptr &start, std::function<bool(const Part::Ptr &)> select, std::function<bool(const Content::Ptr &)> filter) const | 631 | QVector<Part::Ptr> Parser::collect(const Part::Ptr &start, std::function<bool(const Part::Ptr &)> select, std::function<bool(const Content::Ptr &)> filter) const |
586 | { | 632 | { |
587 | QVector<Part::Ptr> ret; | 633 | QVector<Part::Ptr> ret; |
@@ -594,7 +640,6 @@ QVector<Part::Ptr> Parser::collect(const Part::Ptr &start, std::function<bool(co | |||
594 | break; | 640 | break; |
595 | } | 641 | } |
596 | } | 642 | } |
597 | qWarning() << ct << contents.size(); | ||
598 | } | 643 | } |
599 | if (!contents.isEmpty()) { | 644 | if (!contents.isEmpty()) { |
600 | ret.append(part); | 645 | ret.append(part); |
diff --git a/framework/domain/mimetreeparser/tests/interfacetest.cpp b/framework/domain/mimetreeparser/tests/interfacetest.cpp index 615d5742..fb073fc1 100644 --- a/framework/domain/mimetreeparser/tests/interfacetest.cpp +++ b/framework/domain/mimetreeparser/tests/interfacetest.cpp | |||
@@ -79,6 +79,8 @@ private slots: | |||
79 | 79 | ||
80 | contentList = contentPart->content("html"); | 80 | contentList = contentPart->content("html"); |
81 | QCOMPARE(contentList.size(), 0); | 81 | QCOMPARE(contentList.size(), 0); |
82 | auto contentAttachmentList = parser.collectAttachmentParts(); | ||
83 | QCOMPARE(contentAttachmentList.size(), 0); | ||
82 | } | 84 | } |
83 | 85 | ||
84 | void testTextAlternative() | 86 | void testTextAlternative() |
@@ -103,6 +105,8 @@ private slots: | |||
103 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | 105 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); |
104 | QCOMPARE(contentList[0]->encryptions().size(), 0); | 106 | QCOMPARE(contentList[0]->encryptions().size(), 0); |
105 | QCOMPARE(contentList[0]->signatures().size(), 0); | 107 | QCOMPARE(contentList[0]->signatures().size(), 0); |
108 | auto contentAttachmentList = parser.collectAttachmentParts(); | ||
109 | QCOMPARE(contentAttachmentList.size(), 0); | ||
106 | } | 110 | } |
107 | 111 | ||
108 | void testTextHtml() | 112 | void testTextHtml() |
@@ -124,6 +128,8 @@ private slots: | |||
124 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | 128 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); |
125 | QCOMPARE(contentList[0]->encryptions().size(), 0); | 129 | QCOMPARE(contentList[0]->encryptions().size(), 0); |
126 | QCOMPARE(contentList[0]->signatures().size(), 0); | 130 | QCOMPARE(contentList[0]->signatures().size(), 0); |
131 | auto contentAttachmentList = parser.collectAttachmentParts(); | ||
132 | QCOMPARE(contentAttachmentList.size(), 0); | ||
127 | } | 133 | } |
128 | 134 | ||
129 | void testSMimeEncrypted() | 135 | void testSMimeEncrypted() |
@@ -139,6 +145,8 @@ private slots: | |||
139 | QCOMPARE(contentList.size(), 1); | 145 | QCOMPARE(contentList.size(), 1); |
140 | QCOMPARE(contentList[0]->content(), QStringLiteral("The quick brown fox jumped over the lazy dog.").toLocal8Bit()); | 146 | QCOMPARE(contentList[0]->content(), QStringLiteral("The quick brown fox jumped over the lazy dog.").toLocal8Bit()); |
141 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | 147 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); |
148 | auto contentAttachmentList = parser.collectAttachmentParts(); | ||
149 | QCOMPARE(contentAttachmentList.size(), 0); | ||
142 | } | 150 | } |
143 | 151 | ||
144 | void testOpenPGPEncryptedAttachment() | 152 | void testOpenPGPEncryptedAttachment() |
@@ -154,6 +162,12 @@ private slots: | |||
154 | QCOMPARE(contentList.size(), 1); | 162 | QCOMPARE(contentList.size(), 1); |
155 | QCOMPARE(contentList[0]->content(), QStringLiteral("test text").toLocal8Bit()); | 163 | QCOMPARE(contentList[0]->content(), QStringLiteral("test text").toLocal8Bit()); |
156 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | 164 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); |
165 | auto contentAttachmentList = parser.collectAttachmentParts(); | ||
166 | QCOMPARE(contentAttachmentList.size(), 2); | ||
167 | QCOMPARE(contentAttachmentList[0]->availableContents(), QVector<QByteArray>() << "text/plain"); | ||
168 | QCOMPARE(contentAttachmentList[0]->content().size(), 1); | ||
169 | QCOMPARE(contentAttachmentList[1]->availableContents(), QVector<QByteArray>() << "image/png"); | ||
170 | QCOMPARE(contentAttachmentList[1]->content().size(), 1); | ||
157 | } | 171 | } |
158 | 172 | ||
159 | void testOpenPPGInline() | 173 | void testOpenPPGInline() |
@@ -169,6 +183,8 @@ private slots: | |||
169 | QCOMPARE(contentList.size(), 1); | 183 | QCOMPARE(contentList.size(), 1); |
170 | QCOMPARE(contentList[0]->content(), QStringLiteral("asdasd asd asd asdf sadf sdaf sadf äöü").toLocal8Bit()); | 184 | QCOMPARE(contentList[0]->content(), QStringLiteral("asdasd asd asd asdf sadf sdaf sadf äöü").toLocal8Bit()); |
171 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); | 185 | QCOMPARE(contentList[0]->charset(), QStringLiteral("utf-8").toLocal8Bit()); |
186 | auto contentAttachmentList = parser.collectAttachmentParts(); | ||
187 | QCOMPARE(contentAttachmentList.size(), 0); | ||
172 | } | 188 | } |
173 | }; | 189 | }; |
174 | 190 | ||