From 89f1dc42a440383d9d5922d043ca6cb3b871160e Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Tue, 27 Jan 2015 13:59:37 +0100 Subject: [PATCH 1/3] Improve check support --- CMakeLists.txt | 1 + editor/kmcomposewin.cpp | 29 ++++++++++++++- editor/kmcomposewin.h | 2 ++ .../autotests/CMakeLists.txt | 6 ++++ .../potentialphishingdetaildialogtest.cpp | 35 +++++++++++++++++++ .../potentialphishingdetaildialogtest.h | 34 ++++++++++++++++++ .../potentialphishingemailjobtest.cpp | 10 +----- .../autotests/potentialphishingemailjobtest.h | 1 - .../potentialphishingdetaildialog.cpp | 35 +++++++++++++++++++ .../potentialphishingdetaildialog.h | 34 ++++++++++++++++++ .../potentialphishingemailjob.cpp | 4 +-- .../potentialphishingemailjob.h | 2 +- .../potentialphishingemailwarning.cpp | 20 +++++++++-- .../potentialphishingemailwarning.h | 9 ++++- 14 files changed, 204 insertions(+), 18 deletions(-) create mode 100644 editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.cpp create mode 100644 editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.h create mode 100644 editor/potentialphishingemail/potentialphishingdetaildialog.cpp create mode 100644 editor/potentialphishingemail/potentialphishingdetaildialog.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 646a12728..508cfa276 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,6 +142,7 @@ if (KDEPIM_BUILD_DESKTOP) set(kmailprivate_editor_potentialphishingemail_SRCS editor/potentialphishingemail/potentialphishingemailwarning.cpp editor/potentialphishingemail/potentialphishingemailjob.cpp + editor/potentialphishingemail/potentialphishingdetaildialog.cpp ) set(kmailprivate_dialogs_LIB_SRCS dialog/archivefolderdialog.cpp diff --git a/editor/kmcomposewin.cpp b/editor/kmcomposewin.cpp index 1471e6efa..0445cde62 100644 --- a/editor/kmcomposewin.cpp +++ b/editor/kmcomposewin.cpp @@ -178,6 +178,7 @@ #include #include #include +#include using Sonnet::DictionaryComboBox; using MailTransport::TransportManager; @@ -3025,7 +3026,7 @@ void KMComposeWin::confirmBeforeSend() } } -void KMComposeWin::slotCheckSendNow() +void KMComposeWin::slotCheckSendNowStep2() { if ( GlobalSettings::self()->confirmBeforeSend() ) { confirmBeforeSend(); @@ -3046,6 +3047,32 @@ void KMComposeWin::slotCheckSendNow() } } +void KMComposeWin::slotCheckSendNow() +{ + PotentialPhishingEmailJob *job = new PotentialPhishingEmailJob(this); + QStringList lst; + lst << mComposerBase->to(); + if (!mComposerBase->cc().isEmpty()) + lst << mComposerBase->cc().split(QLatin1Char(',')); + if (!mComposerBase->bcc().isEmpty()) + lst << mComposerBase->bcc().split(QLatin1Char(',')); + job->setEmails(lst); + connect(job, SIGNAL(potentialPhishingEmailsFound(QStringList)), this, SLOT(slotPotentialPhishingEmailsFound(QStringList))); + job->start(); +} + +void KMComposeWin::slotPotentialPhishingEmailsFound(const QStringList &list) +{ +#if 1 + slotCheckSendNowStep2(); +#else + if (list.isEmpty()) { + slotCheckSendNowStep2(); + } else { + //mPotentialPhishingEmailWarning->setWarningText(); + } +#endif +} bool KMComposeWin::checkRecipientNumber() const { diff --git a/editor/kmcomposewin.h b/editor/kmcomposewin.h index e82d888a4..29b6e8c7a 100644 --- a/editor/kmcomposewin.h +++ b/editor/kmcomposewin.h @@ -450,6 +450,8 @@ private slots: void slotSnippetWidgetVisibilityChanged(bool b); void slotOverwriteModeWasChanged(bool state); void slotExpandGroupResult(KJob *job); + void slotCheckSendNowStep2(); + void slotPotentialPhishingEmailsFound(const QStringList &list); public: // kmcommand // FIXME we need to remove these, but they're pure virtual in Composer. void addAttach( KMime::Content *msgPart ); diff --git a/editor/potentialphishingemail/autotests/CMakeLists.txt b/editor/potentialphishingemail/autotests/CMakeLists.txt index 8d8c4f849..51384cd20 100644 --- a/editor/potentialphishingemail/autotests/CMakeLists.txt +++ b/editor/potentialphishingemail/autotests/CMakeLists.txt @@ -4,3 +4,9 @@ set( kmail_potentialphishingemailjobtest_SRCS potentialphishingemailjobtest.cpp kde4_add_unit_test( kmail_potentialphishingemailjobtest ${kmail_potentialphishingemailjobtest_SRCS}) target_link_libraries( kmail_potentialphishingemailjobtest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDEPIMLIBS_KPIMUTILS_LIBS}) + +set( kmail_potentialphishingdetaildialogtest_SRCS potentialphishingdetaildialogtest.cpp ../potentialphishingdetaildialog.cpp ) +kde4_add_unit_test( kmail_potentialphishingdetaildialogtest ${kmail_potentialphishingdetaildialogtest_SRCS}) +target_link_libraries( kmail_potentialphishingdetaildialogtest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ) + + diff --git a/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.cpp b/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.cpp new file mode 100644 index 000000000..6c18c4473 --- /dev/null +++ b/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.cpp @@ -0,0 +1,35 @@ +/* + 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 "potentialphishingdetaildialogtest.h" +#include + +PotentialPhishingDetailDialogTest::PotentialPhishingDetailDialogTest(QObject *parent) + : QObject(parent) +{ + +} + +PotentialPhishingDetailDialogTest::~PotentialPhishingDetailDialogTest() +{ + +} + +QTEST_KDEMAIN(PotentialPhishingDetailDialogTest, NoGUI) diff --git a/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.h b/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.h new file mode 100644 index 000000000..720c42631 --- /dev/null +++ b/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.h @@ -0,0 +1,34 @@ +/* + 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 POTENTIALPHISHINGDETAILDIALOGTEST_H +#define POTENTIALPHISHINGDETAILDIALOGTEST_H + +#include + +class PotentialPhishingDetailDialogTest : public QObject +{ + Q_OBJECT +public: + explicit PotentialPhishingDetailDialogTest(QObject *parent = 0); + ~PotentialPhishingDetailDialogTest(); +}; + +#endif // POTENTIALPHISHINGDETAILDIALOGTEST_H diff --git a/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp b/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp index 47746c36a..5f05c6a6d 100644 --- a/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp +++ b/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp @@ -64,19 +64,11 @@ void PotentialPhishingEmailJobTest::shouldReturnPotentialPhishingEmails() void PotentialPhishingEmailJobTest::shouldEmitSignal() { PotentialPhishingEmailJob *job = new PotentialPhishingEmailJob; - QSignalSpy spy(job, SIGNAL(potentialPhisingEmailsFound(QStringList))); + QSignalSpy spy(job, SIGNAL(potentialPhishingEmailsFound(QStringList))); job->setEmails((QStringList() << QLatin1String("\"bla@kde.org\" "))); job->start(); QCOMPARE(spy.count(), 1); } -void PotentialPhishingEmailJobTest::shouldNotEmitSignalWhenPotentialPhishingNotFound() -{ - PotentialPhishingEmailJob *job = new PotentialPhishingEmailJob; - QSignalSpy spy(job, SIGNAL(potentialPhisingEmailsFound(QStringList))); - job->setEmails((QStringList() << QLatin1String(""))); - job->start(); - QCOMPARE(spy.count(), 0); -} QTEST_KDEMAIN(PotentialPhishingEmailJobTest, NoGUI) diff --git a/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.h b/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.h index c44bdac1b..3f971c54f 100644 --- a/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.h +++ b/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.h @@ -35,7 +35,6 @@ private Q_SLOTS: void shouldReturnPotentialPhishingEmails_data(); void shouldReturnPotentialPhishingEmails(); void shouldEmitSignal(); - void shouldNotEmitSignalWhenPotentialPhishingNotFound(); }; #endif // POTENTIALPHISHINGEMAILJOBTEST_H diff --git a/editor/potentialphishingemail/potentialphishingdetaildialog.cpp b/editor/potentialphishingemail/potentialphishingdetaildialog.cpp new file mode 100644 index 000000000..a99711794 --- /dev/null +++ b/editor/potentialphishingemail/potentialphishingdetaildialog.cpp @@ -0,0 +1,35 @@ +/* + 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 "potentialphishingdetaildialog.h" + +#include + +PotentialPhishingDetailDialog::PotentialPhishingDetailDialog(QWidget *parent) + : KDialog(parent) +{ + +} + +PotentialPhishingDetailDialog::~PotentialPhishingDetailDialog() +{ + +} + diff --git a/editor/potentialphishingemail/potentialphishingdetaildialog.h b/editor/potentialphishingemail/potentialphishingdetaildialog.h new file mode 100644 index 000000000..cabec1f4b --- /dev/null +++ b/editor/potentialphishingemail/potentialphishingdetaildialog.h @@ -0,0 +1,34 @@ +/* + 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 POTENTIALPHISHINGDETAILDIALOG_H +#define POTENTIALPHISHINGDETAILDIALOG_H + +#include + +class PotentialPhishingDetailDialog : public KDialog +{ + Q_OBJECT +public: + explicit PotentialPhishingDetailDialog(QWidget *parent=0); + ~PotentialPhishingDetailDialog(); +}; + +#endif // POTENTIALPHISHINGDETAILDIALOG_H diff --git a/editor/potentialphishingemail/potentialphishingemailjob.cpp b/editor/potentialphishingemail/potentialphishingemailjob.cpp index 8ee05b42d..02e37939f 100644 --- a/editor/potentialphishingemail/potentialphishingemailjob.cpp +++ b/editor/potentialphishingemail/potentialphishingemailjob.cpp @@ -59,9 +59,7 @@ bool PotentialPhishingEmailJob::start() } } } - if (!mPotentialPhisingEmails.isEmpty()) { - Q_EMIT potentialPhisingEmailsFound(mPotentialPhisingEmails); - } + Q_EMIT potentialPhishingEmailsFound(mPotentialPhisingEmails); deleteLater(); return true; } diff --git a/editor/potentialphishingemail/potentialphishingemailjob.h b/editor/potentialphishingemail/potentialphishingemailjob.h index 5bff0aeb0..c1a9753d3 100644 --- a/editor/potentialphishingemail/potentialphishingemailjob.h +++ b/editor/potentialphishingemail/potentialphishingemailjob.h @@ -36,7 +36,7 @@ public: bool start(); Q_SIGNALS: - void potentialPhisingEmailsFound(const QStringList &emails); + void potentialPhishingEmailsFound(const QStringList &emails); private: QStringList mEmails; diff --git a/editor/potentialphishingemail/potentialphishingemailwarning.cpp b/editor/potentialphishingemail/potentialphishingemailwarning.cpp index 10f816d28..e6cd591dc 100644 --- a/editor/potentialphishingemail/potentialphishingemailwarning.cpp +++ b/editor/potentialphishingemail/potentialphishingemailwarning.cpp @@ -20,6 +20,7 @@ #include "potentialphishingemailwarning.h" +#include PotentialPhishingEmailWarning::PotentialPhishingEmailWarning(QWidget *parent) : KMessageWidget(parent) @@ -28,6 +29,11 @@ PotentialPhishingEmailWarning::PotentialPhishingEmailWarning(QWidget *parent) setCloseButtonVisible(true); setMessageType(Warning); setWordWrap(true); + + //Add i18n in kf5 + setText(QLatin1String("Some address mail seems a potential phishing email (Details...)")); + + connect(this, SIGNAL(linkActivated(QString)), SLOT(slotShowDetails(QString))); } PotentialPhishingEmailWarning::~PotentialPhishingEmailWarning() @@ -35,7 +41,17 @@ PotentialPhishingEmailWarning::~PotentialPhishingEmailWarning() } -void PotentialPhishingEmailWarning::setWarningText(const QString &text) +void PotentialPhishingEmailWarning::slotShowDetails(const QString &link) +{ + if (link == QLatin1String("phishingdetails")) { + Q_EMIT showDetails(); + } +} + +void PotentialPhishingEmailWarning::setPotentialPhisingEmail(const QStringList &lst) { - animatedShow(); + mPotentialPhishingEmails = lst; + if (!mPotentialPhishingEmails.isEmpty()) { + animatedShow(); + } } diff --git a/editor/potentialphishingemail/potentialphishingemailwarning.h b/editor/potentialphishingemail/potentialphishingemailwarning.h index fedd7b3fd..cff894727 100644 --- a/editor/potentialphishingemail/potentialphishingemailwarning.h +++ b/editor/potentialphishingemail/potentialphishingemailwarning.h @@ -30,7 +30,14 @@ public: explicit PotentialPhishingEmailWarning(QWidget *parent = 0); ~PotentialPhishingEmailWarning(); - void setWarningText(const QString &text); + void setPotentialPhisingEmail(const QStringList &lst); +Q_SIGNALS: + void showDetails(); + +private slots: + void slotShowDetails(const QString &link); +private: + QStringList mPotentialPhishingEmails; }; #endif // POTENTIALPHISHINGEMAILWARNING_H From 21f90273047abd31ee4d5155c157c864582b5c8d Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Tue, 27 Jan 2015 14:01:18 +0100 Subject: [PATCH 2/3] Add potential emails --- editor/kmcomposewin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor/kmcomposewin.cpp b/editor/kmcomposewin.cpp index 0445cde62..79b352564 100644 --- a/editor/kmcomposewin.cpp +++ b/editor/kmcomposewin.cpp @@ -3069,7 +3069,7 @@ void KMComposeWin::slotPotentialPhishingEmailsFound(const QStringList &list) if (list.isEmpty()) { slotCheckSendNowStep2(); } else { - //mPotentialPhishingEmailWarning->setWarningText(); + mPotentialPhishingEmailWarning->setPotentialPhisingEmail(list); } #endif } From 24ff523fe1103e04f860974f909d9b4d6d799dbd Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Tue, 27 Jan 2015 22:40:49 +0100 Subject: [PATCH 3/3] improve check email --- editor/kmcomposewin.cpp | 5 ++ .../potentialphishingdetaildialogtest.cpp | 58 ++++++++++++++- .../potentialphishingdetaildialogtest.h | 5 ++ .../potentialphishingemailjobtest.cpp | 12 +++- .../potentialphishingdetaildialog.cpp | 70 ++++++++++++++++++- .../potentialphishingdetaildialog.h | 12 +++- .../potentialphishingemailjob.cpp | 19 +++-- .../potentialphishingemailjob.h | 3 + .../potentialphishingemailwarning.cpp | 13 +++- .../potentialphishingemailwarning.h | 3 +- 10 files changed, 186 insertions(+), 14 deletions(-) diff --git a/editor/kmcomposewin.cpp b/editor/kmcomposewin.cpp index 79b352564..7655fbfde 100644 --- a/editor/kmcomposewin.cpp +++ b/editor/kmcomposewin.cpp @@ -434,6 +434,7 @@ KMComposeWin::KMComposeWin( const KMime::Message::Ptr &aMsg, bool lastSignState, v->addWidget(mAttachmentMissing); mPotentialPhishingEmailWarning = new PotentialPhishingEmailWarning(this); + connect(mPotentialPhishingEmailWarning, SIGNAL(sendNow()), this, SLOT(slotCheckSendNowStep2())); v->addWidget(mPotentialPhishingEmailWarning); if (GlobalSettings::self()->showForgottenAttachmentWarning()) { @@ -3050,6 +3051,10 @@ void KMComposeWin::slotCheckSendNowStep2() void KMComposeWin::slotCheckSendNow() { PotentialPhishingEmailJob *job = new PotentialPhishingEmailJob(this); + KConfigGroup group( KGlobal::config(), "PotentialPhishing"); + const QStringList whiteList = group.readEntry("whiteList", QStringList()); + qDebug()<<" whiteList"<setEmailWhiteList(whiteList); QStringList lst; lst << mComposerBase->to(); if (!mComposerBase->cc().isEmpty()) diff --git a/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.cpp b/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.cpp index 6c18c4473..1a09fdcb3 100644 --- a/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.cpp +++ b/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.cpp @@ -19,6 +19,9 @@ */ #include "potentialphishingdetaildialogtest.h" +#include "../potentialphishingdetaildialog.h" +#include +#include #include PotentialPhishingDetailDialogTest::PotentialPhishingDetailDialogTest(QObject *parent) @@ -32,4 +35,57 @@ PotentialPhishingDetailDialogTest::~PotentialPhishingDetailDialogTest() } -QTEST_KDEMAIN(PotentialPhishingDetailDialogTest, NoGUI) +void PotentialPhishingDetailDialogTest::shouldHaveDefaultValue() +{ + PotentialPhishingDetailDialog dlg; + QLabel *searchLabel = qFindChild(&dlg, QLatin1String("label")); + QVERIFY(searchLabel); + + QListWidget *listWidget = qFindChild(&dlg, QLatin1String("list_widget")); + QVERIFY(listWidget); + QCOMPARE(listWidget->count(), 0); +} + +void PotentialPhishingDetailDialogTest::shouldFillList() +{ + PotentialPhishingDetailDialog dlg; + QListWidget *listWidget = qFindChild(&dlg, QLatin1String("list_widget")); + QStringList lst; + lst << QLatin1String("bla"); + lst << QLatin1String("bli"); + lst << QLatin1String("blo"); + dlg.fillList(lst); + QCOMPARE(listWidget->count(), lst.count()); +} + +void PotentialPhishingDetailDialogTest::shouldClearListBeforeToAddNew() +{ + PotentialPhishingDetailDialog dlg; + QListWidget *listWidget = qFindChild(&dlg, QLatin1String("list_widget")); + QStringList lst; + lst << QLatin1String("bla"); + lst << QLatin1String("bli"); + lst << QLatin1String("blo"); + dlg.fillList(lst); + QCOMPARE(listWidget->count(), lst.count()); + lst.clear(); + lst << QLatin1String("bla"); + lst << QLatin1String("bli"); + dlg.fillList(lst); + QCOMPARE(listWidget->count(), lst.count()); +} + +void PotentialPhishingDetailDialogTest::shouldNotAddDuplicateEntries() +{ + PotentialPhishingDetailDialog dlg; + QListWidget *listWidget = qFindChild(&dlg, QLatin1String("list_widget")); + QStringList lst; + lst << QLatin1String("bla"); + lst << QLatin1String("blo"); + lst << QLatin1String("blo"); + dlg.fillList(lst); + QCOMPARE(listWidget->count(), (lst.count()-1)); + +} + +QTEST_KDEMAIN(PotentialPhishingDetailDialogTest, GUI) diff --git a/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.h b/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.h index 720c42631..d66faef74 100644 --- a/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.h +++ b/editor/potentialphishingemail/autotests/potentialphishingdetaildialogtest.h @@ -29,6 +29,11 @@ class PotentialPhishingDetailDialogTest : public QObject public: explicit PotentialPhishingDetailDialogTest(QObject *parent = 0); ~PotentialPhishingDetailDialogTest(); +private Q_SLOTS: + void shouldHaveDefaultValue(); + void shouldFillList(); + void shouldClearListBeforeToAddNew(); + void shouldNotAddDuplicateEntries(); }; #endif // POTENTIALPHISHINGDETAILDIALOGTEST_H diff --git a/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp b/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp index 5f05c6a6d..77f9182dd 100644 --- a/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp +++ b/editor/potentialphishingemail/autotests/potentialphishingemailjobtest.cpp @@ -45,20 +45,26 @@ void PotentialPhishingEmailJobTest::shouldNotStartIfNoEmails() void PotentialPhishingEmailJobTest::shouldReturnPotentialPhishingEmails_data() { QTest::addColumn("listEmails"); + QTest::addColumn("whiteListEmail"); QTest::addColumn("hasPotentialPhishing"); - QTest::newRow("NoPotentialPhishing") << (QStringList() << QLatin1String("foo@kde.org")) << false; - QTest::newRow("HasPotentialPhishing") << (QStringList() << QLatin1String("\"bla@kde.org\" ")) << true; + QTest::newRow("NoPotentialPhishing") << (QStringList() << QLatin1String("foo@kde.org")) << QStringList() << false; + QTest::newRow("HasPotentialPhishing") << (QStringList() << QLatin1String("\"bla@kde.org\" ")) << QStringList() << true; + const QString email = QLatin1String("\"bla@kde.org\" "); + QTest::newRow("EmailInWhiteList") << (QStringList() << email) << (QStringList() << email) << false; + QTest::newRow("NotAllEmailInWhiteList") << (QStringList() << email << QLatin1String("\"c@kde.org\" ")) << (QStringList() << email) << true; } void PotentialPhishingEmailJobTest::shouldReturnPotentialPhishingEmails() { QFETCH( QStringList, listEmails ); + QFETCH( QStringList,whiteListEmail ); QFETCH( bool, hasPotentialPhishing ); + PotentialPhishingEmailJob *job = new PotentialPhishingEmailJob; + job->setEmailWhiteList(whiteListEmail); job->setEmails(listEmails); QVERIFY(job->start()); QCOMPARE(job->potentialPhisingEmails().isEmpty(), !hasPotentialPhishing); - } void PotentialPhishingEmailJobTest::shouldEmitSignal() diff --git a/editor/potentialphishingemail/potentialphishingdetaildialog.cpp b/editor/potentialphishingemail/potentialphishingdetaildialog.cpp index a99711794..dbf1505e7 100644 --- a/editor/potentialphishingemail/potentialphishingdetaildialog.cpp +++ b/editor/potentialphishingemail/potentialphishingdetaildialog.cpp @@ -19,17 +19,85 @@ */ #include "potentialphishingdetaildialog.h" - +#include #include +#include +#include +#include + PotentialPhishingDetailDialog::PotentialPhishingDetailDialog(QWidget *parent) : KDialog(parent) { + //Add i18n in kf5 + setCaption( QLatin1String( "Details" ) ); + setButtons( Ok|Cancel ); + setDefaultButton( Ok ); + + setModal( true ); + QWidget *mainWidget = new QWidget( this ); + QVBoxLayout *mainLayout = new QVBoxLayout( mainWidget ); + //kf5 add i18n + QLabel *lab = new QLabel(QLatin1String("Select email to put in whitelist:")); + lab->setObjectName(QLatin1String("label")); + mainLayout->addWidget(lab); + + mListWidget = new QListWidget; + mListWidget->setObjectName(QLatin1String("list_widget")); + mainLayout->addWidget(mListWidget); + connect(this, SIGNAL(okClicked()), this, SLOT(slotSave())); + setMainWidget(mainWidget); + readConfig(); } PotentialPhishingDetailDialog::~PotentialPhishingDetailDialog() { + writeConfig(); +} + +void PotentialPhishingDetailDialog::fillList(const QStringList &lst) +{ + mListWidget->clear(); + QStringList emailsAdded; + Q_FOREACH(const QString & mail, lst) { + if (!emailsAdded.contains(mail)) { + QListWidgetItem *item = new QListWidgetItem(mListWidget); + item->setCheckState(Qt::Unchecked); + item->setText(mail); + emailsAdded << mail; + } + } +} +void PotentialPhishingDetailDialog::readConfig() +{ + KConfigGroup group( KGlobal::config(), "PotentialPhishingDetailDialog" ); + const QSize sizeDialog = group.readEntry( "Size", QSize(800,600) ); + if ( sizeDialog.isValid() ) { + resize( sizeDialog ); + } } +void PotentialPhishingDetailDialog::writeConfig() +{ + KConfigGroup group( KGlobal::config(), "PotentialPhishingDetailDialog" ); + group.writeEntry( "Size", size() ); +} + +void PotentialPhishingDetailDialog::slotSave() +{ + KConfigGroup group( KGlobal::config(), "PotentialPhishing"); + QStringList potentialPhishing = group.readEntry("whiteList", QStringList()); + for (int i=0; i < mListWidget->count(); ++i) { + QListWidgetItem *item = mListWidget->item(i); + if (item->checkState() == Qt::Checked) { + QString email = item->text(); + if (!potentialPhishing.contains(email)) { + potentialPhishing << email; + } + } + } + group.writeEntry( "whiteList", potentialPhishing); + accept(); +} diff --git a/editor/potentialphishingemail/potentialphishingdetaildialog.h b/editor/potentialphishingemail/potentialphishingdetaildialog.h index cabec1f4b..a3a6969b9 100644 --- a/editor/potentialphishingemail/potentialphishingdetaildialog.h +++ b/editor/potentialphishingemail/potentialphishingdetaildialog.h @@ -22,13 +22,23 @@ #define POTENTIALPHISHINGDETAILDIALOG_H #include - +class QListWidget; class PotentialPhishingDetailDialog : public KDialog { Q_OBJECT public: explicit PotentialPhishingDetailDialog(QWidget *parent=0); ~PotentialPhishingDetailDialog(); + + void fillList(const QStringList &lst); + +private slots: + void slotSave(); + +private: + void readConfig(); + void writeConfig(); + QListWidget *mListWidget; }; #endif // POTENTIALPHISHINGDETAILDIALOG_H diff --git a/editor/potentialphishingemail/potentialphishingemailjob.cpp b/editor/potentialphishingemail/potentialphishingemailjob.cpp index 02e37939f..3519814fb 100644 --- a/editor/potentialphishingemail/potentialphishingemailjob.cpp +++ b/editor/potentialphishingemail/potentialphishingemailjob.cpp @@ -32,6 +32,11 @@ PotentialPhishingEmailJob::~PotentialPhishingEmailJob() } +void PotentialPhishingEmailJob::setEmailWhiteList(const QStringList &emails) +{ + mEmailWhiteList = emails; +} + void PotentialPhishingEmailJob::setEmails(const QStringList &emails) { mEmails = emails; @@ -50,12 +55,14 @@ bool PotentialPhishingEmailJob::start() 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); + if (!mEmailWhiteList.contains(addr.trimmed())) { + 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); + } } } } diff --git a/editor/potentialphishingemail/potentialphishingemailjob.h b/editor/potentialphishingemail/potentialphishingemailjob.h index c1a9753d3..0a0786ad8 100644 --- a/editor/potentialphishingemail/potentialphishingemailjob.h +++ b/editor/potentialphishingemail/potentialphishingemailjob.h @@ -31,7 +31,9 @@ public: explicit PotentialPhishingEmailJob(QObject *parent = 0); ~PotentialPhishingEmailJob(); + void setEmailWhiteList(const QStringList &emails); void setEmails(const QStringList &emails); + QStringList potentialPhisingEmails() const; bool start(); @@ -41,6 +43,7 @@ Q_SIGNALS: private: QStringList mEmails; QStringList mPotentialPhisingEmails; + QStringList mEmailWhiteList; }; #endif // POTENTIALPHISHINGEMAILJOB_H diff --git a/editor/potentialphishingemail/potentialphishingemailwarning.cpp b/editor/potentialphishingemail/potentialphishingemailwarning.cpp index e6cd591dc..faafcfd62 100644 --- a/editor/potentialphishingemail/potentialphishingemailwarning.cpp +++ b/editor/potentialphishingemail/potentialphishingemailwarning.cpp @@ -20,7 +20,11 @@ #include "potentialphishingemailwarning.h" +#include "potentialphishingdetaildialog.h" +#include +#include #include +#include PotentialPhishingEmailWarning::PotentialPhishingEmailWarning(QWidget *parent) : KMessageWidget(parent) @@ -34,6 +38,10 @@ PotentialPhishingEmailWarning::PotentialPhishingEmailWarning(QWidget *parent) setText(QLatin1String("Some address mail seems a potential phishing email (Details...)")); connect(this, SIGNAL(linkActivated(QString)), SLOT(slotShowDetails(QString))); + //Add i18n in kf5 + KAction *action = new KAction(QLatin1String( "Send Now" ), this ); + connect( action, SIGNAL(triggered(bool)), SIGNAL(sendNow()) ); + addAction( action ); } PotentialPhishingEmailWarning::~PotentialPhishingEmailWarning() @@ -44,7 +52,10 @@ PotentialPhishingEmailWarning::~PotentialPhishingEmailWarning() void PotentialPhishingEmailWarning::slotShowDetails(const QString &link) { if (link == QLatin1String("phishingdetails")) { - Q_EMIT showDetails(); + QPointer dlg = new PotentialPhishingDetailDialog(this); + dlg->fillList(mPotentialPhishingEmails); + dlg->exec(); + delete dlg; } } diff --git a/editor/potentialphishingemail/potentialphishingemailwarning.h b/editor/potentialphishingemail/potentialphishingemailwarning.h index cff894727..e8397be8b 100644 --- a/editor/potentialphishingemail/potentialphishingemailwarning.h +++ b/editor/potentialphishingemail/potentialphishingemailwarning.h @@ -31,8 +31,9 @@ public: ~PotentialPhishingEmailWarning(); void setPotentialPhisingEmail(const QStringList &lst); + Q_SIGNALS: - void showDetails(); + void sendNow(); private slots: void slotShowDetails(const QString &link);