-# Copyright (C) 2016 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2018 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;
use POSIX qw(strftime);
-use Date::Parse qw(str2time);
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 {}
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;
}
# 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};
$irt = '';
}
my $href = $base . mid_escape($mid) . '/';
- my $date = $hdr->header('Date');
- my $t = eval { str2time($date) } if defined $date;
+ my $t = msg_timestamp($hdr);
my @t = gmtime(defined $t ? $t : time);
my $updated = feed_updated(@t);
}
$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 {