unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 0/3] www: support publicinbox.imapserver
@ 2021-09-16  0:26 Eric Wong
  2021-09-16  0:26 ` [PATCH 1/3] inbox: streamline ->nntp_url Eric Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Wong @ 2021-09-16  0:26 UTC (permalink / raw)
  To: meta

public-inbox-imapd seems to be holding up so far,
so I guess it's safe to advertise...

Eric Wong (3):
  inbox: streamline ->nntp_url
  www: support publicinbox.imapserver
  www_stream: note existence of IMAP and NNTP URLs

 Documentation/public-inbox-config.pod | 28 ++++++---
 lib/PublicInbox/Config.pm             |  7 ++-
 lib/PublicInbox/Inbox.pm              | 83 +++++++++++++--------------
 lib/PublicInbox/WwwStream.pm          | 20 ++++++-
 lib/PublicInbox/WwwText.pm            | 16 +++++-
 t/config.t                            | 13 +++--
 6 files changed, 107 insertions(+), 60 deletions(-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] inbox: streamline ->nntp_url
  2021-09-16  0:26 [PATCH 0/3] www: support publicinbox.imapserver Eric Wong
@ 2021-09-16  0:26 ` Eric Wong
  2021-09-16  0:26 ` [PATCH 2/3] www: support publicinbox.imapserver Eric Wong
  2021-09-16  0:26 ` [PATCH 3/3] www_stream: note existence of IMAP and NNTP URLs Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2021-09-16  0:26 UTC (permalink / raw)
  To: meta

We no longer waste a precious hash slot for a per-Inbox
{nntpserver} if it's only configured globally for all inboxes.
---
 lib/PublicInbox/Config.pm  |  4 ++--
 lib/PublicInbox/Inbox.pm   |  9 +++------
 lib/PublicInbox/WwwText.pm |  4 ++--
 t/config.t                 | 13 +++++++++----
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index ee5322fe..5e7a9f2b 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -424,7 +424,7 @@ sub _fill_ibx {
 	my ($self, $name) = @_;
 	my $pfx = "publicinbox.$name";
 	my $ibx = {};
-	for my $k (qw(watch nntpserver)) {
+	for my $k (qw(watch)) {
 		my $v = $self->{"$pfx.$k"};
 		$ibx->{$k} = $v if defined $v;
 	}
@@ -451,7 +451,7 @@ 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)) {
+			infourl watchheader nntpserver)) {
 		my $v = $self->{"$pfx.$k"} // next;
 		$ibx->{$k} = _array($v);
 	}
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index b0bb9dcc..f234b96f 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -109,8 +109,6 @@ sub new {
 	} else {
 		delete $opts->{feedmax};
 	}
-	$opts->{nntpserver} ||= $pi_cfg->{'publicinbox.nntpserver'};
-
 	# allow any combination of multi-line or comma-delimited hide entries
 	my $hide = {};
 	if (defined(my $h = $opts->{hide})) {
@@ -261,22 +259,21 @@ sub base_url {
 }
 
 sub nntp_url {
-	my ($self) = @_;
+	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};
+		my $ns = $self->{nntpserver} //
+		       $ctx->{www}->{pi_cfg}->get_all('publicinbox.nntpserver');
 		my $group = $self->{newsgroup};
 		my @urls;
 		if ($ns && $group) {
-			$ns = [ $ns ] if ref($ns) ne 'ARRAY';
 			@urls = map {
 				my $u = m!\Anntps?://! ? $_ : "nntp://$_";
 				$u .= '/' if $u !~ m!/\z!;
 				$u.$group;
 			} @$ns;
 		}
-
 		my $mirrors = $self->{nntpmirror};
 		if ($mirrors) {
 			my @m;
diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm
index fabe39f6..177d55e4 100644
--- a/lib/PublicInbox/WwwText.pm
+++ b/lib/PublicInbox/WwwText.pm
@@ -210,7 +210,7 @@ EOF
 		defined(my $v = $ibx->{$k}) or next;
 		$$txt .= "\t$k = $v\n";
 	}
-	$$txt .= "\tnntpmirror = $_\n" for (@{$ibx->nntp_url});
+	$$txt .= "\tnntpmirror = $_\n" for (@{$ibx->nntp_url($ctx)});
 	_coderepo_config($ctx, $txt);
 	1;
 }
@@ -343,7 +343,7 @@ EOM
 Example config snippet for mirrors: $cfg_link
 EOF
 	if ($ibx->can('nntp_url')) {
-		my $nntp = $ibx->nntp_url;
+		my $nntp = $ibx->nntp_url($ctx);
 		if (scalar @$nntp) {
 			$$txt .= "\n";
 			$$txt .= @$nntp == 1 ? 'Newsgroup' : 'Newsgroups are';
diff --git a/t/config.t b/t/config.t
index 877e5d5d..2b02f063 100644
--- a/t/config.t
+++ b/t/config.t
@@ -43,7 +43,6 @@ my ($tmpdir, $for_destroy) = tmpdir();
 		-primary_address => 'meta@public-inbox.org',
 		'name' => 'meta',
 		-httpbackend_limiter => undef,
-		nntpserver => undef,
 	}, "lookup matches expected output");
 
 	is($cfg->lookup('blah@example.com'), undef,
@@ -60,7 +59,6 @@ my ($tmpdir, $for_destroy) = tmpdir();
 		'name' => 'test',
 		'url' => [ 'http://example.com/test' ],
 		-httpbackend_limiter => undef,
-		nntpserver => undef,
 	}, "lookup matches expected output for test");
 }
 
