Subject: Re: auto-reply robot

From: Alan Stebbens <[email-masked]>
Date: Mon, 30 Jan 1995 15:59:17 -0800

> A couple of weeks ago, someone posted an auto-reply robot (like
> vacation,) to this list. Sorry, I lost it. Could whoever posted
> it pls. send me a copy of the script?

Here it is.

#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 12/06/1994 03:18 UTC by ???@dokoka
# Source directory /a/eci1/fs.real/eci1c/home/staff/aks/src/mail/procmail/lib
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   1754 -r--r--r-- headers.rc
#    519 -r--r--r-- dupcheck.rc
#   4225 -r--r--r-- ackmail.rc
#
# ============= headers.rc ==============
if test -f 'headers.rc' -a X"$1" != X"-c"; then
	echo 'x - skipping headers.rc (File already exists)'
else
echo 'x - extracting headers.rc (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'headers.rc' &&
# procmail rc to define patterns to recognize the headers
#
# Author: Alan K. Stebbens <[email-masked]>
# $Id: headers.rc,v 1.1 1994/12/06 02:39:13 aks Exp $
# $Source: /fs/eci1c/home/staff/aks/src/mail/procmail/lib/RCS/headers.rc,v $
#
# Use these is recipes like this:
#
#  # If mail is from john or mary, then file in "+urgent"
#  :0
#  * $ $FROM(john|mary)@
#  urgent/.
#
#  # if the mail is directly to me, then file it
#  :0
#  * $ $TO($USER)@
#  mymail/.
# 
# These patterns span any comment text before and after email addresses
# Use PRE_ADDR_SPAN before any names; it will span a string of non-address
# characters up to the beginning of a valid email address.
PRE_ADDR_SPAN='(.*[^(.%@a-zA-Z0-9])?'
X
# Use POST_ADDR_SPAN after any names; it will span a string of non-address
# characters up to the a comma "," or the end of the line
POST_ADDR_SPAN='(([^),.!:a-zA-Z0-9].*)?(,|$[^>]))'
X
# Use $FROM to match mail from someone
FROM="(^(((Resent-)?(From|Sender)|X-Envelope-From):|>?From )$PRE_ADDR_SPAN)"
X
# Use $TO to match mail to someone (but only "To:", not "Cc:")
TO="(^((Original-)?(Resent-)?To|(X-Envelope|Apparently(-Resent)?)-To):$PRE_ADDR_SPAN)"
X
# Use $CC to match mail to someone (but only "Cc:", not "To")
CC="(^((Original-)?(Resent-)?Cc|(X-Envelope|Apparently(-Resent)?)-Cc):$PRE_ADDR_SPAN)"
X
# For completeness, this should be roughly equivalent to ^TO
TOCC="($TO|$CC)"
X
# Pattern to recognize lists by precedence
LIST_PRECEDENCE='(^Precedence:.*(junk|bulk|list))'
X
# Names of common list mailers
LIST_MAILERS='((Mailer-)?daemon|root|LISTSERV|[a-zA-Z0-9-]+-(list|request|owner)|\
Majordomo|Mailagent|Postmaster|mmdf|news|n?uucp)'
X
# Pattern to put them all together
FROM_LIST="($LIST_PRECEDENCE|$FROM$LIST_MAILERS$POST_ADDR_SPAN)"
SHAR_EOF
chmod 0444 headers.rc ||
echo 'restore of headers.rc failed'
Wc_c="`wc -c < 'headers.rc'`"
test 1754 -eq "$Wc_c" ||
	echo 'headers.rc: original size 1754, current size' "$Wc_c"
fi
# ============= dupcheck.rc ==============
if test -f 'dupcheck.rc' -a X"$1" != X"-c"; then
	echo 'x - skipping dupcheck.rc (File already exists)'
else
echo 'x - extracting dupcheck.rc (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'dupcheck.rc' &&
# procmailrc to check for duplicates
# check for duplicate mail using the msgid
#
# Author: Alan K. Stebbens <[email-masked]>
# $Id: dupcheck.rc,v 1.1 1994/12/06 02:39:13 aks Exp $
# $Source: /fs/eci1c/home/staff/aks/src/mail/procmail/lib/RCS/dupcheck.rc,v $
X
# Turn off comsat -- so it won't get called
# notifing the user about mail "delivered" via
# the formail check.
X
OLDCOMSAT=${COMSAT:-off}
COMSAT=off
X
# Remove duplicate messages
:0 Wh: .msgid.lock
| formail -D 8192 .msgid.cache
X
COMSAT=$OLDCOMSAT
OLDCOMSAT
SHAR_EOF
chmod 0444 dupcheck.rc ||
echo 'restore of dupcheck.rc failed'
Wc_c="`wc -c < 'dupcheck.rc'`"
test 519 -eq "$Wc_c" ||
	echo 'dupcheck.rc: original size 519, current size' "$Wc_c"
fi
# ============= ackmail.rc ==============
if test -f 'ackmail.rc' -a X"$1" != X"-c"; then
	echo 'x - skipping ackmail.rc (File already exists)'
