exec perl -x -S $0 ${1+"$@"}
if ($] !~ /^5\..*/) {
foreach (split(/:/, $ENV{PATH})) { exec("$_/perl5", "-x", "-S", $0, @ARGV) if (-x "$_/perl5");
}
die "Your perl is too old; I need perl 5.\n";
}
eval join("\n", <DATA>);
if ($@) { die "$@"; }
__END__
require 5;
$| = 1;
die "must not run as root" if ($< == 0);
if(@ARGV < 1) {
print "usage: masssievec <path to sievec> [imapd.conf]\n";
exit;
}
$SIEVEC = shift @ARGV;
$imapdconf = shift @ARGV;
if(!defined($imapdconf)) {
$imapdconf = "/etc/imapd.conf";
}
$sievedir = "/usr/sieve";
if(! -x $SIEVEC) {
print "$SIEVEC is not executable\n";
exit;
}
if($SIEVEC !~ /^\//) {
print "$SIEVEC is not an absolute path\n";
exit;
}
sub read_conf {
my $file = shift;
open CONF, $file or die "can't open $file";
while (<CONF>) {
if (/^ next;
}
if (/\@include:\s+(.*)$/) {
push @configs, $1;
}
if (/^sieveusehomedir:\s+(1|t|yes|on)/) {
$nosievedir = 1;
print "you are storing sieve scripts in user's home directories, this script cannot deal with that\n";
exit;
}
if (/^sievedir:\s+(.*)$/) {
$sievedir = $1;
}
}
close CONF;
}
push @configs, $imapdconf;
while ($conf = shift @configs) {
read_conf($conf);
}
print "you are using $sievedir as your sieve directory.\n";
opendir TOP, $sievedir;
while (defined($s = readdir TOP)) {
next if ($s eq "." || $s eq "..");
chdir $sievedir . "/$s";
opendir THISONE, ".";
while(defined($t = readdir THISONE)) {
next if ($t eq "." || $t eq "..");
print "processing user $t\n";
chdir $t;
opendir USER, ".";
while(defined($u = readdir USER)) {
next if ($u eq "." || $u eq "..");
if($u eq "default" && -l $u) {
$dest = readlink $u;
next unless($dest =~ m/\.script$/);
$dest =~ s/\.script$//;
symlink "$dest.bc", "defaultbc" || warn "can't symlink $dest.bc to defaultbc: $!";
unlink ("default");
} elsif ($u eq "default.bc" && -l $u) {
$dest = readlink $u;
next unless($dest =~ m/\.bc$/ && $dest ne "default.bc");
symlink "$dest", "defaultbc" || warn "can't symlink $dest to defaultbc: $!";
unlink ("default.bc");
} elsif ($u eq "default" || $u eq "default.bc") {
warn "$u is not a symlink";
} else {
next unless($u =~ m/\.script$/);
$out = $u;
$out =~ s/\.script$//;
FORK: {
if($pid = fork()) {
waitpid $pid, 0;
} elsif (defined $pid) {
exec $SIEVEC, $u, "$out.bc";
die "souldn't be here";
} elsif ($! =~ /No more process/) {
sleep 5; redo FORK;
} else {
die "cant fork: $!";
}
}
$rc = $? & 0xff00;
$rc >>= 8;
if($rc) {
print "got error compiling $u.\n";
}
}
}
chdir $sievedir . "/$s";
}
closedir THISONE;
}
closedir TOP