V

autoreply_deferentially.rc

A procmail based autoreply/autoresponder/vacation script

Description

There is a number of programs available which allow users to set up automatic mail replies. One of the oldest is vacation. procmail even features some recipes in the procmailex manpages. Anyway, autoreply_deferentially.rc tries to be more cautious and to reply (hopefully) only to directly addressed, personal messages.

Use with caution

Please note that autoreply software is essentially tricky and can cause a lot of trouble. Many administrators discourage the use of such software. Here are some discussions of pros and cons:

Features

Source code

The following shows the core part of the script (slightly simplified). For the full code including more comments, variables' settings and defaults, download autoreply_deferentially.rc.

# --- send autoreply to senders (in case you received a _personal_ message)
:0
* AR_AUTOREPLY ?? yes
* $!^X-Loop: $AR_MYADDRESS
{
  :0 Whc: autoreply_deferentially.lock
  # Check to see if the mail was addressed to us
  * $^(To|CC): (.*\<)?$AR_MYADDRESS
  # Don't reply to daemons and mailinglists, junk, and other mass mailings
  * !^FROM_DAEMON
  * !(^List|mail(ing|(ing)?[- _]?list)|-l@|newsletter)
  #* !^Precedence: (list|junk|bulk) # this is included in ^FROM_DAEMON
  * !^X-Spam-Status: .*DCC_CHECK
  # Never reply to ourselves
  * $!^From: .*$AR_MYADDRESS
  # Miscellaneous criteria
  * !^(X-Sent-)?From: .*((www|web)-?(data|master|admin)|(apache|robot)@)
  * !^(From|Reply-To): .*(noreply|confirm|request|<>)
  * !^Content-Type: multipart/report
  * !^User-Agent: rss2email
  # RFC 3834 suggests to accept only "Auto-Submitted: no"
  * !^Auto-Submitted: ...
  # Don't reply to receipts (delivery notifications, out of office, ...)
  * !^User-Agent: Vacation
  * !^X-Mailer:.*auto.?(reply|mail)
  * !^X-Webmin-Autoreply: 1
  # A MS specific header (we ignore value 'None' since it was never seen)
  * !^X-Auto-Response-Suppress: ..
  # cPanel and BoxTrapper
  * !^X-Precedence: auto_reply
  # CommunicatePro sets (still?) X-Autogenerated: reply
  * !^X-Autogenerated: reply
  # Get a filter list e.g. from http://wox.at/as/_/regex_mail_receipts
  ###* !? grep -Ef /etc/procmailrc_receipts  ### uncomment if available
  # Do not reply to some selected addresses (local blacklist)
  * !^From: .*(@example.com|wf-batch@brz\.gv\.at)
  # Make sure the autoreply text exists
  * ? test -r $AR_MSGFILE
  # Mail loops are evil
  | $AR_FORMAIL -rtD 65532 "$AR_VACATION_CACHE"
 
  :0 ec         # if the senders address was not in the cache
  {
    # Get address to send reply to and write a line to $AR_LOGFILE
    :0
    * ^From:.*\/(<?[a-z0-9_][-a-z0-9_+.=]*@[-a-z0-9.]+[a-z0-9]>?)
    { # Logging the sent autoreplies
      AR_NOW=`date +%Y-%m-%d\ %H:%M`
      AR_LOGFILEBAK="$LOGFILE"
      LOGFILE="$AR_LOGFILE"
      LOG="$MATCH $AR_NOW$AR_NL"
      LOGFILE="$AR_LOGFILEBAK"
    }
    # Write a message to the default procmail log
    LOG="   >>> sending autoreply to $MATCH $AR_NL"
    # Send autoreply message
    :0 h
    | ($AR_FORMAIL -rtA"Precedence: junk" -A"Auto-Submitted: auto-replied" \
      -A"X-Auto-Response-Suppress: All" \
      -A"X-Loop: $AR_MYADDRESS" -A"From: $AR_FROMADDRESS" \
      -A"$AR_EXTRAHEADERS" ;\
      cat $AR_MSGFILE \
      ) | $AR_SENDMAIL -i -t
  }
}

Usage/Installation

I hope it is sufficiently obvious that this should not be used at all unless one at least roughly understands what the procmail recipes are doing. Anyway, please, download the full code and look at the comments for further instructions. Don't forget to provide the file in $AR_MSGFILE and to remove $AR_VACATION_CACHE if an old version exists.

Download

Disclaimer

Use at your own risk! Tested only on Debian 6 & 7.

Discussion

 
autoreply_deferentially.txt · Last modified: 2016-05-03 16:56 by andreas