From: Eric Wong Date: Sat, 19 Sep 2015 02:03:38 +0000 (+0000) Subject: nntp: fix ARTICLE/HEAD/BODY/STAT X-Git-Tag: v1.0.0~863 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=2e8669171f148ecfd410cca543f8794d0f3d69a5 nntp: fix ARTICLE/HEAD/BODY/STAT Article number is optional, but we need to update the article number of the client connection if it was specified (but not if it was given a Message-ID) as stipulated by RFC 977 --- diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 3ded0de4..01039ba1 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -388,41 +388,50 @@ sub header_str ($) { $h->as_string } -sub cmd_article ($$) { +sub set_art { + my ($self, $art) = @_; + $self->{article} = $art if defined $art && $art =~ /\A\d+\z/; +} + +sub cmd_article ($;$) { my ($self, $art) = @_; my $r = $self->art_lookup($art, 1); return $r unless ref $r; 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, "\r\n"); simple_body_write($self, $s); } -sub cmd_head ($$) { +sub cmd_head ($;$) { my ($self, $art) = @_; my $r = $self->art_lookup($art, 2); return $r unless ref $r; my ($n, $mid, $s) = @$r; + set_art($self, $art); more($self, "221 $n <$mid> article retrieved - head follows"); do_more($self, header_str($s)); '.' } -sub cmd_body ($$) { +sub cmd_body ($;$) { my ($self, $art) = @_; my $r = $self->art_lookup($art, 0); return $r unless ref $r; my ($n, $mid, $s) = @$r; + set_art($self, $art); more($self, "222 $n <$mid> article retrieved - body follows"); simple_body_write($self, $s); } -sub cmd_stat ($$) { +sub cmd_stat ($;$) { my ($self, $art) = @_; my $r = $self->art_lookup($art, 0); return $r unless ref $r; my ($n, $mid, undef) = @$r; + set_art($self, $art); "223 $n <$mid> article retrieved - request text separately"; }