]> Sergey Matveev's repositories - public-inbox.git/blobdiff - scripts/import_slrnspool
import_slrnspool: load private config key
[public-inbox.git] / scripts / import_slrnspool
index fec7ebf15b092ce2118aa43bb96e7af8af4fe902..e55c96c7dcde95b376db44f5934bf96fe4d22286 100755 (executable)
@@ -14,25 +14,45 @@ 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 {
+sub key {
        my ($cfg) = @_;
-       $cfg->{importslrnspoolstate} || 0;
+       "publicinbox.$cfg->{listname}.importslrnspoolstate";
+}
+
+sub get_min {
+       my $f = PublicInbox::Config->default_file;
+       my @cmd = (qw/git config/, "--file=$f", key($cfg));
+       use IPC::Run qw/run/;
+
+       my $in = '';
+       my $out = '';
+       unless (run(\@cmd, \$in, \$out)) {
+               $out = 0;
+       }
+       int($out);
 }
 
 sub set_min {
        my ($cfg, $num) = @_;
        my $f = PublicInbox::Config->default_file;
-       my @cmd = (qw/git config/, "--file=$f",
-                  "publicinbox.$cfg->{listname}.importslrnspoolstate", $num);
+       my @cmd = (qw/git config/, "--file=$f", key($cfg), $num);
        system(@cmd) == 0 or die join(' ', @cmd). " failed: $?\n";
 }
 
@@ -41,7 +61,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;
@@ -50,10 +70,13 @@ for (; $n < $max; $n++) {
        my $s = $f->simple;
 
        # gmane rewrites Received headers, which increases spamminess
-       my @h = $s->header('Original-Received');
-       if (@h) {
-               $s->header_set('Received', @h);
-               $s->header_set('Original-Received');
+       # Some older archives set Original-To
+       foreach my $x (qw(Received To)) {
+               my @h = $s->header("Original-$x");
+               if (@h) {
+                       $s->header_set($x, @h);
+                       $s->header_set("Original-$x");
+               }
        }
 
        # triggers for the SA HEADER_SPAM rule