| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Email::MIME::RFC2047::Address; | 
| 2 |  |  |  |  |  |  | $Email::MIME::RFC2047::Address::VERSION = '0.97'; | 
| 3 | 4 |  |  | 4 |  | 53802 | use strict; | 
|  | 4 |  |  |  |  | 12 |  | 
|  | 4 |  |  |  |  | 143 |  | 
| 4 | 4 |  |  | 4 |  | 27 | use warnings; | 
|  | 4 |  |  |  |  | 11 |  | 
|  | 4 |  |  |  |  | 170 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | # ABSTRACT: MIME encoded addresses | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 4 |  |  | 4 |  | 39 | use base qw(Email::MIME::RFC2047::Parser); | 
|  | 4 |  |  |  |  | 10 |  | 
|  | 4 |  |  |  |  | 993 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 4 |  |  | 4 |  | 778 | use Email::MIME::RFC2047::Decoder; | 
|  | 4 |  |  |  |  | 12 |  | 
|  | 4 |  |  |  |  | 132 |  | 
| 11 | 4 |  |  | 4 |  | 1279 | use Email::MIME::RFC2047::Group; | 
|  | 4 |  |  |  |  | 12 |  | 
|  | 4 |  |  |  |  | 137 |  | 
| 12 | 4 |  |  | 4 |  | 408 | use Email::MIME::RFC2047::Mailbox; | 
|  | 4 |  |  |  |  | 12 |  | 
|  | 4 |  |  |  |  | 119 |  | 
| 13 | 4 |  |  | 4 |  | 27 | use Email::MIME::RFC2047::MailboxList; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 1485 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | my $domain_part_re = qr/[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?/; | 
| 16 |  |  |  |  |  |  | my $addr_spec_re   = qr{ | 
| 17 |  |  |  |  |  |  | [\w&'*+.\/=?^{}~-]+ | 
| 18 |  |  |  |  |  |  | \@ | 
| 19 |  |  |  |  |  |  | $domain_part_re (?: \. $domain_part_re)+ | 
| 20 |  |  |  |  |  |  | }x; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub parse { | 
| 23 | 36 |  |  | 36 | 1 | 13194 | my ($class, $string, $decoder) = @_; | 
| 24 | 36 | 100 |  |  |  | 110 | my $string_ref = ref($string) ? $string : \$string; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 36 |  |  |  |  | 61 | my $address; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 36 | 100 |  |  |  | 726 | if ($$string_ref =~ /\G\s*($addr_spec_re)\s*/cg) { | 
| 29 | 9 |  |  |  |  | 31 | $address = Email::MIME::RFC2047::Mailbox->new($1); | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  | else { | 
| 32 | 27 |  | 66 |  |  | 144 | $decoder ||= Email::MIME::RFC2047::Decoder->new(); | 
| 33 | 27 |  |  |  |  | 83 | my $name = $decoder->decode_phrase($string_ref); | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 27 | 100 |  |  |  | 568 | if ($$string_ref =~ /\G<\s*($addr_spec_re)\s*>\s*/cg) { | 
|  |  | 100 |  |  |  |  |  | 
| 36 | 17 |  |  |  |  | 50 | my $addr_spec = $1; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 17 |  |  |  |  | 69 | $address = Email::MIME::RFC2047::Mailbox->new( | 
| 39 |  |  |  |  |  |  | address => $addr_spec, | 
| 40 |  |  |  |  |  |  | ); | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 17 | 100 |  |  |  | 59 | $address->name($name) if $name ne ''; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  | elsif ($$string_ref =~ /\G:/cg) { | 
| 45 | 8 | 50 |  |  |  | 36 | return $class->_parse_error($string_ref, 'group name') | 
| 46 |  |  |  |  |  |  | if $name eq ''; | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 8 |  |  |  |  | 20 | my $mailbox_list; | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 8 | 100 |  |  |  | 41 | if ($$string_ref =~ /\G\s*;\s*/cg) { | 
| 51 | 2 |  |  |  |  | 10 | $mailbox_list = Email::MIME::RFC2047::MailboxList->new(); | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  | else { | 
| 54 | 6 |  |  |  |  | 59 | $mailbox_list = Email::MIME::RFC2047::MailboxList->parse( | 
| 55 |  |  |  |  |  |  | $string_ref, $decoder | 
| 56 |  |  |  |  |  |  | ); | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 4 | 50 |  |  |  | 25 | $$string_ref =~ /\G;\s*/cg | 
| 59 |  |  |  |  |  |  | or return $class->_parse_error($string_ref, 'group'); | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 6 |  |  |  |  | 44 | $address = Email::MIME::RFC2047::Group->new( | 
| 63 |  |  |  |  |  |  | name         => $name, | 
| 64 |  |  |  |  |  |  | mailbox_list => $mailbox_list, | 
| 65 |  |  |  |  |  |  | ); | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  | else { | 
| 68 | 2 |  |  |  |  | 10 | return $class->_parse_error($string_ref, 'address'); | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 32 | 50 | 66 |  |  | 138 | if (!ref($string) && pos($string) < length($string)) { | 
| 73 | 0 |  |  |  |  | 0 | return $class->_parse_error($string_ref); | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 32 |  |  |  |  | 210 | return $address; | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | 1; | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | __END__ |