diff options
author | Sandro Knauß <sknauss@kde.org> | 2016-10-17 15:35:49 +0200 |
---|---|---|
committer | Sandro Knauß <sknauss@kde.org> | 2016-10-17 15:35:49 +0200 |
commit | 1fe0ab05ae2bfe6505736f598bd535a71fb86a6f (patch) | |
tree | 76dff09eb994375624f3c3d2754f808642a019e2 | |
parent | b7a02699eefd84c68ff602bfea91640faec5c4ef (diff) | |
download | kube-1fe0ab05ae2bfe6505736f598bd535a71fb86a6f.tar.gz kube-1fe0ab05ae2bfe6505736f598bd535a71fb86a6f.zip |
replace cid links with actuall content of the images
-rw-r--r-- | framework/domain/messageparser.h | 3 | ||||
-rw-r--r-- | framework/domain/messageparser_new.cpp | 33 | ||||
-rw-r--r-- | framework/domain/messageparser_old.cpp | 23 | ||||
-rw-r--r-- | framework/domain/mimetreeparser/interface.cpp | 11 | ||||
-rw-r--r-- | framework/domain/mimetreeparser/interface.h | 2 |
5 files changed, 60 insertions, 12 deletions
diff --git a/framework/domain/messageparser.h b/framework/domain/messageparser.h index b3d7537d..5eb355e7 100644 --- a/framework/domain/messageparser.h +++ b/framework/domain/messageparser.h | |||
@@ -97,7 +97,7 @@ private: | |||
97 | class NewContentModel : public QAbstractItemModel { | 97 | class NewContentModel : public QAbstractItemModel { |
98 | Q_OBJECT | 98 | Q_OBJECT |
99 | public: | 99 | public: |
100 | NewContentModel (const PartPtr &part); | 100 | NewContentModel (const PartPtr &part, const std::shared_ptr<Parser> &parser); |
101 | 101 | ||
102 | public: | 102 | public: |
103 | enum Roles { | 103 | enum Roles { |
@@ -116,6 +116,7 @@ public: | |||
116 | 116 | ||
117 | private: | 117 | private: |
118 | const PartPtr &mPart; | 118 | const PartPtr &mPart; |
119 | const std::shared_ptr<Parser> &mParser; | ||
119 | }; | 120 | }; |
120 | 121 | ||
121 | class NewModel : public QAbstractItemModel { | 122 | class NewModel : public QAbstractItemModel { |
diff --git a/framework/domain/messageparser_new.cpp b/framework/domain/messageparser_new.cpp index d1b956f5..4395f2e3 100644 --- a/framework/domain/messageparser_new.cpp +++ b/framework/domain/messageparser_new.cpp | |||
@@ -26,7 +26,7 @@ NewModel::NewModel(std::shared_ptr<Parser> parser) | |||
26 | { | 26 | { |
27 | mParts = mParser->collectContentParts(); | 27 | mParts = mParser->collectContentParts(); |
28 | foreach(const auto &part, mParts) { | 28 | foreach(const auto &part, mParts) { |
29 | mContentMap.insert(part.get(), std::shared_ptr<NewContentModel>(new NewContentModel(part))); | 29 | mContentMap.insert(part.get(), std::shared_ptr<NewContentModel>(new NewContentModel(part, mParser))); |
30 | } | 30 | } |
31 | } | 31 | } |
32 | 32 | ||
@@ -87,8 +87,9 @@ int NewModel::columnCount(const QModelIndex &parent) const | |||
87 | return 1; | 87 | return 1; |
88 | } | 88 | } |
89 | 89 | ||
90 | NewContentModel::NewContentModel(const Part::Ptr &part) | 90 | NewContentModel::NewContentModel(const Part::Ptr &part, const std::shared_ptr<Parser> &parser) |
91 | : mPart(part) | 91 | : mPart(part) |
92 | , mParser(parser) | ||
92 | { | 93 | { |
93 | } | 94 | } |
94 | 95 | ||
@@ -121,8 +122,32 @@ QVariant NewContentModel::data(const QModelIndex &index, int role) const | |||
121 | return QString::fromLatin1(content->type()); | 122 | return QString::fromLatin1(content->type()); |
122 | case IsEmbededRole: | 123 | case IsEmbededRole: |
123 | return false; | 124 | return false; |
124 | case ContentRole: | 125 | case ContentRole: { |
125 | return content->encodedContent(); | 126 | auto text = content->encodedContent(); |
127 | if (data(index, TypeRole).toString() == "HtmlContent") { | ||
128 | const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"); | ||
129 | int pos = 0; | ||
130 | while ((pos = rx.indexIn(text, pos)) != -1) { | ||
131 | const auto link = QUrl(rx.cap(3).toUtf8()); | ||
132 | pos += rx.matchedLength(); | ||
133 | const auto repl = mParser->getPart(link); | ||
134 | if (!repl) { | ||
135 | continue; | ||
136 | } | ||
137 | const auto content = repl->content(); | ||
138 | if(content.size() < 1) { | ||
139 | continue; | ||
140 | } | ||
141 | const auto mailMime = content.first()->mailMime(); | ||
142 | const auto mimetype = mailMime->mimetype().name(); | ||
143 | if (mimetype.startsWith("image/")) { | ||
144 | const auto data = content.first()->content(); | ||
145 | text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64()))); | ||
146 | } | ||
147 | } | ||
148 | } | ||
149 | return text; | ||
150 | } | ||
126 | case SecurityLevelRole: | 151 | case SecurityLevelRole: |
127 | return content->encryptions().size() > mPart->encryptions().size() ? "red": "black"; //test for gpg inline | 152 | return content->encryptions().size() > mPart->encryptions().size() ? "red": "black"; //test for gpg inline |
128 | } | 153 | } |
diff --git a/framework/domain/messageparser_old.cpp b/framework/domain/messageparser_old.cpp index a364c8ab..a4247d8c 100644 --- a/framework/domain/messageparser_old.cpp +++ b/framework/domain/messageparser_old.cpp | |||
@@ -64,14 +64,25 @@ QVariant PartModel::data(const QModelIndex &index, int role) const | |||
64 | // qDebug() << "Getting text: " << part->property("text").toString(); | 64 | // qDebug() << "Getting text: " << part->property("text").toString(); |
65 | // FIXME: we should have a list per part, and not one for all parts. | 65 | // FIXME: we should have a list per part, and not one for all parts. |
66 | auto text = part->property("htmlContent").toString(); | 66 | auto text = part->property("htmlContent").toString(); |
67 | auto rx = QRegExp("src=(\"|')cid:([^\1]*)\1"); | 67 | const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"); |
68 | int pos = 0; | 68 | int pos = 0; |
69 | while ((pos = rx.indexIn(text, pos)) != -1) { | 69 | while ((pos = rx.indexIn(text, pos)) != -1) { |
70 | auto repl = mParser->getPart(rx.cap(2).toUtf8()); | 70 | const auto link = QUrl(rx.cap(3).toUtf8()); |
71 | if (repl.isValid()) { | ||
72 | text.replace(rx.cap(0), QString("src=\"%1\"").arg(repl.toString())); | ||
73 | } | ||
74 | pos += rx.matchedLength(); | 71 | pos += rx.matchedLength(); |
72 | const auto repl = mParser->getPart(link); | ||
73 | if (!repl) { | ||
74 | continue; | ||
75 | } | ||
76 | const auto content = repl->content(); | ||
77 | if(content.size() < 1) { | ||
78 | continue; | ||
79 | } | ||
80 | const auto mailMime = content.first()->mailMime(); | ||
81 | const auto mimetype = mailMime->mimetype().name(); | ||
82 | if (mimetype.startsWith("image/")) { | ||
83 | const auto data = content.first()->content(); | ||
84 | text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64()))); | ||
85 | } | ||
75 | } | 86 | } |
76 | return text; | 87 | return text; |
77 | } | 88 | } |
diff --git a/framework/domain/mimetreeparser/interface.cpp b/framework/domain/mimetreeparser/interface.cpp index c2fd1e65..b5e29e6b 100644 --- a/framework/domain/mimetreeparser/interface.cpp +++ b/framework/domain/mimetreeparser/interface.cpp | |||
@@ -143,6 +143,15 @@ MailMime::Ptr MailMime::parent() const | |||
143 | return d->parent; | 143 | return d->parent; |
144 | } | 144 | } |
145 | 145 | ||
146 | QByteArray MailMime::decodedContent() const | ||
147 | { | ||
148 | if (!d->mNode) { | ||
149 | return QByteArray(); | ||
150 | } | ||
151 | return d->mNode->decodedContent(); | ||
152 | } | ||
153 | |||
154 | |||
146 | class PartPrivate | 155 | class PartPrivate |
147 | { | 156 | { |
148 | public: | 157 | public: |
@@ -581,7 +590,7 @@ void SinglePartPrivate::fillFrom(MimeTreeParser::AttachmentMessagePart::Ptr part | |||
581 | q->reachParentD()->createMailMime(part.staticCast<MimeTreeParser::TextMessagePart>()); | 590 | q->reachParentD()->createMailMime(part.staticCast<MimeTreeParser::TextMessagePart>()); |
582 | mType = q->mailMime()->mimetype().name().toUtf8(); | 591 | mType = q->mailMime()->mimetype().name().toUtf8(); |
583 | mContent.clear(); | 592 | mContent.clear(); |
584 | mContent.append(std::make_shared<Content>(part->text().toLocal8Bit(), q)); | 593 | mContent.append(std::make_shared<Content>(q->mailMime()->decodedContent(), q)); |
585 | } | 594 | } |
586 | 595 | ||
587 | SinglePart::SinglePart() | 596 | SinglePart::SinglePart() |
diff --git a/framework/domain/mimetreeparser/interface.h b/framework/domain/mimetreeparser/interface.h index cc6c68d2..f88271af 100644 --- a/framework/domain/mimetreeparser/interface.h +++ b/framework/domain/mimetreeparser/interface.h | |||
@@ -100,6 +100,8 @@ public: | |||
100 | // overwrite default charset with given charset | 100 | // overwrite default charset with given charset |
101 | QString encodedContent(QByteArray charset) const; | 101 | QString encodedContent(QByteArray charset) const; |
102 | 102 | ||
103 | QByteArray decodedContent() const; | ||
104 | |||
103 | bool isFirstTextPart() const; | 105 | bool isFirstTextPart() const; |
104 | bool isFirstPart() const; | 106 | bool isFirstPart() const; |
105 | bool isTopLevelPart() const; | 107 | bool isTopLevelPart() const; |