diff options
author | Sandro Knauß <sknauss@kde.org> | 2016-08-02 09:32:12 +0200 |
---|---|---|
committer | Sandro Knauß <sknauss@kde.org> | 2016-08-02 09:32:12 +0200 |
commit | a34e14a57c7726a99e63d767935379cba1ff6ea2 (patch) | |
tree | b583a44661d619d3baf9b41a934af13f3e1c42c5 | |
parent | 0f67cb5f9851af4e444c41d9f7b8d88350ec2e09 (diff) | |
download | kube-a34e14a57c7726a99e63d767935379cba1ff6ea2.tar.gz kube-a34e14a57c7726a99e63d767935379cba1ff6ea2.zip |
Implement the interface
-rw-r--r-- | framework/domain/mimetreeparser/interface.cpp | 83 | ||||
-rw-r--r-- | framework/domain/mimetreeparser/interface.h | 13 | ||||
-rw-r--r-- | framework/domain/mimetreeparser/interface_p.h | 7 |
3 files changed, 94 insertions, 9 deletions
diff --git a/framework/domain/mimetreeparser/interface.cpp b/framework/domain/mimetreeparser/interface.cpp index a76a6cde..4f45b883 100644 --- a/framework/domain/mimetreeparser/interface.cpp +++ b/framework/domain/mimetreeparser/interface.cpp | |||
@@ -47,12 +47,20 @@ MailMime::MailMime() | |||
47 | 47 | ||
48 | bool MailMime::isFirstTextPart() const | 48 | bool MailMime::isFirstTextPart() const |
49 | { | 49 | { |
50 | if (!d->mNode) { | 50 | if (!d->mNode || !d->mNode->topLevel()) { |
51 | return false; | 51 | return false; |
52 | } | 52 | } |
53 | return (d->mNode->topLevel()->textContent() == d->mNode); | 53 | return (d->mNode->topLevel()->textContent() == d->mNode); |
54 | } | 54 | } |
55 | 55 | ||
56 | bool MailMime::isTopLevelPart() const | ||
57 | { | ||
58 | if (!d->mNode) { | ||
59 | return false; | ||
60 | } | ||
61 | return (d->mNode->topLevel() == d->mNode); | ||
62 | } | ||
63 | |||
56 | MailMime::Disposition MailMime::disposition() const | 64 | MailMime::Disposition MailMime::disposition() const |
57 | { | 65 | { |
58 | if (!d->mNode) { | 66 | if (!d->mNode) { |
@@ -110,6 +118,10 @@ public: | |||
110 | Part *parent() const; | 118 | Part *parent() const; |
111 | 119 | ||
112 | const MailMime::Ptr &mailMime() const; | 120 | const MailMime::Ptr &mailMime() const; |
121 | void createMailMime(const MimeTreeParser::MimeMessagePart::Ptr &part); | ||
122 | void createMailMime(const MimeTreeParser::TextMessagePart::Ptr &part); | ||
123 | void createMailMime(const MimeTreeParser::AlternativeMessagePart::Ptr &part); | ||
124 | void createMailMime(const MimeTreeParser::HtmlMessagePart::Ptr &part); | ||
113 | private: | 125 | private: |
114 | Part *q; | 126 | Part *q; |
115 | Part *mParent; | 127 | Part *mParent; |
@@ -124,6 +136,30 @@ PartPrivate::PartPrivate(Part* part) | |||
124 | 136 | ||
125 | } | 137 | } |
126 | 138 | ||
139 | void PartPrivate::createMailMime(const MimeTreeParser::HtmlMessagePart::Ptr& part) | ||
140 | { | ||
141 | mMailMime = MailMime::Ptr(new MailMime); | ||
142 | mMailMime->d->mNode = part->mNode; | ||
143 | } | ||
144 | |||
145 | void PartPrivate::createMailMime(const MimeTreeParser::AlternativeMessagePart::Ptr& part) | ||
146 | { | ||
147 | mMailMime = MailMime::Ptr(new MailMime); | ||
148 | mMailMime->d->mNode = part->mNode; | ||
149 | } | ||
150 | |||
151 | void PartPrivate::createMailMime(const MimeTreeParser::TextMessagePart::Ptr& part) | ||
152 | { | ||
153 | mMailMime = MailMime::Ptr(new MailMime); | ||
154 | mMailMime->d->mNode = part->mNode; | ||
155 | } | ||
156 | |||
157 | void PartPrivate::createMailMime(const MimeTreeParser::MimeMessagePart::Ptr& part) | ||
158 | { | ||
159 | mMailMime = MailMime::Ptr(new MailMime); | ||
160 | mMailMime->d->mNode = part->mNode; | ||
161 | } | ||
162 | |||
127 | void PartPrivate::appendSubPart(Part::Ptr subpart) | 163 | void PartPrivate::appendSubPart(Part::Ptr subpart) |
128 | { | 164 | { |
129 | subpart->d->mParent = q; | 165 | subpart->d->mParent = q; |
@@ -262,7 +298,16 @@ QByteArray Content::type() const | |||
262 | 298 | ||
263 | MailMime::Ptr Content::mailMime() const | 299 | MailMime::Ptr Content::mailMime() const |
264 | { | 300 | { |
265 | return d->mMailMime; | 301 | if (d->mMailMime) { |
302 | return d->mMailMime; | ||
303 | } else { | ||
304 | return d->mParent->mailMime(); | ||
305 | } | ||
306 | } | ||
307 | |||
308 | Part *Content::parent() const | ||
309 | { | ||
310 | return d->mParent; | ||
266 | } | 311 | } |
267 | 312 | ||
268 | HtmlContent::HtmlContent(const QByteArray& content, Part* parent) | 313 | HtmlContent::HtmlContent(const QByteArray& content, Part* parent) |
@@ -311,6 +356,7 @@ void AlternativePartPrivate::fillFrom(MimeTreeParser::AlternativeMessagePart::Pt | |||
311 | mContent["html"].append(content); | 356 | mContent["html"].append(content); |
312 | content = std::make_shared<PlainTextContent>(part->plaintextContent().toLocal8Bit(), q); | 357 | content = std::make_shared<PlainTextContent>(part->plaintextContent().toLocal8Bit(), q); |
313 | mContent["plaintext"].append(content); | 358 | mContent["plaintext"].append(content); |
359 | q->reachParentD()->createMailMime(part); | ||
314 | } | 360 | } |
315 | 361 | ||
316 | QVector<QByteArray> AlternativePartPrivate::types() const | 362 | QVector<QByteArray> AlternativePartPrivate::types() const |
@@ -349,6 +395,11 @@ QVector<Content::Ptr> AlternativePart::content(const QByteArray& ct) const | |||
349 | return d->content(ct); | 395 | return d->content(ct); |
350 | } | 396 | } |
351 | 397 | ||
398 | PartPrivate* AlternativePart::reachParentD() const | ||
399 | { | ||
400 | return Part::d.get(); | ||
401 | } | ||
402 | |||
352 | class SinglePartPrivate | 403 | class SinglePartPrivate |
353 | { | 404 | { |
354 | public: | 405 | public: |
@@ -367,6 +418,7 @@ void SinglePartPrivate::fillFrom(MimeTreeParser::TextMessagePart::Ptr part) | |||
367 | mContent.clear(); | 418 | mContent.clear(); |
368 | foreach (const auto &mp, part->subParts()) { | 419 | foreach (const auto &mp, part->subParts()) { |
369 | mContent.append(std::make_shared<PlainTextContent>(mp->text().toLocal8Bit(), q)); | 420 | mContent.append(std::make_shared<PlainTextContent>(mp->text().toLocal8Bit(), q)); |
421 | q->reachParentD()->createMailMime(part); | ||
370 | } | 422 | } |
371 | } | 423 | } |
372 | 424 | ||
@@ -375,11 +427,12 @@ void SinglePartPrivate::fillFrom(MimeTreeParser::HtmlMessagePart::Ptr part) | |||
375 | mType = "html"; | 427 | mType = "html"; |
376 | mContent.clear(); | 428 | mContent.clear(); |
377 | mContent.append(std::make_shared<HtmlContent>(part->text().toLocal8Bit(), q)); | 429 | mContent.append(std::make_shared<HtmlContent>(part->text().toLocal8Bit(), q)); |
430 | q->reachParentD()->createMailMime(part); | ||
378 | } | 431 | } |
379 | 432 | ||
380 | void SinglePartPrivate::fillFrom(MimeTreeParser::AttachmentMessagePart::Ptr part) | 433 | void SinglePartPrivate::fillFrom(MimeTreeParser::AttachmentMessagePart::Ptr part) |
381 | { | 434 | { |
382 | 435 | q->reachParentD()->createMailMime(part.staticCast<MimeTreeParser::TextMessagePart>()); | |
383 | } | 436 | } |
384 | 437 | ||
385 | SinglePart::SinglePart() | 438 | SinglePart::SinglePart() |
@@ -411,6 +464,11 @@ QByteArray SinglePart::type() const | |||
411 | return "SinglePart"; | 464 | return "SinglePart"; |
412 | } | 465 | } |
413 | 466 | ||
467 | PartPrivate* SinglePart::reachParentD() const | ||
468 | { | ||
469 | return Part::d.get(); | ||
470 | } | ||
471 | |||
414 | ParserPrivate::ParserPrivate(Parser* parser) | 472 | ParserPrivate::ParserPrivate(Parser* parser) |
415 | : q(parser) | 473 | : q(parser) |
416 | , mNodeHelper(std::make_shared<MimeTreeParser::NodeHelper>()) | 474 | , mNodeHelper(std::make_shared<MimeTreeParser::NodeHelper>()) |
@@ -421,16 +479,16 @@ ParserPrivate::ParserPrivate(Parser* parser) | |||
421 | void ParserPrivate::setMessage(const QByteArray& mimeMessage) | 479 | void ParserPrivate::setMessage(const QByteArray& mimeMessage) |
422 | { | 480 | { |
423 | const auto mailData = KMime::CRLFtoLF(mimeMessage); | 481 | const auto mailData = KMime::CRLFtoLF(mimeMessage); |
424 | KMime::Message::Ptr msg(new KMime::Message); | 482 | mMsg = KMime::Message::Ptr(new KMime::Message); |
425 | msg->setContent(mailData); | 483 | mMsg->setContent(mailData); |
426 | msg->parse(); | 484 | mMsg->parse(); |
427 | 485 | ||
428 | // render the mail | 486 | // render the mail |
429 | StringHtmlWriter htmlWriter; | 487 | StringHtmlWriter htmlWriter; |
430 | ObjectTreeSource source(&htmlWriter); | 488 | ObjectTreeSource source(&htmlWriter); |
431 | MimeTreeParser::ObjectTreeParser otp(&source, mNodeHelper.get()); | 489 | MimeTreeParser::ObjectTreeParser otp(&source, mNodeHelper.get()); |
432 | 490 | ||
433 | otp.parseObjectTree(msg.data()); | 491 | otp.parseObjectTree(mMsg.data()); |
434 | mPartTree = otp.parsedPart().dynamicCast<MimeTreeParser::MessagePart>(); | 492 | mPartTree = otp.parsedPart().dynamicCast<MimeTreeParser::MessagePart>(); |
435 | 493 | ||
436 | mEmbeddedPartMap = htmlWriter.embeddedParts(); | 494 | mEmbeddedPartMap = htmlWriter.embeddedParts(); |
@@ -494,6 +552,16 @@ QVector<Part::Ptr> Parser::collectContentParts() const | |||
494 | if (mime->isFirstTextPart()) { | 552 | if (mime->isFirstTextPart()) { |
495 | return true; | 553 | return true; |
496 | } | 554 | } |
555 | |||
556 | { | ||
557 | const auto parent = content->parent(); | ||
558 | if (parent) { | ||
559 | const auto _mime = parent->mailMime(); | ||
560 | if (_mime && (_mime->isTopLevelPart() || _mime->isFirstTextPart())) { | ||
561 | return true; | ||
562 | } | ||
563 | } | ||
564 | } | ||
497 | const auto cd = mime->disposition(); | 565 | const auto cd = mime->disposition(); |
498 | if (cd && cd == MailMime::Inline) { | 566 | if (cd && cd == MailMime::Inline) { |
499 | // explict "inline" disposition: | 567 | // explict "inline" disposition: |
@@ -526,6 +594,7 @@ QVector<Part::Ptr> Parser::collect(const Part::Ptr &start, std::function<bool(co | |||
526 | break; | 594 | break; |
527 | } | 595 | } |
528 | } | 596 | } |
597 | qWarning() << ct << contents.size(); | ||
529 | } | 598 | } |
530 | if (!contents.isEmpty()) { | 599 | if (!contents.isEmpty()) { |
531 | ret.append(part); | 600 | ret.append(part); |
diff --git a/framework/domain/mimetreeparser/interface.h b/framework/domain/mimetreeparser/interface.h index c71b86d6..a6a7f39d 100644 --- a/framework/domain/mimetreeparser/interface.h +++ b/framework/domain/mimetreeparser/interface.h | |||
@@ -96,9 +96,12 @@ public: | |||
96 | QString encodedContent(QByteArray charset) const; | 96 | QString encodedContent(QByteArray charset) const; |
97 | 97 | ||
98 | bool isFirstTextPart() const; | 98 | bool isFirstTextPart() const; |
99 | bool isTopLevelPart() const; | ||
99 | 100 | ||
100 | private: | 101 | private: |
101 | std::unique_ptr<MailMimePrivate> d; | 102 | std::unique_ptr<MailMimePrivate> d; |
103 | |||
104 | friend class PartPrivate; | ||
102 | }; | 105 | }; |
103 | 106 | ||
104 | class Content | 107 | class Content |
@@ -122,6 +125,7 @@ public: | |||
122 | virtual QVector<Encryption> encryptions() const; | 125 | virtual QVector<Encryption> encryptions() const; |
123 | MailMime::Ptr mailMime() const; | 126 | MailMime::Ptr mailMime() const; |
124 | virtual QByteArray type() const; | 127 | virtual QByteArray type() const; |
128 | Part* parent() const; | ||
125 | private: | 129 | private: |
126 | std::unique_ptr<ContentPrivate> d; | 130 | std::unique_ptr<ContentPrivate> d; |
127 | }; | 131 | }; |
@@ -188,8 +192,9 @@ public: | |||
188 | virtual QVector<Signature> signatures() const; | 192 | virtual QVector<Signature> signatures() const; |
189 | virtual QVector<Encryption> encryptions() const; | 193 | virtual QVector<Encryption> encryptions() const; |
190 | virtual MailMime::Ptr mailMime() const; | 194 | virtual MailMime::Ptr mailMime() const; |
191 | private: | 195 | protected: |
192 | std::unique_ptr<PartPrivate> d; | 196 | std::unique_ptr<PartPrivate> d; |
197 | private: | ||
193 | friend class ParserPrivate; | 198 | friend class ParserPrivate; |
194 | friend class PartPrivate; | 199 | friend class PartPrivate; |
195 | }; | 200 | }; |
@@ -208,9 +213,11 @@ public: | |||
208 | QByteArray type() const Q_DECL_OVERRIDE; | 213 | QByteArray type() const Q_DECL_OVERRIDE; |
209 | 214 | ||
210 | private: | 215 | private: |
216 | PartPrivate *reachParentD() const; | ||
211 | std::unique_ptr<AlternativePartPrivate> d; | 217 | std::unique_ptr<AlternativePartPrivate> d; |
212 | 218 | ||
213 | friend class ParserPrivate; | 219 | friend class ParserPrivate; |
220 | friend class AlternativePartPrivate; | ||
214 | }; | 221 | }; |
215 | 222 | ||
216 | class SinglePart : public Part | 223 | class SinglePart : public Part |
@@ -226,9 +233,11 @@ class SinglePart : public Part | |||
226 | 233 | ||
227 | QByteArray type() const Q_DECL_OVERRIDE; | 234 | QByteArray type() const Q_DECL_OVERRIDE; |
228 | private: | 235 | private: |
236 | PartPrivate *reachParentD() const; | ||
229 | std::unique_ptr<SinglePartPrivate> d; | 237 | std::unique_ptr<SinglePartPrivate> d; |
230 | 238 | ||
231 | friend class ParserPrivate; | 239 | friend class ParserPrivate; |
240 | friend class SinglePartPrivate; | ||
232 | }; | 241 | }; |
233 | 242 | ||
234 | 243 | ||
diff --git a/framework/domain/mimetreeparser/interface_p.h b/framework/domain/mimetreeparser/interface_p.h index f83af6eb..004a50d0 100644 --- a/framework/domain/mimetreeparser/interface_p.h +++ b/framework/domain/mimetreeparser/interface_p.h | |||
@@ -24,6 +24,12 @@ | |||
24 | #include <QSharedPointer> | 24 | #include <QSharedPointer> |
25 | #include <QMap> | 25 | #include <QMap> |
26 | 26 | ||
27 | namespace KMime | ||
28 | { | ||
29 | class Message; | ||
30 | typedef QSharedPointer<Message> MessagePtr; | ||
31 | } | ||
32 | |||
27 | namespace MimeTreeParser | 33 | namespace MimeTreeParser |
28 | { | 34 | { |
29 | class MessagePart; | 35 | class MessagePart; |
@@ -44,6 +50,7 @@ private: | |||
44 | Parser *q; | 50 | Parser *q; |
45 | 51 | ||
46 | MimeTreeParser::MessagePartPtr mPartTree; | 52 | MimeTreeParser::MessagePartPtr mPartTree; |
53 | KMime::MessagePtr mMsg; | ||
47 | std::shared_ptr<MimeTreeParser::NodeHelper> mNodeHelper; | 54 | std::shared_ptr<MimeTreeParser::NodeHelper> mNodeHelper; |
48 | QString mHtml; | 55 | QString mHtml; |
49 | QMap<QByteArray, QUrl> mEmbeddedPartMap; | 56 | QMap<QByteArray, QUrl> mEmbeddedPartMap; |