summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-07 20:41:17 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-07 20:41:17 (GMT)
commit6c50b9f0bfdf3a9e474c4808b7a680c5abeb821d (patch)
tree6856fc213dbffad6233ba330c5cbd2d7a28201b7
parent9fb78251a8fba0d67aa670ecb6f777ee13b670c0 (diff)
Allow to define exclude domain
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddresscheckjobtest.cpp50
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddresscheckjobtest.h2
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddressconfiguretabwidgettest.cpp10
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/confirmaddresscheckjob.cpp61
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/confirmaddresscheckjob.h3
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/confirmaddressconfiguretabwidget.cpp25
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/confirmaddressconfiguretabwidget.h3
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/confirmaddressinterface.cpp4
-rw-r--r--kmail/editorsendcheckplugins/confirm-address/confirmaddressinterface.h7
9 files changed, 142 insertions, 23 deletions
diff --git a/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddresscheckjobtest.cpp b/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddresscheckjobtest.cpp
index 4ddbd14..70d8ed0 100644
--- a/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddresscheckjobtest.cpp
+++ b/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddresscheckjobtest.cpp
@@ -45,7 +45,12 @@ void ConfirmAddressCheckJobTest::shouldReturnEmptyResultWhenNoAddress()
ConfirmAddressCheckJob job;
const QStringList domains{QStringLiteral("foo.com"), QStringLiteral("bla.com")};
const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")};
- job.setCheckSettings(domains, whiteList);
+ job.setCheckSettings(domains, whiteList, false);
+ job.start();
+ QVERIFY(job.invalidEmails().isEmpty());
+ QVERIFY(job.validEmails().isEmpty());
+
+ job.setCheckSettings(domains, whiteList, true);
job.start();
QVERIFY(job.invalidEmails().isEmpty());
QVERIFY(job.validEmails().isEmpty());
@@ -57,7 +62,7 @@ void ConfirmAddressCheckJobTest::shouldReturnAllValidEmailsDomain()
const QStringList domains{QStringLiteral("foo.com"), QStringLiteral("bla.com")};
const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")};
const QStringList emails{QStringLiteral("toto@foo.com"), QStringLiteral("blabla@foo.com")};
- job.setCheckSettings(domains, whiteList);
+ job.setCheckSettings(domains, whiteList, false);
job.setAddressList(emails);
job.start();
QVERIFY(job.invalidEmails().isEmpty());
@@ -65,13 +70,27 @@ void ConfirmAddressCheckJobTest::shouldReturnAllValidEmailsDomain()
QCOMPARE(job.validEmails(), emails);
}
+void ConfirmAddressCheckJobTest::shouldReturnAllValidEmailsDomainRejectedDomain()
+{
+ ConfirmAddressCheckJob job;
+ const QStringList domains{QStringLiteral("foo.com"), QStringLiteral("bla.com")};
+ const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")};
+ const QStringList emails{QStringLiteral("toto@foo.com"), QStringLiteral("blabla@foo.com")};
+ job.setCheckSettings(domains, whiteList, true);
+ job.setAddressList(emails);
+ job.start();
+ QVERIFY(!job.invalidEmails().isEmpty());
+ QCOMPARE(job.invalidEmails(), emails);
+ QVERIFY(job.validEmails().isEmpty());
+}
+
void ConfirmAddressCheckJobTest::shouldReturnAllInValidEmailsDomain()
{
ConfirmAddressCheckJob job;
const QStringList domains{QStringLiteral("foo.fr"), QStringLiteral("bla.com")};
const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")};
const QStringList emails{QStringLiteral("toto@foo.com"), QStringLiteral("blabla@foo.com")};
- job.setCheckSettings(domains, whiteList);
+ job.setCheckSettings(domains, whiteList, false);
job.setAddressList(emails);
job.start();
QVERIFY(!job.invalidEmails().isEmpty());
@@ -79,13 +98,27 @@ void ConfirmAddressCheckJobTest::shouldReturnAllInValidEmailsDomain()
QCOMPARE(job.invalidEmails(), emails);
}
+void ConfirmAddressCheckJobTest::shouldReturnAllInValidEmailsDomainReject()
+{
+ ConfirmAddressCheckJob job;
+ const QStringList domains{QStringLiteral("foo.fr"), QStringLiteral("bla.com")};
+ const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")};
+ const QStringList emails{QStringLiteral("toto@foo.com"), QStringLiteral("blabla@foo.com")};
+ job.setCheckSettings(domains, whiteList, true);
+ job.setAddressList(emails);
+ job.start();
+ QVERIFY(job.invalidEmails().isEmpty());
+ QVERIFY(!job.validEmails().isEmpty());
+ QCOMPARE(job.validEmails(), emails);
+}
+
void ConfirmAddressCheckJobTest::shouldReturnValidAndInvalid()
{
ConfirmAddressCheckJob job;
const QStringList domains{QStringLiteral("foo.fr"), QStringLiteral("bla.com")};
const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")};
const QStringList emails{QStringLiteral("toto@bla.com"), QStringLiteral("blabla@foo.com")};
- job.setCheckSettings(domains, whiteList);
+ job.setCheckSettings(domains, whiteList, false);
job.setAddressList(emails);
job.start();
QVERIFY(!job.invalidEmails().isEmpty());
@@ -100,13 +133,20 @@ void ConfirmAddressCheckJobTest::shouldNotDuplicateValue()
const QStringList domains{QStringLiteral("foo.com"), QStringLiteral("bla.com")};
const QStringList whiteList{QStringLiteral("foo@kde.org"), QStringLiteral("bla@kde.org")};
const QStringList emails{QStringLiteral("toto@foo.com"), QStringLiteral("blabla@foo.com")};
- job.setCheckSettings(domains, whiteList);
+ job.setCheckSettings(domains, whiteList, false);
job.setAddressList(QStringList() << emails << emails);
job.start();
QVERIFY(job.invalidEmails().isEmpty());
QVERIFY(!job.validEmails().isEmpty());
QCOMPARE(job.validEmails(), emails);
+
+ job.setCheckSettings(domains, whiteList, true);
+ job.setAddressList(QStringList() << emails << emails);
+ job.start();
+ QVERIFY(!job.invalidEmails().isEmpty());
+ QVERIFY(job.validEmails().isEmpty());
+ QCOMPARE(job.invalidEmails(), emails);
}
QTEST_MAIN(ConfirmAddressCheckJobTest)
diff --git a/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddresscheckjobtest.h b/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddresscheckjobtest.h
index 4a6f98e..1a12c64 100644
--- a/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddresscheckjobtest.h
+++ b/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddresscheckjobtest.h
@@ -35,6 +35,8 @@ private Q_SLOTS:
void shouldReturnAllInValidEmailsDomain();
void shouldReturnValidAndInvalid();
void shouldNotDuplicateValue();
+ void shouldReturnAllValidEmailsDomainRejectedDomain();
+ void shouldReturnAllInValidEmailsDomainReject();
};
#endif // CONFIRMADDRESSCHECKJOBTEST_H
diff --git a/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddressconfiguretabwidgettest.cpp b/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddressconfiguretabwidgettest.cpp
index b6297e4..922c0b9 100644
--- a/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddressconfiguretabwidgettest.cpp
+++ b/kmail/editorsendcheckplugins/confirm-address/autotests/confirmaddressconfiguretabwidgettest.cpp
@@ -22,6 +22,7 @@
#include <QTest>
#include <QVBoxLayout>
#include <QGroupBox>
+#include <QRadioButton>
#include <PimCommon/SimpleStringlistEditor>
ConfirmAddressConfigureTabWidgetTest::ConfirmAddressConfigureTabWidgetTest(QObject *parent)
@@ -42,6 +43,15 @@ void ConfirmAddressConfigureTabWidgetTest::shouldHaveDefaultValue()
QVERIFY(groupBoxDomainName);
QVBoxLayout *layoutDomainName = w.findChild<QVBoxLayout *>(QStringLiteral("layoutdomainname"));
QVERIFY(layoutDomainName);
+
+ QRadioButton *mAcceptedDomain = w.findChild<QRadioButton *>(QStringLiteral("acceptdomainname"));
+ QVERIFY(mAcceptedDomain);
+ QVERIFY(!mAcceptedDomain->text().isEmpty());
+
+ QRadioButton *mRejectedDomain = w.findChild<QRadioButton *>(QStringLiteral("rejectdomainname"));
+ QVERIFY(mRejectedDomain);
+ QVERIFY(!mRejectedDomain->text().isEmpty());
+
PimCommon::SimpleStringListEditor *mDomainNameListEditor = w.findChild<PimCommon::SimpleStringListEditor *>(QStringLiteral("domainnamelisteditor"));
QVERIFY(mDomainNameListEditor);
diff --git a/kmail/editorsendcheckplugins/confirm-address/confirmaddresscheckjob.cpp b/kmail/editorsendcheckplugins/confirm-address/confirmaddresscheckjob.cpp
index aff3304..9336028 100644
--- a/kmail/editorsendcheckplugins/confirm-address/confirmaddresscheckjob.cpp
+++ b/kmail/editorsendcheckplugins/confirm-address/confirmaddresscheckjob.cpp
@@ -20,6 +20,7 @@
#include "confirmaddresscheckjob.h"
ConfirmAddressCheckJob::ConfirmAddressCheckJob()
+ : mRejectedDomain(false)
{
}
@@ -39,16 +40,7 @@ void ConfirmAddressCheckJob::start()
continue;
}
foundValidEmail = false;
- Q_FOREACH (const QString &domain, mDomains) {
- if (email.contains(domain)) {
- if (!mValidEmails.contains(email)) {
- mValidEmails.append(email);
- }
- foundValidEmail = true;
- break;
- }
- }
- if (!foundValidEmail) {
+ if (mRejectedDomain) {
Q_FOREACH (const QString &whiteEmail, mWhiteEmails) {
if (email.contains(whiteEmail)) {
if (!mValidEmails.contains(email)) {
@@ -58,19 +50,58 @@ void ConfirmAddressCheckJob::start()
break;
}
}
- }
- if (!foundValidEmail) {
- if (!mInvalidEmails.contains(email)) {
- mInvalidEmails.append(email);
+ if (!foundValidEmail) {
+ bool foundRejectedDomain = false;
+ Q_FOREACH (const QString &domain, mDomains) {
+ if (email.contains(domain)) {
+ if (!mInvalidEmails.contains(email)) {
+ mInvalidEmails.append(email);
+ }
+ foundRejectedDomain = true;
+ break;
+ }
+ }
+ if (!foundRejectedDomain) {
+ if (!mValidEmails.contains(email)) {
+ mValidEmails.append(email);
+ }
+ }
+ }
+ } else {
+ Q_FOREACH (const QString &domain, mDomains) {
+ if (email.contains(domain)) {
+ if (!mValidEmails.contains(email)) {
+ mValidEmails.append(email);
+ }
+ foundValidEmail = true;
+ break;
+ }
+ }
+ if (!foundValidEmail) {
+ Q_FOREACH (const QString &whiteEmail, mWhiteEmails) {
+ if (email.contains(whiteEmail)) {
+ if (!mValidEmails.contains(email)) {
+ mValidEmails.append(email);
+ }
+ foundValidEmail = true;
+ break;
+ }
+ }
+ }
+ if (!foundValidEmail) {
+ if (!mInvalidEmails.contains(email)) {
+ mInvalidEmails.append(email);
+ }
}
}
}
}
-void ConfirmAddressCheckJob::setCheckSettings(const QStringList &domains, const QStringList &whiteEmails)
+void ConfirmAddressCheckJob::setCheckSettings(const QStringList &domains, const QStringList &whiteEmails, bool rejectedDomain)
{
mDomains = domains;
mWhiteEmails = whiteEmails;
+ mRejectedDomain = rejectedDomain;
}
void ConfirmAddressCheckJob::setAddressList(const QStringList &addressList)
diff --git a/kmail/editorsendcheckplugins/confirm-address/confirmaddresscheckjob.h b/kmail/editorsendcheckplugins/confirm-address/confirmaddresscheckjob.h
index a9c578b..0dada2a 100644
--- a/kmail/editorsendcheckplugins/confirm-address/confirmaddresscheckjob.h
+++ b/kmail/editorsendcheckplugins/confirm-address/confirmaddresscheckjob.h
@@ -31,7 +31,7 @@ public:
void start();
- void setCheckSettings(const QStringList &domains, const QStringList &whiteEmails);
+ void setCheckSettings(const QStringList &domains, const QStringList &whiteEmails, bool rejectedDomain);
void setAddressList(const QStringList &addressList);
@@ -45,6 +45,7 @@ private:
QStringList mInvalidEmails;
QStringList mDomains;
QStringList mWhiteEmails;
+ bool mRejectedDomain;
};
#endif // CONFIRMADDRESSCHECKJOB_H
diff --git a/kmail/editorsendcheckplugins/confirm-address/confirmaddressconfiguretabwidget.cpp b/kmail/editorsendcheckplugins/confirm-address/confirmaddressconfiguretabwidget.cpp
index e8b9ef0..c26b115 100644
--- a/kmail/editorsendcheckplugins/confirm-address/confirmaddressconfiguretabwidget.cpp
+++ b/kmail/editorsendcheckplugins/confirm-address/confirmaddressconfiguretabwidget.cpp
@@ -22,6 +22,7 @@
#include <KLocalizedString>
#include <QGroupBox>
#include <QVBoxLayout>
+#include <QRadioButton>
#include <PimCommon/SimpleStringlistEditor>
ConfirmAddressConfigureTabWidget::ConfirmAddressConfigureTabWidget(QWidget *parent)
@@ -32,12 +33,27 @@ ConfirmAddressConfigureTabWidget::ConfirmAddressConfigureTabWidget(QWidget *pare
mainLayout->setObjectName(QStringLiteral("mainlayout"));
mainLayout->setMargin(0);
- QGroupBox *groupBoxDomainName = new QGroupBox(i18n("Accepted Domain Name"), this);
+ QGroupBox *groupBoxDomainName = new QGroupBox(this);
groupBoxDomainName->setObjectName(QStringLiteral("groupboxdomainname"));
mainLayout->addWidget(groupBoxDomainName);
QVBoxLayout *layoutDomainName = new QVBoxLayout(groupBoxDomainName);
layoutDomainName->setObjectName(QStringLiteral("layoutdomainname"));
+
+ QHBoxLayout *radioButtonLayout = new QHBoxLayout;
+ layoutDomainName->addLayout(radioButtonLayout);
+ radioButtonLayout->setAlignment(Qt::AlignHCenter);
+
+ mAcceptedDomain = new QRadioButton(i18n("Accepted Domain Name"), this);
+ mAcceptedDomain->setObjectName(QStringLiteral("acceptdomainname"));
+ radioButtonLayout->addWidget(mAcceptedDomain);
+ mAcceptedDomain->setChecked(true);
+
+ mRejectedDomain = new QRadioButton(i18n("Rejected Domain Name"), this);
+ mRejectedDomain->setObjectName(QStringLiteral("rejectdomainname"));
+ radioButtonLayout->addWidget(mRejectedDomain);
+
+
PimCommon::SimpleStringListEditor::ButtonCode buttonCode =
static_cast<PimCommon::SimpleStringListEditor::ButtonCode>(PimCommon::SimpleStringListEditor::Add | PimCommon::SimpleStringListEditor::Remove | PimCommon::SimpleStringListEditor::Modify);
mDomainNameListEditor =
@@ -85,6 +101,12 @@ void ConfirmAddressConfigureTabWidget::loadSettings(const KConfigGroup &grp)
KConfigGroup identityGroup = grp.group(QStringLiteral("Confirm Address %1").arg(mIdentity));
mDomainNameListEditor->setStringList(identityGroup.readEntry("Domains", QStringList()));
mWhiteListEditor->setStringList(identityGroup.readEntry("Emails", QStringList()));
+ const bool rejectedDomain = identityGroup.readEntry("RejectDomain", false);
+ if (rejectedDomain) {
+ mRejectedDomain->setChecked(true);
+ } else {
+ mAcceptedDomain->setChecked(true);
+ }
}
void ConfirmAddressConfigureTabWidget::saveSettings(KConfigGroup &grp)
@@ -92,6 +114,7 @@ void ConfirmAddressConfigureTabWidget::saveSettings(KConfigGroup &grp)
KConfigGroup identityGroup = grp.group(QStringLiteral("Confirm Address %1").arg(mIdentity));
identityGroup.writeEntry("Domains", mDomainNameListEditor->stringList());
identityGroup.writeEntry("Emails", mWhiteListEditor->stringList());
+ identityGroup.writeEntry("RejectDomain", mRejectedDomain->isChecked());
}
void ConfirmAddressConfigureTabWidget::setIdentity(const uint &identity)
diff --git a/kmail/editorsendcheckplugins/confirm-address/confirmaddressconfiguretabwidget.h b/kmail/editorsendcheckplugins/confirm-address/confirmaddressconfiguretabwidget.h
index f3a81cc..987dc51 100644
--- a/kmail/editorsendcheckplugins/confirm-address/confirmaddressconfiguretabwidget.h
+++ b/kmail/editorsendcheckplugins/confirm-address/confirmaddressconfiguretabwidget.h
@@ -26,6 +26,7 @@ namespace PimCommon
class SimpleStringListEditor;
}
class KConfigGroup;
+class QRadioButton;
class ConfirmAddressConfigureTabWidget : public QWidget
{
Q_OBJECT
@@ -46,6 +47,8 @@ private:
uint mIdentity;
PimCommon::SimpleStringListEditor *mDomainNameListEditor;
PimCommon::SimpleStringListEditor *mWhiteListEditor;
+ QRadioButton *mAcceptedDomain;
+ QRadioButton *mRejectedDomain;
};
#endif // CONFIRMADDRESSCONFIGURETABWIDGET_H
diff --git a/kmail/editorsendcheckplugins/confirm-address/confirmaddressinterface.cpp b/kmail/editorsendcheckplugins/confirm-address/confirmaddressinterface.cpp
index 55ac460..f251b33 100644
--- a/kmail/editorsendcheckplugins/confirm-address/confirmaddressinterface.cpp
+++ b/kmail/editorsendcheckplugins/confirm-address/confirmaddressinterface.cpp
@@ -60,7 +60,7 @@ bool ConfirmAddressInterface::exec(const MessageComposer::PluginEditorCheckBefor
}
#endif
ConfirmAddressCheckJob job;
- job.setCheckSettings(settings.mDomains, settings.mWhiteLists);
+ job.setCheckSettings(settings.mDomains, settings.mWhiteLists, settings.mRejectedDomain);
job.setAddressList(emails);
job.start();
@@ -113,6 +113,8 @@ void ConfirmAddressInterface::reloadConfig()
ConfirmAddressSettings settings;
settings.mDomains = identityGroup.readEntry("Domains", QStringList());
settings.mWhiteLists = identityGroup.readEntry("Emails", QStringList());
+ settings.mRejectedDomain = identityGroup.readEntry("RejectDomain", false);
+
mHashSettings.insert(identity, settings);
}
}
diff --git a/kmail/editorsendcheckplugins/confirm-address/confirmaddressinterface.h b/kmail/editorsendcheckplugins/confirm-address/confirmaddressinterface.h
index 5618fe0..0ae9a76 100644
--- a/kmail/editorsendcheckplugins/confirm-address/confirmaddressinterface.h
+++ b/kmail/editorsendcheckplugins/confirm-address/confirmaddressinterface.h
@@ -40,8 +40,15 @@ private:
void slotAddWhiteListEmails(const QStringList &lst, uint currentIdentity);
struct ConfirmAddressSettings {
+ ConfirmAddressSettings()
+ : mRejectedDomain(false)
+ {
+
+ }
+
QStringList mDomains;
QStringList mWhiteLists;
+ bool mRejectedDomain;
};
QHash<uint, ConfirmAddressSettings> mHashSettings;