-# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# Plack app redirector for mapping /$NEWSGROUP requests to
use warnings;
use PublicInbox::Config;
use PublicInbox::MID qw(mid_escape);
+use PublicInbox::Hval qw(prurl);
sub new {
my ($class, $pi_config) = @_;
[ "Redirecting to $url\n" ] ]
}
-sub try_inbox ($$) {
- my ($ibx, $mid) = @_;
+sub try_inbox {
+ my ($ibx, $arg) = @_;
+ return if scalar(@$arg) > 1;
+
# do not pass $env since HTTP_HOST may differ
my $url = $ibx->base_url or return;
+ my ($mid) = @$arg;
eval { $ibx->mm->num_for($mid) } or return;
# 302 since the same message may show up on
# multiple inboxes and inboxes can be added/reordered
- redirect(302, $url .= mid_escape($mid) . '/');
+ $arg->[1] = redirect(302, $url .= mid_escape($mid) . '/');
}
sub call {
my ($ng, $article) = @parts;
my $pi_config = $self->{pi_config};
if (my $ibx = $pi_config->lookup_newsgroup($ng)) {
- my $url = PublicInbox::Hval::prurl($env, $ibx->{url});
+ my $url = prurl($env, $ibx->{url});
my $code = 301;
if (defined $article && $article =~ /\A[0-9]+\z/) {
my $mid = eval { $ibx->mm->mid_for($article) };
}
foreach my $mid (@try) {
- $pi_config->each_inbox(sub {
- $res ||= try_inbox($_[0], $mid);
- });
- last if defined $res;
+ my $arg = [ $mid ];
+ $pi_config->each_inbox(\&try_inbox, $arg);
+ defined($res = $arg->[1]) and last;
}
$res || [ 404, [qw(Content-Type text/plain)], ["404 Not Found\n"] ];
}