[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: procmail regex test utility



Man, you rock! This is just what I wanted ;-)

IMHO, you should commit this in the scripts subdir so that everyone can use 
it.

	Roberto.

Em Quarta 01 Agosto 2001 18:11, # aurelio marinho jargas escreveu:
> i needed today a handy procmail regex test utility to include
> procmail on the txt2regex (http://txt2regex.sf.net) database.
>
> so, i think maybe it will be useful for the procmail folks here test
> the regexes among different texts without the boring
> sending-mail-to-myself task.
>
> THE CODE:
> ------------------------------------------------------------
> #!/bin/bash
> # procmail-re-test
> # 20010801 <verde@conectiva.com.br>
>
> tmpfile=`mktemp /tmp/procmail-re-test.XXXXXX`
> regex="$1"; shift
> txt="$*"; [ "$txt" ] || txt="`cat /dev/stdin`" # $* or stdin
> { echo -e "VERBOSE=y\nLOGFILE=/tmp\nDEFAULT=/dev/null\n:0"
>   echo "* $regex" ; echo /dev/null ; } > $tmpfile
> echo "$txt" | procmail $tmpfile 2>&1 |
> sed -n -e '/^procmail: Invalid regexp/{s/^[^ ]* //p;q}' \
>        -e 's/^procmail: \(\(No m\|M\)atch\) .*/\1/p'
> rm $tmpfile
> ------------------------------------------------------------
>
> THE OUTPUTS (self explanatory):
>
> --------------
> Match
> No match
> Invalid regexp
> --------------
>
>
> USAGE: procmail-re-test regex [text]
>
>
> EXAMPLES:
>
> # cat abc
> one
> two
> three
> four
> # cat abc | ./procmail-re-test '^f'
> Match
> # ./procmail-re-test '^f' < abc
> Match
> # ./procmail-re-test '^f' "`cat abc`"
> Match
> # ./procmail-re-test '^f' `cat abc`
> No match
> # ./procmail-re-test '^f' full
> Match
> # ./procmail-re-test '^f' null
> No match
> # ./procmail-re-test '^(' null
> Invalid regexp "^("
> # ./procmail-re-test 'oo' My cool line
> Match
>
>
> DETAILS:
>
> so, as seen on the examples, the 1st parameter it receives is the
> regex. the text sample is the second (third, ...) argument or missing
> it, it reads the stdin.
>
> have fun.
-
Spamfilter:    spam magnet and regexp collector / blocker
Archive:       http://mail.nl.linux.org/spamfilter/
Website:       http://spamfilter.nl.linux.org/