1 # Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # represents an NNTPD (currently a singleton),
5 # see script/public-inbox-nntpd for how it is used
6 package PublicInbox::NNTPD;
10 use PublicInbox::Config;
11 use PublicInbox::InboxIdle;
15 my $pi_config = PublicInbox::Config->new;
16 my $name = $pi_config->{'publicinbox.nntpserver'};
17 if (!defined($name) or $name eq '') {
19 } elsif (ref($name) eq 'ARRAY') {
27 pi_config => $pi_config,
29 greet => \"201 $name ready - post via email\r\n",
30 # accept_tls => { SSL_server => 1, ..., SSL_reuse_ctx => ... }
31 # idler => PublicInbox::InboxIdle
36 my ($self, $sig) = @_;
37 my $pi_config = $sig ? PublicInbox::Config->new : $self->{pi_config};
38 my $groups = $pi_config->{-by_newsgroup}; # filled during each_inbox
39 $pi_config->each_inbox(sub {
41 my $ngname = $ibx->{newsgroup} or return;
43 warn 'multiple newsgroups not supported: '.
44 join(', ', @$ngname). "\n";
45 # Newsgroup name needs to be compatible with RFC 3977
46 # wildmat-exact and RFC 3501 (IMAP) ATOM-CHAR.
47 # Leave out a few chars likely to cause problems or conflicts:
48 # '|', '<', '>', ';', '#', '$', '&',
49 } elsif ($ngname =~ m![^A-Za-z0-9/_\.\-\~\@\+\=:]!) {
50 warn "newsgroup name invalid: `$ngname'\n";
51 delete $groups->{$ngname};
52 } elsif ($ibx->nntp_usable) {
53 # Only valid if msgmap and search works
55 # preload to avoid fragmentation:
59 delete $groups->{$ngname};
62 $self->{groupnames} = [ sort(keys %$groups) ];
63 $self->{pi_config} = $pi_config;
64 # this will destroy old groups that got deleted
65 $self->{groups} = $groups;
69 $_[0]->{idler} //= PublicInbox::InboxIdle->new($_[0]->{pi_config});