-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 $feed_opts = get_feedopts($ctx);
- my $fh = $cb->([ 200, ['Content-Type' => 'application/atom+xml']]);
- my $max = $ctx->{max} || MAX_PER_PAGE;
- my $x = atom_header($feed_opts);
- my $ibx = $ctx->{-inbox};
- each_recent_blob($ctx, sub {
- my ($path, undef, $ts) = @_;
- if (defined $x) {
- $fh->write($x . feed_updated(undef, $ts));
- $x = undef;
- }
- my $s = feed_entry($feed_opts, $path, $ibx) or return 0;
- $fh->write($s);
- 1;
- });
- end_feed($fh);
-}
-
-sub _no_thread {
- my ($cb) = @_;
- $cb->([404, ['Content-Type', 'text/plain'],
- ["No feed found for thread\n"]]);
-}
-
-sub end_feed {
- my ($fh) = @_;
- $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 $feed_opts = get_feedopts($ctx);
- my $fh = $cb->([200, ['Content-Type' => 'application/atom+xml']]);
-
- 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 $ibx = $ctx->{-inbox};
- foreach my $msg (@{$res->{msgs}}) {
- my $s = feed_entry($feed_opts, mid2path($msg->mid), $ibx);
- $fh->write($s) if defined $s;
- }
- end_feed($fh);
-}
-
-sub _html_index_top {
- my ($feed_opts, $srch) = @_;
-
- my $title = ascii_html($feed_opts->{description} || '');
- 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";
- }
-
- "<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";