summaryrefslogtreecommitdiffstats
path: root/framework/src
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-23 10:30:21 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-05-23 10:30:21 +0200
commite7b821c4308c6ed15daed911184980149cce38ff (patch)
treebdf19f2bc06253aa283dbb1ff56458091737cad5 /framework/src
parent7f90b1ddab470a414833ffadd4fdefc2382ab6fc (diff)
downloadkube-e7b821c4308c6ed15daed911184980149cce38ff.tar.gz
kube-e7b821c4308c6ed15daed911184980149cce38ff.zip
Always use richtext, and avoid using a browser for simple html
Diffstat (limited to 'framework/src')
-rw-r--r--framework/src/domain/messageparser.h1
-rw-r--r--framework/src/domain/messageparser_new.cpp28
2 files changed, 28 insertions, 1 deletions
diff --git a/framework/src/domain/messageparser.h b/framework/src/domain/messageparser.h
index 6d52c4b2..de4d8838 100644
--- a/framework/src/domain/messageparser.h
+++ b/framework/src/domain/messageparser.h
@@ -70,6 +70,7 @@ public:
70 TypeRole = Qt::UserRole + 1, 70 TypeRole = Qt::UserRole + 1,
71 ContentsRole, 71 ContentsRole,
72 ContentRole, 72 ContentRole,
73 IsComplexHtmlContentRole,
73 IsEmbededRole, 74 IsEmbededRole,
74 SecurityLevelRole, 75 SecurityLevelRole,
75 EncryptionErrorType, 76 EncryptionErrorType,
diff --git a/framework/src/domain/messageparser_new.cpp b/framework/src/domain/messageparser_new.cpp
index cb399523..c353becf 100644
--- a/framework/src/domain/messageparser_new.cpp
+++ b/framework/src/domain/messageparser_new.cpp
@@ -21,6 +21,7 @@
21#include "mimetreeparser/interface.h" 21#include "mimetreeparser/interface.h"
22 22
23#include <QDebug> 23#include <QDebug>
24#include <QTextDocument>
24 25
25Q_DECLARE_METATYPE(Part *) 26Q_DECLARE_METATYPE(Part *)
26Q_DECLARE_METATYPE(Content *) 27Q_DECLARE_METATYPE(Content *)
@@ -315,6 +316,7 @@ QHash<int, QByteArray> NewModel::roleNames() const
315 QHash<int, QByteArray> roles; 316 QHash<int, QByteArray> roles;
316 roles[TypeRole] = "type"; 317 roles[TypeRole] = "type";
317 roles[ContentRole] = "content"; 318 roles[ContentRole] = "content";
319 roles[IsComplexHtmlContentRole] = "complexHtmlContent";
318 roles[IsEmbededRole] = "embeded"; 320 roles[IsEmbededRole] = "embeded";
319 roles[SecurityLevelRole] = "securityLevel"; 321 roles[SecurityLevelRole] = "securityLevel";
320 roles[EncryptionErrorType] = "errorType"; 322 roles[EncryptionErrorType] = "errorType";
@@ -422,9 +424,30 @@ QVariant NewModel::data(const QModelIndex &index, int role) const
422 return QString::fromLatin1(content->type()); 424 return QString::fromLatin1(content->type());
423 case IsEmbededRole: 425 case IsEmbededRole:
424 return data(index.parent(), IsEmbededRole); 426 return data(index.parent(), IsEmbededRole);
427 case IsComplexHtmlContentRole: {
428 const auto contentType = data(index, TypeRole).toString();
429 if (contentType == "HtmlContent") {
430 const auto text = content->encodedContent();
431 if (text.contains("<!DOCTYPE html PUBLIC")) {
432 return true;
433 }
434 //Media queries are too advanced
435 if (text.contains("@media")) {
436 return true;
437 }
438 if (text.contains("<style")) {
439 return true;
440 }
441 return false;
442 } else {
443 return false;
444 }
445 break;
446 }
425 case ContentRole: { 447 case ContentRole: {
426 auto text = content->encodedContent(); 448 auto text = content->encodedContent();
427 if (data(index, TypeRole).toString() == "HtmlContent") { 449 const auto contentType = data(index, TypeRole).toString();
450 if (contentType == "HtmlContent") {
428 const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"); 451 const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2");
429 int pos = 0; 452 int pos = 0;
430 while ((pos = rx.indexIn(text, pos)) != -1) { 453 while ((pos = rx.indexIn(text, pos)) != -1) {
@@ -445,6 +468,9 @@ QVariant NewModel::data(const QModelIndex &index, int role) const
445 text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64()))); 468 text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64())));
446 } 469 }
447 } 470 }
471 } else { //We assume plain
472 //We alwas do richtext (so we get highlighted links and stuff).
473 return Qt::convertFromPlainText(text);
448 } 474 }
449 return text; 475 return text;
450 } 476 }