Thanks to all of those that responded.
Based upon all of the ideas, I came up with the following code to do the trick.
-Rich
sub filter_begin () {
...
%lists = &get_lists();
}
#*********************************************************************** # %PROCEDURE: get_list # %ARGUMENTS: # None # %RETURNS: # Array of lists on the system # %DESCRIPTION: # This function fills an array with the names of all of the mailing # lists on the system. #*********************************************************************** my %lists = ();
sub get_lists { return (%lists) if (%lists); open (LISTS, "/var/mailman/bin/list_lists -b|") or die "Could not execute '/var/mailman/bin/list_lists -b'.\n"; while (<LISTS>) { chop; $lists{$_} = 1; } close(LISTS); return (%lists); } #*********************************************************************** # %PROCEDURE: is_list # %ARGUMENTS: # listname -- the name of the mailing list # %RETURNS: # boolean - positive if the recipient matches a list name. # %DESCRIPTION: # This function matches the incoming mailing address with a list name. # We do not scan the contents of mailing lists as spam. #*********************************************************************** sub is_list { my($listname) = shift; ## ## The email address, as it comes in, is surrounded by ## brackets. We have to massage it a little in order to do ## proper matching. eg: '<[EMAIL PROTECTED]>' needs to be 'test'. ## $listname = (split("\@", $listname))[0]; $listname = (split("\<", $listname))[1]; return ($lists{lc($listname)}); }
sub filter_end ($) { my($entity) = @_; ... if ($RelayAddr eq "127.0.0.1" or $RelayAddr eq "my.ip.address.com") { md_graphdefang_log('mail_out',,$RelayAddr); } else { # Do not scan any messages going to any of the mailing lists. foreach $recipient (@Recipients) { if (&is_list($recipient)) { md_graphdefang_log('mail_in', , $RelayAddr); md_graphdefang_log('mailing_list', $hits, $RelayAddr); return; } }
Steffen Kaiser wrote:
On Thu, 8 Jul 2004, Rich West wrote:
Hmm, I'd populate a global variable when the slave starts or in filter_initialize. I do so, anyway.
sub is_list { $listname = (split("\@", $listname))[0]; $listname = (split("\<", $listname))[1];
^^^^ Angle brackets are not mandatory.
foreach $list (@lists) { chop($list); return 1 if ($list =~ /^$listname/i);
^^^^^ here you check only, if the recipient begins with a name of a list.
} return 0; }
BTW: How about preparing the name cache a bit more in order to avoid the foreach loop each time you lookup a name, e.g.
1) use a hash: %mailists = ( 'list1' => 1 , 'list2' => 1, ... ); Then you can do simply return $mailists{lc($listname)}
2) or use a large string: $mailists = '@[EMAIL PROTECTED]@[EMAIL PROTECTED]@'; then do: return index($mailists, '@' . lc($listname) . '@') >= 0; (Because '@' is never part of listname, it's save.)
Bye,
_______________________________________________ Visit http://www.mimedefang.org and http://www.canit.ca MIMEDefang mailing list [EMAIL PROTECTED] http://lists.roaringpenguin.com/mailman/listinfo/mimedefang