# PROCMAIL VACATION MANAGER 0.3b [Feb 14, 2008] # # Email-based vacation autoresponder system # # Written by James Cetrangelo (noob) # based on an idea from Tony Lawrence (http://aplawrence.com) # # This code is free to distribute, change, publish, or sell. Just keep # my name & email somewhere in the comments, and this paragraph intact. # If you like it, hate it, or make improvements, please let me know. # Use at your own risk. I'm not responsible if your mail gets eaten. # # Check http://www.blackfeathermedia.com for updates. # # NOTES: # Change variables on top to suit your system. The recipies are not 100% # portable since it uses 'test -e' to check for existance of files. This # can probably be optimized and cleaned up by someone with more experience. # Needless to say, it's not for fellow noobs. You should know what you're # doing before you let my rogue code near your email. It could also use a # more substantial spam filter to prevent autoreplies to address farmers. # I know some of my shell calls can be optomised to use internal procmail # functions. A good resource: http://pm-doc.sourceforge.net/pm-tips.html # # INSTALLATION: # - Change variables at top to match your system settings # - Rename to .procmailrc and add to your home directory # - Do NOT create 'vacation_message.txt' or header files # (required files will be created or deleted when needed) # # USAGE: # - Send an email to yourself with 'Vacation On' in the subject. The body # of this message will become your outgoing message. # - The system will save that message to local files, and email you back # with a random verification code. # - Reply to that confirmation message to enable the vacation autoresponder. # - Any incoming email will recieve your outgoing message as a reply. # This should exclude obvious spam (if Spam-Asassin is running) and # repeat messages (one reply per email address) # - Disable the autoresponder by sending an email to yourself with # 'Vacation Off' in the subject line. It can also be disabled by # simply deleting the 'vacation_*.txt' files created. # # CHANGELOG: # v0.1b First version, user-unfriendly # # v0.2b Initial release. Generalized variables and added notes # # v0.3b Fixed bug that prevented some users from confirming the # verification code. A stray "^" was removed. (thanks Jason!) # ############################################################################## USERNAME=$LOGNAME USEREMAIL="${USERNAME}@yourhost.com" HOMEDIR=/home/$USERNAME LOGFILE=/dev/null SHELL=/bin/sh VACMESSAGE=$HOMEDIR/vacation_message.txt VACHEADER=$HOMEDIR/vacation_header.txt VACCODE=$HOMEDIR/.vacationcode VACCACHE=$HOMEDIR/vacation.cache # Leave unused alias names below set to $USERNAME. # set it to "sales" or "support" when these are forwarded to you ALIAS1=$USERNAME ALIAS2=$USERNAME ALIAS3=$USERNAME # When user sends an email to themselves with 'vacation on' in the subject, # their new outgoing message is temporarily stored, and a verification code # is sent in a confirmation email. Outgoing messages can be any mime type. :0 * $ ^From.*$\USEREMAIL * H ?? ^Subject:.*Vacation On * $ !^X-Loop: $\USEREMAIL { CODE= `date | md5sum` CODE= `expr substr "$CODE" 3 10` :0 hcW: vacheader.lock | formail -X Content-type | cat > $VACHEADER.tmp :0 bcW: vacmessage.lock | cat > $VACMESSAGE.tmp :0 cWi: vaccode.lock | echo "$CODE" > $VACCODE :0 | (formail -r -I"From: $USEREMAIL" -A"X-Loop: $USEREMAIL" -I"Subject: Vacation Autoresponder Message Recieved"; \ echo -e "This is an automatic message from your vacation autoresponder: \n" \ "\nYour new outgoing message has been saved. To enable vacation mode," \ "simply reply to this message. The code below is used to verify" \ "your email address. Vacation mode wont be enabled until you reply. \n" \ "\nVerification Code: $CODE\n") | $SENDMAIL -oi -t } # When the user replies to the above confirmation email containing the code, # Vacation mode is enabled: Filenames changed, and a cofirmation message is sent :0 * $ ^From.*$\USEREMAIL * ^Subject:.*Vacation Autoresponder Message Recieved * B ?? Verification Code: \/.+ * $ !^X-Loop: $\USEREMAIL * $ ? test -e $VACCODE * $ ? test -e $VACMESSAGE.tmp * $ ? test -e $VACHEADER.tmp { TESTCODE=$MATCH CODE= `cat $VACCODE` :0 * $ TESTCODE ?? $CODE { :0 ci: vacmessage.lock | rm $VACCODE; mv ${VACMESSAGE}.tmp $VACMESSAGE; mv ${VACHEADER}.tmp $VACHEADER :0 a | (formail -r -I"From: $USEREMAIL" -A"X-Loop: $USEREMAIL" -I"Subject: Vacation Autoresponder Enabled"; \ echo -e "This is an automatic message from your vacation autoresponder: \n" \ "\nVacation mode is now enabled. All incoming email will automatically" \ "recieve your outgoing reply. To turn off the vacation autoresponder," \ "simply reply to this message, or send yourself an email with 'Vacation Off'" \ "in the subject line.") | $SENDMAIL -oi -t } } # If the user replies to the above message, or sends an email to themselves # with "Vacation Off" in the subject line, then vacation mode is disabled. # Outgoing message is deleted, and a confirmation message is sent. :0 * $ ^From.*$\USEREMAIL * ^Subject:.*Vacation (Off|Autoresponder Enabled) * $ !^X-Loop: $\USEREMAIL { :0 ci: vaccache.lock * $ ? test -e $VACCACHE | rm $VACCACHE :0 ci: vacmessage.lock | rm $VACHEADER; rm $VACMESSAGE :0 a | (formail -r -I"From: $USEREMAIL" -A"X-Loop: $USEREMAIL" -I"Subject: Vacation Autoresponder Disabled"; \ echo -e "This is an automatic message from your vacation autoresponder: \n" \ "\nVacation mode is now off. Incoming emails will no longer" \ "recieve your vacation message.") | $SENDMAIL -oi -t } # If the vacation message and header files exist, vacation mode is on. # Any incoming mail gets checked against a list. New email addresses are # added to the list, and the outgoing message is sent to them. If Spam-Asassin # is installed, the most obvious spam will be excluded (but not filtered). :0 Whc: vaccache.lock * $ ^To:.*\<($\USERNAME|$\ALIAS1|$\ALIAS2|$\ALIAS3)\> * !^FROM_DAEMON * !^X-Spam-Flag:.*YES * $!^X-Loop: $\USEREMAIL * $ ? test -e $VACHEADER * $ ? test -e $VACMESSAGE # ^Subject:.*Vacation Test | formail -rD 8192 $VACCACHE :0 ehc | formail -r -I"From: $USEREMAIL" -A"X-Loop: $USEREMAIL" | cat - $VACHEADER | tr -s '\n' | cat - $VACMESSAGE | $SENDMAIL -oi -t