Email-Address-List

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


        If address (not display-name/phrase or comments, but
        local-part@domain) contains not ASCII chars then 'not_ascii' is set
        to true. According to RFC 5322 not ASCII chars are not allowed
        within mailbox. However, there are no big problems if those are used
        and actually RFC 6532 extends a few rules from 5322 with
        UTF8-non-ascii. Either use the feature or just skip such addresses
        with skip_not_ascii option.

        Whitespace and Unicode format characters (category "\p{Cf}": ZERO
        WIDTH SPACE, ZWJ, ZWNJ, BOM, soft hyphen, bidi marks, etc.) are
        stripped from "local-part" and "domain". Such characters are
        typically introduced by copy/paste; left in, they produce
        undeliverable mail. Stripping does not apply inside quoted
        local-parts (their contents are preserved literally), nor to the
        display-name or comments.

    group start
        Some headers with mailboxes may contain groupped addresses. This
        element is returned for position where group starts. Under value key
        you find name of the group. NOTE that value is not post processed at

lib/Email/Address/List.pm  view on Meta::CPAN


If address (not display-name/phrase or comments, but
local-part@domain) contains not ASCII chars then 'not_ascii' is
set to true. According to RFC 5322 not ASCII chars are not
allowed within mailbox. However, there are no big problems if
those are used and actually RFC 6532 extends a few rules
from 5322 with UTF8-non-ascii. Either use the feature or just
skip such addresses with skip_not_ascii option.

Whitespace and Unicode format characters (category C<\p{Cf}>:
ZERO WIDTH SPACE, ZWJ, ZWNJ, BOM, soft hyphen, bidi marks, etc.)
are stripped from C<local-part> and C<domain>. Such characters
are typically introduced by copy/paste; left in, they produce
undeliverable mail. Stripping does not apply inside quoted
local-parts (their contents are preserved literally), nor to the
display-name or comments.

=item group start

Some headers with mailboxes may contain groupped addresses. This
element is returned for position where group starts. Under value

t/invisible-chars.t  view on Meta::CPAN

use Test::More;
use Email::Address::List;

# An addr-spec (local-part@domain) should never contain
# whitespace or invisible format characters. They sneak in via
# copy/paste and produce undeliverable mail.
#
# Test the following:
#   - ASCII whitespace (space, tab, ...)
#   - Unicode whitespace (NBSP, EM SPACE, IDEOGRAPHIC SPACE, ...)
#   - Unicode format characters \p{Cf} (ZWSP, ZWJ, ZWNJ, BOM,
#     soft hyphen, bidi marks, ...)

sub addr_of {
    my $line = shift;
    my @list = Email::Address::List->parse($line);
    return undef unless @list == 1 && $list[0]{type} eq 'mailbox';
    return $list[0]{value}->address;
}

# name => character. Mix of Unicode general categories \p{Z}

t/invisible-chars.t  view on Meta::CPAN

    [ 'U+2003 EM SPACE'        => "\x{2003}" ],
    [ 'U+202F NARROW NBSP'     => "\x{202F}" ],
    [ 'U+3000 IDEOGRAPHIC SP'  => "\x{3000}" ],
    [ 'U+00AD SOFT HYPHEN'     => "\x{00AD}" ],
    [ 'U+200B ZERO WIDTH SP'   => "\x{200B}" ],
    [ 'U+200C ZWNJ'            => "\x{200C}" ],
    [ 'U+200D ZWJ'             => "\x{200D}" ],
    [ 'U+200E LRM'             => "\x{200E}" ],
    [ 'U+200F RLM'             => "\x{200F}" ],
    [ 'U+2060 WORD JOINER'     => "\x{2060}" ],
    [ 'U+FEFF ZWNBSP / BOM'    => "\x{FEFF}" ],
);

# Each character, in every position around or inside the addr-spec.
for my $case (@cases) {
    my ($name, $char) = @$case;

    is addr_of("foo\@example.com$char"), 'foo@example.com',
        "trailing $name stripped";

    is addr_of("${char}foo\@example.com"), 'foo@example.com',



( run in 1.162 second using v1.01-cache-2.11-cpan-9581c071862 )