procmail
[Top] [All Lists]

Re: Catting a nastygram at the top of the body

1997-10-08 11:55:24
Ken Hooper asked,

| I actually had this sort-of-working at one point although I've forgotten
| exactly how it was before I caused the mail loop. ;)
| 
|       :0 f
|       * ! ^TOwebmaster(_at_)type2(_dot_)com
|       * ! ^X-Loop: webmaster(_at_)bigkitty(_dot_)azaccess(_dot_)com
|       | (formail -i"From: Mail_Filter(_at_)type2(_dot_)com"\
|       -kbrtA"X-Loop: webmaster(_at_)bigkitty(_dot_)azaccess(_dot_)com" ;)\
|       | $SENDMAIL -t
| 
| Procmail complains about an undefined variable. Why?
| 
|       procmail: Executing " (formail -i"From: 
Mail_Filter(_at_)type2(_dot_)com"\
|        -kbrtA"X-Loop: webmaster(_at_)bigkitty(_dot_)azaccess(_dot_)com" ;)\
|       | $SENDMAIL -t"
|       TERM: Undefined variable.

Because
(1) your .procmailrc has SHELL set to csh or a derivative OR
(2) your .procmailrc doesn't set SHELL, so procmail checks /etc/passwd
    for your login shell, and it's csh or a derivative,

and your .cshrc calls a program that needs a TERM assignment; since the
process is non-interactive, TERM is undefined, and the program complains.
Perhaps previously you had a recipe that did not call a shell, or you
had a SHELL assignment to sh (or something sh-compatible) in your
.procmailrc.

Solution: SHELL=/bin/sh at the top of your .procmailrc.
Second-best solution: put the command that needs TERM into your .login
  instead of your .cshrc.

Another suggestion: leave a space before the continuation backslash in
a long action line.   ")\" on the second line of that long action will
be harmless, but laying the backslash up against the quote with no space
between them on the first line can cause trouble.

Third one: you have the filter flag on a recipe that doesn't write to stdout.
Thus it replaces your message text with nothing, and after mailing out the
autoresponse likely ends up delivering "From foo(_at_)bar [timestamp]" with no
other headers and no body to $DEFAULT.

Fourth, the periods in your regexps are intended literally, so it's a good
idea to escape them.

| Then I want to cat spambounce.txt to the *top* of the body. How do I do
| that?

With a different approach, since that cannot easily be done in the middle of
your current pipe (where it would have to go).  Change "path/to/spambounce.txt"
to either a relative path to it from $MAILDIR or an absolute path:

# Modify the head as before, and append spambounce after the head's closing
# blank line (so that it becomes the top of the body).  Note that -b is no
# longer needed as we are feeding only the head to formail -r and keeping
# the body aside to be reattached after the filter; neither is -k, but it
# might make you feel better and will make sure that the blank line is pre-
# served in case you ever modify the formail options to include a -x or -X:

        :0 fhw
        * ! ^TOwebmaster(_at_)type2\(_dot_)com
        * ! ^X-Loop: webmaster(_at_)bigkitty\(_dot_)azaccess\(_dot_)com
        | formail -i"From: Mail_Filter(_at_)type2(_dot_)com" \
          -rtkA"X-Loop: webmaster(_at_)bigkitty(_dot_)azaccess(_dot_)com" && \
          cat path/to/spambounce.txt
        
        :0a
        ! -t

One can also prepend a file to the body the common-sense way:

        :0bfw
        | cat file -

but here we are already filtering the head anyway to invert it for reply.

<Prev in Thread] Current Thread [Next in Thread>