]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiStore.pm
lei import: keep sync info for Maildir and IMAP folders
[public-inbox.git] / lib / PublicInbox / LeiStore.pm
index f8371abfcb69b347abd6fd525abcf92bfdc30d78..1cf7ffc1d206428ecb4b594620cb41a918465053 100644 (file)
@@ -190,13 +190,28 @@ sub remove_eml_vmd {
        \@docids;
 }
 
+sub set_sync_info ($$$) {
+       my ($self, $oidhex, $sync_info) = @_;
+       ($self->{lms} //= do {
+               require PublicInbox::LeiMailSync;
+               my $f = "$self->{priv_eidx}->{topdir}/mail_sync.sqlite3";
+               my $lms = PublicInbox::LeiMailSync->new($f);
+               $lms->lms_begin;
+               $lms;
+       })->set_src($oidhex, @$sync_info);
+}
+
 sub add_eml {
        my ($self, $eml, $vmd, $xoids) = @_;
        my $im = $self->importer; # may create new epoch
        my ($eidx, $tl) = eidx_init($self); # updates/writes alternates file
        my $oidx = $eidx->{oidx}; # PublicInbox::Import::add checks this
        my $smsg = bless { -oidx => $oidx }, 'PublicInbox::Smsg';
-       $im->add($eml, undef, $smsg) or return; # duplicate returns undef
+       my $im_mark = $im->add($eml, undef, $smsg);
+       if ($vmd && $vmd->{sync_info}) {
+               set_sync_info($self, $smsg->{blob}, $vmd->{sync_info});
+       }
+       $im_mark or return; # duplicate blob returns undef
 
        local $self->{current_info} = $smsg->{blob};
        my $vivify_xvmd = delete($smsg->{-vivify_xvmd}) // []; # exact matches
@@ -379,6 +394,9 @@ sub done {
                        warn $err;
                }
        }
+       if (my $lms = delete $self->{lms}) {
+               $lms->lms_commit;
+       }
        $self->{priv_eidx}->done; # V2Writable::done
        xchg_stderr($self);
        die $err if $err;