File indexing completed on 2025-01-19 04:46:43

0001 /*
0002    SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "confirmaddresscheckjob.h"
0008 
0009 ConfirmAddressCheckJob::ConfirmAddressCheckJob() = default;
0010 
0011 ConfirmAddressCheckJob::~ConfirmAddressCheckJob() = default;
0012 
0013 void ConfirmAddressCheckJob::start()
0014 {
0015     mValidEmails.clear();
0016     mInvalidEmails.clear();
0017     bool foundValidEmail = false;
0018     for (const QString &email : std::as_const(mAddressList)) {
0019         if (email.isEmpty()) {
0020             continue;
0021         }
0022         foundValidEmail = false;
0023         if (mRejectedDomain) {
0024             for (const QString &whiteEmail : std::as_const(mWhiteEmails)) {
0025                 if (email.contains(whiteEmail)) {
0026                     if (!mValidEmails.contains(email)) {
0027                         mValidEmails.append(email);
0028                     }
0029                     foundValidEmail = true;
0030                     break;
0031                 }
0032             }
0033             if (!foundValidEmail) {
0034                 bool foundRejectedDomain = false;
0035                 for (const QString &domain : std::as_const(mDomains)) {
0036                     if (email.contains(domain)) {
0037                         if (!mInvalidEmails.contains(email)) {
0038                             mInvalidEmails.append(email);
0039                         }
0040                         foundRejectedDomain = true;
0041                         break;
0042                     }
0043                 }
0044                 if (!foundRejectedDomain) {
0045                     if (!mValidEmails.contains(email)) {
0046                         mValidEmails.append(email);
0047                     }
0048                 }
0049             }
0050         } else {
0051             for (const QString &domain : std::as_const(mDomains)) {
0052                 if (email.contains(domain)) {
0053                     if (!mValidEmails.contains(email)) {
0054                         mValidEmails.append(email);
0055                     }
0056                     foundValidEmail = true;
0057                     break;
0058                 }
0059             }
0060             if (!foundValidEmail) {
0061                 for (const QString &whiteEmail : std::as_const(mWhiteEmails)) {
0062                     if (email.contains(whiteEmail)) {
0063                         if (!mValidEmails.contains(email)) {
0064                             mValidEmails.append(email);
0065                         }
0066                         foundValidEmail = true;
0067                         break;
0068                     }
0069                 }
0070             }
0071             if (!foundValidEmail) {
0072                 if (!mInvalidEmails.contains(email)) {
0073                     mInvalidEmails.append(email);
0074                 }
0075             }
0076         }
0077     }
0078 }
0079 
0080 void ConfirmAddressCheckJob::setCheckSettings(const QStringList &domains, const QStringList &whiteEmails, bool rejectedDomain)
0081 {
0082     mDomains = domains;
0083     mWhiteEmails = whiteEmails;
0084     mRejectedDomain = rejectedDomain;
0085 }
0086 
0087 void ConfirmAddressCheckJob::setAddressList(const QStringList &addressList)
0088 {
0089     mAddressList = addressList;
0090 }
0091 
0092 QStringList ConfirmAddressCheckJob::validEmails() const
0093 {
0094     return mValidEmails;
0095 }
0096 
0097 QStringList ConfirmAddressCheckJob::invalidEmails() const
0098 {
0099     return mInvalidEmails;
0100 }