]> Sergey Matveev's repositories - public-inbox.git/blobdiff - scripts/import_slrnspool
import_slrnspool: graceful exit for interruptibility
[public-inbox.git] / scripts / import_slrnspool
index ea7a97bf69689bdf85950264d9919cd1fccd5b17..d95836d69c6a8937a9a97bd20d645a05c0c6650f 100755 (executable)
@@ -14,14 +14,22 @@ use PublicInbox::Config;
 use Email::Filter;
 use Email::LocalDelivery;
 sub usage { "Usage:\n".join('',grep(/\t/, `head -n 10 $0`)) }
+my $exit = 0;
+my $sighandler = sub { $exit = 1 };
+$SIG{INT} = $sighandler;
+$SIG{TERM} = $sighandler;
 my $spool = shift @ARGV or die usage();
 my $recipient = $ENV{ORIGINAL_RECIPIENT};
 defined $recipient or die usage();
-my @mda = qw(public-inbox-mda);
 my $config = PublicInbox::Config->new;
 my $cfg = $config->lookup($recipient);
 defined $cfg or exit(1);
-use Data::Dumper; print STDERR Dumper($cfg);
+my @mda;
+if ($ENV{'FILTER'}) {
+       @mda = qw(public-inbox-mda);
+} else {
+       @mda = (qw(ssoma-mda -1), $cfg->{mainrepo});
+}
 
 sub get_min {
        my ($cfg) = @_;
@@ -41,7 +49,7 @@ my $ok;
 my $max_gap = 10000;
 my $max = $n + $max_gap;
 
-for (; $n < $max; $n++) {
+for (; $exit == 0 && $n < $max; $n++) {
        my $fn = "$spool/$n";
        print STDERR $fn, "\n";
        open(my $fh, '<', $fn) or next;