counter
List of available Procedure items (2) in this library
Title Category
[Click to unfilter]
Submitted by Function
Re-threading in TB 3.x Procedure Zygmunt Wereszczynski Threading repair using New Filtering System
Rethread messages Procedure Marck / Zygmunt Wereszczynski Make or break threads for messages in folders

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

Re-threading in TB 3.x
[ Procedure]
Threading repair using New Filtering System Added to the Library by Zygmunt Wereszczynski

Adding and removing message from a thread is simplified due to new filtering
system introduced in 3.0 version of The Bat!. These operations work nearly
in the same manner as in earlier version, but now they are more reliable and
give possibility to re-thread any kind of messages (i.e. with or without
attachments, or multiple messages at once).

'Add_Reference' filter adds message to thread using following procedure:

1. Copy Message-Id to clipboard (including triangle brackets) of the message
   which will be referenced to.
2. Select the message (or messages) which should be inserted into thread.
3. Run manually 'Add_Reference' filter using pre-defined key.
4. Move modified message which appeared in Inbox to appropriate folder.

The filter adds "References:" and "In-Reply-To:" fields to the message
header in several steps. First it exports original message to the file
"C:\Temp\Unix_Msg.txt" using Unix mailbox format. Due to such format the
entire structure of the message can be exported as a plain text file. This
file is used as the source for second action, i.e., exporting modified text
into second file "C:\Temp\export.msg". Modification of message is achieved
by following template:

%_OldMsg(%Put="C:\Temp\Unix_Msg.txt")%-
%SetPattRegExp="(?ismU)(.*)(^Subject:.*\s*.*\n)(\w.*?)"%RegexpBlindMatch(%_OldMsg)%-
%Subpatt(1)%Subpatt(2)In-Reply-To: %Clipboard
References: %Clipboard
%Subpatt(3)%-

The resulting message stored in "C:\Temp\export.msg" file is then imported
in Unix format into Inbox folder using following command line:

C:\Program Files\The Bat!\thebat.exe /IMPORTF=INBOX;X;I="C:\Temp\export.msg"

Original message without references is removed into common Trash folder.

Below is the 'Add_Reference' filter ready for copy and paste into read
messages filter group. You should assign a keyboard shortcut to it, and
probably want to modify file paths and names. They are used in several
places in filter actions (also in first line of exporting template).

$$$$ TB! Message Filter $$$$
beginFilter
UID: [A07FE8E0.01C478BF.6BE0C190.13BA8BD5]
Name: Add_Reference
Filter: {\0D\0A\20`0`0`@\0D\0A}
MoveMessage folder \5C\5C\5CTrash
ExportMessage OverwriteExist FmtUnix filename C:\5CTemp\5CUnix_Msg.txt
ExportMessage OverwriteExist FmtText filename C:\5CTemp\5Cexport.msg
 template %_OldMsg(%Put\3D\22C:\5CTemp\5CUnix_Msg.txt\22)%-
\0D\0A%SetPattRegExp\3D\22(?ismU)(.*)(^Subject:.*\5Cs*.*\5Cn)(\5Cw.*?)\22
%RegexpBlindMatch(%_OldMsg)%-\0D\0A%Subpatt(1)%Subpatt(2)In-Reply-To:\20
%Clipboard\0D\0AReferences:\20%Clipboard\0D\0A%Subpatt(3)%-\0D\0A
RunExternal Wait CmdLine C:\5CProgram\20Files\5CThe\20Bat!\5Cthebat.exe\20
/IMPORTF\3DINBOX;X;I\3D\22C:\5CTemp\5Cexport.msg\22
IsManual
IsActive
IsHotkey
IsSendQueue
endFilter

In the above filter definition the text beginning from 'ExportMessage
OverwriteExist FmtText' and ending with '%Subpatt(3)%-\0D\0A' is one line,
similar to the text between 'RunExternal' and 'export.msg\22' phrases.

'Remove_Reference' filter works in similar way. It removes message out of the
thread due to deleting "References:" and "In-Reply-To:" fields from original
message header. It requires only selecting of the message on the list and
pressing keyboard shortcut. Modified message will appear in Inbox folder and
original will move into common Trash. The main difference is in exporting
template in filter action:

%_OldMsg(%Put="C:\Temp\Unix_Msg.txt")%-
%SetPattRegExp="(?ismU)(.*)(^References:.*\s*.*\n)(\w.*?)"%RegexpBlindMatch(%_OldMsg)%-
%_NewHeader="%Subpatt(1)%Subpatt(3)"%-
%SetPattRegExp="(?ismU)(.*)(^In-Reply-To:.*\s*.*\n)(\w.*?)"%RegexpBlindMatch(%_NewHeader)%-
%Subpatt(1)%Subpatt(3)

%SetPattRegExp="(?ism)\n\n(.*)"%RegexpMatch(%_OldMsg)%-

Notice the empty line before last one is significant! Here is the
'Remove_Reference' filter ready for use:

$$$$ TB! Message Filter $$$$
beginFilter
UID: [A07FE8E0.01C478BF.700A45BD.1A1954B6]
Name: Remove_Reference
Filter: {\0D\0A\20`0`0`@\0D\0A}
MoveMessage folder \5C\5C\5CTrash
ExportMessage OverwriteExist FmtUnix filename C:\5CTemp\5CUnix_Msg.txt
ExportMessage OverwriteExist FmtText filename C:\5CTemp\5Cexport.msg
 template %_OldMsg(%Put\3D\22C:\5CTemp\5CUnix_Msg.txt\22)
