From 94dc387bf046cc04696bc15eb3fad30dda357295 Mon Sep 17 00:00:00 2001 From: Samuel Plentz Date: Thu, 27 Aug 2026 15:25:47 +0200 Subject: [PATCH] Improve contact search logic for email matching Enhance contact search to prefer exact email matches before falling back to previous behavior. See #644 --- src/modules/quicktextParser.mjs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/modules/quicktextParser.mjs b/src/modules/quicktextParser.mjs index a56a795..f27defa 100644 --- a/src/modules/quicktextParser.mjs +++ b/src/modules/quicktextParser.mjs @@ -1227,7 +1227,23 @@ export class QuicktextParser { includeRemote: false, searchString: states['TO'].data['email'][aIndex].toLowerCase() }) - let card = cards.find(c => c.type == "contact"); + + let email = states['TO'].data['email'][aIndex].toLowerCase(); + + // Prefer an exact email address match. + // Thunderbird's quickSearch() may return contacts with similar email addresses, so using the first result can select the wrong contact. + let card = cards.find(c => + c.type == "contact" && + ( + c.properties.PrimaryEmail?.toLowerCase() == email || + c.properties.SecondEmail?.toLowerCase() == email + ) + ); + + // Fall back to the previous behavior if no exact match is available. + if (!card) { + card = cards.find(c => c.type == "contact"); + } if (card != null) { // Get directly stored props first.