diff options
Diffstat (limited to 'framework/domain/mimetreeparser/interface.cpp')
-rw-r--r-- | framework/domain/mimetreeparser/interface.cpp | 103 |
1 files changed, 69 insertions, 34 deletions
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() | |||
141 | { | 141 | { |
142 | } | 142 | } |
143 | 143 | ||
144 | QVector< Encryption > Content::encryptions() const | 144 | QVector<Encryption> Content::encryptions() const |
145 | { | 145 | { |
146 | if (d->mParent) { | 146 | if (d->mParent) { |
147 | return d->mParent->encryptions(); | 147 | return d->mParent->encryptions(); |
@@ -149,7 +149,7 @@ QVector< Encryption > Content::encryptions() const | |||
149 | return QVector<Encryption>(); | 149 | return QVector<Encryption>(); |
150 | } | 150 | } |
151 | 151 | ||
152 | QVector< Signature > Content::signatures() const | 152 | QVector<Signature> Content::signatures() const |
153 | { | 153 | { |
154 | if (d->mParent) { | 154 | if (d->mParent) { |
155 | return d->mParent->signatures(); | 155 | return d->mParent->signatures(); |
@@ -167,6 +167,19 @@ QByteArray Content::charset() const | |||
167 | return d->mCodec; | 167 | return d->mCodec; |
168 | } | 168 | } |
169 | 169 | ||
170 | HtmlContent::HtmlContent(const QByteArray& content, Part* parent) | ||
171 | : Content(content, parent) | ||
172 | { | ||
173 | |||
174 | } | ||
175 | |||
176 | PlainTextContent::PlainTextContent(const QByteArray& content, Part* parent) | ||
177 | : Content(content, parent) | ||
178 | { | ||
179 | |||
180 | } | ||
181 | |||
182 | |||
170 | class AlternativePartPrivate | 183 | class AlternativePartPrivate |
171 | { | 184 | { |
172 | public: | 185 | public: |
@@ -187,7 +200,7 @@ void AlternativePartPrivate::fillFrom(MimeTreeParser::AlternativeMessagePart::Pt | |||
187 | { | 200 | { |
188 | mTypes = QVector<QByteArray>() << "html" << "plaintext"; | 201 | mTypes = QVector<QByteArray>() << "html" << "plaintext"; |
189 | 202 | ||
190 | auto content = std::make_shared<HtmlContent>(part->htmlContent().toLocal8Bit(), q); | 203 | Content::Ptr content = std::make_shared<HtmlContent>(part->htmlContent().toLocal8Bit(), q); |
191 | mContent["html"].append(content); | 204 | mContent["html"].append(content); |
192 | content = std::make_shared<PlainTextContent>(part->plaintextContent().toLocal8Bit(), q); | 205 | content = std::make_shared<PlainTextContent>(part->plaintextContent().toLocal8Bit(), q); |
193 | mContent["plaintext"].append(content); | 206 | mContent["plaintext"].append(content); |
@@ -224,11 +237,6 @@ QVector<QByteArray> AlternativePart::availableContents() const | |||
224 | return d->types(); | 237 | return d->types(); |
225 | } | 238 | } |
226 | 239 | ||
227 | QVector<Content::Ptr> AlternativePart::content() const | ||
228 | { | ||
229 | return d->content(availableContents().first()); | ||
230 | } | ||
231 | |||
232 | QVector<Content::Ptr> AlternativePart::content(const QByteArray& ct) const | 240 | QVector<Content::Ptr> AlternativePart::content(const QByteArray& ct) const |
233 | { | 241 | { |
234 | return d->content(ct); | 242 | return d->content(ct); |
@@ -283,9 +291,12 @@ QVector<QByteArray> SinglePart::availableContents() const | |||
283 | return QVector<QByteArray>() << d->mType; | 291 | return QVector<QByteArray>() << d->mType; |
284 | } | 292 | } |
285 | 293 | ||
286 | QVector< Content::Ptr > SinglePart::content() const | 294 | QVector< Content::Ptr > SinglePart::content(const QByteArray &ct) const |
287 | { | 295 | { |
288 | return d->mContent; | 296 | if (ct == d->mType) { |
297 | return d->mContent; | ||
298 | } | ||
299 | return QVector<Content::Ptr>(); | ||
289 | } | 300 | } |
290 | 301 | ||
291 | QByteArray SinglePart::type() const | 302 | QByteArray SinglePart::type() const |
@@ -293,17 +304,6 @@ QByteArray SinglePart::type() const | |||
293 | return "SinglePart"; | 304 | return "SinglePart"; |
294 | } | 305 | } |
295 | 306 | ||
296 | class MimePartPrivate | ||
297 | { | ||
298 | public: | ||
299 | void fillFrom(MimeTreeParser::MessagePart::Ptr part); | ||
300 | }; | ||
301 | |||
302 | QByteArray MimePart::type() const | ||
303 | { | ||
304 | return "MimePart"; | ||
305 | } | ||
306 | |||
307 | ParserPrivate::ParserPrivate(Parser* parser) | 307 | ParserPrivate::ParserPrivate(Parser* parser) |
308 | : q(parser) | 308 | : q(parser) |
309 | , mNodeHelper(std::make_shared<MimeTreeParser::NodeHelper>()) | 309 | , mNodeHelper(std::make_shared<MimeTreeParser::NodeHelper>()) |
@@ -343,7 +343,7 @@ void ParserPrivate::createTree(const MimeTreeParser::MessagePart::Ptr &start, co | |||
343 | const auto html = mp.dynamicCast<MimeTreeParser::HtmlMessagePart>(); | 343 | const auto html = mp.dynamicCast<MimeTreeParser::HtmlMessagePart>(); |
344 | const auto attachment = mp.dynamicCast<MimeTreeParser::AttachmentMessagePart>(); | 344 | const auto attachment = mp.dynamicCast<MimeTreeParser::AttachmentMessagePart>(); |
345 | if (attachment) { | 345 | if (attachment) { |
346 | auto part = std::make_shared<AttachmentPart>(); | 346 | auto part = std::make_shared<SinglePart>(); |
347 | part->d->fillFrom(attachment); | 347 | part->d->fillFrom(attachment); |
348 | mTree->d->appendSubPart(part); | 348 | mTree->d->appendSubPart(part); |
349 | } else if (text) { | 349 | } else if (text) { |
@@ -376,20 +376,55 @@ Parser::~Parser() | |||
376 | 376 | ||
377 | QVector<Part::Ptr> Parser::collectContentParts() const | 377 | QVector<Part::Ptr> Parser::collectContentParts() const |
378 | { | 378 | { |
379 | return collect<Part>(d->mTree, [](const Part::Ptr &p){return p->availableContents().indexOf("html") > -1 || p->availableContents().indexOf("text") > -1;}, [](const Part::Ptr &p){return true;}); | 379 | return collect(d->mTree, [](const Part::Ptr &p){return p->type() != "EncapsulatedPart";}, |
380 | } | 380 | [](const Content::Ptr &content){ |
381 | 381 | const auto mime = content->mailMime(); | |
382 | template <typename T> | 382 | |
383 | QVector<typename T::Ptr> Parser::collect(const Part::Ptr &start, std::function<bool(const Part::Ptr &)> select, std::function<bool(const typename T::Ptr &)> filter) const | 383 | if (!mime) { |
384 | { | 384 | return true; |
385 | QVector<typename T::Ptr> ret; | 385 | } |
386 | |||
387 | if (mime->isFirstTextPart()) { | ||
388 | return true; | ||
389 | } | ||
390 | const auto cd = mime->disposition(); | ||
391 | if (cd && cd == MailMime::Inline) { | ||
392 | // explict "inline" disposition: | ||
393 | return true; | ||
394 | } | ||
395 | if (cd && cd == MailMime::Attachment) { | ||
396 | // explicit "attachment" disposition: | ||
397 | return false; | ||
398 | } | ||
399 | |||
400 | const auto ct = mime->mimetype(); | ||
401 | if (ct.name().trimmed().toLower() == "text" && ct.name().trimmed().isEmpty() && | ||
402 | (!mime || mime->filename().trimmed().isEmpty())) { | ||
403 | // text/* w/o filename parameter: | ||
404 | return true; | ||
405 | } | ||
406 | return false; | ||
407 | }); | ||
408 | } | ||
409 | |||
410 | QVector<Part::Ptr> Parser::collect(const Part::Ptr &start, std::function<bool(const Part::Ptr &)> select, std::function<bool(const Content::Ptr &)> filter) const | ||
411 | { | ||
412 | QVector<Part::Ptr> ret; | ||
386 | foreach (const auto &part, start->subParts()) { | 413 | foreach (const auto &part, start->subParts()) { |
387 | if (select(part)){ | 414 | QVector<QByteArray> contents; |
388 | const auto p = std::dynamic_pointer_cast<T>(part); | 415 | foreach(const auto &ct, part->availableContents()) { |
389 | if (p && filter(p)) { | 416 | foreach(const auto &content, part->content(ct)) { |
390 | ret.append(p); | 417 | if (filter(content)) { |
418 | contents.append(ct); | ||
419 | break; | ||
420 | } | ||
391 | } | 421 | } |
392 | ret += collect<T>(part, select, filter); | 422 | } |
423 | if (!contents.isEmpty()) { | ||
424 | ret.append(part); | ||
425 | } | ||
426 | if (select(part)){ | ||
427 | ret += collect(part, select, filter); | ||
393 | } | 428 | } |
394 | } | 429 | } |
395 | return ret; | 430 | return ret; |