#!/usr/bin/perl -w
-# Copyright (C) 2015, all contributors <meta@public-inbox.org>
+# Copyright (C) 2015 all contributors <meta@public-inbox.org>
# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
#
# Incremental (or one-shot) importer of a slrnpull news spool
=begin usage
export ORIGINAL_RECIPIENT=address@example.com
- public-inbox-init $LISTNAME $GIT_DIR $HTTP_URL $ORIGINAL_RECIPIENT
+ public-inbox-init $INBOX $GIT_DIR $HTTP_URL $ORIGINAL_RECIPIENT
./import_slrnspool SLRNPULL_ROOT/news/foo/bar
=cut
use strict;
sub key {
my ($cfg) = @_;
- "publicinbox.$cfg->{listname}.importslrnspoolstate";
+ "publicinbox.$cfg->{inbox}.importslrnspoolstate";
}
sub get_min {
print STDERR $fn, "\n";
open(my $fh, '<', $fn) or next;
$max = $n + $max_gap;
- my $f = Email::Filter->new(data => eval { local $/; <$fh> });
- my $s = $f->simple;
- # gmane rewrites Received headers, which increases spamminess
- # 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");
+ # prevent process growth by forking a new process for each message
+ my $pid = fork;
+ die "failed to fork: $!\n" unless defined $pid;
+
+ if ($pid == 0) {
+ my $f = Email::Filter->new(data => eval { local $/; <$fh> });
+ close $fh;
+ $fh = undef;
+ my $s = $f->simple;
+
+ # gmane rewrites Received headers, which increases spamminess
+ # 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
- foreach my $drop (qw(Approved)) { $s->header_set($drop) }
+ # triggers for the SA HEADER_SPAM rule
+ foreach my $drop (qw(Approved)) { $s->header_set($drop) }
- # appears to be an old gmane bug:
- $s->header_set('connect()');
+ # appears to be an old gmane bug:
+ $s->header_set('connect()');
- $f->exit(0);
- $f->pipe(@mda);
+ $f->exit(0);
+ $f->pipe(@mda);
+ exit 0;
+ } else {
+ close $fh;
+ waitpid($pid, 0);
+ die "error: $?\n" if $?;
+ }
$ok = $n + 1;
set_min($cfg, $ok);
}