-# Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# ref: https://cr.yp.to/proto/maildir.html
}
sub new {
- my ($class, $config) = @_;
+ my ($class, $cfg) = @_;
my (%mdmap, $spamc);
my (%imap, %nntp); # url => [inbox objects] or 'watchspam'
# indefinitely...
foreach my $pfx (qw(publicinboxwatch publicinboxlearn)) {
my $k = "$pfx.watchspam";
- defined(my $dirs = $config->{$k}) or next;
+ defined(my $dirs = $cfg->{$k}) or next;
$dirs = PublicInbox::Config::_array($dirs);
for my $dir (@$dirs) {
my $url;
my $k = 'publicinboxwatch.spamcheck';
my $default = undef;
- my $spamcheck = PublicInbox::Spamcheck::get($config, $k, $default);
+ my $spamcheck = PublicInbox::Spamcheck::get($cfg, $k, $default);
$spamcheck = _spamcheck_cb($spamcheck) if $spamcheck;
- $config->each_inbox(sub {
+ $cfg->each_inbox(sub {
# need to make all inboxes writable for spam removal:
my $ibx = $_[0] = PublicInbox::InboxWritable->new($_[0]);
spamcheck => $spamcheck,
mdmap => \%mdmap,
mdre => $mdre,
- config => $config,
+ pi_cfg => $cfg,
imap => scalar keys %imap ? \%imap : undef,
nntp => scalar keys %nntp? \%nntp : undef,
importers => {},
$path =~ /:2,[A-R]*S[T-Za-z]*\z/ or return;
my $eml = eml_from_path($path) or return;
local $SIG{__WARN__} = warn_ignore_cb();
- $self->{config}->each_inbox(\&remove_eml_i, $self, $eml, $path);
+ $self->{pi_cfg}->each_inbox(\&remove_eml_i, $self, $eml, $path);
}
sub import_eml ($$$) {
warn "unmappable dir: $1\n";
return;
}
- my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
+ my $warn_cb = $SIG{__WARN__} || \&CORE::warn;
local $SIG{__WARN__} = sub {
my $pfx = ($_[0] // '') =~ /^([A-Z]: )/g ? $1 : '';
$warn_cb->($pfx, "path: $path\n", @_);
# flesh out common IMAP-specific data structures
sub imap_common_init ($) {
my ($self) = @_;
- my $cfg = $self->{config};
+ my $cfg = $self->{pi_cfg};
my $mic_args = {}; # scheme://authority => Mail:IMAPClient arg
for my $url (sort keys %{$self->{imap}}) {
my $uri = PublicInbox::URIimap->new($url);
if ($flags =~ /\\Seen\b/) {
local $SIG{__WARN__} = warn_ignore_cb();
my $eml = PublicInbox::Eml->new($raw);
- $self->{config}->each_inbox(\&remove_eml_i,
+ $self->{pi_cfg}->each_inbox(\&remove_eml_i,
$self, $eml, "$url UID:$uid");
}
} else {
my $key = $req;
$key =~ s/\.PEEK//;
my ($uids, $batch);
- my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
+ my $warn_cb = $SIG{__WARN__} || \&CORE::warn;
local $SIG{__WARN__} = sub {
my $pfx = ($_[0] // '') =~ /^([A-Z]: )/g ? $1 : '';
$batch //= '?';
delete $self->{opendirs};
PublicInbox::DS->Reset;
%SIG = (%SIG, %{$self->{sig}}, CHLD => 'DEFAULT');
- PublicInbox::Sigfd::sig_setmask($self->{oldset});
+ PublicInbox::DS::sig_setmask($self->{oldset});
}
sub watch_atfork_parent ($) {
my ($self) = @_;
_done_for_now($self);
- PublicInbox::Sigfd::block_signals();
+ PublicInbox::DS::block_signals();
}
sub imap_idle_requeue ($) { # DS::add_timer callback
my ($self, $url_intvl) = @_;
my ($url, $intvl) = @$url_intvl;
pipe(my ($r, $w)) or die "pipe: $!";
- defined(my $pid = fork) or die "fork: $!";
+ my $seed = rand(0xffffffff);
+ my $pid = fork // die "fork: $!";
if ($pid == 0) {
+ srand($seed);
+ eval { Net::SSLeay::randomize() };
close $r;
watch_atfork_child($self);
watch_imap_idle_1($self, $url, $intvl);
imap_idle_fork($self, $url_intvl);
}
};
- PublicInbox::Sigfd::sig_setmask($oldset);
+ PublicInbox::DS::sig_setmask($oldset);
die $@ if $@;
}
- goto(&fs_scan_step) if $self->{mdre};
+ fs_scan_step($self) if $self->{mdre};
}
sub watch_imap_fetch_all ($$) {
return if $self->{quit};
pipe(my ($r, $w)) or die "pipe: $!";
my $oldset = watch_atfork_parent($self);
+ my $seed = rand(0xffffffff);
my $pid = fork;
if (defined($pid) && $pid == 0) {
+ srand($seed);
+ eval { Net::SSLeay::randomize() };
close $r;
watch_atfork_child($self);
if ($urls->[0] =~ m!\Aimaps?://!i) {
close $w;
_exit(0);
}
- PublicInbox::Sigfd::sig_setmask($oldset);
+ PublicInbox::DS::sig_setmask($oldset);
die "fork: $!" unless defined $pid;
$self->{poll_pids}->{$pid} = [ $intvl, $urls ];
PublicInbox::EOFpipe->new($r, \&reap, [$pid, \&poll_fetch_reap, $self]);
# flesh out common NNTP-specific data structures
sub nntp_common_init ($) {
my ($self) = @_;
- my $cfg = $self->{config};
+ my $cfg = $self->{pi_cfg};
my $nn_args = {}; # scheme://authority => Net::NNTP->new arg
for my $url (sort keys %{$self->{nntp}}) {
my $sec = uri_section(uri_new($url));
$beg = $l_art + 1;
warn "I: $url fetching ARTICLE $beg..$end\n";
- my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
+ my $warn_cb = $SIG{__WARN__} || \&CORE::warn;
my ($err, $art);
local $SIG{__WARN__} = sub {
my $pfx = ($_[0] // '') =~ /^([A-Z]: )/g ? $1 : '';
}
} elsif ($inboxes eq 'watchspam') {
my $eml = PublicInbox::Eml->new(\$raw);
- $self->{config}->each_inbox(\&remove_eml_i,
+ $self->{pi_cfg}->each_inbox(\&remove_eml_i,
$self, $eml, "$url ARTICLE $art");
} else {
die "BUG: destination unknown $inboxes";
sub scan {
my ($self, $op) = @_;
push @{$self->{ops}}, $op;
- goto &fs_scan_step;
+ fs_scan_step($self);
}
sub _importer_for {