1 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Writes PublicInbox::Eml objects atomically to a mbox variant or Maildir
5 package PublicInbox::LeiToMail;
8 use parent qw(PublicInbox::IPC);
10 use PublicInbox::ProcessPipe;
11 use PublicInbox::Spawn qw(spawn);
12 use PublicInbox::PktOp qw(pkt_do);
13 use Symbol qw(gensym);
14 use IO::Handle; # ->autoflush
15 use Fcntl qw(SEEK_SET SEEK_END O_CREAT O_EXCL O_WRONLY);
17 my %kw2char = ( # Maildir characters
20 forwarded => 'P', # passed
26 flagged => [ 'X-Status' => 'F' ],
27 answered => [ 'X-Status' => 'A' ],
28 seen => [ 'Status' => 'R' ],
29 draft => [ 'X-Status' => 'T' ],
32 sub _mbox_hdr_buf ($$$) {
33 my ($eml, $type, $smsg) = @_;
34 $eml->header_set($_) for (qw(Lines Bytes Content-Length));
36 my %hdr = (Status => []); # set Status, X-Status
37 for my $k (@{$smsg->{kw} // []}) {
38 if (my $ent = $kw2status{$k}) {
39 push @{$hdr{$ent->[0]}}, $ent->[1];
41 warn "# keyword `$k' not supported for mbox\n";
44 # Messages are always 'O' (non-\Recent in IMAP), it saves
45 # MUAs the trouble of rewriting the mbox if no other
46 # changes are made. We put 'O' at the end (e.g. "Status: RO")
47 # to match mutt(1) output.
48 $eml->header_set('Status', join('', sort(@{$hdr{Status}})). 'O');
49 if (my $chars = delete $hdr{'X-Status'}) {
50 $eml->header_set('X-Status', join('', sort(@$chars)));
52 my $buf = delete $eml->{hdr};
54 # fixup old bug from import (pre-a0c07cba0e5d8b6a)
55 $$buf =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
56 my $ident = $smsg->{blob} // 'lei';
57 if (defined(my $pct = $smsg->{pct})) { $ident .= "=$pct" }
59 substr($$buf, 0, 0, # prepend From line
60 "From $ident\@$type Thu Jan 1 00:00:00 1970$eml->{crlf}");
64 sub atomic_append { # for on-disk destinations (O_APPEND, or O_EXCL)
66 if (defined(my $w = syswrite($lei->{1} // return, $$buf))) {
67 return if $w == length($$buf);
68 $buf = "short atomic write: $w != ".length($$buf);
70 return $lei->note_sigpipe(1);
72 $buf = "atomic write: $!";
77 sub eml2mboxrd ($;$) {
78 my ($eml, $smsg) = @_;
79 my $buf = _mbox_hdr_buf($eml, 'mboxrd', $smsg);
80 if (my $bdy = delete $eml->{bdy}) {
81 $$bdy =~ s/^(>*From )/>$1/gm;
82 $$buf .= $eml->{crlf};
83 substr($$bdy, 0, 0, $$buf); # prepend header
86 $$buf .= $eml->{crlf};
91 my ($eml, $smsg) = @_;
92 my $buf = _mbox_hdr_buf($eml, 'mboxo', $smsg);
93 if (my $bdy = delete $eml->{bdy}) {
94 $$bdy =~ s/^From />From /gm;
95 $$buf .= $eml->{crlf};
96 substr($$bdy, 0, 0, $$buf); # prepend header
99 $$buf .= $eml->{crlf};
103 sub _mboxcl_common ($$$) {
104 my ($buf, $bdy, $crlf) = @_;
105 # add Lines: so mutt won't have to add it on MUA close
106 my $lines = $$bdy =~ tr!\n!\n!;
107 $$buf .= 'Content-Length: '.length($$bdy).$crlf.
108 'Lines: '.$lines.$crlf.$crlf;
109 substr($$bdy, 0, 0, $$buf); # prepend header
113 # mboxcl still escapes "From " lines
115 my ($eml, $smsg) = @_;
116 my $buf = _mbox_hdr_buf($eml, 'mboxcl', $smsg);
117 my $crlf = $eml->{crlf};
118 if (my $bdy = delete $eml->{bdy}) {
119 $$bdy =~ s/^From />From /gm;
120 _mboxcl_common($buf, $bdy, $crlf);
126 # mboxcl2 has no "From " escaping
128 my ($eml, $smsg) = @_;
129 my $buf = _mbox_hdr_buf($eml, 'mboxcl2', $smsg);
130 my $crlf = $eml->{crlf};
131 if (my $bdy = delete $eml->{bdy}) {
132 _mboxcl_common($buf, $bdy, $crlf);
138 sub git_to_mail { # git->cat_async callback
139 my ($bref, $oid, $type, $size, $arg) = @_;
140 return warn("W: $oid is $type (!= blob)\n") if $type ne 'blob';
141 return warn("E: $oid is empty\n") unless $size;
142 my ($write_cb, $smsg) = @$arg;
143 die "BUG: expected=$smsg->{blob} got=$oid" if $smsg->{blob} ne $oid;
144 $write_cb->($bref, $smsg);
147 sub reap_compress { # dwaitpid callback
148 my ($lei, $pid) = @_;
149 my $cmd = delete $lei->{"pid.$pid"};
151 $lei->fail("@$cmd failed", $? >> 8);
154 sub _post_augment_mbox { # open a compressor process from top-level process
155 my ($self, $lei) = @_;
156 my $zsfx = $self->{zsfx} or return;
157 my $cmd = PublicInbox::MboxReader::zsfx2cmd($zsfx, undef, $lei);
158 my ($r, $w) = @{delete $lei->{zpipe}};
159 my $rdr = { 0 => $r, 1 => $lei->{1}, 2 => $lei->{2} };
160 my $pid = spawn($cmd, undef, $rdr);
162 my $dup = bless { "pid.$pid" => $cmd }, ref($lei);
163 $dup->{$_} = $lei->{$_} for qw(2 sock);
164 tie *$pp, 'PublicInbox::ProcessPipe', $pid, $w, \&reap_compress, $dup;
168 # --augment existing output destination, with deduplication
169 sub _augment { # MboxReader eml_cb
170 my ($eml, $lei) = @_;
171 # ignore return value, just populate the skv
172 $lei->{dedupe}->is_dup($eml);
175 sub _mbox_augment_kw_maybe {
176 my ($eml, $lei, $lse, $augment) = @_;
177 my $kw = PublicInbox::MboxReader::mbox_keywords($eml);
178 update_kw_maybe($lei, $lse, $eml, $kw);
179 _augment($eml, $lei) if $augment;
182 sub _mbox_write_cb ($$) {
183 my ($self, $lei) = @_;
184 my $ovv = $lei->{ovv};
185 my $m = 'eml2'.$ovv->{fmt};
186 my $eml2mbox = $self->can($m) or die "$self->$m missing";
187 $lei->{1} // die "no stdout ($m, $ovv->{dst})"; # redirected earlier
188 $lei->{1}->autoflush(1);
189 my $atomic_append = !defined($ovv->{lock_path});
190 my $dedupe = $lei->{dedupe};
191 $dedupe->prepare_dedupe;
192 my $lse = $lei->{lse}; # may be undef
193 sub { # for git_to_mail
194 my ($buf, $smsg, $eml) = @_;
195 $eml //= PublicInbox::Eml->new($buf);
196 return if $dedupe->is_dup($eml, $smsg);
197 $lse->xsmsg_vmd($smsg) if $lse;
198 $buf = $eml2mbox->($eml, $smsg);
199 return atomic_append($lei, $buf) if $atomic_append;
200 my $lk = $ovv->lock_for_scope;
205 sub update_kw_maybe ($$$$) {
206 my ($lei, $lse, $eml, $kw) = @_;
208 my $c = $lse->kw_changed($eml, $kw, my $docids = []);
209 my $vmd = { kw => $kw };
210 if (scalar @$docids) { # already in lei/store
211 $lei->{sto}->ipc_do('set_eml_vmd', undef, $vmd, $docids) if $c;
212 } elsif (my $xoids = $lei->{ale}->xoids_for($eml)) {
213 # it's in an external, only set kw, here
214 $lei->{sto}->ipc_do('set_xvmd', $xoids, $eml, $vmd);
215 } else { # never-before-seen, import the whole thing
216 # XXX this is critical in protecting against accidental
217 # data loss without --augment
218 $lei->{sto}->ipc_do('set_eml', $eml, $vmd);
222 sub _md_update { # maildir_each_eml cb
223 my ($f, $kw, $eml, $lei, $lse, $unlink) = @_;
224 update_kw_maybe($lei, $lse, $eml, $kw);
225 $unlink ? unlink($f) : _augment($eml, $lei);
228 # maildir_each_file callback, \&CORE::unlink doesn't work with it
229 sub _unlink { unlink($_[0]) }
233 sprintf('%x,%x,%x,%x', rand(0xffffffff), time, $$, ++$seq);
237 my ($dst, $buf, $smsg) = @_;
238 my $kw = $smsg->{kw} // [];
239 my $sfx = join('', sort(map { $kw2char{$_} // () } @$kw));
240 my $rand = ''; # chosen by die roll :P
241 my ($tmp, $fh, $final, $ok);
242 my $common = $smsg->{blob} // _rand;
243 if (defined(my $pct = $smsg->{pct})) { $common .= "=$pct" }
245 $tmp = $dst.'tmp/'.$rand.$common;
246 } while (!($ok = sysopen($fh, $tmp, O_CREAT|O_EXCL|O_WRONLY)) &&
247 $!{EEXIST} && ($rand = _rand.','));
248 if ($ok && print $fh $$buf and close($fh)) {
249 # ignore new/ and write only to cur/, otherwise MUAs
250 # with R/W access to the Maildir will end up doing
251 # a mass rename which can take a while with thousands
256 $final = $dst.$rand.$common.':2,'.$sfx;
257 } while (!($ok = link($tmp, $final)) && $!{EEXIST} &&
258 ($rand = _rand.','));
259 die "link($tmp, $final): $!" unless $ok;
260 unlink($tmp) or warn "W: failed to unlink $tmp: $!\n";
262 my $err = "Error writing $smsg->{blob} to $dst: $!\n";
263 $_[0] = undef; # clobber dst
269 sub _maildir_write_cb ($$) {
270 my ($self, $lei) = @_;
271 my $dedupe = $lei->{dedupe};
272 $dedupe->prepare_dedupe if $dedupe;
273 my $dst = $lei->{ovv}->{dst};
274 my $lse = $lei->{lse}; # may be undef
275 sub { # for git_to_mail
276 my ($buf, $smsg, $eml) = @_;
277 $dst // return $lei->fail; # dst may be undef-ed in last run
278 $buf //= \($eml->as_string);
279 $lse->xsmsg_vmd($smsg) if $lse;
280 return _buf2maildir($dst, $buf, $smsg) if !$dedupe;
281 $eml //= PublicInbox::Eml->new($$buf); # copy buf
282 return if $dedupe->is_dup($eml, $smsg);
284 _buf2maildir($dst, $buf, $smsg);
288 sub _imap_write_cb ($$) {
289 my ($self, $lei) = @_;
290 my $dedupe = $lei->{dedupe};
291 $dedupe->prepare_dedupe if $dedupe;
292 my $imap_append = $lei->{net}->can('imap_append');
293 my $mic = $lei->{net}->mic_get($self->{uri});
294 my $folder = $self->{uri}->mailbox;
295 my $lse = $lei->{lse}; # may be undef
296 sub { # for git_to_mail
297 my ($bref, $smsg, $eml) = @_;
298 $mic // return $lei->fail; # mic may be undef-ed in last run
300 $eml //= PublicInbox::Eml->new($$bref); # copy bref
301 return if $dedupe->is_dup($eml, $smsg);
303 $lse->xsmsg_vmd($smsg) if $lse;
304 eval { $imap_append->($mic, $folder, $bref, $smsg, $eml) };
312 sub _text_write_cb ($$) {
313 my ($self, $lei) = @_;
314 my $dedupe = $lei->{dedupe};
315 $dedupe->prepare_dedupe if $dedupe;
316 my $lvt = $lei->{lvt};
317 my $ovv = $lei->{ovv};
318 $lei->{1} // die "no stdout ($ovv->{dst})"; # redirected earlier
319 $lei->{1}->autoflush(1);
320 binmode $lei->{1}, ':utf8';
321 my $lse = $lei->{lse}; # may be undef
322 sub { # for git_to_mail
323 my ($bref, $smsg, $eml) = @_;
324 $lse->xsmsg_vmd($smsg) if $lse;
325 $eml //= PublicInbox::Eml->new($bref); # copy bref
326 return if $dedupe && $dedupe->is_dup($eml, $smsg);
327 my $lk = $ovv->lock_for_scope;
328 $lei->out(${$lvt->eml_to_text($smsg, $eml)}, "\n");
332 sub write_cb { # returns a callback for git_to_mail
333 my ($self, $lei) = @_;
334 # _mbox_write_cb, _maildir_write_cb or _imap_write_cb
335 my $m = "_$self->{base_type}_write_cb";
340 my ($cls, $lei) = @_;
341 my $fmt = $lei->{ovv}->{fmt};
342 my $dst = $lei->{ovv}->{dst};
343 my $self = bless {}, $cls;
344 if ($fmt eq 'maildir') {
345 require PublicInbox::MdirReader;
346 $self->{base_type} = 'maildir';
347 -e $dst && !-d _ and die
348 "$dst exists and is not a directory\n";
349 $lei->{ovv}->{dst} = $dst .= '/' if substr($dst, -1) ne '/';
350 } elsif (substr($fmt, 0, 4) eq 'mbox') {
351 require PublicInbox::MboxReader;
352 $self->can("eml2$fmt") or die "bad mbox format: $fmt\n";
353 $self->{base_type} = 'mbox';
354 } elsif ($fmt =~ /\Aimaps?\z/) {
355 require PublicInbox::NetWriter;
356 require PublicInbox::URIimap;
357 my $net = PublicInbox::NetWriter->new;
358 $net->{quiet} = $lei->{opt}->{quiet};
359 my $uri = PublicInbox::URIimap->new($dst)->canonical;
361 my $err = $net->errors($lei);
362 return $lei->fail($err) if $err;
363 $uri->mailbox or return $lei->fail("No mailbox: $dst");
365 $dst = $lei->{ovv}->{dst} = $$uri; # canonicalized
367 $self->{base_type} = 'imap';
368 } elsif ($fmt eq 'text') {
369 require PublicInbox::LeiViewText;
370 $lei->{lvt} = PublicInbox::LeiViewText->new($lei);
371 $self->{base_type} = 'text';
373 die "bad mail --format=$fmt\n";
375 if ($self->{base_type} =~ /\A(?:text|mbox)\z/) {
376 (-d $dst || (-e _ && !-w _)) and die
377 "$dst exists and is not a writable file\n";
379 if ($self->{base_type} eq 'text') {
381 defined($lei->{opt}->{$_}) ? "--$_" : ();
383 die "@err incompatible with $fmt\n" if @err;
386 $lei->{dedupe} = $lei->{lss} // do {
387 my $dd_cls = 'PublicInbox::'.
388 ($lei->{opt}->{save} ? 'LeiSavedSearch' : 'LeiDedupe');
389 eval "require $dd_cls";
390 die "$dd_cls: $@" if $@;
396 sub _pre_augment_maildir {
397 my ($self, $lei) = @_;
398 my $dst = $lei->{ovv}->{dst};
399 for my $x (qw(tmp new cur)) {
403 File::Path::mkpath($d);
404 -d $d or die "$d is not a directory";
406 # for utime, so no opendir
407 open $self->{poke_dh}, '<', "${dst}cur" or die "open ${dst}cur: $!";
410 sub _do_augment_maildir {
411 my ($self, $lei) = @_;
412 return if ($lei->{opt}->{save} // 0) < 0;
413 my $dst = $lei->{ovv}->{dst};
414 my $lse = $lei->{opt}->{'import-before'} ? $lei->{lse} : undef;
415 my $mdr = PublicInbox::MdirReader->new;
416 if ($lei->{opt}->{augment}) {
417 my $dedupe = $lei->{dedupe};
418 if ($dedupe && $dedupe->prepare_dedupe) {
419 $mdr->{shard_info} = $self->{shard_info};
420 $mdr->maildir_each_eml($dst, \&_md_update, $lei, $lse);
421 $dedupe->pause_dedupe;
424 $mdr->{shard_info} = $self->{shard_info};
425 $mdr->maildir_each_eml($dst, \&_md_update, $lei, $lse, 1);
426 } else {# clobber existing Maildir
427 $mdr->maildir_each_file($dst, \&_unlink);
431 sub _imap_augment_or_delete { # PublicInbox::NetReader::imap_each cb
432 my ($url, $uid, $kw, $eml, $lei, $lse, $delete_mic) = @_;
433 update_kw_maybe($lei, $lse, $eml, $kw);
435 $lei->{net}->imap_delete_1($url, $uid, $delete_mic);
437 _augment($eml, $lei);
441 sub _do_augment_imap {
442 my ($self, $lei) = @_;
443 return if ($lei->{opt}->{save} // 0) < 0;
444 my $net = $lei->{net};
445 my $lse = $lei->{opt}->{'import-before'} ? $lei->{lse} : undef;
446 if ($lei->{opt}->{augment}) {
447 my $dedupe = $lei->{dedupe};
448 if ($dedupe && $dedupe->prepare_dedupe) {
449 $net->imap_each($self->{uri}, \&_imap_augment_or_delete,
451 $dedupe->pause_dedupe;
455 $net->imap_each($self->{uri}, \&_imap_augment_or_delete,
456 $lei, $lse, \$delete_mic);
457 $delete_mic->expunge if $delete_mic;
458 } elsif (!$self->{-wq_worker_nr}) { # undef or 0
459 # clobber existing IMAP folder
460 $net->imap_delete_all($self->{uri});
464 sub _pre_augment_text {
465 my ($self, $lei) = @_;
466 my $dst = $lei->{ovv}->{dst};
468 my $devfd = $lei->path_to_fd($dst) // die "bad $dst";
470 $out = $lei->{$devfd};
471 } else { # normal-looking path
473 open $out, '>', $dst or die "open($dst): $!";
474 } elsif (-f _ || !-e _) {
475 # text allows augment, HTML/Atom won't
476 my $mode = $lei->{opt}->{augment} ? '>>' : '>';
477 open $out, $mode, $dst or die "open($mode, $dst): $!";
479 die "$dst is not a file or FIFO\n";
482 $lei->{ovv}->ovv_out_lk_init if !$lei->{ovv}->{lock_path};
487 sub _pre_augment_mbox {
488 my ($self, $lei) = @_;
489 my $dst = $lei->{ovv}->{dst};
491 my $devfd = $lei->path_to_fd($dst) // die "bad $dst";
493 $out = $lei->{$devfd};
494 } else { # normal-looking path
496 open $out, '>', $dst or die "open($dst): $!";
497 } elsif (-f _ || !-e _) {
498 require PublicInbox::MboxLock;
499 my $m = $lei->{opt}->{'lock'} //
500 PublicInbox::MboxLock->defaults;
501 $self->{mbl} = PublicInbox::MboxLock->acq($dst, 1, $m);
502 $out = $self->{mbl}->{fh};
504 die "$dst is not a file or FIFO\n";
506 $lei->{old_1} = $lei->{1}; # keep for spawning MUA
508 # Perl does SEEK_END even with O_APPEND :<
509 $self->{seekable} = seek($out, 0, SEEK_SET);
510 if (!$self->{seekable} && !$!{ESPIPE} && !defined($devfd)) {
511 die "seek($dst): $!\n";
513 if (!$self->{seekable}) {
514 my $imp_before = $lei->{opt}->{'import-before'};
515 die "--import-before specified but $dst is not seekable\n"
516 if $imp_before && !ref($imp_before);
517 die "--augment specified but $dst is not seekable\n" if
518 $lei->{opt}->{augment};
520 if ($self->{zsfx} = PublicInbox::MboxReader::zsfx($dst)) {
521 pipe(my ($r, $w)) or die "pipe: $!";
522 $lei->{zpipe} = [ $r, $w ];
523 $lei->{ovv}->{lock_path} and
524 die 'BUG: unexpected {ovv}->{lock_path}';
525 $lei->{ovv}->ovv_out_lk_init;
526 } elsif (!$self->{seekable} && !$lei->{ovv}->{lock_path}) {
527 $lei->{ovv}->ovv_out_lk_init;
533 sub _do_augment_mbox {
534 my ($self, $lei) = @_;
535 return unless $self->{seekable};
536 my $opt = $lei->{opt};
537 return if ($opt->{save} // 0) < 0;
539 my ($fmt, $dst) = @{$lei->{ovv}}{qw(fmt dst)};
540 return unless -s $out;
541 unless ($opt->{augment} || $opt->{'import-before'}) {
542 truncate($out, 0) or die "truncate($dst): $!";
546 if (my $zsfx = $self->{zsfx}) {
547 $rd = PublicInbox::MboxReader::zsfxcat($out, $zsfx, $lei);
549 open($rd, '+>>&', $out) or die "dup: $!";
552 if ($opt->{augment}) {
553 $dedupe = $lei->{dedupe};
554 $dedupe->prepare_dedupe if $dedupe;
556 if ($opt->{'import-before'}) { # the default
557 my $lse = $lei->{lse};
558 PublicInbox::MboxReader->$fmt($rd, \&_mbox_augment_kw_maybe,
559 $lei, $lse, $opt->{augment});
560 if (!$opt->{augment} and !truncate($out, 0)) {
561 die "truncate($dst): $!";
563 } else { # --augment --no-import-before
564 PublicInbox::MboxReader->$fmt($rd, \&_augment, $lei);
566 # maybe some systems don't honor O_APPEND, Perl does this:
567 seek($out, 0, SEEK_END) or die "seek $dst: $!";
568 $dedupe->pause_dedupe if $dedupe;
571 sub pre_augment { # fast (1 disk seek), runs in same process as post_augment
572 my ($self, $lei) = @_;
573 # _pre_augment_maildir, _pre_augment_mbox
574 my $m = $self->can("_pre_augment_$self->{base_type}") or return;
578 sub do_augment { # slow, runs in wq worker
579 my ($self, $lei) = @_;
580 # _do_augment_maildir, _do_augment_mbox, or _do_augment_imap
581 my $m = $self->can("_do_augment_$self->{base_type}") or return;
585 # fast (spawn compressor or mkdir), runs in same process as pre_augment
587 my ($self, $lei, @args) = @_;
588 my $wait = $lei->{opt}->{'import-before'} ?
589 $lei->{sto}->ipc_do('checkpoint', 1) : 0;
591 my $m = $self->can("_post_augment_$self->{base_type}") or return;
592 $m->($self, $lei, @args);
595 # called by every single l2m worker process
598 my $lei = $self->{lei};
599 # lei_xsearch can start as soon as all l2m workers get here
600 pkt_do($lei->{pkt_op_p}, 'incr_start_query') or
601 die "incr_start_query: $!";
603 if (lock_free($self)) { # all workers do_augment
604 my $mod = $self->{-wq_nr_workers};
605 my $shard = $self->{-wq_worker_nr};
606 if (my $net = $lei->{net}) {
607 $net->{shard_info} = [ $mod, $shard ];
609 $self->{shard_info} = [ $mod, $shard ];
611 $aug = '+'; # incr_post_augment
612 } elsif ($self->{-wq_worker_nr} == 0) { # 1st worker do_augment
613 $aug = '.'; # do_post_augment
616 local $0 = 'do_augment';
617 eval { do_augment($self, $lei) };
618 $lei->fail($@) if $@;
619 pkt_do($lei->{pkt_op_p}, $aug) == 1 or
620 die "do_post_augment trigger: $!";
622 # done augmenting, connect the compressor pipe for each worker
623 if (my $zpipe = delete $lei->{zpipe}) {
624 $lei->{1} = $zpipe->[1];
627 $self->{wcb} = $self->write_cb($lei);
630 sub ipc_atfork_child {
632 my $lei = $self->{lei};
633 $lei->_lei_atfork_child;
634 $lei->{auth}->do_auth_atfork($self) if $lei->{auth};
635 $SIG{__WARN__} = PublicInbox::Eml::warn_ignore_cb();
636 $self->SUPER::ipc_atfork_child;
640 $_[0]->{base_type} =~ /\A(?:maildir|imap|jmap)\z/ ? 1 : 0;
643 # wakes up the MUA when complete so it can refresh messages list
646 if ($self->{base_type} eq 'maildir') {
648 utime($t, $t, $self->{poke_dh}) or warn "futimes: $!";
652 sub write_mail { # via ->wq_io_do
653 my ($self, $smsg, $eml) = @_;
654 return $self->{wcb}->(undef, $smsg, $eml) if $eml;
655 $self->{lei}->{ale}->git->cat_async($smsg->{blob}, \&git_to_mail,
656 [$self->{wcb}, $smsg]);
659 sub wq_atexit_child {
662 $self->{lei}->{ale}->git->async_wait_all;
665 # called in top-level lei-daemon when LeiAuth is done
666 sub net_merge_complete {
668 $self->wq_broadcast('do_post_auth');
672 no warnings 'once'; # the following works even when LeiAuth is lazy-loaded
673 *net_merge_all = \&PublicInbox::LeiAuth::net_merge_all;