procmail
[Top] [All Lists]

Re: capturing the OR that succeeds ???

2004-05-13 19:26:08
* Dallman Ross <dman(_at_)nomotek(_dot_)com> [2004:05:14:01:41:30+0200] scribed:
On Thu, May 13, 2004 at 11:47:42AM -0500, Michael D Schleif wrote:
Suppose that I have this:

   :0 BD
   * 9876543210^0 aaa
   * 9876543210^0 bbb
   * 9876543210^0 ccc
   * 9876543210^0 ddd
   * 9876543210^0 eee
   {
      :0 fhw
      | formail -I "X-Procmail: alphabet soup"
   
      :0 A
      alphabet/soup
   }

Yes, I am doing this several places, so I made this generic example;
but, it works as is.

However, now I want to identify _which_ condition was satisfied, and
plug that into the X-Procmail line:

   | formail -I "X-Procmail: alphabet soup: $MATCH"

I am confused, and I do not know the simplest way to do this capture?

Use the match token, '\/', before each regex.  Since you start the
matching at the start of the regex, you'll need to quote the match
token to avoid a syntax error.  Thus the empty parenthesis sets below:

     MATCH  # unset this first to avoid contamination from earlier recipes
     :0 BD
     * 9876543210^0 ()\/aaa
     * 9876543210^0 ()\/bbb
     * 9876543210^0 ()\/ccc
     * 9876543210^0 ()\/ddd
     * 9876543210^0 ()\/eee

However, you're still running body greps up to five times on "hit" messages
and all of five times on non-triggering messages.  You can have the same
effect with one pass like so:

  MATCH
  :0 D fw
  * B ?? ()\/(aaa|bbb|ccc|ddd|eee)
  | formail -I "X-Procmail: alphabet soup: $MATCH"

This has also avoided the unnecessary extra recipe you have above.

Thank you, for these insights.

Could this be an improvement?

        MATCH
        :0 BD
        * 9876543210^0 aaa
        * 9876543210^0 bbb
        * 9876543210^0 ccc
        * 9876543210^0 ddd
        * 9876543210^0 eee
        {
            :0 D fhw
            * B ?? ()\/(aaa|bbb|ccc|ddd|eee)
            | formail -I "X-Procmail: alphabet soup: $MATCH"
        
            :0 A
            alphabet/soup
        }


Won't this avoid superfluous condition checks, at least in the
overwhelming majority of cases where *NONE* of the OR'd conditions
succeed?

Yes, those that meet an original OR'd condition are subject to
duplication of effort; but, the real world regexen (e.g., `aaa') are, in
reality much more complex, and longer.

In fact, this is part of my virus/spam checking.  Sometimes, I OR
another regex, and I get many false positives.  Other than re-sending
these fp's through another time, it would be alot nicer if the resulting
headers are self-documented.

Also, your last line suggests, "avoided the unnecessary extra recipe" --
what do you mean?  I want to send *ALL* messages that meet any of the
OR'd conditions to `alphabet/soup'.

What do you think?

-- 
Best Regards,

mds
-
Dare to fix things before they break . . .
-
Our capacity for understanding is inversely proportional to how much
we think we know.  The more I know, the more I know I don't know . . .
--

Attachment: signature.asc
Description: Digital signature

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail