line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2003-2020 by [Mark Overmeer ]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
5
|
|
|
|
|
|
|
# This code is part of distribution User-Identity. Meta-POD processed with |
6
|
|
|
|
|
|
|
# OODoc into POD and HTML manual-pages. See README.md |
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Mail::Identity; |
10
|
1
|
|
|
1
|
|
6
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.00'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
5
|
use base 'User::Identity::Item'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
16
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
4
|
use User::Identity; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
19
|
1
|
|
|
1
|
|
6
|
use Scalar::Util 'weaken'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1144
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub type() { "email" } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub init($) |
26
|
1
|
|
|
1
|
0
|
3
|
{ my ($self, $args) = @_; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
50
|
|
|
4
|
$args->{name} ||= '-x-'; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
6
|
$self->SUPER::init($args); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
exists $args->{$_} && ($self->{'MI_'.$_} = delete $args->{$_}) |
33
|
1
|
|
100
|
|
|
24
|
foreach qw/address charset comment domain language |
34
|
|
|
|
|
|
|
location organization pgp_key phrase signature |
35
|
|
|
|
|
|
|
username/; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$self->{UII_name} = $self->phrase || $self->address |
38
|
1
|
50
|
0
|
|
|
5
|
if $self->{UII_name} eq '-x-'; |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
3
|
$self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub from($) |
45
|
0
|
|
|
0
|
0
|
|
{ my ($class, $other) = (shift, shift); |
46
|
0
|
0
|
|
|
|
|
return $other if $other->isa(__PACKAGE__); |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if($other->isa('Mail::Address')) |
49
|
0
|
|
|
|
|
|
{ return $class->new |
50
|
|
|
|
|
|
|
( phrase => $other->phrase |
51
|
|
|
|
|
|
|
, address => $other->address |
52
|
|
|
|
|
|
|
, comment => $other->comment |
53
|
|
|
|
|
|
|
, @_); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if($other->isa('User::Identity')) |
57
|
0
|
0
|
|
|
|
|
{ my $emails = $other->collection('emails') or next; |
58
|
0
|
0
|
|
|
|
|
my @roles = $emails->roles or return (); |
59
|
0
|
|
|
|
|
|
return $roles[0]; # first Mail::Identity |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
undef; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub comment($) |
67
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
68
|
0
|
0
|
|
|
|
|
return $self->{MI_comment} = shift if @_; |
69
|
0
|
0
|
|
|
|
|
return $self->{MI_comment} if defined $self->{MI_comment}; |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
my $user = $self->user or return undef; |
72
|
0
|
0
|
|
|
|
|
my $full = $user->fullName or return undef; |
73
|
0
|
0
|
|
|
|
|
$self->phrase eq $full ? undef : $full; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub charset() |
78
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
79
|
0
|
0
|
|
|
|
|
return $self->{MI_charset} if defined $self->{MI_charset}; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
my $user = $self->user or return undef; |
82
|
0
|
|
|
|
|
|
$user->charset; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub language() |
87
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
return $self->{MI_language} if defined $self->{MI_language}; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
my $user = $self->user or return undef; |
92
|
0
|
|
|
|
|
|
$user->language; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub domain() |
97
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
98
|
|
|
|
|
|
|
return $self->{MI_domain} |
99
|
0
|
0
|
|
|
|
|
if defined $self->{MI_domain}; |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
my $address = $self->{MI_address} or return 'localhost'; |
102
|
0
|
0
|
|
|
|
|
$address =~ s/.*?\@// ? $address : undef; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub address() |
107
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
108
|
0
|
0
|
|
|
|
|
return $self->{MI_address} if defined $self->{MI_address}; |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
if(my $username = $self->username) |
111
|
0
|
0
|
|
|
|
|
{ if(my $domain = $self->domain) |
112
|
0
|
0
|
|
|
|
|
{ if($username =~ /[^a-zA-Z0-9!#\$%&'*+\-\/=?^_`{|}~.]/) |
113
|
|
|
|
|
|
|
{ # When the local part does contain a different character |
114
|
|
|
|
|
|
|
# than an atext or dot, make it quoted-string |
115
|
0
|
|
|
|
|
|
$username =~ s/"/\\"/g; |
116
|
0
|
|
|
|
|
|
$username = qq{"$username"}; |
117
|
|
|
|
|
|
|
} |
118
|
0
|
|
|
|
|
|
return "$username\@$domain"; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $name = $self->name; |
123
|
0
|
0
|
|
|
|
|
return $name if index($name, '@') >= 0; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $user = $self->user; |
126
|
0
|
0
|
|
|
|
|
defined $user ? $user->nickname : $name; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub location() |
131
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
132
|
0
|
|
|
|
|
|
my $location = $self->{MI_location}; |
133
|
|
|
|
|
|
|
|
134
|
0
|
0
|
|
|
|
|
if(! defined $location) |
|
|
0
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
{ my $user = $self->user or return; |
136
|
0
|
|
|
|
|
|
my @locs = $user->collection('locations'); |
137
|
0
|
0
|
|
|
|
|
$location = @locs ? $locs[0] : undef; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
elsif(! ref $location) |
140
|
0
|
0
|
|
|
|
|
{ my $user = $self->user or return; |
141
|
0
|
|
|
|
|
|
$location = $user->find(location => $location); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
$location; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub organization() |
149
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
return $self->{MI_organization} if defined $self->{MI_organization}; |
152
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
my $location = $self->location or return; |
154
|
0
|
|
|
|
|
|
$location->organization; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
#pgp_key |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub phrase() |
160
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
161
|
0
|
0
|
|
|
|
|
return $self->{MI_phrase} if defined $self->{MI_phrase}; |
162
|
0
|
0
|
|
|
|
|
my $user = $self->user or return undef; |
163
|
0
|
0
|
|
|
|
|
my $full = $user->fullName or return undef; |
164
|
0
|
|
|
|
|
|
$full; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
#signature |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub username() |
171
|
0
|
|
|
0
|
1
|
|
{ my $self = shift; |
172
|
0
|
0
|
|
|
|
|
return $self->{MI_username} if defined $self->{MI_username}; |
173
|
|
|
|
|
|
|
|
174
|
0
|
0
|
|
|
|
|
if(my $address = $self->{MI_address}) |
175
|
0
|
|
|
|
|
|
{ $address =~ s/\@.*$//; # strip domain part if present |
176
|
0
|
|
|
|
|
|
return $address; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
0
|
0
|
|
|
|
|
my $user = $self->user or return; |
180
|
0
|
|
|
|
|
|
$user->nickname; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
1; |
184
|
|
|
|
|
|
|
|