X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWwwAtomStream.pm;h=ecb82bc39bec19a319ccc33380e6da180fc7723a;hb=5a2891dc8a0270af2e5cca0964bb862556b61d20;hp=5720384cf648f4f50c93f661f2ab467bf2392d77;hpb=95d4bf7aded41cb3b0040c321d315532f68633e1;p=public-inbox.git diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm index 5720384c..ecb82bc3 100644 --- a/lib/PublicInbox/WwwAtomStream.pm +++ b/lib/PublicInbox/WwwAtomStream.pm @@ -6,13 +6,12 @@ package PublicInbox::WwwAtomStream; use strict; use warnings; -# FIXME: locale-independence: use POSIX qw(strftime); -use Date::Parse qw(strptime); - +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 mid2path mid_escape/; +use PublicInbox::MID qw/mid_clean mid_escape/; # called by PSGI server after getline: sub close {} @@ -72,7 +71,8 @@ sub atom_header { my $mtime = (stat($ibx->{mainrepo}))[9] || time; qq(\n) . - qq{} . + qq() . qq{$title} . qq() . @@ -81,25 +81,36 @@ sub atom_header { feed_updated(gmtime($mtime)); } +sub mid2uuid ($) { + my ($mid) = @_; + utf8::encode($mid); # really screwed up In-Reply-To fields exist + $mid = sha1_hex($mid); + my $h = '[a-f0-9]'; + my (@uuid5) = ($mid =~ m!\A($h{8})($h{4})($h{4})($h{4})($h{12})!o); + 'urn:uuid:' . join('-', @uuid5); +} + # returns undef or string sub feed_entry { my ($self, $mime) = @_; my $ctx = $self->{ctx}; my $hdr = $mime->header_obj; my $mid = mid_clean($hdr->header_raw('Message-ID')); - - my $uuid = mid2path($mid); - $uuid =~ tr!/!!d; - my $h = '[a-f0-9]'; - my (@uuid5) = ($uuid =~ m!\A($h{8})($h{4})($h{4})($h{4})($h{12})!o); - $uuid = 'urn:uuid:' . join('-', @uuid5); - - $mid = PublicInbox::Hval->new_msgid($mid); - my $href = $ctx->{feed_base_url} . $mid->{href}. '/'; - + my $irt = PublicInbox::View::in_reply_to($hdr); + my $uuid = mid2uuid($mid); + my $base = $ctx->{feed_base_url}; + if (defined $irt) { + my $irt_uuid = mid2uuid($irt); + $irt = mid_escape($irt); + $irt = qq(); + } else { + $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 = eval { str2time($date) } if defined $date; + my @t = gmtime(defined $t ? $t : time); my $updated = feed_updated(@t); my $title = $hdr->header('Subject'); @@ -118,13 +129,13 @@ sub feed_entry { } $s .= "$name$email" . "$title$updated" . + qq(). + "$uuid$irt" . qq{} . qq{} . qq() . PublicInbox::View::multipart_text_as_html($mime, $href) . - '' . - qq!!. - "$uuid"; + ''; } sub feed_updated {