Using mh in the School of Computing

Last modified: 2003-03-17

This document describes my personal setup for using mh in the School of Computing Facility. Despite my position as Facility Director, this is not anything supported by the School of Computing Facility. However, the Facility is not here to tell people what they can and cannot do, so if you choose to use an unsupported mail client, then have fun. Just don't go sending mail to the SoC Facility asking for help as they won't know what you are talking about; you're on your own if you want to use mh.

Being the stuck-in-the-mud that I am, I put some time into customizing my .procmailrc file and my environment, and got things working using mh. I haven't tried this out with exmh, xmh, or the like, although those probably wouldn't be too difficult to get running if you point them to the new inc script described herein. Feel free to drop me mail if you run into any problems or have any questions. I'm a pretty busy guy, but if I have time I'd be happy to help out.

Setting up your .procmailrc file

The SoC Facility mail server uses procmail to deliver incoming mail into people's mailboxes. It defaults to delivering in Maildir format, which unfortunately mh does not understand. However, you can control how procmail delivers mail via your ~/.procmailrc. Basically all we want to do is refile email ourselves using mh's rcvstore program. Here is what I have in my ~/.procmailrc file:

    RCVSTORE=/usr/local/lib/rcvstore 
    #
    # By default, refile stuff into an inbox of some sort  
    #
    :0 : inbox.lock
    | $RCVSTORE +newmail
The line at the top just defines a variable called RCVSTORE that points to the rcvstore executable. The last two lines are what actually deliver the email, by sending to the rcvstore program which files it into an mh-folder called newmail.

Once this is done, you should be able to watch all your incoming email go into this new folder. If for some reason it fails, the email should fall through and get stored in your regular Maildir folder.

Tweaking inc

Now that you have mail in mh, you are pretty much done. You can read email by running scan +newmail and what have you. However, there are some features of inc that I miss, namely doing an inc and seeing a new chunk of email, with the current mail set to the first thing inc'd. Since things get delivered individually into the newmail folder, there is no real way to see what is new since the last time you looked.

Well, so I wrote my own inc. Actually, it isn't so bad as you might think. Since I use bash as my shell, I just added these lines to my ~/.bashrc file:

    inc ()
    {
        cur_folder=`folder -fast`;
        num=`folder +newmail | awk '{print $3}'`;
        if [ "$num" = "no" ]; then
           folder -fast +$cur_folder >/dev/null;
           echo "No new messages.";
        else
           mark +inbox -sequence cur last;
           refile first:$num -src +newmail +inbox;
           mark +inbox -sequence cur next;
           scan +inbox cur-last;
        fi
    }
This just defines a function that simulates the inc behavior; it copies all mail from the newmail folder over to inbox, and then resets the current message. You could easily translate this into a shell script, by saving the bits inbetween the curly braces into a file, putting a line that reads #!/bin/bash and making that file executable. Same diff.

And that's it. That's all I have done and so far life seems to be working fine. If you want to auto-file some messages into mh-folders automatically, just use the same .procmailrc magic as above, only rcvstore it into a different folder name.