+ $from = "$uri/test";
+ $to = "$from/";
+ $res = $cb->(GET($from));
+ is(301, $res->code, 'is permanent redirect');
+ is($to, $res->header('Location'),
+ 'redirect location matches with trailing slash');
+
+ for my $t (qw(T t)) {
+ my $u = $pfx . "/blah\@example.com/$t";
+ $res = $cb->(GET($u));
+ is(301, $res->code, "redirect for missing /");
+ my $location = $res->header('Location');
+ like($location, qr!/\Q$t\E/#u\z!,
+ 'redirected with missing /');
+ }
+
+ for my $t (qw(f)) { # legacy redirect
+ my $u = $pfx . "/blah\@example.com/$t";
+ $res = $cb->(GET($u));
+ is(301, $res->code, "redirect for legacy /f");
+ my $location = $res->header('Location');
+ like($location, qr!/blah\@example\.com/\z!,
+ 'redirected with missing /');
+ }
+
+ my $atomurl = "$uri/test/new.atom";
+ $res = $cb->(GET("$uri/test/new.html"));
+ is(200, $res->code, 'success response received');
+ like($res->content, qr!href="new\.atom"!,
+ 'atom URL generated');
+ like($res->content, qr!href="blah\@example\.com/"!,
+ 'index generated');
+ like($res->content, qr!1993-10-02!, 'date set');
+
+ $res = $cb->(GET($pfx . '/atom.xml'));
+ is(200, $res->code, 'success response received for atom');
+ my $body = $res->content;
+ like($body, qr!link\s+href="\Q$pfx\E/blah\@example\.com/"!s,
+ 'atom feed generated correct URL');
+ like($body, qr/<title>test for public-inbox/,
+ "set title in XML feed");
+ like($body, qr/zzzzzz/, 'body included');
+ $res = $cb->(GET($pfx . '/description'));
+ like($res->content, qr/test for public-inbox/, 'got description');
+
+ my $path = '/blah@example.com/';
+ $res = $cb->(GET($pfx . $path));
+ is(200, $res->code, "success for $path");
+ my $html = $res->content;
+ like($html, qr!\bhref="\Q../_/text/help/"!, 'help available');
+ like($html, qr!<title>hihi - Me</title>!, 'HTML returned');
+ like($html, qr!<a\nhref=raw!s, 'raw link present');
+ like($html, qr!> quoted text!s, 'quoted text inline');
+ unlike($html, qr!thread overview!,
+ 'thread overview not shown w/o ->over');
+
+ $path .= 'f/';
+ $res = $cb->(GET($pfx . $path));
+ is(301, $res->code, "redirect for $path");
+ my $location = $res->header('Location');
+ like($location, qr!/blah\@example\.com/\z!,
+ '/$MESSAGE_ID/f/ redirected to /$MESSAGE_ID/');
+
+ $res = $cb->(GET($pfx . '/multipart@example.com/'));
+ like($res->content,
+ qr/hi\n.*-- Attachment #2.*\nbye\n/s, 'multipart split');
+
+ $res = $cb->(GET($pfx . '/patch@example.com/'));
+ $html = $res->content;
+ like($html, qr!see attached!, 'original body');
+ like($html, qr!.*Attachment #2: foo&(?:amp|#38);\.patch --!,
+ 'parts split with filename');
+
+ $res = $cb->(GET($pfx . '/qp@example.com/'));
+ like($res->content, qr/\bhi = bye\b/, "HTML output decoded QP");
+
+
+ $res = $cb->(GET($pfx . '/blah@example.com/raw'));
+ is(200, $res->code, 'success response received for /*/raw');
+ like($res->content, qr!^From !sm, "mbox returned");
+ is($res->header('Content-Type'), 'text/plain; charset=iso-8859-1',
+ 'charset from message used');
+
+ $res = $cb->(GET($pfx . '/broken@example.com/raw'));
+ is($res->header('Content-Type'), 'text/plain; charset=UTF-8',
+ 'broken charset ignored');
+
+ $res = $cb->(GET($pfx . '/199707281508.AAA24167@hoyogw.example/raw'));
+ is($res->header('Content-Type'), 'text/plain; charset=ISO-2022-JP',
+ 'ISO-2002-JP returned');
+ chomp($body = $res->content);
+ my $raw = PublicInbox::Eml->new(\$body);
+ is($raw->body_raw, $eml->body_raw, 'ISO-2022-JP body unmodified');
+
+ $res = $cb->(GET($pfx . '/blah@example.com/t.mbox.gz'));
+ is(501, $res->code, '501 when overview missing');
+ like($res->content, qr!\bOverview\b!, 'overview omission noted');
+
+ # legacy redirects
+ for my $t (qw(m f)) {
+ $res = $cb->(GET($pfx . "/$t/blah\@example.com.txt"));
+ is(301, $res->code, "redirect for old $t .txt link");
+ $location = $res->header('Location');
+ like($location, qr!/blah\@example\.com/raw\z!,
+ ".txt redirected to /raw");
+ }
+
+ my %umap = (
+ 'm' => '',
+ 'f' => '',
+ 't' => 't/',
+ );
+ while (my ($t, $e) = each %umap) {
+ $res = $cb->(GET($pfx . "/$t/blah\@example.com.html"));
+ is(301, $res->code, "redirect for old $t .html link");
+ $location = $res->header('Location');
+ like($location, qr!/blah\@example\.com/$e(?:#u)?\z!,
+ ".html redirected to new location");
+ }
+
+ for my $sfx (qw(mbox mbox.gz)) {
+ $res = $cb->(GET($pfx . "/t/blah\@example.com.$sfx"));
+ is(301, $res->code, 'redirect for old thread link');
+ $location = $res->header('Location');
+ like($location,
+ qr!/blah\@example\.com/t\.mbox(?:\.gz)?\z!,
+ "$sfx redirected to /mbox.gz");
+ }
+
+ # for a while, we used to support /$INBOX/$X40/
+ # when we "compressed" long Message-IDs to SHA-1
+ # Now we're stuck supporting them forever :<
+ for my $path ('f2912279bd7bcd8b7ab3033234942d58746d56f7') {
+ $from = "$uri/test/$path/";
+ $res = $cb->(GET($from));