diff options
Diffstat (limited to 'framework/src/domain/messageparser_old.cpp')
-rw-r--r-- | framework/src/domain/messageparser_old.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/framework/src/domain/messageparser_old.cpp b/framework/src/domain/messageparser_old.cpp new file mode 100644 index 00000000..a4247d8c --- /dev/null +++ b/framework/src/domain/messageparser_old.cpp | |||
@@ -0,0 +1,151 @@ | |||
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 | |||
21 | PartModel::PartModel(QSharedPointer<MimeTreeParser::MessagePart> partTree, std::shared_ptr<Parser> parser) | ||
22 | : mPartTree(partTree) | ||
23 | , mParser(parser) | ||
24 | { | ||
25 | } | ||
26 | |||
27 | QHash<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 | |||
41 | QModelIndex 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 | |||
57 | QVariant 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 | |||
108 | QModelIndex 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 | |||
131 | int 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 | |||
146 | int PartModel::columnCount(const QModelIndex &parent) const | ||
147 | { | ||
148 | // qDebug() << "Column count " << parent; | ||
149 | return 1; | ||
150 | } | ||
151 | |||