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 /framework/domain/messageparser_new.cpp | |
parent | b7a02699eefd84c68ff602bfea91640faec5c4ef (diff) | |
download | kube-1fe0ab05ae2bfe6505736f598bd535a71fb86a6f.tar.gz kube-1fe0ab05ae2bfe6505736f598bd535a71fb86a6f.zip |
replace cid links with actuall content of the images
Diffstat (limited to 'framework/domain/messageparser_new.cpp')
-rw-r--r-- | framework/domain/messageparser_new.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
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 | } |