]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NNTP.pm
nntp: use substr to check for trailing CRLF
[public-inbox.git] / lib / PublicInbox / NNTP.pm
index 3929f81737901507e06c80994a694718617e3910..b223eb07d417bad27115bcf5411090f4e9ab257c 100644 (file)
@@ -502,7 +502,7 @@ sub msg_body_write ($$) {
        # these can momentarily double the memory consumption :<
        $$msg =~ s/^\./../smg;
        $$msg =~ s/(?<!\r)\n/\r\n/sg; # Alpine barfs without this
-       $$msg .= "\r\n" unless $$msg =~ /\r\n\z/s;
+       $$msg .= "\r\n" unless substr($$msg, -2, 2) eq "\r\n";
        $self->msg_more($$msg);
 }
 
@@ -883,8 +883,6 @@ sub cmd_xover ($;$) {
        $self->long_response(\&xover_i, @$r);
 }
 
-sub compressed { undef }
-
 sub cmd_starttls ($) {
        my ($self) = @_;
        my $sock = $self->{sock} or return;
@@ -903,7 +901,9 @@ sub cmd_compress ($$) {
        my ($self, $alg) = @_;
        return "503 Only DEFLATE is supported\r\n" if uc($alg) ne 'DEFLATE';
        return r502 if $self->compressed;
-       PublicInbox::NNTPdeflate->enable($self);
+       PublicInbox::NNTPdeflate->enable($self) or return
+                               \"403 Unable to activate compression\r\n";
+       PublicInbox::DS::write($self, \"206 Compression active\r\n");
        $self->requeue;
        undef
 }
@@ -985,4 +985,8 @@ sub busy { # for graceful shutdown in PublicInbox::Daemon:
        defined($self->{rbuf}) || defined($self->{wbuf})
 }
 
+package PublicInbox::NNTPdeflate;
+use PublicInbox::DSdeflate;
+our @ISA = qw(PublicInbox::DSdeflate PublicInbox::NNTP);
+
 1;