X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWwwAtomStream.pm;h=c3fbb1a7cef589479f55860474390a7a3b3e5687;hb=c91490ccae1a1775da1e816866ef0b08b234ff54;hp=05659f1fad7e2355cdd3052f1e597daebee54449;hpb=290b8ef18659a52f3cfa97458b5dc5334519dfed;p=public-inbox.git diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm index 05659f1f..c3fbb1a7 100644 --- a/lib/PublicInbox/WwwAtomStream.pm +++ b/lib/PublicInbox/WwwAtomStream.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2019 all contributors +# Copyright (C) 2016-2020 all contributors # License: AGPL-3.0+ # # Atom body stream for which yields getline+close methods @@ -12,8 +12,7 @@ use warnings; use POSIX qw(strftime); 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::Hval qw(ascii_html mid_href); use PublicInbox::MsgTime qw(msg_timestamp); # called by PSGI server after getline: @@ -21,9 +20,8 @@ sub close {} sub new { my ($class, $ctx, $cb) = @_; - $ctx->{emit_header} = 1; $ctx->{feed_base_url} = $ctx->{-inbox}->base_url($ctx->{env}); - bless { cb => $cb || *close, ctx => $ctx }, $class; + bless { cb => $cb || \&close, ctx => $ctx, emit_header => 1 }, $class; } sub response { @@ -36,7 +34,7 @@ sub response { sub getline { my ($self) = @_; if (my $middle = $self->{cb}) { - my $smsg = $middle->(); + my $smsg = $middle->($self->{ctx}); return feed_entry($self, $smsg) if $smsg; } delete $self->{cb} ? '' : undef; @@ -71,7 +69,7 @@ sub atom_header { my $mid = $ctx->{mid}; my $page_id; if (defined $mid) { # per-thread - $self_url .= mid_escape($mid).'/t.atom'; + $self_url .= mid_href($mid).'/t.atom'; $page_id = to_uuid("t\n".$mid) } elsif (defined $search_q) { my $query = $search_q->{'q'}; @@ -84,7 +82,7 @@ sub atom_header { $self_url .= 'new.atom'; $page_id = "mailto:$ibx->{-primary_address}"; } - my $mtime = (stat($ibx->{mainrepo}))[9] || time; + my $mtime = (stat($ibx->{inboxdir}))[9] || time; qq(\n) . qq({ctx}; - my $mime = $smsg->{mime}; + my $mid = $smsg->mid; # may extract Message-ID from {mime} + my $mime = delete $smsg->{mime}; my $hdr = $mime->header_obj; - my $mid = $smsg->mid; my $irt = PublicInbox::View::in_reply_to($hdr); my $uuid = to_uuid($mid); my $base = $ctx->{feed_base_url}; if (defined $irt) { my $irt_uuid = to_uuid($irt); - $irt = mid_escape($irt); + $irt = mid_href($irt); $irt = qq(); } else { $irt = ''; } - my $href = $base . mid_escape($mid) . '/'; + my $href = $base . mid_href($mid) . '/'; my $t = msg_timestamp($hdr); my @t = gmtime(defined $t ? $t : time); my $updated = feed_updated(@t); @@ -131,7 +129,7 @@ sub feed_entry { $email = ascii_html($email); my $s = ''; - if (delete $ctx->{emit_header}) { + if (delete $self->{emit_header}) { $s .= atom_header($ctx, $title); } $s .= "$name$email" . @@ -140,9 +138,12 @@ sub feed_entry { "$uuid$irt" . qq{} . qq{} . - qq() . - PublicInbox::View::multipart_text_as_html($mime, $href, $ctx) . - ''; + qq(); + $ctx->{obuf} = \$s; + $ctx->{mhref} = $href; + PublicInbox::View::multipart_text_as_html($mime, $ctx); + delete $ctx->{obuf}; + $s .= ''; } sub feed_updated {