From: jrh@jrh.uucp (James R. Hamilton)
Subject: rcvsearch: mhooks program that looks for arbitrary strings
Organization: private system, Toronto, Ontario
Date: Wed, 14 Oct 1992 00:55:34 GMT

    I've grown tired of mis-matching headers in my .maildelivery file and
    so I've written a small program to do full regular expression pattern
    mathing rather than just matching any string in any location of a par-
    ticular header component.  For example a .maildelivery string,

    from,root@jrh,|,A,"/mhpath/rcvstore +junk"

    would correctly match mail from root@jrh but would also match mail from
    beetroot@jrh.  The following rcvsearch string would solve the problem:

    *,-,|,A,"/mhpath/rcvsearch '^Subject:.* root@h\.' \ /mhpath/rcvstore +junk"

    Enjoy,

             --jrh
   
........................> cut here <........................................
#!/bin/sh
#---------------------------------------------------------------------------
#
#			FILE:	rcvsearch
#			Author:	James R. Hamilton
#			Date:	92.10.12 @ 10:37:51
#
#   USAGE: Rcvsearch search_string maildelivery_program
#
#   WHERE: Search_string is any egrep legal string and maildelivery_program
#          is any arbitrary maildelivery problem.  The key problems with the
#          slocal/.maildelivery combination are the search strings are 1)
#          restricted to header entries only, and 2) restricted to literal
#          matches rather than using fully general regular expressions.  If
#          you were searching for root@jrh, you would mistakenly match 
#          beetroot@jrh as well.  A rcvsearch string of " root@jrh$" avoids
#          this possibility.
#
#   EXAMPLE: The .maildelivery string:
#
#         *,-,|,A,/usr/local/lib/mh/rcvsearch '^[^#]*\.x$' \
#             /usr/local/lib/mh/rcvstore +foundit
#
#         Will store all messages containing a line ending in ".x" without
#         any leading "#" characters.  Note that the .maildelivery string 
#         must not be continued accros multiple lines as I have here.  See 
#         the "slocal" and "mhook" man pages for more info. 
#
#   COMMENTS/FIXES TO: James Hamilton <jrh@jrh.gts.org>
#---------------------------------------------------------------------------

    #{ exec >/tmp/rcvsearch.out 2>&1; set -x; }		# Uncomment to debug
    PROG=`basename $0`
    if [ $# -lt 2 ] ; then
	echo "$PROG: USAGE: \"$PROG search_string maildelivery_program\"."
        exit 10				# Exit handler not set, return fail.
    fi
    RC=20				# Return code: Assume failure
    tmp=/tmp/$PROG.$$			# Tmp file to store note.
    trap 'rm -f $tmp; exit $RC;' 0 1 2 3 14 15	# Clean up and return RC
    cat >$tmp				# Save mail int tmp file.
    egrep "$1" $tmp			# Look for search string.
    [ $? != 0 ] && exit			# Didn't find it so fail to deliver.
    NewProg="$2"			# NewProgram Name is Arg 2.
    shift 2				# get rid of $0,$1, and $2.
    $NewProg "$@" <$tmp			# Call the supplied program to process.
    RC=$?				# Done, return code is last result.
    exit				# Jump to exit handler.

#
#------------------------------> End of File <------------------------------
........................> cut here <........................................

-- 

James R. Hamilton                                   inet: jrh@jrh.gts.org
telephone: +1 416 493 4162                          uunet: ...!uunet!jrh!jrh
Toronto, Canada                                     bitnet: jrh%jrh@uunet.uu.net
Newsgroups: comp.mail.mh