summaryrefslogtreecommitdiffstats
path: root/framework/mail/messageparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/mail/messageparser.cpp')
-rw-r--r--framework/mail/messageparser.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/framework/mail/messageparser.cpp b/framework/mail/messageparser.cpp
new file mode 100644
index 00000000..2529a677
--- /dev/null
+++ b/framework/mail/messageparser.cpp
@@ -0,0 +1,76 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#include "messageparser.h"
20
21#include "stringhtmlwriter.h"
22#include "objecttreesource.h"
23#include "csshelper.h"
24
25#include <QFile>
26#include <QImage>
27#include <QDebug>
28#include <QTime>
29#include <MessageViewer/ObjectTreeParser>
30
31MessageParser::MessageParser(QObject *parent)
32 : QObject(parent)
33{
34
35}
36
37QString MessageParser::html() const
38{
39 return mHtml;
40}
41
42QVariant MessageParser::message() const
43{
44 return QVariant();
45}
46
47void MessageParser::setMessage(const QVariant &message)
48{
49 QTime time;
50 time.start();
51 const auto mailData = KMime::CRLFtoLF(message.toByteArray());
52 KMime::Message::Ptr msg(new KMime::Message);
53 msg->setContent(mailData);
54 msg->parse();
55 qWarning() << "parsed: " << time.elapsed();
56 qWarning() << "parsed: " << message.toByteArray();
57
58 // render the mail
59 StringHtmlWriter htmlWriter;
60 QImage paintDevice;
61 CSSHelper cssHelper(&paintDevice);
62 MessageViewer::NodeHelper nodeHelper;
63 ObjectTreeSource source(&htmlWriter, &cssHelper);
64 MessageViewer::ObjectTreeParser otp(&source, &nodeHelper);
65
66 htmlWriter.begin(QString());
67 htmlWriter.queue(cssHelper.htmlHead(false));
68
69 otp.parseObjectTree(msg.data());
70
71 htmlWriter.queue(QStringLiteral("</body></html>"));
72 htmlWriter.end();
73
74 mHtml = htmlWriter.html();
75 emit htmlChanged();
76}