Commit f6960615 authored by Laurent Montel's avatar Laurent Montel 😁

Extract emails

parent 6fdf0005
...@@ -55,38 +55,38 @@ void CheckDuplicateEmailsJobTest::shouldReturnEmails_data() ...@@ -55,38 +55,38 @@ void CheckDuplicateEmailsJobTest::shouldReturnEmails_data()
QTest::newRow("empty") << QStringList() << QMap<QString, int>(); QTest::newRow("empty") << QStringList() << QMap<QString, int>();
QStringList lst; QStringList lst;
lst.append(QStringLiteral("foo")); lst.append(QStringLiteral("foo@kde.org"));
lst.append(QStringLiteral("bla")); lst.append(QStringLiteral("bla@kde.org"));
lst.append(QStringLiteral("blo")); lst.append(QStringLiteral("blo@kde.org"));
QTest::newRow("emptyresultbutnotemptylist") << lst << QMap<QString, int>(); QTest::newRow("emptyresultbutnotemptylist") << lst << QMap<QString, int>();
lst.clear(); lst.clear();
lst.append(QStringLiteral("foo")); lst.append(QStringLiteral("foo@kde.org"));
lst.append(QStringLiteral("foo")); lst.append(QStringLiteral("foo@kde.org"));
lst.append(QStringLiteral("blo")); lst.append(QStringLiteral("blo@kde.org"));
QMap<QString, int> result; QMap<QString, int> result;
result.insert(QStringLiteral("foo"), 2); result.insert(QStringLiteral("foo@kde.org"), 2);
QTest::newRow("oneduplicateemails") << lst << result; QTest::newRow("oneduplicateemails") << lst << result;
lst.clear(); lst.clear();
lst.append(QStringLiteral("foo")); lst.append(QStringLiteral("foo@kde.org"));
lst.append(QStringLiteral("foo")); lst.append(QStringLiteral("foo@kde.org"));
lst.append(QStringLiteral("blo")); lst.append(QStringLiteral("blo@kde.org"));
lst.append(QStringLiteral("blo")); lst.append(QStringLiteral("blo@kde.org"));
result.clear(); result.clear();
result.insert(QStringLiteral("foo"), 2); result.insert(QStringLiteral("foo@kde.org"), 2);
result.insert(QStringLiteral("blo"), 2); result.insert(QStringLiteral("blo@kde.org"), 2);
QTest::newRow("twoduplicateemails") << lst << result; QTest::newRow("twoduplicateemails") << lst << result;
lst.clear(); lst.clear();
lst.append(QStringLiteral("foo")); lst.append(QStringLiteral("foo@kde.org"));
lst.append(QStringLiteral("foo")); lst.append(QStringLiteral("foo@kde.org"));
lst.append(QStringLiteral("foo")); lst.append(QStringLiteral("foo@kde.org"));
lst.append(QStringLiteral("blo")); lst.append(QStringLiteral("blo@kde.org"));
lst.append(QStringLiteral("blo")); lst.append(QStringLiteral("blo@kde.org"));
result.clear(); result.clear();
result.insert(QStringLiteral("foo"), 3); result.insert(QStringLiteral("foo@kde.org"), 3);
result.insert(QStringLiteral("blo"), 2); result.insert(QStringLiteral("blo@kde.org"), 2);
QTest::newRow("twoduplicateemailswithdifferentvalue") << lst << result; QTest::newRow("twoduplicateemailswithdifferentvalue") << lst << result;
} }
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#include "checkduplicateemailsjob.h" #include "checkduplicateemailsjob.h"
#include <KEmailAddress>
#include <QDebug>
CheckDuplicateEmailsJob::CheckDuplicateEmailsJob() CheckDuplicateEmailsJob::CheckDuplicateEmailsJob()
{ {
...@@ -36,11 +38,14 @@ void CheckDuplicateEmailsJob::start() ...@@ -36,11 +38,14 @@ void CheckDuplicateEmailsJob::start()
} }
QMap<QString, int> results; QMap<QString, int> results;
Q_FOREACH(const QString &email, mEmails) { Q_FOREACH(const QString &email, mEmails) {
int val = results.value(email, 0); QString tname, temail;
KEmailAddress::extractEmailAddressAndName(email, temail, tname); // ignore return value
int val = results.value(temail, 0);
if (val == 0) { if (val == 0) {
results.insert(email, val+1); results.insert(temail, val+1);
} else { } else {
results[email] = val+1; results[temail] = val+1;
} }
} }
QMapIterator<QString, int> i(results); QMapIterator<QString, int> i(results);
......
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