- } else {
- push @commits, undef;
- }
-
- close $log; # we may EPIPE here
- # for pagination
- $commits[-1];
-}
-
-# private functions below
-sub get_feedopts {
- my ($args) = @_;
- my $pi_config = $args->{pi_config};
- my $listname = $args->{listname};
- my $cgi = $args->{cgi};
- my %rv;
- if (open my $fh, '<', "$args->{git_dir}/description") {
- chomp($rv{description} = <$fh>);
- close $fh;
- }
-
- if ($pi_config && defined $listname && length $listname) {
- foreach my $key (qw(address)) {
- $rv{$key} = $pi_config->get($listname, $key) || "";
- }
- }
- my $url_base;
- if ($cgi) {
- my $path_info = $cgi->path_info;
- my $base;
- if (ref($cgi) eq 'CGI') {
- $base = $cgi->url(-base);
- } else {
- $base = $cgi->base->as_string;
- $base =~ s!/\z!!;
- }
- $url_base = $path_info;
- if ($url_base =~ s!/(?:|index\.html)?\z!!) {
- $rv{atomurl} = "$base$url_base/atom.xml";
- } else {
- $url_base =~ s!/atom\.xml\z!!;
- $rv{atomurl} = $base . $path_info;
- $url_base = $base . $url_base; # XXX is this needed?
- }
- } else {
- $url_base = "http://example.com";
- $rv{atomurl} = "$url_base/atom.xml";
- }
- $rv{url} ||= "$url_base/";
- $rv{midurl} = "$url_base/m/";
- $rv{fullurl} = "$url_base/f/";
-
- \%rv;
-}
-
-sub mime_header {
- my ($mime, $name) = @_;
- PublicInbox::Hval->new_oneline($mime->header($name))->raw;
-}
-
-sub feed_date {
- my ($date) = @_;
- my @t = eval { strptime($date) };
-
- scalar(@t) ? POSIX::strftime(DATEFMT, @t) : 0;
-}
-
-# returns 0 (skipped) or 1 (added)
-sub add_to_feed {
- my ($feed_opts, $feed, $add, $git) = @_;
-
- my $mime = do_cat_mail($git, $add) or return 0;
- my $midurl = $feed_opts->{midurl} || 'http://example.com/m/';
- my $fullurl = $feed_opts->{fullurl} || 'http://example.com/f/';
-
- my $mid = $mime->header_obj->header_raw('Message-ID');
- defined $mid or return 0;
- $mid = PublicInbox::Hval->new_msgid($mid);
- my $href = $mid->as_href . '.html';
- my $content = PublicInbox::View->as_feed_entry($mime, $fullurl . $href);
- defined($content) or return 0;
-
- my $subject = mime_header($mime, 'Subject') or return 0;
-
- my $from = mime_header($mime, 'From') or return 0;
- my @from = Email::Address->parse($from);
- my $name = $from[0]->name;
- defined $name or $name = "";
- my $email = $from[0]->address;
- defined $email or $email = "";
-
- my $date = $mime->header('Date');
- $date = PublicInbox::Hval->new_oneline($date);
- $date = feed_date($date->raw) or return 0;
- $add =~ tr!/!!d;
- my $h = '[a-f0-9]';
- my (@uuid5) = ($add =~ m!\A($h{8})($h{4})($h{4})($h{4})($h{12})!o);
-
- $feed->add_entry(
- author => { name => $name, email => $email },
- title => $subject,
- updated => $date,
- content => { type => 'xhtml', content => $content },
- link => $midurl . $href,
- id => 'urn:uuid:' . join('-', @uuid5),
- );
- 1;
-}
-
-sub dump_html_line {
- my ($self, $level, $html) = @_;
- if ($self->message) {
- $$html .= (' ' x $level);
- my $mime = $self->message;
- my $subj = $mime->header('Subject');
- my $mid = $mime->header_obj->header_raw('Message-ID');
- $mid = PublicInbox::Hval->new_msgid($mid);
- my $href = 'm/' . $mid->as_href . '.html';
- my $from = mime_header($mime, 'From');
-
- my @from = Email::Address->parse($from);
- $from = $from[0]->name;
- (defined($from) && length($from)) or $from = $from[0]->address;
-
- $from = PublicInbox::Hval->new_oneline($from)->as_html;
- $subj = PublicInbox::Hval->new_oneline($subj)->as_html;
- $$html .= "<a href=\"$href\">$subj</a> $from\n";