1 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Represents a public-inbox (which may have multiple mailing addresses)
5 package PublicInbox::Inbox;
8 use Scalar::Util qw(weaken);
12 my ($class, $opts) = @_;
18 weaken($self->{$_}) foreach qw(git mm search);
23 $self->{git} ||= eval { PublicInbox::Git->new($self->{mainrepo}) };
28 $self->{mm} ||= eval { PublicInbox::Msgmap->new($self->{mainrepo}) };
33 $self->{search} ||= eval { PublicInbox::Search->new($self->{mainrepo}) };
39 if (open(my $fh, '<', $path)) {
48 my $desc = $self->{description};
49 return $desc if defined $desc;
50 $desc = try_cat("$self->{mainrepo}/description");
53 $desc = '($GIT_DIR/description missing)' if $desc eq '';
54 $self->{description} = $desc;
59 my $url = $self->{cloneurl};
61 $url = try_cat("$self->{mainrepo}/cloneurl");
62 my @url = split(/\s+/s, $url);
64 $self->{cloneurl} = \@url;
68 my ($self, $prq) = @_; # Plack::Request
70 my $url = $prq->base->as_string;
71 $url .= '/' if $url !~ m!/\z!; # for mount in Plack::Builder
72 $url .= $self->{name} . '/';
74 # either called from a non-PSGI environment (e.g. NNTP/POP3)
75 $self->{-base_url} ||= do {
76 my $url = $self->{url};
77 # expand protocol-relative URLs to HTTPS if we're
78 # not inside a web server
79 $url = "https:$url" if $url =~ m!\A//!;
80 $url .= '/' if $url !~ m!/\z!;
88 my $ret = $self->mm && $self->search;
89 $self->{mm} = $self->{search} = undef;