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 b60fc741 authored by Laurent Montel's avatar Laurent Montel 😁

improve check email

parent 7b09eab5
......@@ -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"<<whiteList;
job->setEmailWhiteList(whiteList);
QStringList lst;
lst << mComposerBase->to();
if (!mComposerBase->cc().isEmpty())
......
......@@ -19,6 +19,9 @@
*/
#include "potentialphishingdetaildialogtest.h"
#include "../potentialphishingdetaildialog.h"
#include <QLabel>
#include <QListWidget>
#include <qtest_kde.h>
PotentialPhishingDetailDialogTest::PotentialPhishingDetailDialogTest(QObject *parent)
......@@ -32,4 +35,57 @@ PotentialPhishingDetailDialogTest::~PotentialPhishingDetailDialogTest()
}
QTEST_KDEMAIN(PotentialPhishingDetailDialogTest, NoGUI)
void PotentialPhishingDetailDialogTest::shouldHaveDefaultValue()
{
PotentialPhishingDetailDialog dlg;
QLabel *searchLabel = qFindChild<QLabel *>(&dlg, QLatin1String("label"));
QVERIFY(searchLabel);
QListWidget *listWidget = qFindChild<QListWidget *>(&dlg, QLatin1String("list_widget"));
QVERIFY(listWidget);
QCOMPARE(listWidget->count(), 0);
}
void PotentialPhishingDetailDialogTest::shouldFillList()
{
PotentialPhishingDetailDialog dlg;
QListWidget *listWidget = qFindChild<QListWidget *>(&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<QListWidget *>(&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<QListWidget *>(&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)
......@@ -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
......@@ -45,20 +45,26 @@ void PotentialPhishingEmailJobTest::shouldNotStartIfNoEmails()
void PotentialPhishingEmailJobTest::shouldReturnPotentialPhishingEmails_data()
{
QTest::addColumn<QStringList>("listEmails");
QTest::addColumn<QStringList>("whiteListEmail");
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;
QTest::newRow("NoPotentialPhishing") << (QStringList() << QLatin1String("foo@kde.org")) << QStringList() << false;
QTest::newRow("HasPotentialPhishing") << (QStringList() << QLatin1String("\"bla@kde.org\" <foo@kde.org>")) << QStringList() << true;
const QString email = QLatin1String("\"bla@kde.org\" <foo@kde.org>");
QTest::newRow("EmailInWhiteList") << (QStringList() << email) << (QStringList() << email) << false;
QTest::newRow("NotAllEmailInWhiteList") << (QStringList() << email << QLatin1String("\"c@kde.org\" <dd@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()
......
......@@ -19,17 +19,85 @@
*/
#include "potentialphishingdetaildialog.h"
#include <KSharedConfig>
#include <KLocalizedString>
#include <qboxlayout.h>
#include <QLabel>
#include <QListWidget>
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();
}
......@@ -22,13 +22,23 @@
#define POTENTIALPHISHINGDETAILDIALOG_H
#include <KDialog>
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
......@@ -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);
}
}
}
}
......
......@@ -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
......@@ -20,7 +20,11 @@
#include "potentialphishingemailwarning.h"
#include "potentialphishingdetaildialog.h"
#include <KAction>
#include <KIcon>
#include <KLocalizedString>
#include <QPointer>
PotentialPhishingEmailWarning::PotentialPhishingEmailWarning(QWidget *parent)
: KMessageWidget(parent)
......@@ -34,6 +38,10 @@ PotentialPhishingEmailWarning::PotentialPhishingEmailWarning(QWidget *parent)
setText(QLatin1String("Some address mail seems a potential phishing email <a href=\"phishingdetails\">(Details...)</a>"));
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<PotentialPhishingDetailDialog> dlg = new PotentialPhishingDetailDialog(this);
dlg->fillList(mPotentialPhishingEmails);
dlg->exec();
delete dlg;
}
}
......
......@@ -31,8 +31,9 @@ public:
~PotentialPhishingEmailWarning();
void setPotentialPhisingEmail(const QStringList &lst);
Q_SIGNALS:
void showDetails();
void sendNow();
private slots:
void slotShowDetails(const QString &link);
......
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