about summary refs log tree commit homepage
path: root/lib/PublicInbox/Inbox.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-09-16 00:26:52 +0000
committerEric Wong <e@80x24.org>2021-09-16 04:29:12 +0000
commit3690f0625fbfb75dcc73986d78abba738e9113a4 (patch)
treea14a9b4aca80b9b168bf8bfbeb49dd624b45ce64 /lib/PublicInbox/Inbox.pm
parentb4bc9aeed78078feae58d150970fe224f10098e3 (diff)
downloadpublic-inbox-3690f0625fbfb75dcc73986d78abba738e9113a4.tar.gz
This allows PublicInbox::WWW hosts to advertise the existence of
IMAP servers in addition to NNTP servers.
Diffstat (limited to 'lib/PublicInbox/Inbox.pm')
-rw-r--r--lib/PublicInbox/Inbox.pm80
1 files changed, 41 insertions, 39 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index f234b96f..6cd20ec0 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -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);