| 1 | package Email::MIME::RFC2047::Mailbox; | ||||||||||||||||||||||||||||
| 2 | 4 | $Email::MIME::RFC2047::Mailbox::VERSION = '0.96'; | |||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Handling of MIME encoded mailboxes | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use base qw(Email::MIME::RFC2047::Address); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Email::MIME::RFC2047::Decoder; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Email::MIME::RFC2047::Encoder; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | my $domain_part_re = qr/[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?/; | |||||||||||||||||||||||||||
| 14 | 4 | my $addr_spec_re = qr{ | |||||||||||||||||||||||||||
| 15 | [\w&'*+.\/=?^{}~-]+ | ||||||||||||||||||||||||||||
| 16 | \@ | ||||||||||||||||||||||||||||
| 17 | $domain_part_re (?: \. $domain_part_re)+ | ||||||||||||||||||||||||||||
| 18 | }x; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub new { | ||||||||||||||||||||||||||||
| 21 | 65 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 65 | my $self; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 65 | ▶ | if (@_ >= 2) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 26 | 35 | $self = { @_ }; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | elsif (ref($_[0])) { | ||||||||||||||||||||||||||||
| 29 | 16 | $self = $_[0]; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | else { | ||||||||||||||||||||||||||||
| 32 | 14 | $self = { address => $_[0] }; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 65 | return bless($self, $class); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub parse { | ||||||||||||||||||||||||||||
| 39 | 30 | ▶ | my ($class, $string, $decoder) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 30 | ▶ | my $string_ref = ref($string) ? $string : \$string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 30 | my $mailbox; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 30 | ▶ | if ($$string_ref =~ /\G\s*($addr_spec_re)\s*/cg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 5 | $mailbox = $class->new($1); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||||||||||
| 48 | 25 | ▶ | $decoder ||= Email::MIME::RFC2047::Decoder->new(); | ||||||||||||||||||||||||||
|
Condition66%2/3
$decoder ||= "Email::MIME::RFC2047::Decoder"->new
MC/DC0%0/2
$decoder ||= "Email::MIME::RFC2047::Decoder"->new
$decoder
"Email::MIME::RFC2047::Decoder"->new
Truth table66%2/3
A ||= B
A= $decoderB= "Email::MIME::RFC2047::Decoder"->new
| |||||||||||||||||||||||||||||
| 49 | 25 | my $name = $decoder->decode_phrase($string_ref); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 25 | ▶ | $$string_ref =~ /\G<\s*($addr_spec_re)\s*>\s*/cg | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | or return $class->_parse_error($string_ref, 'mailbox'); | ||||||||||||||||||||||||||||
| 53 | 18 | my $addr_spec = $1; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 18 | $mailbox = $class->new(name => $name, address => $addr_spec); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 23 | ▶ | if (!ref($string) && pos($string) < length($string)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not ref $string and pos $string < length $string
MC/DC0%0/2
not ref $string and pos $string < length $string
not ref $string
pos $string < length $string
Truth table66%2/3
not(A) and B
A= not ref $stringB= pos $string < length $string
| |||||||||||||||||||||||||||||
| 59 | 0 | return $class->_parse_error($string_ref); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 23 | return $mailbox; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub name { | ||||||||||||||||||||||||||||
| 66 | 19 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 19 | my $old_name = $self->{name}; | |||||||||||||||||||||||||||
| 69 | 19 | ▶ | $self->{name} = $_[0] if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 19 | return $old_name; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub address { | ||||||||||||||||||||||||||||
| 75 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
address: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 4 | my $old_address = $self->{address}; | |||||||||||||||||||||||||||
| 78 | 4 | ▶ | $self->{address} = $_[0] if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 4 | return $old_address; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | sub format { | ||||||||||||||||||||||||||||
| 84 | 16 | ▶ | my ($self, $encoder) = @_; | ||||||||||||||||||||||||||
|
Subroutine
format: called CC=6 SCAR=18.8
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 16 | my $name = $self->{name}; | |||||||||||||||||||||||||||
| 87 | 16 | my $address = $self->{address}; | |||||||||||||||||||||||||||
| 88 | 16 | ▶ | defined($address) && $address =~ /^$addr_spec_re\z/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $address and $address =~ /^$addr_spec_re\z/
MC/DC0%0/2
defined $address and $address =~ /^$addr_spec_re\z/
defined $address
$address =~ /^$addr_spec_re\z/
Truth table33%1/3
A and B
A= defined $addressB= $address =~ /^$addr_spec_re\z/
| |||||||||||||||||||||||||||||
| 89 | or die ("invalid email address"); | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 16 | my $result; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 16 | ▶ | if (!defined($name) || $name eq '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $name or $name eq ""
MC/DC50%1/2
not defined $name or $name eq ""
not defined $name
$name eq ""
Truth table66%2/3
not(A) or B
A= not defined $nameB= $name eq ""
| |||||||||||||||||||||||||||||
| 94 | 4 | $result = $address; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | else { | ||||||||||||||||||||||||||||
| 97 | 12 | ▶ | $encoder ||= Email::MIME::RFC2047::Encoder->new(); | ||||||||||||||||||||||||||
|
Condition33%1/3
$encoder ||= "Email::MIME::RFC2047::Encoder"->new
MC/DC0%0/2
$encoder ||= "Email::MIME::RFC2047::Encoder"->new
$encoder
"Email::MIME::RFC2047::Encoder"->new
Truth table33%1/3
A ||= B
A= $encoderB= "Email::MIME::RFC2047::Encoder"->new
| |||||||||||||||||||||||||||||
| 98 | 12 | my $encoded_name = $encoder->encode_phrase($name); | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 12 | $result = "$encoded_name <$address>"; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 16 | return $result; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 4 | 1; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | __END__ | ||||||||||||||||||||||||||||