...making Linux just a little more fun!

<-- prev | next -->

Emacs and Email: The VM Mail Package

By V. L. Simpson

If you've been using a GNU/Linux system for more than, let's say, a few days, you've probably noticed the plethora of email reading software that's included with said system.

And you've no doubt observed a variety of text editors lurking about, waiting to confuse you with esoteric interfaces.

Well, you don't get much more esoteric than the GNU Emacs text editor - what with Usenet, FTP, Telnet, and Email capabilities built-in as standard features. You can even do IRC or play Zork while you're working in emacs.

Emacs has three built-in mail reading and sending interfaces:

RMAIL
RMAIL is a basic (and the default) mail reading package.
MH-E
MH-E is a front-end for the MH mail tools.
Gnus
Gnus is mainly a Usenet reading package but has capabilities for reading mail and doing other strange things.

Now that you know your options inherent in Emacs I'm going to tell you about my favorite non-standard mail user agent (MUA): VM (View Mail) written by Kyle Jones.

In this article I'm going to cover installing, setting up, and using VM as your primary email interface.

Since I use GNU Emacs exclusively, that editor will be the primary focus, but this can be adapted to other emacsen as necessary. I'm also going to assume you have the base knowledge of executing emacs commands and key bindings and what the '~/.emacs' file is. But I'll toss in some generic emacs hints every now and then.

