RealRaven2000 / SmartTemplates

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

Tb115 - account template not loaded when changing From address #256

Closed RealRaven2000 closed 10 months ago

RealRaven2000 commented 10 months ago

When selecting a different identity, the new one isn't selected in SmartTemplates 4.1. instead we see the following error log:

Uncaught (in promise) TypeError: this.smartTemplate is undefined
    loadIdentity chrome://smarttemplate4/content/smartTemplate-main.js:741
    LoadIdentity chrome://messenger/content/messengercompose/MsgComposeCommands.js:9533
    oncommand chrome://messenger/content/messengercompose/messengercompose.xhtml:1
smartTemplate-main.js:741:11
RealRaven2000 commented 10 months ago

It appears that the new event handler "compose-from-changed" calls SmartTemplate4.loadIdentity() with the wrong context. "this" evaluates to ChromeWindow chrome://messenger/content/messengercompose/messengercompose.xhtml and not to the SmartTemplate4 instance of the script. This can be changed by binding a different context in the event listener.

  // old code
  window.addEventListener("compose-from-changed", SmartTemplate4.loadIdentity);
  // new code:
  window.addEventListener("compose-from-changed", SmartTemplate4.loadIdentity.bind(SmartTemplate4));

After fixing that, on top of that I am still having problems when detecting the change - because changing the identity during LoadIdentity() in core sets the gMsgCompose.bodyModified flag:

image

this is a problem because I do not allow changing the mail text if it was already modified (in my mind, this flag is / should be reserved for the user having edited the email)

RealRaven2000 commented 10 months ago

Ok, here is the bigger picture:

image

the problem is exactly when I would need the bodyModified flag to tell me the truth it pretends that the email was edited. I need to follow the triggering of this and load the identity template but need to know that this event was caused by Thunderbird's LoadIdentity function and nothing else. I will search the Core database to see whether it is being triggered from anywhere else.

RealRaven2000 commented 10 months ago

Just playing this through - Thunderbird (I believe falsely) also resets the bodyModified flag in this case after the user has done edits. I don't think it should do this, it should store the previous bodyModfied state and restore it at the end of LoadIdentity(). Ideally it should do that before dispatching the compose-from-changed event

RealRaven2000 commented 10 months ago

Since I cannot determine reliably whether the body was modified when the user changes the identity, I have decided to prompt them:

image

Clicking OK will discard anything that was written by the user since composer started, Cancel will leave the contents of the email unchanged (It may swap the signature out though).

smartTemplate-fx-4.1.1pre10.zip


To install the preview version above, please download the zip file and then drag the file into Thunderbird Add-ons Manager. Do not extract file contents, as they won't install.

RealRaven2000 commented 10 months ago

Implemented in 4.2.1, published 25/09/2023