Discussion:
[maildropl] Ability to match against message body using lookup()
Darren Spruell
2013-10-04 20:51:57 UTC
Permalink
Greetings,

I have a use case where I have short but growing list of patterns I'd
like to match against for filtering. I'd like the matches to be limited
to the Subject header and message body (but no other headers). I also
like the capability lookup() provides to stash patterns in a file (with
comments/etc.). I can see from the documentation that matching against a
concise expression (e.g. $MATCH1 from a header match) using lookup() is
easy, but how can you handle an expressions that matches against the
message body generally? Is it valid/correct to do something remotely
like this?

if ( /^Subject:\s*(.*)/ && lookup( $MATCH1, "interesting.dat" ) ||
lookup( //:b, "interesting.dat" ) )
{
# Do stuff
}
--
DS
Sam Varshavchik
2013-10-04 23:42:23 UTC
Permalink
Post by Darren Spruell
Greetings,
I have a use case where I have short but growing list of patterns I'd
like to match against for filtering. I'd like the matches to be limited
to the Subject header and message body (but no other headers). I also
like the capability lookup() provides to stash patterns in a file (with
comments/etc.). I can see from the documentation that matching against a
concise expression (e.g. $MATCH1 from a header match) using lookup() is
easy, but how can you handle an expressions that matches against the
message body generally? Is it valid/correct to do something remotely
like this?
if ( /^Subject:\s*(.*)/ && lookup( $MATCH1, "interesting.dat" ) ||
lookup( //:b, "interesting.dat" ) )
{
# Do stuff
}
The only way to do a full-body scan would be something like this:

foreach /.*/:b
{
if (lookup($MATCH, "interesting.dat"))
{



Body lookups will get done one line at a time. This will be slow, but, for
personal use, and not overly large mail, this should be fine; but you'll
want to make sure that you're running the current version of maildrop, which
properly MIME-decodes message bodies, before matching them.
Darren Spruell
2013-10-05 01:15:04 UTC
Permalink
Post by Darren Spruell
Greetings,
I have a use case where I have short but growing list of patterns
I'd like to match against for filtering. I'd like the matches to
be limited to the Subject header and message body (but no other
headers). I also like the capability lookup() provides to stash
patterns in a file (with comments/etc.). I can see from the
documentation that matching against a concise expression (e.g.
$MATCH1 from a header match) using lookup() is easy, but how can
you handle an expressions that matches against the message body
generally? Is it valid/correct to do something remotely like
this?
if ( /^Subject:\s*(.*)/ && lookup( $MATCH1, "interesting.dat" )
|| lookup( //:b, "interesting.dat" ) ) { # Do stuff }
foreach /.*/:b { if (lookup($MATCH, "interesting.dat")) { …
Body lookups will get done one line at a time. This will be slow,
but, for personal use, and not overly large mail, this should be
fine; but you'll want to make sure that you're running the current
version of maildrop, which properly MIME-decodes message bodies,
before matching them.
Thanks! I'll give this is a shot and see how it works.

DS

Loading...