76 lines
2.2 KiB
Plaintext
Executable File
76 lines
2.2 KiB
Plaintext
Executable File
:
|
|
eval 'exec perl -S $0 ${1+"$@"}'
|
|
if $running_under_some_shell;
|
|
##
|
|
## petidomo-kickout -- Petidomo kickout tool
|
|
## Copyright (c) 2000 Ralf S. Engelschall <rse@engelschall.com>
|
|
##
|
|
|
|
my $pattern = $ARGV[0] || die "Usage: petidomo-kickout <address-pattern>";
|
|
|
|
# locate the file with the approval passwords
|
|
my $config = "$ENV{HOME}/.petidomo";
|
|
|
|
# locate the Sendmail program
|
|
my $sendmail = "sendmail";
|
|
foreach my $dir (split(/:/, "$ENV{PATH}:/bin:/sbin:/usr/bin:/usr/sbin:/lib:/usr/lib")) {
|
|
if (-x "$dir/sendmail") {
|
|
$sendmail = "$dir/sendmail";
|
|
last;
|
|
}
|
|
}
|
|
|
|
# locate the Petidomo basedir
|
|
my $basedir = `petidomo --version 2>&1`;
|
|
$basedir =~ s|^.+\((\S+)\).*$|$1|s;
|
|
|
|
# read config
|
|
my $list = {};
|
|
open(FP, "<$config") || die "No ~/.petidomo file found";
|
|
while (<FP>) {
|
|
next if (m|^\s*#.*| or m|^\s*$|);
|
|
if (m|^\s*(\S+)\s+(\S+)|) {
|
|
my ($l, $pw) = ($1, $2);
|
|
$l =~ s|@[^@]+$||;
|
|
if (-f "$basedir/$l.list") {
|
|
$list->{$l} = {};
|
|
$list->{$l}->{PASSWORD} = $pw;
|
|
$list->{$l}->{MEMBERS} = [];
|
|
open(LST, "<$basedir/$l.list");
|
|
while (<LST>) {
|
|
s|\n$||s;
|
|
push(@{$list->{$l}->{MEMBERS}}, $_);
|
|
}
|
|
close(LST);
|
|
}
|
|
}
|
|
}
|
|
close(FP);
|
|
|
|
# iterate over all mailing lists
|
|
foreach my $l (keys(%{$list})) {
|
|
foreach my $m (@{$list->{$l}->{MEMBERS}}) {
|
|
if ($m =~ m|$pattern|) {
|
|
print "petidomo-kickout: $l: <$m> Kickout? [Y/n] ";
|
|
my $yn = <STDIN>;
|
|
$yn =~ s|\n$||s;
|
|
$yn = "y" if ($yn eq '');
|
|
$yn = lc($yn);
|
|
if ($yn eq 'y') {
|
|
open(SM, "|$sendmail petidomo") || die "cannot spawn $sendmail";
|
|
print SM "To: petidomo\n" .
|
|
"\n" .
|
|
"password ".$list->{$l}->{PASSWORD}."\n" .
|
|
"unsubscribe $l $m\n";
|
|
"password ".$list->{petidomo}->{PASSWORD}."\n" .
|
|
"subscribe bounces $m\n";
|
|
close(SM);
|
|
print "petidomo-kickout: kicked out <$m>\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
sleep(1);
|
|
exit(0);
|
|
|