From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 5/4] watch_maildir: tighten up path checks
Date: Sun, 19 Jun 2016 03:44:10 +0000 [thread overview]
Message-ID: <20160619034410.GA15456@dcvr.yhbt.net> (raw)
In-Reply-To: <20160619002847.26685-1-e@80x24.org>
Only mark seen messages as spam, otherwise it could be
too aggressive and cause problems or over training.
We wouldn't want a wayward FIFO ruining our day, either :)
---
lib/PublicInbox/WatchMaildir.pm | 12 +++++-------
t/watch_maildir.t | 3 ++-
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index cb64f89..4468a44 100644
--- a/lib/PublicInbox/WatchMaildir.pm
+++ b/lib/PublicInbox/WatchMaildir.pm
@@ -71,6 +71,7 @@ sub _try_fsn_paths {
sub _check_spam {
my ($self, $path) = @_;
+ $path =~ /:2,[A-R]*S[T-Z]*\z/ or return;
my $mime = _path_to_mime($path) or return;
_force_mid($mime);
foreach my $inbox (values %{$self->{mdmap}}) {
@@ -107,6 +108,9 @@ sub _force_mid {
sub _try_path {
my ($self, $path) = @_;
+ my @p = split(m!/+!, $path);
+ return unless $p[-1] =~ /\A[a-zA-Z0-9][\w:,=\.]+\z/;
+ return unless -f $path;
if ($path !~ $self->{mdre}) {
warn "unrecognized path: $path\n";
return;
@@ -155,13 +159,7 @@ sub scan {
next;
}
while (my $fn = readdir($dh)) {
- next unless $fn =~ /\A[a-zA-Z0-9][\w:,=\.]+\z/;
- $fn = "$dir/$fn";
- if (-f $fn) {
- _try_path($self, $fn);
- } else {
- warn "not a file: $fn\n";
- }
+ _try_path($self, "$dir/$fn");
}
closedir $dh;
}
diff --git a/t/watch_maildir.t b/t/watch_maildir.t
index 8a2c934..e8c9740 100644
--- a/t/watch_maildir.t
+++ b/t/watch_maildir.t
@@ -25,6 +25,7 @@ Date: Sat, 18 Jun 2016 00:00:00 +0000
something
EOF
PublicInbox::Emergency->new($maildir)->prepare(\$msg);
+ok(POSIX::mkfifo("$maildir/cur/fifo", 0777));
my $sem = PublicInbox::Emergency->new($spamdir); # create dirs
my $config = PublicInbox::Config->new({
@@ -47,7 +48,7 @@ my $write_spam = sub {
my @new = glob("$spamdir/new/*");
is(scalar @new, 1);
my @p = split(m!/+!, $new[0]);
- ok(link($new[0], "$spamdir/cur/".$p[-1]));
+ ok(link($new[0], "$spamdir/cur/".$p[-1].":2,S"));
is(unlink($new[0]), 1);
};
$write_spam->();
prev parent reply other threads:[~2016-06-19 3:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-19 0:28 [PATCH 0/4] watch improvements for mirroring Eric Wong
2016-06-19 0:28 ` [PATCH 1/4] emergency: avoid needless mkpath dependency Eric Wong
2016-06-19 0:28 ` [PATCH 2/4] watch_maildir: add scan test Eric Wong
2016-06-19 0:28 ` [PATCH 3/4] watch_maildir: spam removal support Eric Wong
2016-06-19 0:28 ` [PATCH 4/4] import: allow messages without subject Eric Wong
2016-06-19 3:44 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160619034410.GA15456@dcvr.yhbt.net \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).