- $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->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_msg {
- my ($self, $level, $html, $state) = @_;
- my $mime = $self->message;
- if ($mime) {
- $$html .= PublicInbox::View->index_entry($mime, $level, $state);
- }
- dump_msg($self->child, $level+1, $html, $state) if $self->child;
- dump_msg($self->next, $level, $html, $state) if $self->next;
-}
-
-sub do_cat_mail {
- my ($git, $path) = @_;
- my $mime = eval {
- my $str = $git->cat_file("HEAD:$path");
- Email::MIME->new($str);
- };
- $@ ? undef : $mime;
-}