Commit ebec7bd1 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Return a struct so we can return more element

parent 4583d819
......@@ -337,18 +337,17 @@ void DefaultRendererPrivate::render(const HtmlMessagePart::Ptr &mp, HtmlWriter *
block.setProperty("loadExternal", htmlLoadExternal());
block.setProperty("isPrinting", isPrinting());
{
QString extraHead;
//laurent: FIXME port to async method webengine
QString bodyText = Util::processHtml(mp->bodyHtml(), extraHead);
Util::HtmlMessageInfo messageInfo = Util::processHtml(mp->bodyHtml());
if (isHtmlPreferred) {
mp->nodeHelper()->setNodeDisplayedEmbedded(mp->content(), true);
htmlWriter->extraHead(extraHead);
htmlWriter->extraHead(messageInfo.extraHead);
}
block.setProperty("containsExternalReferences",
Util::containsExternalReferences(bodyText, extraHead));
c.insert(QStringLiteral("content"), bodyText);
Util::containsExternalReferences(messageInfo.htmlSource, messageInfo.extraHead));
c.insert(QStringLiteral("content"), messageInfo.htmlSource);
}
{
......
......@@ -73,11 +73,10 @@ void MessageViewerUtilsTest::shouldExtractHtml()
{
QFETCH(QString, input);
QFETCH(QString, output);
QString header;
const QString processHtml = MessageViewer::Util::processHtml(input, header);
bool equal = processHtml == output;
const MessageViewer::Util::HtmlMessageInfo processHtml = MessageViewer::Util::processHtml(input);
bool equal = processHtml.htmlSource == output;
if (!equal) {
qDebug() << " processed " << processHtml;
qDebug() << " processed " << processHtml.htmlSource;
qDebug() << " ref " << output;
}
QVERIFY(equal);
......
......@@ -699,8 +699,9 @@ void Util::readGravatarConfig()
// until we have that back, at least attempt to fix some of the damage
// yes, "parsing" HTML with regexps is very very wrong, but it's still better than not filtering
// this at all...
QString Util::processHtml(const QString &htmlSource, QString &extraHead)
Util::HtmlMessageInfo Util::processHtml(const QString &htmlSource)
{
Util::HtmlMessageInfo messageInfo;
QString s = htmlSource.trimmed();
const int indexDoctype = s.indexOf(QRegExp(QStringLiteral("<!DOCTYPE[^>]*>"), Qt::CaseInsensitive));
QString textBeforeDoctype;
......@@ -717,14 +718,15 @@ QString Util::processHtml(const QString &htmlSource, QString &extraHead)
const auto endIndex = s.indexOf(QLatin1String("</head>"), Qt::CaseInsensitive);
if (endIndex < 0) {
return htmlSource;
messageInfo.htmlSource = htmlSource;
return messageInfo;
}
extraHead = s.mid(startIndex + 6, endIndex - startIndex - 6);
messageInfo.extraHead = s.mid(startIndex + 6, endIndex - startIndex - 6);
#if QTWEBENGINEWIDGETS_VERSION < QT_VERSION_CHECK(5, 13, 0)
//Remove this hack with https://codereview.qt-project.org/#/c/256100/2 is merged
//Don't authorize to refresh content.
if (MessageViewer::Util::excludeExtraHeader(s)) {
extraHead.clear();
messageInfo.extraHead.clear();
}
#endif
s = s.remove(startIndex, endIndex - startIndex + 7).trimmed();
......@@ -736,7 +738,8 @@ QString Util::processHtml(const QString &htmlSource, QString &extraHead)
s = s.remove(QRegExp(QStringLiteral("</html>$"), Qt::CaseInsensitive)).trimmed();
s = s.remove(QRegExp(QStringLiteral("</body>$"), Qt::CaseInsensitive)).trimmed();
s = textBeforeDoctype + s;
return s;
messageInfo.htmlSource = s;
return messageInfo;
}
......
......@@ -77,7 +77,7 @@ struct HtmlMessageInfo {
QString extraHead;
};
Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT QString processHtml(const QString &htmlSource, QString &extraHead);
Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT HtmlMessageInfo processHtml(const QString &htmlSource);
Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT QByteArray htmlCodec(const QByteArray &data, const QByteArray &currentCodec);
Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT QString generateFileNameForExtension(const Akonadi::Item &msgBase, const QString &extension);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment