procmail
[Top] [All Lists]

Re: Procmail filters based on subject- but read from a file

2000-11-22 23:58:46
PSE-L(_at_)mail(_dot_)professional(_dot_)org (Professional Software 
Engineering) writes:
...
Additionally, there is no per-string regexp capability (I don't believe you 
can specify a string in the text file with a regexp, so you can't match 
something like "low (toner|printer|fax) prices" as a subject line and have 
it interpret that as anything but a static string - I realize here, I use 
fgrep, but I believe the same holds true for plain grep as well).

I'm not sure what you're trying to say there.  I do know that you can
put regexps in the file that you pass to grep/egrep with the -f flag.
As for the other way, treating the subject as a regexp to match against
a given file, well, just put the subject on grep's command line:

        :0
        * ? egrep -e "`formail -zxSubject:`" file-to-search
        { whatever... }


The rule itself is quite simple:

:0
* $? $FORMAIL -xSubject: | $FGREP -i -f $PMDIR/junksubjects.dat
$MAILDIR/junksubjects

Arg!  Lose that leading '$', please!  The command given after the '?'
is being passed to shell (after all, it has a '|').  The shell will
perform variable expansions before executing the command.  If the
command did not require a shell to be executed, procmail itself would
perform variable and command expansion before doing the fork/exec.  It
may seem harmless to leave it in, but that's only true as long as no
quoting is being done and all the variables involved are guaranteed to
be free from shell metacharacters.  That's true for the above, but that
doesn't make it right.  It just makes it a bad habit.


...
$FORMAIL points to the formail executable, $FGREP points to a grep (doesn't 
have to be fgrep tho for this example), $PMDIR is the procmail dir (where 
recipe and other support files are).

I strongly advise that you not hardcode paths to executables: the shell
(and procmail) both use the PATH if you let them.  It's clearer and
less like to break if you just use the bare command name:

        :0
        * ? formail -xSubject: | fgrep -i -f $PMDIR/junksubjects.dat
        $MAILDIR/junksubjects


Philip Guenther
_______________________________________________
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>