From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 2A24E1FA00 for ; Wed, 3 Mar 2021 13:48:58 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/4] lei: use maildir_each_eml in more places Date: Wed, 3 Mar 2021 13:48:56 +0000 Message-Id: <20210303134857.7227-4-e@80x24.org> In-Reply-To: <20210303134857.7227-1-e@80x24.org> References: <20210303134857.7227-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This saves us some code and redundant callsites for eml_from_path. We'll change maildir_each_eml to include the filename to facilitate an upcoming change to "lei q" without --augment --- lib/PublicInbox/LeiConvert.pm | 3 +-- lib/PublicInbox/LeiToMail.pm | 18 ++++++------------ lib/PublicInbox/MdirReader.pm | 10 ++++++---- t/lei-convert.t | 2 +- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm index 4c0bbd88..0c705ba4 100644 --- a/lib/PublicInbox/LeiConvert.pm +++ b/lib/PublicInbox/LeiConvert.pm @@ -7,7 +7,6 @@ use strict; use v5.10.1; use parent qw(PublicInbox::IPC); use PublicInbox::Eml; -use PublicInbox::InboxWritable qw(eml_from_path); use PublicInbox::LeiStore; use PublicInbox::LeiOverview; @@ -24,7 +23,7 @@ sub net_cb { # callback for ->imap_each, ->nntp_each } sub mdir_cb { - my ($kw, $eml, $self) = @_; + my ($f, $kw, $eml, $self) = @_; $self->{wcb}->(undef, { kw => $kw }, $eml); } diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm index de640657..31b8aba8 100644 --- a/lib/PublicInbox/LeiToMail.pm +++ b/lib/PublicInbox/LeiToMail.pm @@ -19,7 +19,6 @@ use IO::Handle; # ->autoflush use Fcntl qw(SEEK_SET SEEK_END O_CREAT O_EXCL O_WRONLY); use Errno qw(EEXIST ESPIPE ENOENT EPIPE); use Digest::SHA qw(sha256_hex); -my ($maildir_each_file); # struggles with short-lived repos, Gcf2Client makes little sense with lei; # but we may use in-process libgit2 in the future. @@ -268,8 +267,8 @@ sub _mbox_write_cb ($$) { } } -sub _augment_file { # maildir_each_file cb - my ($f, $lei, $mod, $shard) = @_; +sub _augment_file { # maildir_each_eml cb + my ($f, undef, $eml, $lei, $mod, $shard) = @_; if ($mod) { # can't get dirent.d_ino w/ pure Perl, so we extract the OID # if it looks like one: @@ -278,7 +277,6 @@ sub _augment_file { # maildir_each_file cb my $recno = hex(substr($hex, 0, 8)); return if ($recno % $mod) != $shard; } - my $eml = PublicInbox::InboxWritable::eml_from_path($f) or return; _augment($eml, $lei); } @@ -375,12 +373,7 @@ sub new { my $dst = $lei->{ovv}->{dst}; my $self = bless {}, $cls; if ($fmt eq 'maildir') { - $maildir_each_file //= do { - require PublicInbox::MdirReader; - PublicInbox::MdirReader->can('maildir_each_file'); - }; - $lei->{opt}->{augment} and - require PublicInbox::InboxWritable; # eml_from_path + require PublicInbox::MdirReader; $self->{base_type} = 'maildir'; -e $dst && !-d _ and die "$dst exists and is not a directory\n"; @@ -430,12 +423,13 @@ sub _do_augment_maildir { my $dedupe = $lei->{dedupe}; if ($dedupe && $dedupe->prepare_dedupe) { my ($mod, $shard) = @{$self->{shard_info} // []}; - $maildir_each_file->($dst, \&_augment_file, + PublicInbox::MdirReader::maildir_each_eml($dst, + \&_augment_file, $lei, $mod, $shard); $dedupe->pause_dedupe; } } else { # clobber existing Maildir - $maildir_each_file->($dst, \&_unlink); + PublicInbox::MdirReader::maildir_each_file($dst, \&_unlink); } } diff --git a/lib/PublicInbox/MdirReader.pm b/lib/PublicInbox/MdirReader.pm index 5fa534f5..44724af1 100644 --- a/lib/PublicInbox/MdirReader.pm +++ b/lib/PublicInbox/MdirReader.pm @@ -48,17 +48,19 @@ sub maildir_each_eml ($$;@) { next if substr($bn, 0, 1) eq '.'; my @f = split(/:/, $bn, -1); next if scalar(@f) != 1; - my $eml = eml_from_path($pfx.$bn) or next; - $cb->([], $eml, @arg); + my $f = $pfx.$bn; + my $eml = eml_from_path($f) or next; + $cb->($f, [], $eml, @arg); } } $pfx = "$dir/cur/"; opendir my $dh, $pfx or return; while (defined(my $bn = readdir($dh))) { my $fl = maildir_basename_flags($bn) // next; - my $eml = eml_from_path($pfx.$bn) or next; + my $f = $pfx.$bn; + my $eml = eml_from_path($f) or next; my @kw = sort(map { $c2kw{$_} // () } split(//, $fl)); - $cb->(\@kw, $eml, @arg); + $cb->($f, \@kw, $eml, @arg); } } diff --git a/t/lei-convert.t b/t/lei-convert.t index 20099f65..186cfb13 100644 --- a/t/lei-convert.t +++ b/t/lei-convert.t @@ -58,7 +58,7 @@ test_lei({ tmpdir => $tmpdir }, sub { ok(-d "$d/md", 'Maildir created'); my @md; PublicInbox::MdirReader::maildir_each_eml("$d/md", sub { - push @md, $_[1]; + push @md, $_[2]; }); is(scalar(@md), scalar(@mboxrd), 'got expected emails in Maildir'); @md = sort { ${$a->{bdy}} cmp ${$b->{bdy}} } @md;