Bug 370385

Summary: EMail Addresses with Underscores in Contacts Not Recognised
Product: [Applications] kmail2 Reporter: brgreen <xndlcx>
Component: searchAssignee: kdepim bugs <kdepim-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: kde_bugtracker, montel, sknauss
Priority: NOR    
Version: 5.16.1   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In: 5.17.0
Sentry Crash Report:

Description brgreen 2016-10-10 00:55:10 UTC
Hi - regarding email addresses in the headers of incoming emails. Right-clicking on those already in my Contacts gives the standard "Edit Contact Option".

But - email addresses with underscores in them are not recognised, and give the options of "Add to Address Book" and "Add to Existing Contact".

(My first bug report so apologies for any errors, or being put in the wrong location etc...)
Comment 1 Laurent Montel 2016-10-28 06:54:43 UTC
Do you have the problem for other emails ?

could you give me an example as email which doesn't work ?
Thanks
Comment 2 jc_gargma 2019-04-21 00:25:30 UTC
I know this is an old bug, but I have this problem as well on kmail 19.04.0
kmail seems unable to correlate an email address to a saved kaddressbook contact when the part before the @ contains an underscore. example_email@example.com
On top of kmail not allowing the edit contact context menu for said address, all other options for the contact linked to that email are not recognized, such as avatar, preferred GnuPG key, and sign/encrypt preferences.
Comment 3 Sandro Knauß 2021-02-03 02:27:21 UTC
I can confirm this. It is an issue of the indexer in akonadi-search. I already created a unit test for it:

diff --git a/akonadiplugin/autotests/searchplugintest.cpp b/akonadiplugin/autotests/searchplugintest.cpp
index eb7e84a..fde4500 100644
--- a/akonadiplugin/autotests/searchplugintest.cpp
+++ b/akonadiplugin/autotests/searchplugintest.cpp
@@ -160,7 +160,7 @@ private Q_SLOTS:
             b->setBody("body4");
             msg->addContent(b, true);
 
-            msg->from()->addAddress("john@test.com", QStringLiteral("John Doe"));
+            msg->from()->addAddress("john_rt@test.com", QStringLiteral("John Doe"));
             msg->to()->addAddress("jane@test.com", QStringLiteral("Jane Doe"));
             msg->cc()->addAddress("cc@test.com", QStringLiteral("Jane Doe"));
             msg->bcc()->addAddress("bcc@test.com", QStringLiteral("Jane Doe"));
@@ -265,7 +265,8 @@ private Q_SLOTS:
             KContacts::Addressee addressee;
             addressee.setUid(QStringLiteral("uid2"));
             addressee.setName(QStringLiteral("Jane Doe"));
-            addressee.setEmails(QStringList() << QStringLiteral("jane@test.com"));
+            addressee.setEmails({QStringLiteral("jane@test.com"),
+                    QStringLiteral("jane_rt@test.com")});
 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
             addressee.setBirthday(QDateTime(QDate(2000, 01, 01)));
 #else
@@ -661,6 +662,13 @@ private Q_SLOTS:
             QSet<qint64> result = QSet<qint64>() << 101 << 102;
             QTest::newRow("contact by email") << QString::fromLatin1(query.toJSON()) << collections << contactMimeTypes << result;
         }
+        {
+            Akonadi::SearchQuery query;
+            query.addTerm(Akonadi::ContactSearchTerm(Akonadi::ContactSearchTerm::Email, QStringLiteral("JANE_RT@TEST.COM"), Akonadi::SearchTerm::CondContains));
+            QVector<qint64> collections({3});
+            QSet<qint64> result({101});
+            QTest::newRow("contact by email2") << QString::fromLatin1(query.toJSON()) << collections << contactMimeTypes << result;
+        }
         {
             Akonadi::SearchQuery query;
             query.addTerm(Akonadi::ContactSearchTerm(Akonadi::ContactSearchTerm::Name, QStringLiteral("Doe"), Akonadi::SearchTerm::CondContains));
@@ -1099,6 +1107,13 @@ private Q_SLOTS:
             QSet<qint64> result = QSet<qint64>() << 1 << 2 << 3 << 4 << 5 << 6;
             QTest::newRow("search by from email part") << QString::fromLatin1(query.toJSON()) << allEmailCollections << emailMimeTypes << result;
         }
+        {
+            Akonadi::SearchQuery query;
+            query.addTerm(Akonadi::EmailSearchTerm(Akonadi::EmailSearchTerm::HeaderFrom, QStringLiteral("john_rt@test.com"), Akonadi::SearchTerm::CondContains));
+            QSet<qint64> result({4});
+            QTest::newRow("search by from email part") << QString::fromLatin1(query.toJSON()) << allEmailCollections << emailMimeTypes << result;
+        }
+
     }
 
     void testEmailSearch()
Comment 4 Sandro Knauß 2021-02-05 19:41:14 UTC
Git commit f87c1644469fc1ebb370f76f40b8f8cc00c6ed15 by Sandro Knauß.
Committed on 05/02/2021 at 19:39.
Pushed by knauss into branch 'master'.

SearchPluginTest: Add tests for underscore usage in email addresses.

M  +40   -3    akonadiplugin/autotests/searchplugintest.cpp

https://invent.kde.org/pim/akonadi-search/commit/f87c1644469fc1ebb370f76f40b8f8cc00c6ed15
Comment 5 jc_gargma 2021-08-09 21:10:12 UTC
I still experience this bug with kmail Version 5.17.3 (21.04.3)
Comment 6 Sandro Knauß 2021-09-25 10:03:46 UTC
(In reply to jc_gargma from comment #5)
> I still experience this bug with kmail Version 5.17.3 (21.04.3)

The bug is fixed, but the fix do no trigger a reindex of the contact. So you need to open the editpage of  the contact and press OK, than the contact is reindex and the emailadress with underscore is found afterwards.