- my $th = Mail::Thread->new(@messages);
- $th->thread;
- my @args = (
- "<html><head><title>$title</title>" .
- '<link rel=alternate title=Atom.feed href="' .
- $feed_opts->{atomurl} . '" type="application/atom+xml"/>' .
- '</head><body><pre>');
- push @args, $feed_opts->{midurl};
-
- # sort by date, most recent at top
- $th->order(sub {
- sort {
- $b->topmost->message->header('X-PI-Date') <=>
- $a->topmost->message->header('X-PI-Date')
- } @_;
+ my $title = $feed_opts->{description} || '';
+ $title = PublicInbox::Hval->new_oneline($title)->as_html;
+ my $atom_url = $feed_opts->{atomurl};
+ my ($footer, $param, $last);
+ my $state = { ctx => $ctx, seen => {}, anchor_idx => 0 };
+ my $srch = $ctx->{srch};
+
+ my $top = "<b>$title</b> (<a\nhref=\"$atom_url\">Atom feed</a>)";
+
+ if ($srch) {
+ $top = qq{<form\naction=""><tt>$top} .
+ qq{ <input\nname=q\ntype=text />} .
+ qq{<input\ntype=submit\nvalue=search />} .
+ qq{</tt></form>} .
+ PublicInbox::View::PRE_WRAP;
+ } else {
+ $top = PublicInbox::View::PRE_WRAP . $top . "\n";
+ }
+
+ $fh->write("<html><head><title>$title</title>" .
+ "<link\nrel=alternate\ntitle=\"Atom feed\"\n".
+ "href=\"$atom_url\"\ntype=\"application/atom+xml\"/>" .
+ "</head><body>$top");
+
+ # if the 'r' query parameter is given, it is a legacy permalink
+ # which we must continue supporting:
+ my $cgi = $ctx->{cgi};
+ if ($cgi && !$cgi->param('r') && $srch) {
+ $state->{srch} = $srch;
+ $last = PublicInbox::View::emit_index_topics($state, $fh);
+ $param = 'o';
+ } else {
+ $last = emit_index_nosrch($ctx, $state, $fh);
+ $param = 'r';
+ }
+ $footer = nav_footer($cgi, $last, $feed_opts, $state, $param);
+ if ($footer) {
+ my $list_footer = $ctx->{footer};
+ $footer .= "\n\n" . $list_footer if $list_footer;
+ $footer = "<hr /><pre>$footer</pre>";
+ }
+ $fh->write("$footer</body></html>");
+ $fh->close;
+}
+
+sub emit_index_nosrch {
+ my ($ctx, $state, $fh) = @_;
+ my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+ my (undef, $last) = each_recent_blob($ctx, sub {
+ my ($path, $commit, $ts, $u, $subj) = @_;
+ $state->{first} ||= $commit;
+
+ my $mime = do_cat_mail($git, $path) or return 0;
+ PublicInbox::View::index_entry($fh, $mime, 0, $state);
+ 1;