]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WwwAtomStream.pm
run update-copyrights from gnulib for 2019
[public-inbox.git] / lib / PublicInbox / WwwAtomStream.pm
index a6817b31475c4e2df23c9d2ab141d56f64a09b1f..fd861d45b549586962aed303760322a2b07887aa 100644 (file)
@@ -1,18 +1,20 @@
-# Copyright (C) 2016 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Atom body stream for which yields getline+close methods
+# public-inbox-httpd favors "getline" response bodies to take a
+# "pull"-based approach to feeding slow clients (as opposed to a
+# more common "push" model)
 package PublicInbox::WwwAtomStream;
 use strict;
 use warnings;
 
-# FIXME: locale-independence:
 use POSIX qw(strftime);
-use Date::Parse qw(strptime);
 use Digest::SHA qw(sha1_hex);
 use PublicInbox::Address;
 use PublicInbox::Hval qw(ascii_html);
 use PublicInbox::MID qw/mid_clean mid_escape/;
+use PublicInbox::MsgTime qw(msg_timestamp);
 
 # called by PSGI server after getline:
 sub close {}
@@ -34,8 +36,8 @@ sub response {
 sub getline {
        my ($self) = @_;
        if (my $middle = $self->{cb}) {
-               my $mime = $middle->();
-               return feed_entry($self, $mime) if $mime;
+               my $smsg = $middle->();
+               return feed_entry($self, $smsg) if $smsg;
        }
        delete $self->{cb} ? '</feed>' : undef;
 }
@@ -93,10 +95,11 @@ sub mid2uuid ($) {
 
 # returns undef or string
 sub feed_entry {
-       my ($self, $mime) = @_;
+       my ($self, $smsg) = @_;
        my $ctx = $self->{ctx};
+       my $mime = $smsg->{mime};
        my $hdr = $mime->header_obj;
-       my $mid = mid_clean($hdr->header_raw('Message-ID'));
+       my $mid = $smsg->mid;
        my $irt = PublicInbox::View::in_reply_to($hdr);
        my $uuid = mid2uuid($mid);
        my $base = $ctx->{feed_base_url};
@@ -109,9 +112,8 @@ sub feed_entry {
                $irt = '';
        }
        my $href = $base . mid_escape($mid) . '/';
-       my $date = $hdr->header('Date');
-       my @t = eval { strptime($date) } if defined $date;
-       @t = gmtime(time) unless scalar @t;
+       my $t = msg_timestamp($hdr);
+       my @t = gmtime(defined $t ? $t : time);
        my $updated = feed_updated(@t);
 
        my $title = $hdr->header('Subject');
@@ -130,13 +132,13 @@ sub feed_entry {
        }
        $s .= "<entry><author><name>$name</name><email>$email</email>" .
                "</author>$title$updated" .
+               qq(<link\nhref="$href"/>).
+               "<id>$uuid</id>$irt" .
                qq{<content\ntype="xhtml">} .
                qq{<div\nxmlns="http://www.w3.org/1999/xhtml">} .
                qq(<pre\nstyle="white-space:pre-wrap">) .
-               PublicInbox::View::multipart_text_as_html($mime, $href) .
-               '</pre>' .
-               qq!</div></content><link\nhref="$href"/>!.
-               "<id>$uuid</id>$irt</entry>";
+               PublicInbox::View::multipart_text_as_html($mime, $href, $ctx) .
+               '</pre></div></content></entry>';
 }
 
 sub feed_updated {