From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: meta@public-inbox.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 4BC351F452 for ; Tue, 22 Sep 2015 10:09:52 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/7] nntp: avoid setting Bytes and Lines headers Date: Tue, 22 Sep 2015 10:09:45 +0000 Message-Id: <20150922100948.8160-5-e@80x24.org> In-Reply-To: <20150922100948.8160-1-e@80x24.org> References: <20150922100948.8160-1-e@80x24.org> List-Id: These are internal metadata should be calculated, so avoid leaking it into the header. --- lib/PublicInbox/NNTP.pm | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 71b774d..e5bb683 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -374,18 +374,16 @@ found: my $bytes; my $s = eval { Email::MIME->new($ng->gcf->cat_file($o, \$bytes)) }; return $err unless $s; + my $lines; if ($set_headers) { $s->header_set('Newsgroups', $ng->{name}); - $s->header_set('Lines', $s->body =~ tr!\n!\n!); $s->header_set('Xref', xref($ng, $n)); + $lines = $s->body =~ tr!\n!\n!; # must be last - if ($set_headers == 2) { - $s->header_set('Bytes', $bytes); - $s->body_set(''); - } + $s->body_set('') if ($set_headers == 2); } - [ $n, $mid, $s ]; + [ $n, $mid, $s, $bytes, $lines ]; } sub simple_body_write ($$) { @@ -399,13 +397,6 @@ sub simple_body_write ($$) { '.' } -sub header_str ($) { - my ($s) = @_; - my $h = $s->header_obj; - $h->header_set('Bytes'); - $h->as_string -} - sub set_art { my ($self, $art) = @_; $self->{article} = $art if defined $art && $art =~ /\A\d+\z/; @@ -418,7 +409,7 @@ sub cmd_article ($;$) { my ($n, $mid, $s) = @$r; set_art($self, $art); more($self, "220 $n <$mid> article retrieved - head and body follow"); - do_more($self, header_str($s)); + do_more($self, $s->header_obj->as_string); do_more($self, "\r\n"); simple_body_write($self, $s); } @@ -430,7 +421,7 @@ sub cmd_head ($;$) { my ($n, $mid, $s) = @$r; set_art($self, $art); more($self, "221 $n <$mid> article retrieved - head follows"); - do_more($self, header_str($s)); + do_more($self, $s->header_obj->as_string); '.' } @@ -486,6 +477,9 @@ sub get_range ($$) { sub xhdr ($$) { my ($r, $header) = @_; + $header = lc $header; + return $r->[3] if ($header eq 'bytes'); + return $r->[4] if ($header eq 'lines'); $r = $r->[2]->header_obj->header($header); defined $r or return; $r =~ s/[\r\n\t]+/ /sg; -- EW