diff options
Diffstat (limited to 'framework/src/domain/messageparser_new.cpp')
-rw-r--r-- | framework/src/domain/messageparser_new.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
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 | ||
25 | Q_DECLARE_METATYPE(Part *) | 26 | Q_DECLARE_METATYPE(Part *) |
26 | Q_DECLARE_METATYPE(Content *) | 27 | Q_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 | } |