about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiToMail.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-03 13:48:57 +0000
committerEric Wong <e@80x24.org>2021-03-04 14:29:20 -0400
commitfbc11e24a72f41b0ed7ead30d199288a4d674be4 (patch)
tree9ce1e0f18633319ccace53c250091eada77dda86 /lib/PublicInbox/LeiToMail.pm
parent6fd748af8d4792d8cb857c3d2ec132ec3cca9bb8 (diff)
downloadpublic-inbox-fbc11e24a72f41b0ed7ead30d199288a4d674be4.tar.gz
This will eventually be supported for other mail stores,
but Maildir is the easiest to test and support, here.

This lets us avoid a situation where flag changes get
lost between search results.
Diffstat (limited to 'lib/PublicInbox/LeiToMail.pm')
-rw-r--r--lib/PublicInbox/LeiToMail.pm33
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 31b8aba8..3420b06e 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -267,8 +267,8 @@ sub _mbox_write_cb ($$) {
         }
 }
 
-sub _augment_file { # maildir_each_eml cb
-        my ($f, undef, $eml, $lei, $mod, $shard) = @_;
+sub _augment_or_unlink { # maildir_each_eml cb
+        my ($f, $kw, $eml, $lei, $lse, $mod, $shard, $unlink) = @_;
         if ($mod) {
                 # can't get dirent.d_ino w/ pure Perl, so we extract the OID
                 # if it looks like one:
@@ -276,8 +276,16 @@ sub _augment_file { # maildir_each_eml cb
                                 $1 : sha256_hex($f);
                 my $recno = hex(substr($hex, 0, 8));
                 return if ($recno % $mod) != $shard;
+                if ($lse) {
+                        my $x = $lse->kw_changed($eml, $kw);
+                        if ($x) {
+                                $lei->{sto}->ipc_do('set_eml', $eml, @$kw);
+                        } elsif (!defined($x)) {
+                                # TODO: xkw
+                        }
+                }
         }
-        _augment($eml, $lei);
+        $unlink ? unlink($f) : _augment($eml, $lei);
 }
 
 # maildir_each_file callback, \&CORE::unlink doesn't work with it
@@ -419,20 +427,31 @@ sub _pre_augment_maildir {
 sub _do_augment_maildir {
         my ($self, $lei) = @_;
         my $dst = $lei->{ovv}->{dst};
+        my $lse = $lei->{sto}->search if $lei->{opt}->{'import-augment'};
+        my ($mod, $shard) = @{$self->{shard_info} // []};
         if ($lei->{opt}->{augment}) {
                 my $dedupe = $lei->{dedupe};
                 if ($dedupe && $dedupe->prepare_dedupe) {
-                        my ($mod, $shard) = @{$self->{shard_info} // []};
                         PublicInbox::MdirReader::maildir_each_eml($dst,
-                                                \&_augment_file,
-                                                $lei, $mod, $shard);
+                                                \&_augment_or_unlink,
+                                                $lei, $lse, $mod, $shard);
                         $dedupe->pause_dedupe;
                 }
-        } else { # clobber existing Maildir
+        } elsif ($lse) {
+                PublicInbox::MdirReader::maildir_each_eml($dst,
+                                        \&_augment_or_unlink,
+                                        $lei, $lse, $mod, $shard, 1);
+        } else {# clobber existing Maildir
                 PublicInbox::MdirReader::maildir_each_file($dst, \&_unlink);
         }
 }
 
+sub _post_augment_maildir {
+        my ($self, $lei) = @_;
+        $lei->{opt}->{'import-augment'} or return;
+        my $wait = $lei->{sto}->ipc_do('checkpoint', 1);
+}
+
 sub _augment_imap { # PublicInbox::NetReader::imap_each cb
         my ($url, $uid, $kw, $eml, $lei) = @_;
         _augment($eml, $lei);