The Bat!The Bat! and Templates The Bat!

by A. Curtis Martin.

Back to The Bat! FAQ / How-Do-I

You are caller No. counter

Table of contents:

  1. Introduction
  2. TB!'s Templates ... more on what makes them better.
  3. More On Template Types
  4. Other Mentionable Macros
  5. Template woes: "the problem with the %To, %CC and %BCC macros being included in folder templates


One of The Bat!'s most winning features is its template support. When most think of templates, they think of blocks of text predefined by the user which are placed in messages, as needed, to cut down on repetition. The Bat!(TB!) takes this basic concept much further in that it offers templates whose contents are dynamically changed through the use of macros, and additionally, they may be used to automatically execute other user defined functions such as cursor positioning, addressing changes, identity changes, active account changes among many other things. There are four main areas where templates may be defined:

  1. At the account level where a default set of new, reply and forwarded message templates may be defined. These templates will be used when more specific templates have not been defined for the intended message recipient. The editors for these templates are located in the account properties.

  2. At the folder level where a set of new, reply and forward message templates may be assigned to a particular folder. If you are creating new messages, replying to or forwarding messages from a folder, the templates defined for the folder will be used. A simple application for this is a folder to which a particular friends mail is filtered to. You may define templates to be used specifically for your friend. Folder template editors may be accessed through the folder properties invoked via the folders right click context menus.

  3. At the address book level where a set of new, reply and forward message templates may be assigned to a particular address book group or a single address book entry. Applications for address book group specific templates include defining a particular set of templates for your business associates as opposed to another for your close friends. Address book entry specific templates allow you to define templates for a particular individual such as your close loved one. Since address book templates are most specific, they will take precedence over folder and default templates and be used preferentially if you create a message to an individual for which address book templates have been defined. An added advantage with these templates is that they work with messages no matter where they may be located in the folder tree. You may access address book group and entry specific templates by opening the group or entry properties. To use and create an address book template, the option to use these specific templates has to be enabled for each template.

  4. Quick templates are an independent set of templates configured via a single configuration panel/editor accessed via the 'Options' menu. They may be used in two ways:

    1. To create templates that are not used often and also which are not peculiar to a particular recipient, group or folder. An example would be a template for technical support.

    2. To create templates to be placed within other templates described above. Through special macros, you may insert the output of quick templates into that of other templates defined. Uses of this feature include signature changes or entire template changes on the fly, where the old signature or template is automatically erased and replaced by the quick template.

Templates may also be used in other areas within TB! and these areas are:

  1. In message filters where message autoreplies may be generated and sent. The autoreply editor is actually a message template which allows the user to generate personalised autoreplies.

  2. In message receipt notification messages. These may be defined at the default account, folder and address book levels as with new, reply and forward templates. Using template macros will make you able to personalize your message auto-replies.

  3. For printing messages. You may define using a template, the format with which your messages will be printed. The template editor for doing this is found in the print setup configuration dialog.

  4. For saving messages. You may save single or multiple messages to a simple text file with the format of the saved message being definable using templates. The format of saved messages may be defined on a per account basis. The template editor for doing this is found in each accounts properties under the templates section.

[Back to top]

TB!'s Templates ... more on what makes them better

Let us look at some useful applications of TB! based templates in more detail:

Signature generation:

Although you will not find either a 'signature editor/configuration panel' or a clearcut facility to define multiple signatures in The Bat!, through templates, you are armed with an unlimited degree of flexibility with signatures. You may define any amount of signatures you like either locally or in remote text files, calleable through template macros. Through templates you may assign signatures to be used automatically on an individual basis! If you have signatures defined as quick templates, through the use of the %ISSIGNATURE macro, you may switch between them with a few keystrokes while composing your message.

Special Addressing:

While managing e-mail, you may wish to change how you identify yourself to particular recipients such as using only your first name or an alias. You may also wish to change your reply-to address. These may be achieved automatically through the use of templates (template macros %FROM="" and %REPLYTO=""), thus offering a better solution than making global identity changes or creating an whole new identity as you would have to do with other e-mail clients.

If you wish to send messages to a particular recipient/s, always using a particular account, this may be automatically achieved through templates using a macro (in this case %ACCOUNT="").

If you wish to always add CC or BCC addresses to particular messages you may do this using the %CC= and %BCC= template macros.

Other Header Changes:

You may change your organisation name, insert header comments, change a message subject, insert a new message subject or define a return path through the use of templates.

