require PublicInbox::MboxReader;
return 1 if $fmt eq 'eml';
# XXX: should this handle {gz,bz2,xz}? that's currently in LeiToMail
- PublicInbox::MboxReader->can($fmt) or
+ PublicInbox::MboxReader->reads($fmt) or
return $lei->fail("--$opt_key=$fmt unrecognized");
1;
}
+# import a single file handle of $name
+# Subclass must define ->eml_cb and ->mbox_cb
+sub input_fh {
+ my ($self, $ifmt, $fh, $name, @args) = @_;
+ if ($ifmt eq 'eml') {
+ my $buf = do { local $/; <$fh> } //
+ return $self->{lei}->child_error(1 << 8, <<"");
+error reading $name: $!
-sub prepare_inputs {
+ # mutt pipes single RFC822 messages with a "From " line,
+ # but no Content-Length or "From " escaping.
+ # "git format-patch" also generates such files by default.
+ $buf =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
+ $self->eml_cb(PublicInbox::Eml->new(\$buf), @args);
+ } else {
+ # prepare_inputs already validated $ifmt
+ my $cb = PublicInbox::MboxReader->reads($ifmt) //
+ die "BUG: bad fmt=$ifmt";
+ $cb->(undef, $fh, $self->can('mbox_cb'), $self, @args);
+ }
+}
+
+sub prepare_inputs { # returns undef on error
my ($self, $lei, $inputs) = @_;
my $in_fmt = $lei->{opt}->{'in-format'};
if ($lei->{opt}->{stdin}) {
if (-f $input_path) {
require PublicInbox::MboxLock;
require PublicInbox::MboxReader;
- PublicInbox::MboxReader->can($ifmt) or return
+ PublicInbox::MboxReader->reads($ifmt) or return
$lei->fail("$ifmt not supported");
} elsif (-d _) {
require PublicInbox::MdirReader;
$self->{inputs} = $inputs;
}
+sub input_only_atfork_child {
+ my ($self) = @_;
+ my $lei = $self->{lei};
+ $lei->lei_atfork_child;
+ PublicInbox::IPC::ipc_atfork_child($self);
+ $lei->{auth}->do_auth_atfork($self) if $lei->{auth};
+ undef;
+}
+
1;