summaryrefslogtreecommitdiffstats
path: root/framework/domain/messageparser_old.cpp
diff options
context:
space:
mode:
authorSandro Knauß <sknauss@kde.org>2016-10-17 15:35:49 +0200
committerSandro Knauß <sknauss@kde.org>2016-10-17 15:35:49 +0200
commit1fe0ab05ae2bfe6505736f598bd535a71fb86a6f (patch)
tree76dff09eb994375624f3c3d2754f808642a019e2 /framework/domain/messageparser_old.cpp
parentb7a02699eefd84c68ff602bfea91640faec5c4ef (diff)
downloadkube-1fe0ab05ae2bfe6505736f598bd535a71fb86a6f.tar.gz
kube-1fe0ab05ae2bfe6505736f598bd535a71fb86a6f.zip
replace cid links with actuall content of the images
Diffstat (limited to 'framework/domain/messageparser_old.cpp')
-rw-r--r--framework/domain/messageparser_old.cpp23
1 files changed, 17 insertions, 6 deletions
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 }