summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandro Knauß <sknauss@kde.org>2016-10-18 20:33:00 +0200
committerSandro Knauß <sknauss@kde.org>2016-10-18 20:33:00 +0200
commitbe38c2ebaa77b116028cbe34f777e3d8e5cbc776 (patch)
treeef5372b4a87c442b7242b904396006ceecdd744a
parent2e83f97afb05d6475bc39375400e7846bd77bdff (diff)
downloadkube-be38c2ebaa77b116028cbe34f777e3d8e5cbc776.tar.gz
kube-be38c2ebaa77b116028cbe34f777e3d8e5cbc776.zip
output content from content item
-rw-r--r--framework/domain/messageparser.h1
-rw-r--r--framework/domain/messageparser_new.cpp57
2 files changed, 45 insertions, 13 deletions
diff --git a/framework/domain/messageparser.h b/framework/domain/messageparser.h
index e3b81dd7..55c884f9 100644
--- a/framework/domain/messageparser.h
+++ b/framework/domain/messageparser.h
@@ -133,6 +133,7 @@ public:
133 enum Roles { 133 enum Roles {
134 TypeRole = Qt::UserRole + 1, 134 TypeRole = Qt::UserRole + 1,
135 ContentsRole, 135 ContentsRole,
136 ContentRole,
136 IsEmbededRole, 137 IsEmbededRole,
137 SecurityLevelRole 138 SecurityLevelRole
138 }; 139 };
diff --git a/framework/domain/messageparser_new.cpp b/framework/domain/messageparser_new.cpp
index 2a3b68e9..db4b36c5 100644
--- a/framework/domain/messageparser_new.cpp
+++ b/framework/domain/messageparser_new.cpp
@@ -298,6 +298,7 @@ QHash<int, QByteArray> NewModel::roleNames() const
298 QHash<int, QByteArray> roles; 298 QHash<int, QByteArray> roles;
299 roles[TypeRole] = "type"; 299 roles[TypeRole] = "type";
300 roles[ContentsRole] = "contents"; 300 roles[ContentsRole] = "contents";
301 roles[ContentRole] = "content";
301 roles[IsEmbededRole] = "embeded"; 302 roles[IsEmbededRole] = "embeded";
302 roles[SecurityLevelRole] = "securityLevel"; 303 roles[SecurityLevelRole] = "securityLevel";
303 return roles; 304 return roles;
@@ -330,26 +331,27 @@ QVariant NewModel::data(const QModelIndex &index, int role) const
330 } 331 }
331 if (index.internalPointer()) { 332 if (index.internalPointer()) {
332 const auto entry = static_cast<Entry *>(index.internalPointer()); 333 const auto entry = static_cast<Entry *>(index.internalPointer());
333 const auto data = entry->mData; 334 const auto _data = entry->mData;
334 if (data->userType() == qMetaTypeId<Signature *>()) { 335 if (_data->userType() == qMetaTypeId<Signature *>()) {
335 const auto signature = data->value<Signature *>(); 336 const auto signature = _data->value<Signature *>();
336 int i = d->getPos(signature); 337 int i = d->getPos(signature);
337 switch(role) { 338 switch(role) {
338 case Qt::DisplayRole: 339 case Qt::DisplayRole:
339 case TypeRole:
340 return QStringLiteral("Signature%1").arg(i); 340 return QStringLiteral("Signature%1").arg(i);
341 case TypeRole:
342 return QStringLiteral("Signature");
341 } 343 }
342 } else if (data->userType() == qMetaTypeId<Encryption *>()) { 344 } else if (_data->userType() == qMetaTypeId<Encryption *>()) {
343 const auto first = d->mParts.first(); 345 const auto encryption = _data->value<Encryption *>();
344 const auto encryption = data->value<Encryption *>();
345 int i = d->getPos(encryption); 346 int i = d->getPos(encryption);
346 switch(role) { 347 switch(role) {
347 case Qt::DisplayRole: 348 case Qt::DisplayRole:
348 case TypeRole:
349 return QStringLiteral("Encryption%1").arg(i); 349 return QStringLiteral("Encryption%1").arg(i);
350 case TypeRole:
351 return QStringLiteral("Encryption");
350 } 352 }
351 } else if (data->userType() == qMetaTypeId<Part *>()) { 353 } else if (_data->userType() == qMetaTypeId<Part *>()) {
352 const auto part = data->value<Part *>(); 354 const auto part = _data->value<Part *>();
353 switch (role) { 355 switch (role) {
354 case Qt::DisplayRole: 356 case Qt::DisplayRole:
355 case TypeRole: 357 case TypeRole:
@@ -361,13 +363,42 @@ QVariant NewModel::data(const QModelIndex &index, int role) const
361 case ContentsRole: 363 case ContentsRole:
362 return QVariant::fromValue<QAbstractItemModel *>(d->mContentMap.value(part).get()); 364 return QVariant::fromValue<QAbstractItemModel *>(d->mContentMap.value(part).get());
363 } 365 }
364 } else if (data->userType() == qMetaTypeId<Content *>()) { 366 } else if (_data->userType() == qMetaTypeId<Content *>()) {
365 const auto content = data->value<Content *>(); 367 const auto content = _data->value<Content *>();
366 int i = d->getPos(content); 368 int i = d->getPos(content);
367 switch(role) { 369 switch(role) {
368 case Qt::DisplayRole: 370 case Qt::DisplayRole:
369 case TypeRole:
370 return QStringLiteral("Content%1").arg(i); 371 return QStringLiteral("Content%1").arg(i);
372 case TypeRole:
373 return QString::fromLatin1(content->type());
374 case IsEmbededRole:
375 return false;
376 case ContentRole: {
377 auto text = content->encodedContent();
378 if (data(index, TypeRole).toString() == "HtmlContent") {
379 const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2");
380 int pos = 0;
381 while ((pos = rx.indexIn(text, pos)) != -1) {
382 const auto link = QUrl(rx.cap(3).toUtf8());
383 pos += rx.matchedLength();
384 const auto repl = d->mParser->getPart(link);
385 if (!repl) {
386 continue;
387 }
388 const auto content = repl->content();
389 if(content.size() < 1) {
390 continue;
391 }
392 const auto mailMime = content.first()->mailMime();
393 const auto mimetype = mailMime->mimetype().name();
394 if (mimetype.startsWith("image/")) {
395 const auto data = content.first()->content();
396 text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64())));
397 }
398 }
399 }
400 return text;
401 }
371 } 402 }
372 } 403 }
373 } 404 }