Kevin Benko <kevin(_at_)efn(_dot_)org> writes:
I need to make a recipe as follows:
:0:
* ^From.*(addy1|addy2|...|addyn)
somefolder
But I would really like to avoid overloading the condition line with a
huge amount '|'-separated addresses.
I was wondering if I could put the addresses (currently about 30) in
an external file and have the condition line grep the external file of
addresses for a match.
If that isn't possible, are there any non-brute-force suggestions that
anyone could offer?
Simply putting all the addresses in the condition line is almost
certainly the fastest and most efficient way to do it as far as the
computer is concerned. If you expect the list to be changing fairly
often or growing much longer and you would like to be able to simply
store the addresses in a file, then the recommended solution is to use
a shell script to generate the recipe from the file of addresses.
For example, you could store the addresses in the file "$HOME/.addresses"
and use the following shellscript to convert it to a recipe:
#!/bin/sh
addresses=$HOME/.addresses
rcfile=$HOME/.procmailrc.from_recipe
while read line; do
case "$line" in
#*) continue;; # handle comments in the .addresses file
esac
c="$c${c+|}$line"
done <$addresses
c="* ^From.*($c)"
len=`echo "$c " | wc -c` # the spaces are to make sure it's
# big enough
echo "# This file was automatically generated by $0 on `date`" \
>$rcfile.new
if test $len -gt 2048; then
echo "LINEBUF=$len" >>$rcfile.new
fi
echo ":0:
$c
somefolder
" >>$rcfile.new
mv $rcfile.new $rcfile
Then, in your main .procmailrc you would simply say:
INCLUDERC = $HOME/.procmailrc.from_recipe
That may seem overly complicated, but once you've set it up, it's fast,
convenient and efficient. You can even put a comment at the top of
the .addresses file saying something like:
# After making changes to this file run the program "whatever"
# to update the actual recipe.
Philip Guenther