* [PATCH 5/4] watch_maildir: tighten up path checks
@ 2016-06-19 3:44 7% ` Eric Wong
0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2016-06-19 3:44 UTC (permalink / raw)
To: meta
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->();
^ permalink raw reply related [relevance 7%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-06-19 0:28 [PATCH 0/4] watch improvements for mirroring Eric Wong
2016-06-19 3:44 7% ` [PATCH 5/4] watch_maildir: tighten up path checks Eric Wong
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).