RealRaven2000 / SmartTemplates

Thunderbird Add-on: SmartTemplates
http://smarttemplates.quickfolders.org/
Other
25 stars 15 forks source link

`%from(addressbook,nickname)%` throws an error when trying to use Cardbook with CardDav (remote provider) #230

Open RealRaven2000 opened 1 year ago

RealRaven2000 commented 1 year ago

It appears that when using the CardBook extension to replace address variables (such as %from(addressbook,nickname)% or just %from(nickname)% ), SmartTemplates doesn't resolve the address and shows this message instead:

image

According to the debug log:

classifyReservedWord(from)
 chrome://smarttemplate4/content/smartTemplate-overlay.js:1425
card.getProperty is not a function
 split
  chrome://smarttemplate4/content/smartTemplate-overlay.js:1425:40
smartTemplate-util.js:706:11
TypeError: card.getProperty is not a function
    split chrome://smarttemplate4/content/smartTemplate-overlay.js:1425
smartTemplate-overlay.js:2401:17
SmartTemplates - invalid token: %from(addressbook,nickname)% smartTemplate-util.js:1018:11

Looks like there is some fallback code here that uses card.getProperty without a fallback. (getProperty should not be used if it doesn't exist - as in modern Thunderbird platforms.

smartTemplate-overlay.js, line 1424:

   if (prefs.getMyBoolPref('mime.resolveAB.preferNick')) {
     firstName = correctMime(card.getProperty("NickName", cardFirstName));
   }
RealRaven2000 commented 1 year ago

On top of the above - the original poster (OP) for this issue is using a remote address book via the CalDav/CardDav provider and no other address variables resolve to any useful data (all blanks) - which is the underlying problem of having to call the faulty fallback code in the aforementioned lines. This is caused by trying to populate the first name with the preferred nickname.

Here is a quick fix that will remove the error message caused by "Prefer nickname" but will not fix the problem of CardBook not returning data:

smartTemplate-fx-3.16.1pre4.zip

To install, download the version above and drag the (zip) file into Thunderbird Add-ons Manager. it will remove the faulty error message. However if Cardbook does not return data this is still an issue to be fixed.

RealRaven2000 commented 1 year ago

Technical note on the difference in the quickText Add-on (which according to the OP retrieves the data successfully) - this uses an internal interface of cardbook:

https://github.com/jobisoft/quicktext/blob/TB102/chrome/content/modules/wzQuicktextVar.jsm#L783-L803

      let cardbookRepository = ChromeUtils.import("chrome://cardbook/content/cardbookRepository.js").cardbookRepository;
      let card = cardbookRepository.cardbookUtils.getCardFromEmail(aIdentity.email.toLowerCase());

this kind of access it of course discouraged because it hinders future-proofing our Add-ons and keeping them independent from each others internal structuring.