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

Double template inserted when replying to own email - Tb Conversations Add-on! #139

Closed
RealRaven2000 opened this issue Jun 28, 2021 · 25 comments
Assignees
Labels

Comments

@RealRaven2000
Copy link
Owner

RealRaven2000 commented Jun 28, 2021

I haven't been able to reproduce this but apparently there may be conditions that lead to the identity being inserted in the same way as if the identity was changed manually by selecting another "from" address) - before the actual SmartTemplates insertTemplate() code was fully executed - this leads to a duplication of the template within the email.

@RealRaven2000 RealRaven2000 self-assigned this Jun 28, 2021
@RealRaven2000
Copy link
Owner Author

RealRaven2000 commented Jun 28, 2021

Here is a test version which will omit inserting the template if loadIdentity() is called with a "falsy"startup argument and there is no previous identity passed in, this means SmartTemplates didn't have a chance to run yet, so SmartTemplates is just omitting it's own workload in this case and logs a debug line as well.

smartTemplate-fx-3.6.1pre2.zip

To install this test version, download the zip file and then drag that into Thunderbird Add-ons manager.

@macdeport
Copy link

The checkbox has the reverse of expected behavior:
floating-screenshot-201051

@marknow22
Copy link

Hi,
I think we have this bug sort of as well.
However, we do not reply to our own email.

here is what happens:

When replying to any mail, the template is being inserted twice.

One insert is above the signature, this is correct.
The other insert is below the signature

The template is a textfile that is being inserted by using the %file variable

%file(C:\Program Files\Mozilla Thunderbird\templates\thunderbird_template_cust.html)%

The behavior only occurs under Windows 8.1 and 10 with Thunderbird 91.0.3 and SmartTemplatesPro 3.7

Thank you very much.

@RealRaven2000 RealRaven2000 pinned this issue Sep 16, 2021
@RealRaven2000
Copy link
Owner Author

I think we have this bug sort of as well. However, we do not reply to our own email.

here is what happens:
When replying to any mail, the template is being inserted twice.

One insert is above the signature, this is correct.
The other insert is below the signature

Does your template include the %sig% variable?

The behavior only occurs under Windows 8.1 and 10 with Thunderbird 91.0.3 and SmartTemplatesPro 3.7

Thank you very much.

Could you please share the source code of the html please? Also when you reply to the mail, can you check whether it has no quoted mail from you using the same (or another) Smart Template?

@marknow22
Copy link

marknow22 commented Sep 17, 2021

Does your template include the %sig% variable?
No it does not.
The signature is being configured under the account settings of thunderbird as included textfile. It contains the email adress.

Also when you reply to the mail, can you check whether it has no quoted mail from you using the same (or another) Smart Template?
It does not contain quoted mail from any smarttemplate. I have checked the behavior. Also, while having disabled the signature, the template still is being duplicated.

Could you please share the source code of the html please?

Sehr geehrte/r<br> <br> Mailtext<br> <br> Mit freundlichen Grüßen<br> Ihr AGORA direct™ Team

The same behavior occurs, when inserting the HTML directly into the reply settings of smart template.

@marknow22
Copy link

marknow22 commented Sep 17, 2021

These are the settings
image

This is the behavior
screenshot

@marknow22
Copy link

A collegue just noticed that when he changes the mail identity, then the normal behavior returns and the duplicate is being removed. When he returns to the original mail identity, the duplicate is gone.

@RealRaven2000
Copy link
Owner Author

A collegue just noticed that when he changes the mail identity, then the normal behavior returns and the duplicate is being removed. When he returns to the original mail identity, the duplicate is gone.

Yes, the template is reloaded when you change identity, but it's obviously not a good workaround. Was the original mail also made with SmartTemplates? I think this part may be important. I will work on this bug over this weekend because (when it happens) it is super annoying!

@RealRaven2000
Copy link
Owner Author

Quick first debugging result - there is an event handler for loading identities, which is called by Thunderbird whne the identity is changed. The normal case is Thunderbird emitting the NotifyComposBodyReady event which is when I usually load the template. Apparently in this case the "LoadIdentity" function is also called as well - SmartTemplates is normally robust enough by removing any previous template it inserted but maybe this is in the middle of inserting the template the first time around. My main problem is how to detect whether this is currently the case or not, so that the code for changing identity (by the user) still works.

@marknow22
Copy link

Was the original mail also made with SmartTemplates?

Hi I think not, as the sender is not using SmartTemplate.

I just noticed that the bug also occurs under Linux, here I am using 91.1.0 with SmartTemplate 3.7

@marknow22
Copy link

I just noticed that the bug also occurs under Linux, here I am using 91.1.0 with SmartTemplate 3.7
I know this is annoying, but now the bug has gone. I have reopened the mail, which I wanted to answer and the bug has been gone. I will wait what you find out over the weekend.

@RealRaven2000
Copy link
Owner Author

So what happens if an account template is activated on reply and you are in a different account than the where the original email came from (so the mail was moved across accounts either manually or by a filter rule) one of the first things Thunderbird does is call LoadIdentity(false) . The false is actually the startup parameter that is hardcoded in Thunderbird (and should really be set to true IMHO).

Then if your signature or template contains any commands that pull in external files (such as images, style sheets or html fragments) may cause the event NotifyComposeBodyReady to be triggered before LoadIdentity is complete. This is a classic race condition. I have added some code that should avoid this when an external template is selected via the reply button, and it seems to also work when you use the %file()% command from your account template. I still see duplication when I have the html in the account template itself and the signature pulls in an image, so this is still WIP.

At the heart of the patch is trying to avoid the payload of "NotifyComposeBodyReady" being called more than once concurrently

NotifyComposeBodyReady: function(event) {
   ...
+  if (SmartTemplate4.PreprocessingFlags.NotifyComposeBodyReadyFired) 
+    isNotify = false; // [issue 139]
+  SmartTemplate4.PreprocessingFlags.NotifyComposeBodyReadyFired = true;
  
   if (isNotify) {
     window.setTimeout(
       function(){ SmartTemplate4.notifyComposeBodyReady(event); }, eventDelay);
   }      
   ...
}

Thunderbird 68: smartTemplate-fx-2.17pre24.zip
Thunderbird 78-91:
smartTemplate-fx-3.8pre27.zip

to install these, download the zip file and then drag it into Thunderbird Add-ons Manager.

@macdeport
Copy link

macdeport commented Oct 15, 2021

Thunderbird 78.14.0
smartTemplate-fx-3.8pre169.zip
Still make double template insertion...
Let me know if you need more stuff.

@RealRaven2000
Copy link
Owner Author

@marknow22 can you test what happens if you disable custom headers and put in your own?

image

Just to make sure we are comparing apples with apples, please use the very latest build:

smartTemplate-fx-3.8pre170.zip

@RealRaven2000
Copy link
Owner Author

@marknow22 - here is my result using Thunderbird 78.14.0 - no quote header and just loading your HTML text from a file using
%file(E:\Dev\Mozilla\Dev\SmartTemplate\Support\issue_139\marknow22.html)%

image

@marknow22
Copy link

I have tested with smarttemplate 3.8 and TB 91.3.0 and the error was still there.
Sorry that it took so long.

@RealRaven2000
Copy link
Owner Author

I have tested with smarttemplate 3.8 and TB 91.3.0 and the error was still there. Sorry that it took so long.

Workaround - If you have Thunderbird conversations installed, use the reply button on the main toolbar instead:

image

this will also give you the benefit of being able to add different templates:

image

@RealRaven2000 RealRaven2000 changed the title Double template inserted when replying to own email Double template inserted when replying to own email - Tb Conversations Add-on! Nov 17, 2021
@RealRaven2000
Copy link
Owner Author

I changed the title because this problem can be reproduced reliably by installing the Thunderbird Conversations Add-on by Jonathan Protzenko and Standard8 - the built in reply button uses the official API which is allowed to run from a content script (and doesn't require full access to the Thunderbird back end code)

Here is the button (within the content preview area of Thunderbird Conversations) that causes the issue:
image

This also means that it is not possible for SmartTemplates currently to inject it's file templates submenu into this reply button. IN contrast, here is the Thunderbird owned reply button on the Main toolbar that can be used as a workaround:

image

The dropdown button on the right hand side can be used to call up custom templates / standard replies based on external HTML files:
image

Until I have fixed this issue I highly recommend adding the standard reply button to the main toolbar of Thunderbird, by rght-clicking and selecting customize...
image

Here you can also add buttons such as forward / reply to list etc. which are all serviced by the SmartTemplates submenu...

@RealRaven2000
Copy link
Owner Author

Test version with attempted fix:

smartTemplate-fx-3.8.1pre10.zip

To install, as always download the zip file and then drag it into Add-ons Manager. please add feedback below!!

@RealRaven2000
Copy link
Owner Author

@marknow22 can you test the version above on Mac when you get a minute?

@RealRaven2000
Copy link
Owner Author

Here is a test version for Thunderbird 68:

smartTemplate-fx-2.17pre102.zip

To test this version, download the zip file. then drag the zip file into Thunderbird 68 Add-ons Manager to install it.

@RealRaven2000
Copy link
Owner Author

#155 closed as duplicate of this one.

@marknow22
Copy link

marknow22 commented Dec 8, 2021

@marknow22 can you test the version above on Mac when you get a minute?

Hi, sorry again that it took so long again.

Tested on Mac, by using different accounts and all the reply-buttons that were available (the one in the main icon bar and the one in the messaging window and also the right-click [I use a PC mouse on the mac] one) and the bug seems to be gone.

I am using:
SmartTemplate 3.8.1pre10
Thunderbird on OSX 9.1.4.0 (64bit)
No conversations Addon

For the sake of it, I have tested it too on:
Thunderbird on Linux (Ubuntu 18.04) 9.1.4.0 (64bit)
SmartTemplate 3.8.1pre10

And the bug was gone here as well.

@RealRaven2000
Copy link
Owner Author

Fixed in 3.9 - released on 09/12/2021

@RealRaven2000
Copy link
Owner Author

Fixed in v. 3.9 - released on Dec. 9, 2021

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

No branches or pull requests

3 participants