else
echo 'x - extracting ackmail.rc (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'ackmail.rc' &&
# ackmail.rc -- procmail rc to acknowledge mail (with either a 
#		vacation message, or an acknowledgement)
#
# Author: Alan Stebbens <[email-masked]>
#
# $Id: ackmail.rc,v 1.1 1994/12/06 02:39:13 aks Exp $
# $Source: /fs/eci1c/home/staff/aks/src/mail/procmail/lib/RCS/ackmail.rc,v $
#
# Usage:
#
#   After setting the variables below appropriately, add the following
#   to your .procmailrc:
#
#      INCLUDERC=ackmail.rc
#
# Features:
#
#  If the file $VACAMSG exists, it is assumed that the user is in
#  "vacation mode", and mail will be acknowledged with the contents of
#  the $VACAMSG file, with the subject line appended with "[on
#  vacation]".
#
#  If $VACAMSG doesn't exist, and $ACKMSG does, mail will be
#  acknowledged with the contents of $ACKMSG with the subject line
#  appended with "[acknowledgment]".
#
#  If neither the file $ACKMSG nor $VACAMSG exists, this recipe does
#  nothing.
#
#  Mail from any daemon or the usual set of mailing lists will not be
#  acknowledged (uses ^FROM_DAEMON).
#
#  Mail from any of a set of configured users ($NOACKS) will not be
#  acknowledged (be default, this includes the user).
#
#  Mail from any user will only be acknowledged once per day.
#
#  Regardless of whether or not "ackmail.rc" acknowledges the mail, any
#  recipes following the INCLUDERC will continue to filter the incoming
#  mail (that is, it is not considered to be delivered).
#
# Before including the "ackmail.rc" file, be sure to setup the following
# variables: 
#
# MY_ADDR	- preferred email address for the user
#
# MY_NAMES	- regex matcing personal names & alternatives;
#		  ultimately, only mail addressed to $MY_NAMES
#		  will be acknowledged; defaults to the
#		  contents of $SIGNATURE or $HOME/.signature, in
#		  that order.
#
# NOACKS	- regex matching people from whom to NOT 
#		  acknowledge mail; defaults to $MY_ADDR
#
# ACKS		- file containing the acknowledgment cache;
#		  defaults to $MAILDIR/.acks.cache
#
# ACKMSG	- file containing the message to reply with;
#		  defaults to $MAILDIR/ackmsg
#
# VACAMSG	- file containing the message to reply with;
#		  defaults to $MAILDIR/vacation.msg
#
# FROMSIG	- From: header to use in the auto-ack; defaults
#		  to "Mailer-Daemon of $USER"
#
# And be sure PATH includes the directory containing "formail".
X
# If the mail is directly to me, and not an auto-reply itself 
# then do the auto-ack 
X
MY_NAMES=${MY_NAMES:-${SIGNATURE:-`cat $HOME/.signature 2>/dev/null`}}
ACKS=${ACKS:-$MAILDIR/.acks.cache}
ACKMSG=${ACKMSG:-$MAILDIR/ackmsg}
VACAMSG=${VACAMSG:-$MAILDIR/vacation.msg}
FROMSIG=${FROMSIG:-"Mailer-Daemon of $USER"}
NOACKS=${NOACKS:-$MY_ADDR}
X
:0ch
* $^TO($USER|$MY_ADDR)
* ? test -f $ACKMSG -o -f $VACAMSG
* !^FROM_DAEMON
* !$ $FROM(Majordomo|Listserv)
* !^Subject: .*(\[(ack(nowledge?ment)?|on vacation)\]|\
X		auto(matic)[- ]reply|\
X		away from mail|\
X		out of town|\
X		can ?not (reply|answer)|\
X		(on |via )vacation( program)?)
* !$^X-Loop: $MY_ADDR
* !$^(((Resent-)?(From|Sender)|X-Envelope-From):|>?From ).*($NOACKS)
* $^TO($MY_NAMES)
{
X    # We're forking for the auto-ack, shut up comsat, and assume that,
X    # in this process, the mail is delivered
X    COMSAT=off
X    DELIVERED=yes
X
X    # Don't output logfile info; the user can query $ACKS to see which
X    # users have been acknowledged.  This only affects the child
X    # process.
X    LOGABSTRACT=no
X
X    # Check the mail to see if we have replied recently, and if so, if
X    # we should reply again
X    DATE=`date +'%D'`
X    FROM=`formail -rzx To:`
X    SUBJ=`formail -zx Subject: | sed -e 's/^Re: *//g' -e 's/["~]/_/g'`
X    ACKFILE=`if [ -f $VACAMSG ]; then echo $VACAMSG ; else echo $ACKMSG ; fi`
X    ACKM="`if [ -f $VACAMSG ]; then echo 'on vacation' ; else echo acknowledgment ; fi`"
X
X    # Check the cache for a recent ack
X    :0:$ACKS.$LOCKEXT
X    * !? fgrep -s "$FROM $DATE" $ACKS
X    | ( fgrep -v "$FROM" $ACKS ; echo "$FROM $DATE" ) >$ACKS.new ; \
X      rm -f $ACKS ; mv $ACKS.new $ACKS ; \
X      ( formail -rI"From:       $FROMSIG" \
X		 -I"Reply-To:   $MY_ADDR" \
X		 -I"Precedence: junk" \
X		 -I"Subject:    Re: $SUBJ [$ACKM]" \
X		 -I"X-Loop:     $MY_ADDR" \
X		 -I"References:" ; \
X	sed -e "s~\$SUBJECT~$SUBJ~" $ACKFILE ) \
X      | $SENDMAIL -oi -t
}
X
SHAR_EOF
chmod 0444 ackmail.rc ||
echo 'restore of ackmail.rc failed'
Wc_c="`wc -c < 'ackmail.rc'`"
test 4225 -eq "$Wc_c" ||
	echo 'ackmail.rc: original size 4225, current size' "$Wc_c"
fi
exit 0
i