On Sat, 10 Jan 1998, Marcus Holmes <mholmes(_at_)world(_dot_)std(_dot_)com>
asked:
with the word ICQ in the subject procmail will send out a reply &attach a file
I use the recipe below to autoreply with file "foo.zip" if asked specifically
for the case-but-not-space-insensitive "send file foo.zip" on the Subject line.
This not only sends the desired file, but, all I have to specify is the
a)directory, b) file name, c) and subject
to repeat for any number of auto-replies.
Plus, it sends a "personalized" header, on top of each file sent, directed
to the recipient (using the recipient's full name if they are company
employees; otherwise, it leaves the full name blank).
However, there are (at least) two enhancements I haven't figured out yet:
QUESTION 1: How to make the request a variable yet preserving case
insensitivity (and adding space insensitivity)?
QUESTION 2: How to add second request without duplicating the whole recipe?
(currently I repeat the whole recipe for file "bar" if asked
"send file bar")
For resolution of question 1 above, I tried setting a variable for the REQUEST:
REQUEST="send file foo.zip"
and then I used, instead of "* $ ^Subject:.*send file foo.zip",
* $ ^Subject:.*$KEYWORD
But, I lost the case insensitivity (and space insensitivity isn't there either).
*******************************************************************
* Does anyone know how to make a case/space insensitive variable? *
*******************************************************************
For the 2nd question, when I need an additional auto-reply recipe, say, for
"send file bar", I simply repeat the filter, changing only the three lines
for the directory, file name, and subject line. I'm sure a case statement
or braces with an if-then-else style syntax would be more appropriate.
************************************************************************
* How can I add other requests without repeating the recipe each time? *
************************************************************************
Despite those 2 (&, I'm sure other ;-) drawbacks, here is what works for me:
MYDIR=/tmp # The directory (sans trailing slash)
MYFILE=foo.zip # The file name
MYSUBJECT="Here it is..." # Any desired additional text
DATE1=`date +%d%h%y` # Info for your personal log file
DATE2=`date +%d%h%y`" at "`date +%T`" "`date +%Z` # Just more info
AUTOLOG=autoreply.log # Logs all requests to the file:
REPLY_TO=`formail -rtzx To:` # Figures internal users' names out
JUSTNAME=`echo $REPLY_TO|/bin/awk -F@ '{print $1}'` # from /etc/passwd
UNAME=`/bin/ypmatch $JUSTNAME passwd|/bin/awk -F: '{print $5}'`
REQUEST=`formail -zx"Subject:"|sed -e 's/ /-/g'` #Munges the request a bit
:0
* $ ^Subject:.*send file foo.zip
* !X-Loop: mholmes(_at_)world(_dot_)std(_dot_)com
* !Subject:.*Re:
* !FROM_DAEMON
{
:0c:myLockFile
| (formail -rt -A "X-Loop: mholmes(_at_)world(_dot_)std(_dot_)com" \
-I "Subject: To $REPLY_TO on $DATE1 Re: $REQUEST --> $MYSUBJECT";\
echo ; echo "$UNAME";\
echo 'On '$DATE2', you ('$REPLY_TO') requested '$REQUEST'.';\
echo "Here is the requested file in $MYDIR";\
echo "File name is '$MYFILE'"; echo; echo; cat $MYDIR/$MYFILE) \
| $SENDMAIL $SENDMAILFLAGS
#
:0
| echo "$DATE2;$REPLY_TO;$JUSTNAME;$UNAME;$REQUEST;$MYFILE" >> $AUTOLOG
}
# Reset any variables that need to be reset since I repeat this for any
# other files such as "send file bar".
REPLY_TO=
REQUEST=
MYDIR=
MYFILE=
MYSUBJECT=
DATE1=
DATE2=
AUTOLOG=
UNAME=
JUSTNAME=
# --------------------------------------------------------------------------