- } elsif ($reverse) {
- unshift @commits, undef
- } else {
- push @commits, undef;
- }
-
- close $log; # we may EPIPE here
- # for pagination
- $reverse ? ($commits[-1],$commits[0]) : ($commits[0],$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 $cgi_url = $cgi->url(-path=>1, -relative=>1);
- my $base = $cgi->url(-base);
- $url_base = $cgi_url;
- if ($url_base =~ s!/(?:|index\.html)?\z!!) {
- $rv{atomurl} = "$base$url_base/atom.xml";
- } else {
- $url_base =~ s!/atom\.xml\z!!;
- $rv{atomurl} = $base . $cgi_url;
- $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 utf8_header {
- my ($simple, $name) = @_;
- my $val = $simple->header($name);
- return "" unless defined $val;
- $val =~ tr/\t\n / /s;
- $val =~ tr/\r//d;
- $enc_utf8->encode($enc_mime->decode($val));
-}
-
-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, $top, $git) = @_;
-
- my $mime = do_cat_mail($git, 'Email::MIME', $add) or return 0;
- if ($top && $mime->header("In-Reply-To")) {
- return 0;
- }
-
- my $midurl = $feed_opts->{midurl} || 'http://example.com/m/';
- my $fullurl = $feed_opts->{fullurl} || 'http://example.com/f/';
-
- my $content = PublicInbox::View->as_feed_entry($mime, $fullurl);
- defined($content) or return 0;
-
- my $mid = utf8_header($mime, "Message-ID") or return 0;
- $mid =~ s/\A<//; $mid =~ s/>\z//;
-
- my $subject = utf8_header($mime, "Subject") || "";
- length($subject) or return 0;
-
- my $from = utf8_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 $url = $midurl . uri_escape($mid);
- my $date = utf8_header($mime, "Date");
- $date or return 0;
- $date = feed_date($date) or return 0;
- $feed->add_entry(
- author => { name => $name, email => $email },
- title => $subject,
- updated => $date,
- content => { type => "html", content => $content },
- link => $url,
- id => $add,
- );
- 1;
-}
-
-sub dump_html_line {
- my ($self, $level, $args) = @_; # args => [ $html, $midurl ]
- if ($self->message) {
- $args->[0] .= (' ' x $level);
- my $simple = $self->message;
- my $subj = utf8_header($simple, "Subject");
- my $mid = utf8_header($simple, "Message-ID");
- $mid =~ s/\A<//;
- $mid =~ s/>\z//;
- my $url = $args->[1] . uri_escape($mid);
- my $from = utf8_header($simple, "From");
- my @from = Email::Address->parse($from);
- $from = $from[0]->name;
- (defined($from) && length($from)) or $from = $from[0]->address;
- $from = xs_html($from);
- $subj = xs_html($subj);
- $args->[0] .= "<a href=\"$url.html\">$subj</a> $from\n";