Skip to content

Improve contact search logic for email matching - #645

Open
SamuelPlentz wants to merge 1 commit into
jobisoft:Mainfrom
SamuelPlentz:patch-1
Open

Improve contact search logic for email matching#645
SamuelPlentz wants to merge 1 commit into
jobisoft:Mainfrom
SamuelPlentz:patch-1

Conversation

@SamuelPlentz

Copy link
Copy Markdown
Contributor

Enhance contact search to prefer exact email matches before falling back to previous behavior. See #644

Enhance contact search to prefer exact email matches before falling back to previous behavior. See jobisoft#644
@SamuelPlentz

Copy link
Copy Markdown
Contributor Author

Description

This PR improves contact selection for the TO tag by preferring an exact email address match.

Problem

browser.contacts.quickSearch() can return multiple contacts when their email addresses are similar.

For example:

  • John Doedoe@example.com
  • Jane Doejane.doe@example.com

When composing an email to doe@example.com, Thunderbird may return both contacts.

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.

Solution

This change first looks for a contact whose PrimaryEmail or SecondEmail exactly matches the recipient address.

If no exact match is found, the existing behavior is retained by falling back to the first contact returned by quickSearch().

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");
}

Testing

Tested with the following contacts:

  • John Doedoe@example.com
  • Jane Doejane.doe@example.com

When composing an email to doe@example.com, Quicktext now selects John Doe even when Thunderbird returns Jane Doe as the first search result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant