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::Lock;
11 use PublicInbox::ProcessPipe;
12 use PublicInbox::Spawn qw(which spawn popen_rd);
13 use PublicInbox::LeiDedupe;
15 use PublicInbox::GitAsyncCat;
16 use PublicInbox::PktOp qw(pkt_do);
17 use Symbol qw(gensym);
18 use IO::Handle; # ->autoflush
19 use Fcntl qw(SEEK_SET SEEK_END O_CREAT O_EXCL O_WRONLY);
20 use Errno qw(EEXIST ESPIPE ENOENT EPIPE);
21 use Digest::SHA qw(sha256_hex);
23 # struggles with short-lived repos, Gcf2Client makes little sense with lei;
24 # but we may use in-process libgit2 in the future.
25 $PublicInbox::GitAsyncCat::GCF2C = 0;
27 my %kw2char = ( # Maildir characters
35 flagged => [ 'X-Status' => 'F' ],
36 answered => [ 'X-Status' => 'A' ],
37 seen => [ 'Status' => 'R' ],
38 draft => [ 'X-Status' => 'T' ],
41 sub _mbox_hdr_buf ($$$) {
42 my ($eml, $type, $smsg) = @_;
43 $eml->header_set($_) for (qw(Lines Bytes Content-Length));
45 # Messages are always 'O' (non-\Recent in IMAP), it saves
46 # MUAs the trouble of rewriting the mbox if no other
48 my %hdr = (Status => [ 'O' ]); # set Status, X-Status
49 for my $k (@{$smsg->{kw} // []}) {
50 if (my $ent = $kw2status{$k}) {
51 push @{$hdr{$ent->[0]}}, $ent->[1];
53 warn "TODO: keyword `$k' not supported for mbox\n";
56 while (my ($name, $chars) = each %hdr) {
57 $eml->header_set($name, join('', sort @$chars));
59 my $buf = delete $eml->{hdr};
61 # fixup old bug from import (pre-a0c07cba0e5d8b6a)
62 $$buf =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
63 my $ident = $smsg->{blob} // 'lei';
64 if (defined(my $pct = $smsg->{pct})) { $ident .= "=$pct" }
66 substr($$buf, 0, 0, # prepend From line
67 "From $ident\@$type Thu Jan 1 00:00:00 1970$eml->{crlf}");
71 sub atomic_append { # for on-disk destinations (O_APPEND, or O_EXCL)
73 if (defined(my $w = syswrite($lei->{1} // return, $$buf))) {
74 return if $w == length($$buf);
75 $buf = "short atomic write: $w != ".length($$buf);
76 } elsif ($! == EPIPE) {
77 return $lei->note_sigpipe(1);
79 $buf = "atomic write: $!";
84 sub eml2mboxrd ($;$) {
85 my ($eml, $smsg) = @_;
86 my $buf = _mbox_hdr_buf($eml, 'mboxrd', $smsg);
87 if (my $bdy = delete $eml->{bdy}) {
88 $$bdy =~ s/^(>*From )/>$1/gm;
89 $$buf .= $eml->{crlf};
90 substr($$bdy, 0, 0, $$buf); # prepend header
93 $$buf .= $eml->{crlf};
98 my ($eml, $smsg) = @_;
99 my $buf = _mbox_hdr_buf($eml, 'mboxo', $smsg);
100 if (my $bdy = delete $eml->{bdy}) {
101 $$bdy =~ s/^From />From /gm;
102 $$buf .= $eml->{crlf};
103 substr($$bdy, 0, 0, $$buf); # prepend header
106 $$buf .= $eml->{crlf};
110 sub _mboxcl_common ($$$) {
111 my ($buf, $bdy, $crlf) = @_;
112 # add Lines: so mutt won't have to add it on MUA close
113 my $lines = $$bdy =~ tr!\n!\n!;
114 $$buf .= 'Content-Length: '.length($$bdy).$crlf.
115 'Lines: '.$lines.$crlf.$crlf;
116 substr($$bdy, 0, 0, $$buf); # prepend header
120 # mboxcl still escapes "From " lines
122 my ($eml, $smsg) = @_;
123 my $buf = _mbox_hdr_buf($eml, 'mboxcl', $smsg);
124 my $crlf = $eml->{crlf};
125 if (my $bdy = delete $eml->{bdy}) {
126 $$bdy =~ s/^From />From /gm;
127 _mboxcl_common($buf, $bdy, $crlf);
133 # mboxcl2 has no "From " escaping
135 my ($eml, $smsg) = @_;
136 my $buf = _mbox_hdr_buf($eml, 'mboxcl2', $smsg);
137 my $crlf = $eml->{crlf};
138 if (my $bdy = delete $eml->{bdy}) {
139 _mboxcl_common($buf, $bdy, $crlf);
145 sub git_to_mail { # git->cat_async callback
146 my ($bref, $oid, $type, $size, $arg) = @_;
147 if ($type ne 'blob') {
148 if ($type eq 'missing') {
149 warn "missing $oid\n";
151 warn "unexpected type=$type for $oid\n";
154 my ($write_cb, $smsg) = @$arg;
155 if ($smsg->{blob} ne $oid) {
156 die "BUG: expected=$smsg->{blob} got=$oid";
158 $write_cb->($bref, $smsg) if $size > 0;
161 sub reap_compress { # dwaitpid callback
162 my ($lei, $pid) = @_;
163 my $cmd = delete $lei->{"pid.$pid"};
165 $lei->fail("@$cmd failed", $? >> 8);
168 # all of these support -c for stdout and -d for decompression,
169 # mutt is commonly distributed with hooks for gz, bz2 and xz, at least
170 # { foo => '' } means "--foo" is passed to the command-line,
171 # otherwise { foo => '--bar' } passes "--bar"
173 gz => [ qw(GZIP pigz gzip), { rsyncable => '' } ],
174 bz2 => [ 'bzip2', {} ],
176 # XXX does anybody care for these? I prefer zstd on entire FSes,
177 # so it's probably not necessary on a per-file basis
178 # zst => [ 'zstd', { -default => [ qw(-q) ], # it's noisy by default
179 # rsyncable => '', threads => '-T' } ],
180 # zz => [ 'pigz', { -default => [ '--zlib' ],
181 # rsyncable => '', threads => '-p' }],
182 # lzo => [ 'lzop', {} ],
183 # lzma => [ 'lzma', {} ],
187 my ($zsfx, $decompress, $lei) = @_;
188 my $x = $zsfx2cmd{$zsfx} // die "no support for suffix=.$zsfx";
190 my $cmd_opt = pop @info;
191 my @cmd = (undef, $decompress ? qw(-dc) : qw(-c));
192 for my $exe (@info) {
193 # I think respecting client's ENV{GZIP} is OK, not sure
194 # about ENV overrides for other, less-common compressors
195 if ($exe eq uc($exe)) {
196 $exe = $lei->{env}->{$exe} or next;
198 $cmd[0] = which($exe) and last;
200 $cmd[0] // die join(' or ', @info)." missing for .$zsfx";
201 # push @cmd, @{$cmd_opt->{-default}} if $cmd_opt->{-default};
202 for my $bool (qw(rsyncable)) {
203 my $switch = $cmd_opt->{rsyncable} // next;
204 push @cmd, '--'.($switch || $bool);
206 for my $key (qw(rsyncable)) { # support compression level?
207 my $switch = $cmd_opt->{$key} // next;
208 my $val = $lei->{opt}->{$key} // next;
209 push @cmd, $switch, $val;
214 sub _post_augment_mbox { # open a compressor process
215 my ($self, $lei) = @_;
216 my $zsfx = $self->{zsfx} or return;
217 my $cmd = zsfx2cmd($zsfx, undef, $lei);
218 my ($r, $w) = @{delete $lei->{zpipe}};
219 my $rdr = { 0 => $r, 1 => $lei->{1}, 2 => $lei->{2} };
220 my $pid = spawn($cmd, undef, $rdr);
222 my $dup = bless { "pid.$pid" => $cmd }, ref($lei);
223 $dup->{$_} = $lei->{$_} for qw(2 sock);
224 tie *$pp, 'PublicInbox::ProcessPipe', $pid, $w, \&reap_compress, $dup;
228 sub decompress_src ($$$) {
229 my ($in, $zsfx, $lei) = @_;
230 my $cmd = zsfx2cmd($zsfx, 1, $lei);
231 popen_rd($cmd, undef, { 0 => $in, 2 => $lei->{2} });
236 open my $dup, '+>>&', $in or die "dup: $!";
240 # --augment existing output destination, with deduplication
241 sub _augment { # MboxReader eml_cb
242 my ($eml, $lei) = @_;
243 # ignore return value, just populate the skv
244 $lei->{dedupe}->is_dup($eml);
247 sub _mbox_augment_kw_maybe {
248 my ($eml, $lei, $lse, $augment) = @_;
249 my $kw = PublicInbox::MboxReader::mbox_keywords($eml);
250 update_kw_maybe($lei, $lse, $eml, $kw);
251 _augment($eml, $lei) if $augment;
254 sub _mbox_write_cb ($$) {
255 my ($self, $lei) = @_;
256 my $ovv = $lei->{ovv};
257 my $m = 'eml2'.$ovv->{fmt};
258 my $eml2mbox = $self->can($m) or die "$self->$m missing";
259 $lei->{1} // die "no stdout ($m, $ovv->{dst})"; # redirected earlier
260 $lei->{1}->autoflush(1);
261 my $atomic_append = !defined($ovv->{lock_path});
262 my $dedupe = $lei->{dedupe};
263 $dedupe->prepare_dedupe;
264 my $lse = $lei->{sto} ? $lei->{sto}->search : undef;
265 sub { # for git_to_mail
266 my ($buf, $smsg, $eml) = @_;
267 $eml //= PublicInbox::Eml->new($buf);
268 return if $dedupe->is_dup($eml, $smsg->{blob});
269 $lse->xsmsg_vmd($smsg) if $lse;
270 $buf = $eml2mbox->($eml, $smsg);
271 return atomic_append($lei, $buf) if $atomic_append;
272 my $lk = $ovv->lock_for_scope;
277 sub update_kw_maybe ($$$$) {
278 my ($lei, $lse, $eml, $kw) = @_;
280 my $x = $lse->kw_changed($eml, $kw);
281 my $vmd = { kw => $kw };
283 $lei->{sto}->ipc_do('set_eml', $eml, $vmd);
284 } elsif (!defined($x)) {
285 if (my $xoids = $lei->{ale}->xoids_for($eml)) {
286 $lei->{sto}->ipc_do('set_xvmd', $xoids, $eml, $vmd);
288 $lei->{sto}->ipc_do('set_eml', $eml, $vmd);
293 sub _augment_or_unlink { # maildir_each_eml cb
294 my ($f, $kw, $eml, $lei, $lse, $mod, $shard, $unlink) = @_;
296 # can't get dirent.d_ino w/ pure Perl, so we extract the OID
297 # if it looks like one:
298 my $hex = $f =~ m!\b([a-f0-9]{40,})[^/]*\z! ?
300 my $recno = hex(substr($hex, 0, 8));
301 return if ($recno % $mod) != $shard;
302 update_kw_maybe($lei, $lse, $eml, $kw);
304 $unlink ? unlink($f) : _augment($eml, $lei);
307 # maildir_each_file callback, \&CORE::unlink doesn't work with it
308 sub _unlink { unlink($_[0]) }
312 sprintf('%x,%x,%x,%x', rand(0xffffffff), time, $$, ++$seq);
316 my ($dst, $buf, $smsg) = @_;
317 my $kw = $smsg->{kw} // [];
318 my $sfx = join('', sort(map { $kw2char{$_} // () } @$kw));
319 my $rand = ''; # chosen by die roll :P
320 my ($tmp, $fh, $final, $ok);
321 my $common = $smsg->{blob} // _rand;
322 if (defined(my $pct = $smsg->{pct})) { $common .= "=$pct" }
324 $tmp = $dst.'tmp/'.$rand.$common;
325 } while (!($ok = sysopen($fh, $tmp, O_CREAT|O_EXCL|O_WRONLY)) &&
326 $! == EEXIST && ($rand = _rand.','));
327 if ($ok && print $fh $$buf and close($fh)) {
328 # ignore new/ and write only to cur/, otherwise MUAs
329 # with R/W access to the Maildir will end up doing
330 # a mass rename which can take a while with thousands
335 $final = $dst.$rand.$common.':2,'.$sfx;
336 } while (!($ok = link($tmp, $final)) && $! == EEXIST &&
337 ($rand = _rand.','));
338 die "link($tmp, $final): $!" unless $ok;
339 unlink($tmp) or warn "W: failed to unlink $tmp: $!\n";
341 my $err = "Error writing $smsg->{blob} to $dst: $!\n";
342 $_[0] = undef; # clobber dst
348 sub _maildir_write_cb ($$) {
349 my ($self, $lei) = @_;
350 my $dedupe = $lei->{dedupe};
351 $dedupe->prepare_dedupe if $dedupe;
352 my $dst = $lei->{ovv}->{dst};
353 my $lse = $lei->{sto} ? $lei->{sto}->search : undef;
354 sub { # for git_to_mail
355 my ($buf, $smsg, $eml) = @_;
356 $dst // return $lei->fail; # dst may be undef-ed in last run
357 $buf //= \($eml->as_string);
358 $lse->xsmsg_vmd($smsg) if $lse;
359 return _buf2maildir($dst, $buf, $smsg) if !$dedupe;
360 $eml //= PublicInbox::Eml->new($$buf); # copy buf
361 return if $dedupe->is_dup($eml, $smsg->{blob});
363 _buf2maildir($dst, $buf, $smsg);
367 sub _imap_write_cb ($$) {
368 my ($self, $lei) = @_;
369 my $dedupe = $lei->{dedupe};
370 $dedupe->prepare_dedupe if $dedupe;
371 my $imap_append = $lei->{net}->can('imap_append');
372 my $mic = $lei->{net}->mic_get($self->{uri});
373 my $folder = $self->{uri}->mailbox;
374 my $lse = $lei->{sto} ? $lei->{sto}->search : undef;
375 sub { # for git_to_mail
376 my ($bref, $smsg, $eml) = @_;
377 $mic // return $lei->fail; # dst may be undef-ed in last run
379 $eml //= PublicInbox::Eml->new($$bref); # copy bref
380 return if $dedupe->is_dup($eml, $smsg->{blob});
382 $lse->xsmsg_vmd($smsg) if $lse;
383 eval { $imap_append->($mic, $folder, $bref, $smsg, $eml) };
391 sub write_cb { # returns a callback for git_to_mail
392 my ($self, $lei) = @_;
393 # _mbox_write_cb, _maildir_write_cb or _imap_write_cb
394 my $m = "_$self->{base_type}_write_cb";
399 my ($cls, $lei) = @_;
400 my $fmt = $lei->{ovv}->{fmt};
401 my $dst = $lei->{ovv}->{dst};
402 my $self = bless {}, $cls;
403 if ($fmt eq 'maildir') {
404 require PublicInbox::MdirReader;
405 $self->{base_type} = 'maildir';
406 -e $dst && !-d _ and die
407 "$dst exists and is not a directory\n";
408 $lei->{ovv}->{dst} = $dst .= '/' if substr($dst, -1) ne '/';
409 } elsif (substr($fmt, 0, 4) eq 'mbox') {
410 require PublicInbox::MboxReader;
411 (-d $dst || (-e _ && !-w _)) and die
412 "$dst exists and is not a writable file\n";
413 $self->can("eml2$fmt") or die "bad mbox format: $fmt\n";
414 $self->{base_type} = 'mbox';
415 } elsif ($fmt =~ /\Aimaps?\z/) { # TODO .onion support
416 require PublicInbox::NetWriter;
417 my $net = PublicInbox::NetWriter->new;
419 $net->{quiet} = $lei->{opt}->{quiet};
420 my $err = $net->errors($dst);
421 return $lei->fail($err) if $err;
422 require PublicInbox::URIimap; # TODO: URI cast early
423 $self->{uri} = PublicInbox::URIimap->new($dst);
424 $self->{uri}->mailbox or die "No mailbox: $dst";
426 $self->{base_type} = 'imap';
428 die "bad mail --format=$fmt\n";
431 $lei->{dedupe} = PublicInbox::LeiDedupe->new($lei);
435 sub _pre_augment_maildir {
436 my ($self, $lei) = @_;
437 my $dst = $lei->{ovv}->{dst};
438 for my $x (qw(tmp new cur)) {
442 File::Path::mkpath($d);
443 -d $d or die "$d is not a directory";
447 sub _do_augment_maildir {
448 my ($self, $lei) = @_;
449 my $dst = $lei->{ovv}->{dst};
450 my $lse = $lei->{sto}->search if $lei->{opt}->{'import-before'};
451 my ($mod, $shard) = @{$self->{shard_info} // []};
452 if ($lei->{opt}->{augment}) {
453 my $dedupe = $lei->{dedupe};
454 if ($dedupe && $dedupe->prepare_dedupe) {
455 PublicInbox::MdirReader::maildir_each_eml($dst,
456 \&_augment_or_unlink,
457 $lei, $lse, $mod, $shard);
458 $dedupe->pause_dedupe;
461 PublicInbox::MdirReader::maildir_each_eml($dst,
462 \&_augment_or_unlink,
463 $lei, $lse, $mod, $shard, 1);
464 } else {# clobber existing Maildir
465 PublicInbox::MdirReader::maildir_each_file($dst, \&_unlink);
469 sub _imap_augment_or_delete { # PublicInbox::NetReader::imap_each cb
470 my ($url, $uid, $kw, $eml, $lei, $lse, $delete_mic) = @_;
471 update_kw_maybe($lei, $lse, $eml, $kw);
473 $lei->{net}->imap_delete_1($url, $uid, $delete_mic);
475 _augment($eml, $lei);
479 sub _do_augment_imap {
480 my ($self, $lei) = @_;
481 my $net = $lei->{net};
482 my $lse = $lei->{sto}->search if $lei->{opt}->{'import-before'};
483 if ($lei->{opt}->{augment}) {
484 my $dedupe = $lei->{dedupe};
485 if ($dedupe && $dedupe->prepare_dedupe) {
486 $net->imap_each($self->{uri}, \&_imap_augment_or_delete,
488 $dedupe->pause_dedupe;
492 $net->imap_each($self->{uri}, \&_imap_augment_or_delete,
493 $lei, $lse, \$delete_mic);
494 $delete_mic->expunge if $delete_mic;
495 } elsif (!$self->{-wq_worker_nr}) { # undef or 0
496 # clobber existing IMAP folder
497 $net->imap_delete_all($self->{uri});
501 sub _pre_augment_mbox {
502 my ($self, $lei) = @_;
503 my $dst = $lei->{ovv}->{dst};
505 if ($dst ne '/dev/stdout') {
508 open $out, '>', $dst or die "open($dst): $!";
509 } elsif (-f _ || !-e _) {
510 require PublicInbox::MboxLock;
511 my $m = $lei->{opt}->{'lock'} //
512 PublicInbox::MboxLock->defaults;
513 $self->{mbl} = PublicInbox::MboxLock->acq($dst, 1, $m);
514 $out = $self->{mbl}->{fh};
516 $lei->{old_1} = $lei->{1}; # keep for spawning MUA
518 # Perl does SEEK_END even with O_APPEND :<
519 $self->{seekable} = seek($out, 0, SEEK_SET);
520 if (!$self->{seekable} && $! != ESPIPE && $dst ne '/dev/stdout') {
521 die "seek($dst): $!\n";
523 if (!$self->{seekable}) {
524 my $ia = $lei->{opt}->{'import-before'};
525 die "--import-before specified but $dst is not seekable\n"
527 die "--augment specified but $dst is not seekable\n" if
528 $lei->{opt}->{augment};
530 state $zsfx_allow = join('|', keys %zsfx2cmd);
531 if (($self->{zsfx}) = ($dst =~ /\.($zsfx_allow)\z/)) {
532 pipe(my ($r, $w)) or die "pipe: $!";
533 $lei->{zpipe} = [ $r, $w ];
534 $lei->{ovv}->{lock_path} and
535 die 'BUG: unexpected {ovv}->{lock_path}';
536 $lei->{ovv}->ovv_out_lk_init;
537 } elsif (!$self->{seekable} && !$lei->{ovv}->{lock_path}) {
538 $lei->{ovv}->ovv_out_lk_init;
544 sub _do_augment_mbox {
545 my ($self, $lei) = @_;
546 return unless $self->{seekable};
547 my $opt = $lei->{opt};
549 my ($fmt, $dst) = @{$lei->{ovv}}{qw(fmt dst)};
550 return unless -s $out;
551 unless ($opt->{augment} || $opt->{'import-before'}) {
552 truncate($out, 0) or die "truncate($dst): $!";
555 my $zsfx = $self->{zsfx};
556 my $rd = $zsfx ? decompress_src($out, $zsfx, $lei) : dup_src($out);
558 if ($opt->{augment}) {
559 $dedupe = $lei->{dedupe};
560 $dedupe->prepare_dedupe if $dedupe;
562 if ($opt->{'import-before'}) { # the default
563 my $lse = $lei->{sto}->search;
564 PublicInbox::MboxReader->$fmt($rd, \&_mbox_augment_kw_maybe,
565 $lei, $lse, $opt->{augment});
566 if (!$opt->{augment} and !truncate($out, 0)) {
567 die "truncate($dst): $!";
569 } else { # --augment --no-import-before
570 PublicInbox::MboxReader->$fmt($rd, \&_augment, $lei);
572 # maybe some systems don't honor O_APPEND, Perl does this:
573 seek($out, 0, SEEK_END) or die "seek $dst: $!";
574 $dedupe->pause_dedupe if $dedupe;
577 sub pre_augment { # fast (1 disk seek), runs in same process as post_augment
578 my ($self, $lei) = @_;
579 # _pre_augment_maildir, _pre_augment_mbox
580 my $m = $self->can("_pre_augment_$self->{base_type}") or return;
584 sub do_augment { # slow, runs in wq worker
585 my ($self, $lei) = @_;
586 # _do_augment_maildir, _do_augment_mbox, or _do_augment_imap
587 my $m = "_do_augment_$self->{base_type}";
591 # fast (spawn compressor or mkdir), runs in same process as pre_augment
593 my ($self, $lei, @args) = @_;
594 my $wait = $lei->{opt}->{'import-before'} ?
595 $lei->{sto}->ipc_do('checkpoint', 1) : 0;
597 my $m = $self->can("_post_augment_$self->{base_type}") or return;
598 $m->($self, $lei, @args);
603 my $lei = $self->{lei};
604 # lei_xsearch can start as soon as all l2m workers get here
605 pkt_do($lei->{pkt_op_p}, 'incr_start_query') or
606 die "incr_start_query: $!";
608 if (lock_free($self)) {
609 my $mod = $self->{-wq_nr_workers};
610 my $shard = $self->{-wq_worker_nr};
611 if (my $net = $lei->{net}) {
612 $net->{shard_info} = [ $mod, $shard ];
613 } else { # Maildir (MH?)
614 $self->{shard_info} = [ $mod, $shard ];
616 $aug = '+'; # incr_post_augment
617 } elsif ($self->{-wq_worker_nr} == 0) {
618 $aug = '.'; # do_post_augment
621 local $0 = 'do_augment';
622 eval { do_augment($self, $lei) };
623 $lei->fail($@) if $@;
624 pkt_do($lei->{pkt_op_p}, $aug) == 1 or
625 die "do_post_augment trigger: $!";
627 if (my $zpipe = delete $lei->{zpipe}) {
628 $lei->{1} = $zpipe->[1];
631 $self->{wcb} = $self->write_cb($lei);
634 sub ipc_atfork_child {
636 my $lei = $self->{lei};
637 $lei->lei_atfork_child;
638 $lei->{auth}->do_auth_atfork($self) if $lei->{auth};
639 $SIG{__WARN__} = PublicInbox::Eml::warn_ignore_cb();
640 $self->SUPER::ipc_atfork_child;
644 $_[0]->{base_type} =~ /\A(?:maildir|mh|imap|jmap)\z/ ? 1 : 0;
649 if ($self->{base_type} eq 'maildir') {
651 utime($t, $t, $self->{dst} . 'cur');
655 sub write_mail { # via ->wq_io_do
656 my ($self, $smsg) = @_;
657 git_async_cat($self->{lei}->{ale}->git, $smsg->{blob}, \&git_to_mail,
658 [$self->{wcb}, $smsg]);
661 sub wq_atexit_child {
664 $self->{lei}->{ale}->git->async_wait_all;
665 $SIG{__WARN__} = 'DEFAULT';
668 # called in top-level lei-daemon when LeiAuth is done
669 sub net_merge_complete {
671 $self->wq_broadcast('do_post_auth');
675 no warnings 'once'; # the following works even when LeiAuth is lazy-loaded
676 *net_merge_all = \&PublicInbox::LeiAuth::net_merge_all;