Email::Address::XS and PublicInbox::MsgTime both emit warnings
which are likely to trigger from spam messages. Since this can
be configured to remove spam, just filter out those warnings to
avoid cluttering up stderr with useless information.
use PublicInbox::Import;
use PublicInbox::Filter::Base qw(REJECT);
use Errno qw(ENOENT);
use PublicInbox::Import;
use PublicInbox::Filter::Base qw(REJECT);
use Errno qw(ENOENT);
-our @EXPORT_OK = qw(eml_from_path);
+our @EXPORT_OK = qw(eml_from_path warn_ignore_cb);
use constant {
PERM_UMASK => 0,
use constant {
PERM_UMASK => 0,
delete @{$_[0]}{qw(over mm git search)};
}
delete @{$_[0]}{qw(over mm git search)};
}
+# warnings to ignore when handling spam mailboxes and maybe other places
+sub warn_ignore {
+ my $s = "@_";
+ # Email::Address::XS warnings
+ $s =~ /^Argument contains empty address at /
+ || $s =~ /^Element at index [0-9]+ contains /
+ # PublicInbox::MsgTime
+ || $s =~ /^bogus TZ offset: .+?, ignoring and assuming \+0000/
+ || $s =~ /^bad Date: .+? in /
+}
+
+# this expects to be RHS in this assignment: "local $SIG{__WARN__} = ..."
+sub warn_ignore_cb {
+ my $cb = $SIG{__WARN__} // sub { print STDERR @_ };
+ sub {
+ return if warn_ignore(@_);
+ $cb->(@_);
+ }
+}
+
use strict;
use warnings;
use PublicInbox::Eml;
use strict;
use warnings;
use PublicInbox::Eml;
-use PublicInbox::InboxWritable qw(eml_from_path);
+use PublicInbox::InboxWritable qw(eml_from_path warn_ignore_cb);
use PublicInbox::Filter::Base qw(REJECT);
use PublicInbox::Spamcheck;
use PublicInbox::Sigfd;
use PublicInbox::Filter::Base qw(REJECT);
use PublicInbox::Spamcheck;
use PublicInbox::Sigfd;
# path must be marked as (S)een
$path =~ /:2,[A-R]*S[T-Za-z]*\z/ or return;
my $eml = eml_from_path($path) or return;
# path must be marked as (S)een
$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->{config}->each_inbox(\&remove_eml_i, [ $self, $eml, $path ]);
}
return;
}
my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
return;
}
my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
- local $SIG{__WARN__} = sub {
- $warn_cb->("path: $path\n");
- $warn_cb->(@_);
- };
+ local $SIG{__WARN__} = sub { $warn_cb->("path: $path\n", @_) };
if (!ref($inboxes) && $inboxes eq 'watchspam') {
return _remove_spam($self, $path);
}
if (!ref($inboxes) && $inboxes eq 'watchspam') {
return _remove_spam($self, $path);
}
my $x = import_eml($self, $ibx, $eml);
}
} elsif ($inboxes eq 'watchspam') {
my $x = import_eml($self, $ibx, $eml);
}
} elsif ($inboxes eq 'watchspam') {
+ local $SIG{__WARN__} = warn_ignore_cb();
my $eml = PublicInbox::Eml->new($raw);
my $arg = [ $self, $eml, "$url UID:$uid" ];
$self->{config}->each_inbox(\&remove_eml_i, $arg);
my $eml = PublicInbox::Eml->new($raw);
my $arg = [ $self, $eml, "$url UID:$uid" ];
$self->{config}->each_inbox(\&remove_eml_i, $arg);
my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
local $SIG{__WARN__} = sub {
$batch //= '?';
my $warn_cb = $SIG{__WARN__} || sub { print STDERR @_ };
local $SIG{__WARN__} = sub {
$batch //= '?';
- $warn_cb->("$url UID:$batch\n");
- $warn_cb->(@_);
+ $warn_cb->("$url UID:$batch\n", @_);