PGP related automation:

You may use templates to automatically sign and/or encrypt messages to particular recipients or groups. You may even automatically insert or attach your PGP public key to messages sent to particular recipients.

Quote prefixing:

Through the use of templates you can adjust your TB! supported quote prefixing on a per message basis rather than as a global setting.

Cursor placement:

You may use a template macro to define where in the message editor you wish your cursor to be upon generation of your messages.

Regular Expressions support:

For those who do not know, regular expressions offer a way of using a single string of coded text to match multiple strings in a text search. TB!'s template facility offers regular expression support where you may extract and output text from any area in a received message. You may then generate the matched text at will in your reply message. You may even extract single or multiple matched subpatterns defined in your regular expressions. Example of this in action include the extraction of the message date from message RFC headers so that it may be used in reply introductions or automatically stripping repetitive blocks of text such as ads from quoted text when replying to messages.

There are two regular expression templates that users of TB! have found indispensible. These are the local time conversion macro for reply quotes and the PGP signature / egroups advertising remover macros. This dissertation would not be complete without including them for your use:

  • A regular expression macro to put the local time at the top of quotes in a reply in this format

    On 24 September 2000 at 16:36:28 GMT -0700 (which was 00:36 where I live) A. Person wrote and made these points on the subject of "The message subject":

    - and here is the macro -

    %SUBPATT="3"GMT%SUBPATT="4" %-
    (which was %OTIME where I live) %OFROMNAME %-
    wrote and made these points on the subject of "%OSUBJ":

  • A regular expression macro to put the extract quotation text from within a PGP signed message with or without a preceding eGroups ad block

    %quotes="%SETPATTREGEXP='(?is)(^-+ eGroups.*~-~>.*-*_->$\s+){0,1}%-
    (^-----BEGIN PGP SIGNED.*?\n(Hash:.*?\n)?\s*)?%-
    (.*?)(^(- --\s*\n|%-
    -----BEGIN PGP SIGNATURE)|\z)'%-

To use these macros just copy them straight from this page into your template.

These especially mentionable, yet not readily perceived applications of TB! based templates singly or in combination, with the use of numerous other macros, make TB! templates extremely addictive. When you have become proficient with using them, you will start wondering how you could have done without them. :-)

[Back to top]

More On Template Types

Now, for a few pointers on the advantages/disadvantages of the various template levels and how they may be used together to provide a degree of automation that you never dreamed possible with an e-mail client.

  1. Quick templates offer a tremendous central repository for templates which may be used within multiple other templates. Say, for example, you use the same signature in the templates for five folders. You may create a single instance of the signature template and then use it in all your folder templates by using the %QINCLUDE="qt handle" macro where "qt handle" denotes the handle name that you assigned the signature quick template. If you wish to change the signature, you may then change it only once and this will be reflected in all templates that you use the signature via the %QINCLUDE macro.

    Another notable advantage of quick templates comes through the %CLEAR and %ISSIGNTAURE macros. The %CLEAR macro does the simple task of deleting the previous templates output and then putting the quick template output in it's place. The %ISSIGNATURE macro does the same thing but with the messages signature which is denoted by all text that comes after the string "-- ", a standard signature delimiter.

  2. Folder templates allow you to define a single set of templates to be used for all messages created when the folder is being browsed and also for all messages filtered to the folder. You may also define an address to be automatically filled in when creating new messages from a particular folder. You should, however be careful when doing this as discussed later in this article.

    The use of folder templates create restrictions that should be mentioned here. All of these stem from the fact that in order to use a folder's templates, the folder has to be selected at the time. If you have folder templates defined for a particular recipient and you wish to create a new message to the recipient via the New Message [favorites] drop down menu, the templates will not be applied if the appropriate folder is not selected. This also creates problems when managing new messages via the ticker associated virtual folder in that if you wish to reply to a message using a folders templates you have to first ensure that the folder is selected. As you will note in further discussions below, address book based templates will avoid these two problems and their use is encouraged if there is no particular reason for using folder based templates.

  3. Address book templates are particularly nice since you may define templates to be used for messages to a particular individual, group of individuals, or an individual in a group. The address book based templates, are also always used in preference to the folder and default templates. This allows you the flexibility to use templates for a particular recipient or recipient group, even though their messages may reside in more than one folder or when no particular folder is selected.

    Address book group templates defined for a particular address book group will be used whenever sending messages to all members of the address book group and also when sending messages to a single member of the group. However, if a member of an address book group has templates defined specifically for him/her, these specific templates will be used instead of the group specific templates when a message is created for him/her alone.

    Address book templates may be even used across a network as long as the address book is allowed to be shared across the network.

    Finally, address book based templates are not invoked only via the address book. If while creating a new message, you enter an address which has special or group templates defined for it in the address book, as soon as you place the cursor in the editor window to start editing your message, the appropriate address book template will be applied 'automagically'!

    Despite the outlined advantages of address book templates over folder templates, folder templates do appear to be processed faster than address book based templates and address book templates cannot be used when the intended messages recipient is unknown.

