summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--applications/kube-mail/package/contents/ui/SingleMailView.qml5
-rw-r--r--framework/CMakeLists.txt10
-rw-r--r--framework/mail/CMakeLists.txt5
-rw-r--r--framework/mail/maillistmodel.cpp38
-rw-r--r--framework/mail/maillistmodel.h3
-rw-r--r--framework/mail/objecttreesource.cpp144
-rw-r--r--framework/mail/objecttreesource.h57
-rw-r--r--framework/mail/stringhtmlwriter.cpp134
-rw-r--r--framework/mail/stringhtmlwriter.h68
-rw-r--r--framework/settings/CMakeLists.txt3
10 files changed, 461 insertions, 6 deletions
diff --git a/applications/kube-mail/package/contents/ui/SingleMailView.qml b/applications/kube-mail/package/contents/ui/SingleMailView.qml
index caec88dd..b6163798 100644
--- a/applications/kube-mail/package/contents/ui/SingleMailView.qml
+++ b/applications/kube-mail/package/contents/ui/SingleMailView.qml
@@ -60,8 +60,11 @@ Item {
60 text: model.subject 60 text: model.subject
61 } 61 }
62 62
63 Label { 63 /*Label {
64 text: model.mimeMessage 64 text: model.mimeMessage
65 }*/
66 Label {
67 text: model.renderedMessage
65 } 68 }
66 } 69 }
67 } 70 }
diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt
index d59061d2..0b2b505d 100644
--- a/framework/CMakeLists.txt
+++ b/framework/CMakeLists.txt
@@ -16,12 +16,22 @@ include(KDEInstallDirs)
16 16
17find_package(Qt5 COMPONENTS REQUIRED Core Qml) 17find_package(Qt5 COMPONENTS REQUIRED Core Qml)
18 18
19find_package(KF5Otp "5.1.42" CONFIG REQUIRED)
20find_package(KF5Mime "4.87.0" CONFIG REQUIRED)
21find_package(Akonadi2Common CONFIG REQUIRED)
22find_package(KF5Async)
23find_package(KF5Libkleo)
24
19set(CMAKE_AUTOMOC ON) 25set(CMAKE_AUTOMOC ON)
20add_definitions("-Wall -std=c++0x -g") 26add_definitions("-Wall -std=c++0x -g")
21include_directories(.) 27include_directories(.)
22include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/common) 28include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/common)
23include_directories(SYSTEM /work/install/include/) 29include_directories(SYSTEM /work/install/include/)
24include_directories(SYSTEM /work/install/include/KF5/) 30include_directories(SYSTEM /work/install/include/KF5/)
31include_directories(SYSTEM /work/install/include/KF5/KIconThemes)
32include_directories(SYSTEM /work/install/include/KF5/KMime)
33include_directories(SYSTEM /work/install/include/KF5/KService)
34include_directories(SYSTEM /work/install/include/KF5/KCoreAddons)
25 35
26enable_testing() 36enable_testing()
27 37
diff --git a/framework/mail/CMakeLists.txt b/framework/mail/CMakeLists.txt
index 6188c93c..9a32cc83 100644
--- a/framework/mail/CMakeLists.txt
+++ b/framework/mail/CMakeLists.txt
@@ -6,14 +6,15 @@ set(mailplugin_SRCS
6 folderlistmodel.cpp 6 folderlistmodel.cpp
7 folderlistcontroller.cpp 7 folderlistcontroller.cpp
8 actions/akonadiactions.cpp 8 actions/akonadiactions.cpp
9 objecttreesource.cpp
10 stringhtmlwriter.cpp
9) 11)
10 12
11add_library(mailplugin SHARED ${mailplugin_SRCS}) 13add_library(mailplugin SHARED ${mailplugin_SRCS})
12 14
13qt5_use_modules(mailplugin Core Quick Qml) 15qt5_use_modules(mailplugin Core Quick Qml)
14 16
15target_link_libraries(mailplugin /work/install/lib64/libakonadi2common.so actionplugin) 17target_link_libraries(mailplugin actionplugin KF5::akonadi2common KF5::Otp actionplugin)
16#target_link_libraries(mailplugin /home/mike/projects/_install/lib/x86_64-linux-gnu/libakonadi2common.so)
17 18
18install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail) 19install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail)
19install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail) 20install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail)
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}
diff --git a/framework/mail/maillistmodel.h b/framework/mail/maillistmodel.h
index 22146eac..1d56e6b8 100644
--- a/framework/mail/maillistmodel.h
+++ b/framework/mail/maillistmodel.h
@@ -47,7 +47,8 @@ public:
47 Important, 47 Important,
48 Id, 48 Id,
49 MimeMessage, 49 MimeMessage,
50 DomainObject 50 DomainObject,
51 RenderedMessage
51 }; 52 };
52 53
53 QHash<int, QByteArray> roleNames() const; 54 QHash<int, QByteArray> roleNames() const;
diff --git a/framework/mail/objecttreesource.cpp b/framework/mail/objecttreesource.cpp
new file mode 100644
index 00000000..1aca5d54
--- /dev/null
+++ b/framework/mail/objecttreesource.cpp
@@ -0,0 +1,144 @@
1/*
2 Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
3 Copyright (c) 2009 Andras Mantia <andras@kdab.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18*/
19
20#include "objecttreesource.h"
21
22#include <MessageViewer/AttachmentStrategy>
23
24class ObjectSourcePrivate
25{
26public:
27 ObjectSourcePrivate()
28 : mWriter(0)
29 , mCSSHelper(0)
30 , mAllowDecryption(false)
31 , mHtmlLoadExternal(false)
32 , mHtmlMail(false)
33 {
34
35 }
36 MessageViewer::HtmlWriter *mWriter;
37 MessageViewer::CSSHelperBase *mCSSHelper;
38 bool mAllowDecryption;
39 bool mHtmlLoadExternal;
40 bool mHtmlMail;
41};
42
43ObjectTreeSource::ObjectTreeSource(MessageViewer::HtmlWriter *writer,
44 MessageViewer::CSSHelperBase *cssHelper)
45 : MessageViewer::ObjectTreeSourceIf()
46 , d(new ObjectSourcePrivate)
47 {
48 d->mWriter = writer;
49 d->mCSSHelper = cssHelper;
50 }
51
52ObjectTreeSource::~ObjectTreeSource()
53{
54 delete d;
55}
56
57void ObjectTreeSource::setAllowDecryption(bool allowDecryption)
58{
59 d->mAllowDecryption = allowDecryption;
60}
61
62MessageViewer::HtmlWriter *ObjectTreeSource::htmlWriter()
63{
64 return d->mWriter;
65}
66MessageViewer::CSSHelperBase *ObjectTreeSource::cssHelper()
67{
68 return d->mCSSHelper;
69}
70
71bool ObjectTreeSource::htmlLoadExternal()
72{
73 return d->mHtmlLoadExternal;
74}
75
76void ObjectTreeSource::setHtmlLoadExternal(bool loadExternal)
77{
78 d->mHtmlLoadExternal = loadExternal;
79}
80
81bool ObjectTreeSource::htmlMail()
82{
83 return d->mHtmlMail;
84}
85
86void ObjectTreeSource::setHtmlMail(bool htmlMail)
87{
88 d->mHtmlMail = htmlMail;
89}
90
91bool ObjectTreeSource::decryptMessage()
92{
93 return d->mAllowDecryption;
94}
95
96bool ObjectTreeSource::showSignatureDetails()
97{
98 return true;
99}
100
101int ObjectTreeSource::levelQuote()
102{
103 return 1;
104}
105
106const QTextCodec *ObjectTreeSource::overrideCodec()
107{
108 return Q_NULLPTR;
109}
110
111QString ObjectTreeSource::createMessageHeader(KMime::Message *message)
112{
113 return QString();
114}
115
116const MessageViewer::AttachmentStrategy *ObjectTreeSource::attachmentStrategy()
117{
118 return MessageViewer::AttachmentStrategy::smart();
119}
120
121QObject *ObjectTreeSource::sourceObject()
122{
123 return Q_NULLPTR;
124}
125
126void ObjectTreeSource::setHtmlMode(MessageViewer::Util::HtmlMode mode)
127{
128 Q_UNUSED(mode);
129}
130
131bool ObjectTreeSource::autoImportKeys()
132{
133 return false;
134}
135
136bool ObjectTreeSource::showEmoticons()
137{
138 return false;
139}
140
141bool ObjectTreeSource::showExpandQuotesMark()
142{
143 return false;
144} \ No newline at end of file
diff --git a/framework/mail/objecttreesource.h b/framework/mail/objecttreesource.h
new file mode 100644
index 00000000..4823999f
--- /dev/null
+++ b/framework/mail/objecttreesource.h
@@ -0,0 +1,57 @@
1/*
2 Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
3 Copyright (c) 2009 Andras Mantia <andras@kdab.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18*/
19
20#ifndef MAILVIEWER_OBJECTTREEEMPTYSOURCE_H
21#define MAILVIEWER_OBJECTTREEEMPTYSOURCE_H
22
23#include <MessageViewer/ObjectTreeSourceIf>
24
25class QString;
26
27class ObjectSourcePrivate;
28class ObjectTreeSource : public MessageViewer::ObjectTreeSourceIf
29{
30public:
31 ObjectTreeSource(MessageViewer::HtmlWriter *writer,
32 MessageViewer::CSSHelperBase *cssHelper);
33 virtual ~ObjectTreeSource();
34 void setHtmlLoadExternal(bool loadExternal);
35 void setHtmlMail(bool htmlMail);
36 bool htmlMail() Q_DECL_OVERRIDE;
37 bool decryptMessage() Q_DECL_OVERRIDE;
38 bool htmlLoadExternal() Q_DECL_OVERRIDE;
39 bool showSignatureDetails() Q_DECL_OVERRIDE;
40 void setHtmlMode(MessageViewer::Util::HtmlMode mode) Q_DECL_OVERRIDE;
41 void setAllowDecryption(bool allowDecryption);
42 int levelQuote() Q_DECL_OVERRIDE;
43 const QTextCodec *overrideCodec() Q_DECL_OVERRIDE;
44 QString createMessageHeader(KMime::Message *message) Q_DECL_OVERRIDE;
45 const MessageViewer::AttachmentStrategy *attachmentStrategy() Q_DECL_OVERRIDE;
46 MessageViewer::HtmlWriter *htmlWriter() Q_DECL_OVERRIDE;
47 MessageViewer::CSSHelperBase *cssHelper() Q_DECL_OVERRIDE;
48 QObject *sourceObject() Q_DECL_OVERRIDE;
49 bool autoImportKeys() Q_DECL_OVERRIDE;
50 bool showEmoticons() Q_DECL_OVERRIDE;
51 bool showExpandQuotesMark() Q_DECL_OVERRIDE;
52private:
53 ObjectSourcePrivate *const d;
54};
55
56#endif
57
diff --git a/framework/mail/stringhtmlwriter.cpp b/framework/mail/stringhtmlwriter.cpp
new file mode 100644
index 00000000..2c84dc6f
--- /dev/null
+++ b/framework/mail/stringhtmlwriter.cpp
@@ -0,0 +1,134 @@
1/* -*- c++ -*-
2 filehtmlwriter.cpp
3
4 This file is part of KMail, the KDE mail client.
5 Copyright (c) 2003 Marc Mutz <mutz@kde.org>
6
7 KMail is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License, version 2, as
9 published by the Free Software Foundation.
10
11 KMail is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 In addition, as a special exception, the copyright holders give
21 permission to link the code of this program with any edition of
22 the Qt library by Trolltech AS, Norway (or with modified versions
23 of Qt that use the same license as Qt), and distribute linked
24 combinations including the two. You must obey the GNU General
25 Public License in all respects for all of the code used other than
26 Qt. If you modify this file, you may extend this exception to
27 your version of the file, but you are not obligated to do so. If
28 you do not wish to do so, delete this exception statement from
29 your version.
30*/
31
32#include "stringhtmlwriter.h"
33
34#include <QDebug>
35#include <QTextStream>
36
37StringHtmlWriter::StringHtmlWriter()
38 : MessageViewer::HtmlWriter()
39 , mState(Ended)
40{
41}
42
43StringHtmlWriter::~StringHtmlWriter()
44{
45}
46
47void StringHtmlWriter::begin(const QString &css)
48{
49 if (mState != Ended) {
50 qWarning() << "begin() called on non-ended session!";
51 reset();
52 }
53
54 mState = Begun;
55 mExtraHead.clear();
56 mHtml.clear();
57
58 if (!css.isEmpty()) {
59 write(QLatin1String("<!-- CSS Definitions \n") + css + QLatin1String("-->\n"));
60 }
61}
62
63void StringHtmlWriter::end()
64{
65 if (mState != Begun) {
66 qWarning() << "Called on non-begun or queued session!";
67 }
68
69 if (!mExtraHead.isEmpty()) {
70 insertExtraHead();
71 mExtraHead.clear();
72 }
73 mState = Ended;
74}
75
76void StringHtmlWriter::reset()
77{
78 if (mState != Ended) {
79 mHtml.clear();
80 mExtraHead.clear();
81 mState = Begun; // don't run into end()'s warning
82 end();
83 mState = Ended;
84 }
85}
86
87void StringHtmlWriter::write(const QString &str)
88{
89 if (mState != Begun) {
90 qWarning() << "Called in Ended or Queued state!";
91 }
92 mHtml.append(str);
93}
94
95void StringHtmlWriter::queue(const QString &str)
96{
97 write(str);
98}
99
100void StringHtmlWriter::flush()
101{
102 mState = Begun; // don't run into end()'s warning
103 end();
104}
105
106void StringHtmlWriter::embedPart(const QByteArray &contentId, const QString &url)
107{
108 write("<!-- embedPart(contentID=" + contentId + ", url=" + url + ") -->\n");
109}
110void StringHtmlWriter::extraHead(const QString &extraHead)
111{
112 if (mState != Ended) {
113 qWarning() << "Called on non-started session!";
114 }
115 mExtraHead.append(extraHead);
116}
117
118
119void StringHtmlWriter::insertExtraHead()
120{
121 const QString headTag(QStringLiteral("<head>"));
122 const int index = mHtml.indexOf(headTag);
123 if (index != -1) {
124 mHtml.insert(index + headTag.length(), mExtraHead);
125 }
126}
127
128QString StringHtmlWriter::html() const
129{
130 if (mState != Ended) {
131 qWarning() << "Called on non-ended session!";
132 }
133 return mHtml;
134}
diff --git a/framework/mail/stringhtmlwriter.h b/framework/mail/stringhtmlwriter.h
new file mode 100644
index 00000000..0805d027
--- /dev/null
+++ b/framework/mail/stringhtmlwriter.h
@@ -0,0 +1,68 @@
1/* -*- c++ -*-
2
3 Copyright (c) 2016 Sandro Knauß <sknauss@kde.org>
4
5 Kube is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License, version 2, as
7 published by the Free Software Foundation.
8
9 Kube is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18 In addition, as a special exception, the copyright holders give
19 permission to link the code of this program with any edition of
20 the Qt library by Trolltech AS, Norway (or with modified versions
21 of Qt that use the same license as Qt), and distribute linked
22 combinations including the two. You must obey the GNU General
23 Public License in all respects for all of the code used other than
24 Qt. If you modify this file, you may extend this exception to
25 your version of the file, but you are not obligated to do so. If
26 you do not wish to do so, delete this exception statement from
27 your version.
28*/
29
30#ifndef __KUBE_FRAMEWORK_MAIL_STRINGHTMLWRITER_H__
31#define __KUBE_FRAMEWORK_MAIL_STRINGHTMLWRITER_H__
32
33#include <MessageViewer/HtmlWriter>
34
35#include <QFile>
36#include <QTextStream>
37
38class QString;
39
40class StringHtmlWriter : public MessageViewer::HtmlWriter
41{
42public:
43 explicit StringHtmlWriter();
44 virtual ~StringHtmlWriter();
45
46 void begin(const QString &cssDefs) Q_DECL_OVERRIDE;
47 void end() Q_DECL_OVERRIDE;
48 void reset() Q_DECL_OVERRIDE;
49 void write(const QString &str) Q_DECL_OVERRIDE;
50 void queue(const QString &str) Q_DECL_OVERRIDE;
51 void flush() Q_DECL_OVERRIDE;
52 void embedPart(const QByteArray &contentId, const QString &url) Q_DECL_OVERRIDE;
53 void extraHead(const QString &str) Q_DECL_OVERRIDE;
54
55 QString html() const;
56private:
57 void insertExtraHead();
58
59 QString mHtml;
60 QString mExtraHead;
61 enum State {
62 Begun,
63 Queued,
64 Ended
65 } mState;
66};
67
68#endif // __MESSAGEVIEWER_FILEHTMLWRITER_H__
diff --git a/framework/settings/CMakeLists.txt b/framework/settings/CMakeLists.txt
index b0a8fe28..5d61851f 100644
--- a/framework/settings/CMakeLists.txt
+++ b/framework/settings/CMakeLists.txt
@@ -9,8 +9,7 @@ add_library(settingsplugin SHARED ${settingsplugin_SRCS})
9 9
10qt5_use_modules(settingsplugin Core Quick Qml) 10qt5_use_modules(settingsplugin Core Quick Qml)
11 11
12target_link_libraries(settingsplugin /work/install/lib64/libakonadi2common.so) 12target_link_libraries(settingsplugin KF5::akonadi2common)
13#target_link_libraries(settingsplugin /home/mike/projects/_install/lib/x86_64-linux-gnu/libakonadi2common.so)
14 13
15install(TARGETS settingsplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/akonadi2/settings) 14install(TARGETS settingsplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/akonadi2/settings)
16install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/akonadi2/settings) \ No newline at end of file 15install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/akonadi2/settings) \ No newline at end of file