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

Losing all text in compose window when changing identity / signature not updated #7

Open
ckeydel opened this issue Aug 26, 2019 · 10 comments
Assignees

Comments

@ckeydel
Copy link

@ckeydel ckeydel commented Aug 26, 2019

I have a secondary, non-default identity for an email account that I have defined a signature for in TB account settings. Since signatures are different, I use %sig% in ST4 template, e.g. in the "Reply" settings.
In TB, when I do a "Reply" for an email, it first comes up with the default-identity signature which is fine. In the "From" field, I now switch to the secondary identity which causes the signature to change accordingly, so at first glance it appears correct. However, any changes I do to the signature in TB account settings are not applied, not even after a restart, it always stays the same. ST4 seems to have captured this signature once for the %sig% variable, but not updated it after.

@RealRaven2000

This comment has been minimized.

Copy link
Owner

@RealRaven2000 RealRaven2000 commented Aug 26, 2019

Well, I think SmartTemplate cannot "remember" signatures, especially when you restart Thunderbird. There are a couple of other things possible:

  • maybe it chooses another identity (how many additional identities do you have)
  • if you are using external templates make sure the [x] Attach sig from file instead is checked in identity settings.

when you write:
"However, any changes I do to the signature in TB account settings are not applied, not even after a restart, it always stays the same. "
do you mean it should change while the composer window is already open? That's currently not possible, because the replacement code runs only once; potentially we could wrap it into the "deferred variables" magic, but this is going to be tricky as it also has an effect on how the signature looks. Example with %to(name)% :
image

@ckeydel

This comment has been minimized.

Copy link
Author

@ckeydel ckeydel commented Aug 27, 2019

do you mean it should change while the composer window is already open? That's currently not possible,

Of course it is, it's always been that way that you open the compose window first and then choose the account/identity combination from the drop-down list at the "From:" field and when you do, the signature changes. This works if there has been no text entered manually. If it weren't that way, individual signature settings for each identity the way TB implements them would not make sense (there is no "reply with.." function for example).
But I found the problem - the ST4 settings dialog has an "accounts" drop-down list the same way the compose window's "From:" field has, which means you can set everything not only per account but per account/identity combination, which is cool. And that's where I had the old default signature put in (not %sig%). So my fault, when I add %sig% there it works as advertised.

@ckeydel ckeydel closed this Aug 27, 2019
@RealRaven2000

This comment has been minimized.

Copy link
Owner

@RealRaven2000 RealRaven2000 commented Sep 1, 2019

do you mean it should change while the composer window is already open? That's currently not possible,

Of course it is, it's always been that way that you open the compose window first and then choose the account/identity combination from the drop-down list at the "From:" field and when you do, the signature changes.

Yes (and no) if you change the identity SmartTemplate⁴ "starts from scratch" - as if you opened the Compose window with the new identity. However, this will not work once you start editing - you have to do it as the first thing before you type; otherwise, SmartTemplate⁴ would throw away your changes.

@ckeydel

This comment has been minimized.

Copy link
Author

@ckeydel ckeydel commented Sep 1, 2019

SmartTemplate⁴ would throw away your changes

True. This has happened to me, and there is no "undo". If you already wrote a lot of text into the compose window and then thought about changing the identity and select another one, losing everything is pretty unnerving. If keeping the text is not an option, and I can understand that it'd be too difficult to implement, could there be at least a warning with "cancel" option or an undo option?

@ckeydel ckeydel reopened this Sep 1, 2019
@ckeydel ckeydel changed the title %sig% not updated with account settings for non-default identity Losing all text in compose window when changing identity (was: %sig% not updated with account settings for non-default identity) Sep 1, 2019
@RealRaven2000

This comment has been minimized.

Copy link
Owner

@RealRaven2000 RealRaven2000 commented Sep 1, 2019

yeah to be honest, SmartTemplate⁴ shouldn't even do anything in that case - hadn't tested this in a long time but my understanding is that it used to not touch the email once you started typing. The whole method of ST is to shrink down the email to "almost nothing" apart from the quoted email which you reply to. It then rebuilds all the part bit by bit; but it cannot distinguish between the stuff that Thunderbird has added automatically and the stuff you have typed - there is a flag gMsgCompose.bodyModified which we used to check, but I can see how I can improve the whole thing.

@RealRaven2000 RealRaven2000 self-assigned this Nov 27, 2019
@RealRaven2000

