Email::Address::List(3pm) | User Contributed Perl Documentation | Email::Address::List(3pm) |
Email::Address::List - RFC close address list parsing
use Email::Address::List; my $header = <<'END'; Foo Bar <simple@example.com>, (an obsolete comment),,, a group: a . weird . address @ for-real .biz ; invalid thingy, < more@example.com > END my @list = Email::Address::List->parse($header); foreach my $e ( @list ) { if ($e->{'type'} eq 'mailbox') { print "an address: ", $e->{'value'}->format ,"\n"; } 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
Parser for From, To, Cc, Bcc, Reply-To, Sender and previous prefixed with Resent- (eg Resent-From) headers.
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.
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:
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.
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.
It can be controlled which elements are skipped, for example:
Email::Address::List->parse($line, skip_unknown => 1, ...);
Ruslan Zakirov <ruz@bestpractical.com>
Under the same terms as Perl itself.
2022-12-07 | perl v5.36.0 |