Message/Head/ListGroup.pm

filter: Statementstmt 94.8% 110 / 116 Branchbran 80.4% 74 / 92 Conditioncond 61.1% 33 / 54 MC/DCmcdc 35.4% 11 / 31 Subroutinesub 94.1% 16 / 17 Podpod 87.5% 7 / 8 totaltotal 78.9% 251 / 318 CC 66 SCAR 27.8
CC
66
Cov
83%
from
25.9
address
23.0
listname
10.5
CRAP 16.1
« Message/Construct/Bounce.pm ↑ Summary Message/TransferEnc/Binary.pm »
1 # This code is part of Perl distribution Mail-Message version 4.05.
2 # The POD got stripped from this file by OODoc version 3.06.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2001-2026 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 #XXX Do the list still exist?
13 #XXX Add Simplelists
14  
15 package Mail::Message::Head::ListGroup;{
16 2 our $VERSION = '4.05';
17 }
18  
19 2 ▶use parent 'Mail::Message::Head::FieldGroup';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 2 ▶use Log::Report 'mail-message', import => [ qw/__x error/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 2 ▶use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 #--------------------
30  
31 sub init($$)
32 20 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=8 SCAR=21.6
Pod undocumented
33 20 $self->SUPER::init($args);
34  
35 20 my $address = $args->{address};
36 20 ▶ if(!defined $address) { ; }
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $address) { } 19 1 20
elsif (not ref $address && $address->isa('Mail::Message::Field::Address')) { } 1 0 1
37 ▶ elsif(!ref $address || !$address->isa('Mail::Message::Field::Address'))
Condition33%1/3
ref $address && $address->isa('Mail::Message::Field::Address')
!ll&&!rl&&r
100
MC/DC0%0/2
ref $address && $address->isa('Mail::Message::Field::Address')
ref $address $address->isa('Mail::Message::Field::Address')
Truth table33%1/3
A && B
A= ref $addressB= $address->isa('Mail::Message::Field::Address')
ABresult
0X0
100
111
38 1 { require Mail::Message::Field::Address;
39 1 ▶ my $mi = Mail::Message::Field::Address->coerce($address)
Branch: 1 branch
BranchTrueFalseTotal
my $mi = "Mail::Message::Field::Address"->coerce($address) or &error(&__x("cannot convert '{address}' into an address object.", "address", $address)) 1 0 1
40 or error __x"cannot convert '{address}' into an address object.", address => $address;
41  
42 1 $address = $mi;
43 }
44  
45 20 ▶ $self->{MMHL_address} = $address if defined $args->{address};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"address"} 1 19 20
46 20 ▶ $self->{MMHL_listname} = $args->{listname} if defined $args->{listname};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"listname"} 0 20 20
47 20 ▶ $self->{MMHL_rfc} = $args->{rfc} if defined $args->{rfc};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"rfc"} 0 20 20
48 20 $self->{MMHL_fns} = [];
49 20 $self;
50 }
51  
52  
53 sub from($)
54 19 ▶{ my ($class, $from) = @_;
Subroutine from: called CC=25 SCAR=32.6
Pod documented
55 19 ▶ my $head = $from->isa('Mail::Message::Head') ? $from : $from->head;
Branch: 1 branch
BranchTrueFalseTotal
$from->isa('Mail::Message::Head') ? : 19 0 19
56 19 my $self = $class->new(head => $head);
57 19 ▶ $self->collectFields or return ();
Branch: 1 branch
BranchTrueFalseTotal
$self->collectFields or return () 17 2 19
58  
59 17 my ($type, $software, $version, $field);
60 17 ▶ if(my $communigate = $head->get('X-ListServer'))
Branch: 14 branches
BranchTrueFalseTotal
if (my $communigate = $head->get('X-ListServer')) { } 2 15 17
elsif (my $mailman = $head->get('X-Mailman-Version')) { } 2 13 15
elsif (my $majordomo = $head->get('X-Majordomo-Version')) { } 0 13 13
elsif (my $ecartis = $head->get('X-Ecartis-Version')) { } 1 12 13
elsif (my $listar = $head->get('X-Listar-Version')) { } 1 11 12
elsif (defined($field = $head->get('List-Software')) and $field =~ /listbox/i) { } 1 10 11
elsif ($field = &first(sub { m[LISTSERV-TCP/IP]s; } , $head->get('Received'))) { } 2 8 10
elsif (defined($field = $head->get('X-Mailing-List')) and $field =~ m[archive/latest]) { } 1 7 8
elsif (defined($field = $head->get('Mailing-List')) and $field =~ /yahoo/i) { } 1 6 7
elsif (defined $field and $field =~ /(ezmlm)/i) { } 1 5 6
elsif (my $fml = $head->get('X-MLServer')) { } 2 3 5
elsif (defined($field = $head->get('List-Subscribe') || $head->get('List-Unsubscribe')) and $field =~ /sympa/i) { } 1 2 3
elsif (&first(sub { /majordom/i; } , $head->get('Received'))) { } 1 1 2
elsif (defined($field = $head->get('List-ID')) and $field =~ /listbox\.com/i) { } 1 0 1
61 2 { ($software, $version) = $communigate =~ m/^(.*)\s+LIST\s*([\d.]+)\s*$/i;
62 2 ▶ $type = ($software =~ m/Pro/ ? 'CommuniGatePro' : 'CommuniGate');
Branch: 1 branch
BranchTrueFalseTotal
$software =~ /Pro/ ? : 1 1 2
63 }
64 elsif(my $mailman = $head->get('X-Mailman-Version'))
65 2 { $version = "$mailman";
66 2 $type = 'Mailman';
67 }
68 elsif(my $majordomo = $head->get('X-Majordomo-Version'))
69 0 { $version = "$majordomo";
70 0 $type = 'Majordomo';
71 }
72 elsif(my $ecartis = $head->get('X-Ecartis-Version'))
73 1 { ($software, $version) = $ecartis =~ m/^(.*)\s+(v[\d.]+)/;
74 1 $type = 'Ecartis';
75 }
76 elsif(my $listar = $head->get('X-Listar-Version'))
77 1 { ($software, $version) = $listar =~ m/^(.*?)\s+(v[\w.]+)/;
78 1 $type = 'Listar';
79 }
80 ▶ elsif(defined($field = $head->get('List-Software')) && $field =~ m/listbox/i)
Condition100%3/3
defined($field = $head->get("List-Software")) and $field =~ /listbox/i
!ll&&!rl&&r
911
MC/DC100%2/2
defined($field = $head->get("List-Software")) and $field =~ /listbox/i
defined($field = $head->get("List-Software")) $field =~ /listbox/i
Truth table100%3/3
A and B
A= defined($field = $head->get("List-Software"))B= $field =~ /listbox/i
ABresult
0X0
100
111
81 1 { ($software, $version) = $field =~ m/^(\S*)\s*(v[\d.]+)\s*$/;
82 1 $type = 'Listbox';
83 }
84 42 ▶ elsif($field = first { m!LISTSERV-TCP/IP!s } $head->get('Received'))
Subroutine __ANON__: called CC=1 SCAR=0.0
85 { # Listserv is hard to recognise
86 2 ($software, $version) = $field =~
87 m!\( (LISTSERV-TCP/IP) \s+ release \s+ (\S+) \)!xs;
88 2 $type = 'Listserv';
89 }
90 ▶ elsif(defined($field = $head->get('X-Mailing-List')) && $field =~ m[archive/latest])
Condition66%2/3
defined($field = $head->get("X-Mailing-List")) and $field =~ m[archive/latest]
!ll&&!rl&&r
701
MC/DC50%1/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 table66%2/3
A and B
A= defined($field = $head->get("X-Mailing-List"))B= $field =~ m[archive/latest]
ABresult
0X0
100
111
91 1 { $type = 'Smartlist' }
92 ▶ elsif(defined($field = $head->get('Mailing-List')) && $field =~ m/yahoo/i )
Condition100%3/3
defined($field = $head->get("Mailing-List")) and $field =~ /yahoo/i
!ll&&!rl&&r
511
MC/DC100%2/2
defined($field = $head->get("Mailing-List")) and $field =~ /yahoo/i
defined($field = $head->get("Mailing-List")) $field =~ /yahoo/i
Truth table100%3/3
A and B
A= defined($field = $head->get("Mailing-List"))B= $field =~ /yahoo/i
ABresult
0X0
100
111
93 1 { $type = 'YahooGroups' }
94 ▶ elsif(defined($field) && $field =~ m/(ezmlm)/i )
Condition66%2/3
defined $field and $field =~ /(ezmlm)/i
!ll&&!rl&&r
501
MC/DC50%1/2
defined $field and $field =~ /(ezmlm)/i
defined $field $field =~ /(ezmlm)/i
Truth table66%2/3
A and B
A= defined $fieldB= $field =~ /(ezmlm)/i
ABresult
0X0
100
111
95 1 { $type = 'Ezmlm' }
96 elsif(my $fml = $head->get('X-MLServer'))
97 2 { ($software, $version) = $fml =~ m/^\s*([^\s\[]+)\s*\[\S*\s*([^\]]*?)\s*\]/;
98 2 $type = 'FML';
99 }
100 ▶ elsif(defined($field = $head->get('List-Subscribe') || $head->get('List-Unsubscribe')) && $field =~ m/sympa/i)
Condition83%5/6
defined($field = $head->get("List-Subscribe") || $head->get("List-Unsubscribe")) and $field =~ /sympa/i
!ll&&!rl&&r
111
$head->get('List-Subscribe') || $head->get('List-Unsubscribe')
l!l&&r!l&&!r
201
MC/DC66%2/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 table60%3/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
101 1 { $type = 'Sympa' }
102 7 ▶ elsif(first { m/majordom/i } $head->get('Received'))
Subroutine __ANON__: called CC=1 SCAR=0.0
103 { # Majordomo is hard to recognize
104 1 $type = "Majordomo";
105 }
106 ▶ elsif(defined($field = $head->get('List-ID')) && $field =~ m/listbox\.com/i)
Condition33%1/3
defined($field = $head->get("List-ID")) and $field =~ /listbox\.com/i
!ll&&!rl&&r
001
MC/DC0%0/2
defined($field = $head->get("List-ID")) and $field =~ /listbox\.com/i
defined($field = $head->get("List-ID")) $field =~ /listbox\.com/i
Truth table33%1/3
A and B
A= defined($field = $head->get("List-ID"))B= $field =~ /listbox\.com/i
ABresult
0X0
100
111
107 1 { $type = "Listbox" }
108  
109 17 $self->detected($type, $software, $version);
110 17 $self;
111 }
112  
113  
114 sub rfc()
115 18 ▶{ my $self = shift;
Subroutine rfc: called CC=4 SCAR=13.9
Pod documented
116 18 ▶ return $self->{MMHL_rfc} if defined $self->{MMHL_rfc};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MMHL_rfc"} 0 18 18
117  
118 18 my $head = $self->head;
119 18 ▶ defined $head->get('List-Post') ? 'rfc2369'
Branch: 2 branches
BranchTrueFalseTotal
defined $head->get('List-Post') ? : 4 14 18
defined $head->get('List-Id') ? : 4 10 14
120 : defined $head->get('List-Id') ? 'rfc2919'
121 : undef;
122 }
123  
124  
125 sub address()
126 20 ▶{ my $self = shift;
Subroutine address: called CC=19 SCAR=31.3
Pod documented
127 20 ▶ return $self->{MMHL_address} if exists $self->{MMHL_address};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MMHL_address"} 3 17 20
128  
129 17 ▶ my $type = $self->type || 'Unknown';
Condition50%1/2
$self->type || 'Unknown'
l!l
170
MC/DC0%0/1
$self->type || 'Unknown'
$self->type
Truth table50%1/2
A
A= $self->type
Aresult
11
00
130 17 my $head = $self->head;
131  
132 17 my ($field, $address);
133 17 ▶ 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'))) { } 1 16 17
elsif ($type eq 'YahooGroups') { } 1 15 16
elsif ($type eq 'Listserv') { } 2 13 15
Condition66%2/3
$type eq "Smartlist" and defined($field = $head->get("X-Mailing-List"))
!ll&&!rl&&r
1601
MC/DC50%1/2
$type eq "Smartlist" and defined($field = $head->get("X-Mailing-List"))
$type eq "Smartlist" defined($field = $head->get("X-Mailing-List"))
Truth table66%2/3
A and B
A= $type eq "Smartlist"B= defined($field = $head->get("X-Mailing-List"))
ABresult
0X0
100
111
134 1 ▶ { $address = $1 if $field =~ m/\<([^>]+)\>/ }
Branch: 1 branch
BranchTrueFalseTotal
if $field =~ /\<([^>]+)\>/ 1 0 1
135 elsif($type eq 'YahooGroups')
136 1 { $address = $head->get('X-Apparently-To')->unfoldedBody }
137 elsif($type eq 'Listserv')
138 2 { $address = $head->get('Sender') }
139  
140 17 ▶ $address ||= $head->get('List-Post') || $head->get('Reply-To') || $head->get('Sender');
Condition55%5/9
$address ||= $head->get("List-Post") || $head->get("Reply-To") || $head->get("Sender")
l!l&&r!l&&!r
4130
$head->get('List-Post') || $head->get('Reply-To') || $head->get('Sender')
l!l&&r!l&&!r
1300
$head->get("List-Post") or $head->get("Reply-To")
l!l&&r!l&&!r
490
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
141 17 ▶ $address = $address->study if blessed $address;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($address) 15 2 17
142  
143 17 ▶ if(!defined $address) { ; }
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $address) { } 0 17 17
elsif (not ref $address) { } 2 15 17
elsif ($address->isa('Mail::Message::Field::Addresses')) { } 11 4 15
elsif ($address->isa('Mail::Message::Field::URIs')) { } 4 0 4
144 elsif(!ref $address)
145 2 { $address =~ s/\bowner-|-(?:owner|bounce|admin)\@//i;
146 2 $address = Mail::Message::Field::Address->new(address => $address);
147 }
148 elsif($address->isa('Mail::Message::Field::Addresses'))
149 { # beautify
150 11 $address = ($address->addresses)[0];
151 11 ▶ my $username = defined $address ? $address->username : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $address ? : 11 0 11
152 11 ▶ if($username =~ s/^owner-|-(owner|bounce|admin)$//i)
Branch: 1 branch
BranchTrueFalseTotal
if ($username =~ s/^owner-|-(owner|bounce|admin)$//i) 0 11 11
153 0 { $address = Mail::Message::Field::Address->new(username => $username, domain => $address->domain);
154 }
155 }
156 elsif($address->isa('Mail::Message::Field::URIs'))
157 4 ▶ { my $uri = first { $_->scheme eq 'mailto' } $address->URIs;
Subroutine __ANON__: called CC=1 SCAR=0.0
158 4 ▶ $address = defined $uri ? Mail::Message::Field::Address->new(address => $uri->to) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $uri ? : 4 0 4
159 }
160 else # Don't understand life anymore :-(
161 0 { undef $address;
162 }
163  
164 17 $self->{MMHL_address} = $address;
165 }
166  
167  
168 sub listname()
169 1 ▶{ my $self = shift;
Subroutine listname: called CC=7 SCAR=23.6
Pod documented
170 1 ▶ exists $self->{MMHL_listname} and return $self->{MMHL_listname};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"MMHL_listname"} and return $self->{"MMHL_listname"} 0 1 1
171  
172 1 my $head = $self->head;
173  
174 # Some lists have a field with the name only
175 1 ▶ my $list = $head->get('List-ID') || $head->get('X-List') || $head->get('X-ML-Name');
Condition33%2/6
$head->get('List-ID') || $head->get('X-List') || $head->get('X-ML-Name')
l!l&&r!l&&!r
001
$head->get("List-ID") or $head->get("X-List")
l!l&&r!l&&!r
001
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 table25%1/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
176  
177 1 my $listname;
178 1 ▶ if(defined $list)
Branch: 2 branches
BranchTrueFalseTotal
if (defined $list) { } 0 1 1
elsif (my $address = $self->address) { } 1 0 1
179 0 { $listname = $list->study->decodedBody;
180 }
181 elsif(my $address = $self->address)
182 1 ▶ { $listname = $address->phrase || $address->address;
Condition33%1/3
$address->phrase || $address->address
l!l&&r!l&&!r
100
MC/DC0%0/2
$address->phrase || $address->address
$address->phrase $address->address
Truth table33%1/3
A || B
A= $address->phraseB= $address->address
ABresult
1X1
011
000
183 }
184  
185 1 $self->{MMHL_listname} = $listname;
186 }
187  
188 #--------------------
189  
190 2 my $list_field_names = qr/
191 ^ (?: List|X-Envelope|X-Original ) -
192 | ^ (?: Precedence|Mailing-List|Approved-By ) $
193 | ^ X-(?: Loop|BeenThere|Sequence|List|Sender|MLServer ) $
194 | ^ X-(?: Mailman|Listar|Egroups|Encartis|ML ) -
195 | ^ X-(?: Archive|Mailing|Original|Mail|ListServer ) -
196 | ^ (?: Mail-Followup|Delivered|Errors|X-Apperently ) -To $
197 /xi;
198  
199 0 ▶sub isListGroupFieldName($) { $_[1] =~ $list_field_names }
Subroutine isListGroupFieldName: not called CC=1 SCAR=6.9
Pod documented
200  
201 #--------------------
202  
203 sub collectFields()
204 19 ▶{ my $self = shift;
Subroutine collectFields: called CC=1 SCAR=0.0
Pod documented
205 19 my @names = map $_->name, $self->head->grepNames($list_field_names);
206 19 $self->addFields(@names);
207 19 @names;
208 }
209  
210 #--------------------
211  
212 sub details()
213 17 ▶{ my $self = shift;
Subroutine details: called CC=8 SCAR=20.9
Pod documented
214 17 ▶ my $type = $self->type || 'Unknown';
Condition50%1/2
$self->type || 'Unknown'
l!l
170
MC/DC0%0/1
$self->type || 'Unknown'
$self->type
Truth table50%1/2
A
A= $self->type
Aresult
11
00
215 17 my $software = $self->software;
216 17 my $version = $self->version;
217  
218 17 ▶ undef $software if defined $software && $type eq $software;
Branch: 1 branch
BranchTrueFalseTotal
if defined $software and $type eq $software 3 14 17
Condition100%3/3
defined $software and $type eq $software
!ll&&!rl&&r
863
MC/DC100%2/2
defined $software and $type eq $software
defined $software $type eq $software
Truth table100%3/3
A and B
A= defined $softwareB= $type eq $software
ABresult
0X0
100
111
219  
220 17 ▶ my $release
Branch: 3 branches
BranchTrueFalseTotal
defined $software ? : 6 11 17
defined $version ? : 6 0 6
defined $version ? : 5 6 11
221 = defined $software
222 ? (defined $version ? " ($software $version)" : " ($software)")
223 : (defined $version ? " ($version)" : '');
224  
225 17 ▶ my $address = $self->address || 'unknown address';
Condition50%1/2
$self->address || 'unknown address'
l!l
170
MC/DC0%0/1
$self->address || 'unknown address'
$self->address
Truth table50%1/2
A
A= $self->address
Aresult
11
00
226 17 my $fields = scalar $self->fields;
227 17 "$type at $address$release, $fields fields";
228 }
229  
230 #--------------------
231  
232 2 1;
« Message/Construct/Bounce.pm ↑ Summary Message/TransferEnc/Binary.pm »