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


In reply to Re: unicode problem with Email::Valid by McA
in thread unicode problem with Email::Valid by natxo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.