+sub new {
+ my ($class, $opts) = @_;
+ my $v = $opts->{address} ||= [ 'public-inbox@example.com' ];
+ my $p = $opts->{-primary_address} = ref($v) eq 'ARRAY' ? $v->[0] : $v;
+ $opts->{domain} = ($p =~ /\@(\S+)\z/) ? $1 : 'localhost';
+ my $pi_cfg = delete $opts->{-pi_cfg};
+ _set_limiter($opts, $pi_cfg, 'httpbackend');
+ _set_uint($opts, 'feedmax', 25);
+ $opts->{nntpserver} ||= $pi_cfg->{'publicinbox.nntpserver'};
+ my $dir = $opts->{inboxdir};
+ if (defined $dir && -f "$dir/inbox.lock") {
+ $opts->{version} = 2;
+ }
+
+ # allow any combination of multi-line or comma-delimited hide entries
+ my $hide = {};
+ if (defined(my $h = $opts->{hide})) {
+ foreach my $v (@$h) {
+ $hide->{$_} = 1 foreach (split(/\s*,\s*/, $v));
+ }
+ $opts->{-hide} = $hide;
+ }
+ bless $opts, $class;
+}
+
+sub version { $_[0]->{version} // 1 }
+
+sub git_epoch {
+ my ($self, $epoch) = @_; # v2-only, callers always supply $epoch
+ $self->{"$epoch.git"} ||= do {
+ my $git_dir = "$self->{inboxdir}/git/$epoch.git";
+ return unless -d $git_dir;
+ my $g = PublicInbox::Git->new($git_dir);
+ $g->{-httpbackend_limiter} = $self->{-httpbackend_limiter};
+ # no cleanup needed, we never cat-file off this, only clone
+ $g;
+ };
+}
+