Subject: Re: email file server?

From: Alan Stebbens <[email-masked]>
Date: Thu, 20 Apr 1995 09:39:50 -0700

> Can anyone suggest a good email file server?  Seems like overkill to use 
> a mailing list program's file abilities when there isn't a list involved.

Try my "commandrc", a recipe for my procmail filter which processes
"commands" on the subject line.  

Tailor to taste.  It should be easy to alter for your needs.

# ~/.commandrc
#
# procmailrc file to check for commands in the subject line
#
# Current commands are:
#
#	(send | get) (help | info)
#	(send | get) pgp key
#	(send | get) procmail lib(rary)
#	(send | get) procmailrc
#
###############################
# Check for any of the commands
###############################
:0 h
* ^Subject: *(send|get) *(help|info(rmation)?|procmail(rc| *lib(rary)?)|pgp *key)
{
    # We're forking at this point -- so shutup procmail
    COMSAT=off

    # Get the reply address and subject (sans quotes)
    FROM=`$FORMAIL -rt -xTo:`
    SUBJ=`$FORMAIL -zx'Subject:' | sed -e 's/[Rr]e: *//g' -e 's/["~]/_/g'`

    # Just in case these aren't defined
    FROMSIG="${FROMSIG:-\"The Mailer-Daemon of $USER\" <$USER>}"
    MY_ADDR="${MY_ADDR:-<$USER>}"

    # Lock up the recipe
    LOCKEXT=.lock
    LOCKFILE=$HOME/.commandrc$LOCKEXT

    #########################
    # Generate a reply header
    #########################
    JUNK=`($FORMAIL -rI"From:       $FROMSIG" \
		    -I"Reply-To:   $MY_ADDR" \
		    -I"Subject:    Re: $SUBJ" \
		    -I"Precedence: junk" \
		    -I"X-Loop:     $MY_ADDR" ; \
	    echo "This message was sent auotmatically in reponse to your recent mail" ; \
	    echo "with the subject: \"$SUBJ\"." ; \
	    echo "" ) \
	> $HOME/.commandrc.reply`

    ##########################
    # Now process each command
    ##########################

    # send help

    :0 ch
    * ^Subject:.*(help|info(rmation)?)
    | ( cat $HOME/.commandrc.reply $HOME/.commandrc.help ) \
      | $SENDMAIL -oi -t

    # send procmailrc

    :0 Ech
    * ^Subject:.*procmailrc
    | ( cd $HOME ; \
	cat $HOME/.commandrc.reply ; \
	shar -cCem .procmailrc .commandrc .commandrc.help ) \
      | $SENDMAIL -oi -t

    # Send procmail lib

    :0 Ech
    * ^Subject:.*procmail *lib(rary)?
    * ? test -f $HOME/src/mail/procmail/lib/procmail-lib.shar
    | ( cat $HOME/.commandrc.reply \
	$HOME/src/mail/procmail/lib/procmail-lib.shar ) \
      | $SENDMAIL -oi -t

    # send pgp key

    :0 Ech
    * ^Subject:.*pgp *key
    | ($FORMAIL -rI"From: $FROMSIG" \
		-I"Reply-To: $MY_ADDR" \
		-I"Subject: PGP public key" \
		-I"Mime-Version: 1.0" \
		-I"Content-Type: application/pgp; format=keys-only" \
		-I"Content-Description: PGP key of $MY_ADDR" \
		-I"Content-Transfer-Encoding: 7bit" \
		-I"X-Loop: $MY_ADDR" ;\
		sh -c "pgp -kxaf $MY_ADDR 2>/dev/null") \
      | $SENDMAIL -oi -t
    
    # Don't log anything else
    LOGABSTRACT=off

    :0 Achw: pgpkey-requests$LOCKEXT
    | echo "`date` : $FROM : $SUBJ" >> $MAILDIR/pgpkey-requests.log

    # Log this request
    :0 w
    | echo "`date` : $FROM : $SUBJ" >> $MAILDIR/commandrc.log

    # Junk the reply, and fool procmail into thinking the mail was delivered
    :0 h
    |rm -f $HOME/.commandrc.reply

    DELIVERED=yes
    LOCKFILE
}

# End of ~/.commandrc