-sub _mbox_write_cb ($$$$) {
- my ($cls, $mbox, $dst, $lei) = @_;
- my $m = "eml2$mbox";
- my $eml2mbox = $cls->can($m) or die "$cls->$m missing";
- my ($out, $pipe_lk, $seekable);
- # XXX should we support /dev/stdout.gz ?
- if ($dst eq '/dev/stdout') {
- $out = $lei->{1};
- } else { # TODO: mbox locking (but mairix doesn't...)
- my $mode = -p $dst ? '>' : '+>>';
- if (-f _ && !$lei->{opt}->{augment} and !unlink($dst)) {
- die "unlink $dst: $!" if $! != ENOENT;
- }
- open $out, $mode, $dst or die "open $dst: $!";
- # Perl does SEEK_END even with O_APPEND :<
- $seekable = seek($out, 0, SEEK_SET);
- die "seek $dst: $!\n" if !$seekable && $! != ESPIPE;
- }
- my $jobs = $lei->{opt}->{jobs} // 0;
- state $zsfx_allow = join('|', keys %zsfx2cmd);
- my ($zsfx) = ($dst =~ /\.($zsfx_allow)\z/);
- my $write = $jobs > 1 && !$zsfx ? \&atomic_append : \&_print_full;
- my $dedupe = $lei->{dedupe} = PublicInbox::LeiDedupe->new($lei);
- if ($lei->{opt}->{augment}) {
- die "cannot augment $dst, not seekable\n" if !$seekable;
- if (-s $out && $dedupe->prepare_dedupe) {
- my $rd = $zsfx ? decompress_src($out, $zsfx, $lei) :
- dup_src($out);
- PublicInbox::MboxReader->$mbox($rd, \&_augment, $lei);
- }
- # maybe some systems don't honor O_APPEND, Perl does this:
- seek($out, 0, SEEK_END) or die "seek $dst: $!";
- $dedupe->pause_dedupe if $jobs; # are we forking?
- }
- $dedupe->prepare_dedupe if !$jobs;
- ($out, $pipe_lk) = compress_dst($out, $zsfx, $lei) if $zsfx;
+sub _mbox_write_cb ($$) {
+ my ($self, $lei) = @_;
+ my $ovv = $lei->{ovv};
+ my $m = 'eml2'.$ovv->{fmt};
+ my $eml2mbox = $self->can($m) or die "$self->$m missing";
+ my $out = $lei->{1} // die "no stdout ($m, $ovv->{dst})"; # redirected earlier
+ $out->autoflush(1);
+ my $write = $ovv->{lock_path} ? \&_print_full : \&atomic_append;
+ my $dedupe = $lei->{dedupe};
+ $dedupe->prepare_dedupe;