procmail
[Top] [All Lists]

Re: newbie question about autoreply (vacation) subject line

2003-05-27 11:58:41
At 12:49 2003-05-27 -0500, C. Wilson wrote:

I've been messing around with "formail" with little success. Could someone kindly help me out or point me to some good documentation.

formail is documented in 'man formail'. However, you cannot extract a header and rewrite it's contents in one invocation of formail.


:0
# Perform a quick check to see if the mail was addressed to us
# (specifically, DIRECTLY to us, not Bcc: like a mailing list, or simply
# Cc: (for informational/filing purposes)
* $^To:.*\<$\LOGNAME\>
# Don't reply to daemons and mailinglists
* !^FROM_DAEMON
# Mail loops are evil
* !^X-Loop: furball(_at_)kitty(_dot_)com
{
        # note addition of bracing level, and that the flags are down on
        # the formail invocation, rather than the preceeding level of
        # conditions.  This means the whole lot of this recipe is dependant
        # upon the above conditions - althought the 'e' flag on the second
        # part implies this, the bracing makes it pretty explicit, and much
        # easier to visualize when working with the recipe later.

        :0 Whc: vacation.lock
        | /usr/bin/formail -rD 8192 vacation.cache

        # if the name was not in the cache
        :0 e
        {
                # extract the subject (I actually do this, and other headers,
                # in advance of all my regular recipes, so that it is
                # available to all recipes without special work)
                :0
                * ^Subject:[    ]*\/[^  ].*
                {
                        SUBJECT=$MATCH
                }

                :0c
                | (/usr/bin/formail -rI"Precedence: junk" \
                        -I"Subject: Autoreply To: $SUBJECT" \
                        -A"X-Loop: mneuman(_at_)cooketech(_dot_)net" ; \
                        cat /home/mneuman/info.txt ) \
                        | $SENDMAIL -oi -t -f furball(_at_)kitty(_dot_)com
        }
}


Note that if your user isn't a "trusted user" according to the MTA (such as Sendmail), using -f to change the sender will result in a X-Authentication-Warning: header being added to the message (unless the MTA config has this disabled).

Also, your recipe had "/usr/lib/sendmail" for the delivery action - you should use $SENDMAIL - if $SENDMAIL isn't properly defined (and you can't recompile procmail properly), then you should redefine it to the necessary path, but you should still continue to use $SENDMAIL (it's what is used for ! forward operations as well). It is sometimes useful to redefine $SENDMAIL -- my sandbox config (see my .sig), redefines it to run a local shell script so that when testing, mail isn't actually sent (which could be a PITA to whomever it is getting addressed), but is instead dumped into a file where you can confirm what your script would have been sending (which, BTW, would be an excellent way to test your current script).

You could use $HOME instead of /home/mneuman, which would make your recipe that much more portable. As a rule, I put autoreply texts into a subdir from my (extensive) procmail recipes, and actually define a path elsewhere in the procmailrc file:

        # directory for procmail files (separate from maildir)
        # (my definition, not a procmail one)
        PMDIR=$HOME/.procmail

        # directory for auto-reply bodies
        # (my definition, not a procmail one)
        AUTOREPLY=$PMDIR/auto-reply

When your procmail use eventually climbs, you'll appreciate putting everything in its own place - it will help to keep things self-documenting, and will reduce clutter.

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail