Re: Implementing Mail::SRS in MIMEDefang

Mark <[email protected]> Sun, 03 Oct 2004 17:48:22 GMT
Newsgroups gmane.mail.spam.srs.general
Organization Asarian-host
Message-ID <[email protected]>
Michael Faurot wrote:

> But if I deliberately use a malformed SRS address (as a spammer would
> presumably do), then Mail::SRS causes my MIMEDefang slave process
> to die with the following error:
>
> Oct  2 17:50:49 mail mimedefang-multiplexor[393]: Slave 1
> stderr: Parse error in `SRS0+YYpR7b=MV=atww.org=mfaurot':
> Invalid hash at /usr/local/share/perl/5.6.1/Mail/SRS/Shortcut.pm
> line 86.
>
> Looking around further, I see lots of use of 'die' in these modules.
> This presents a problem when trying to integrate Mail::SRS into a
> larger system.  I need a return code of some type to tell me whether a
> particular address is invalid--not have the module terminate my
> program.
>
> Please advise how I should implement validation and address reversal
> using $srs->reverse(), without it terminating my programs.

The "die" statements are quite the standard way of doing things in Perl
modules. So this is actually really a Perl question.

At any rate, you should enclose SRS calls in an 'eval' function, which will
return undef upon die. Like so:

if (eval {$_ = $srs -> reverse ($to)}) {
    print "Reversed SRS address is $_\n";
}

Watch out for pitfalls like these:

if (eval {my $address = $srs -> reverse ($to)}) {

As the lexical scope of "my $address" is limited to within the eval
construct. What you want then, is this:

my $address;
if (eval {$address = $srs -> reverse ($to)}) {

And you'll be fine.

- Mark

        System Administrator Asarian-host.org

---
"If you were supposed to understand it,
we wouldn't call it code." - FedEx