+sub need_search {
+ my ($ctx) = @_;
+ my $msg = <<EOF;
+<html><head><title>Search not available for this
+public-inbox</title><body><pre>Search is not available for this public-inbox
+<a href="../">Return to index</a></pre></body></html>
+EOF
+ [ 501, [ 'Content-Type' => 'text/html; charset=UTF-8' ], [ $msg ] ];
+}
+
+# /$INBOX/$MESSAGE_ID/t.mbox -> thread as mbox
+# /$INBOX/$MESSAGE_ID/t.mbox.gz -> thread as gzipped mbox
+# note: I'm not a big fan of other compression formats since they're
+# significantly more expensive on CPU than gzip and less-widely available,
+# especially on older systems. Stick to zlib since that's what git uses.
+sub get_thread_mbox {
+ my ($ctx, $sfx) = @_;
+ my $srch = searcher($ctx) or return need_search($ctx);
+ require PublicInbox::Mbox;
+ PublicInbox::Mbox::thread_mbox($ctx, $srch, $sfx);
+}
+
+
+# /$INBOX/$MESSAGE_ID/t.atom -> thread as Atom feed
+sub get_thread_atom {
+ my ($ctx) = @_;
+ searcher($ctx) or return need_search($ctx);
+ $ctx->{self_url} = $ctx->{cgi}->uri->as_string;
+ require PublicInbox::Feed;
+ PublicInbox::Feed::generate_thread_atom($ctx);
+}
+
+sub legacy_redirects {
+ my ($self, $ctx, $path_info) = @_;
+
+ # single-message pages
+ if ($path_info =~ m!$INBOX_RE/m/(\S+)/\z!o) {
+ r301($ctx, $1, $2);
+ } elsif ($path_info =~ m!$INBOX_RE/m/(\S+)/raw\z!o) {
+ r301($ctx, $1, $2, 'raw');
+
+ } elsif ($path_info =~ m!$INBOX_RE/f/(\S+)/\z!o) {
+ r301($ctx, $1, $2);
+
+ # thread display
+ } elsif ($path_info =~ m!$INBOX_RE/t/(\S+)/\z!o) {
+ r301($ctx, $1, $2, 't/#u');
+
+ } elsif ($path_info =~ m!$INBOX_RE/t/(\S+)/mbox(\.gz)?\z!o) {
+ r301($ctx, $1, $2, "t.mbox$3");
+
+ # even older legacy redirects
+ } elsif ($path_info =~ m!$INBOX_RE/m/(\S+)\.html\z!o) {
+ r301($ctx, $1, $2);
+
+ } elsif ($path_info =~ m!$INBOX_RE/t/(\S+)\.html\z!o) {
+ r301($ctx, $1, $2, 't/#u');
+
+ } elsif ($path_info =~ m!$INBOX_RE/f/(\S+)\.html\z!o) {
+ r301($ctx, $1, $2);
+
+ } elsif ($path_info =~ m!$INBOX_RE/(?:m|f)/(\S+)\.txt\z!o) {
+ r301($ctx, $1, $2, 'raw');
+
+ } elsif ($path_info =~ m!$INBOX_RE/t/(\S+)(\.mbox(?:\.gz)?)\z!o) {
+ r301($ctx, $1, $2, "t$3");
+
+ # legacy convenience redirects, order still matters
+ } elsif ($path_info =~ m!$INBOX_RE/m/(\S+)\z!o) {
+ r301($ctx, $1, $2);
+ } elsif ($path_info =~ m!$INBOX_RE/t/(\S+)\z!o) {
+ r301($ctx, $1, $2, 't/#u');
+ } elsif ($path_info =~ m!$INBOX_RE/f/(\S+)\z!o) {
+ r301($ctx, $1, $2);
+
+ # some Message-IDs have slashes in them and the HTTP server
+ # may try to be clever and unescape them :<
+ } elsif ($path_info =~ m!$INBOX_RE/(\S+/\S+)/$END_RE\z!o) {
+ msg_page($self, $ctx, $1, $2, $3);
+
+ # in case people leave off the trailing slash:
+ } elsif ($path_info =~ m!$INBOX_RE/(\S+/\S+)/(T|t)\z!o) {
+ r301($ctx, $1, $2, $3 eq 't' ? 't/#u' : $3);
+ } elsif ($path_info =~ m!$INBOX_RE/(\S+/\S+)/f\z!o) {
+ r301($ctx, $1, $2);
+ } else {
+ $self->news_www->call($ctx->{cgi}->{env});
+ }
+}
+
+sub r301 {
+ my ($ctx, $inbox, $mid, $suffix) = @_;
+ my $cgi = $ctx->{cgi};
+ my $obj = $ctx->{-inbox};
+ unless ($obj) {
+ my $r404 = invalid_inbox($ctx->{www}, $ctx, $inbox);
+ return $r404 if $r404;
+ $obj = $ctx->{-inbox};
+ }
+ my $url = $obj->base_url($cgi);
+ my $qs = $ctx->{env}->{QUERY_STRING};
+ $url .= (uri_escape_utf8($mid) . '/') if (defined $mid);
+ $url .= $suffix if (defined $suffix);
+ $url .= "?$qs" if $qs ne '';
+