October 15, 2004

Using Firefox's mozex extension to call an external mail program

Author: Philip J. Hollenback

I recently moved from Mozilla to Firefox 1.0PR for Web browsing on my Fedora Core 1 Linux desktop system. On that platform, Firefox doesn't do anything with mailto: links by default; it just
prints an error message if you click on one. However, a Firefox extension called mozex allows you to use any external mail program for mailto: links in Firefox.Note that Firefox on Windows does understand mailto: links, and will open the mailer you specify in your Internet Properties control panel. However, if you want to use an arbitrary program that doesn't register with that control panel, mozex works fine on Windows, and gives you other useful features I'll discuss below.

To install mozex, click on the install link while running Firefox. The first time you do this, you will receive a message from Firefox stating that it has blocked software installs from the mozex Web site for security reasons. Click on the warning (at the top of the page) and add the mozex site to your list of approved sites. Then, click on the install
link again. Follow the instructions, and mozex will be ready to run after you restart Firefox.

One caveat: mozex has not yet been updated to fully support Firefox version 1.0PR or above. This means that you have to hand-edit your Firefox preferences file before you run it. Quit Firefox, edit the file ~/.mozilla/firefox/<something>.default/prefs.js, and add the
following lines to the end:

user_pref("mozex.command.aim", "");
user_pref("mozex.command.download", "");
user_pref("mozex.command.ed2k", "");
user_pref("mozex.command.ftp", "");
user_pref("mozex.command.irc", "");
user_pref("mozex.command.mailer", "/usr/bin/xterm -title mutt -bg black -fg white -e mutt mailto:%A?subject=%S&cc=%C&body=%B");
user_pref("mozex.command.news", "");
user_pref("mozex.command.source", "/usr/bin/xterm -title mutt -bg black -fg white -e /usr/bin/vim %t");
user_pref("mozex.command.telnet", "");
user_pref("mozex.command.textarea", "/usr/bin/xterm -title mutt -bg black -fg white -e /usr/bin/vim %t");
user_pref("mozex.general.tmpdir", "/tmp");
user_pref("mozex.intercept.ftp", false);
user_pref("mozex.intercept.irc", false);
user_pref("mozex.intercept.mailto", true);
user_pref("mozex.intercept.news", false);
user_pref("mozex.universal.command", "");
user_pref("mozex.universal.schemes", "");

The mozex.command.mailer entry is the one responsible for
launching your external mail program. In my case, I run mutt in an xterm. You
can call any mail program you want. Note that you should specify the full path
to the program, and you need to also set mozex.intercept.mail to

Now you can run Firefox, click on a mailto: link, and your external mailer pops up. The extra arguments to mozex.command.mailer fill in other optional fields like the subject, cc, and body, so the experience of using an external mail program with Firefox should be exactly the same as using the built-in mailer with Mozilla.

But what about those other preferences, in particular mozex.command.source and
mozex.command.textarea? These are also very useful additions to Firefox. The mozex.command.source setting allows you to control what program is used when you right-click on a Web page and choose View Page Source from the mozex menu. My example settings above load the Web page source into the vim text editor, which lets you easily edit and save the HTML source of a page, but you can use any text or HTML editor. Note that if you choose View->Source from the Firefox menu, Firefox will still use its internal source viewer.

I find the mozex support for textareas (config option mozex.command.textarea) possibly even more useful than the support for mailto: URLs. This feature allows you to edit any text input field on a Web page in an external editor. I have always found the text editor built in to Mozilla and Firefox extremely limiting -- for example, there's no way to search for text just in the textarea you are editing. Many Web sites have feedback forms, but you can't easily insert text from another file or check your spelling while editing them.

The textarea support in mozex fixes all this. I have configured mozex to launch vim for textareas. To edit a textarea in an external editor, right-click on the textarea in Firefox. go to the mozex menu, and select Edit Textarea. If this selection is grayed out, that means you clicked on something that wasn't a textarea. If you don't see a mozex menu listed when you right-click on a Web page, you don't have mozex installed.

Mozex will open your editor and load the existing text from the textarea. Make any changes you like. Here's a handy vi hint: use :r /tmp/file.txt to copy the contents of file.txt into your current document. When you are satisfied with your text, save it and exit the editor. You will notice that nothing has changed yet on the Web page in Firefox, which can be a bit confusing. To get Firefox to accept your new text, you must left-click in the textarea once. If you don't do this and attempt to use mozex open the textarea in an external editor again, you will get a message indicating that an editing session is already open.

As you can see from my configuration example, mozex has other settings I haven't touched on here, such as handlers for telnet: and news: URLs. One thing that catches my eye is the universal handler, which allows you to create arbitrary URL schemes. The example script shows how you could use rlogin: or pop: URLs. For instance, you could specify a link rlogin://foo.example.com on a Web page that when clicked would launch an external rlogin program to presumably connect to foo.example.com. While this universal mechanism is probably not that useful on the Internet at large, you could use it to create links to all sorts of custom intranet applications.

The mozex extension illustrates one of the greatest strengths of Firefox: how easy it is to customize. If you are a new Firefox user, spend some time browsing the Firefox extension repository for many other ways to improve your Web browsing experience. There are dozens of useful extensions like mozex out there, and more are appearing all the time.

Click Here!