Copying the search scope of virtual Thunderbird search-folders
Emin Gabrielyan
2009-10-25
Manually copying virtual search folders of Thunderbird can become a time consuming process, especially when dealing with large sets of IMAP folders to scan across many accounts. Each time new search folder with slightly different search criteria is created; the set of IMAP folders selected for search must be manually re-defined by checking all concerned folders via the property panel of the new virtual search-folder.
For avoiding such manual cloning of the set of folders selected for search, a script is suggested doing this automatically. We assume that Thunderbird virtual search-folders sharing the same set of IMAP folders to search, are grouped under one local folder. We also assume that this local folder (in the example below called ‘employees2’) contains a special search-folder named ‘_Infect’ (case sensitive). With the proposed script, you need to check the list of IMAP folders considered for search, only in the properties of the special ‘_Infect’ folder. Once the script is run, all search-folders located in the same folder (in this case ‘employees2’) will inherit the set of IMAP folders from ‘_Infect’. The search criteria will not be affected, only the search scope is copied.
Only one ‘_Infect’ folder is permitted at once. The short script shown below modifies the ‘virtualFolders.dat’ in Thunderbird’s default profile directory.
To launch the script, unzip the text file, launch Cygwin, change the current directory to the folder where the script file is unzipped, and type the script name preceded by ‘./’ in the Cygwin window:
$ ./cp-search-scope.sh.txt
Searching for the location of your Thunderbird's default profile..
The Perl must be installed in your Cygwin environment. The full code of the script is shown below:
#!/bin/bash
#
echo "Searching for the location of your Thunderbird's default profile.." #
vf=`ls /cygdrive/*/Documents\ and\ Settings/*/Application\ Data/Thunderbird/Profiles/*.default/virtualFolders.dat 2>/dev/null | head -1` #
if [ -z "$vf" ] #
then #
echo "No defualt profile or virtual folder file is found" #
exit #
fi #
echo -e "\nFound the following Thunderbird virtual folder file:\n\n \"$vf\"\n" #
#
if [ `egrep "^uri=.*/_Infect$" "$vf" | wc -l` -ne 1 ] #
then #
echo "No '_Infect' search folder is found (or there are more than one such folders)." #
echo "Select a search folder and rename it to '_Infect' in order to copy its search scope," #
echo "i.e. its list of IMAP folders to scan, to all other search folders located in the" #
echo "same directory with '_Infect' (other search folders will not be affected)." #
exit #
fi #
affect=`egrep "^uri=.*/_Infect$" "$vf" | perl -ne '/^(uri=.*\/)_Infect$/; print $1'` #
if [ -z "$affect" ] #
then #
echo "Perl error (when searching the folder of search folders)" #
exit #
fi #
echo "Search scopes of all search folders of \"$affect\" will be updated" #
dir=`echo "$vf" | perl -ne 's/\/[^\/]*$//; print'` #
while true; do ps=`ps -W | grep -i thunderbird`; if [ -z "$ps" ]; then break; else echo "Please stop Thunderbird $ps"; fi; sleep 10; done #
cd "$dir" #
echo "extracting the scope.." #
cat "$vf" | perl -e '$ok=0; while(<>){$ok=0 if(/^uri=/); $ok=1 if(/^uri=.*\/_Infect$/); if($ok==1 && /^scope=/){print; last}}' > tmp_infect_scope1.txt #
grep -A1 "^uri=.*/_Infect$" "$vf" | tail -1 > tmp_infect_scope2.txt #
diff tmp_infect_scope1.txt tmp_infect_scope2.txt > /dev/null #
if [ $? -ne 0 ] #
then #
echo "Format error (when extracting the scope)" #
rm tmp_infect_scope1.txt tmp_infect_scope2.txt #
exit #
fi #
rm tmp_infect_scope1.txt #
(echo $affect; cat tmp_infect_scope2.txt; cat virtualFolders.dat) | perl -e '
$_=<>;
s/[\r\n]*//g;
$affect=$_;
$scope=<>;
while(<>)
{
if(/^uri=/)
{
$infect=0;
$f=$_;
$f=~s/\/[^\/]*$/\//;
$infect=1 if($f eq $affect)
}
if(/^scope=/ && $infect==1)
{
print $scope
}
else
{
}
}' > tmp_virtualFolders.dat.txt #
rm tmp_infect_scope2.txt #
echo -n "Diff output lines: " #
diff virtualFolders.dat tmp_virtualFolders.dat.txt | wc -l #
mv virtualFolders.dat virtualFolders.dat.backup.`date "+%y%m%d.%H%M%S"` #
mv tmp_virtualFolders.dat.txt virtualFolders.dat #
echo "You can now launch your Thunderbird" #
References
Script for copying the search scope of Thunderbird virtual folders (this page)
http://switzernet.com/public/091025-cp-thunderbird-search-scope/
http://unappel.ch/public/091025-cp-thunderbird-search-scope/
Copying search folders
http://switzernet.com/public/080901-thunderbird-search/
http://unappel.ch/public/080901-thunderbird-search/
Posted on forums.mozillazine.org for validation
http://forums.mozillazine.org/viewtopic.php?t=1554305
* * *
Copyright © 2009, Switzernet