From 903960116eb3329631702723bba11f5463eff573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Fri, 22 Jul 2016 13:23:17 +0200 Subject: fixes the build issues --- framework/domain/mimetreeparser/interface.cpp | 103 +++++++++++++++++--------- 1 file changed, 69 insertions(+), 34 deletions(-) (limited to 'framework/domain/mimetreeparser/interface.cpp') diff --git a/framework/domain/mimetreeparser/interface.cpp b/framework/domain/mimetreeparser/interface.cpp index aa7e3911..5cf36d10 100644 --- a/framework/domain/mimetreeparser/interface.cpp +++ b/framework/domain/mimetreeparser/interface.cpp @@ -141,7 +141,7 @@ Content::~Content() { } -QVector< Encryption > Content::encryptions() const +QVector Content::encryptions() const { if (d->mParent) { return d->mParent->encryptions(); @@ -149,7 +149,7 @@ QVector< Encryption > Content::encryptions() const return QVector(); } -QVector< Signature > Content::signatures() const +QVector Content::signatures() const { if (d->mParent) { return d->mParent->signatures(); @@ -167,6 +167,19 @@ QByteArray Content::charset() const return d->mCodec; } +HtmlContent::HtmlContent(const QByteArray& content, Part* parent) + : Content(content, parent) +{ + +} + +PlainTextContent::PlainTextContent(const QByteArray& content, Part* parent) + : Content(content, parent) +{ + +} + + class AlternativePartPrivate { public: @@ -187,7 +200,7 @@ void AlternativePartPrivate::fillFrom(MimeTreeParser::AlternativeMessagePart::Pt { mTypes = QVector() << "html" << "plaintext"; - auto content = std::make_shared(part->htmlContent().toLocal8Bit(), q); + Content::Ptr content = std::make_shared(part->htmlContent().toLocal8Bit(), q); mContent["html"].append(content); content = std::make_shared(part->plaintextContent().toLocal8Bit(), q); mContent["plaintext"].append(content); @@ -224,11 +237,6 @@ QVector AlternativePart::availableContents() const return d->types(); } -QVector AlternativePart::content() const -{ - return d->content(availableContents().first()); -} - QVector AlternativePart::content(const QByteArray& ct) const { return d->content(ct); @@ -283,9 +291,12 @@ QVector SinglePart::availableContents() const return QVector() << d->mType; } -QVector< Content::Ptr > SinglePart::content() const +QVector< Content::Ptr > SinglePart::content(const QByteArray &ct) const { - return d->mContent; + if (ct == d->mType) { + return d->mContent; + } + return QVector(); } QByteArray SinglePart::type() const @@ -293,17 +304,6 @@ QByteArray SinglePart::type() const return "SinglePart"; } -class MimePartPrivate -{ -public: - void fillFrom(MimeTreeParser::MessagePart::Ptr part); -}; - -QByteArray MimePart::type() const -{ - return "MimePart"; -} - ParserPrivate::ParserPrivate(Parser* parser) : q(parser) , mNodeHelper(std::make_shared()) @@ -343,7 +343,7 @@ void ParserPrivate::createTree(const MimeTreeParser::MessagePart::Ptr &start, co const auto html = mp.dynamicCast(); const auto attachment = mp.dynamicCast(); if (attachment) { - auto part = std::make_shared(); + auto part = std::make_shared(); part->d->fillFrom(attachment); mTree->d->appendSubPart(part); } else if (text) { @@ -376,20 +376,55 @@ Parser::~Parser() QVector Parser::collectContentParts() const { - return collect(d->mTree, [](const Part::Ptr &p){return p->availableContents().indexOf("html") > -1 || p->availableContents().indexOf("text") > -1;}, [](const Part::Ptr &p){return true;}); -} - -template -QVector Parser::collect(const Part::Ptr &start, std::function select, std::function filter) const -{ - QVector ret; + return collect(d->mTree, [](const Part::Ptr &p){return p->type() != "EncapsulatedPart";}, + [](const Content::Ptr &content){ + const auto mime = content->mailMime(); + + if (!mime) { + return true; + } + + if (mime->isFirstTextPart()) { + return true; + } + const auto cd = mime->disposition(); + if (cd && cd == MailMime::Inline) { + // explict "inline" disposition: + return true; + } + if (cd && cd == MailMime::Attachment) { + // explicit "attachment" disposition: + return false; + } + + const auto ct = mime->mimetype(); + if (ct.name().trimmed().toLower() == "text" && ct.name().trimmed().isEmpty() && + (!mime || mime->filename().trimmed().isEmpty())) { + // text/* w/o filename parameter: + return true; + } + return false; + }); +} + +QVector Parser::collect(const Part::Ptr &start, std::function select, std::function filter) const +{ + QVector ret; foreach (const auto &part, start->subParts()) { - if (select(part)){ - const auto p = std::dynamic_pointer_cast(part); - if (p && filter(p)) { - ret.append(p); + QVector contents; + foreach(const auto &ct, part->availableContents()) { + foreach(const auto &content, part->content(ct)) { + if (filter(content)) { + contents.append(ct); + break; + } } - ret += collect(part, select, filter); + } + if (!contents.isEmpty()) { + ret.append(part); + } + if (select(part)){ + ret += collect(part, select, filter); } } return ret; -- cgit v1.2.3