diff --git a/editor/potentialphishingemail/autotests/CMakeLists.txt b/editor/potentialphishingemail/autotests/CMakeLists.txt new file mode 100644 index 000000000..8d8c4f849 --- /dev/null +++ b/editor/potentialphishingemail/autotests/CMakeLists.txt @@ -0,0 +1,6 @@ +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}) + diff --git a/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp b/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp new file mode 100644 index 000000000..a3eb97cb0 --- /dev/null +++ b/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp @@ -0,0 +1,63 @@ +/* + Copyright (c) 2015 Montel Laurent + + 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 +#include + +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("listEmails"); + QTest::addColumn("hasPotentialPhishing"); + QTest::newRow("NoPotentialPhishing") << (QStringList() << QLatin1String("foo@kde.org")) << false; + QTest::newRow("HasPotentialPhishing") << (QStringList() << QLatin1String("\"bla@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) diff --git a/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.h b/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.h new file mode 100644 index 000000000..ade03249d --- /dev/null +++ b/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.h @@ -0,0 +1,39 @@ +/* + Copyright (c) 2015 Montel Laurent + + 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 + +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 diff --git a/editor/potentialphishingemail/potentialphishingemailjob.cpp b/editor/potentialphishingemail/potentialphishingemailjob.cpp new file mode 100644 index 000000000..bcbbdd4ec --- /dev/null +++ b/editor/potentialphishingemail/potentialphishingemailjob.cpp @@ -0,0 +1,67 @@ +/* + Copyright (c) 2015 Montel Laurent + + 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 +#include +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; +} + diff --git a/editor/potentialphishingemail/potentialphishingemailjob.h b/editor/potentialphishingemail/potentialphishingemailjob.h new file mode 100644 index 000000000..5bff0aeb0 --- /dev/null +++ b/editor/potentialphishingemail/potentialphishingemailjob.h @@ -0,0 +1,46 @@ +/* + Copyright (c) 2015 Montel Laurent + + 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 +#include + +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 diff --git a/editor/potentialphishingemail/potentialphisingemailwarning.cpp b/editor/potentialphishingemail/potentialphisingemailwarning.cpp new file mode 100644 index 000000000..8de753858 --- /dev/null +++ b/editor/potentialphishingemail/potentialphisingemailwarning.cpp @@ -0,0 +1,41 @@ +/* + Copyright (c) 2015 Montel Laurent + + 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(); +} diff --git a/editor/potentialphishingemail/potentialphisingemailwarning.h b/editor/potentialphishingemail/potentialphisingemailwarning.h new file mode 100644 index 000000000..30390aca4 --- /dev/null +++ b/editor/potentialphishingemail/potentialphisingemailwarning.h @@ -0,0 +1,36 @@ +/* + Copyright (c) 2015 Montel Laurent + + 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 + +class PotentialPhisingEmailWarning : public KMessageWidget +{ + Q_OBJECT +public: + explicit PotentialPhisingEmailWarning(QWidget *parent = 0); + ~PotentialPhisingEmailWarning(); + + void setWarningText(const QString &text); +}; + +#endif // POTENTIALPHISINGEMAILWARNING_H