Improve contact search logic for email matching - #645
Conversation
Enhance contact search to prefer exact email matches before falling back to previous behavior. See jobisoft#644
DescriptionThis PR improves contact selection for the Problem
For example:
When composing an email to The current implementation simply selects the first contact returned: let card = cards.find(c => c.type == "contact");As a result, Quicktext may use Jane Doe's contact information instead of John Doe's, depending on the order of the search results. SolutionThis change first looks for a contact whose If no exact match is found, the existing behavior is retained by falling back to the first contact returned by 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");
}TestingTested with the following contacts:
When composing an email to |
Enhance contact search to prefer exact email matches before falling back to previous behavior. See #644