This comment has been minimized.

Copy link
Owner

@RealRaven2000 RealRaven2000 commented Nov 27, 2019

Just testing this now, when I switch between identities:

If you change the identity before editing it (i.e. before you start typing) then SmartTemplate⁴ will rebuild the email according to the identity specific template.

If you select another identity after editing the email - Thunderbird itself actually changes the Signature(*) - at this stage, SmartTemplate⁴ doesn't do anything, it simply leaves the email alone - so the behavior you are seeing is actually Thunderbird composer messing it up - in my case, it kept the (non-quoted) portion of my email (Write case, not reply). The real question here is - should it really do anything? If it was to rebuild the mail how would it distinguish the text you typed from what the template has generated? You have to remember that some ST4 commands can use regular expressions to sift out content from the original email and do quite complicated stuff; it's really not reasonable to assume that it may be able to "keep only what's typed" - so I don't really know what to do in that case.

(*) in some cases it leaves the old signature in, so you may end up with two signatures:

image

Also if your signature contains smartTemplate variables, these will not be replaced (SmartTemplate⁴ is not involved in the signature replacement that Thunderbird does. I might look into overwriting the internal function of Thunderbird in order to fix that)

@RealRaven2000

This comment has been minimized.

Copy link
Owner

@RealRaven2000 RealRaven2000 commented Nov 27, 2019

OK, I tested the "change identity case" (when user hasn't typed in mail) in more detail again and found that ST4 inserted the correct (processed by ST4) signature, but then call the original load identity command from Thunderbird. Apparently I had guarded against this (see variable isTemplateProcessed) but for some removed the check 7 years ago:
image
I will try to see what happens if I put it back in...

@RealRaven2000

This comment has been minimized.

Copy link
Owner

@RealRaven2000 RealRaven2000 commented Nov 27, 2019

So testing the above with the line back in behaves satisfactorily as long as we don't type (isBodyModified=false); once we do, Thunderbird will keep the typed text but replace with an (unprocessed) signature. I will see if the original LoadIdentity( ) code runs synchronously, in which case I can try to once again replace the signature node with the processed one (from the correct identity).

one problem seems to be that the bodyModified flag (which is taken from the global gMsgCompose) is actually reset when we change the identity for the second time, which can lead to the SmartTemplate being loaded and the email being overwritten (this feels like it is a bug of Thunderbird itself, it should keep this flag even after Loading an Identity) - maybe that's something I can prevent.

@RealRaven2000

This comment has been minimized.

Copy link
Owner

@RealRaven2000 RealRaven2000 commented Nov 27, 2019

So here is a test version that will replace the signature, even after something has been typed. It leaves the processing to Thundebird (which replaces the signature first and apparently keeps the typed text) and it then will replace the signature again with the processed one (in the process replacing all ST4 variables accordingly, so you can use things like %identity(name,link)% in the signature, like in this example:

image

Interestingly I had to restore the isBodyModified flag manually so that this (changing identity wihout data loss) can be done multiple times. However one thing I haven't solved is the problem that "late resolved variables" (such as the to(name) field in the example above) are losing their "JavaScript" magic (the context menu/refresh on click and even the clean up button will be dysfunctional). Thunderbird itself does not support storing JavaScript in an email. I believe the best way forward in this case would be to replace / clean all SmartTemplate4 variables because they will be a pain to remove manually.

smartTemplate-fx-2.6pre5.zip

In order for the functionality to work these options must be enabled:
image

@RealRaven2000 RealRaven2000 changed the title Losing all text in compose window when changing identity (was: %sig% not updated with account settings for non-default identity) Losing all text in compose window when changing identity / signature not updated Nov 27, 2019
@RealRaven2000

This comment has been minimized.

Copy link
Owner

@RealRaven2000 RealRaven2000 commented Nov 27, 2019

Alright!

I have just also implemented some change that removes the unresolved fields (such as %to(name)%) when writing a new Email and then changing the identity after having typed something in the body of the mail. Thunderbird will keep the typed text, replace the signature (which will be processed by SmartTemplate!) and try to resolve the variables (in the case of to(name) it will try to read and replace the name from the address widget) - after that, unresolved variables will be deleted. I think this is as good as it currently can get. So one has to think of filling the To / Subject fields before changing the template, or type after changing the template (then the complete email is regenerated by SmartTemplate⁴ anyway)

smartTemplate-fx-2.6pre7.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.