]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NNTP.pm
update copyrights for 2018
[public-inbox.git] / lib / PublicInbox / NNTP.pm
index 5b055bca0c9c9ef859e85fc7da4cef162668da67..56d8e010f96b7d2db8061f100213b1e47f6eaf8e 100644 (file)
@@ -1,5 +1,5 @@
-# Copyright (C) 2015 all contributors <meta@public-inbox.org>
-# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+# Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Each instance of this represents a NNTP client socket
 package PublicInbox::NNTP;
@@ -9,12 +9,14 @@ use base qw(Danga::Socket);
 use fields qw(nntpd article rbuf ng long_res);
 use PublicInbox::Search;
 use PublicInbox::Msgmap;
+use PublicInbox::MID qw(mid_escape);
 use PublicInbox::Git;
 require PublicInbox::EvCleanup;
 use Email::Simple;
 use POSIX qw(strftime);
 use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
-use URI::Escape qw(uri_escape_utf8);
+use Digest::SHA qw(sha1_hex);
+use Time::Local qw(timegm timelocal);
 use constant {
        r501 => '501 command syntax error',
        r221 => '221 Header follows',
@@ -125,6 +127,7 @@ sub process_line ($$) {
        my $res = eval { $req->($self, @args) };
        my $err = $@;
        if ($err && !$self->{closed}) {
+               local $/ = "\n";
                chomp($l);
                err($self, 'error from: %s (%s)', $l, $err);
                $res = '503 program fault - command not performed';
@@ -236,7 +239,6 @@ sub cmd_listgroup ($;$) {
 
 sub parse_time ($$;$) {
        my ($date, $time, $gmt) = @_;
-       use Time::Local qw();
        my ($hh, $mm, $ss) = unpack('A2A2A2', $time);
        if (defined $gmt) {
                $gmt =~ /\A(?:UTC|GMT)\z/i or die "GM invalid: $gmt";
@@ -248,15 +250,15 @@ sub parse_time ($$;$) {
                ($YYYY, $MM, $DD) = unpack('A4A2A2', $date);
        } else { # legacy clients send YYMMDD
                ($YYYY, $MM, $DD) = unpack('A2A2A2', $date);
-               if ($YYYY > strftime('%y', @now)) {
-                       my $cur_year = $now[5] + 1900;
+               my $cur_year = $now[5] + 1900;
+               if ($YYYY > $cur_year) {
                        $YYYY += int($cur_year / 1000) * 1000 - 100;
                }
        }
        if ($gmt) {
-               Time::Local::timegm($ss, $mm, $hh, $DD, $MM - 1, $YYYY);
+               timegm($ss, $mm, $hh, $DD, $MM - 1, $YYYY);
        } else {
-               Time::Local::timelocal($ss, $mm, $hh, $DD, $MM - 1, $YYYY);
+               timelocal($ss, $mm, $hh, $DD, $MM - 1, $YYYY);
        }
 }
 
@@ -285,7 +287,6 @@ sub wildmat2re (;$) {
        return $_[0] = qr/.*/ if (!defined $_[0] || $_[0] eq '*');
        my %keep;
        my $salt = rand;
-       use Digest::SHA qw(sha1_hex);
        my $tmp = $_[0];
 
        $tmp =~ s#(?<!\\)\[(.+)(?<!\\)\]#
@@ -420,7 +421,7 @@ sub set_nntp_headers {
        $hdr->header_set('Xref', xref($ng, $n));
        header_append($hdr, 'List-Post', "<mailto:$ng->{-primary_address}>");
        if (my $url = $ng->base_url) {
-               $mid = uri_escape_utf8($mid);
+               $mid = mid_escape($mid);
                header_append($hdr, 'Archived-At', "<$url$mid/>");
                header_append($hdr, 'List-Archive', "<$url>");
        }