vkhera has asked for the wisdom of the Perl Monks concerning the following question:

I currently use Mail::RFC822::Address to validate email addresses given to us on a web form.

Given that IDN registrations are now being permitted, what do I need to do to accept international domain names?

Am I supposed to convert them to punycode first, then pass them to validate, or do I need a newer validator? Is there a newer one?

Should I store them as IDN or in the punycode form?

Do I use them to send mail in IDN format or punycode format? I use Net::SMTP if that matters.

Thanks for any help and guidance.

  • Comment on international domain names and email validation

Replies are listed 'Best First'.
Re: international domain names and email validation
by CountZero (Bishop) on Dec 02, 2009 at 22:00 UTC
    What makes you think Mail::RFC822::Address cannot deal with e-mail addresses that contain non-ASCII characters?
    use strict; use charnames ':full'; use Mail::RFC822::Address qw(valid); use Encode::Punycode; use Encode; my $email_address = "\N{ARABIC SIGN SALLALLAHOU ALAYHE WASSALLAM}" . ' +@' . "\N{CYPRIOT SYLLABLE TA}" . 'be'; my $puny = encode('Punycode', $email_address); print "$puny\n"; print "That's a valid unicode address\n" if valid($email_address); print "That's a valid Punycode address\n" if valid($email_address);
    Output:
    xn--@be-0we00514a That's a valid unicode address That's a valid Punycode address
    Update: added Punycode representation.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James