Mailing List Archive

rmail bang address convertion - comments please
I'm putting the finishing touches to a new rmail command for qmail and I'd
like some opinion on the following ! path conversion code.

! paths have to be converted to FQDNs for qmail. This ! path convertion
routine is particularly lenient on troublesome ! addresses (leastwise from
my collection). Some people view that leniency is only encouraging ongoing
abuse of ! addressing. I can certainly understand that perspective.

Anyway, the following code can be fed ! addresses via stdin so if you have
bang addresses that fail to convert as you'd expect, can you send them to me
please?

For those perl gurus out there, I went for clarify of code rather than
compact, but I'm always willing to do things in a cleaner way.


Regards.


-----------------------------------
#! /usr/local/bin/perl

# OUR_UUCP_NAMES will be stripped from the front of a !path
%OUR_UUCP_NAMES = (
'mira' => 1,
'mira.net.au'=> 1,
);

while (<>) {
chomp;
$newaddr = &convert_bang_address($_);
printf("%-30s %-30s %s\n", $_, $newaddr, ($_ eq $newaddr) ? "unchanged"
: "CHANGED");
}
exit(0);


# Rule 1: While leading ! field matches our uucp name(s) - remove
# Rule 2: If no residual !, exit
# Rule 3: Convert Token!therest to therest@Token
# (But not Token!the@rest)
# Rule 4: While leading ! field matches our uucp name(s) - remove

sub convert_bang_address {

my($addr) = shift;

$addr = $2 while $addr =~ /^([^!]*)!(.*)/ and $OUR_UUCP_NAMES{lc($1)};
# Rule 1.

return $addr if ! $addr =~ /!/;
# Rule 2.

$addr = $2 . '@' . $1 if $addr =~ /^([^!]*)!([^\@]*)$/;
# Rule 3.

$addr = $2 while $addr =~ /^([^!]*)!(.*)/ and $OUR_UUCP_NAMES{lc($1)};
# Rule 4.

return $addr;
}


------------------------------