sub new {
my ($class, $config) = @_;
my (%mdmap, @mdir, $spamc, $spamdir);
+ my %uniq;
# "publicinboxwatch" is the documented namespace
# "publicinboxlearn" is legacy but may be supported
# skip "new", no MUA has seen it, yet.
my $cur = "$dir/cur";
$spamdir = $cur;
+ my $old = $mdmap{$cur};
+ if (ref($old)) {
+ foreach my $ibx (@$old) {
+ warn <<"";
+"$cur already watched for `$ibx->{name}'
+
+ }
+ die;
+ }
push @mdir, $cur;
+ $uniq{$cur}++;
$mdmap{$cur} = 'watchspam';
} else {
warn "unsupported $k=$dir\n";
}
my $new = "$watch/new";
my $cur = "$watch/cur";
- push @mdir, $new, $cur;
- die "$new already in use\n" if $mdmap{$new};
- die "$cur already in use\n" if $mdmap{$cur};
- $mdmap{$new} = $mdmap{$cur} = $ibx;
+ push @mdir, $new unless $uniq{$new}++;
+ push @mdir, $cur unless $uniq{$cur}++;
+
+ push @{$mdmap{$new} ||= []}, $ibx;
+ push @{$mdmap{$cur} ||= []}, $ibx;
} else {
warn "watch unsupported: $k=$watch\n";
}
warn "unrecognized path: $path\n";
return;
}
- my $inbox = $self->{mdmap}->{$1};
- unless ($inbox) {
+ my $inboxes = $self->{mdmap}->{$1};
+ unless ($inboxes) {
warn "unmappable dir: $1\n";
return;
}
- if (!ref($inbox) && $inbox eq 'watchspam') {
+ if (!ref($inboxes) && $inboxes eq 'watchspam') {
return _remove_spam($self, $path);
}
- my $im = _importer_for($self, $inbox);
- my $mime = _path_to_mime($path) or return;
- my $wm = $inbox->{-watchheader};
- if ($wm) {
- my $v = $mime->header_obj->header_raw($wm->[0]);
- return unless ($v && $v =~ $wm->[1]);
- }
- if (my $scrub = $inbox->filter) {
- my $ret = $scrub->scrub($mime) or return;
- $ret == REJECT() and return;
- $mime = $ret;
- }
+ foreach my $ibx (@$inboxes) {
+ my $mime = _path_to_mime($path) or next;
+ my $im = _importer_for($self, $ibx);
- $im->add($mime, $self->{spamcheck});
+ my $wm = $ibx->{-watchheader};
+ if ($wm) {
+ my $v = $mime->header_obj->header_raw($wm->[0]);
+ next unless ($v && $v =~ $wm->[1]);
+ }
+ if (my $scrub = $ibx->filter) {
+ my $ret = $scrub->scrub($mime) or next;
+ $ret == REJECT() and next;
+ $mime = $ret;
+ }
+ $im->add($mime, $self->{spamcheck});
+ }
}
sub quit { trigger_scan($_[0], 'quit') }
'create FIFO to ensure we do not get stuck on it :P');
my $sem = PublicInbox::Emergency->new($spamdir); # create dirs
-my $config = PublicInbox::Config->new({
+my %orig = (
"$cfgpfx.address" => $addr,
"$cfgpfx.mainrepo" => $mainrepo,
"$cfgpfx.watch" => "maildir:$maildir",
"$cfgpfx.filter" => 'PublicInbox::Filter::Vger',
- "publicinboxlearn.watchspam" => "maildir:$spamdir",
-});
+ "publicinboxlearn.watchspam" => "maildir:$spamdir"
+);
+my $config = PublicInbox::Config->new({%orig});
my $ibx = $config->lookup_name('test');
ok($ibx, 'found inbox by name');
my $srch = $ibx->search;
is($post->{blob}, $msgs->[0]->{blob}, 'same message');
}
+# multiple inboxes in the same maildir
+{
+ my $v1repo = "$tmpdir/v1";
+ my $v1pfx = "publicinbox.v1";
+ my $v1addr = 'v1-public@example.com';
+ is(system(qw(git init -q --bare), $v1repo), 0, 'v1 init OK');
+ my $config = PublicInbox::Config->new({
+ %orig,
+ "$v1pfx.address" => $v1addr,
+ "$v1pfx.mainrepo" => $v1repo,
+ "$v1pfx.watch" => "maildir:$maildir",
+ });
+ my $both = <<EOF;
+From: user\@example.com
+To: $addr, $v1addr
+Subject: both
+Message-Id: <both\@b.com>
+Date: Sat, 18 Jun 2016 00:00:00 +0000
+
+both
+EOF
+ PublicInbox::Emergency->new($maildir)->prepare(\$both);
+ PublicInbox::WatchMaildir->new($config)->scan('full');
+ my ($total, $msgs) = $srch->reopen->query('m:both@b.com');
+ my $v1 = $config->lookup_name('v1');
+ my $msg = $v1->git->cat_file($msgs->[0]->{blob});
+ is($both, $$msg, 'got original message back from v1');
+ $msg = $ibx->git->cat_file($msgs->[0]->{blob});
+ is($both, $$msg, 'got original message back from v2');
+}
+
done_testing;