##### procmail_vacation.rc # # Vacation Response # Procmail resource file for generating vacation responses, # included from ~/.procmailrc via INCLUDERC=procmailrc_vacation. # This works on Solaris 2.7. # # Install: # Replace variable $VOLKER and string "volker" with something suitable. # Create a vacation response file; this file contains the text of the # auto-reply. Any string "$SUBJECT" (no quotes) it contains will be replaced # with the actual subject of the msg replied to. # Adjust variables VACMAILDIR and VACMSG to preference, plus anything else you # don't like. # Check ECHO is set correctly for your system! (If it isn't, the whole thing # might crash.) # # To Activate: # Search for string "debug" and uncomment the lines suppressing a reply when # one was already sent to the current sender, and the lines which actually # send the reply. Uncomment the lines of the last recipe which does some # logging, if you like. If you want everything logged, you have to add a "c" # flag to the recipe which sends the reply. # # Copyright Volker Kuhlmann 2000 # Released under GNU General Public License Version 2. # 24, 25, 27, 28, 29, 30 Apr; 1, 10 May; 22 Jun; 12 Jul 2000 # # The directory for files associated with this vacation thingy. # Adjust names as desired. # procmail.vacation.log will be generated # procmail.vacation.cache cache storing who already got a reply # (cache size is hardcoded in the recipe) # procmail.vacation{.cached,.notcached,.nomatch} generated for debugging #VACMAILDIR=$HOME/.procmail # The message sent back as a reply. # Any $SUBJECT it contains will be replaced by the real subject of the # msg being replied to. # The first N lines of the original msg body will also be returned (N is # hardcoded in the awk command). #VACMSG=$VACMAILDIR/procmail_vacationmsg # set verbose and logging, saving old values LF=$LOGFILE LOGFILE=$VACMAILDIR/procmail.vacation.log LOG="---------- '$VACMAILDIR', '$VACMSG' " VE=$VERBOSE VERBOSE=on # These conditions detect whether the msg is NOT from a mailing list # (conditions originally from Bennett Todd ) :0 c * $ ^To:.*$VOLKER * ! ^FROM_DAEMON * ! ^List- * ! ^(Mailing-List|Approved-By|BestServHost|Resent-(Message-ID|Sender)): * ! ^Sender: (.*-errors@|owner-) * ! ^X-[^:]*-List: * ! ^X-(Authentication-Warning|Loop|Sent-To|(Listprocessor|Mailman)-Version): * ! ^Precedence: (junk|bulk|list) * !$ ^From +$LOGNAME(@| |$) { # WARNING: This must be an echo which does not interpret any backslash # escapes in its (quoted) argument. # Solaris 2.7: /usr/ucb/echo is ok, /bin/echo and the built-in echos of # /bin/sh, /bin/ksh are not. Built-in echos of /bin/csh, /bin/tcsh are ok. # Linux (SuSE 6.3): /bin/echo is ok, likewise built-ins of bash, csh, tcsh. # Or try printf. # The test is: echo '\\' must print 2 backslashes, not 1. #ECHO="echo" ECHO="/usr/ucb/echo" #ECHO="/bin/tcsh -fc \"echo ...\"" # WON'T WORK IN ANY CASE! #ECHO="printf %s" #:0 fw #| cat ; set >$MAILTEST/env # Check whether this sender already got a reply before. When using # this (formail -rD ..), also use w: or W: and a lockfile. # Set $CACHED non-empty if the sender was found in the cache. # Should stop here if it was found (unless debugging)... CACHED=$VACMAILDIR/procmail.vacation.cache :0 Wc: $CACHED$LOCKEXT | formail -rD 64536 $CACHED :0 e { CACHED="" } ## if NOT(!) debug: ## #:0 #* ! CACHED ?? ^$ #/dev/null # if cached, exit vacation processing ## :end debug ## # Generate the headers for the reply with formail -r # (add -k -p "> " to include and quote original body - no use here) # The subject will be in $MATCH (init to "" in case there is no Subject: # line; also ensures recipe is always executed) :0 hfw * 1^0 .*$\/ * 1^0 ^Subject:[ ]*\/[^ ].* | formail -r -I"Precedence: junk" \ -I"Subject: Out of office [$MATCH]" \ -A"X-Loop: volker out of office" # The "MATCH=" must be quoted with doublequotes to preserve white space, # backslash, probably others. # Inside doublequotes, backslashes must be doubled for procmail. # For sed, a literal backslash "\" can be obtained by "\\". # For the second sed (the one replacing '$SUBJECT') we must escape the # characters "\&/"; "\&" because they have special meaning for sed, and "/" # because it's used as RE delimiter. # Makes a lot of backslashes in places... but wouldn't work with any less. # Because calling external programs is expensive, do it only when necessary # (i.e. the subject actually contains any of "&/\"). :0 * MATCH ?? [&/\] { MATCH="`$ECHO \"$MATCH\" \ | sed -e 's,\\\\,\\\\\\\\,g' -e 's,/,\\\\/,g' -e 's/&/\\\\&/g'" } # Include vacation response into new msg body and return original body quoted. # Adjust the number of lines before truncation to personal preference (or # remove the awk completely). # The 'sed "s/\$SUBJ..' must(!) have only 1 "\" escaping that "$". :0 bfwi | sed -e "s/\$SUBJECT/$MATCH/g" <$VACMSG; \ awk '{print "> "$0}; NR >= 50 {print "--- TRUNCATED ---"; exit}' # Send reply off #:0 #| $SENDMAIL $SENDMAILFLAGS -t ## debug: ## this will be de-activated by uncommenting the "send" above :0 hfw # formail adds From_ | formail -dbs :0: * ! CACHED ?? ^$ $VACMAILDIR/procmail.vacation.cached :0: $VACMAILDIR/procmail.vacation.notcached ## :end debug ## } ## debug: ## :0 Ec: $VACMAILDIR/procmail.vacation.nomatch ## :end debug ## # restore verbose and logging VERBOSE=$VE LOGFILE=$LF ##### EOF procmail_vacation.rc