summaryrefslogtreecommitdiffstats
path: root/framework/src
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-02 09:25:13 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-02 10:03:57 +0200
commitd4bd3ad8d6d1f75b6c284336148e3a2c71dc1882 (patch)
treebc7f45f5c232e3a37e4df67cae429d9fbb25e1e8 /framework/src
parentdd582091bc72ddf61a66d2bc3a3e0ce47f2296b5 (diff)
downloadkube-d4bd3ad8d6d1f75b6c284336148e3a2c71dc1882.tar.gz
kube-d4bd3ad8d6d1f75b6c284336148e3a2c71dc1882.zip
Removed the old models that we're not even using anymore
Diffstat (limited to 'framework/src')
-rw-r--r--framework/src/CMakeLists.txt1
-rw-r--r--framework/src/domain/messageparser.cpp52
-rw-r--r--framework/src/domain/messageparser.h44
-rw-r--r--framework/src/domain/messageparser_old.cpp151
4 files changed, 0 insertions, 248 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt
index c82626a0..10773f8a 100644
--- a/framework/src/CMakeLists.txt
+++ b/framework/src/CMakeLists.txt
@@ -23,7 +23,6 @@ set(SRCS
23 domain/composercontroller.cpp 23 domain/composercontroller.cpp
24 domain/messageparser.cpp 24 domain/messageparser.cpp
25 domain/messageparser_new.cpp 25 domain/messageparser_new.cpp
26 domain/messageparser_old.cpp
27 domain/mailtemplates.cpp 26 domain/mailtemplates.cpp
28 domain/modeltest.cpp 27 domain/modeltest.cpp
29 domain/retriever.cpp 28 domain/retriever.cpp
diff --git a/framework/src/domain/messageparser.cpp b/framework/src/domain/messageparser.cpp
index 46ffe79d..6df50ebd 100644
--- a/framework/src/domain/messageparser.cpp
+++ b/framework/src/domain/messageparser.cpp
@@ -19,29 +19,13 @@
19#include "messageparser.h" 19#include "messageparser.h"
20 20
21#include "modeltest.h" 21#include "modeltest.h"
22#include "stringhtmlwriter.h"
23#include "objecttreesource.h"
24
25#include "mimetreeparser/interface.h" 22#include "mimetreeparser/interface.h"
26 23
27#include <QRegExp>
28
29#include <QFile>
30#include <QImage>
31#include <QDebug> 24#include <QDebug>
32#include <QTime>
33#include <QUrl>
34#include <MimeTreeParser/ObjectTreeParser>
35#include <MimeTreeParser/MessagePart>
36
37 25
38class MessagePartPrivate 26class MessagePartPrivate
39{ 27{
40public: 28public:
41 QSharedPointer<MimeTreeParser::MessagePart> mPartTree;
42 QString mHtml;
43 QMap<QByteArray, QUrl> mEmbeddedPartMap;
44 std::shared_ptr<MimeTreeParser::NodeHelper> mNodeHelper;
45 std::shared_ptr<Parser> mParser; 29 std::shared_ptr<Parser> mParser;
46}; 30};
47 31
@@ -57,16 +41,6 @@ MessageParser::~MessageParser()
57 41
58} 42}
59 43
60QString MessageParser::html() const
61{
62 return d->mHtml;
63}
64
65bool MessageParser::isSimpleHtml() const
66{
67 return d->mHtml.contains("foobar");
68}
69
70QVariant MessageParser::message() const 44QVariant MessageParser::message() const
71{ 45{
72 return QVariant(); 46 return QVariant();
@@ -74,36 +48,10 @@ QVariant MessageParser::message() const
74 48
75void MessageParser::setMessage(const QVariant &message) 49void MessageParser::setMessage(const QVariant &message)
76{ 50{
77 // QTime time;
78 // time.start();
79 d->mParser = std::shared_ptr<Parser>(new Parser(message.toByteArray())); 51 d->mParser = std::shared_ptr<Parser>(new Parser(message.toByteArray()));
80
81 const auto mailData = KMime::CRLFtoLF(message.toByteArray());
82 KMime::Message::Ptr msg(new KMime::Message);
83 msg->setContent(mailData);
84 msg->parse();
85 // qWarning() << "parsed: " << time.elapsed();
86
87 // render the mail
88 StringHtmlWriter htmlWriter;
89 //temporary files only have the lifetime of the nodehelper, so we keep it around until the mail changes.
90 d->mNodeHelper = std::make_shared<MimeTreeParser::NodeHelper>();
91 ObjectTreeSource source(&htmlWriter);
92 MimeTreeParser::ObjectTreeParser otp(&source, d->mNodeHelper.get());
93
94 otp.parseObjectTree(msg.data());
95 d->mPartTree = otp.parsedPart().dynamicCast<MimeTreeParser::MessagePart>();
96
97 d->mEmbeddedPartMap = htmlWriter.embeddedParts();
98 d->mHtml = htmlWriter.html();
99 emit htmlChanged(); 52 emit htmlChanged();
100} 53}
101 54
102QAbstractItemModel *MessageParser::partTree() const
103{
104 return new PartModel(d->mPartTree, d->mParser);
105}
106
107QAbstractItemModel *MessageParser::newTree() const 55QAbstractItemModel *MessageParser::newTree() const
108{ 56{
109 const auto model = new NewModel(d->mParser); 57 const auto model = new NewModel(d->mParser);
diff --git a/framework/src/domain/messageparser.h b/framework/src/domain/messageparser.h
index 2c4febaf..6d52c4b2 100644
--- a/framework/src/domain/messageparser.h
+++ b/framework/src/domain/messageparser.h
@@ -27,17 +27,10 @@
27#include <QModelIndex> 27#include <QModelIndex>
28 28
29#include <memory> 29#include <memory>
30#include <MimeTreeParser/MessagePart>
31 30
32class QAbstractItemModel; 31class QAbstractItemModel;
33 32
34class Parser; 33class Parser;
35class Part;
36class Encryption;
37class Signature;
38typedef std::shared_ptr<Part> PartPtr;
39class Content;
40typedef std::shared_ptr<Content> ContentPtr;
41class MessagePartPrivate; 34class MessagePartPrivate;
42 35
43class NewModelPrivate; 36class NewModelPrivate;
@@ -47,9 +40,6 @@ class MessageParser : public QObject
47{ 40{
48 Q_OBJECT 41 Q_OBJECT
49 Q_PROPERTY (QVariant message READ message WRITE setMessage) 42 Q_PROPERTY (QVariant message READ message WRITE setMessage)
50 Q_PROPERTY (QString html READ html NOTIFY htmlChanged)
51 Q_PROPERTY (bool isSimpleHtml READ isSimpleHtml NOTIFY htmlChanged)
52 Q_PROPERTY (QAbstractItemModel* partTree READ partTree NOTIFY htmlChanged)
53 Q_PROPERTY (QAbstractItemModel* newTree READ newTree NOTIFY htmlChanged) 43 Q_PROPERTY (QAbstractItemModel* newTree READ newTree NOTIFY htmlChanged)
54 Q_PROPERTY (QAbstractItemModel* attachments READ attachments NOTIFY htmlChanged) 44 Q_PROPERTY (QAbstractItemModel* attachments READ attachments NOTIFY htmlChanged)
55 45
@@ -57,12 +47,8 @@ public:
57 explicit MessageParser(QObject *parent = Q_NULLPTR); 47 explicit MessageParser(QObject *parent = Q_NULLPTR);
58 ~MessageParser(); 48 ~MessageParser();
59 49
60 QString html() const;
61 bool isSimpleHtml() const;
62
63 QVariant message() const; 50 QVariant message() const;
64 void setMessage(const QVariant &to); 51 void setMessage(const QVariant &to);
65 QAbstractItemModel *partTree() const;
66 QAbstractItemModel *newTree() const; 52 QAbstractItemModel *newTree() const;
67 QAbstractItemModel *attachments() const; 53 QAbstractItemModel *attachments() const;
68 54
@@ -73,36 +59,6 @@ private:
73 std::unique_ptr<MessagePartPrivate> d; 59 std::unique_ptr<MessagePartPrivate> d;
74}; 60};
75 61
76class PartModel : public QAbstractItemModel {
77 Q_OBJECT
78public:
79 PartModel(QSharedPointer<MimeTreeParser::MessagePart> partTree, std::shared_ptr<Parser> parser);
80
81public:
82 enum Roles {
83 Text = Qt::UserRole + 1,
84 IsHtml,
85 IsEncrypted,
86 IsAttachment,
87 HasContent,
88 Type,
89 IsHidden
90 };
91
92 QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
93 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
94 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
95 QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
96 int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
97 int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
98
99private:
100 QSharedPointer<MimeTreeParser::MessagePart> mPartTree;
101 QMap<QByteArray, QUrl> mEmbeddedPartMap;
102 std::shared_ptr<Parser> mParser;
103};
104
105
106class NewModel : public QAbstractItemModel { 62class NewModel : public QAbstractItemModel {
107 Q_OBJECT 63 Q_OBJECT
108public: 64public:
diff --git a/framework/src/domain/messageparser_old.cpp b/framework/src/domain/messageparser_old.cpp
deleted file mode 100644
index a4247d8c..00000000
--- a/framework/src/domain/messageparser_old.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
1/*
2 This library is free software; you can redistribute it and/or modify it
3 under the terms of the GNU Library General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or (at your
5 option) any later version.
6
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
10 License for more details.
11
12 You should have received a copy of the GNU Library General Public License
13 along with this library; see the file COPYING.LIB. If not, write to the
14 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 02110-1301, USA.
16*/
17
18#include "messageparser.h"
19#include "mimetreeparser/interface.h"
20
21PartModel::PartModel(QSharedPointer<MimeTreeParser::MessagePart> partTree, std::shared_ptr<Parser> parser)
22 : mPartTree(partTree)
23 , mParser(parser)
24{
25}
26
27QHash<int, QByteArray> PartModel::roleNames() const
28{
29 QHash<int, QByteArray> roles;
30 roles[Text] = "text";
31 roles[IsHtml] = "isHtml";
32 roles[IsHidden] = "isHidden";
33 roles[IsEncrypted] = "isEncrypted";
34 roles[IsAttachment] = "isAttachment";
35 roles[HasContent] = "hasContent";
36 roles[Type] = "type";
37 roles[IsHidden] = "isHidden";
38 return roles;
39}
40
41QModelIndex PartModel::index(int row, int column, const QModelIndex &parent) const
42{
43 // qDebug() << "index " << parent << row << column << mPartTree->subParts().size();
44 if (!parent.isValid()) {
45 if (row < mPartTree->subParts().size()) {
46 auto part = mPartTree->subParts().at(row);
47 return createIndex(row, column, part.data());
48 }
49 } else {
50 auto part = static_cast<MimeTreeParser::MessagePart*>(parent.internalPointer());
51 auto subPart = part->subParts().at(row);
52 return createIndex(row, column, subPart.data());
53 }
54 return QModelIndex();
55}
56
57QVariant PartModel::data(const QModelIndex &index, int role) const
58{
59 // qDebug() << "Getting data for index";
60 if (index.isValid()) {
61 auto part = static_cast<MimeTreeParser::MessagePart*>(index.internalPointer());
62 switch (role) {
63 case Text: {
64 // qDebug() << "Getting text: " << part->property("text").toString();
65 // FIXME: we should have a list per part, and not one for all parts.
66 auto text = part->property("htmlContent").toString();
67 const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2");
68 int pos = 0;
69 while ((pos = rx.indexIn(text, pos)) != -1) {
70 const auto link = QUrl(rx.cap(3).toUtf8());
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 }
86 }
87 return text;
88 }
89 case IsAttachment:
90 return part->property("attachment").toBool();
91 case IsEncrypted:
92 return part->property("isEncrypted").toBool();
93 case IsHtml:
94 return part->property("isHtml").toBool();
95 case HasContent:
96 return !part->property("htmlContent").toString().isEmpty();
97 case Type:
98 return part->metaObject()->className();
99 case IsHidden:
100 return false;
101 //return part->property("isHidden").toBool();
102
103 }
104 }
105 return QVariant();
106}
107
108QModelIndex PartModel::parent(const QModelIndex &index) const
109{
110 // qDebug() << "parent " << index;
111 if (index.isValid()) {
112 auto part = static_cast<MimeTreeParser::MessagePart*>(index.internalPointer());
113 auto parentPart = static_cast<MimeTreeParser::MessagePart*>(part->parentPart());
114 auto row = 0;//get the parents parent to find the index
115 if (!parentPart) {
116 parentPart = mPartTree.data();
117 }
118 int i = 0;
119 for (const auto &p : parentPart->subParts()) {
120 if (p.data() == part) {
121 row = i;
122 break;
123 }
124 i++;
125 }
126 return createIndex(row, index.column(), parentPart);
127 }
128 return QModelIndex();
129}
130
131int PartModel::rowCount(const QModelIndex &parent) const
132{
133 // qDebug() << "Row count " << parent;
134 if (!parent.isValid()) {
135 // qDebug() << "Row count " << mPartTree->subParts().size();
136 return mPartTree->subParts().size();
137 } else {
138 auto part = static_cast<MimeTreeParser::MessagePart*>(parent.internalPointer());
139 if (part) {
140 return part->subParts().size();
141 }
142 }
143 return 0;
144}
145
146int PartModel::columnCount(const QModelIndex &parent) const
147{
148 // qDebug() << "Column count " << parent;
149 return 1;
150}
151