Commit 65cce9e3 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Readd autotest

parent 45fe9c20
Pipeline #24306 canceled with stage
......@@ -25,6 +25,27 @@ MessageViewerUtilsTest::MessageViewerUtilsTest(QObject *parent)
{
}
void MessageViewerUtilsTest::shouldExcludeHeader_data()
{
QTest::addColumn<QString>("header");
QTest::addColumn<bool>("exclude");
QTest::newRow("emptylist") << QString() << false;
QTest::newRow("REFRESH1") << QStringLiteral("<meta content=\"0;URL=http://www.kde.org\" http-equiv=\'REFRESH\'></head>") << true;
QTest::newRow("REFRESH2") << QStringLiteral("<meta content=\"0;URL=http://www.kde.org\" http-equiv=\"REFRESH\"></head>") << true;
QTest::newRow("REFRESH3") << QStringLiteral("<meta content=\"0;URL=http://www.kde.org\" http-equiv=\"refresh\"></head>") << true;
QTest::newRow("REFRESH4") << QStringLiteral("<meta content=\"0;URL=http://www.kde.org\" http-equiv=\"&#82;EFRESH\"></head>") << true;
QTest::newRow("REFRESH5") << QStringLiteral("<meta content=\"0;URL=http://www.kde.org\" http-equiv=\'&#82;EFRESH\'></head>") << true;
QTest::newRow("REFRESH6") << QStringLiteral("<meta content=\"0;URL=http://www.kde.org\" http-equiv= \"REFRESH\"></head>") << true;
}
void MessageViewerUtilsTest::shouldExcludeHeader()
{
QFETCH(QString, header);
QFETCH(bool, exclude);
QCOMPARE(MessageViewer::Util::excludeExtraHeader(header), exclude);
}
void MessageViewerUtilsTest::shouldContainsExternalReferences_data()
{
QTest::addColumn<QString>("filename");
......
......@@ -27,6 +27,9 @@ public:
explicit MessageViewerUtilsTest(QObject *parent = nullptr);
~MessageViewerUtilsTest() = default;
private Q_SLOTS:
void shouldExcludeHeader_data();
void shouldExcludeHeader();
void shouldContainsExternalReferences_data();
void shouldContainsExternalReferences();
......
......@@ -635,6 +635,15 @@ bool Util::saveMessageInMbox(const Akonadi::Item::List &retrievedMsgs, QWidget *
return saveMessageInMboxAndGetUrl(url, retrievedMsgs, parent, appendMessages);
}
bool Util::excludeExtraHeader(const QString &s)
{
QRegularExpression ref(QStringLiteral("http-equiv=\\s*(\'|\")(&#82;|R)EFRESH(\'|\")"), QRegularExpression::CaseInsensitiveOption);
if (s.contains(ref)) {
return true;
}
return false;
}
QAction *Util::createAppAction(const KService::Ptr &service, bool singleOffer, QActionGroup *actionGroup, QObject *parent)
{
QString actionName(service->name().replace(QLatin1Char('&'), QStringLiteral("&&")));
......
......@@ -63,6 +63,7 @@ Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT bool containsExternalReferences(const QSt
Q_REQUIRED_RESULT bool MESSAGEVIEWER_EXPORT checkOverwrite(const QUrl &url, QWidget *w);
Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT bool saveMessageInMboxAndGetUrl(QUrl &url, const Akonadi::Item::List &retrievedMsgs, QWidget *parent, bool appendMessages = false);
Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT bool saveMessageInMbox(const Akonadi::Item::List &retrievedMsgs, QWidget *parent, bool appendMessages = false);
Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT bool excludeExtraHeader(const QString &s);
Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT QString generateMboxFileName(const Akonadi::Item &msgBase);
Q_REQUIRED_RESULT MESSAGEVIEWER_EXPORT bool saveAttachments(const KMime::Content::List &contents, QWidget *parent, QList<QUrl> &saveUrl);
......
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