]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: support publicinbox.imapserver
authorEric Wong <e@80x24.org>
Thu, 16 Sep 2021 00:26:52 +0000 (00:26 +0000)
committerEric Wong <e@80x24.org>
Thu, 16 Sep 2021 04:29:12 +0000 (04:29 +0000)
This allows PublicInbox::WWW hosts to advertise the existence of
IMAP servers in addition to NNTP servers.

Documentation/public-inbox-config.pod
lib/PublicInbox/Config.pm
lib/PublicInbox/Inbox.pm
lib/PublicInbox/WwwText.pm

index 5b86ef6cbfcd0152cb8ff41a285c28e31835fea3..a5bc67fd63289f69f3fce69a8218db23371bd884 100644 (file)
@@ -62,13 +62,15 @@ Default: none, optional
 
 =item publicinbox.<name>.newsgroup
 
-The NNTP group name for use with L<public-inbox-nntpd(8)>.  This
+The NNTP group name for use with L<public-inbox-nntpd(1)>.  This
 may be any newsgroup name with hierarchies delimited by C<.>.
 For example, the newsgroup for L<mailto:meta@public-inbox.org>
 is: C<inbox.comp.mail.public-inbox.meta>
 
-Omitting this for the given inbox will prevent the group from
-being read by L<public-inbox-nntpd(1)>
+It also configures the folder hierarchy used by L<public-inbox-imapd(1)>.
+
+Omitting this for a given inbox will prevent the inbox from
+being served by L<public-inbox-nntpd(1)> and/or L<public-inbox-imapd(1)>.
 
 Default: none, optional
 
@@ -98,6 +100,12 @@ needs to match.
 
 Default: none
 
+=item publicinbox.<name>.imapmirror
+
+This may be the full IMAP URL of an independently-run IMAP mirror.
+
+Default: none
+
 =item publicinbox.<name>.nntpmirror
 
 This may be the full NNTP URL of an independently-run mirror.
@@ -203,14 +211,18 @@ See L<public-inbox-watch(1)>
 
 See L<public-inbox-watch(1)>
 
-=item publicinbox.nntpserver
+=item publicinbox.imapserver
 
-Set this to point to the hostname of the L<public-inbox-nntpd(1)>
-instance.  This is used to advertise the existence of the NNTP
+Set this to point to the hostname(s) of the L<public-inbox-imapd(1)>
+instance.  This is used to advertise the existence of the IMAP
 endpoint in the L<PublicInbox::WWW> HTML interface.
 
-Multiple values are allowed for instances with multiple hostnames
-or mirrors.
+Default: none
+
+=item publicinbox.nntpserver
+
+Same as C<publicinbox.imapserver>, but for the hostname(s) of the
+L<public-inbox-nntpd(1)> instance.
 
 Default: none
 
index 5e7a9f2b6d8d55e61fce036ca101bbda10c9f761..b3bf5d12c4169ad4344d8ad6fe974582829151d1 100644 (file)
@@ -450,8 +450,9 @@ sub _fill_ibx {
        }
        # TODO: more arrays, we should support multi-value for
        # more things to encourage decentralization
-       for my $k (qw(address altid nntpmirror coderepo hide listid url
-                       infourl watchheader nntpserver)) {
+       for my $k (qw(address altid nntpmirror imapmirror
+                       coderepo hide listid url
+                       infourl watchheader nntpserver imapserver)) {
                my $v = $self->{"$pfx.$k"} // next;
                $ibx->{$k} = _array($v);
        }
index f234b96f782f66f76d11df40f83e2ede5710c54b..6cd20ec0b0418a088785e8ac0e70a94f0419688e 100644 (file)
@@ -258,50 +258,52 @@ sub base_url {
        };
 }
 
