getaddr

getaddr is a Perl script I wrote as an extension to the wonderful email client MH. I use it to extract email addresses from messages and add aliases for them to my aliases file. (the aliases file is MH-speak for what most MUAs call the address book).

(If you don't know what MH is, here's a good place to start: it's the online version of the O'Reilly book MH & xmh: Email for Users & Programmers.)

Standard MH offers no facilities for helping you to add new entries to the aliases file: you're expected to just edit it with your favourite editor. This is fair enough, but I got tired of viewing a message and cutting-and-pasting the email address into an editor buffer, so I wrote getaddr.

getaddr is intelligent about its argument parsing, so you can say things like:

getaddr
extract address from current message, prompt for an alias (nickname)
getaddr fred
extract address from current message, add the alias 'fred' for that address
getaddr 54
extract address from message 54, prompt for alias to use.
getaddr +inbox last
get the address from the last message in the 'inbox' folder, and prompt for the alias to use.
getaddr --force mark
extract address from current message, make 'mark' an alias for it, overwriting any existing alias 'mark' without asking.

Another reason for writing the script was to demonstrate just how easy it is to add programs to MH such that they effectively become part of the MUA. How many other mailers could you add a 'get address' function to so easily, using the language of your choice? I've tried to make it act like the standard MH programs, so it accepts 'cur', 'first', 'last', etc as message specifications.

You can look at the script itself if you like.

NB: this code is covered by a copyright similar to the XFree86 copyright. See the script for exact text, but basically you can do what you like with the code, but don't remove my name and don't blame me if it eats your aliases file :-)


This page written by Peter Maydell (pmaydell@chiark.greenend.org.uk).