+ 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!$LISTNAME_RE/m/(\S+)/\z!o) {
+ r301($ctx, $1, $2);
+ } elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)/raw\z!o) {
+ r301($ctx, $1, $2, 'raw');
+
+ } elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)/\z!o) {
+ r301($ctx, $1, $2, 'f/');
+
+ # thread display
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)/\z!o) {
+ r301($ctx, $1, $2, 't/#u');
+
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)/mbox(\.gz)?\z!o) {
+ r301($ctx, $1, $2, "t.mbox$3");
+
+ # even older legacy redirects
+ } elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)\.html\z!o) {
+ r301($ctx, $1, $2);
+
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.html\z!o) {
+ r301($ctx, $1, $2, 't/#u');
+
+ } elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)\.html\z!o) {
+ r301($ctx, $1, $2, 'f/');
+
+ } elsif ($path_info =~ m!$LISTNAME_RE/(?:m|f)/(\S+)\.txt\z!o) {
+ r301($ctx, $1, $2, 'raw');
+
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)(\.mbox(?:\.gz)?)\z!o) {
+ r301($ctx, $1, $2, "t$3");
+
+ # legacy convenience redirects, order still matters
+ } elsif ($path_info =~ m!$LISTNAME_RE/m/(\S+)\z!o) {
+ r301($ctx, $1, $2);
+ } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\z!o) {
+ r301($ctx, $1, $2, 't/#u');
+ } elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)\z!o) {
+ r301($ctx, $1, $2, 'f/');
+
+ # some Message-IDs have slashes in them and the HTTP server
+ # may try to be clever and unescape them :<
+ } elsif ($path_info =~ m!$LISTNAME_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!$LISTNAME_RE/(\S+/\S+)/(f|T|t)\z!o) {
+ r301($ctx, $1, $2, $3 eq 't' ? 't/#u' : $3);
+ } else {
+ $self->news_www->call($ctx->{cgi}->{env});
+ }
+}
+
+sub r301 {
+ my ($ctx, $listname, $mid, $suffix) = @_;
+ my $cgi = $ctx->{cgi};
+ my $url;
+ my $qs = $cgi->env->{QUERY_STRING};
+ $url = $cgi->base->as_string . $listname . '/';
+ $url .= (uri_escape_utf8($mid) . '/') if (defined $mid);
+ $url .= $suffix if (defined $suffix);
+ $url .= "?$qs" if $qs ne '';
+
+ [ 301,
+ [ Location => $url, 'Content-Type' => 'text/plain' ],
+ [ "Redirecting to $url\n" ] ]
+}
+
+sub msg_page {
+ my ($self, $ctx, $list, $mid, $e) = @_;
+ my $ret;
+ $ret = invalid_list_mid($self, $ctx, $list, $mid) and return $ret;
+ '' eq $e and return get_mid_html($ctx);
+ 't/' eq $e and return get_thread($ctx);
+ 't.atom' eq $e and return get_thread_atom($ctx);
+ 't.mbox' eq $e and return get_thread_mbox($ctx);
+ 't.mbox.gz' eq $e and return get_thread_mbox($ctx, '.gz');
+ 'T/' eq $e and return get_thread($ctx, 1);
+ 'raw' eq $e and return get_mid_txt($ctx);
+ 'f/' eq $e and return get_full_html($ctx);
+ 'R/' eq $e and return get_reply_html($ctx);
+ r404($ctx);
+}
+
+sub serve_git {
+ my ($cgi, $git, $path) = @_;
+ PublicInbox::GitHTTPBackend::serve($cgi, $git, $path);
+}
+
+sub news_www {
+ my ($self) = @_;
+ my $nw = $self->{news_www};
+ return $nw if $nw;
+ require PublicInbox::NewsWWW;
+ $self->{news_www} = PublicInbox::NewsWWW->new($self->{pi_config});