Commit 610b769e authored by Laurent Montel's avatar Laurent Montel 😁

increase script support

parent 170f0192
......@@ -36,7 +36,7 @@ set(KPIMTEXTEDIT_LIB_VERSION "5.2.40")
set(KDEPIM_APPS_LIB_VERSION "5.2.40")
set(LIBKDEPIM_LIB_VERSION "5.2.40")
set(AKONADI_VERSION "5.1.80")
set(AKONADI_VERSION "5.2.41")
find_package(KF5Akonadi ${AKONADI_VERSION} CONFIG REQUIRED)
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets Test UiTools Network WebKitWidgets)
......@@ -58,7 +58,7 @@ find_package(KF5Completion ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Codecs ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Config ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5XmlGui ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5AkonadiSearch "5.0.42" CONFIG REQUIRED)
find_package(KF5AkonadiSearch "5.2.40" CONFIG REQUIRED)
set_package_properties(KF5AkonadiSearch PROPERTIES DESCRIPTION "The Akonadi Search libraries" URL "http://www.kde.org" TYPE REQUIRED PURPOSE "Provides search capabilities in KMail and Akonadi")
find_package(KF5ItemViews ${KF5_VERSION} CONFIG REQUIRED)
......
......@@ -96,6 +96,7 @@ if (QTWEBENGINE_SUPPORT_OPTION)
viewer/webengine/mailwebenginepage.cpp
viewer/webengine/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
viewer/webengine/cidreferencesurlinterceptor/cidreferencesurlinterceptor.cpp
viewer/webengine/mailwebenginescript.cpp
${libmessageviewer_mailviewer_SRCS}
findbar/findbarwebengineview.cpp
......
......@@ -362,6 +362,7 @@ void AdBlockSettingWidget::hasChanged()
updateCheckBox();
mChanged = true;
Q_EMIT changed(true);
Q_EMIT settingsChanged();
}
bool AdBlockSettingWidget::changed() const
......
......@@ -57,6 +57,7 @@ public:
Q_SIGNALS:
void changed(bool);
void settingsChanged();
protected:
bool event(QEvent *event) Q_DECL_OVERRIDE;
......
......@@ -85,17 +85,24 @@ ScamCheckShortUrl *ScamDetectionWebEngine::scamCheckShortUrl() const
void ScamDetectionWebEngine::scanPage(QWebEnginePage *page)
{
if (MessageViewer::MessageViewerSettings::self()->scamDetectionEnabled()) {
page->runJavaScript(MessageViewer::WebEngineScript::findAllAnchors(), invoke(this, &ScamDetectionWebEngine::handleScanPage));
page->runJavaScript(MessageViewer::WebEngineScript::findAllAnchorsAndForms(), invoke(this, &ScamDetectionWebEngine::handleScanPage));
}
}
void ScamDetectionWebEngine::handleScanPage(const QVariant &result)
{
bool foundScam = false;
d->mDetails.clear();
const QVariantList resultList = result.toList();
if (resultList.count() != 1) {
Q_EMIT resultScanDetection(foundScam);
return;
}
d->mDetails = QLatin1String("<b>") + i18n("Details:") + QLatin1String("</b><ul>");
QRegularExpression ip4regExp(QStringLiteral("\\b[0-9]{1,3}\\.[0-9]{1,3}(?:\\.[0-9]{0,3})?(?:\\.[0-9]{0,3})?"));
const QList<QVariant> lst = result.toList();
const QVariantMap mapResult = resultList.at(0).toMap();
const QList<QVariant> lst = mapResult.value(QStringLiteral("anchors")).toList();
Q_FOREACH (const QVariant &var, lst) {
QMap<QString, QVariant> mapVariant = var.toMap();
//qDebug()<<" mapVariant"<<mapVariant;
......@@ -155,13 +162,10 @@ void ScamDetectionWebEngine::handleScanPage(const QVariant &result)
}
}
}
#if 0 //FIXME
//3) has form
if (rootElement.findAll(QStringLiteral("form")).count() > 0) {
if (mapResult.value(QStringLiteral("forms")).toInt() > 0) {
d->mDetails += QLatin1String("<li></b>") + i18n("Message contains form element. This is often the case in scam emails.") + QLatin1String("</b></li>");
foundScam = true;
}
#endif
d->mDetails += QLatin1String("</ul>");
//qDebug()<<" d->mDetails "<< d->mDetails;
if (foundScam) {
......
/*
Copyright (c) 2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mailwebenginescript.h"
#include "webengine/webenginescript.h"
#include <QDebug>
using namespace MessageViewer;
QString MailWebEngineScript::injectAttachments(const QString &delayedHtml, const QString &elementStr)
{
const QString source = QString::fromLatin1("var element = document.getElementById('%1'); "
"if (element) { "
" element.innerHTML += '%2';"
"}").arg(elementStr).arg(delayedHtml);
qDebug() << "QString MailWebEngineScript::injectAttachments(const QString &delayedHtml, const QString &elementStr) :" << source;
return source;
}
QString MailWebEngineScript::replaceInnerHtml(const QString &field, const QString &html, bool doShow)
{
const QString replaceInnerHtmlStr = QLatin1String("iconFull") + field + QLatin1String("AddressList");
const QString source = QString::fromLatin1("(function() {"
"var doShow = %3;"
"var field = \'%4\';"
"var out = [];"
"var element = document.getElementById('%1'); "
"if (element) { "
" element.innerHTML = '%2';"
" out.push({"
" field: field,"
" doShow: doShow"
" });"
"}"
"return out;"
"})()").arg(replaceInnerHtmlStr).arg(html).arg(doShow).arg(field);
qDebug() << "QString MailWebEngineScript::replaceInnerHtml(const QString &delayedHtml, const QString &elementStr) :" << source;
return source;
}
QString MailWebEngineScript::updateToggleFullAddressList(const QString &field, bool doShow)
{
const QString dotsFullStr = QLatin1String("dotsFull") + field + QLatin1String("AddressList");
const QString hiddenFullStr = QLatin1String("hiddenFull") + field + QLatin1String("AddressList");
const QString source = QString::fromLatin1(" %1;"
" %2;")
.arg(MessageViewer::WebEngineScript::setElementByIdVisible(dotsFullStr, !doShow))
.arg(MessageViewer::WebEngineScript::setElementByIdVisible(hiddenFullStr, doShow));
qDebug() << "QString MailWebEngineScript::updateToggleFullAddressList(const QString &delayedHtml, const QString &elementStr) :" << source;
return source;
}
QString MailWebEngineScript::toggleFullAddressList(const QString &field, const QString &html, bool doShow)
{
const QString replaceInnerHtmlStr = QLatin1String("iconFull") + field + QLatin1String("AddressList");
const QString dotsFullStr = QLatin1String("dotsFull") + field + QLatin1String("AddressList");
const QString hiddenFullStr = QLatin1String("hiddenFull") + field + QLatin1String("AddressList");
const QString source = QString::fromLatin1("var element = document.getElementById('%1'); "
"if (element) { "
" element.innerHTML = '%2';"
" %3;"
" %4;"
"}").arg(replaceInnerHtmlStr).arg(html)
.arg(MessageViewer::WebEngineScript::setElementByIdVisible(dotsFullStr, !doShow))
.arg(MessageViewer::WebEngineScript::setElementByIdVisible(hiddenFullStr, doShow));
qDebug() << "QString MailWebEngineScript::injectAttachments(const QString &delayedHtml, const QString &elementStr) :" << source;
return source;
}
/*
Copyright (c) 2016 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MAILWEBENGINESCRIPT_H
#define MAILWEBENGINESCRIPT_H
#include "messageviewer_export.h"
#include <QString>
#include <QPoint>
namespace MessageViewer
{
namespace MailWebEngineScript
{
MESSAGEVIEWER_EXPORT QString injectAttachments(const QString &delayedHtml, const QString &element);
MESSAGEVIEWER_EXPORT QString toggleFullAddressList(const QString &field, const QString &html, bool doShow);
MESSAGEVIEWER_EXPORT QString replaceInnerHtml(const QString &field, const QString &html, bool doShow);
MESSAGEVIEWER_EXPORT QString updateToggleFullAddressList(const QString &field, bool doShow);
}
}
#endif // MAILWEBENGINESCRIPT_H
......@@ -20,8 +20,6 @@
#include <QObject>
#include "messageviewer_export.h"
class QAction;
class KActionCollection;
class QWebEngineView;
namespace MessageViewer
{
......
......@@ -29,7 +29,6 @@ class QWebEngineView;
namespace MessageViewer
{
class WebEngineAccessKeyPrivate;
class WebEngineAccessKeyAnchor;
class MESSAGEVIEWER_EXPORT WebEngineAccessKey : public QObject
{
Q_OBJECT
......
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