user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH 0/2] config-related cleanups...
@ 2019-01-01 10:18 Eric Wong
  2019-01-01 10:18 ` [PATCH 1/2] use PublicInbox::Config::each_inbox where appropriate Eric Wong
  2019-01-01 10:18 ` [PATCH 2/2] config: relax name inbox name restrictions Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2019-01-01 10:18 UTC (permalink / raw)
  To: meta

I wanted to use a '.' in the middle of a inbox name and ran
myself out of space because indexlevel= was not picked up :x

Eric Wong (2):
  use PublicInbox::Config::each_inbox where appropriate
  config: relax name inbox name restrictions

 lib/PublicInbox/Config.pm       | 13 ++++++++++---
 lib/PublicInbox/WatchMaildir.pm | 19 ++++++++-----------
 script/public-inbox-index       | 14 ++++++--------
 3 files changed, 24 insertions(+), 22 deletions(-)

-- 
EW

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

* [PATCH 1/2] use PublicInbox::Config::each_inbox where appropriate
  2019-01-01 10:18 [PATCH 0/2] config-related cleanups Eric Wong
@ 2019-01-01 10:18 ` Eric Wong
  2019-01-01 10:18 ` [PATCH 2/2] config: relax name inbox name restrictions Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2019-01-01 10:18 UTC (permalink / raw)
  To: meta

No need to reach into PublicInbox::Config internals and iterate
through the hashref by hand
---
 lib/PublicInbox/WatchMaildir.pm | 19 ++++++++-----------
 script/public-inbox-index       | 14 ++++++--------
 2 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index 13dea16..b558cda 100644
--- a/lib/PublicInbox/WatchMaildir.pm
+++ b/lib/PublicInbox/WatchMaildir.pm
@@ -45,30 +45,27 @@ sub new {
 	my $spamcheck = PublicInbox::Spamcheck::get($config, $k, $default);
 	$spamcheck = _spamcheck_cb($spamcheck) if $spamcheck;
 
-	# need to make all inboxes writable for spam removal:
-	$config->each_inbox(sub { PublicInbox::InboxWritable->new($_[0]) });
+	$config->each_inbox(sub {
+		# need to make all inboxes writable for spam removal:
+		my $ibx = $_[0] = PublicInbox::InboxWritable->new($_[0]);
 
-	foreach $k (keys %$config) {
-		$k =~ /\Apublicinbox\.([^\.]+)\.watch\z/ or next;
-		my $name = $1;
-		my $watch = $config->{$k};
+		my $watch = $ibx->{watch} or return;
 		if ($watch =~ s/\Amaildir://) {
 			$watch =~ s!/+\z!!;
-			my $inbox = $config->lookup_name($name);
-			if (my $wm = $inbox->{watchheader}) {
+			if (my $wm = $ibx->{watchheader}) {
 				my ($k, $v) = split(/:/, $wm, 2);
-				$inbox->{-watchheader} = [ $k, qr/\Q$v\E/ ];
+				$ibx->{-watchheader} = [ $k, qr/\Q$v\E/ ];
 			}
 			my $new = "$watch/new";
 			my $cur = "$watch/cur";
 			push @mdir, $new, $cur;
 			die "$new already in use\n" if $mdmap{$new};
 			die "$cur already in use\n" if $mdmap{$cur};
-			$mdmap{$new} = $mdmap{$cur} = $inbox;
+			$mdmap{$new} = $mdmap{$cur} = $ibx;
 		} else {
 			warn "watch unsupported: $k=$watch\n";
 		}
-	}
+	});
 	return unless @mdir;
 
 	my $mdre = join('|', map { quotemeta($_) } @mdir);
diff --git a/script/public-inbox-index b/script/public-inbox-index
index e487e3f..73ad9bc 100755
--- a/script/public-inbox-index
+++ b/script/public-inbox-index
@@ -73,16 +73,14 @@ if (@ARGV) {
 sub usage { print STDERR "Usage: $usage\n"; exit 1 }
 usage() unless @dirs;
 
-foreach my $k (keys %$config) {
-	$k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
-	my $name = $1;
-	my $v = $config->{$k};
+$config->each_inbox(sub {
+	my ($ibx) = @_;
+
 	for my $i (0..$#dirs) {
-		next if $dirs[$i] ne $v;
-		my $ibx = $config->lookup_name($name);
-		$dirs[$i] = $ibx if $ibx;
+		next if $dirs[$i] ne $ibx->{mainrepo};
+		$dirs[$i] = $ibx;
 	}
-}
+});
 
 foreach my $dir (@dirs) {
 	if (!ref($dir) && -f "$dir/inbox.lock") { # v2
-- 
EW


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

* [PATCH 2/2] config: relax name inbox name restrictions
  2019-01-01 10:18 [PATCH 0/2] config-related cleanups Eric Wong
  2019-01-01 10:18 ` [PATCH 1/2] use PublicInbox::Config::each_inbox where appropriate Eric Wong
@ 2019-01-01 10:18 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2019-01-01 10:18 UTC (permalink / raw)
  To: meta

Since "publicinbox" sections are analogous to git remotes, we
may use the same rules for naming git remotes to reduce
cognitive overhead.

Most notably, this allows '.' in the middle of inbox names,
(e.g. "foo.bar") as it's common for email addresses, too.
---
 lib/PublicInbox/Config.pm | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 7858656..a2b721d 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -54,7 +54,7 @@ sub lookup {
 	my $pfx;
 
 	foreach my $k (keys %$self) {
-		$k =~ /\A(publicinbox\.[\w-]+)\.address\z/ or next;
+		$k =~ m!\A(publicinbox\.[^/]+)\.address\z! or next;
 		my $v = $self->{$k};
 		if (ref($v) eq "ARRAY") {
 			foreach my $alias (@$v) {
@@ -81,7 +81,7 @@ sub each_inbox {
 	my ($self, $cb) = @_;
 	my %seen;
 	foreach my $k (keys %$self) {
-		$k =~ /\Apublicinbox\.([A-Z0-9a-z-]+)\.mainrepo\z/ or next;
+		$k =~ m!\Apublicinbox\.([^/]+)\.mainrepo\z! or next;
 		next if $seen{$1};
 		$seen{$1} = 1;
 		my $ibx = lookup_name($self, $1) or next;
@@ -96,7 +96,7 @@ sub lookup_newsgroup {
 	return $rv if $rv;
 
 	foreach my $k (keys %$self) {
-		$k =~ /\A(publicinbox\.[\w-]+)\.newsgroup\z/ or next;
+		$k =~ m!\A(publicinbox\.[^/]+)\.newsgroup\z! or next;
 		my $v = $self->{$k};
 		my $pfx = $1;
 		if ($v eq $ng) {
@@ -184,6 +184,13 @@ sub _fill {
 	return unless $rv->{mainrepo};
 	my $name = $pfx;
 	$name =~ s/\Apublicinbox\.//;
+
+	# same rules as git.git/remote.c::valid_remote_nick
+	if ($name eq '' || $name =~ m!/! || $name eq '.' || $name eq '..') {
+		warn "invalid inbox name: '$name'\n";
+		return;
+	}
+
 	$rv->{name} = $name;
 	$rv->{-pi_config} = $self;
 	$rv = PublicInbox::Inbox->new($rv);
-- 
EW


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

end of thread, other threads:[~2019-01-01 10:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01 10:18 [PATCH 0/2] config-related cleanups Eric Wong
2019-01-01 10:18 ` [PATCH 1/2] use PublicInbox::Config::each_inbox where appropriate Eric Wong
2019-01-01 10:18 ` [PATCH 2/2] config: relax name inbox name restrictions Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).