If you're an emacs newbie, I highly recommend taking the built-in tutorial (if you haven't already) to learn how emacs uses the control, escape, and tab keys to auto-complete and execute its various commands. Type the keys 'C-h t' (that's Control-h then t) to start.

Installing VM

Let me state at the outset that none of this is a one-way street. If you've been using some other mail program such as Pine or Mutt that uses the standard UNIX mbox format, you can always go back to them if VM turns out to be a dead end for your use. As a matter of fact you can switch between them with no problems. VM doesn't use any strange mailbox [1] format that breaks compatibility with other mail programs. VM can also handle RMAIL Babyl, Bell, SYSV, and MMDF formats. Maildir and MH folders can be read with a bit of tweaking. (See FAQ reference at end of article.)

VM is not part of the standard GNU Emacs lisp packages so it may be necessary for you to install VM on your own. Check your Linux distribution's available packages to see if it can be installed via rpm, apt-get, or whatever tool is appropriate.

Following are some notes and observations building the VM package from the source code.

First, it would do well to look over and adjust some variables in the Makefile (there's no configure script). Here's the configuration section with the original values commented out and my installation tweaks following:


# top of the installation
#prefix = /usr/local
prefix = /usr/share/emacs/site-lisp   

# where the Info file should go
#INFODIR = ${prefix}/lib/emacs/info
INFODIR = /usr/local/info
# You'll have to enter an entry for VM to the info/dir file by
hand.  Look at any entry for the format.

# where the vm.elc, tapestry.elc, etc. files should go
#LISPDIR = ${prefix}/lib/emacs/site-lisp
LISPDIR = ${prefix}/vm

# where the toolbar pixmaps should go.
# vm-toolbar-pixmap-directory must point to the same place.
# vm-image-directory must point to the same place.
# 
#PIXMAPDIR = ${prefix}/lib/emacs/etc/vm
PIXMAPDIR = ${prefix}/vm

# where the binaries should be go.
BINDIR = /usr/local/bin  # This is for some optional C programs
                         # that come with the distribution.

The above settings then put all the VM files in '/usr/share/emacs/site-lisp/vm' and the info files in '/usr/info' (assuming you have root access.)

You can follow my suggestions if they match with your particular Emacs installation tree or you can ignore everything here, run 'make' and hand-copy the files wherever you want to put them. Nothing gets hard-coded in the files so it's fine if you just byte-compile them and skip the 'make install' command. Just make sure you put the ultimate destination in your emacs load-path (which will be covered in a moment). You could, if you wish, just unpack the source files, run make and add that path to the load-path variable.

Configuring VM

Load Path

If you've installed the vm*.el[c] files someplace other than the site-lisp directory you will need to add that path to the load-path' variable.
Use the function 'add-to-list'.
These forms need to go in your '$HOME/.emacs file'. Use your favorite editor (emacs, of course) to create the file if you don't have one already.
Example:


     (add-to-list 'load-path "~/.emacs.d/lisp/vm")

Place the cursor after this code and press "C-xC-e".
This runs 'eval-last-sexp' and updates the load-path. There is no need to exit and restart emacs.[2]

Autoload VM Commands

Emacs has a function called autoload that allows emacs to know about functions and commands that have not been loaded into a running emacs with functions such as "load", "load-file", and "load-library".

Here are some suggested autoloads taken from the VM documentation:


     (autoload 'vm "vm" "Start VM on your primary inbox." t)
     (autoload 'vm-other-frame "vm" "Like `vm' but starts in another frame." t)
     (autoload 'vm-visit-folder "vm" "Start VM on an arbitrary folder." t)
     (autoload 'vm-visit-virtual-folder "vm" "Visit a VM virtual folder." t)
     (autoload 'vm-mode "vm" "Run VM major mode on a buffer" t)
     (autoload 'vm-mail "vm" "Send a mail message using VM." t)
     (autoload 'vm-submit-bug-report "vm" "Send a bug report about VM." t)

An easy way to make emacs aware of this new code is to highlight the region containing the autoload definitions and typing
"M-x eval-region".

[ Note: "M-" is emacs-speak for the 'Alt' key. -- Ben ]

Now you can type 'M-x any-of-the-above-commands' The main vm package file is loaded and the command is executed.

If all your mail is delivered to your system mailbox (usually '/var/spool/mail/$USER') the above is all you need to set in order to use VM. To check your mail type 'M-x vm'. VM will load, read your system mailbox and move the mail into the file ~/INBOX by default. From there just hit the space bar and you'll walk through whatever mail you have.

The following sections will cover setting up your general email environment within emacs and some interesting VM features.

Emacs Email Environment

Following are some general emacs variables you might wish to set in your '~/.emacs' file:


     (setq user-full-name "Your Full Name"
           mail-from-style 'angles
           user-mail-address "[email protected]"
           mail-default-reply-to user-mail-address)     

Use the "C-h v variable-name" command to read documentation on the above variables.

VM Features

VM has quite a few variables controlling its behavior. In order to help keep a handle on these options, VM reads the file '$HOME/.vm' after starting up. Other than the autoloaded functions described above, all vm options can be stored in this file to help keep your .emacs file manageable.

VM Display

VM's default display configuration is, for me, a bit annoying. If you run emacs under X, VM will make a new frame for just about everything you do. To keep various windows and buffers in one frame, add these options to your .emacs or .vm file:


     (setq vm-mutable-windows t
           vm-mutable-frames nil)

POP Mailboxes

You can access remote mailboxes from VM via POP3 with the command: 'M-x vm-visit-pop-folder.'

Set this option:[3]


(setq vm-pop-folder-alist
      '(
        ("pop:your.pop3.server:110:pass:remote username:*" "identifier")
        ("pop:another.pop.server:110:pass:remote username:*" "unique id")
      ))

The '*' stands in for your POP password, you'll be prompted after running 'vm-visit-pop-folder'. "identifier" is a name you can give to this pop box as an alias for that long "pop:" format. You'll be prompted for the identifier. You might want autoload that command

Miscellaneous Features

I'll just list these as the configuration and explanation is a bit hairy for this article. Please read through the VM FAQ and check the manual for more thorough explanations.

One feature I use a lot that needs a bit of detail is the option 'dired-bind-vm'. Add this bit of code to your .emacs file:

     (add-hook 'dired-load-hook
               (lambda ()
                 (setq dired-bind-vm t)))

What does this do? It sets the 'V' key in Dired Mode to run vm on a file the cursor happens to be on. So what I do is run dired-mode on my $HOME/Mail directory. I scan through all my procmail-split mboxes very quickly using the 'n' 'V' and 'q' keys. Sounds more painful than it is. It's something you'll just have to try to really see what I mean. Go ahead, try it. It won't hurt.

Interesting VM Add-ons

A couple of third-party add-ons to VM that I use.

vm-pine.el
vm-pine.el adds draft handling features that the base VM package lacks. If you follow the set-up instructions in the commentary section of the file about binding to 'C-xm', you'll also need to autoload vm function 'vm-initialize-session'.
          (autoload 'vm-initialize-session "vm")
u-vm-color.el
Adds some extra colorization to the default vm display. Ultimately, it's pointless. But it's a little extra color in your life, so why not.

VM Resources

NOTES:
1. VM does utilize its own mail file format. It's merely the standard mbox style with some vm specific headers the program needs for vm to process the mail files. You'll never know they exist unless you look at the raw mail file.

2. This applies to any code you may add to your emacs initialization file.

3. Yes, I know Emacs lisp has a strange syntax. You'll get used to it. Trust me. Copy the form and put your own parameters in if you wish to try these.

 


[BIO] V. L. Simpson, after being unceremoniously (and rather rudely) informed that GNU Emacs is not an operating system, has been re-adjusted to a happy, regular life after many protracted sessions with 'the doctor'.

A webpage is available here.

Copyright © 2004, V. L. Simpson. Released under the Open Publication license unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 109 of Linux Gazette, December 2004

<-- prev | next -->
Tux