- sub { emit_html_index($_[0], $ctx) };
-}
-
-# private subs
-
-sub title_tag {
- my ($title) = @_;
- $title =~ tr/\t\n / /s; # squeeze spaces
- # try to avoid the type attribute in title:
- $title = ascii_html($title);
- my $type = index($title, '&') >= 0 ? "\ntype=\"html\"" : '';
- "<title$type>$title</title>";
-}
-
-sub atom_header {
- my ($feed_opts, $title) = @_;
-
- $title = title_tag($feed_opts->{description}) unless (defined $title);
-
- qq(<?xml version="1.0" encoding="us-ascii"?>\n) .
- qq{<feed\nxmlns="http://www.w3.org/2005/Atom">} .
- qq{$title} .
- qq(<link\nrel="alternate"\ntype="text/html") .
- qq(\nhref="$feed_opts->{url}"/>) .
- qq(<link\nrel="self"\nhref="$feed_opts->{atomurl}"/>) .
- qq(<id>mailto:$feed_opts->{id_addr}</id>);
-}
-
-sub emit_atom {
- my ($cb, $ctx) = @_;
- my $fh = $cb->([ 200, ['Content-Type' => 'application/atom+xml']]);
- my $max = $ctx->{max} || MAX_PER_PAGE;
- my $feed_opts = get_feedopts($ctx);
- my $x = atom_header($feed_opts);
- my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
- each_recent_blob($ctx, sub {
- my ($path, undef, $ts) = @_;
- if (defined $x) {
- $fh->write($x . feed_updated(undef, $ts));
- $x = undef;
- }
- add_to_feed($feed_opts, $fh, $path, $git);
- });
- end_feed($fh);
-}
-
-sub _no_thread {
- my ($cb) = @_;
- my $fh = $cb->([404, ['Content-Type' => 'text/plain']]);
- $fh->write("No feed found for thread\n");
- $fh->close;
-}
-
-sub end_feed {
- my ($fh) = @_;
- Email::Address->purge_cache;
- $fh->write('</feed>');
- $fh->close;
-}
-
-sub emit_atom_thread {
- my ($cb, $ctx) = @_;
- my $res = $ctx->{srch}->get_thread($ctx->{mid});
- return _no_thread($cb) unless $res->{total};
- my $fh = $cb->([200, ['Content-Type' => 'application/atom+xml']]);
- my $feed_opts = get_feedopts($ctx);
-
- my $html_url = $feed_opts->{atomurl} = $ctx->{self_url};
- $html_url =~ s!/t\.atom\z!/!;
- $feed_opts->{url} = $html_url;
- $feed_opts->{emit_header} = 1;
-
- my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
- foreach my $msg (@{$res->{msgs}}) {
- add_to_feed($feed_opts, $fh, mid2path($msg->mid), $git);
- }
- end_feed($fh);
-}
-
-sub emit_html_index {
- my ($res, $ctx) = @_;
- my $fh = $res->([200,['Content-Type'=>'text/html; charset=UTF-8']]);
-
- my $max = $ctx->{max} || MAX_PER_PAGE;
- my $feed_opts = get_feedopts($ctx);
-
- my $title = ascii_html($feed_opts->{description} || '');
- my ($footer, $param, $last);
- my $state = { ctx => $ctx, seen => {}, anchor_idx => 0, fh => $fh };
- my $srch = $ctx->{srch};
-
- my $top = "<b>$title</b> (<a\nhref=\"new.atom\">Atom feed</a>)";
-
- if ($srch) {
- $top = qq{<form\naction=""><pre>$top} .
- qq{ <input\nname=q\ntype=text />} .
- qq{<input\ntype=submit\nvalue=search />} .
- q{</pre></form><pre>}
- } else {
- $top = '<pre>' . $top . "\n";
- }
-
- $fh->write("<html><head><title>$title</title>" .
- "<link\nrel=alternate\ntitle=\"Atom feed\"\n".
- "href=\"new.atom\"\ntype=\"application/atom+xml\"/>" .
- PublicInbox::Hval::STYLE .
- "</head><body>$top");
-