procmail
[Top] [All Lists]

Re: testing for only the subject and the body (was Re: Testing for alternate Environment variables)

1997-06-13 00:23:00
On Thu, 12 Jun 1997 11:45:23 -0700, dummy(_at_)cyberpass(_dot_)net (Robert)
wrote:
With experimentation, I cannot get this to work.  I'd like to match both
"foo" and "bar" only if they're on the subject line or somewhere in the
body.  I don't want to do:

:0HB:
*foo
*bar
folder

because "foo" or "bar" may occur somewhere else in the header (which I'm
not interested in).

And I'd prefer not to do:
<...>

Here's an alternate solution: trim it down to only the stuff you
specifically want to search and then search on that:

    :0fh
    | formail -XSubject:

    :0HB:
    * foo
    * bar
    folder

This becomes a bit complicated if you have other recipes after this
one which again have to search the whole header. If you generate a
duplicate for this snippet, you will have to figure out how to get rid
of it if this matches. Off the top of my head, the best solution I can
think of is perhaps to put this in a separate .rc file and feed the
message into a second procmail. The file would then end with something
like

    EXITCODE=1

if the search didn't match. 
  I feel stupid. Can somebody come up with a better solution?

... except of course perhaps

    :0:
    * ? formail -k -XSubject: | search-for-em foo bar
    folder

I almost wrote | fgrep foo | fgrep bar but unfortunately, it's not
quite that simple. (BOY do I feel stupid today. :-) If you can live
with an invocation of Perl for each message received, this should do:

    :0:
    * ? formail -k -XSubject: | \
        perl -0777 -ne 'exit 1 unless (/foo/ and /bar/)'
    folder

It can probably be coded with tr and sed or awk instead of Perl, but
don't ask me about that right now. Thank you.

Hmm. Anyway, hope this helps,

/* era */

-- 
Defin-i-t-e-ly. Sep-a-r-a-te. Gram-m-a-r.  <http://www.iki.fi/~era/>
 * Enjoy receiving spam? Register at <http://www.iki.fi/~era/spam.html>

<Prev in Thread] Current Thread [Next in Thread>