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);
10 use PublicInbox::MID qw(mid2path);
13 my ($class, $opts) = @_;
19 weaken($self->{$_}) foreach qw(git mm search);
24 $self->{git} ||= eval { PublicInbox::Git->new($self->{mainrepo}) };
29 $self->{mm} ||= eval { PublicInbox::Msgmap->new($self->{mainrepo}) };
34 $self->{search} ||= eval { PublicInbox::Search->new($self->{mainrepo}) };
40 if (open(my $fh, '<', $path)) {
49 my $desc = $self->{description};
50 return $desc if defined $desc;
51 $desc = try_cat("$self->{mainrepo}/description");
54 $desc = '($GIT_DIR/description missing)' if $desc eq '';
55 $self->{description} = $desc;
60 my $url = $self->{cloneurl};
62 $url = try_cat("$self->{mainrepo}/cloneurl");
63 my @url = split(/\s+/s, $url);
65 $self->{cloneurl} = \@url;
69 my ($self, $prq) = @_; # Plack::Request
71 my $url = $prq->base->as_string;
72 $url .= '/' if $url !~ m!/\z!; # for mount in Plack::Builder
73 $url .= $self->{name} . '/';
75 # either called from a non-PSGI environment (e.g. NNTP/POP3)
76 $self->{-base_url} ||= do {
77 my $url = $self->{url} or return undef;
78 # expand protocol-relative URLs to HTTPS if we're
79 # not inside a web server
80 $url = "https:$url" if $url =~ m!\A//!;
81 $url .= '/' if $url !~ m!/\z!;
89 my $ret = $self->mm && $self->search;
90 $self->{mm} = $self->{search} = undef;
94 sub msg_by_path ($$;$) {
95 my ($self, $path, $ref) = @_;
96 # TODO: allow other refs:
97 git($self)->cat_file('HEAD:'.$path, $ref);
100 sub msg_by_mid ($$;$) {
101 my ($self, $mid, $ref) = @_;
102 msg_by_path($self, mid2path($mid), $ref);