Subject: Re: MH-style mail boxes

From: Joe Hildebrand <[email-masked]>
Date: Wed, 4 Jan 1995 10:51:15 -0500

Note to people on procmail list:  (ding) is a re-write of gnus (the
emacs news reader).  It is still in active development, and I'll post
a new "emacs recipe" when I have tested my configuration some more.

> "Joe" == Joe Hildebrand <[email-masked]> writes:

   Joe> I have a mail-processing program with which I am very happy.
   Joe> I have it deliver to MH-style mailboxes, which gnus reads
   Joe> without difficulty.  

Note to people on the (ding) list: this program is procmail, at:
file://ftp.informatik.rwth-aachen.de/pub/packages/procmail/procmail.tar.gz

   Joe> I thought that I would just be able to set up (ding) to read
   Joe> those mailboxes as if they were a local news spool with
   Joe> nnspool.  I haven't been able to get it to work, however.

> "Lars" == Lars Magne Ingebrigtsen <[email-masked]> writes:

   Lars> The main reason it doesn't work (yet) is that I know
   Lars> absolutely nothing about MH. At all. If some kind soul could
   Lars> explain to me the format that MH uses, it would be no problem
   Lars> to whip up a backend that would work, I think.

MH folders look exactly the same as the news spool directories, except
for the active file.  That is, each folder is a directory, and each
article is a separate, sequentially-numbered file.

I'm getting damn close at getting (ding) to work, using nnml.  The
hard part is the active file.  I cobbled up a perl script to update an
existing active file whenever new mail arrives (see the add-active
script at the end of this message).  I already had a script from
somewhere or other that created an active file based on the current
contents of your MH folders (see the make-active script at the end of
this message).

Then I changed my gnus-read-mail function to:

(defun gnus-read-mail ()
  "Read mail with GNUS"
  (interactive)
  (setq gnus-select-method (list 'nnml (system-name)))
  (gnus) )

and voila!  I'm still testing this setup, but it seems to work ok.
Using (ding) for reading mail now starts up *significantly* faster
than gnus did, since gnus had to build the active file every time.

Note that there is code to generate active files on the fly in
mhspool.el, in the gnus distribution.  If Lars could integrate that in
to (ding), as well as adding functions to move and delete articles
without messing up the .newsrc file, I'd be a happy camper.

-- start add-active -- snip --
#!/usr/local/bin/perl

if ($#ARGV < 0) {
    print "usage in .procmailrc: TRAP='$0 \$LASTFOLDER'\n";
    exit 64;
}

$act = "$ENV{'HOME'}/Mail/active";
$actold = $act . ".old";

rename($act,$actold) || die "$!";

($group=$ARGV[0]) =~ s#/#\.#g;
$group =~ s/\.[0-9]+$//;
($num=$ARGV[0]) =~ s#.*/([0-9]+)$#$1#;

open(ACTIVE, "$actold") || die "Could not open $actold";
open(NEW_ACTIVE, ">$act") || die "Could not open $act";

while (<ACTIVE>) {
    s/^$group [0-9]+/$group $num/;
    print NEW_ACTIVE;
}

-- end add-active -- snip --

-- start make-active -- snip --
#!/bin/sh
if [ $# -lt  1 ] ; then
        echo $0: usage: make-active directory
        exit 64
fi
base=/users/$USER/Mail
active=$1/active
cd $1
( for i in `find * -type d -print`
do
   first=`(cd $base/$i; /bin/ls -1 | egrep '^[0-9]+$' |sort -n | head -1)`
   last=`(cd $base/$i; /bin/ls -1 | egrep '^[0-9]+$' | sort -n | tail -1)`
   if [ $first ] ; then
      echo `echo $i | tr / .` $last $first n
   fi
done
# Comment the following line if you don't use NNTP.
echo NNTP 0 0 n
) > $active
exit 0

-- end make-active -- snip --

-- 
Joe Hildebrand                  Fuentez Systems Concepts
[email-masked]              11781 Lee-Jackson Hwy, Suite 700
Senior Software Engineer        Fairfax, VA 22033
                                Phone:    (703)273-1447   
                                Fax:      (703)273-2972
                                PGPprint: 0x06C96661

Standard disclaimers apply

---

From: Scott Blachowicz <[email-masked]>
Date: Wed, 04 Jan 1995 08:31:49 -0800

Looks like stuff from Karl Kleinpaste's modified-gnus distribution (from

    ftp://aphrodite.nectar.cs.cmu.edu/pub/gnus-4.1

if I remember correctly) to support the "mixspool" access method that I hacked
into gnus a while back. (FYI: "mixspool" lets you do NNTP & MH-style mail
folders in the same gnus session)

If you want to create the active file with MH commands, the script looks
something like this:

    #! /bin/sh
    mhdir=/usr/local/mh/bin
    [ -d $mhdir ] || exit 1

    MHCONTEXT=/tmp/mkact.$$ export MHCONTEXT
    trap 'rm -f /tmp/mkact.$$' 0 2 3 15

    PATH=$PATH:${mhdir}
    basedir=$HOME/Mixspool

    cd $basedir
    cp mh_active sv_mhactive

    {
       # Dummy entry to make sure we get NetNews inserted (for mixspool)...
       echo NNTP 0 0 n

       # I don't want to see my +inbox folder in news...
       find "$@" -type d ! -name inbox -print |
       while read dir
       do
          fl=`pick +./$dir first last 2>/dev/null`
          if [ $? -eq 0 ]
          then
             set -- $fl
             echo `echo $dir | tr '/' '.'` ${2:-$1} $1 n >$dir/mh_active
             cat $dir/mh_active
          fi
       done
    } > $basedir/mh_active

[NOTE: I tweaked some localizations out of that script on the fly without
       retesting, so I may have screwed it up...]

Scott Blachowicz    Ph: 206/283-8802x240    StatSci, a div of MathSoft, Inc.
                                            1700 Westlake Ave N #500
[email-masked]                           Seattle, WA USA   98109
[email-masked]