Message/Head/ListGroup.pm

filter: Statementstmt 15.7% 18 / 114 Branchbran 0.0% 0 / 92 Conditioncond 0.0% 0 / 54 MC/DCmcdc 0.0% 0 / 31 Subroutinesub 31.2% 5 / 16 Podpod 87.5% 7 / 8 totaltotal 9.5% 30 / 315 SCAR 81.8
CC
66
Cov
7%
from
650.0
address
380.0
init
72.0
CRAP 3578.5
↑ Summary Message/Replace/MailInternet.pm »
1 # Copyrights 2001-2023 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 Mail-Message. 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::Message::Head::ListGroup;
10 2 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 $VERSION = '3.013';
12  
13 2 ▶use base 'Mail::Message::Head::FieldGroup';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 sub init($$)
22 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=8 SCAR=42.8
Pod undocumented
23 0 $self->SUPER::init($args);
24  
25 0 my $address = $args->{address};
26 0 ▶ if(!defined $address) { ; }
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $address) { } 0 0 0
elsif (not ref $address && $address->isa('Mail::Message::Field::Address')) { } 0 0 0
27 ▶ elsif(!ref $address || !$address->isa('Mail::Message::Field::Address'))
Condition0%0/3
ref $address && $address->isa('Mail::Message::Field::Address')
!ll&&!rl&&r
000
MC/DC0%0/2
ref $address && $address->isa('Mail::Message::Field::Address')
ref $address $address->isa('Mail::Message::Field::Address')
Truth table0%0/3
A && B
A= ref $addressB= $address->isa('Mail::Message::Field::Address')
ABresult
0X0
100
111
28 0 { require Mail::Message::Field::Address;
29 0 my $mi = Mail::Message::Field::Address->coerce($address);
30  
31 0 ▶ defined $mi
Branch: 1 branch
BranchTrueFalseTotal
defined $mi or $self->log("ERROR", qq[Cannot convert "$address" into an address object]), return 0 0 0
32 or $self->log(ERROR => "Cannot convert \"$address\" into an address object"), return;
33  
34 0 $address = $mi;
35 }
36 0 ▶ $self->{MMHL_address} = $address if defined $args->{address};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"address"} 0 0 0
37  
38 0 ▶ $self->{MMHL_listname} = $args->{listname} if defined $args->{listname};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"listname"} 0 0 0
39 0 ▶ $self->{MMHL_rfc} = $args->{rfc} if defined $args->{rfc};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"rfc"} 0 0 0
40 0 $self->{MMHL_fns} = [];
41 0 $self;
42 }
43  
44 #------------------------------------------
45  
46  
47 sub from($)
48 0 ▶{ my ($class, $from) = @_;
Subroutine from: not called CC=25 SCAR=64.8
Pod documented
49 0 ▶ my $head = $from->isa('Mail::Message::Head') ? $from : $from->head;
Branch: 1 branch
BranchTrueFalseTotal
$from->isa('Mail::Message::Head') ? : 0 0 0
50 0 my $self = $class->new(head => $head);
51  
52 0 ▶ return () unless $self->collectFields;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->collectFields 0 0 0
53  
54 0 my ($type, $software, $version, $field);
55 0 ▶ if(my $communigate = $head->get('X-ListServer'))
Branch: 14 branches
BranchTrueFalseTotal
if (my $communigate = $head->get('X-ListServer')) { } 0 0 0
elsif (my $mailman = $head->get('X-Mailman-Version')) { } 0 0 0
elsif (my $majordomo = $head->get('X-Majordomo-Version')) { } 0 0 0
elsif (my $ecartis = $head->get('X-Ecartis-Version')) { } 0 0 0
elsif (my $listar = $head->get('X-Listar-Version')) { } 0 0 0
elsif (defined($field = $head->get('List-Software')) and $field =~ /listbox/i) { } 0 0 0
elsif ($field = &first(sub { m[LISTSERV-TCP/IP]s; } , $head->get('Received'))) { } 0 0 0
elsif (defined($field = $head->get('X-Mailing-List')) and $field =~ m[archive/latest]) { } 0 0 0
elsif (defined($field = $head->get('Mailing-List')) and $field =~ /yahoo/i) { } 0 0 0
elsif (defined $field and $field =~ /(ezmlm)/i) { } 0 0 0
elsif (my $fml = $head->get('X-MLServer')) { } 0 0 0
elsif (defined($field = $head->get('List-Subscribe') || $head->get('List-Unsubscribe')) and $field =~ /sympa/i) { } 0 0 0
elsif (&first(sub { /majordom/i; } , $head->get('Received'))) { } 0 0 0
elsif ($field = $head->get('List-ID') && $field =~ /listbox\.com/i) { } 0 0 0
56 0 { ($software, $version) = $communigate =~ m/^(.*)\s+LIST\s*([\d.]+)\s*$/i;
57 0 ▶ $type = ($software =~ m/Pro/ ? 'CommuniGatePro' : 'CommuniGate');
Branch: 1 branch
BranchTrueFalseTotal
$software =~ /Pro/ ? : 0 0 0
58 }
59 elsif(my $mailman = $head->get('X-Mailman-Version'))
60 0 { $version = "$mailman";
61 0 $type = 'Mailman';
62 }
63 elsif(my $majordomo = $head->get('X-Majordomo-Version'))
64 0 { $version = "$majordomo";
65 0 $type = 'Majordomo';
66 }
67 elsif(my $ecartis = $head->get('X-Ecartis-Version'))
68 0 { ($software, $version) = $ecartis =~ m/^(.*)\s+(v[\d.]+)/;
69 0 $type = 'Ecartis';
70 }
71 elsif(my $listar = $head->get('X-Listar-Version'))
72 0 { ($software, $version) = $listar =~ m/^(.*?)\s+(v[\w.]+)/;
73 0 $type = 'Listar';
74 }
75 ▶ elsif(defined($field = $head->get('List-Software'))
Condition0%0/3
defined($field = $head->get("List-Software")) and $field =~ /listbox/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined($field = $head->get("List-Software")) and $field =~ /listbox/i
defined($field = $head->get("List-Software")) $field =~ /listbox/i
Truth table0%0/3
A and B
A= defined($field = $head->get("List-Software"))B= $field =~ /listbox/i
ABresult
0X0
100
111
76 && $field =~ m/listbox/i)
77 0 { ($software, $version) = $field =~ m/^(\S*)\s*(v[\d.]+)\s*$/;
78 0 $type = 'Listbox';
79 }
80 0 ▶ elsif($field = first { m!LISTSERV-TCP/IP!s } $head->get('Received'))
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 { # Listserv is hard to recognise
82 0 ($software, $version) = $field =~
83 m!\( (LISTSERV-TCP/IP) \s+ release \s+ (\S+) \)!xs;
84 0 $type = 'Listserv';
85 }
86 ▶ elsif(defined($field = $head->get('X-Mailing-List'))
Condition0%0/3
defined($field = $head->get("X-Mailing-List")) and $field =~ m[archive/latest]
!ll&&!rl&&r
000
MC/DC0%0/2
defined($field = $head->get("X-Mailing-List")) and $field =~ m[archive/latest]
defined($field = $head->get("X-Mailing-List")) $field =~ m[archive/latest]
Truth table0%0/3
A and B
A= defined($field = $head->get("X-Mailing-List"))B= $field =~ m[archive/latest]
ABresult
0X0
100
111
87 && $field =~ m[archive/latest])
88 0 { $type = 'Smartlist' }
89 ▶ elsif(defined($field = $head->get('Mailing-List')) && $field =~ m/yahoo/i )
Condition0%0/3
defined($field = $head->get("Mailing-List")) and $field =~ /yahoo/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined($field = $head->get("Mailing-List")) and $field =~ /yahoo/i
defined($field = $head->get("Mailing-List")) $field =~ /yahoo/i
Truth table0%0/3
A and B
A= defined($field = $head->get("Mailing-List"))B= $field =~ /yahoo/i
ABresult
0X0
100
111
90 0 { $type = 'YahooGroups' }
91 ▶ elsif(defined($field) && $field =~ m/(ezmlm)/i )
Condition0%0/3
defined $field and $field =~ /(ezmlm)/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $field and $field =~ /(ezmlm)/i
defined $field $field =~ /(ezmlm)/i
Truth table0%0/3
A and B
A= defined $fieldB= $field =~ /(ezmlm)/i
ABresult
0X0
100
111
92 0 { $type = 'Ezmlm' }
93 elsif(my $fml = $head->get('X-MLServer'))
94 0 { ($software, $version) = $fml =~ m/^\s*(\S+)\s*\[\S*\s*([^\]]*?)\s*\]/;
95 0 $type = 'FML';
96 }
97 ▶ elsif(defined($field = $head->get('List-Subscribe')
Condition0%0/6
defined($field = $head->get("List-Subscribe") || $head->get("List-Unsubscribe")) and $field =~ /sympa/i
!ll&&!rl&&r
000
$head->get('List-Subscribe') || $head->get('List-Unsubscribe')
l!l&&r!l&&!r
000
MC/DC0%0/3
defined($field = $head->get("List-Subscribe") || $head->get("List-Unsubscribe")) and $field =~ /sympa/i
$head->get('List-Subscribe') $head->get('List-Unsubscribe') $field =~ /sympa/i
Truth table0%0/5
A || B and C
A= $head->get('List-Subscribe')B= $head->get('List-Unsubscribe')C= $field =~ /sympa/i
ABCresult
00X0
1X00
0100
1X11
0111
98 || $head->get('List-Unsubscribe'))
99 && $field =~ m/sympa/i)
100 0 { $type = 'Sympa' }
101 0 ▶ elsif(first { m/majordom/i } $head->get('Received'))
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 { # Majordomo is hard to recognize
103 0 $type = "Majordomo";
104 }
105 ▶ elsif($field = $head->get('List-ID') && $field =~ m/listbox\.com/i)
Condition0%0/3
$head->get('List-ID') && $field =~ /listbox\.com/i
!ll&&!rl&&r
000
MC/DC0%0/2
$head->get('List-ID') && $field =~ /listbox\.com/i
$head->get('List-ID') $field =~ /listbox\.com/i
Truth table0%0/3
A && B
A= $head->get('List-ID')B= $field =~ /listbox\.com/i
ABresult
0X0
100
111
106 0 { $type = "Listbox" }
107  
108 0 $self->detected($type, $software, $version);
109 0 $self;
110 }
111  
112 #------------------------------------------
113  
114  
115 sub rfc()
116 0 ▶{ my $self = shift;
Subroutine rfc: not called CC=4 SCAR=30.0
Pod documented
117 0 ▶ return $self->{MMHL_rfc} if defined $self->{MMHL_rfc};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MMHL_rfc"} 0 0 0
118  
119 0 my $head = $self->head;
120 0 ▶ defined $head->get('List-Post') ? 'rfc2369'
Branch: 2 branches
BranchTrueFalseTotal
defined $head->get('List-Post') ? : 0 0 0
defined $head->get('List-Id') ? : 0 0 0
121 : defined $head->get('List-Id') ? 'rfc2919'
122 : undef;
123 }
124  
125 #------------------------------------------
126  
127  
128 sub address()
129 0 ▶{ my $self = shift;
Subroutine address: not called CC=19 SCAR=59.4
Pod documented
130 0 ▶ return $self->{MMHL_address} if exists $self->{MMHL_address};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MMHL_address"} 0 0 0
131  
132 0 ▶ my $type = $self->type || 'Unknown';
Condition0%0/2
$self->type || 'Unknown'
l!l
00
MC/DC0%0/1
$self->type || 'Unknown'
$self->type
Truth table0%0/2
A
A= $self->type
Aresult
11
00
133 0 my $head = $self->head;
134  
135 0 my ($field, $address);
136 0 ▶ if($type eq 'Smartlist' && defined($field = $head->get('X-Mailing-List')))
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'Smartlist' and defined($field = $head->get('X-Mailing-List'))) { } 0 0 0
elsif ($type eq 'YahooGroups') { } 0 0 0
elsif ($type eq 'Listserv') { } 0 0 0
Condition0%0/3
$type eq "Smartlist" and defined($field = $head->get("X-Mailing-List"))
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "Smartlist" and defined($field = $head->get("X-Mailing-List"))
$type eq "Smartlist" defined($field = $head->get("X-Mailing-List"))
Truth table0%0/3
A and B
A= $type eq "Smartlist"B= defined($field = $head->get("X-Mailing-List"))
ABresult
0X0
100
111
137 0 ▶ { $address = $1 if $field =~ m/\<([^>]+)\>/ }
Branch: 1 branch
BranchTrueFalseTotal
if $field =~ /\<([^>]+)\>/ 0 0 0
138 elsif($type eq 'YahooGroups')
139 0 { $address = $head->get('X-Apparently-To')->unfoldedBody }
140 elsif($type eq 'Listserv')
141 0 { $address = $head->get('Sender') }
142  
143 0 ▶ $address ||= $head->get('List-Post') || $head->get('Reply-To')
Condition0%0/9
$address ||= $head->get("List-Post") || $head->get("Reply-To") || $head->get("Sender")
l!l&&r!l&&!r
000
$head->get('List-Post') || $head->get('Reply-To') || $head->get('Sender')
l!l&&r!l&&!r
000
$head->get("List-Post") or $head->get("Reply-To")
l!l&&r!l&&!r
000
MC/DC0%0/4
$address ||= $head->get("List-Post") || $head->get("Reply-To") || $head->get("Sender")
$address $head->get("List-Post") $head->get("Reply-To") $head->get('Sender')
Truth table0%0/5
A ||= B or C || D
A= $addressB= $head->get("List-Post")C= $head->get("Reply-To")D= $head->get('Sender')
ABCDresult
1XXX1
01XX1
001X1
00011
00000
144 || $head->get('Sender');
145 0 ▶ $address = $address->study if ref $address;
Branch: 1 branch
BranchTrueFalseTotal
if ref $address 0 0 0
146  
147 0 ▶ if(!defined $address) { ; }
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $address) { } 0 0 0
elsif (not ref $address) { } 0 0 0
elsif ($address->isa('Mail::Message::Field::Addresses')) { } 0 0 0
elsif ($address->isa('Mail::Message::Field::URIs')) { } 0 0 0
148 elsif(!ref $address)
149 0 { $address =~ s/\bowner-|-(?:owner|bounce|admin)\@//i;
150 0 $address = Mail::Message::Field::Address->new(address => $address);
151 }
152 elsif($address->isa('Mail::Message::Field::Addresses'))
153 { # beautify
154 0 $address = ($address->addresses)[0];
155 0 ▶ my $username = defined $address ? $address->username : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $address ? : 0 0 0
156 0 ▶ if($username =~ s/^owner-|-(owner|bounce|admin)$//i)
Branch: 1 branch
BranchTrueFalseTotal
if ($username =~ s/^owner-|-(owner|bounce|admin)$//i) 0 0 0
157 0 { $address = Mail::Message::Field::Address->new
158 (username => $username, domain => $address->domain);
159 }
160 }
161 elsif($address->isa('Mail::Message::Field::URIs'))
162 0 ▶ { my $uri = first { $_->scheme eq 'mailto' } $address->URIs;
Subroutine __ANON__: not called CC=1 SCAR=6.9
163 0 ▶ $address = defined $uri
Branch: 1 branch
BranchTrueFalseTotal
defined $uri ? : 0 0 0
164 ? Mail::Message::Field::Address->new(address => $uri->to)
165 : undef;
166 }
167 else # Don't understand life anymore :-(
168 0 { undef $address;
169 }
170  
171 0 $self->{MMHL_address} = $address;
172 }
173  
174 #------------------------------------------
175  
176  
177 sub listname()
178 0 ▶{ my $self = shift;
Subroutine listname: not called CC=7 SCAR=40.3
Pod documented
179 0 ▶ return $self->{MMHL_listname} if exists $self->{MMHL_listname};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MMHL_listname"} 0 0 0
180  
181 0 my $head = $self->head;
182  
183 # Some lists have a field with the name only
184 0 ▶ my $list = $head->get('List-ID') || $head->get('X-List')
Condition0%0/6
$head->get('List-ID') || $head->get('X-List') || $head->get('X-ML-Name')
l!l&&r!l&&!r
000
$head->get("List-ID") or $head->get("X-List")
l!l&&r!l&&!r
000
MC/DC0%0/3
$head->get('List-ID') || $head->get('X-List') || $head->get('X-ML-Name')
$head->get("List-ID") $head->get("X-List") $head->get('X-ML-Name')
Truth table0%0/4
A or B || C
A= $head->get("List-ID")B= $head->get("X-List")C= $head->get('X-ML-Name')
ABCresult
1XX1
01X1
0011
0000
185 || $head->get('X-ML-Name');
186  
187 0 my $listname;
188 0 ▶ if(defined $list)
Branch: 2 branches
BranchTrueFalseTotal
if (defined $list) { } 0 0 0
elsif (my $address = $self->address) { } 0 0 0
189 0 { $listname = $list->study->decodedBody;
190 }
191 elsif(my $address = $self->address)
192 0 ▶ { $listname = $address->phrase || $address->address;
Condition0%0/3
$address->phrase || $address->address
l!l&&r!l&&!r
000
MC/DC0%0/2
$address->phrase || $address->address
$address->phrase $address->address
Truth table0%0/3
A || B
A= $address->phraseB= $address->address
ABresult
1X1
011
000
193 }
194  
195 0 $self->{MMHL_listname} = $listname;
196 }
197  
198 #------------------------------------------
199  
200  
201 2 my $list_field_names
202 = qr/ ^ (?: List|X-Envelope|X-Original ) -
203 | ^ (?: Precedence|Mailing-List|Approved-By ) $
204 | ^ X-(?: Loop|BeenThere|Sequence|List|Sender|MLServer ) $
205 | ^ X-(?: Mailman|Listar|Egroups|Encartis|ML ) -
206 | ^ X-(?: Archive|Mailing|Original|Mail|ListServer ) -
207 | ^ (?: Mail-Followup|Delivered|Errors|X-Apperently ) -To $
208 /xi;
209  
210 0 ▶sub isListGroupFieldName($) { $_[1] =~ $list_field_names }
Subroutine isListGroupFieldName: not called CC=1 SCAR=6.9
Pod documented
211  
212 #------------------------------------------
213  
214  
215 sub collectFields()
216 0 ▶{ my $self = shift;
Subroutine collectFields: not called CC=1 SCAR=6.9
Pod documented
217 0 my @names = map { $_->name } $self->head->grepNames($list_field_names);
218 0 $self->addFields(@names);
219 0 @names;
220 }
221  
222 #------------------------------------------
223  
224  
225 sub details()
226 0 ▶{ my $self = shift;
Subroutine details: not called CC=8 SCAR=42.8
Pod documented
227 0 ▶ my $type = $self->type || 'Unknown';
Condition0%0/2
$self->type || 'Unknown'
l!l
00
MC/DC0%0/1
$self->type || 'Unknown'
$self->type
Truth table0%0/2
A
A= $self->type
Aresult
11
00
228  
229 0 my $software = $self->software;
230 0 ▶ undef $software if defined($software) && $type eq $software;
Branch: 1 branch
BranchTrueFalseTotal
if defined $software and $type eq $software 0 0 0
Condition0%0/3
defined $software and $type eq $software
!ll&&!rl&&r
000
MC/DC0%0/2
defined $software and $type eq $software
defined $software $type eq $software
Truth table0%0/3
A and B
A= defined $softwareB= $type eq $software
ABresult
0X0
100
111
231 0 my $version = $self->version;
232 0 ▶ my $release
Branch: 3 branches
BranchTrueFalseTotal
defined $software ? : 0 0 0
defined $version ? : 0 0 0
defined $version ? : 0 0 0
233 = defined $software
234 ? (defined $version ? " ($software $version)" : " ($software)")
235 : (defined $version ? " ($version)" : '');
236  
237 0 ▶ my $address = $self->address || 'unknown address';
Condition0%0/2
$self->address || 'unknown address'
l!l
00
MC/DC0%0/1
$self->address || 'unknown address'
$self->address
Truth table0%0/2
A
A= $self->address
Aresult
11
00
238 0 my $fields = scalar $self->fields;
239 0 "$type at $address$release, $fields fields";
240 }
241  
242 #------------------------------------------
243  
244  
245 2 1;
↑ Summary Message/Replace/MailInternet.pm »