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;
67 # TODO: can we remove this?
70 my $footer = $self->{footer};
71 return $footer if defined $footer;
72 $footer = try_cat("$self->{mainrepo}/public-inbox/footer.html");
74 $self->{footer} = $footer;
78 my ($self, $prq) = @_; # Plack::Request
80 my $url = $prq->base->as_string;
81 $url .= '/' if $url !~ m!/\z!; # for mount in Plack::Builder
82 $url .= $self->{name} . '/';
84 # either called from a non-PSGI environment (e.g. NNTP/POP3)
85 $self->{-base_url} ||= do {
86 my $url = $self->{url};
87 # expand protocol-relative URLs to HTTPS if we're
88 # not inside a web server
89 $url = "https:$url" if $url =~ m!\A//!;
90 $url .= '/' if $url !~ m!/\z!;