- my ($class, $args) = @_;
- my $max = $args->{max} || 50;
- my $top = $args->{top}; # bool
- local $ENV{GIT_DIR} = $args->{git_dir};
- my $feed_opts = get_feedopts($args);
- my $title = escapeHTML($feed_opts->{description} || "");
- my @messages;
- each_recent_blob($max, sub {
- my $str = `git cat-file blob $_[0]`;
- return 0 if $? != 0;
- my $simple = Email::Simple->new($str);
- if ($top && ($simple->header("In-Reply-To") ||
- $simple->header("References"))) {
- return 0;
+ my ($ctx) = @_;
+ sub { emit_html_index($_[0], $ctx) };
+}
+
+# private subs
+
+sub emit_atom {
+ my ($cb, $ctx) = @_;
+ require POSIX;
+ my $fh = $cb->([ 200, ['Content-Type' => 'application/xml']]);
+ my $max = $ctx->{max} || MAX_PER_PAGE;
+ my $feed_opts = get_feedopts($ctx);
+ my $addr = $feed_opts->{address};
+ $addr = $addr->[0] if ref($addr);
+ $addr ||= 'public-inbox@example.com';
+ my $title = $feed_opts->{description} || "unnamed feed";
+ $title = PublicInbox::Hval->new_oneline($title)->as_html;
+ my $type = index($title, '&') >= 0 ? "\ntype=\"html\"" : '';
+ my $url = $feed_opts->{url} || "http://example.com/";
+ my $atomurl = $feed_opts->{atomurl};
+ $fh->write(qq(<?xml version="1.0" encoding="us-ascii"?>\n) .
+ qq{<feed\nxmlns="http://www.w3.org/2005/Atom">} .
+ qq{<title$type>$title</title>} .
+ qq{<link\nhref="$url"/>} .
+ qq{<link\nrel="self"\nhref="$atomurl"/>} .
+ qq{<id>mailto:$addr</id>} .
+ '<updated>' . POSIX::strftime(DATEFMT, gmtime) . '</updated>');
+
+ my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+ each_recent_blob($ctx, sub {
+ my ($add, undef) = @_;
+ add_to_feed($feed_opts, $fh, $add, $git);
+ });
+ $git = undef; # destroy pipes
+ Email::Address->purge_cache;
+ $fh->write("</feed>");
+ $fh->close;
+}
+
+
+sub emit_html_index {
+ my ($cb, $ctx) = @_;
+ my $fh = $cb->([200,['Content-Type'=>'text/html; charset=UTF-8']]);
+
+ my $max = $ctx->{max} || MAX_PER_PAGE;
+ my $feed_opts = get_feedopts($ctx);
+
+ my $title = $feed_opts->{description} || '';
+ $title = PublicInbox::Hval->new_oneline($title)->as_html;
+ my $atom_url = $feed_opts->{atomurl};
+
+ $fh->write("<html><head><title>$title</title>" .
+ "<link\nrel=alternate\ntitle=\"Atom feed\"\n".
+ "href=\"$atom_url\"\ntype=\"application/atom+xml\"/>" .
+ '</head><body>' . PublicInbox::View::PRE_WRAP .
+ "<b>$title</b> (<a\nhref=\"$atom_url\">Atom feed</a>)\n");
+
+ my $state;
+ my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+ my $topics;
+ my $srch = $ctx->{srch};
+ $srch and $topics = [ [], {} ];
+ my (undef, $last) = each_recent_blob($ctx, sub {
+ my ($path, $commit, $ts, $u, $subj) = @_;
+ $state ||= [ undef, {}, $commit, 0 ];
+
+ if ($srch) {
+ add_topic($git, $srch, $topics, $path, $ts, $u, $subj);
+ } else {
+ my $mime = do_cat_mail($git, $path) or return 0;
+ PublicInbox::View::index_entry($fh, $mime, 0, $state);
+ 1;