summaryrefslogtreecommitdiffstats
path: root/framework/domain/mimetreeparser/interface.cpp
diff options
context:
space:
mode:
authorSandro Knauß <sknauss@kde.org>2016-07-22 13:23:17 +0200
committerSandro Knauß <sknauss@kde.org>2016-07-22 13:23:17 +0200
commit903960116eb3329631702723bba11f5463eff573 (patch)
tree84e80e507289cfcb633ad09ffed03a2b1d077e83 /framework/domain/mimetreeparser/interface.cpp
parentcf5b3e797421e7dbf2c0d7b1efff91fc07277652 (diff)
downloadkube-903960116eb3329631702723bba11f5463eff573.tar.gz
kube-903960116eb3329631702723bba11f5463eff573.zip
fixes the build issues
Diffstat (limited to 'framework/domain/mimetreeparser/interface.cpp')
-rw-r--r--framework/domain/mimetreeparser/interface.cpp103
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
144QVector< Encryption > Content::encryptions() const 144QVector<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
152QVector< Signature > Content::signatures() const 152QVector<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
170HtmlContent::HtmlContent(const QByteArray& content, Part* parent)
171 : Content(content, parent)
172{
173
174}
175
176PlainTextContent::PlainTextContent(const QByteArray& content, Part* parent)
177 : Content(content, parent)
178{
179
180}
181
182
170class AlternativePartPrivate 183class AlternativePartPrivate
171{ 184{
172public: 185public:
@@ -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
227QVector<Content::Ptr> AlternativePart::content() const
228{
229 return d->content(availableContents().first());
230}
231
232QVector<Content::Ptr> AlternativePart::content(const QByteArray& ct) const 240QVector<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
286QVector< Content::Ptr > SinglePart::content() const 294QVector< 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
291QByteArray SinglePart::type() const 302QByteArray SinglePart::type() const
@@ -293,17 +304,6 @@ QByteArray SinglePart::type() const
293 return "SinglePart"; 304 return "SinglePart";
294} 305}
295 306
296class MimePartPrivate
297{
298public:
299 void fillFrom(MimeTreeParser::MessagePart::Ptr part);
300};
301
302QByteArray MimePart::type() const
303{
304 return "MimePart";
305}
306
307ParserPrivate::ParserPrivate(Parser* parser) 307ParserPrivate::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
377QVector<Part::Ptr> Parser::collectContentParts() const 377QVector<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();
382template <typename T> 382
383QVector<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
410QVector<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;