Richard Damon wrote:
>
>The question is, can a spam filter be set up to check both the From 
>fields and the To/CC fields?


Yes, but it's awkward at best. header_filter_rules are Python regular
expressions that are matched against the entire set of message headers
in MULTILINE and IGNORECASE mode. The awkwardness comes about because
you don't know if the From: precedes or follows the To: or Cc: so you
need to check both possibilities. A regexp like

^From:.*user1@example\.com[^\177]*^(To:|Cc:).*user2@example\.net'

will match a From: header containing us...@example.com followed by a
To: or Cc: header containing us...@example.net.

Note the use of [^\177]* to skip all the intervening headers between
From: and To: or Cc:. [^\177] will match anything that isn't a rubout
(octal 177, hex 7F) including newlines. There should be no rubouts in
email message headers. You can't use .* here because . won't match a
newline, and you can't use (?s) to set 'dot matches all' because that
would allow .*user1@example\.com to match beyond the From: header.

Then you could add a second regexp to the rule

^(To:|Cc:).*user1@example\.com[^\177]*^From:.*user2@example\.net'

to cover the case where the To: or Cc: precedes From: and then add two
more with the roles of user1 and user2 reversed.

You might get away with combining all this into one as

^(From:|To:|Cc:).*(user1@example\.com|user2@example\.net)[^\177]*^(From:|To:|Cc:).*(user1@example\.com|user2@example\.net)'

(all on one line). This would match any From:, To: or Cc: containing
either us...@example.com followed by a From:, To: or Cc: containing
us...@example.net. The drawback of this all in one is it would match a
message From: a 3rd party To: one of the users with Cc: to the other
and would match a message from one of the users with a Cc: to herself.

-- 
Mark Sapiro <m...@msapiro.net>        The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan

------------------------------------------------------
Mailman-Users mailing list Mailman-Users@python.org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-users/archive%40jab.org

Reply via email to