+sub msg_by_path ($$;$) {
+ my ($self, $path, $ref) = @_;
+ # TODO: allow other refs:
+ my $str = git($self)->cat_file('HEAD:'.$path, $ref);
+ $$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s if $str;
+ $str;
+}
+
+sub msg_by_smsg ($$;$) {
+ my ($self, $smsg, $ref) = @_;
+
+ # ghosts may have undef smsg (from SearchThread.node) or
+ # no {blob} field (from each_smsg_by_mid)
+ return unless defined $smsg;
+ defined(my $blob = $smsg->{blob}) or return;
+
+ my $str = git($self)->cat_file($blob, $ref);
+ $$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s if $str;
+ $str;
+}
+
+sub smsg_mime {
+ my ($self, $smsg, $ref) = @_;
+ if (my $s = msg_by_smsg($self, $smsg, $ref)) {
+ $smsg->{mime} = PublicInbox::MIME->new($s);
+ return $smsg;
+ }
+}
+
+sub path_check {
+ my ($self, $path) = @_;
+ git($self)->check('HEAD:'.$path);
+}
+
+sub mid2num($$) {
+ my ($self, $mid) = @_;
+ my $mm = mm($self) or return;
+ $mm->num_for($mid);
+}
+
+sub smsg_by_mid ($$) {
+ my ($self, $mid) = @_;
+ my $srch = search($self) or return;
+ # favor the Message-ID we used for the NNTP article number:
+ my $num = mid2num($self, $mid);
+ defined $num ? $srch->lookup_article($num) : undef;
+}
+
+sub msg_by_mid ($$;$) {
+ my ($self, $mid, $ref) = @_;
+ my $srch = search($self) or
+ return msg_by_path($self, mid2path($mid), $ref);
+ my $smsg = smsg_by_mid($self, $mid);
+ $smsg ? msg_by_smsg($self, $smsg, $ref) : undef;
+}
+
+sub recent {
+ my ($self, $opts) = @_;
+ search($self)->query('', $opts);
+}
+