Re: [Evolution] Filtering Incoming e-mail using the Addressbook
- From: Brad Warkentin <brad warkentin rogers com>
- To: Doug Bainbridge <doug_bainbridge onetel net uk>
- Cc: Evolution Mailing List <evolution lists ximian com>
- Subject: Re: [Evolution] Filtering Incoming e-mail using the Addressbook
- Date: Fri, 27 Feb 2004 07:34:37 -0500
Doug Bainbridge wrote:
Is it possible to filter incoming e-mail into a folder by recognising
the sender's e-mail address - without having to specify each address
individually - just by referring to the 'Contacts' addressbook ?
I can't see how the Filter rules might allow you to do this.
You want whitelist filtering... Evolution currently does not do this. A
brute force solution is to pipe all incoming messages to an external
program that extracts the sender and verifies against your address book.
Here is a program I adapted from Cliff Wells:
#!/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);
}
}
}
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 ) {
# print "KEY: $key \nRECORD: \n$record \n";
print "$db_email \n";
untie %address_db;
exit(1);
}
}
}
untie %address_db;
exit(0);
}
cheers,
brad
--
Email: <brad warkentin rogers com>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]