[Back to top]

Other Mentionable Macros

The macros which may be used in TB!'s templates are numerous and a list of them as well as a brief description of what they do may be found in the on-line help. A few other macros, aside from those mentioned before, also deserve special mention.

  • The %COOKIE macro allows you to randomly extract single lines of text from a local or remote text file. By defining the line delimiter \n in your lines of text you may generate cookies that consist of multiple lines if text when generated. Cookies may be entered in the local cookie file accessed via the Account options. Cookies may also be placed in a remote file and retrieved as needed via the %COOKIE macro. Cookie may be used to rotate tag lines or greetings.

  • The %CHARSET macro allows you to define a particular charset to be used for messages being sent to a particular recipient.

  • You may automatically attach files or insert the contents of text files into messages via the %ATTACHFILE="file path" and %PUT="path to text file" macros respectively.

  • You may even create templates as remote text files and generate them in your messages through the %INCLUDE="path to template file" macro.

[Back to top]

Template woes: the problem with the %To, %CC and %BCC macros being included in folder templates

Folder level templates provide a fine solution for e-mail messaging where recipient addresses are previously unknown e.g. Tech support or Sales templates are best handled using folder level templates. However, you should avoid listing main recipient or a number of recipients in folder templates using the %TO, %CC or %BCC macros. If you do this, what you have instructed TB! to do, is to include the address/es defined by the template in *every single* message which uses that template. At the folder template level, hard coded addresses in %TO, %CC or %BCC macros can, and usually will cause more problems than they are worth in that messages can be inadvertently sent to the wrong address/es.

A commonly used template macro on the TB! discussion list is:


This macro actually comprises two macros which do the following:

%TO="" ... this deletes all addresses from the To: field which may have already been added.

%TO='"%OFROMNAME on TBUDL" <TBUDL@THEBAT.DUTAINT.COM>' .... This second part inserts the the new customised address.

  • In fact, a regex-based, template macro that does the same thing and could be used in *any* discussion lists reply template would be:

    %TO=""%TO='"%OFROMNAME on %-
    %SubPatt=#1# " <%OREPLYADDR>'

This template macro is used in discussion list reply templates to include the original senders name in the reply address (in this case the list address). This helps others on the list to know which message is being replied to especially if they do not use the message threading feature. However, if this macro is used in a folders reply template, *any* message in the folder for which you send a reply will be addressed to the list. Replies for un/subscription notices may be inadvertently sent to the list. Replies to any non-list message which may be in the folder will be addressed as you instructed, which would be the list address!

The same goes for placing %TO macros in the new message templates of folders. This one is particularly dangerous especially with regards to 'mailto:' URL's. When a 'mailto:' URL is invoked, the address defined by your %TO macro will be added to the address generated by the 'mailto:' URL. Therefore it is a common thing to see un/subscription requests reaching wrong addresses such as a discussion lists because the %TO="<discussion list address>" macro has been added to the discussion list folder's new message templates.

Address book level templates provide a sanctuary from the misdirected mail problems being discussed, simply because they are invoked only when sending messages to a particular recipient or group of recipients as defined by the user. They are great for addresses you previously know and they of course, cannot be used for addresses which are unknown (folder templates are there for that). For example, the address for the TB! user discussion list is a well known address. It doesn't vary from message to message. Therefore, if you include the previously mentioned customised %TO macro in the reply template at the address book level, it will be invoked *only* when sending replies to the list address. Remember also that address book templates carry the added advantage of working across folders. Furthermore, you will not need to use the %TO macro in new message templates because the To: address is already defined. Problems with double addressing with MailTo: URL's would therefore be avoided.


So, as outlined for you, TB!'s template support is extensive and allows great ways of getting rid of the repetitive aspects of mail management.

[Back to top]