Pages: 1
RSS
Removing addresses from recipients when doing Reply-To
 
I've been looking through available TB macros, and I can't figure this one out: I would like to tell TB to do this: "When performing Reply-To, never include these two e-mail addresses among the recipients." Is this possible?

Motivation: the mail server has two alias e-mail addresses that point to the same inbox of my main address. So, when someone sends me a message to one of the alias addresses and I do a Reply-To, the reply will also be sent to myself (the alias address) unless I manually delete it from the recipients, of course.

I can think of a workaround: create a filter which detects such replies of mine and deletes them upon arrival. But, is it possible to tell TB not to send such messages to my alias addresses at all?

EDIT: Not Reply-To, I meant Reply-All
Edited: Miloš Radovanović - 09 November 2023 11:19:02 (Not Reply-To, I meant Reply-All (argh))
 
Please check your entry in Address Book. If you have two aliases in this entry, then probably you have set the option "Automatically add secondary addresses to the following field:". Try to set this to "Don't add".
 
Quote
Zygmunt Wereszczyński wrote:
Please check your entry in Address Book. If you have two aliases in this entry, then probably you have set the option "Automatically add secondary addresses to the following field:". Try to set this to "Don't add".

Thanks, but: Argh, I just noticed I didn't express the question properly. (SORRY!) "Reply-To" from my first post should read "Reply-All". So, the Reply-All operation picks up my alias address from the list of recipients of the message being replied-all to, and includes it in the recipients of the reply. I want to tell TB not to do that.

And yes, if the original problem was with Reply-To, your suggestion would have been a very probable solution. But for Reply-All in my case it doesn't do the trick.
Edited: Miloš Radovanović - 09 November 2023 10:55:43
 
Quote
Miloš Radovanović wrote:

And yes, if the original problem was with Reply-To, your suggestion would have been a very probable solution. But for Reply-All in my case it doesn't do the trick.
Oh, I see it. Several months ago I solved similar problem with removing and adding addesses in reply-all mails. See https://www.ritlabs.com/ru/forums/forum2/topic15911/message54722/#message54722 (in Russian). I will try to modify templates given in that post and present the solution.

My questions:

1. Are your aliases in received messages written in full format, i.e. "Full Name" <alias1@mail.domain>? Please give the example of such addressing in your e-mails (of course, all personal data should be removed).

2. Are the cases when both aliases are used in received messages?
 
Quote
Zygmunt Wereszczyński wrote:
Oh, I see it. Several months ago I solved similar problem with removing and adding addesses in reply-all mails. See  https://www.ritlabs.com/ru/forums/forum2/topic15911/message54722/#message54722  (in Russian). I will try to modify templates given in that post and present the solution.

Whoah! Never in a million years could I have come up with something like that. Thanks.

Quote
1. Are your aliases in received messages written in full format, i.e. "Full Name"  alias1@mail.domain >? Please give the example of such addressing in your e-mails (of course, all personal data should be removed).

Sometimes in full format, sometimes just the address. I'll try to give examples of both types and be precise as possible:

Type A: "Milos Radovanovic" <alias1@dom1.dom2.dom3.dom4> or Milos Radovanovic <alias1@dom1.dom2.dom3.dom4> or just alias1@dom1.dom2.dom3.dom4

Type B: "Milos Radovanovic" <alias2@dom1.dom4> or Milos Radovanovic <alias2@dom1.dom4> or just alias2@dom1.dom4

(dom1 and dom4 from Type A and B are equal strings)

My name can also be spelt with what some call "funny letters": Miloš Radovanović.

Quote
2. Are the cases when both aliases are used in received messages?

No.
 
