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 CC 66 SCAR 57.4
CC
66
Cov
7%
from
650.0
address
380.0
init
72.0
CRAP 310.0
↑ Summary Message/Construct/Build.pm »
1 # Copyrights 2001-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 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.012';
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 ▶ $self->log(ERROR =>
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mi 0 0 0
32 "Cannot convert \"$address\" into an address object"), return
33 unless defined $mi;
34  
35 0 $address = $mi;
36 }
37 0 ▶ $self->{MMHL_address} = $address if defined $args->{address};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"address"} 0 0 0
38  
39 0 ▶ $self->{MMHL_listname} = $args->{listname} if defined $args->{listname};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"listname"} 0 0 0
40 0 ▶ $self->{MMHL_rfc} = $args->{rfc} if defined $args->{rfc};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"rfc"} 0 0 0
41 0 $self->{MMHL_fns} = [];
42 0 $self;
43 }
44  
45 #------------------------------------------
46  
47  
48 sub from($)
49 0 ▶{ my ($class, $from) = @_;
Subroutine from: not called CC=25 SCAR=64.8
Pod documented
50 0 ▶ my $head = $from->isa('Mail::Message::Head') ? $from : $from->head;
Branch: 1 branch
BranchTrueFalseTotal
$from->isa('Mail::Message::Head') ? : 0 0 0
51 0 my $self = $class->new(head => $head);
52  
53 0 ▶ return () unless $self->collectFields;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->collectFields 0 0 0
54  
55 0 my ($type, $software, $version, $field);
56 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
57 0 { ($software, $version) = $communigate =~ m/^(.*)\s+LIST\s*([\d.]+)\s*$/i;
58 0 ▶ $type = ($software =~ m/Pro/ ? 'CommuniGatePro' : 'CommuniGate');
Branch: 1 branch
BranchTrueFalseTotal
$software =~ /Pro/ ? : 0 0 0
59 }
60 elsif(my $mailman = $head->get('X-Mailman-Version'))
61 0 { $version = "$mailman";
62 0 $type = 'Mailman';
63 }
64 elsif(my $majordomo = $head->get('X-Majordomo-Version'))
65 0 { $version = "$majordomo";
66 0 $type = 'Majordomo';
67 }
68 elsif(my $ecartis = $head->get('X-Ecartis-Version'))
69 0 { ($software, $version) = $ecartis =~ m/^(.*)\s+(v[\d.]+)/;
70 0 $type = 'Ecartis';
71 }
72 elsif(my $listar = $head->get('X-Listar-Version'))
73 0 { ($software, $version) = $listar =~ m/^(.*?)\s+(v[\w.]+)/;
74 0 $type = 'Listar';
75 }
76 ▶ 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
77 && $field =~ m/listbox/i)
78 0 { ($software, $version) = $field =~ m/^(\S*)\s*(v[\d.]+)\s*$/;
79 0 $type = 'Listbox';
80 }
81 0 ▶ elsif($field = first { m!LISTSERV-TCP/IP!s } $head->get('Received'))
Subroutine __ANON__: not called CC=1 SCAR=6.9
82 { # Listserv is hard to recognise
83 0 ($software, $version) = $field =~
84 m!\( (LISTSERV-TCP/IP) \s+ release \s+ (\S+) \)!xs;
85 0 $type = 'Listserv';
86 }
87 ▶ 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
88 && $field =~ m[archive/latest])
89 0 { $type = 'Smartlist' }
90 ▶ 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
91 0 { $type = 'YahooGroups' }
92 ▶ 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
93 0 { $type = 'Ezmlm' }
94 elsif(my $fml = $head->get('X-MLServer'))
95 0 { ($software, $version) = $fml =~ m/^\s*(\S+)\s*\[\S*\s*([^\]]*?)\s*\]/;
96 0 $type = 'FML';
97 }
98 ▶ 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
99 || $head->get('List-Unsubscribe'))
100 && $field =~ m/sympa/i)
101 0 { $type = 'Sympa' }
102 0 ▶ elsif(first { m/majordom/i } $head->get('Received'))
Subroutine __ANON__: not called CC=1 SCAR=6.9
103 { # Majordomo is hard to recognize
104 0 $type = "Majordomo";
105 }
106 ▶ 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
107 0 { $type = "Listbox" }
108  
109 0 $self->detected($type, $software, $version);
110 0 $self;
111 }
112  
113 #------------------------------------------
114  
115  
116 sub rfc()
117 0 ▶{ my $self = shift;
Subroutine rfc: not called CC=4 SCAR=30.0
Pod documented
118 0 ▶ return $self->{MMHL_rfc} if defined $self->{MMHL_rfc};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MMHL_rfc"} 0 0 0
119  
120 0 my $head = $self->head;
121 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
122 : defined $head->get('List-Id') ? 'rfc2919'
123 : undef;
124 }
125  
126 #------------------------------------------
127  
128  
129 sub address()
130 0 ▶{ my $self = shift;
Subroutine address: not called CC=19 SCAR=59.4
Pod documented
131 0 ▶ return $self->{MMHL_address} if exists $self->{MMHL_address};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MMHL_address"} 0 0 0
132  
133 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
134 0 my $head = $self->head;
135  
136 0 my ($field, $address);
137 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
138 0 ▶ { $address = $1 if $field =~ m/\<([^>]+)\>/ }
Branch: 1 branch
BranchTrueFalseTotal
if $field =~ /\<([^>]+)\>/ 0 0 0
139 elsif($type eq 'YahooGroups')
140 0 { $address = $head->get('X-Apparently-To')->unfoldedBody }
141 elsif($type eq 'Listserv')
142 0 { $address = $head->get('Sender') }
143  
144 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
145 || $head->get('Sender');
146 0 ▶ $address = $address->study if ref $address;
Branch: 1 branch
BranchTrueFalseTotal
if ref $address 0 0 0
147  
148 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
149 elsif(!ref $address)
150 0 { $address =~ s/\bowner-|-(?:owner|bounce|admin)\@//i;
151 0 $address = Mail::Message::Field::Address->new(address => $address);
152 }
153 elsif($address->isa('Mail::Message::Field::Addresses'))
154 { # beautify
155 0 $address = ($address->addresses)[0];
156 0 ▶ my $username = defined $address ? $address->username : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $address ? : 0 0 0
157 0 ▶ if($username =~ s/^owner-|-(owner|bounce|admin)$//i)
Branch: 1 branch
BranchTrueFalseTotal
if ($username =~ s/^owner-|-(owner|bounce|admin)$//i) 0 0 0
158 0 { $address = Mail::Message::Field::Address->new
159 (username => $username, domain => $address->domain);
160 }
161 }
162 elsif($address->isa('Mail::Message::Field::URIs'))
163 0 ▶ { my $uri = first { $_->scheme eq 'mailto' } $address->URIs;
Subroutine __ANON__: not called CC=1 SCAR=6.9
164 0 ▶ $address = defined $uri
Branch: 1 branch
BranchTrueFalseTotal
defined $uri ? : 0 0 0
165 ? Mail::Message::Field::Address->new(address => $uri->to)
166 : undef;
167 }
168 else # Don't understand life anymore :-(
169 0 { undef $address;
170 }
171  
172 0 $self->{MMHL_address} = $address;
173 }
174  
175 #------------------------------------------
176  
177  
178 sub listname()
179 0 ▶{ my $self = shift;
Subroutine listname: not called CC=7 SCAR=40.3
Pod documented
180 0 ▶ return $self->{MMHL_listname} if exists $self->{MMHL_listname};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MMHL_listname"} 0 0 0
181  
182 0 my $head = $self->head;
183  
184 # Some lists have a field with the name only
185 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
186 || $head->get('X-ML-Name');
187  
188 0 my $listname;
189 0 ▶ if(defined $list)
Branch: 2 branches
BranchTrueFalseTotal
if (defined $list) { } 0 0 0
elsif (my $address = $self->address) { } 0 0 0
190 0 { $listname = $list->study->decodedBody;
191 }
192 elsif(my $address = $self->address)
193 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
194 }
195  
196 0 $self->{MMHL_listname} = $listname;
197 }
198  
199 #------------------------------------------
200  
201  
202 2 my $list_field_names
203 = qr/ ^ (?: List|X-Envelope|X-Original ) -
204 | ^ (?: Precedence|Mailing-List|Approved-By ) $
205 | ^ X-(?: Loop|BeenThere|Sequence|List|Sender|MLServer ) $
206 | ^ X-(?: Mailman|Listar|Egroups|Encartis|ML ) -
207 | ^ X-(?: Archive|Mailing|Original|Mail|ListServer ) -
208 | ^ (?: Mail-Followup|Delivered|Errors|X-Apperently ) -To $
209 /xi;
210  
211 0 ▶sub isListGroupFieldName($) { $_[1] =~ $list_field_names }
Subroutine isListGroupFieldName: not called CC=1 SCAR=6.9
Pod documented
212  
213 #------------------------------------------
214  
215  
216 sub collectFields()
217 0 ▶{ my $self = shift;
Subroutine collectFields: not called CC=1 SCAR=6.9
Pod documented
218 0 my @names = map { $_->name } $self->head->grepNames($list_field_names);
219 0 $self->addFields(@names);
220 0 @names;
221 }
222  
223 #------------------------------------------
224  
225  
226 sub details()
227 0 ▶{ my $self = shift;
Subroutine details: not called CC=8 SCAR=42.8
Pod documented
228 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
229  
230 0 my $software = $self->software;
231 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
232 0 my $version = $self->version;
233 0 ▶ my $release
Branch: 3 branches
BranchTrueFalseTotal
defined $software ? : 0 0 0
defined $version ? : 0 0 0
defined $version ? : 0 0 0
234 = defined $software
235 ? (defined $version ? " ($software $version)" : " ($software)")
236 : (defined $version ? " ($version)" : '');
237  
238 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
239 0 my $fields = scalar $self->fields;
240 0 "$type at $address$release, $fields fields";
241 }
242  
243 #------------------------------------------
244  
245  
246 2 1;
↑ Summary Message/Construct/Build.pm »