in reply to unicode problem with Email::Valid

Hi,

the problem is that the from address is an email header part. And in a header only ASCII is valid. That's the reason why only ASCII encoded strings can be valid. Therefore the word containing the non-ascii character é is encoded as =?iso-8859-1?Q?Jos=E9_Name?=.

When you take this byte string into the validation routine everything is fine. So, IMHO, the solution must be that you encode the unicode string representing the email address in a valid ascii representation.

#!/bin/perl use strict; use warnings; use 5.010; use Email::Valid; use Data::Dumper; use Encode qw(encode decode); my $utf8_from = decode('UTF-8', 'José <J.name@web.de>'); my $from = encode('MIME-Header', $utf8_from); say "Mail: $from"; my $validator = Email::Valid->new(); if(my $addr = $validator->address( $from )) { say "OK: ", Dumper($addr); } else { say "Not valid"; }

Regards
McA

Replies are listed 'Best First'.
Re^2: unicode problem with Email::Valid
by natxo (Scribe) on Jul 07, 2014 at 13:52 UTC
    yes! thanks for the explanation, it makes perfect sense.