@@ -99,20 +97,27 @@ EOF
 	my $str = <<EOF;
 $pfx.address=test\@example.com
 $pfx.inboxdir=/path/to/non/existent
+$pfx.newsgroup=inbox.test
 publicinbox.nntpserver=news.example.com
 EOF
 	my $cfg = PublicInbox::Config->new(\$str);
 	my $ibx = $cfg->lookup_name('test');
-	is($ibx->{nntpserver}, 'news.example.com', 'global NNTP server');
+	is_deeply($ibx->nntp_url({ www => { pi_cfg => $cfg }}),
+		[ 'nntp://news.example.com/inbox.test' ],
+		'nntp_url uses global NNTP server');
 
 	$str = <<EOF;
 $pfx.address=test\@example.com
 $pfx.inboxdir=/path/to/non/existent
+$pfx.newsgroup=inbox.test
 $pfx.nntpserver=news.alt.example.com
+publicinbox.nntpserver=news.example.com
 EOF
 	$cfg = PublicInbox::Config->new(\$str);
 	$ibx = $cfg->lookup_name('test');
-	is($ibx->{nntpserver}, 'news.alt.example.com','per-inbox NNTP server');
+	is_deeply($ibx->nntp_url({ www => { pi_cfg => $cfg }}),
+		[ 'nntp://news.alt.example.com/inbox.test' ],
+		'nntp_url uses per-inbox NNTP server');
 }
 
 # no obfuscate domains

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] www: support publicinbox.imapserver
  2021-09-16  0:26 [PATCH 0/3] www: support publicinbox.imapserver Eric Wong
  2021-09-16  0:26 ` [PATCH 1/3] inbox: streamline ->nntp_url Eric Wong
@ 2021-09-16  0:26 ` Eric Wong
  2021-09-16  0:26 ` [PATCH 3/3] www_stream: note existence of IMAP and NNTP URLs Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2021-09-16  0:26 UTC (permalink / raw)
  To: meta

This allows PublicInbox::WWW hosts to advertise the existence of
IMAP servers in addition to NNTP servers.
---
 Documentation/public-inbox-config.pod | 28 +++++++---
 lib/PublicInbox/Config.pm             |  5 +-
 lib/PublicInbox/Inbox.pm              | 80 ++++++++++++++-------------
 lib/PublicInbox/WwwText.pm            | 12 ++++
 4 files changed, 76 insertions(+), 49 deletions(-)

diff --git a/Documentation/public-inbox-config.pod b/Documentation/public-inbox-config.pod
index 5b86ef6c..a5bc67fd 100644
--- a/Documentation/public-inbox-config.pod
+++ b/Documentation/public-inbox-config.pod
@@ -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
 
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 5e7a9f2b..b3bf5d12 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -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);
 	}
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);
diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm
index 177d55e4..bb9a0a0f 100644
--- a/lib/PublicInbox/WwwText.pm
+++ b/lib/PublicInbox/WwwText.pm
@@ -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) {

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] www_stream: note existence of IMAP and NNTP URLs
  2021-09-16  0:26 [PATCH 0/3] www: support publicinbox.imapserver Eric Wong
  2021-09-16  0:26 ` [PATCH 1/3] inbox: streamline ->nntp_url Eric Wong
  2021-09-16  0:26 ` [PATCH 2/3] www: support publicinbox.imapserver Eric Wong
@ 2021-09-16  0:26 ` Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2021-09-16  0:26 UTC (permalink / raw)
  To: meta

The "mirror" link may not clue users into the existence of
NNTP and IMAP servers, so add a note about them (but don't
list them, in case there are dozens of URLs :>).
---
 lib/PublicInbox/WwwStream.pm | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index a88ff972..5be5ed0c 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -116,8 +116,26 @@ sub _html_end {
 		$x = <<EOF;
 This is a public inbox, see <a
 href="$m">mirroring instructions</a>
-on how to clone and mirror all data and code used for this inbox
+for how to clone and mirror all data and code used for this inbox
 EOF
+		my $has_nntp = @{$ctx->{ibx}->nntp_url($ctx)};
+		my $has_imap = @{$ctx->{ibx}->imap_url($ctx)};
+		if ($has_nntp || $has_imap) {
+			substr($x, -1, 1) = ";\n"; # s/\n/;\n
+			if ($has_nntp && $has_imap) {
+				$x .= <<EOM;
+as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).
+EOM
+			} elsif ($has_nntp) {
+				$x .= <<EOM;
+as well as URLs for NNTP newsgroup(s).
+EOM
+			} else {
+				$x .= <<EOM;
+as well as URLs for IMAP folder(s).
+EOM
+			}
+		}
 	} else {
 		$x = <<EOF;
 This is an external index of several public inboxes,

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-16  0:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-16  0:26 [PATCH 0/3] www: support publicinbox.imapserver Eric Wong
2021-09-16  0:26 ` [PATCH 1/3] inbox: streamline ->nntp_url Eric Wong
2021-09-16  0:26 ` [PATCH 2/3] www: support publicinbox.imapserver Eric Wong
2021-09-16  0:26 ` [PATCH 3/3] www_stream: note existence of IMAP and NNTP URLs Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).