summaryrefslogtreecommitdiffstats
path: root/framework/mail/maillistmodel.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-21 11:36:43 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-21 11:36:43 +0100
commitbf96cfa0d75d256e036c76ec64f0f456014f2739 (patch)
tree3ab0ff603dfccb9f28040af3a1559b01af09aa3f /framework/mail/maillistmodel.cpp
parente4e11ba46f4ccce5f9ca63ab758a132d945061e8 (diff)
parent9a3059769a0bf9dbf81e523c9245d2aa98420bb5 (diff)
downloadkube-bf96cfa0d75d256e036c76ec64f0f456014f2739.tar.gz
kube-bf96cfa0d75d256e036c76ec64f0f456014f2739.zip
Merge remote-tracking branch 'origin/dev/libotp' into develop
Conflicts: framework/mail/CMakeLists.txt
Diffstat (limited to 'framework/mail/maillistmodel.cpp')
-rw-r--r--framework/mail/maillistmodel.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/framework/mail/maillistmodel.cpp b/framework/mail/maillistmodel.cpp
index 3ed50ad6..2314e155 100644
--- a/framework/mail/maillistmodel.cpp
+++ b/framework/mail/maillistmodel.cpp
@@ -20,7 +20,13 @@
20 20
21#include "maillistmodel.h" 21#include "maillistmodel.h"
22 22
23#include "stringhtmlwriter.h"
24#include "objecttreesource.h"
25
23#include <QFile> 26#include <QFile>
27#include <QImage>
28#include <KF5/MessageViewer/ObjectTreeParser>
29#include <KF5/MessageViewer/CSSHelperBase>
24 30
25MailListModel::MailListModel(QObject *parent) 31MailListModel::MailListModel(QObject *parent)
26 : QIdentityProxyModel() 32 : QIdentityProxyModel()
@@ -45,6 +51,7 @@ QHash< int, QByteArray > MailListModel::roleNames() const
45 roles[Important] = "important"; 51 roles[Important] = "important";
46 roles[Id] = "id"; 52 roles[Id] = "id";
47 roles[MimeMessage] = "mimeMessage"; 53 roles[MimeMessage] = "mimeMessage";
54 roles[RenderedMessage] = "renderedMessage";
48 roles[DomainObject] = "domainObject"; 55 roles[DomainObject] = "domainObject";
49 56
50 return roles; 57 return roles;
@@ -81,6 +88,37 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const
81 } 88 }
82 return "Failed to read mail."; 89 return "Failed to read mail.";
83 } 90 }
91 case RenderedMessage: {
92 auto filename = srcIdx.sibling(srcIdx.row(), 6).data(Qt::DisplayRole).toString();
93 QFile file(filename);
94 if (file.open(QFile::ReadOnly)) {
95 const auto mailData = KMime::CRLFtoLF(file.readAll());
96 KMime::Message::Ptr msg(new KMime::Message);
97 msg->setContent(mailData);
98 msg->parse();
99
100 // render the mail
101 StringHtmlWriter htmlWriter;
102 QImage paintDevice;
103 MessageViewer::CSSHelperBase cssHelper(&paintDevice);
104 MessageViewer::NodeHelper nodeHelper;
105 ObjectTreeSource source(&htmlWriter, &cssHelper);
106 MessageViewer::ObjectTreeParser otp(&source, &nodeHelper);
107
108 htmlWriter.begin(QString());
109 htmlWriter.queue(cssHelper.htmlHead(false));
110
111 otp.parseObjectTree(msg.data());
112
113 htmlWriter.queue(QStringLiteral("</body></html>"));
114 htmlWriter.end();
115
116 return htmlWriter.html();
117 } else {
118 qWarning() << "Failed to open the file";
119 }
120 return "Failed to read mail.";
121 }
84 } 122 }
85 return QIdentityProxyModel::data(idx, role); 123 return QIdentityProxyModel::data(idx, role);
86} 124}