%-\0D\0A%SetPattRegExp\3D\22(?ismU)(.*)(^References:.*\5Cs*.*\5Cn)(\5Cw.*?)\22
%RegexpBlindMatch(%_OldMsg)%-\0D\0A%_NewHeader\3D\22%Subpatt(1)%Subpatt(3)\22%-
\0D\0A%SetPattRegExp\3D\22(?ismU)(.*)(^In-Reply-To:.*\5Cs*.*\5Cn)(\5Cw.*?)\22
%RegexpBlindMatch(%_NewHeader)%-\0D\0A%Subpatt(1)%Subpatt(3)\0D\0A\0D\0A
%SetPattRegExp\3D\22(?ism)\5Cn\5Cn(.*)\22%RegexpMatch(%_OldMsg)%-\0D\0A
RunExternal Wait CmdLine C:\5CProgram\20Files\5CThe\20Bat!\5Cthebat.exe\20
/IMPORTF\3DINBOX;X;I\3D\22C:\5CTemp\5Cexport.msg\22
IsManual
IsActive
IsHotkey
IsCheckRule
IsHotkeyOnly
IsSendQueue
endFilter

Here the same line wrapping occurs as in 'Add_Reference' filter definition,
so please use text editor to correct this before copy and paste into The Bat!

Keyboard shortcut, path and file names in filter actions should be modified
according to individual needs.


Rethread messages
[ Procedure]
Make or break threads for messages in folders Added to the Library by Marck / Zygmunt Wereszczynski

Here are a couple of special filters to help with two related problems that
arise when using a threaded mail client like TB.

The first filter is called Add_Reference. This filter is to thread an
orphaned reply message to the message to which it is a reply.

ToDo: First copy these filters to Notepad or SmartBat and tidy them up.
You must make sure that the "Actions:" and "SaveTemplate:" values are pasted
as a single line of text and not wrapped as they appear here. Copy the tidied
up filter to the clipboard and then paste it into your sorting office using
Ctrl-V. It is best to put these filters into the "Read messages" section.

BeginFilter
Name: Add_Reference
Active: 1
Source: \\Inbox
Target: \\Inbox
CopyFolder: \\\\none
MainSet: 00@
Actions: faDelMsg,faExport,faExternal,faoExportOver,
 faoManualOnly,faoHotKey,faoHKCheckMsg,faoAdvNoAttach
