Skip to content

Commit

Permalink
Merge pull request #1098 & #1357 from ikedas/ldidry/fix-1058 by ldidr…
Browse files Browse the repository at this point in the history
…y & ikedas

✨ — Add "bouncers reset", "bouncers del" and "bouncers [--status] review" commands to sympa.pl
  • Loading branch information
ikedas authored Mar 5, 2022
2 parents 9959895 + ffb3c76 commit 587f94c
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ nobase_dist_modules_DATA = \
Sympa/Internals/Workflow.pod
CLI_modules = \
Sympa/CLI/add.pm \
Sympa/CLI/bouncers.pm \
Sympa/CLI/bouncers/del.pm \
Sympa/CLI/bouncers/reset.pm \
Sympa/CLI/check.pm \
Sympa/CLI/close.pm \
Sympa/CLI/conf_2_db.pm \
Expand All @@ -49,6 +52,7 @@ CLI_modules = \
Sympa/CLI/rebuildarc.pm \
Sympa/CLI/reload_list_config.pm \
Sympa/CLI/restore.pm \
Sympa/CLI/review.pm \
Sympa/CLI/send_digest.pm \
Sympa/CLI/show_pending_lists.pm \
Sympa/CLI/sync_list_db.pm \
Expand Down
80 changes: 80 additions & 0 deletions src/lib/Sympa/CLI/bouncers.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4

# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright 2022 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
# 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, see <http://www.gnu.org/licenses/>.

package Sympa::CLI::bouncers;

use strict;
use warnings;

use parent qw(Sympa::CLI);

use constant _options => qw();
use constant _args => qw();
use constant _need_priv => 0;

sub _run {
my $class = shift;
my $options = shift;
my @argv = @_;

Sympa::CLI->run(qw(help bouncers));
}

1;
__END__
=encoding utf-8
=head1 NAME
sympa-bouncers - Manipulate list bounced users
=head1 SYNOPSIS
C<sympa bouncers> I<sub-command> ...
=head1 DESCRIPTION
TBD.
=head1 SUB-COMMANDS
Currently following sub-commands are available.
To see detail of each sub-command, run 'C<sympal.pl help bouncers> I<sub-command>'.
=over
=item L<"sympa bouncers del ..."|sympa-bouncers-del(1)>
Unsubscribe bounced users from a list
=item L<"sympa bouncers reset ..."|sympa-bouncers-reset(1)>
Reset the bounce status of all bounced users of a list
=back
=head1 HISTORY
This option was added on Sympa 6.2.69b.
=cut
95 changes: 95 additions & 0 deletions src/lib/Sympa/CLI/bouncers/del.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4

# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright 2022 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
# 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, see <http://www.gnu.org/licenses/>.

package Sympa::CLI::bouncers::del;

use strict;
use warnings;

use Sympa;
use Sympa::List;
use Sympa::Spindle::ProcessRequest;

use parent qw(Sympa::CLI::bouncers);

use constant _options => qw();
use constant _args => qw(list);
use constant _need_priv => 1;

sub _run {
my $class = shift;
my $options = shift;
my $list = shift;

my @bounced;
for (
my $i = $list->get_first_bouncing_list_member();
$i;
$i = $list->get_next_bouncing_list_member()
) {
push @bounced, $i->{email};
}

unless (scalar @bounced) {
printf STDERR "No bounced users in list %s.\n", $list->get_id;
exit 1;
}

my $spindle = Sympa::Spindle::ProcessRequest->new(
context => $list,
action => 'del',
role => 'member',
email => [@bounced],
sender => Sympa::get_address($list, 'listmaster'),
scenario_context => {skip => 1},
);
unless ($spindle and $spindle->spin and $class->_report($spindle)) {
printf STDERR "Failed to delete email addresses from %s.\n",
$list->get_id;
exit 1;
}

exit 0;
}

1;
__END__
=encoding utf-8
=head1 NAME
sympa-bouncers-del - Unsubscribe bounced users from a list
=head1 SYNOPSIS
C<sympa bouncers del> I<list>[ C<@>I<domain> ]
=head1 DESCRIPTION
Unsubscribe bounced users from a list.
=head1 HISTORY
This option was added on Sympa 6.2.69b.
=cut
97 changes: 97 additions & 0 deletions src/lib/Sympa/CLI/bouncers/reset.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4

# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright 2022 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
# 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, see <http://www.gnu.org/licenses/>.

package Sympa::CLI::bouncers::reset;

use strict;
use warnings;

use Sympa;
use Sympa::List;
use Sympa::Spindle::ProcessRequest;

use parent qw(Sympa::CLI::bouncers);

use constant _options => qw();
use constant _args => qw(list);
use constant _need_priv => 1;

sub _run {
my $class = shift;
my $options = shift;
my $list = shift;

my ($errors, $users) = (0, 0);
for (
my $i = $list->get_first_bouncing_list_member();
$i;
$i = $list->get_next_bouncing_list_member()
) {
if ($list->update_list_member(
$i->{email},
bounce => undef,
update_date => time,
bounce_score => 0
)
) {
$users++;
} else {
printf STDERR "Unable to cancel bounce error for %s.\n", $i->{email};
}
$errors++;
}

if ($errors) {
my $text =
($users > 1)
? "Canceled %i bounce errors on %i.\n"
: "Canceled %i bounce error on %i.\n";
printf $text, $users, $errors;
} else {
print "No bounce errors to cancel.\n";
}

exit 0;
}

1;
__END__
=encoding utf-8
=head1 NAME
sympa-bouncers-reset - Reset the bounce status of all bounced users of a list
=head1 SYNOPSIS
C<sympa bouncers reset> I<list>[ C<@>I<domain> ]
=head1 DESCRIPTION
Reset the bounce status of all bounced users of a list
=head1 HISTORY
This option was added on Sympa 6.2.69b.
=cut
104 changes: 104 additions & 0 deletions src/lib/Sympa/CLI/review.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4

# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright 2022 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
# 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, see <http://www.gnu.org/licenses/>.

package Sympa::CLI::review;

use strict;
use warnings;
use English qw(-no_match_vars);

use Sympa;
use Sympa::List;

use parent qw(Sympa::CLI);

use constant _options => qw(status);
use constant _args => qw(list);

sub _run {
my $class = shift;
my $options = shift;
my $list = shift;

if ($list) {
my @members = $list->get_members(
'unconcealed_member',
order => 'email'
);
my @bounced = ();
my @suspended = ();

printf "%i member(s) in list %s.\n",
scalar(@members), $list->get_id;
for my $member (@members) {
printf "%s\n", $member->{email};
push @bounced, $member->{'email'}
if defined $member->{'bounce'};
push @suspended, $member->{'email'}
if defined $member->{'suspend'};
}

if ($options->{'status'}) {
print "------------------\n";

printf "%i bounced member(s) in list %s.\n",
scalar(@bounced), $list->get_id;
for my $member (@bounced) {
printf "%s\n", $member;
}

printf "%i suspended member(s) in list %s.\n",
scalar(@suspended), $list->get_id;
for my $member (@suspended) {
printf "%s\n", $member;
}
}

exit 0;
} else {
printf STDERR "Error : please provide the name of a list\n";
exit 1;
}
}

1;
__END__
=encoding utf-8
=head1 NAME
sympa-review - Show subscribers of the list.
=head1 SYNOPSIS
C<sympa review> S<[ C<--status> ]> I<list>[ C<@>I<domain> ]
=head1 DESCRIPTION
Show subscribers of the list.
=head1 HISTORY
This option was added on Sympa 6.2.69b.
=cut
Loading

0 comments on commit 587f94c

Please sign in to comment.