line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ============================================================================ |
2
|
|
|
|
|
|
|
package Mail::Builder::Address; |
3
|
|
|
|
|
|
|
# ============================================================================ |
4
|
|
|
|
|
|
|
|
5
|
8
|
|
|
8
|
|
77
|
use namespace::autoclean; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
64
|
|
6
|
8
|
|
|
8
|
|
616
|
use Moose; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
174
|
|
7
|
8
|
|
|
8
|
|
26105
|
use Mail::Builder::TypeConstraints; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
139
|
|
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
25
|
use Carp; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
458
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
8
|
|
|
8
|
|
4012
|
use Email::Valid; |
|
8
|
|
|
|
|
409528
|
|
|
8
|
|
|
|
|
4276
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Mail::Builder::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'email' => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
isa => 'Mail::Builder::Type::EmailAddress', |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'name' => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
isa => 'Str', |
25
|
|
|
|
|
|
|
predicate => 'has_name', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has 'comment' => ( |
29
|
|
|
|
|
|
|
is => 'rw', |
30
|
|
|
|
|
|
|
isa => 'Str', |
31
|
|
|
|
|
|
|
predicate => 'has_comment', |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=encoding utf8 |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Mail::Builder::Address - Module for handling e-mail addresses |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 SYNOPSIS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
use Mail::Builder; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $mail = Mail::Builder::Address->new('mightypirate@meele-island.mq','Gaybrush Thweedwood'); |
45
|
|
|
|
|
|
|
# Now correct type in the display name and address |
46
|
|
|
|
|
|
|
$mail->name('Guybrush Threepwood'); |
47
|
|
|
|
|
|
|
$mail->email('verymightypirate@meele-island.mq'); |
48
|
|
|
|
|
|
|
$mail->comment('Mighty Pirate (TM)'); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Serialize |
51
|
|
|
|
|
|
|
print $mail->serialize; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Use the address as a recipient for Mail::Builder object |
54
|
|
|
|
|
|
|
$mb->to($mail); # Removes all other recipients |
55
|
|
|
|
|
|
|
OR |
56
|
|
|
|
|
|
|
$mb->to->add($mail); # Adds one more recipient (without removing the existing ones) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This is a simple module for handling e-mail addresses. It can store the address |
61
|
|
|
|
|
|
|
and an optional display name. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 METHODS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 Constructor |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head3 new |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Mail::Builder::Address->new(EMAIL[,DISPLAY NAME[,COMMENT]]); |
70
|
|
|
|
|
|
|
OR |
71
|
|
|
|
|
|
|
Mail::Builder::Address->new({ |
72
|
|
|
|
|
|
|
email => EMAIL, |
73
|
|
|
|
|
|
|
[ name => DISPLAY NAME, ] |
74
|
|
|
|
|
|
|
[ comment => COMMENT, ] |
75
|
|
|
|
|
|
|
}) |
76
|
|
|
|
|
|
|
OR |
77
|
|
|
|
|
|
|
my $email = Email::Address->parse(...); |
78
|
|
|
|
|
|
|
Mail::Builder::Address->new($email); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Simple constructor |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
around BUILDARGS => sub { |
86
|
|
|
|
|
|
|
my $orig = shift; |
87
|
|
|
|
|
|
|
my $class = shift; |
88
|
|
|
|
|
|
|
my @args = @_; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $args_length = scalar @args; |
91
|
|
|
|
|
|
|
my %params; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
if ($args_length == 1) { |
94
|
|
|
|
|
|
|
if (blessed $args[0] && $args[0]->isa('Email::Address')) { |
95
|
|
|
|
|
|
|
$params{email} = $args[0]->address; |
96
|
|
|
|
|
|
|
$params{name} = $args[0]->phrase; |
97
|
|
|
|
|
|
|
$params{comment} = $args[0]->comment; |
98
|
|
|
|
|
|
|
} elsif (ref $args[0] eq 'HASH') { |
99
|
|
|
|
|
|
|
return $class->$orig($args[0]); |
100
|
|
|
|
|
|
|
} elsif (ref $args[0] eq 'ARRAY') { |
101
|
|
|
|
|
|
|
$params{email} = $args[0]->[0]; |
102
|
|
|
|
|
|
|
$params{name} = $args[0]->[1]; |
103
|
|
|
|
|
|
|
$params{comment} = $args[0]->[2]; |
104
|
|
|
|
|
|
|
} else { |
105
|
|
|
|
|
|
|
$params{email} = $args[0]; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} elsif ($args_length == 2 |
108
|
|
|
|
|
|
|
&& $args[0] ne 'email') { |
109
|
|
|
|
|
|
|
$params{email} = $args[0]; |
110
|
|
|
|
|
|
|
$params{name} = $args[1]; |
111
|
|
|
|
|
|
|
} elsif ($args_length == 3) { |
112
|
|
|
|
|
|
|
$params{email} = $args[0]; |
113
|
|
|
|
|
|
|
$params{name} = $args[1]; |
114
|
|
|
|
|
|
|
$params{comment} = $args[2]; |
115
|
|
|
|
|
|
|
} else { |
116
|
|
|
|
|
|
|
return $class->$orig(@args); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
delete $params{name} |
120
|
|
|
|
|
|
|
unless defined $params{name} && $params{name} !~ /^\s*$/; |
121
|
|
|
|
|
|
|
delete $params{comment} |
122
|
|
|
|
|
|
|
unless defined $params{comment} && $params{comment} !~ /^\s*$/; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
return $class->$orig(\%params); |
125
|
|
|
|
|
|
|
}; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub address { |
128
|
4
|
|
|
4
|
0
|
7
|
my $self = shift; |
129
|
4
|
|
|
|
|
86
|
return $self->email(@_); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 Public Methods |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head3 serialize |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Prints the address as required for creating the e-mail header. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub serialize { |
141
|
27
|
|
|
27
|
1
|
33
|
my ($self) = @_; |
142
|
|
|
|
|
|
|
|
143
|
27
|
100
|
|
|
|
674
|
return $self->email |
144
|
|
|
|
|
|
|
unless $self->has_name; |
145
|
|
|
|
|
|
|
|
146
|
14
|
|
|
|
|
296
|
my $name = $self->name; |
147
|
14
|
|
|
|
|
20
|
$name =~ s/"/\\"/g; |
148
|
|
|
|
|
|
|
|
149
|
14
|
|
|
|
|
41
|
my $encoded = Mail::Builder::Utils::encode_mime($name); |
150
|
14
|
100
|
|
|
|
3923
|
$encoded = qq["$encoded"] |
151
|
|
|
|
|
|
|
unless $encoded =~ /=\?/; |
152
|
14
|
|
|
|
|
319
|
my $return = sprintf '%s <%s>',$encoded,$self->email; |
153
|
14
|
100
|
|
|
|
371
|
$return .= ' '.Mail::Builder::Utils::encode_mime($self->comment) |
154
|
|
|
|
|
|
|
if $self->has_comment; |
155
|
|
|
|
|
|
|
|
156
|
14
|
|
|
|
|
74
|
return $return; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head3 compare |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$obj->compare(OBJECT); |
162
|
|
|
|
|
|
|
or |
163
|
|
|
|
|
|
|
$obj->compare(E-MAIL); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Checks if two address objects contain the same e-mail address. Returns true |
166
|
|
|
|
|
|
|
or false. The compare method does not check if the address names of the |
167
|
|
|
|
|
|
|
two objects are identical. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Instead of a C<Mail::Builder::Address> object you can also pass a |
170
|
|
|
|
|
|
|
scalar value representing the e-mail address. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub compare { |
175
|
29
|
|
|
29
|
1
|
29
|
my ($self,$compare) = @_; |
176
|
|
|
|
|
|
|
|
177
|
29
|
50
|
|
|
|
42
|
return 0 |
178
|
|
|
|
|
|
|
unless (defined $compare); |
179
|
|
|
|
|
|
|
|
180
|
29
|
100
|
|
|
|
48
|
if (blessed($compare)) { |
181
|
17
|
50
|
|
|
|
39
|
return 0 unless $compare->isa(__PACKAGE__); |
182
|
17
|
100
|
|
|
|
377
|
return (uc($self->email) eq uc($compare->email)) ? 1:0; |
183
|
|
|
|
|
|
|
} else { |
184
|
12
|
100
|
|
|
|
45
|
return ( uc($compare) eq uc($self->{email}) ) ? 1:0; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub empty { |
189
|
0
|
|
|
0
|
0
|
|
croak('DEPRECATED') |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 Accessors |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head3 name |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Display name |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head3 email |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
E-mail address. Will be checked with L<Email::Valid> |
205
|
|
|
|
|
|
|
L<Email::Valid> options may be changed by setting the appropriate values |
206
|
|
|
|
|
|
|
in the %Mail::Builder::TypeConstraints::EMAILVALID hash. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Eg. if you want to disable the check for valid TLDs you can set the 'tldcheck' |
209
|
|
|
|
|
|
|
option (without dashes 'tldcheck' and not '-tldcheck'): |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
$Mail::Builder::TypeConstraints::EMAILVALID{tldcheck} = 0; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Required |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head3 comment |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Comment |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 AUTHOR |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Maroš Kollár |
222
|
|
|
|
|
|
|
CPAN ID: MAROS |
223
|
|
|
|
|
|
|
maros [at] k-1.com |
224
|
|
|
|
|
|
|
http://www.k-1.com |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=cut |