I have developed quick template with identifier "Alias_Del" that you should call from the reply template of your account using %QT(Alias_Del) macro. This template check if "CC" field in reply is empty (as in the case of "normal' replies), and if it is not, then aliases are removed. Here is the template:
Code
%If:%CC<>""%-
:^%SetHeader('To','%OFromName <%OFromAddr>')%-
%SetHeader('Cc','')%-
%If:%OCC<>""%-
:%_CC='%OTo, %OCC'%-
:%_CC='%OTo'%-
%_RE1="(?ism)(.*(,\s)+)*(.*alias1@dom1\.dom2\.dom3\.dom4(>)?(,\s)?)(.*)"%-
%_CC(%ReplaceRegExp("%_RE1", "", "%_CC", 3))%-
%SetpattRegExp="(?ismU)(.*)(,\s)*$"%-
%RegExpBlindMatch(%_CC)%-
%_CC(%SubPatt(1))%-
%_RE1="(?ism)(.*(,\s)+)*(.*alias2@dom1\.dom4(>)?(,\s)?)(.*)"%-
%_CC(%ReplaceRegExp("%_RE1", "", "%_CC", 3))%-
%SetpattRegExp="(?ismU)(.*)(,\s)*$"%-
%RegExpBlindMatch(%_CC)%-
%_CC(%SubPatt(1))%-
%SetHeader('Cc','%_CC')%-^
:^^
Please note that aliases are written here using regex convention, i.e. instead of "." in domain name the "\." is used (for example "alias1@dom1\.dom2\.dom3\.dom4"). It does not matter the format of the aliase, only pure e-mail address is sufficient (without names).
 
I see my template has some glitches, so I repeated check and slightly modified it to the following:
Code
%SetHeader('To','%OFromName <%OFromAddr>')%-
%SetHeader('Cc','')%-
%If:%OCC<>""%-
:%_CC='%OTo, %OCC'%-
:%_CC='%OTo'%-
%_RE1="(?ism)(.*(,\s)+)*(.*alias1@dom1\.dom2\.dom3\.dom4(>)?(,\s)?)(.*)"%-
%_CC(%ReplaceRegExp("%_RE1", "", "%_CC", 3))%-
%SetpattRegExp="(?ismU)(.*)(,\s)*$"%-
%RegExpBlindMatch(%_CC)%-
%_CC(%SubPatt(1))%-
%_RE1="(?ism)(.*(,\s)+)*(.*alias2@dom1\.dom4(>)?(,\s)?)(.*)"%-
%_CC(%ReplaceRegExp("%_RE1", "", "%_CC", 3))%-
%SetpattRegExp="(?ismU)(.*)(,\s)*$"%-
%RegExpBlindMatch(%_CC)%-
%_CC(%SubPatt(1))%-
%SetHeader('Cc','')%-
%SetHeader('Cc','%_CC')%-

Calling this template from account (or folder) reply template is now following:

Code
%If:%CC<>""%-
:'%QT("Alias_Del")'%-

Please check if it works correctly.
Edited: Zygmunt Wereszczyński - 09 November 2023 23:11:08
 
Amazing.. great job Zygmunt!!

I have a great admiration for people who speak RegEx. Somehow it's just too abstract for me to wrap my head around (I have the same problem with 'C').
I volunteer as a moderator to help keep the forum tidy. I do not work for Ritlabs SRL.
 
Does the job perfectly. Just wow! Thank you Zygmunt for ridding me of this annoyance.

OK, it didn't work at first. It seems to me the reason was that TB puts all addresses in the To field when doing Reply-All, instead of using both To and CC. TB wasn't always like that, the behavior started relatively recently.

The trick was to call the second posted script without the If, just %QT(Alias_Del), so it runs even if the CC field is empty. I tested with several dozen e-mails, the desired recipient lists are always produced. The script even nicely rearranges the recipients into appropriate To and CC fields, which I find more appropriate.
 
I spoke a bit too soon. One thing needs to be adjusted in order for the template to fully work for me.

As I described above, when I do a Reply-All TB puts all addresses in the To field, leaving CC empty. It wasn't always like that, but from some relatively recent version it is.

Now that I have a better understanding what the script does, I concur that the initial If which checks whether %CC is empty fails to distinguish between Reply and Reply-All. If I leave the If in the Reply template, the script is never triggered, and if I remove it the script is always triggered, messing up regular Reply-s.

In order for the whole thing to work properly, I think one of two things needs to happen (and I failed at both):

1. Somehow revert TB to the old behavior of putting addresses in the CC field when performing a Reply-All. In this case the solution should work as is.

OR

2. Find a way to determine whether there are multiple recipients in the To field, replacing the initial If with this test.

Help?
 
Unfortunately, I am not able to solve the problem of different behaviour of The Bat! in Reply and Reply-All procedures. However, I have found another solution that uses the modified Alias_Del template to delete aliases in Reply-All only message. Here is the solution:

The Bat! has "Reply to All" button on the Standard toolbar. With this button is associated the drop-down list of Quick Templates which have the Use for Reply Messages option set. So, you should set this option in Alias_Del template.

Then, using this "Reply to All" button with Alias_Del template selected from the list it is possible to have desired reesult. If the button is used without template, then classic Reply to All will be generated.

Of course, in the modified Alias_Del template should be also present the default reply template copied from account properties. This is needed to generate common reply text. I added the standard reply template before the macros used to remove aliases. Here is the modified Alias_Del template:

Code
Hello %OFromFName,
  
%Cursor
  
%ODateEn, %OTimeLongEn, you wrote:
  
%Quotes
  
-- 
Best regards,
%FromName
%SetHeader('To','%OFromName <%OFromAddr>')%-
%SetHeader('Cc','')%-
%_CC='%OToList, %OCCList'%-
%_RE1="(?ism)(.*(,\s)+)*(.*alias1@dom1\.dom2\.dom3\.dom4(>)?(,\s)?)(.*)"%-
%_CC(%ReplaceRegExp("%_RE1", "", "%_CC", 3))%-
%SetpattRegExp="(?ismU)(.*)(,\s)*$"%-
%RegExpBlindMatch(%_CC)%-
%_CC(%SubPatt(1))%-
%_RE1="(?ism)(.*(,\s)+)*(.*alias2@dom1\.dom4(>)?(,\s)?)(.*)"%-
%_CC(%ReplaceRegExp("%_RE1", "", "%_CC", 3))%-
%SetpattRegExp="(?ismU)(.*)(,\s)*$"%-
%RegExpBlindMatch(%_CC)%-
%_CC(%SubPatt(1))%-
%SetHeader('Cc','%_CC')%-

I hope such solution will work exactly as you need.
Edited: Zygmunt Wereszczyński - 11 November 2023 01:07:37
 
Zygmunt, you just made my life complete  :D  Works like a charm. Made a keyboard shortcut for it to avoid additional clicks (and misclicks).

EDIT: I needed to make a small adjustment by also removing my main address in the same way as the aliases. Otherwise, in some situations the Reply-All would include my original address in the recipients.
Edited: Miloš Radovanović - 12 November 2023 01:12:24
 
I slightly modified the Alias_Del template and added a new Address_Del template to make it more generalized. The Address_Del template is called from the Alias_Del template. The Alias_Del template is now following:
Code
Hello %OFromFName,
  
%Cursor
  
%ODateEn, %OTimeLongEn, you wrote:
  
%Quotes
  
-- 
Best regards,
%FromName
%SetHeader('To','%OFromName <%OFromAddr>')%-
%SetHeader('Cc','')%-
%_CC='%OToList, %OCCList'%-
%_RE1="(?ism)(.*(,\s)+)*(.*alias1@domain1\.com(>)?(,\s)?)(.*)"%-
%QT(Address_Del, "%_RE1")%-
%_RE1="(?ism)(.*(,\s)+)*(.*alias2@domain2\.com(>)?(,\s)?)(.*)"%-
%QT(Address_Del, "%_RE1")%-
%_RE1="(?ism)(.*(,\s)+)*(.*alias3@domain3\.pl(>)?(,\s)?)(.*)"%-
%QT(Address_Del, "%_RE1")%-
%SetHeader('Cc','%_CC')%-

And here is the Address_Del template:
Code
%_CC(%ReplaceRegExp("%_1", "", "%_CC", 3))%-
%SetpattRegExp="(?ismU)(.*)(,\s)*$"%-
%RegExpBlindMatch(%_CC)%-
%_CC(%SubPatt(1))%-

Perhaps it will be easier for you to modify the templates yourself if I explain the meaning of each entry.

The initial lines in the Alias_Del template up to the %FromName macro are a copy of the default response template from The Bat! account. You can modify it freely because it formats only the content of the response without interfering with the recipient lists.

The next macro %SetHeader('To','%OFromName <%OFromAddr>') defines the contents of the "To" field in the response. I assume that only the sender of the original message will appear here. The %SetHeader('Cc','') macro is used to clear the "Cc" field of the response being created. The remaining recipients appear in the "To" and "Cc" fields of the original message. They are collected in a common list, which is the value of the %_CC variable (macro %_CC='%OToList, %OCCList').

Next comes the definition of a regular expression, which will be stored in the %_RE1 variable. The individual elements of this expression can be explained as follows:
(?ism) - these are search options used in regular expressions (e.g. case insensitive, multi-line search, etc.)
(.*(,\s)+)* - text preceding the searched e-mail address, i.e. a string of arbitrary characters symbolized by ".*", followed by one comma with a space symbolized by (,\s)+
(.*alias1@domain1\.com(>)?(,\s)?) - the address you are looking for, preceded by any number of characters and ending with the optional ">" character, i.e. (>)?, and a comma with a space (,\ s)?.
(.*) - any text that may follow the searched address.

The regular expression defined in this way is sent to the Address_Del template as an argument: %QT(Address_Del, "%_RE1"). In this template, the list of recipients contained in the %_CC variable is properly processed. First, the requested address sent to the template as an argument is removed and %ReplaceRegExp("%_1", "", "%_CC", 3) is used to do this. This macro looks up the requested address in the %_CC variable based on the regular expression provided and replaces it with the empty string "". Then the value of the variable is modified and from that moment on it no longer contains the address we are looking for.

It may happen that a "comma,space" pair remains at the end of the list of recipients and three more macros are used to optionally remove it:
%SetpattRegExp="(?ismU)(.*)(,\s)*$"%-
%RegExpBlindMatch(%_CC)%-
%_CC(%SubPatt(1))%-

The Address_Del template is called three times from the Alias_Del template. Each call is preceded by an appropriate definition of the %_RE1 variable, in which the address to be removed should be placed. Finally, the "Cc" field in the created response is modified, giving it the value of the %_CC variable - macro %SetHeader('Cc','%_CC').
 
Beautiful! Thank you for the refactoring and documentation. I can confirm that it works as well as the previous version.
Pages: 1