Commit 3a7f4701 authored by Laurent Montel's avatar Laurent Montel 😁

Remove webkit support

parent fad121db
......@@ -18,7 +18,7 @@ include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)
include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
set(MESSAGELIB_LIB_VERSION "5.2.56")
set(MESSAGELIB_LIB_VERSION "5.2.57")
set(KF5_VERSION "5.19.0")
set(KDEPIMLIBS_LIB_VERSION "5.2.40")
......@@ -80,17 +80,8 @@ find_package(KF5PimCommon ${PIMCOMMON_LIB_VERSION} CONFIG REQUIRED)
option(KDEPIM_ENTERPRISE_BUILD "Enable features specific to the enterprise branch, which are normally disabled. Also, it disables many components not needed for Kontact such as the Kolab client." FALSE)
option(QTWEBENGINE_SUPPORT_OPTION "Enable support for QtWebEngine. False by default." FALSE)
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED WebEngine WebEngineWidgets)
option(MESSAGEVIEWER_USE_QTWEBENGINE "Use QtWebEngine in mail viewer. False by default." FALSE)
if (QTWEBENGINE_SUPPORT_OPTION)
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED WebEngine WebEngineWidgets)
endif()
if (MESSAGEVIEWER_USE_QTWEBENGINE AND NOT QTWEBENGINE_SUPPORT_OPTION)
MESSAGE(FATAL_ERROR "QTWEBENGINE_SUPPORT_OPTION must be ON when you activate MESSAGEVIEWER_USE_QTWEBENGINE support.")
endif()
# Support for the GIT revision number in messagecomposer-version.h
if(EXISTS "${Messagelib_SOURCE_DIR}/.git")
......@@ -115,9 +106,7 @@ add_subdirectory(templateparser)
add_subdirectory(messagecomposer)
add_subdirectory(messagecore)
add_subdirectory(messagelist)
if (QTWEBENGINE_SUPPORT_OPTION)
add_subdirectory(webengineviewer)
endif()
add_subdirectory(webengineviewer)
install( FILES messagelib.categories DESTINATION ${KDE_INSTALL_CONFDIR} )
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
......@@ -38,9 +38,7 @@ if(BUILD_TESTING)
add_subdirectory(adblock/common/autotests)
add_subdirectory(viewerplugins/tests/)
add_subdirectory(htmlwriter/autotests/)
if (QTWEBENGINE_SUPPORT_OPTION)
add_subdirectory(viewer/webengine/tests)
endif()
add_subdirectory(viewer/webengine/tests)
endif()
add_subdirectory(pics)
add_subdirectory(kconf_update)
......@@ -77,30 +75,19 @@ if (NOT MESSAGEVIEWER_USE_QTWEBENGINE)
)
endif()
if (NOT MESSAGEVIEWER_USE_QTWEBENGINE)
set(libmessageviewer_mailviewer_SRCS
viewer/webview/mailwebview.cpp
viewer/webview/webpage.cpp
viewer/webview/networkaccessmanager.cpp
viewer/webview/webviewaccesskey.cpp
)
set(libmessageviewer_web_LIB KF5::WebKit Qt5::WebKitWidgets)
endif()
if (QTWEBENGINE_SUPPORT_OPTION)
set(libmessageviewer_mailviewer_SRCS
viewer/webengine/mailwebengineview.cpp
viewer/webengine/mailwebenginepage.cpp
viewer/webengine/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
viewer/webengine/cidreferencesurlinterceptor/cidreferencesurlinterceptor.cpp
viewer/webengine/mailwebenginescript.cpp
set(libmessageviewer_mailviewer_SRCS
viewer/webengine/mailwebengineview.cpp
viewer/webengine/mailwebenginepage.cpp
viewer/webengine/loadexternalreferencesurlinterceptor/loadexternalreferencesurlinterceptor.cpp
viewer/webengine/cidreferencesurlinterceptor/cidreferencesurlinterceptor.cpp
viewer/webengine/mailwebenginescript.cpp
${libmessageviewer_mailviewer_SRCS}
findbar/findbarwebengineview.cpp
)
${libmessageviewer_mailviewer_SRCS}
findbar/findbarwebengineview.cpp
)
set(libmessageviewer_web_LIB Qt5::WebEngineWidgets ${libmessageviewer_web_LIB} KF5::WebEngineViewer)
endif()
set(libmessageviewer_web_LIB Qt5::WebEngineWidgets ${libmessageviewer_web_LIB} KF5::WebEngineViewer)
set(libmessageviewer_viewer_SRCS
viewer/bodypartformatterfactory.cpp
......@@ -131,11 +118,9 @@ set(libmessageviewer_widgets_SRCS
widgets/zoomactionmenu.cpp
)
if (QTWEBENGINE_SUPPORT_OPTION)
set(libmessageviewer_widgets_webengine_SRCS
widgets/mailsourcewebengineviewer.cpp
)
endif()
set(libmessageviewer_widgets_webengine_SRCS
widgets/mailsourcewebengineviewer.cpp
)
set(libmessageviewer_header_SRCS
header/contactdisplaymessagememento.cpp
......@@ -166,11 +151,9 @@ if (NOT MESSAGEVIEWER_USE_QTWEBENGINE)
set(libmessageviewer_scamdetection_SRCS scamdetection/scamdetection.cpp ${libmessageviewer_scamdetection_SRCS})
endif()
if (QTWEBENGINE_SUPPORT_OPTION)
set(libmessageviewer_scamdetection_webengine_SRCS
scamdetection/scamdetectionwebengine.cpp
)
endif()
set(libmessageviewer_scamdetection_webengine_SRCS
scamdetection/scamdetectionwebengine.cpp
)
set(libmessageviewer_findbar_SRCS
findbar/findbarbase.cpp
......@@ -185,24 +168,16 @@ set(libmessageviewer_utils_SRCS
utils/messageviewerutil.cpp
)
if (QTWEBENGINE_SUPPORT_OPTION)
set(libmessageviewer_htmlwriter_webengine_SRCS
htmlwriter/webengineparthtmlwriter.cpp
htmlwriter/webengineembedpart.cpp
)
endif()
set(libmessageviewer_htmlwriter_webengine_SRCS
htmlwriter/webengineparthtmlwriter.cpp
htmlwriter/webengineembedpart.cpp
)
set(libmessageviewer_htmlwriter_SRCS
htmlwriter/teehtmlwriter.cpp
${libmessageviewer_htmlwriter_webengine_SRCS}
)
if (NOT MESSAGEVIEWER_USE_QTWEBENGINE)
set(libmessageviewer_htmlwriter_SRCS htmlwriter/webkitparthtmlwriter.cpp ${libmessageviewer_htmlwriter_SRCS})
endif()
set(libmessageviewer_antispam_SRCS
antispam/spamheaderanalyzer.cpp
antispam/antispamconfig.cpp
......@@ -317,17 +292,15 @@ ecm_generate_headers(MessageViewer_Camelcasewebviewer_HEADERS
RELATIVE viewer/webview
)
if (QTWEBENGINE_SUPPORT_OPTION)
ecm_generate_headers(MessageViewer_Camelcasewebengine_HEADERS
HEADER_NAMES
MailWebEnginePage
MailWebEngineView
ecm_generate_headers(MessageViewer_Camelcasewebengine_HEADERS
HEADER_NAMES
MailWebEnginePage
MailWebEngineView
REQUIRED_HEADERS MessageViewer_webengine_HEADERS
PREFIX MessageViewer
RELATIVE viewer/webengine
)
endif()
REQUIRED_HEADERS MessageViewer_webengine_HEADERS
PREFIX MessageViewer
RELATIVE viewer/webengine
)
ecm_generate_headers(MessageViewer_Camelcasescam_HEADERS
HEADER_NAMES
......@@ -382,15 +355,13 @@ ecm_generate_headers(MessageViewer_Camelfindbar_HEADERS
RELATIVE findbar
)
if (QTWEBENGINE_SUPPORT_OPTION)
ecm_generate_headers(MessageViewer_CamelfindbarWebEngine_HEADERS
HEADER_NAMES
FindBarWebEngineView
REQUIRED_HEADERS MessageViewer_findbarWebEngine_HEADERS
PREFIX MessageViewer
RELATIVE findbar
)
endif()
ecm_generate_headers(MessageViewer_CamelfindbarWebEngine_HEADERS
HEADER_NAMES
FindBarWebEngineView
REQUIRED_HEADERS MessageViewer_findbarWebEngine_HEADERS
PREFIX MessageViewer
RELATIVE findbar
)
ecm_generate_headers(MessageViewer_Camelcaseantispam_HEADERS
HEADER_NAMES
......
if (QTWEBENGINE_SUPPORT_OPTION)
ecm_add_test(webengineembedparttest.cpp ../webengineembedpart.cpp
TEST_NAME webengineembedparttest
NAME_PREFIX "messageviewer-webengine-"
LINK_LIBRARIES Qt5::Test Qt5::Core
)
endif()
ecm_add_test(webengineembedparttest.cpp ../webengineembedpart.cpp
TEST_NAME webengineembedparttest
NAME_PREFIX "messageviewer-webengine-"
LINK_LIBRARIES Qt5::Test Qt5::Core
)
/* -*- c++ -*-
webkitparthtmlwriter.cpp
This file is part of KMail, the KDE mail client.
Copyright (c) 2003 Marc Mutz <mutz@kde.org>
Copyright (c) 2009 Torgny Nyblom <nyblom@kde.org>
KMail 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.
KMail 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
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include "webkitparthtmlwriter.h"
#include "messageviewer_debug.h"
#include "viewer/webview/mailwebview.h"
#include <QUrl>
#include <cassert>
#include <QByteArray>
#include <QWebView>
#include <QWebElement>
#include <QWebFrame>
using namespace MessageViewer;
WebKitPartHtmlWriter::WebKitPartHtmlWriter(MailWebView *view, QObject *parent)
: QObject(parent), MimeTreeParser::HtmlWriter(),
mHtmlView(view), mState(Ended)
{
assert(view);
}
WebKitPartHtmlWriter::~WebKitPartHtmlWriter()
{
}
void WebKitPartHtmlWriter::begin(const QString &css)
{
// The stylesheet is now included CSSHelper::htmlHead()
Q_UNUSED(css);
if (mState != Ended) {
qCWarning(MESSAGEVIEWER_LOG) << "begin() called on non-ended session!";
reset();
}
mEmbeddedPartMap.clear();
// clear the widget:
mHtmlView->setUpdatesEnabled(false);
mHtmlView->scrollUp(10);
// PENDING(marc) push into MailWebView
mHtmlView->load(QUrl());
mState = Begun;
}
void WebKitPartHtmlWriter::end()
{
if (mState != Begun) {
qCWarning(MESSAGEVIEWER_LOG) << "Called on non-begun or queued session!";
}
if (!mExtraHead.isEmpty()) {
insertExtraHead();
mExtraHead.clear();
}
mHtmlView->setHtml(mHtml, QUrl(QStringLiteral("file:///")));
mHtmlView->show();
mHtml.clear();
resolveCidUrls();
mHtmlView->scamCheck();
mHtmlView->setUpdatesEnabled(true);
mHtmlView->update();
mState = Ended;
Q_EMIT finished();
}
void WebKitPartHtmlWriter::reset()
{
if (mState != Ended) {
mHtml.clear();
mState = Begun; // don't run into end()'s warning
end();
mState = Ended;
}
}
void WebKitPartHtmlWriter::write(const QString &str)
{
if (mState != Begun) {
qCWarning(MESSAGEVIEWER_LOG) << "Called in Ended or Queued state!";
}
mHtml.append(str);
}
void WebKitPartHtmlWriter::queue(const QString &str)
{
write(str);
}
void WebKitPartHtmlWriter::flush()
{
mState = Begun; // don't run into end()'s warning
end();
}
void WebKitPartHtmlWriter::embedPart(const QByteArray &contentId,
const QString &contentURL)
{
mEmbeddedPartMap[QLatin1String(contentId)] = contentURL;
}
void WebKitPartHtmlWriter::resolveCidUrls()
{
// FIXME: instead of patching around in the HTML source, this should
// be replaced by a custom QNetworkAccessManager (for QWebView), or
// virtual loadResource() (for QTextBrowser)
QWebElement root = mHtmlView->page()->mainFrame()->documentElement();
QWebElementCollection images = root.findAll(QStringLiteral("img"));
QWebElementCollection::iterator end(images.end());
for (QWebElementCollection::iterator it = images.begin(); it != end; ++it) {
QUrl url((*it).attribute(QStringLiteral("src")));
if (url.scheme() == QLatin1String("cid")) {
EmbeddedPartMap::const_iterator cit = mEmbeddedPartMap.constFind(url.path());
if (cit != mEmbeddedPartMap.constEnd()) {
qCDebug(MESSAGEVIEWER_LOG) << "Replacing" << url.toDisplayString() << "by" << cit.value();
(*it).setAttribute(QStringLiteral("src"), cit.value());
}
}
}
}
void WebKitPartHtmlWriter::insertExtraHead()
{
const QString headTag(QStringLiteral("<head>"));
const int index = mHtml.indexOf(headTag);
if (index != -1) {
mHtml.insert(index + headTag.length(), mExtraHead);
}
}
void WebKitPartHtmlWriter::extraHead(const QString &str)
{
mExtraHead = str;
}
/* -*- c++ -*-
webkitparthtmlwriter.h
This file is part of KMail, the KDE mail client.
Copyright (c) 2003 Marc Mutz <mutz@kde.org>
Copyright (c) 2009 Torgny Nyblom <nyblom@kde.org>
KMail 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.
KMail 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
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifndef MESSAGEVIEWER_WEBKITPARTHTMLWRITER_H
#define MESSAGEVIEWER_WEBKITPARTHTMLWRITER_H
#include <MimeTreeParser/HtmlWriter>
#include <QObject>
#include <QString>
#include <QByteArray>
#include <QMap>
namespace MessageViewer
{
class MailWebView;
}
namespace MessageViewer
{
class WebKitPartHtmlWriter : public QObject, public MimeTreeParser::HtmlWriter
{
Q_OBJECT
public:
explicit WebKitPartHtmlWriter(MailWebView *view, QObject *parent = Q_NULLPTR);
~WebKitPartHtmlWriter();
void begin(const QString &cssDefs) Q_DECL_OVERRIDE;
void end() Q_DECL_OVERRIDE;
void reset() Q_DECL_OVERRIDE;
void write(const QString &str) Q_DECL_OVERRIDE;
void queue(const QString &str) Q_DECL_OVERRIDE;
void flush() Q_DECL_OVERRIDE;
void embedPart(const QByteArray &contentId, const QString &url) Q_DECL_OVERRIDE;
void extraHead(const QString &str) Q_DECL_OVERRIDE;
Q_SIGNALS:
void finished();
private:
void resolveCidUrls();
void insertExtraHead();
private:
MailWebView *mHtmlView;
QString mHtml;
QString mExtraHead;
enum State {
Begun,
Queued,
Ended
} mState;
// Key is Content-Id, value is URL
typedef QMap<QString, QString> EmbeddedPartMap;
EmbeddedPartMap mEmbeddedPartMap;
};
}
#endif // __MESSAGEVIEWER_WEBKITPARTHTMLWRITER_H__
if (NOT MESSAGEVIEWER_USE_QTWEBENGINE)
ecm_add_test(test_scamdetection.cpp
TEST_NAME scamdetectiontest
NAME_PREFIX "messageviewer-scamdetection-"
LINK_LIBRARIES KF5::MessageViewer Qt5::Test Qt5::WebKitWidgets
)
endif()
ecm_add_test(scamattributetest.cpp ../scamattribute.cpp
TEST_NAME scamattributetest
NAME_PREFIX "messageviewer-scamdetection-"
LINK_LIBRARIES Qt5::Test KF5::AkonadiCore
)
if (QTWEBENGINE_SUPPORT_OPTION)
ecm_add_test(scamdetectionwebenginetest.cpp
TEST_NAME scamdetectionwebenginetest
NAME_PREFIX "messageviewer-scamwebenginedetection-"
LINK_LIBRARIES KF5::MessageViewer Qt5::Test Qt5::WebEngine Qt5::WebEngineWidgets
)
endif()
ecm_add_test(scamdetectionwebenginetest.cpp
TEST_NAME scamdetectionwebenginetest
NAME_PREFIX "messageviewer-scamwebenginedetection-"
LINK_LIBRARIES KF5::MessageViewer Qt5::Test Qt5::WebEngine Qt5::WebEngineWidgets
)
/*
Copyright (c) 2013-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 "test_scamdetection.h"
#include "scamdetection/scamdetection.h"
#include "scamdetection/scamcheckshorturl.h"
#include <QWebElement>
#include <QWebFrame>
#include <QWebSettings>
#include <QWebPage>
bool ScamDetectionTest::scanPage(QWebFrame *frame)
{
QString details;
bool foundScam = false;
const QWebElement rootElement = frame->documentElement();
bool result = MessageViewer::ScamDetection::scanFrame(rootElement, details);
if (result) {
foundScam = true;
}
foreach (QWebFrame *childFrame, frame->childFrames()) {
result = MessageViewer::ScamDetection::scanFrame(childFrame->documentElement(), details);
if (result) {
foundScam = true;
}
}
return foundScam;
}
bool ScamDetectionTest::testHtml(const QString &content)
{
QWebPage page;
page.settings()->setAttribute(QWebSettings::JavascriptEnabled, false);
page.settings()->setAttribute(QWebSettings::JavaEnabled, false);
page.settings()->setAttribute(QWebSettings::PluginsEnabled, false);
page.currentFrame()->setHtml(content);
return scanPage(page.currentFrame());
}
void ScamDetectionTest::testNoScam()
{
QString content = QStringLiteral("<html><body><a href=\"www.kde.org\">kde</a></body></html>");
QCOMPARE(testHtml(content), false);
content = QStringLiteral("<html><body><a href=\"http://www.kde.org\" title=\"http://www.kde.org\">kde</a></body></html>");
QCOMPARE(testHtml(content), false);
content = QStringLiteral("<html><body><a href=\"https://www.kde.org\" title=\"https://www.kde.org\">kde</a></body></html>");
QCOMPARE(testHtml(content), false);
}
void ScamDetectionTest::testHexaValue()
{
const QString content = QStringLiteral("<html><body><a href=\"http://125.15.55.88/\" title=\"http://0x12.0x1e.0x0A.0x00\">test</a></body></html>");
QCOMPARE(testHtml(content), true);
}
void ScamDetectionTest::testIp()
{
QString content = QStringLiteral("<html><body><a href=\"http://127.0.0.1/\">test</a></body></html>");
QCOMPARE(testHtml(content), false);
content = QStringLiteral("<html><body><a href=\"http://125.15.55.88/\" title=\"http://www.kde.org\">test</a></body></html>");
QCOMPARE(testHtml(content), true);
content = QStringLiteral("<html><body><a href=\"http://125.15.55.88/\" title=\"http://125.15.55.88/\">test</a></body></html>");
QCOMPARE(testHtml(content), true);
}
void ScamDetectionTest::testHref()
{
const QString content = QStringLiteral("<html><body><a href=\"http://www.kde.org/\" title=\"http://www.kde.org\">test</a></body></html>");
QCOMPARE(testHtml(content), false);
}
void ScamDetectionTest::testRedirectUrl()
{
QString content = QStringLiteral("<html><body><a href=\"http://www.google.fr/url?q=http://www.yahoo.com\">test</a></body></html>");
QCOMPARE(testHtml(content), true);
content = QStringLiteral("<html><body><a href=\"kmail:showAuditLog?log=http://www.foo.com%3http://www.bla.com\">test</a></body></html>");
QCOMPARE(testHtml(content), false);
}
void ScamDetectionTest::testUrlWithNumericValue()
{
QString content = QStringLiteral("<html><body><a href=\"http://baseball2.2ndhalfplays.com/nested/attribs/\">http://baseball2.2ndhalfplays.com/nested/attribs</html>");
QCOMPARE(testHtml(content), false);
content = QStringLiteral("<html><body><a href=\"http://25.15.55.88/\">test</a></body></html>");
QCOMPARE(testHtml(content), true);
content = QStringLiteral("<html><body><a href=\"http://255.0.1.1/\">test</a></body></html>");
QCOMPARE(testHtml(content), true);
content = QStringLiteral("<html><body><a href=\"http://1.0.1.1/\">test</a></body></html>");
QCOMPARE(testHtml(content), true);
content = QStringLiteral("<html><body><a href=\"http://255.500.1.1/\">test</a></body></html>");
QCOMPARE(testHtml(content), true);
content = QStringLiteral("<html><body><a href=\"http://baseball.2ndhalfplays.com/nested/attribs/\">http://baseball2.2ndhalfplays.com/nested/attribs</html>");
QCOMPARE(testHtml(content), false);
content = QStringLiteral("<html><body><a href=\"http://baseball.2ndhalfplays.com/nested/attribs/\">http://baseball2.2ndhalfplays.com/nested/attribs</html>");