Wednesday, December 13, 2006

Removing an Address Book from Thunderbird

Thoroughly use and test a couple dozen email programs and you'll find few better than Thunderbird. Maybe one will have an editor you like better. Maybe another is geekier, in the sense that you can navigate everywhere without touching the mouse. There may well be an email client that allows you to easily send automated emails or to harvest email addresses from mail received. But Thunderbird does a lot well and comfortably. If you're a beginning or average or even an advanced email user and want to use just one email application for all normal email needs, Thunderbird's not a bad choice.

As much as Thunderbird has to offer in ease of use and functionality, it doesn't have the best interface for managing multiple address books or even managing just one address book with multiple email accounts. One significant feature Thunderbird lacks is the ability to completely remove one of several address books.

If you have an address book you no longer need and is just getting in the way, you'll find no button to click nor any menu item for deleting it. You'll have to resort to hand-editing files, files which, moreover, aren't really designed for humans to open up and make changes to. In fact, at the top of the file we'll be editing it says, "Do not edit this file." Actually we'll be following that warning because we'll be creating a new file and editing that one.

Screenshot showing multiple address books in Thunderbird.
Figure 1. Screen shot of the upper-left corner of Thunderbird's Compose window, after clicking on the drop-down menu of address books. Everything but the drop-down menu is dimmed. This graphic shows eight address books, one of which will be removed. Because Thunderbird allows the configuration of windows in several different ways, your Compose window may look different from this.

The first thing to do is to identify the address book to be removed. This is easy. Type Alt-n to open the "Compose" window as if you were writing a new message, click on the bar below "Address Book", and in the dropdown menu (shown in the graphic to the left) note the name of the address book to be removed. In this exercise we'll be removing the one called "dems".

The next thing to do is to shut down Thunderbird. This is necessary because Thunderbird writes updates to various files while running, including files we'll be editing. To avoid having our edits overwritten by a running Thunderbird, click File | Quit.

Now we need to find the appropriate files to edit, prefs.js and one other one. These are generally put into a directory (or "folder") under one called .thunderbird under your home directory. But this directory can have different names, and even different locations, depending upon how you configured Thunderbird and which operating system you're using. So go to a terminal window and type

find ~/.thunderbird -name prefs.js

Using the cd command, go to the directory where this file is found (or, if you find more than one prefs.js, its most recent instance). The directory in question on my Thunderbird installation (version 1.5.0.8 on Linux) is under the ~/.thunderbird directory, specifically, it's ~/.thunderbird/cx7ws9zz.default; the actual name of this second directory on your machine will almost certainly be different.

Note for MacIntosh and Windows users: The few commands used here— find, ls, mv, and grep— are basic commands used in Linux and UNIX. If you're working on a Mac with OS X, you already have versions of all these commands, so you need only to open up a terminal window and type them in. Windows users can probably make due with its search utility and the DIR and REN commands. Users of either of these operating systems, and others even more obscure, can obtain GNU versions of these commands (and many other handy tools) free of cost in packages available at http://www.gnu.org/software/coreutils/coreutils.html, http://directory.fsf.org/grep.html, and http://directory.fsf.org/findutils.html.

The files listed there— displayed by the ls command— are those below. You should have pretty much the same.

$ ls
6400567.s        compatibility.ini  ImapMail        panacea.dat
abook-1.mab      components.ini     impab-1.mab     persdict.dat
abook-2.mab      compreg.dat        impab-2.mab     pgprules.xml
abook-3.mab      cookies.txt        impab.mab       prefs.js
abook-4.mab      defaults.ini       install.log     prefs.js.bak
abook-5.mab      downloads.rdf      key3.db         secmod.db
abook-6.mab.bak  extensions         localstore.rdf  training.dat
abook.mab        extensions.cache   lock            US
abook.mab.bak    extensions.ini     Mail            virtualFolders.dat
cert8.db         extensions.rdf     mailViews.dat   xpti.dat
chrome           history.mab        mimeTypes.rdf   XUL.mfasl

Before altering prefs.js at all, we'll run cp prefs.js prefs.js.bak to make a backup copy of it. This backup file is just a precaution, used only in the event we want to undo the changes we'll be making. Next we take a peek into prefs.js to find the name of the address book we want to get rid of. Doing a grep of prefs.js for the name of the address book (dems), as below, will show the several lines you'll need to delete:

$ grep dems prefs.js
user_pref("ldap_2.servers.dems.description", "dems");
user_pref("ldap_2.servers.dems.dirType", 2);
user_pref("ldap_2.servers.dems.filename", "abook-5.mab");
user_pref("ldap_2.servers.dems.isOffline", false);
user_pref("ldap_2.servers.dems.protocolVersion", "2");
user_pref("ldap_2.servers.dems.replication.lastChangeNumber", 0);

Take note of the third line, the one specifying the filename, here abook-5.mab. Whatever filename is given in this line of your output will be dealt with shortly.

Note concerning Windows editors: This prefs.js file is an example of what is known as a "flat ASCII file," that is, a file containing at most only the 128 characters used in the first days of the personal computer. An editor such as Microsoft's Word silently and secretly and automatically inserts many other kinds of characters into a file during editing. For our purposes here this is not good, not good at all. So to avoid turning your file into garbage, use a different editor, one which will not corrupt the file with non-ASCII characters. Emacs is a great alternative, another GNU product, and an editor which handles just about any kind of file you might want to throw at it. It's open source, available for just about every operating system on the planet, and free and available right now at http://www.gnu.org/software/emacs/.

Next fire up your best editor, delete the six lines grep told us about, and save and close the file. Be sure to remember the name of the filename (e.g., abook-5.mab) because the next step is to rename it, like so:

mv abook-5.mab abook-5.mab.bak

Now you can restart Thunderbird. Check to ensure that the address books are functioning as desired and that only the correct one has been deleted. If everything is working fine— and you can take your good time to ascertain this, even a week or two— you can safely remove the two bak files you created.

And you're done. Reflect a moment on the methods used here, like giving a file a different name instead of deleting it and creating a backup file before making any changes to a critical file. These precautions mean that if something goes wrong, it's possible to put the files back to how they were previously. Having a way certain to back out of changes made also means that you can be more adventurous with your system, and make changes just to see what they will do. This will enable you to play around more with your system, learn more about it, and make it work the way you want it to. Learn to do this and you've done more more than simply learn how to delete an address book. You're on the way to becoming a savvy hacker.

3 comments:

Hette said...

Thank you for posting this note - it was very helpful to me. I was trying to import a address list into Thunderbird and accidentally made about 5 copies and a couple of blank ones before I realized that it was actually working... Because there is no way to see the address books unless you are in write mode!

I am in a Windows XP 5.1 (build 2600.xpsp_sp3_gdr.080814-1236 : Service Pack 3 environment).

I found the pref.js file along with the related files in C:\Documents and Settings\..myname..\Application Data\Thunderbird\Profiles\mh2x7sm.default (where "..myname.." is the user on the windows system)
There were also copies in Mozilla Thunderbird\defaults\profile but I think those are just basic defaults for use during installation.

I am running Thunderbird version 2.0.0.21 (20090302)

Anonymous said...

Tks for this very efficient topic.

Anonymous said...

hi,
my first steps in Linux.

Only a few contacts years ago.

No idea of thunderbird, but the same problems with the address book.

Just remembered the existence of an xterm window, copied your commands into the command line, installed emacs (yes, there was this editor more than ten years ago), deleted the relevant lines, and finally: Successfull.

Thanks for the detailed description.

5 free Domains with Select Hosting Plans. Get yours!