procmail
[Top] [All Lists]

Re: testing for only the subject and the body

1997-06-12 15:21:00
Robert Brown, as I understand, wants to test for this:

(("foo" in subject) or ("foo" in body)) and \
               (("bar" in subject) or ("bar" in body))

Both "foo" and "bar" must be present, and they must be in the subject or the
body; if they're in any other header lines they don't count, but it's all
right if one is in the subject and the other is in the body.

Robert, if I've misunderstood, please inform me, because that's the question
I'm going to answer.

 :0HB
 * ^^(.+$)*(Subject:|$(.*$)*).*foo
 * ^^(.+$)*(Subject:|$(.*$)*).*bar
 action

Logic:

HB -- examine entire text
^^ -- from start of search area
(.+$)* -- allow zero or more non-empty lines (i.e., stay in the head)
(Subject:| -- and then in the subject header or
 $(.*$)*)  -- after an empty line (i.e., into the body) and zero or
              more lines, empty or non-empty (i.e., anywhere in the body),
.* -- perhaps some characters away from the left margin [if in the body]
      or away from the colon [if in the Subject: header]
foo -- find "foo".

Because "foo" (or "bar" in the second condition) must be preceded by either
an empty line [so that it counts only in the body] or, if there was no empty
line, by Subject: at the beginning of its line, it will not count if it ap-
pears elsewhere in the head.

Here's another approach, which I think is self-explanatory:

 :0
 * 10^0 ^Subject:.*foo
 * 10^0 B ?? foo
 * 1^0 ^Subject:.*bar
 * 1^0 B ?? bar
 {
   SCORE = $=
  
   :0 flags # if $SCORE is 11, 12, 21, or 22 (but not 0, 1, 2, 10, nor 20)
   * SCORE ?? [12][12]
   action
 }