Skip to content

Commit

Permalink
Fix sympa-community#295 — Add domain blacklist feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ldidry committed Nov 13, 2018
1 parent 2779fac commit 85acc21
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions default/mail_tt2/report.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@ Warning: this message may already have been sent by one of the list's moderators
[%~ ELSIF report_entry == 'incorrect_email' ~%]
[%|loc(report_param.email || report_param.value)%]Address "%1" is incorrect[%END%]

[%~ ELSIF report_entry == 'blacklisted_domain' ~%]
[%|loc(report_param.email || report_param.value)%]Address "%1" belongs to a blacklisted domain[%END%]

[%~ ELSIF report_entry == 'incorrect_passwd' ~%]
[%|loc%]Provided password is incorrect[%END%]

Expand Down
12 changes: 12 additions & 0 deletions src/lib/Sympa/ConfDef.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,18 @@ our @params = (
'file' => 'wwsympa.conf',
'optional' => 1,
},
{
'name' => 'domains_blacklist',
'gettext_id' =>
'Prevent people to subscribe to a list with adresses using these domains',
'gettext_comment' =>
'This parameter is a comma-separated list.',
'default' => undef,
'sample' => 'example.org,spammer.com',
'split_char' => ',',
'file' => 'sympa.conf',
'optional' => 1,
},

## Not implemented yet.
## {
Expand Down
14 changes: 14 additions & 0 deletions src/lib/Sympa/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3826,6 +3826,20 @@ sub add_list_member {
$new_user->{'email'});
next;
}
if (defined($Conf::Conf{'domains_blacklist'})) {
my @parts = split '@', $who;
my $next = 0;
foreach my $f (split ',', lc($Conf::Conf{'domains_blacklist'})) {
if ($parts[1] && $parts[1] eq $f) {
$log->syslog('err',
'Ignoring %s which uses a blacklisted domain',
$new_user->{'email'});
$next++;
next;
}
}
next if $next;
}
unless (
$current_list_members_count < $self->{'admin'}{'max_list_members'}
|| $self->{'admin'}{'max_list_members'} == 0) {
Expand Down
14 changes: 14 additions & 0 deletions src/lib/Sympa/Request/Handler/add.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ sub _twist {
return undef;
}

if (defined($Conf::Conf{'domains_blacklist'})) {
my @parts = split '@', Sympa::Tools::Text::canonic_email($email);
foreach my $f (split ',', lc($Conf::Conf{'domains_blacklist'})) {
if ($parts[1] && $parts[1] eq $f) {
$self->add_stash($request, 'user', 'blacklisted_domain',
{'email' => $email});
$log->syslog('err',
'ADD command rejected; blacklisted domain for "%s"',
$email);
return undef;
}
}
}

if ($list->is_list_member($email)) {
$self->add_stash($request, 'user', 'already_subscriber',
{'email' => $email, 'listname' => $list->{'name'}});
Expand Down

0 comments on commit 85acc21

Please sign in to comment.