Email-Address-List

 view release on metacpan or  search on metacpan

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

        }
        else {
            print $e->{'type'}, "\n"
        }
    }

    # prints:
    # an address: "Foo Bar" <simple@example.com>
    # comment
    # group start
    # an address: a.weird.address@forreal.biz
    # group end
    # unknown
    # an address: more@example.com

=head1 DESCRIPTION

Parser for From, To, Cc, Bcc, Reply-To, Sender and
previous prefixed with Resent- (eg Resent-From) headers.

=head1 REASONING

L<Email::Address> is good at parsing addresses out of any text
even mentioned headers and this module is derived work
from Email::Address.

However, mentioned headers are structured and contain lists
of addresses. Most of the time you want to parse such field
from start to end keeping everything even if it's an invalid
input.

=head1 METHODS

=head2 parse

A class method that takes a header value (w/o name and :) and
a set of named options, for example:

    my @list = Email::Address::List->parse( $line, option => 1 );

Returns list of hashes. Each hash at least has 'type' key that
describes the entry. Types:

=over 4

=item mailbox

A mailbox entry with L<Email::Address> object under value key.

If mailbox has obsolete parts then 'obsolete' is true.

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
key you find name of the group. B<NOTE> that value is not post
processed at the moment, so it may contain spaces, comments,
quoted strings and other noise. Author willing to take patches
and warns that this will be changed at some point without additional
notifications, so if you need groups info then you better send a
patch :)

Groups can not be nested, but one field may have multiple groups or
mix of addresses that are in a group and not in any.

See skip_groups option.

=item group end

Returned when a group ends.

=item comment

Obsolete syntax allows one to use standalone comments between mailboxes
that can not be addressed to any mailbox. In such situations a comment
returned as an entry of this type. Comment itself is under value.

=item unknown

Returned if parser met something that shouldn't be there. Parser
tries to recover by jumping over to next comma (or semicolon if inside
group) that is out quoted string or comment, so "foo, bar, baz" string
results in three unknown entries. Jumping over comments and quoted strings
means that parser is very sensitive to unbalanced quotes and parens,
but it's on purpose.

=back

It can be controlled which elements are skipped, for example:

    Email::Address::List->parse($line, skip_unknown => 1, ...);

=over 4

=item skip_comments

Skips comments between mailboxes. Comments inside and next to a mailbox
are not skipped, but returned as part of mailbox entry.

=item skip_not_ascii

Skips mailboxes where address part has not ASCII characters.

=item skip_groups



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