summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--applications/kube-mail/package/contents/ui/SingleMailView.qml5
-rw-r--r--framework/CMakeLists.txt7
-rw-r--r--framework/mail/CMakeLists.txt2
-rw-r--r--framework/mail/filehtmlwriter.cpp111
-rw-r--r--framework/mail/filehtmlwriter.h64
-rw-r--r--framework/mail/maillistmodel.cpp46
-rw-r--r--framework/mail/maillistmodel.h3
-rw-r--r--framework/mail/objecttreesource.cpp129
-rw-r--r--framework/mail/objecttreesource.h55
9 files changed, 419 insertions, 3 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 c91ee0d1..8301392a 100644
--- a/framework/CMakeLists.txt
+++ b/framework/CMakeLists.txt
@@ -16,14 +16,21 @@ 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)
19find_package(Akonadi2Common CONFIG REQUIRED) 21find_package(Akonadi2Common CONFIG REQUIRED)
20find_package(KF5Async) 22find_package(KF5Async)
23find_package(KF5Libkleo)
21 24
22set(CMAKE_AUTOMOC ON) 25set(CMAKE_AUTOMOC ON)
23add_definitions("-Wall -std=c++0x -g") 26add_definitions("-Wall -std=c++0x -g")
24include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/common) 27include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/common)
25include_directories(SYSTEM /work/install/include/) 28include_directories(SYSTEM /work/install/include/)
26include_directories(SYSTEM /work/install/include/KF5/) 29include_directories(SYSTEM /work/install/include/KF5/)
30include_directories(SYSTEM /work/install/include/KF5/KIconThemes)
31include_directories(SYSTEM /work/install/include/KF5/KMime)
32include_directories(SYSTEM /work/install/include/KF5/KService)
33include_directories(SYSTEM /work/install/include/KF5/KCoreAddons)
27 34
28enable_testing() 35enable_testing()
29 36
diff --git a/framework/mail/CMakeLists.txt b/framework/mail/CMakeLists.txt
index a8a4b3e8..e7286763 100644
--- a/framework/mail/CMakeLists.txt
+++ b/framework/mail/CMakeLists.txt
@@ -13,7 +13,7 @@ add_library(mailplugin SHARED ${mailplugin_SRCS})
13 13
14qt5_use_modules(mailplugin Core Quick Qml) 14qt5_use_modules(mailplugin Core Quick Qml)
15 15
16target_link_libraries(mailplugin KF5::akonadi2common) 16target_link_libraries(mailplugin KF5::akonadi2common KF5::Otp)
17 17
18install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail) 18install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail)
19install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail) 19install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail)
diff --git a/framework/mail/filehtmlwriter.cpp b/framework/mail/filehtmlwriter.cpp
new file mode 100644
index 00000000..e435e1be
--- /dev/null
+++ b/framework/mail/filehtmlwriter.cpp
@@ -0,0 +1,111 @@
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 "filehtmlwriter.h"
33
34#include <QTextStream>
35
36FileHtmlWriter::FileHtmlWriter(const QString &filename)
37 : MessageViewer::HtmlWriter(),
38 mFile(filename.isEmpty() ? QStringLiteral("filehtmlwriter.out") : filename)
39{
40 mStream.setCodec("UTF-8");
41}
42
43FileHtmlWriter::~FileHtmlWriter()
44{
45 if (mFile.isOpen()) {
46 mStream.setDevice(0);
47 mFile.close();
48 }
49}
50
51void FileHtmlWriter::begin(const QString &css)
52{
53 openOrWarn();
54 if (!css.isEmpty()) {
55 write(QLatin1String("<!-- CSS Definitions \n") + css + QLatin1String("-->\n"));
56 }
57}
58
59void FileHtmlWriter::end()
60{
61 flush();
62 mStream.setDevice(0);
63 mFile.close();
64}
65
66void FileHtmlWriter::reset()
67{
68 if (mFile.isOpen()) {
69 mStream.setDevice(0);
70 mFile.close();
71 }
72}
73
74void FileHtmlWriter::write(const QString &str)
75{
76 mStream << str.toUtf8();
77 flush();
78}
79
80void FileHtmlWriter::queue(const QString &str)
81{
82 write(str);
83}
84
85void FileHtmlWriter::flush()
86{
87 mStream.flush();
88 mFile.flush();
89}
90
91void FileHtmlWriter::openOrWarn()
92{
93 if (mFile.isOpen()) {
94 mStream.setDevice(0);
95 mFile.close();
96 }
97 if (!mFile.open(QIODevice::WriteOnly)) {
98 } else {
99 mStream.setDevice(&mFile);
100 }
101}
102
103void FileHtmlWriter::embedPart(const QByteArray &contentId, const QString &url)
104{
105 mStream << "<!-- embedPart(contentID=" << contentId << ", url=" << url << ") -->" << endl;
106 flush();
107}
108void FileHtmlWriter::extraHead(const QString &)
109{
110
111} \ No newline at end of file
diff --git a/framework/mail/filehtmlwriter.h b/framework/mail/filehtmlwriter.h
new file mode 100644
index 00000000..8bda39f8
--- /dev/null
+++ b/framework/mail/filehtmlwriter.h
@@ -0,0 +1,64 @@
1/* -*- c++ -*-
2 filehtmlwriter.h
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#ifndef __MESSAGEVIEWER_FILEHTMLWRITER_H__
33#define __MESSAGEVIEWER_FILEHTMLWRITER_H__
34
35#include <MessageViewer/HtmlWriter>
36
37#include <QFile>
38#include <QTextStream>
39
40class QString;
41
42class FileHtmlWriter : public MessageViewer::HtmlWriter
43{
44public:
45 explicit FileHtmlWriter(const QString &filename);
46 virtual ~FileHtmlWriter();
47
48 void begin(const QString &cssDefs) Q_DECL_OVERRIDE;
49 void end() Q_DECL_OVERRIDE;
50 void reset() Q_DECL_OVERRIDE;
51 void write(const QString &str) Q_DECL_OVERRIDE;
52 void queue(const QString &str) Q_DECL_OVERRIDE;
53 void flush() Q_DECL_OVERRIDE;
54 void embedPart(const QByteArray &contentId, const QString &url) Q_DECL_OVERRIDE;
55 void extraHead(const QString &str) Q_DECL_OVERRIDE;
56private:
57 void openOrWarn();
58
59private:
60 QFile mFile;
61 QTextStream mStream;
62};
63
64#endif // __MESSAGEVIEWER_FILEHTMLWRITER_H__
diff --git a/framework/mail/maillistmodel.cpp b/framework/mail/maillistmodel.cpp
index e6a9c218..c37e2be4 100644
--- a/framework/mail/maillistmodel.cpp
+++ b/framework/mail/maillistmodel.cpp
@@ -1,6 +1,12 @@
1#include "maillistmodel.h" 1#include "maillistmodel.h"
2 2
3#include "filehtmlwriter.h"
4#include "objecttreesource.h"
5
3#include <QFile> 6#include <QFile>
7#include <QImage>
8#include <KF5/MessageViewer/ObjectTreeParser>
9#include <KF5/MessageViewer/CSSHelper>
4 10
5MailListModel::MailListModel(QObject *parent) 11MailListModel::MailListModel(QObject *parent)
6 : QIdentityProxyModel() 12 : QIdentityProxyModel()
@@ -25,6 +31,7 @@ QHash< int, QByteArray > MailListModel::roleNames() const
25 roles[Important] = "important"; 31 roles[Important] = "important";
26 roles[Id] = "id"; 32 roles[Id] = "id";
27 roles[MimeMessage] = "mimeMessage"; 33 roles[MimeMessage] = "mimeMessage";
34 roles[RenderedMessage] = "renderedMessage";
28 roles[DomainObject] = "domainObject"; 35 roles[DomainObject] = "domainObject";
29 36
30 return roles; 37 return roles;
@@ -61,6 +68,45 @@ QVariant MailListModel::data(const QModelIndex &idx, int role) const
61 } 68 }
62 return "Failed to read mail."; 69 return "Failed to read mail.";
63 } 70 }
71 case RenderedMessage: {
72 auto filename = srcIdx.sibling(srcIdx.row(), 6).data(Qt::DisplayRole).toString();
73 QFile file(filename);
74 if (file.open(QFile::ReadOnly)) {
75 const auto mailData = KMime::CRLFtoLF(file.readAll());
76 KMime::Message::Ptr msg(new KMime::Message);
77 msg->setContent(mailData);
78 msg->parse();
79
80 // render the mail
81 const QString fname("/tmp/test.html");
82 FileHtmlWriter htmlWriter(fname);
83 QImage paintDevice;
84 MessageViewer::CSSHelper cssHelper(&paintDevice);
85 MessageViewer::NodeHelper nodeHelper;
86 ObjectTreeSource source(&htmlWriter, &cssHelper);
87 MessageViewer::ObjectTreeParser otp(&source, &nodeHelper);
88
89 htmlWriter.begin(QString());
90 htmlWriter.queue(cssHelper.htmlHead(false));
91
92 otp.parseObjectTree(msg.data());
93
94 htmlWriter.queue(QStringLiteral("</body></html>"));
95 htmlWriter.flush();
96 htmlWriter.end();
97
98 QFile file(fname);
99 if (file.open(QFile::ReadOnly)) {
100 const auto content = file.readAll();
101 return content;
102 } else {
103 qWarning() << "Failed to open the file";
104 }
105 } else {
106 qWarning() << "Failed to open the file";
107 }
108 return "Failed to read mail.";
109 }
64 } 110 }
65 return QIdentityProxyModel::data(idx, role); 111 return QIdentityProxyModel::data(idx, role);
66} 112}
diff --git a/framework/mail/maillistmodel.h b/framework/mail/maillistmodel.h
index 7718477c..7eb55ffd 100644
--- a/framework/mail/maillistmodel.h
+++ b/framework/mail/maillistmodel.h
@@ -27,7 +27,8 @@ public:
27 Important, 27 Important,
28 Id, 28 Id,
29 MimeMessage, 29 MimeMessage,
30 DomainObject 30 DomainObject,
31 RenderedMessage
31 }; 32 };
32 33
33 QHash<int, QByteArray> roleNames() const; 34 QHash<int, QByteArray> roleNames() const;
diff --git a/framework/mail/objecttreesource.cpp b/framework/mail/objecttreesource.cpp
new file mode 100644
index 00000000..cde4775a
--- /dev/null
+++ b/framework/mail/objecttreesource.cpp
@@ -0,0 +1,129 @@
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::CSSHelper *mCSSHelper;
38 bool mAllowDecryption;
39 bool mHtmlLoadExternal;
40 bool mHtmlMail;
41};
42
43ObjectTreeSource::ObjectTreeSource(MessageViewer::HtmlWriter *writer,
44 MessageViewer::CSSHelper *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::CSSHelper *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} \ No newline at end of file
diff --git a/framework/mail/objecttreesource.h b/framework/mail/objecttreesource.h
new file mode 100644
index 00000000..c61ba715
--- /dev/null
+++ b/framework/mail/objecttreesource.h
@@ -0,0 +1,55 @@
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::CSSHelper *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::CSSHelper *cssHelper() Q_DECL_OVERRIDE;
48 QObject *sourceObject() Q_DECL_OVERRIDE;
49
50private:
51 ObjectSourcePrivate *const d;
52};
53
54#endif
55