Here's some sample code to give people a better idea of what I am trying to
do (it's not pretty). It will parse the email address given as I had
planned, but doesn't actually do any comparisons yet. My primary reason for
wanting to do this is DWIM for the user, where [EMAIL PROTECTED] will
not be disallowed by "*@tobago.*" whose intent is to filter tobago.com,
tobago.net, etc, not prodigy.net.
==================================================CUT FROM HERE
#/usr/bin/perl

# This would actually come from a .cfg file
my $users = "fred\@fsck.com, john\@ted.com, dev\@null.*, weiner\@fred.*";

my $user = shift; # get email from shell - "prog.pl [EMAIL PROTECTED]"

my $valid_tlds =
"[com][gov][org][edu][net][biz][arpa][int][nato][info][name][museum][coop][a
ero][pro][co][mil]";

my $bool = &check_user( $user, $users ); # call sub

sub check_user {
    my $user = shift @_;
    my $blocked_users = shift @_;
    my( @bad_users, $name, $tmp, @cnames, $dn, $tld, $country, $port );
    $blocked_users =~ s/\,\s*/+/g;
    foreach( split /\+/, $blocked_users ) {
        push @bad_users, $_;
    }
    ($name, my $tmp) = split /\@/, $user;
    @cnames = split /\./, $tmp;
    $tld = pop @cnames;
    if( length( $tld ) < 3 ) {
        $country = $tld;
        $tld = pop @cnames;
        if( $valid_tlds !~ /\[$tld\]/ ) {
            $dn = $tld;
            $tld = $country;
        }
    }
    $dn = pop @cnames if !$dn;
    $dn = $tld if !$dn;
    print "NAME: $name\n" if $name;
    print "CNAMES: ", join( '.', @cnames ), "\n";
    print "DOMAIN: $dn\n";
    print "TLD: $tld\n" if defined $tld;
    print "COUNTRY: $country\n" if defined $country;
} # end check_user()
=========================================CUT TO HERE
Each of the @bad_users entries is parsed exactly the same with '*'s replaced
with '.*'s, and then each component would be matched against the
corresponding user component, like so:
$user_tld =~ /^$blocked_tld$/ if $user_tld;
$user_dn =~ /^$blocked_dn$/ if $user_dn;
...
Hope that helps,
Grant M.


_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to