ExtCmd: "C:\Program Files\The Bat!\thebat.exe" /IMPORT;F=Inbox;I="C:\Temp\export.msg"
ExtFile: C:\Temp\export.msg
HotKey: 49234
SaveTemplate: %IF:_%SETPATTREGEXP\3D\22(?is)(References:.*?\5C>)
 \22%REGEXPMATCH\3D\22%HEADERS\22_\3D__:_%-\0D\0A
 %IF:#%SETPATTREGEXP\3D\22(?is)(In-Reply-To:.*?\5C>)
 \22%REGEXPMATCH\3D\22%HEADERS#\3D##:#%-\0D\0A%HEADERS\0D\0A
 %TEXT%-\0D\0A#:#%-\0D\0A%SETPATTREGEXP\3D\22(?is)(.*)\5Cn
 (In-Reply-To:.*?\5C>)\5Cn(.*)\22%-\0D\0A
 %REGEXPBLINDMATCH\3D\22%HEADERS\22%SUBPATT\3D\221\22\0D\0A
 %SUBPATT\3D\223\22\0D\0A%TEXT%-\0D\0A#_:_\0D\0A
 %SETPATTREGEXP\3D\22(?is)(.*)\5Cn(References:.*?\5C>)\5Cn(.*)
 \22%-\0D\0A%REGEXPBLINDMATCH\3D\22%HEADERS\22%SUBPATT\3D\221\22\0D\0A
 %SUBPATT\3D\223\22\0D\0A%TEXT_%-\0D\0A\0D\0A
EndFilter


This filter can be used to repair threads broken by (for instance) Outlook
Express.

Before using this filter, you must first load up the Windows clipboard with
a copy if the message ID from the message [1] you want to thread the
orphaned message to. To do this, select the message [1] and (either) view
the source (F9) of the message (or) turn on 'kludge' view (Ctrl-Shift-K).
Find the header line that says "Message ID: <blahxxxxxx@1234567.domain>".
This is the message ID you're looking for. Mark the ID (from the '<' to
the '>' inclusive) and press Ctrl-C to copy it to the clipboard.

Now select the message you want to re-thread and activate the filter by using
the <Ctrl-Alt-R> combination.

A new version of the message will be created in your inbox. Move it to the
folder and, as if by magic, there it is, nicely threaded.

--------------------------------------------------
The next filter is used to break threads at a point of your choosing.
Sometimes a thread changes direction in the middle or gets re-titled or
maybe someone who doesn't know about threading replies to a message in the
middle of the thread with a completely different topic. For whatever reason,
you now need to separate the sub-thread from the main root. This filter lets
you do it.

This filter is activated with the <Shift-Ctrl-Alt-R> key combo. Just point
to a message in a thread that you want to make into the head of a brand new
thread and press the hotkey.

BeginFilter
Name: Remove_Reference
Active: 1
Source: \\Inbox
Target: \\Inbox
CopyFolder: \\\\none
MainSet: 00@
Actions: faDelMsg,faExport,faExternal,faoExportOver,faoManualOnly,faoHotKey
ExtCmd: "C:\Program Files\The Bat!\thebat.exe" /IMPORT;F=Inbox;I="C:\Temp\export.msg"
ExtFile: C:\Temp\export.msg
HotKey: 57426
SaveTemplate: %SETPATTREGEXP\3D\22(.*\5Cn?)(In-Reply-To:?)|(References:?)\22%-
 \0D\0A%REGEXPBLINDMATCH\3D\22%HEADERS\22%subpatt\3D\221\22%-
 \0D\0A%SETPATTREGEXP\3D\22(?is)(.*\5Cn?)(In-Reply-To:|References:)[^:]*?\5Cn%-
 \0D\0A([\5Cw\5Cd\5C-]*:\20.*)\5Cn\22%REGEXPBLINDMATCH\3D\22%HEADERS\22%subpatt\3D\223\22%-
 \0D\0A%TEXT%-\0D\0A
EndFilter

In both cases the original message is removed, but this feature may be
changed (switching off the appropriate option in the filter configuration
window). Of course, even if the message is deleted, it may be revisited
using the "Browse deleted messages" function before compressing the folder.
Both filters should be placed into "Read messages" group.

Copyright © 1996 - 2004 Marck D. Pearlstone


Last Updated 15th-October-2009