| 1 | # Copyrights 2003-2022 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||||||||||
| 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.03. | ||||||||||||||||||||||||||||
| 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 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | $VERSION = '1.01'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use base 'User::Identity::Item'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use User::Identity; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub type() { "email" } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub init($) | ||||||||||||||||||||||||||||
| 26 | 1 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=6 SCAR=19.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | $args->{name} ||= '-x-'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"name"} ||= "-x-"
MC/DC0%0/1
$args->{"name"} ||= "-x-"
$args->{"name"}
Truth table50%1/2
A
A= $args->{"name"}
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | $self->SUPER::init($args); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | exists $args->{$_} && ($self->{'MI_'.$_} = delete $args->{$_}) | ||||||||||||||||||||||||||||
| 33 | 1 | ▶ | foreach qw/address charset comment domain language | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | location organization pgp_key phrase signature | ||||||||||||||||||||||||||||
| 35 | username/; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | $self->{UII_name} = $self->phrase || $self->address | ||||||||||||||||||||||||||||
| 38 | 1 | ▶ | if $self->{UII_name} eq '-x-'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->phrase || $self->address
MC/DC0%0/2
$self->phrase || $self->address
$self->phrase
$self->address
Truth table0%0/3
A || B
A= $self->phraseB= $self->address
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | $self; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | sub from($) | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | { my ($class, $other) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
from: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return $other if $other->isa(__PACKAGE__); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if($other->isa('Mail::Address')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | { # Mail::Address is far to lazy | ||||||||||||||||||||||||||||
| 50 | 0 | return $class->parse($other->format); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if($other->isa('User::Identity')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | { my $emails = $other->collection('emails') or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my @roles = $emails->roles or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | return $roles[0]; # first Mail::Identity | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | undef; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub comment($) | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
comment: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return $self->{MI_comment} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $self->{MI_comment} if defined $self->{MI_comment}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my $user = $self->user or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $full = $user->fullName or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | $self->phrase eq $full ? undef : $full; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub charset() | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
charset: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | return $self->{MI_charset} if defined $self->{MI_charset}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my $user = $self->user or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | $user->charset; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | sub language() | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
language: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return $self->{MI_language} if defined $self->{MI_language}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $user = $self->user or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | $user->language; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub domain() | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
domain: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | return $self->{MI_domain} | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if defined $self->{MI_domain}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $address = $self->{MI_address} or return 'localhost'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $address =~ s/.*?\@// ? $address : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub address() | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
address: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | return $self->{MI_address} if defined $self->{MI_address}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if(my $username = $self->username) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | { if(my $domain = $self->domain) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | { if($username =~ /[^a-zA-Z0-9!#\$%&'*+\-\/=?^_`{|}~.]/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | return $name if index($name, '@') >= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | my $user = $self->user; | |||||||||||||||||||||||||||
| 123 | 0 | ▶ | defined $user ? $user->nickname : $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | sub location() | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
location: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | 0 | my $location = $self->{MI_location}; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if(! defined $location) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | { my $user = $self->user or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | my @locs = $user->collection('locations'); | |||||||||||||||||||||||||||
| 134 | 0 | ▶ | $location = @locs ? $locs[0] : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | elsif(! ref $location) | ||||||||||||||||||||||||||||
| 137 | 0 | ▶ | { my $user = $self->user or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | $location = $user->find(location => $location); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | $location; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | sub organization() | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
organization: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | return $self->{MI_organization} if defined $self->{MI_organization}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my $location = $self->location or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | $location->organization; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | #pgp_key | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | sub phrase() | ||||||||||||||||||||||||||||
| 157 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
phrase: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | return $self->{MI_phrase} if defined $self->{MI_phrase}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $user = $self->user or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my $full = $user->fullName or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | $full; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | #signature | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | sub username() | ||||||||||||||||||||||||||||
| 168 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
username: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | return $self->{MI_username} if defined $self->{MI_username}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if(my $address = $self->{MI_address}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | { $address =~ s/\@.*$//; # strip domain part if present | |||||||||||||||||||||||||||
| 173 | 0 | return $address; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | my $user = $self->user or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 0 | $user->nickname; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 1 | 1; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||