Re: [Evolution] Evo pop3 whitelist - challenge/response



Hi Jeff,

Is anyone aware of a whitelist that will work with Evo (running Pop3)?
TMDA seems to be a good example, but it requires procmail or its
equivalent.  I was looking for an external program or plugin and cannot
find one for the life of me.

I have written an external one in Perl, that can be plugged in as a
filter. It does basic verification against your address book, including
secondary email addresses for contacts. You should be able to use it as
a starting point for what you want. 

If you are running Spamassassin (highly recommended) you can weight
scanned emails by whitelist. 

cheers,
brad

-- 
Brad Warkentin, P.Eng
Email: <brad warkentin rogers com>
Home:  (613) 599-5014
Cell:  (613) 799-5014

--- start whitelist.pl ---

#!/usr/bin/perl
# ------------------------------------------------------------------
# Written by Brad Warkentin (ideas from Cliff Wells python script)
#
# Extracts sender's email address from "From:" line of standard
# email message. Checks if sender is in Evolution's address book.
# Match is case insensitive. Used to do whitelist filtering of
# email messages.
# ------------------------------------------------------------------
# ASSUMPTIONS: 
# 1) Shell variable $home is defined
# 2) Evolution address book is in $home/evolution/share/Contacts
# 3) Addressbook is called "addressbook.db"
#
# INPUT:    standard email message
# OUTPUT:   email address if matched
# RETURNS:  1, if sender is in address book
#           0, if sender is not in address book
# ------------------------------------------------------------------
# USAGE: Define a filter with the following:
# If
# Action:  "Pipe Message to Shell Command" 
# Command: whitelist.pl
# Test:    "Does not return 0"
# Then
# Action:  "Move to Folder"
# Folder:  "some folder name"
# Action:  "Stop Processing"
# ------------------------------------------------------------------

use strict;
use DB_File;

# Scan through email from STDIN
while ( <> ) {
    if ( /From\:/ ) {
        # Hookey attempt at matching most email addresses
        # Will miss some RFC822 compliant addresses
        if (
/([A-Za-z_0-9][\-A-Za-z_0-9.]+[\-A-Za-z_0-9]\@(?:[\w][\-_\w.]+\w)+\.[A-Za-z]{2,7})/ ) {
            # print "Found: $1 \n";
            &whitelist_email($1);
        }
    }
}

# If get here, no valid address was found in email message
exit(0);

sub whitelist_email {
    my $address_book =
$ENV{'HOME'}.'/evolution/local/Contacts/addressbook.db';
    my $email = shift;
    $email = lc($email);
    my %address_db;
    # Tie Berkeley db format addressbook to hash
    tie %address_db, 'DB_File', $address_book;
    my $key;
    my $record;
    # Walk through all records in addressbook
    while ( ($key, $record) = each %address_db ) {
        my @lines = split /^/, $record; 
        my $line;
        # Each record may contain multiple email address... check them all
        foreach $line ( @lines ) {
            $line =~ /EMAIL\;INTERNET\:(.*)/;
            my $db_email;
            chop ($db_email = $1);
            if ( lc($db_email) eq $email ) {
                # Address match found
                # print "KEY: $key \nRECORD: \n$record \n";     
                print "$db_email \n";
                untie %address_db;
                exit(1);
            }
        }
    }
    # Address match not found
    untie %address_db;
    exit(0);
}
        






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]