[Mimedefang] Using Spamassassin's spamd/c

jmiller at purifieddata.net jmiller at purifieddata.net
Tue Oct 15 14:19:00 EDT 2002


On Tue, 15 Oct 2002 listuser at neo.pittstate.edu wrote:

> On Mon, 14 Oct 2002 jmiller at purifieddata.net wrote:
>
> > Haven't looked into spamd/c much... but I commented on whitelisting...
> >
> > On Mon, 14 Oct 2002 listuser at neo.pittstate.edu wrote:
> >
>
> <snip>
>
> > >
> > > Thanks
> > >  Justin
> > >
> >
> > The short answer on whitelisting, yes, mimedefang can do it.
> >
> > I haven't used the default filter, so I'm not sure if it's already got a
> > provision for this in it, but I added something similar to the following
> > above where I do my spamassassin checks. It'll open two different files
> > (each with one e-mail address per line), one for recipients, one for
> > senders, and if it finds a match, it won't run spamassassin on the
> > message. Please note, though this code should work, it doesn't have all
> > the extra fancy data integrity checks in it, or even checks to make sure
> > it can open the whitelist files. I tried to keep it short so it'd be
> > easier to understand.
> >
> > my $whitelisted;
> > open(RWL,"< /etc/mail/recipient_whitelist");
> > RWLLOOP: while(<RWL>) {
> > 	chomp;
> > 	foreach my $recipient (@Recipients) {
> > 		$recipient =~ s/[<>]//g; # braces not desireable
> > 		if ($recipient =~ /$_/i) {
> > 			whitelisted++; last RWLLOOP;
> > 		}
> > 	}
> > }
> > close(RWL);
> > unless ($whitelisted) {
> > 	open(SWL,"< /etc/mail/sender_whitelist");
> > 	while (<SWL>) {
> > 		chomp;
> > 		if ($Sender =~ /$_/i) {
> > 			$whitelisted++; last;
> > 		}
> > 	}
> > 	close(RWL);
> > }
> > if ( (! $whitelisted) && $Features{SpamAssassin} ) {
> > 	# ... do spam checks
> > } else {
> > 	syslog('warning',"$MsgID: Whitelisted");
> > }
>
> Thanks for the code, Josh!  Things like this should be added to the
> recipes page I think.  They are quite useful IMHO.  Question about the
> whitelist files, what format should they be in?  Can it just be a domain
> or does it have to be a full email address?
>
> Thanks again,
>   Justin
>

fwiw, mimedefang-x.xx/contrib/linuxorg/filter contains a whitelist
feature, using the file "spam-deliver".

If you use the example from above, the format would be a perl compatable
regular expression on each line. How the code and whitelist is built
really depends on the level of flexability you want to have in your
whitelists.
For example, in the stuff above, you'd want to quote stuff that might get
interpreted incorrectly by perl.
If it should match an e-mail of: bob|george at domain.com
a correct whitelist entry would be:
^bob\|george at domain\.com$
	or:
^\Qbob|george at domain.com\E$

A more elaborate parser for the whitelist could be built to allow really
easy whitelist entries including "@domain.com" type stuff, or *'s in the
entry, in just a few minutes.

If you just want to enter plain full e-mail addresses into the whitelist
whithout any escaping, change the following lines:
	if ($recipient =~ /$_/i) {
	if ($Sender =~ /$_/i) {
into:
	if ($recipient =~ /^\Q$_\E$/i) {
	if ($Sender =~ /^\Q$_\E$/i) {

(the \Q and \E mean "quote from here on" and "end quoting")
(the "^" and "$" at begining and end force it to match only when the string
 both begins and ends with that stuff. That way a whitelist for
 "bob at domain.com" doesn't match on "aprilandbob at domain.com")

If you need something to handle the @domain.com entries as well, let me know
and I'll shoot you out some code later tonight. Gotta get back to work now.

--
Josh I.




More information about the MIMEDefang mailing list