RealRaven2000 / SmartTemplates

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

Reply with template from tab: "cmd_reply not available in this context" #309

Closed RealRaven2000 closed 3 months ago

RealRaven2000 commented 3 months ago

Sometimes, when I am replying using an external template from a mail displayed in a tab I am getting the following error message:

image

"The function cmd_reply is not available in this context"

It must have something to do with the way single mail tabs are stored in the session.

RealRaven2000 commented 3 months ago

Not sure how to reliably reproduce this, but I wrote a patch anyway. See the new version below:

smartTemplate-fx-4.7pre17.zip

when no valid controller is found from the command, it goes through this check which tries to retrieve an enabled action button in the message header that can handle the it:

      let btn = this.investigateFollowupHeaderBtn(command);
      if (btn && !btn.getAttribute("hidden") && !btn.getAttribute("disabled"))  {
        btn.click();
        return true;
      }
      if (btn) {
        SmartTemplate4.Util.logToConsole(`the button ${btn.id} is either disabled or hidden, so no alternative follow up method is possible`)
      }

This is the (highly implementation dependant) helper function to find the button:

  investigateFollowupHeaderBtn: function(command) {
    const currentInfo = SmartTemplate4.Util.tabmail?.currentTabInfo;
    if (!currentInfo) {
      return null;
    }
    if (currentInfo.mode.name==="mailMessageTab" ) {
      let ctlButtonId;
      // future extension: should we support hdrFollowupButton ?
      switch(command) {
        case "cmd_reply":
          ctlButtonId = "hdrReplyButton";
          break;
        case "cmd_replyall":
          ctlButtonId = "hdrReplyAllButton";
          break;
        case "cmd_replylist":
          ctlButtonId = "hdrReplyListButton";
          break;
        case "cmd_forward":
          ctlButtonId = "hdrForwardButton";
          break;
        default :return null; // not applicable
      }
      return currentInfo.chromeBrowser.contentDocument.getElementById(ctlButtonId)
    }
    return null;
  },

As always, to try the version above download zip file and drag the file into Thunderbird Add-ons Manager (do not extract contents, it won't install like that)

RealRaven2000 commented 3 months ago

Fixed in 4.7 - published 05/08/2024