Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 9c121db7 authored by Laurent Montel's avatar Laurent Montel 😁

Look at to detect potential problem with email

parent 6354a534
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
set( kmail_potentialphishingemailjobtest_SRCS potentialphishingemailjobtest.cpp ../potentialphishingemailjob.cpp )
kde4_add_unit_test( kmail_potentialphishingemailjobtest ${kmail_potentialphishingemailjobtest_SRCS})
target_link_libraries( kmail_potentialphishingemailjobtest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDEPIMLIBS_KPIMUTILS_LIBS})
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "potentialphishingemailjobtest.h"
#include "../potentialphishingemailjob.h"
#include <qtest_kde.h>
#include <QStringList>
PotentialPhishingEmailJobTest::PotentialPhishingEmailJobTest(QObject *parent)
: QObject(parent)
{
}
PotentialPhishingEmailJobTest::~PotentialPhishingEmailJobTest()
{
}
void PotentialPhishingEmailJobTest::shouldNotStartIfNoEmails()
{
PotentialPhishingEmailJob *job = new PotentialPhishingEmailJob;
QVERIFY(!job->start());
QVERIFY(job->potentialPhisingEmails().isEmpty());
}
void PotentialPhishingEmailJobTest::shouldReturnPotentialPhishingEmails_data()
{
QTest::addColumn<QStringList>("listEmails");
QTest::addColumn<bool>("hasPotentialPhishing");
QTest::newRow("NoPotentialPhishing") << (QStringList() << QLatin1String("foo@kde.org")) << false;
QTest::newRow("HasPotentialPhishing") << (QStringList() << QLatin1String("\"bla@kde.org\" <foo@kde.org>")) << true;
}
void PotentialPhishingEmailJobTest::shouldReturnPotentialPhishingEmails()
{
QFETCH( QStringList, listEmails );
QFETCH( bool, hasPotentialPhishing );
PotentialPhishingEmailJob *job = new PotentialPhishingEmailJob;
job->setEmails(listEmails);
QVERIFY(job->start());
QCOMPARE(job->potentialPhisingEmails().isEmpty(), !hasPotentialPhishing);
}
QTEST_KDEMAIN(PotentialPhishingEmailJobTest, NoGUI)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef POTENTIALPHISHINGEMAILJOBTEST_H
#define POTENTIALPHISHINGEMAILJOBTEST_H
#include <QObject>
class PotentialPhishingEmailJobTest : public QObject
{
Q_OBJECT
public:
explicit PotentialPhishingEmailJobTest(QObject *parent = 0);
~PotentialPhishingEmailJobTest();
private Q_SLOTS:
void shouldNotStartIfNoEmails();
void shouldReturnPotentialPhishingEmails_data();
void shouldReturnPotentialPhishingEmails();
};
#endif // POTENTIALPHISHINGEMAILJOBTEST_H
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "potentialphishingemailjob.h"
#include <KPIMUtils/Email>
#include <QDebug>
PotentialPhishingEmailJob::PotentialPhishingEmailJob(QObject *parent)
: QObject(parent)
{
}
PotentialPhishingEmailJob::~PotentialPhishingEmailJob()
{
}
void PotentialPhishingEmailJob::setEmails(const QStringList &emails)
{
mEmails = emails;
}
QStringList PotentialPhishingEmailJob::potentialPhisingEmails() const
{
return mPotentialPhisingEmails;
}
bool PotentialPhishingEmailJob::start()
{
mPotentialPhisingEmails.clear();
if (mEmails.isEmpty()) {
deleteLater();
return false;
}
Q_FOREACH(const QString &addr, mEmails) {
QString tname, temail;
KPIMUtils::extractEmailAddressAndName( addr, temail, tname ); // ignore return value
// which is always false
if (tname.contains(QLatin1String("@"))) { //Potential address
if (temail != tname) {
mPotentialPhisingEmails.append(addr);
}
}
}
Q_EMIT potentialPhisingEmailsFound(mPotentialPhisingEmails);
deleteLater();
return true;
}
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef POTENTIALPHISHINGEMAILJOB_H
#define POTENTIALPHISHINGEMAILJOB_H
#include <QObject>
#include <QStringList>
class PotentialPhishingEmailJob : public QObject
{
Q_OBJECT
public:
explicit PotentialPhishingEmailJob(QObject *parent = 0);
~PotentialPhishingEmailJob();
void setEmails(const QStringList &emails);
QStringList potentialPhisingEmails() const;
bool start();
Q_SIGNALS:
void potentialPhisingEmailsFound(const QStringList &emails);
private:
QStringList mEmails;
QStringList mPotentialPhisingEmails;
};
#endif // POTENTIALPHISHINGEMAILJOB_H
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "potentialphisingemailwarning.h"
PotentialPhisingEmailWarning::PotentialPhisingEmailWarning(QWidget *parent)
: KMessageWidget(parent)
{
setVisible(false);
setCloseButtonVisible(true);
setMessageType(Warning);
setWordWrap(true);
}
PotentialPhisingEmailWarning::~PotentialPhisingEmailWarning()
{
}
void PotentialPhisingEmailWarning::setWarningText(const QString &text)
{
animatedShow();
}
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef POTENTIALPHISINGEMAILWARNING_H
#define POTENTIALPHISINGEMAILWARNING_H
#include <KMessageWidget>
class PotentialPhisingEmailWarning : public KMessageWidget
{
Q_OBJECT
public:
explicit PotentialPhisingEmailWarning(QWidget *parent = 0);
~PotentialPhisingEmailWarning();
void setWarningText(const QString &text);
};
#endif // POTENTIALPHISINGEMAILWARNING_H
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