1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# fields/mail-address -- lintian check script (rewrite) -*- perl -*-
#
# Copyright (C) 2004 Marc Brockschmidt
# Copyright (C) 2020 Felix Lechner
# Copyright (C) 2020 Chris Lamb <lamby@debian.org>
#
# Parts of the code were taken from the old check script, which
# was Copyright (C) 1998 Richard Braakman (also licensed under the
# GPL 2 or higher)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, you can find it on the World Wide
# Web at https://www.gnu.org/copyleft/gpl.html, or write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.
package Lintian::Check::Fields::MailAddress;
use v5.20;
use warnings;
use utf8;
use Const::Fast;
use Data::Validate::Domain;
use Email::Address::XS;
use List::SomeUtils qw(any all);
use List::UtilsBy qw(uniq_by);
use Moo;
use namespace::clean;
with 'Lintian::Check';
const my $QA_GROUP_PHRASE => 'Debian QA Group';
const my $QA_GROUP_ADDRESS => 'packages@qa.debian.org';
const my $ARROW => q{ -> };
# list of addresses known to bounce messages from role accounts
my @KNOWN_BOUNCE_ADDRESSES = qw(
ubuntu-devel-discuss@lists.ubuntu.com
);
sub always {
my ($self) = @_;
my @singles = qw(Maintainer Changed-By);
my @groups = qw(Uploaders);
my @singles_present
= grep { $self->processable->fields->declares($_) } @singles;
my @groups_present
= grep { $self->processable->fields->declares($_) } @groups;
my %parsed;
for my $role (@singles_present, @groups_present) {
my $value = $self->processable->fields->value($role);
$parsed{$role} = [Email::Address::XS->parse($value)];
}
for my $role (keys %parsed) {
my @invalid = grep { !$_->is_valid } @{$parsed{$role}};
$self->hint('malformed-contact', $role, $_->original)for @invalid;
my @valid = grep { $_->is_valid } @{$parsed{$role}};
my @unique = uniq_by { $_->format } @valid;
$self->check_single_address($role, $_) for @unique;
}
for my $role (@singles_present) {
$self->hint('too-many-contacts', $role,
$self->processable->fields->value($role))
if @{$parsed{$role}} > 1;
}
for my $role (@groups_present) {
my @valid = grep { $_->is_valid } @{$parsed{$role}};
my @addresses = map { $_->address } @valid;
my %count;
$count{$_}++ for @addresses;
my @duplicates = grep { $count{$_} > 1 } keys %count;
$self->hint('duplicate-contact', $role, $_) for @duplicates;
}
return;
}
sub check_single_address {
my ($self, $role, $parsed) = @_;
$self->hint('mail-contact', $role, $parsed->format);
unless (all { length } ($parsed->address, $parsed->user, $parsed->host)) {
$self->hint('incomplete-mail-address', $role, $parsed->format);
return;
}
$self->hint('bogus-mail-host', $role, $parsed->address)
unless is_domain($parsed->host, {domain_disable_tld_validation => 1});
$self->hint('mail-address-loops-or-bounces',$role, $parsed->address)
if any { $_ eq $parsed->address } @KNOWN_BOUNCE_ADDRESSES;
unless (length $parsed->phrase) {
$self->hint('no-phrase', $role, $parsed->format);
return;
}
$self->hint('root-in-contact', $role, $parsed->format)
if $parsed->user eq 'root' || $parsed->phrase eq 'root';
# Debian QA Group
$self->hint('faulty-debian-qa-group-phrase',
$role, $parsed->phrase . $ARROW . $QA_GROUP_PHRASE)
if $parsed->address eq $QA_GROUP_ADDRESS
&& $parsed->phrase ne $QA_GROUP_PHRASE;
$self->hint('faulty-debian-qa-group-address',
$role, $parsed->address . $ARROW . $QA_GROUP_ADDRESS)
if ( $parsed->phrase =~ /\bdebian\s+qa\b/i
&& $parsed->address ne $QA_GROUP_ADDRESS)
|| $parsed->address eq 'debian-qa@lists.debian.org';
$self->hint('mailing-list-on-alioth', $role, $parsed->address)
if $parsed->host eq 'lists.alioth.debian.org';
return;
}
1;
# Local Variables:
# indent-tabs-mode: nil
# cperl-indent-level: 4
# End:
# vim: syntax=perl sw=4 sts=4 sr et
|