diff options
author | Sandro Knauß <sknauss@kde.org> | 2016-08-02 10:11:23 +0200 |
---|---|---|
committer | Sandro Knauß <sknauss@kde.org> | 2016-08-02 10:11:23 +0200 |
commit | 2d0608ddf1b84991ca7a693ce00e70b6447644d9 (patch) | |
tree | d90888ebe04f97bba950ca4e4704d2ff0278ea4a /framework/domain/mimetreeparser/interface.cpp | |
parent | c64288bfe549ccc95eb6b887f3b803b397ae412c (diff) | |
download | kube-2d0608ddf1b84991ca7a693ce00e70b6447644d9.tar.gz kube-2d0608ddf1b84991ca7a693ce00e70b6447644d9.zip |
Implement collectAttachmentParts
Diffstat (limited to 'framework/domain/mimetreeparser/interface.cpp')
-rw-r--r-- | framework/domain/mimetreeparser/interface.cpp | 47 |
1 files changed, 46 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); |