about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-03 13:48:56 +0000
committerEric Wong <e@80x24.org>2021-03-04 14:29:19 -0400
commit6fd748af8d4792d8cb857c3d2ec132ec3cca9bb8 (patch)
tree04d20542291e3ad6550950bbb3d29221fedcd577
parent06349427654334deb14b21769a66e03a3e646684 (diff)
downloadpublic-inbox-6fd748af8d4792d8cb857c3d2ec132ec3cca9bb8.tar.gz
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
-rw-r--r--lib/PublicInbox/LeiConvert.pm3
-rw-r--r--lib/PublicInbox/LeiToMail.pm18
-rw-r--r--lib/PublicInbox/MdirReader.pm10
-rw-r--r--t/lei-convert.t2
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;