+ my $mm = $other->mm or return;
+
+ # try to find the URL with Msgmap to avoid forking
+ my $num = $mm->num_for($ctx->{mid});
+ if (defined $num) {
+ push @{$ctx->{found}}, $other;
+ } else {
+ # no point in trying the fork fallback if we
+ # know Xapian is up-to-date but missing the
+ # message in the current repo
+ push @{$ctx->{again}}, $other;
+ }
+}
+
+sub ext_msg_step {
+ my ($pi_cfg, $section, $ctx) = @_;
+ if (defined($section)) {
+ return if $section !~ m!\Apublicinbox\.([^/]+)\z!;
+ my $ibx = $pi_cfg->lookup_name($1) or return;
+ ext_msg_i($ibx, $ctx);
+ } else { # undef == "EOF"
+ finalize_exact($ctx);
+ }
+}
+
+sub ext_msg_ALL ($) {
+ my ($ctx) = @_;
+ my $ALL = $ctx->{www}->{pi_cfg}->ALL or return;
+ my $by_eidx_key = $ctx->{www}->{pi_cfg}->{-by_eidx_key};
+ my $cur_key = eval { $ctx->{ibx}->eidx_key } //
+ return partial_response($ctx); # $cur->{ibx} == $ALL
+ my %seen = ($cur_key => 1);
+ my ($id, $prev);
+ while (my $x = $ALL->over->next_by_mid($ctx->{mid}, \$id, \$prev)) {
+ my $xr3 = $ALL->over->get_xref3($x->{num});
+ for my $k (@$xr3) {
+ $k =~ s/:[0-9]+:$x->{blob}\z// or next;
+ next if $k eq $cur_key;
+ my $ibx = $by_eidx_key->{$k} // next;
+ $ibx->base_url or next;
+ push(@{$ctx->{found}}, $ibx) unless $seen{$k}++;
+ }
+ }
+ return exact($ctx) if $ctx->{found};
+
+ # fall back to partial MID matching
+ for my $ibxish ($ctx->{ibx}, $ALL) {
+ my $mids = search_partial($ibxish, $ctx->{mid}) or next;
+ push @{$ctx->{partial}}, [ $ibxish, $mids ];
+ last if ($ctx->{n_partial} += scalar(@$mids)) >= PARTIAL_MAX;
+ }
+ partial_response($ctx);
+}
+
+sub ext_msg {
+ my ($ctx) = @_;
+ ext_msg_ALL($ctx) // sub {
+ $ctx->{-wcb} = $_[0]; # HTTP server write callback
+
+ if ($ctx->{env}->{'pi-httpd.async'}) {
+ require PublicInbox::ConfigIter;
+ my $iter = PublicInbox::ConfigIter->new(
+ $ctx->{www}->{pi_cfg},
+ \&ext_msg_step, $ctx);
+ $iter->event_step;