summaryrefslogtreecommitdiffstats
path: root/framework/domain/messageparser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain/messageparser.cpp')
-rw-r--r--framework/domain/messageparser.cpp123
1 files changed, 4 insertions, 119 deletions
diff --git a/framework/domain/messageparser.cpp b/framework/domain/messageparser.cpp
index febd1363..ef9fb0d2 100644
--- a/framework/domain/messageparser.cpp
+++ b/framework/domain/messageparser.cpp
@@ -33,125 +33,6 @@
33#include <MimeTreeParser/ObjectTreeParser> 33#include <MimeTreeParser/ObjectTreeParser>
34#include <MimeTreeParser/MessagePart> 34#include <MimeTreeParser/MessagePart>
35 35
36PartModel::PartModel(QSharedPointer<MimeTreeParser::MessagePart> partTree, std::shared_ptr<Parser> parser)
37 : mPartTree(partTree)
38 , mParser(parser)
39{
40}
41
42QHash<int, QByteArray> PartModel::roleNames() const
43{
44 QHash<int, QByteArray> roles;
45 roles[Text] = "text";
46 roles[IsHtml] = "isHtml";
47 roles[IsHidden] = "isHidden";
48 roles[IsEncrypted] = "isEncrypted";
49 roles[IsAttachment] = "isAttachment";
50 roles[HasContent] = "hasContent";
51 roles[Type] = "type";
52 roles[IsHidden] = "isHidden";
53 return roles;
54}
55
56QModelIndex PartModel::index(int row, int column, const QModelIndex &parent) const
57{
58 // qDebug() << "index " << parent << row << column << mPartTree->subParts().size();
59 if (!parent.isValid()) {
60 if (row < mPartTree->subParts().size()) {
61 auto part = mPartTree->subParts().at(row);
62 return createIndex(row, column, part.data());
63 }
64 } else {
65 auto part = static_cast<MimeTreeParser::MessagePart*>(parent.internalPointer());
66 auto subPart = part->subParts().at(row);
67 return createIndex(row, column, subPart.data());
68 }
69 return QModelIndex();
70}
71
72QVariant PartModel::data(const QModelIndex &index, int role) const
73{
74 // qDebug() << "Getting data for index";
75 if (index.isValid()) {
76 auto part = static_cast<MimeTreeParser::MessagePart*>(index.internalPointer());
77 switch (role) {
78 case Text: {
79 // qDebug() << "Getting text: " << part->property("text").toString();
80 // FIXME: we should have a list per part, and not one for all parts.
81 auto text = part->property("htmlContent").toString();
82 auto rx = QRegExp("src=(\"|')cid:([^\1]*)\1");
83 int pos = 0;
84 while ((pos = rx.indexIn(text, pos)) != -1) {
85 auto repl = mParser->getPart(rx.cap(2).toUtf8());
86 if (repl.isValid()) {
87 text.replace(rx.cap(0), QString("src=\"%1\"").arg(repl.toString()));
88 }
89 pos += rx.matchedLength();
90 }
91 return text;
92 }
93 case IsAttachment:
94 return part->property("attachment").toBool();
95 case IsEncrypted:
96 return part->property("isEncrypted").toBool();
97 case IsHtml:
98 return part->property("isHtml").toBool();
99 case HasContent:
100 return !part->property("htmlContent").toString().isEmpty();
101 case Type:
102 return part->metaObject()->className();
103 case IsHidden:
104 return false;
105 //return part->property("isHidden").toBool();
106
107 }
108 }
109 return QVariant();
110}
111
112QModelIndex PartModel::parent(const QModelIndex &index) const
113{
114 // qDebug() << "parent " << index;
115 if (index.isValid()) {
116 auto part = static_cast<MimeTreeParser::MessagePart*>(index.internalPointer());
117 auto parentPart = static_cast<MimeTreeParser::MessagePart*>(part->parentPart());
118 auto row = 0;//get the parents parent to find the index
119 if (!parentPart) {
120 parentPart = mPartTree.data();
121 }
122 int i = 0;
123 for (const auto &p : parentPart->subParts()) {
124 if (p.data() == part) {
125 row = i;
126 break;
127 }
128 i++;
129 }
130 return createIndex(row, index.column(), parentPart);
131 }
132 return QModelIndex();
133}
134
135int PartModel::rowCount(const QModelIndex &parent) const
136{
137 // qDebug() << "Row count " << parent;
138 if (!parent.isValid()) {
139 // qDebug() << "Row count " << mPartTree->subParts().size();
140 return mPartTree->subParts().size();
141 } else {
142 auto part = static_cast<MimeTreeParser::MessagePart*>(parent.internalPointer());
143 if (part) {
144 return part->subParts().size();
145 }
146 }
147 return 0;
148}
149
150int PartModel::columnCount(const QModelIndex &parent) const
151{
152 // qDebug() << "Column count " << parent;
153 return 1;
154}
155 36
156class MessagePartPrivate 37class MessagePartPrivate
157{ 38{
@@ -217,3 +98,7 @@ QAbstractItemModel *MessageParser::partTree() const
217 return new PartModel(d->mPartTree, d->mParser); 98 return new PartModel(d->mPartTree, d->mParser);
218} 99}
219 100
101QAbstractItemModel *MessageParser::newTree() const
102{
103 return new NewModel(d->mParser);
104}