From be38c2ebaa77b116028cbe34f777e3d8e5cbc776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Tue, 18 Oct 2016 20:33:00 +0200 Subject: output content from content item --- framework/domain/messageparser.h | 1 + framework/domain/messageparser_new.cpp | 57 ++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 13 deletions(-) (limited to 'framework') 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: enum Roles { TypeRole = Qt::UserRole + 1, ContentsRole, + ContentRole, IsEmbededRole, SecurityLevelRole }; 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 NewModel::roleNames() const QHash roles; roles[TypeRole] = "type"; roles[ContentsRole] = "contents"; + roles[ContentRole] = "content"; roles[IsEmbededRole] = "embeded"; roles[SecurityLevelRole] = "securityLevel"; return roles; @@ -330,26 +331,27 @@ QVariant NewModel::data(const QModelIndex &index, int role) const } if (index.internalPointer()) { const auto entry = static_cast(index.internalPointer()); - const auto data = entry->mData; - if (data->userType() == qMetaTypeId()) { - const auto signature = data->value(); + const auto _data = entry->mData; + if (_data->userType() == qMetaTypeId()) { + const auto signature = _data->value(); int i = d->getPos(signature); switch(role) { case Qt::DisplayRole: - case TypeRole: return QStringLiteral("Signature%1").arg(i); + case TypeRole: + return QStringLiteral("Signature"); } - } else if (data->userType() == qMetaTypeId()) { - const auto first = d->mParts.first(); - const auto encryption = data->value(); + } else if (_data->userType() == qMetaTypeId()) { + const auto encryption = _data->value(); int i = d->getPos(encryption); switch(role) { case Qt::DisplayRole: - case TypeRole: return QStringLiteral("Encryption%1").arg(i); + case TypeRole: + return QStringLiteral("Encryption"); } - } else if (data->userType() == qMetaTypeId()) { - const auto part = data->value(); + } else if (_data->userType() == qMetaTypeId()) { + const auto part = _data->value(); switch (role) { case Qt::DisplayRole: case TypeRole: @@ -361,13 +363,42 @@ QVariant NewModel::data(const QModelIndex &index, int role) const case ContentsRole: return QVariant::fromValue(d->mContentMap.value(part).get()); } - } else if (data->userType() == qMetaTypeId()) { - const auto content = data->value(); + } else if (_data->userType() == qMetaTypeId()) { + const auto content = _data->value(); int i = d->getPos(content); switch(role) { case Qt::DisplayRole: - case TypeRole: return QStringLiteral("Content%1").arg(i); + case TypeRole: + return QString::fromLatin1(content->type()); + case IsEmbededRole: + return false; + case ContentRole: { + auto text = content->encodedContent(); + if (data(index, TypeRole).toString() == "HtmlContent") { + const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"); + int pos = 0; + while ((pos = rx.indexIn(text, pos)) != -1) { + const auto link = QUrl(rx.cap(3).toUtf8()); + pos += rx.matchedLength(); + const auto repl = d->mParser->getPart(link); + if (!repl) { + continue; + } + const auto content = repl->content(); + if(content.size() < 1) { + continue; + } + const auto mailMime = content.first()->mailMime(); + const auto mimetype = mailMime->mimetype().name(); + if (mimetype.startsWith("image/")) { + const auto data = content.first()->content(); + text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64()))); + } + } + } + return text; + } } } } -- cgit v1.2.3