1 # Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 package PublicInbox::Config;
6 use File::Path::Expand qw/expand_filename/;
9 # returns key-value pairs of config directives in a hash
10 # if keys may be multi-value, the value is an array ref containing all values
12 my ($class, $file) = @_;
15 $file = default_file() unless defined($file);
16 IPC::Run::run([qw/git config --file/, $file, '-l'], \$in, \$out);
17 $? == 0 or die "git config --file $file -l failed: $?\n";
19 foreach my $line (split(/\n/, $out)) {
20 my ($k, $v) = split(/=/, $line, 2);
24 if (ref($cur) eq "ARRAY") {
27 $rv{$k} = [ $cur, $v ];
37 my ($self, $recipient) = @_;
38 my $addr = lc($recipient);
41 foreach my $k (keys %$self) {
42 $k =~ /\A(publicinbox\.[A-Z0-9a-z-]+)\.address\z/ or next;
44 if (ref($v) eq "ARRAY") {
45 foreach my $alias (@$v) {
46 (lc($alias) eq $addr) or next;
51 (lc($v) eq $addr) or next;
57 defined $pfx or return;
60 foreach my $k (qw(mainrepo address)) {
61 my $v = $self->{"$pfx.$k"};
62 $rv{$k} = $v if defined $v;
65 $listname =~ s/\Apublicinbox\.//;
66 $rv{listname} = $listname;
68 $rv{-primary_address} = ref($v) eq 'ARRAY' ? $v->[0] : $v;
73 my ($self, $listname, $key) = @_;
75 $self->{"publicinbox.$listname.$key"};
79 my $f = $ENV{PI_CONFIG};
80 return $f if defined $f;
81 my $pi_dir = $ENV{PI_DIR} || expand_filename('~/.public-inbox/');