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