Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: retrieve an email from address book using name / nickname #326

Open
RealRaven2000 opened this issue Oct 12, 2024 · 6 comments
Assignees

Comments

@RealRaven2000
Copy link
Owner

As it is possible to extract a keyword from a subject line (for instance when writing an email from a OS context menu, using "send to >> email") it would be good to be able to take the file name (or part of it) to retrieve an email address from the address book. This could be done by setting something like:

%matchTextFromSubject("Emailing: (.*)",1,toclipboard)%
%header.set(to,clipboard)%

since this will likely not contain a full email address, it should be possible to use the "nickname" (or maybe display name) in order to find a matching email address and then set the final recipient.

At the moment it just inserts the name and an empty address as it finds no match based on email:

kcQDhi5v5Jvr0r2O

@hinkis
Copy link

hinkis commented Oct 13, 2024

Looking forward to it, thank you

@RealRaven2000
Copy link
Owner Author

RealRaven2000 commented Oct 14, 2024

From what I see, the AddrBookDirectory Service has no direct function to find a card from a name, but there is a "search" function that may be able to do something like this:

https://searchfox.org/comm-esr128/source/mailnews/addrbook/modules/AddrBookDirectory.sys.mjs#305

I also sent a question to the author of CardBook, whether he has such a function (or could provide one). Not sure right now whether he also has a "search" interface that would support such a function.

@RealRaven2000
Copy link
Owner Author

I asked @CardBook whether he could implement this function in Cardbook (which supports finding entries from the Cardbook address book), I want to implement searching for nickname (and maybe name) both from the standard address book and the one that is implemented in Cardbook.

He immediately came through and made a test version which I want to test first before I implement the standard search:

in last CardBook version, I've added the search you asked yesterday (I hope :). So get CardBook code (branch Thunderbird-128).

Then invoke :

  let result = await messenger.runtime.sendMessage("[email protected]", 
    {query: "smartTemplates.getContactsFromSearch", value: "wer"}, { });

the second argument might be:

{
  query: "smartTemplates.getContactsFromSearch" // fixed
  value: "string" // the value you're searching
  field: "string" // default "fn" which is the display name, you might use "nickname" or "firstname" or whatever CardBook fields
  term: "string" // default "Contains", might also be "Is", "Isnt" and others Thunderbird usual terms
  casse: "string" // default "dig", 
  possibilities ["dig", "ignoreCaseIgnoreDiacriticLabel"], ["ig", "ignoreCaseMatchDiacriticLabel"], ["dg", "matchCaseIgnoreDiacriticLabel"], ["g", "matchCaseMatchDiacriticLabel"]
}

I will add the other side of the interface in my background script and add it as a possible value, just need to come up with a Syntax. My first idea was to automatically fall back to nickname search if the email parameter in SmartTemplates doesn't include an @ symbol, but that would exclude other types of searches. We could also implement this type of search to utilise all address book fields, based on a "nickname" search , see:

https://smarttemplates.quickfolders.org/variables.html#ab_fields

@RealRaven2000
Copy link
Owner Author

RealRaven2000 commented Oct 21, 2024

So I am still pondering on how best to implement the SmartTemplates variables exactly, as it seems overkill to expand all header.set and header.append variables with complicated search syntax, I think it would be better if we had a dedicated search interface and maybe a special variable that is able to store the card contents, then that could be used with all address related variables, for instance; we could have a %card% variable that stores the last lookup from the address book, and then could be used in various ways.

We could have a search function for the AB (which can also support clipboard as a search parameter)

%card.find("text",Is,nickname)%
or
%card.find(clipboard,Is,nickname)%

This would either preload the %card% variable with the data from an address book search or an empty string (if nothing was found). We then could use it in header.set / append and even header.delete:

%header.set(to,card)%

and it could then be extended with its own field lookup functionality, like the other address variables:

%card(firstname,lastname,chatname)%
would work just like
%from(firstname,lastname,chatname)%

So we would end up with the following use for the requested use case:

%matchTextFromSubject("Emailing: (.*)",1,toclipboard)%
%card.find(clipboard,Is,nickname)%
%header.set(to,card)%

this would
1 - extract the "root name" for the address from the subject line (this already works)
2 - lookup the address book according to the search interface, and store the first matched address in the new global %card% variable
3 - set the "To" address by filling in "displayname <email>" from the card. If the card contains nothing (empty string) it would not do anything.

This is syntactically a little more complicated than implementing everything into the %header.set% command, but it is vastly more flexible, and also makes documenting the new features a little easier. It however introduces a new concept: a dedicated complex data type "card" which is a new concept for SmartTemplates users, who have only dealt with strings so far.

RealRaven2000 added a commit that referenced this issue Oct 26, 2024
- added clipboard flavor parameters
- moved AB functions to SmartTemplate4.AB
- support using empty parentheses e.g. %from()% for sandbox
@RealRaven2000 RealRaven2000 changed the title Feature request: %header.set(to)% should retrieve an email from address book using name / nickname Feature request: retrieve an email from address book using name / nickname Oct 26, 2024
@RealRaven2000
Copy link
Owner Author

Implementation takes a little longer, sorry - haven;t forgotten about it, and will do a commit with some partial changes today. But we are not anywhere near testing yet.

RealRaven2000 added a commit that referenced this issue Oct 31, 2024
- new cardbook.getContactsFromSearch
@RealRaven2000
Copy link
Owner Author

So apparently there is no API for this functionality at the moment. I will have to decide whether I can implement something lie this through the nsIAbDirectory.search() function, but that's definitely a lot of effort. Will ask Phillipe about this the next time we are meeting on the Add-on developers call.

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

No branches or pull requests

2 participants