]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WwwAtomStream.pm
www: rework async_* to use method table
[public-inbox.git] / lib / PublicInbox / WwwAtomStream.pm
index 073df1dfaf6656b1e6739187f1e70d7a55d53cf4..1ed806fd42543fcf4ad650577f8ad369732fbccb 100644 (file)
@@ -1,10 +1,8 @@
 # Copyright (C) 2016-2020 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)
+# Atom body stream for HTTP responses
+# See PublicInbox::GzipFilter for details.
 package PublicInbox::WwwAtomStream;
 use strict;
 use parent 'PublicInbox::GzipFilter';
@@ -37,7 +35,7 @@ sub async_next ($) {
        warn "E: $@" if $@;
 }
 
-sub async_eml { # ->{async_eml} for async_blob_cb
+sub async_eml { # for async_blob_cb
        my ($ctx, $eml) = @_;
        my $smsg = delete $ctx->{smsg};
        $ctx->{http_out}->write($ctx->translate(feed_entry($ctx, $smsg, $eml)))
@@ -47,7 +45,7 @@ sub response {
        my ($class, $ctx, $code, $cb) = @_;
        my $res_hdr = [ 'Content-Type' => 'application/atom+xml' ];
        $class->new($ctx, $cb);
-       $ctx->psgi_response($code, $res_hdr, \&async_next, \&async_eml);
+       $ctx->psgi_response($code, $res_hdr);
 }
 
 # called once for each message by PSGI server
@@ -138,16 +136,13 @@ sub feed_entry {
        $title = '(no subject)' unless defined $title && $title ne '';
        $title = title_tag($title);
 
-       my $from = $hdr->header('From') or return;
+       my $from = $hdr->header('From') // $hdr->header('Sender') //
+               $ctx->{-inbox}->{-primary_address};
        my ($email) = PublicInbox::Address::emails($from);
-       my $name = join(', ',PublicInbox::Address::names($from));
-       $name = ascii_html($name);
-       $email = ascii_html($email);
+       my $name = ascii_html(join(', ', PublicInbox::Address::names($from)));
+       $email = ascii_html($email // $ctx->{-inbox}->{-primary_address});
 
-       my $s = '';
-       if (delete $ctx->{emit_header}) {
-               $s .= atom_header($ctx, $title);
-       }
+       my $s = delete($ctx->{emit_header}) ? atom_header($ctx, $title) : '';
        $s .= "<entry><author><name>$name</name><email>$email</email>" .
                "</author>$title$updated" .
                qq(<link\nhref="$href"/>).