]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NNTP.pm
nntp: use msg_more as a method
[public-inbox.git] / lib / PublicInbox / NNTP.pm
index 57a67a50ff8475f1882a4aa6a90aa2e477c1d4cc..9b8b81ec66720ec959b7515d3d5e2a3929023508 100644 (file)
@@ -14,7 +14,7 @@ use PublicInbox::Git;
 require PublicInbox::EvCleanup;
 use Email::Simple;
 use POSIX qw(strftime);
-PublicInbox::DS->import(qw(now msg_more));
+PublicInbox::DS->import(qw(now));
 use Digest::SHA qw(sha1_hex);
 use Time::Local qw(timegm timelocal);
 use constant {
@@ -31,6 +31,14 @@ my @OVERVIEW = qw(Subject From Date Message-ID References Xref);
 my $OVERVIEW_FMT = join(":\r\n", @OVERVIEW, qw(Bytes Lines)) . ":\r\n";
 my $LIST_HEADERS = join("\r\n", @OVERVIEW,
                        qw(:bytes :lines Xref To Cc)) . "\r\n";
+my $CAPABILITIES = <<"";
+101 Capability list:\r
+VERSION 2\r
+READER\r
+NEWNEWS\r
+LIST ACTIVE ACTIVE.TIMES NEWSGROUPS OVERVIEW.FMT\r
+HDR\r
+OVER\r
 
 my $EXPMAP; # fd -> [ idle_time, $self ]
 my $expt;
@@ -121,6 +129,17 @@ sub process_line ($$) {
        res($self, $res);
 }
 
+# The keyword argument is not used (rfc3977 5.2.2)
+sub cmd_capabilities ($;$) {
+       my ($self, undef) = @_;
+       my $res = $CAPABILITIES;
+       if (ref($self->{sock}) ne 'IO::Socket::SSL' &&
+                       $self->{nntpd}->{accept_tls}) {
+               $res .= "STARTTLS\r\n";
+       }
+       $res .= '.';
+}
+
 sub cmd_mode ($$) {
        my ($self, $arg) = @_;
        $arg = uc $arg;
@@ -139,12 +158,12 @@ sub cmd_xgtitle ($;$) {
 
 sub list_overview_fmt ($) {
        my ($self) = @_;
-       msg_more($self, $OVERVIEW_FMT);
+       $self->msg_more($OVERVIEW_FMT);
 }
 
 sub list_headers ($;$) {
        my ($self) = @_;
-       msg_more($self, $LIST_HEADERS);
+       $self->msg_more($LIST_HEADERS);
 }
 
 sub list_active ($;$) {
@@ -498,7 +517,7 @@ sub msg_body_write ($$) {
        $$msg =~ s/^\./../smg;
        $$msg =~ s/(?<!\r)\n/\r\n/sg; # Alpine barfs without this
        $$msg .= "\r\n" unless $$msg =~ /\r\n\z/s;
-       msg_more($self, $$msg);
+       $self->msg_more($$msg);
        '.'
 }
 
@@ -519,7 +538,7 @@ sub msg_hdr_write ($$$) {
        # affect messages already in the archive.
        $hdr =~ s/^(Message-ID:)[ \t]*\r\n[ \t]+([^\r]+)\r\n/$1 $2\r\n/igsm;
        $hdr .= "\r\n" if $body_follows;
-       msg_more($self, $hdr);
+       $self->msg_more($hdr);
 }
 
 sub cmd_article ($;$) {
@@ -738,7 +757,7 @@ sub hdr_searchmsg ($$$$) {
                                $tmp .= $s->{num} . ' ' . $s->$field . "\r\n";
                        }
                        utf8::encode($tmp);
-                       msg_more($self, $tmp);
+                       $self->msg_more($tmp);
                        $cur = $msgs->[-1]->{num} + 1;
                });
        }
@@ -905,7 +924,7 @@ sub cmd_xpath ($$) {
 
 sub res ($$) { do_write($_[0], $_[1] . "\r\n") }
 
-sub more ($$) { msg_more($_[0], $_[1] . "\r\n") }
+sub more ($$) { $_[0]->msg_more($_[1] . "\r\n") }
 
 sub do_write ($$) {
        my $self = $_[0];