On Fri, 5 Dec 1997 16:34:48 -0500 (EST), Bishop & Bebe
<beck(_at_)tiac(_dot_)net>
wrote:
REMOVE = `formail -rzx "From:"`
^^^^^^^
You specifically want "To:" here. The FAQ explains why.
<http://www.iki.fi/~era/procmail/mini-faq.html>
:0 c
| (sed -n /$REMOVE/d .address > $HOME/temp_file \
mv tempfile .address) ;\
What's the final semicolon and backslash for? You need a semicolon
near the end of the +first+ line though -- the function of the
backslash is to glue everything together on one happy long line,
yielding something like
| ( sed -n /$REMOVE/d .address > $HOME/temp_file mv tempfile .address) ;
The parentheses are also not necessary, and note that you are using
different names for the temp file. Finally, you should use either a
unique temp file name, or make sure no two Procmails are writing the
temp file at the same time (i.e. a lock file). We might end up with
something like
TMP=/tmp/$$.remove
:0c:$TMP$LOCKEXT
| sed -n "/$REMOVE/d" .address > $TMP ; mv $TMP .address
In principle, it would be prudent to attempt to backslash-escape any
regex special characters in REMOVE before giving it to sed, and
perhaps anchor it. Here's something for that (the usual kudos to David
Tamkin) -- put this before the above recipe and then give $SAFEREMOVE
instead of $REMOVE to sed:
# $\REMOVE produces a suitably backslash-escaped expression
# for Procmail's own use, but it's not directly usable in sed
# because sed's palette of special characters is different from
# Procmail's. Some of this can be remedied by removing the
# leading empty parentheses that $\REMOVE will always have.
# In this case, REMOVE will never contain round parens
# (formail will have stripped away any parentheses as they are
# comments according to RFC822) so we don't have to look for
# those, and sed should be able to cope with a spurious backslash
# before any plus character (+ is not a regex operator in traditional
# sed implementations) ... there can be other cases I've overlooked.
FIRST="$\REMOVE"
:0
* FIRST ?? ^^\(\)\/.*
{ SAFEREMOVE="^$MATCH$" }
# Now you can use $SAFEREMOVE in place of $REMOVE -- other than
# that, you can use the above recipe
In practice, merely anchoring the regex (say "/^$REMOVE"'$/d' instead
of /$REMOVE/d -- the double quotes are also a good safety measure
against the shell interpreting the brokets in <era(_at_)iki(_dot_)fi> as
redirection operators ;^) might be enough, unless you expect to see
addresses with asterisks or square brackets in them (other regex
metacharacters such as question mark are also not special to classic
sed). (But better safe than sorry -- e.g.
postmaster(_at_)[127(_dot_)0(_dot_)0(_dot_)1] is a
valid address which will not work correctly unless you quote the
square brackets, because sed would interpret [127.0.0.1] as the
equivalent of the regex character class [0127.] i.e. any one of these
five characters, and always exactly one character; note that the
opening bracket is missing from the set of characters that match.)
Hope this helps,
/* era */
--
Paparazzi of the Net: No matter what you do to protect your privacy,
they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>