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;
}
} 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//!;
sub nntp_usable {
my ($self) = @_;
my $ret = $self->mm && $self->search;
- weaken_all();
+ $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;