procmail
[Top] [All Lists]

CONTRIB procmail regex test cmdline utility

2001-08-01 23:05:38
hi,

i'm not a subscriber of the list but i think maybe some of you
would be interested.

i needed today a handy procmail regex test utility to include
procmail on the txt2regex (http://txt2regex.sf.net) database.

i've readed some FAQs and ML archive but i've not found nothing
handy like a command line utility or --option

so i've made one based on the jari aalto's dry run test
(http://www.procmail.org/jari/pm-tips-body.html), but clean
executable and using only a temporary file.

it's useful to do fast regexes tests among different texts
without the boring sending-mail-to-myself task.

(it's a 1/2 hour hack, so i'm accepting corrections/improvements)
&:)


THE CODE:
------------------------------------------------------------
#!/bin/bash
# procmail-re-test
# 20010801 <verde(_at_)conectiva(_dot_)com(_dot_)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.




-- 
s·:(·>(·×^a]×http://www.verde666.org×^[:wq


_______________________________________________
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>
  • CONTRIB procmail regex test cmdline utility, # aurelio marinho jargas <=