-sub nntp_url {
-       my ($self, $ctx) = @_;
-       $self->{-nntp_url} ||= do {
-               # no checking for nntp_usable here, we can point entirely
-               # to non-local servers or users run by a different user
-               my $ns = $self->{nntpserver} //
-                      $ctx->{www}->{pi_cfg}->get_all('publicinbox.nntpserver');
-               my $group = $self->{newsgroup};
-               my @urls;
-               if ($ns && $group) {
-                       @urls = map {
-                               my $u = m!\Anntps?://! ? $_ : "nntp://$_";
-                               $u .= '/' if $u !~ m!/\z!;
-                               $u.$group;
-                       } @$ns;
-               }
-               my $mirrors = $self->{nntpmirror};
-               if ($mirrors) {
-                       my @m;
-                       foreach (@$mirrors) {
-                               my $u = m!\Anntps?://! ? $_ : "nntp://$_";
-                               if ($u =~ m!\Anntps?://[^/]+/?\z!) {
-                                       if ($group) {
-                                               $u .= '/' if $u !~ m!/\z!;
-                                               $u .= $group;
-                                       } else {
-                                               warn
-"publicinbox.$self->{name}.nntpmirror=$_ missing newsgroup name\n";
-                                       }
+sub _x_url ($$$) {
+       my ($self, $x, $ctx) = @_; # $x is "nntp" or "imap"
+       # no checking for nntp_usable here, we can point entirely
+       # to non-local servers or users run by a different user
+       my $ns = $self->{"${x}server"} //
+              $ctx->{www}->{pi_cfg}->get_all("publicinbox.${x}server");
+       my $group = $self->{newsgroup};
+       my @urls;
+       if ($ns && $group) {
+               @urls = map {
+                       my $u = m!\A${x}s?://! ? $_ : "$x://$_";
+                       $u .= '/' if $u !~ m!/\z!;
+                       $u.$group;
+               } @$ns;
+       }
+       if (my $mirrors = $self->{"${x}mirror"}) {
+               my @m;
+               for (@$mirrors) {
+                       my $u = m!\A${x}s?://! ? $_ : "$x://$_";
+                       if ($u =~ m!\A${x}s?://[^/]+/?\z!) {
+                               if ($group) {
+                                       $u .= '/' if $u !~ m!/\z!;
+                                       $u .= $group;
+                               } else { # n.b. IMAP uses "newsgroup"
+                                       warn <<EOM;
+publicinbox.$self->{name}.${x}mirror=$_ missing newsgroup name
+EOM
                                }
-                               # else: allow full URLs like:
-                               # nntp://news.example.com/alt.example
-                               push @m, $u;
                        }
-
-                       # List::Util::uniq requires Perl 5.26+, maybe we
-                       # can use it by 2030 or so
-                       my %seen;
-                       @urls = grep { !$seen{$_}++ } (@urls, @m);
+                       # else: allow full URLs like:
+                       # nntp://news.example.com/alt.example
+                       push @m, $u;
                }
-               \@urls;
-       };
+
+               # List::Util::uniq requires Perl 5.26+, maybe we
+               # can use it by 2030 or so
+               my %seen;
+               @urls = grep { !$seen{$_}++ } (@urls, @m);
+       }
+       \@urls;
 }
 
+# my ($self, $ctx) = @_;
+sub nntp_url { $_[0]->{-nntp_url} //= _x_url($_[0], 'nntp', $_[1]) }
+sub imap_url { $_[0]->{-imap_url} //= _x_url($_[0], 'imap', $_[1]) }
+
 sub nntp_usable {
        my ($self) = @_;
        my $ret = mm($self) && over($self);
index 177d55e46aa1b6a2d269e29b512a9bc06306b0e4..bb9a0a0ff54b5e3edd1b6cd83c428a70a72a6de6 100644 (file)
@@ -211,6 +211,7 @@ EOF
                $$txt .= "\t$k = $v\n";
        }
        $$txt .= "\tnntpmirror = $_\n" for (@{$ibx->nntp_url($ctx)});
+       $$txt .= "\timapmirror = $_\n" for (@{$ibx->imap_url($ctx)});
        _coderepo_config($ctx, $txt);
        1;
 }
@@ -342,6 +343,17 @@ EOM
 
 Example config snippet for mirrors: $cfg_link
 EOF
+       if ($ibx->can('imap_url')) {
+               my $imap = $ibx->imap_url($ctx);
+               if (@$imap) {
+                       $$txt .= "\n";
+                       $$txt .= 'IMAP subfolder(s) available under:';
+                       $$txt .= "\n\t" . join("\n\t", @$imap) . "\n";
+                       $$txt .= <<EOM
+       # each subfolder (starting with `0') holds 50K messages at most
+EOM
+               }
+       }
        if ($ibx->can('nntp_url')) {
                my $nntp = $ibx->nntp_url($ctx);
                if (scalar @$nntp) {