+ return unless valid_foo_name($name, 'publicinbox');
+ $ibx->{name} = $name;
+ $ibx->{-pi_cfg} = $self;
+ $ibx = PublicInbox::Inbox->new($ibx);
+ foreach (@{$ibx->{address}}) {
+ my $lc_addr = lc($_);
+ $self->{-by_addr}->{$lc_addr} = $ibx;
+ $self->{-no_obfuscate}->{$lc_addr} = 1;
+ }
+ if (my $listids = $ibx->{listid}) {
+ # RFC2919 section 6 stipulates "case insensitive equality"
+ foreach my $list_id (@$listids) {
+ $self->{-by_list_id}->{lc($list_id)} = $ibx;
+ }
+ }
+ if (defined(my $ngname = $ibx->{newsgroup})) {
+ if (ref($ngname)) {
+ delete $ibx->{newsgroup};
+ warn 'multiple newsgroups not supported: '.
+ join(', ', @$ngname). "\n";
+ # Newsgroup name needs to be compatible with RFC 3977
+ # wildmat-exact and RFC 3501 (IMAP) ATOM-CHAR.
+ # Leave out a few chars likely to cause problems or conflicts:
+ # '|', '<', '>', ';', '#', '$', '&',
+ } elsif ($ngname =~ m![^A-Za-z0-9/_\.\-\~\@\+\=:]! ||
+ $ngname eq '') {
+ delete $ibx->{newsgroup};
+ warn "newsgroup name invalid: `$ngname'\n";
+ } else {
+ # PublicInbox::NNTPD does stricter ->nntp_usable
+ # checks, keep this lean for startup speed
+ $self->{-by_newsgroup}->{$ngname} = $ibx;
+ }
+ }
+ unless (defined $ibx->{newsgroup}) { # for ->eidx_key
+ my $abs = rel2abs_collapsed($dir);
+ if ($abs ne $dir) {
+ warn "W: `$dir' canonicalized to `$abs'\n";
+ $ibx->{inboxdir} = $abs;
+ }
+ }
+ $self->{-by_name}->{$name} = $ibx;
+ if ($ibx->{obfuscate}) {
+ $ibx->{-no_obfuscate} = $self->{-no_obfuscate};
+ $ibx->{-no_obfuscate_re} = $self->{-no_obfuscate_re};
+ fill_all($self); # noop to populate -no_obfuscate
+ }
+ if (my $es = ALL($self)) {
+ require PublicInbox::Isearch;
+ $ibx->{isrch} = PublicInbox::Isearch->new($ibx, $es);
+ }
+ $self->{-by_eidx_key}->{$ibx->eidx_key} = $ibx;
+}