Commit 6c50b9f0 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to define exclude domain

parent 9fb78251
......@@ -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)
......@@ -35,6 +35,8 @@ private Q_SLOTS:
void shouldReturnAllInValidEmailsDomain();
void shouldReturnValidAndInvalid();
void shouldNotDuplicateValue();
void shouldReturnAllValidEmailsDomainRejectedDomain();
void shouldReturnAllInValidEmailsDomainReject();
};
#endif // CONFIRMADDRESSCHECKJOBTEST_H
......@@ -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);
......
......@@ -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)
......
......@@ -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
......@@ -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)
......
......@@ -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
......@@ -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);
}
}
......@@ -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;
......
Supports Markdown
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