line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Email::MIME::RFC2047::Mailbox; |
2
|
|
|
|
|
|
|
$Email::MIME::RFC2047::Mailbox::VERSION = '0.95'; |
3
|
4
|
|
|
4
|
|
16257
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
120
|
|
4
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
148
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Handling of MIME encoded mailboxes |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
25
|
use base qw(Email::MIME::RFC2047::Address); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
812
|
|
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
24
|
use Email::MIME::RFC2047::Decoder; |
|
4
|
|
|
|
|
23
|
|
|
4
|
|
|
|
|
804
|
|
11
|
4
|
|
|
4
|
|
1845
|
use Email::MIME::RFC2047::Encoder; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
2068
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $domain_part_re = qr/[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?/; |
14
|
|
|
|
|
|
|
my $addr_spec_re = qr{ |
15
|
|
|
|
|
|
|
[\w&'*+.\/=?^{}~-]+ |
16
|
|
|
|
|
|
|
\@ |
17
|
|
|
|
|
|
|
$domain_part_re (?: \. $domain_part_re)+ |
18
|
|
|
|
|
|
|
}x; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
65
|
|
|
65
|
1
|
129
|
my $class = shift; |
22
|
|
|
|
|
|
|
|
23
|
65
|
|
|
|
|
42
|
my $self; |
24
|
|
|
|
|
|
|
|
25
|
65
|
100
|
|
|
|
123
|
if (@_ >= 2) { |
|
|
100
|
|
|
|
|
|
26
|
35
|
|
|
|
|
82
|
$self = { @_ }; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
elsif (ref($_[0])) { |
29
|
16
|
|
|
|
|
13
|
$self = $_[0]; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
14
|
|
|
|
|
34
|
$self = { address => $_[0] }; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
65
|
|
|
|
|
122
|
return bless($self, $class); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub parse { |
39
|
30
|
|
|
30
|
1
|
3807
|
my ($class, $string, $decoder) = @_; |
40
|
30
|
100
|
|
|
|
51
|
my $string_ref = ref($string) ? $string : \$string; |
41
|
|
|
|
|
|
|
|
42
|
30
|
|
|
|
|
23
|
my $mailbox; |
43
|
|
|
|
|
|
|
|
44
|
30
|
100
|
|
|
|
2434
|
if ($$string_ref =~ /\G\s*($addr_spec_re)\s*/cg) { |
45
|
5
|
|
|
|
|
12
|
$mailbox = $class->new($1); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { |
48
|
25
|
|
66
|
|
|
65
|
$decoder ||= Email::MIME::RFC2047::Decoder->new(); |
49
|
25
|
|
|
|
|
62
|
my $name = $decoder->decode_phrase($string_ref); |
50
|
|
|
|
|
|
|
|
51
|
25
|
100
|
|
|
|
416
|
$$string_ref =~ /\G<\s*($addr_spec_re)\s*>\s*/cg |
52
|
|
|
|
|
|
|
or return $class->_parse_error($string_ref, 'mailbox'); |
53
|
18
|
|
|
|
|
31
|
my $addr_spec = $1; |
54
|
|
|
|
|
|
|
|
55
|
18
|
|
|
|
|
40
|
$mailbox = $class->new(name => $name, address => $addr_spec); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
23
|
50
|
66
|
|
|
100
|
if (!ref($string) && pos($string) < length($string)) { |
59
|
0
|
|
|
|
|
0
|
return $class->_parse_error($string_ref); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
23
|
|
|
|
|
68
|
return $mailbox; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub name { |
66
|
19
|
|
|
19
|
1
|
22
|
my $self = shift; |
67
|
|
|
|
|
|
|
|
68
|
19
|
|
|
|
|
43
|
my $old_name = $self->{name}; |
69
|
19
|
100
|
|
|
|
39
|
$self->{name} = $_[0] if @_; |
70
|
|
|
|
|
|
|
|
71
|
19
|
|
|
|
|
44
|
return $old_name; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub address { |
75
|
4
|
|
|
4
|
1
|
3
|
my $self = shift; |
76
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
5
|
my $old_address = $self->{address}; |
78
|
4
|
50
|
|
|
|
9
|
$self->{address} = $_[0] if @_; |
79
|
|
|
|
|
|
|
|
80
|
4
|
|
|
|
|
13
|
return $old_address; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub format { |
84
|
16
|
|
|
16
|
1
|
28
|
my ($self, $encoder) = @_; |
85
|
|
|
|
|
|
|
|
86
|
16
|
|
|
|
|
29
|
my $name = $self->{name}; |
87
|
16
|
|
|
|
|
19
|
my $address = $self->{address}; |
88
|
16
|
50
|
33
|
|
|
1024
|
defined($address) && $address =~ /^$addr_spec_re\z/ |
89
|
|
|
|
|
|
|
or die ("invalid email address"); |
90
|
|
|
|
|
|
|
|
91
|
16
|
|
|
|
|
39
|
my $result; |
92
|
|
|
|
|
|
|
|
93
|
16
|
100
|
66
|
|
|
64
|
if (!defined($name) || $name eq '') { |
94
|
4
|
|
|
|
|
7
|
$result = $address; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
else { |
97
|
12
|
|
33
|
|
|
26
|
$encoder ||= Email::MIME::RFC2047::Encoder->new(); |
98
|
12
|
|
|
|
|
31
|
my $encoded_name = $encoder->encode_phrase($name); |
99
|
|
|
|
|
|
|
|
100
|
12
|
|
|
|
|
29
|
$result = "$encoded_name <$address>"; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
16
|
|
|
|
|
56
|
return $result; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |