procmail
[Top] [All Lists]

Re: to modify the body

2001-02-27 14:52:34
Michele Cerioni wrote:
I some condition I can receive a mail with an email address in the first
line of the body.

... which he wants to extract for further use. A start might be (untested):

    LP="[-a-z0-9_+.]+"  # local part of address
    DP="[-a-z0-9]+"     # domain part
    ILLEGAL="[^-a-z0-9_+(_at_)]*"

    :0 B
    * $ ^^${ILLEGAL}\/${LP}(_at_)${DP}(\.${DP})
    { ... }

This takes the first address if there's more than one, and there are
probably some more esoteric addresses that it doesn't catch, but
you'll have to judge yourself whether these are real problems in your
case.

      :0 fbwc
      | sed -e 's/michele(_at_)ptnet(_dot_)it/$MATCH/';

Drop the "c" flag, and you'll need double quotation marks so that you
don't replace the address with the literal string "$MATCH", but with
the content of the variable. I'd make that

    :0 fbw
    | sed "s/michele(_at_)ptnet\(_dot_)it/$MATCH/g"

(Note that $MATCH can't contain slashes if it's extracted like I
suggested above; if you choose another way, make sure slashes can't
get into $MATCH, otherwise sed will get confused here.)

      :0 fwhb
      | ( formail -r -I"From: torello(_at_)preplay(_dot_)it" \
                -I"To: michele(_at_)ptnet(_dot_)it" \
                -I"Subject: in TO ci va $MATCH ";  \
        ) \
      | $SENDMAIL -oi -t

The "hb" isn't necessary, but doesn't do any harm either; same for the
semicolon and the parentheses. You have to call formail with -k,
though, to keep the body.

      /dev/null
    }
    /dev/null
}

Huh? Doesn't procmail complain about this in the logfile?

I haven't fully understood what you're trying to accomplish, but if
you want to stop processing the modified copy, one way is to unset the
HOST variable:

    :0 fw
    | formail ... | $SENDMAIL -oi -t

    :0
    { HOST }

In case you also want to keep the original, add a "c" flag to the
entire block (so that you have ":0 Bc").

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

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