]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Inbox.pm
inbox: move field population logic to initializer
[public-inbox.git] / lib / PublicInbox / Inbox.pm
index 4bcab96f61469df0ff22a806f64741e12d1d281d..3f1b7334f01109343a1b1723c165f6d5bbe5b299 100644 (file)
@@ -7,9 +7,13 @@ use strict;
 use warnings;
 use Scalar::Util qw(weaken);
 use PublicInbox::Git;
+use PublicInbox::MID qw(mid2path);
 
 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';
        bless $opts, $class;
 }
 
@@ -64,16 +68,6 @@ sub cloneurl {
        $self->{cloneurl} = \@url;
 }
 
-# TODO: can we remove this?
-sub footer_html {
-       my ($self) = @_;
-       my $footer = $self->{footer};
-       return $footer if defined $footer;
-       $footer = try_cat("$self->{mainrepo}/public-inbox/footer.html");
-       chomp $footer;
-       $self->{footer} = $footer;
-}
-
 sub base_url {
        my ($self, $prq) = @_; # Plack::Request
        if (defined $prq) {
@@ -83,7 +77,7 @@ sub base_url {
        } else {
                # either called from a non-PSGI environment (e.g. NNTP/POP3)
                $self->{-base_url} ||= do {
-                       my $url = $self->{url};
+                       my $url = $self->{url} or return undef;
                        # expand protocol-relative URLs to HTTPS if we're
                        # not inside a web server
                        $url = "https:$url" if $url =~ m!\A//!;
@@ -93,4 +87,22 @@ sub base_url {
        }
 }
 
+sub nntp_usable {
+       my ($self) = @_;
+       my $ret = $self->mm && $self->search;
+       $self->{mm} = $self->{search} = undef;
+       $ret;
+}
+
+sub msg_by_path ($$;$) {
+       my ($self, $path, $ref) = @_;
+       # TODO: allow other refs:
+       git($self)->cat_file('HEAD:'.$path, $ref);
+}
+
+sub msg_by_mid ($$;$) {
+       my ($self, $mid, $ref) = @_;
+       msg_by_path($self, mid2path($mid), $ref);
+}
+
 1;