From bfe6a3e13c286d60a5bfa46cef7625f83ae0ca18 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 25 May 2021 11:01:36 +0000 Subject: lei forget-mail-sync: new command to drop sync information Sometimes a user stops caring to sync an IMAP or Maildir folder, or wants to force a resync. Let them run this command to have lei forget all the sync information about the mail folder. This won't delete any stored messages in git, but will leave "lei index" users with dangling references. --- lib/PublicInbox/LeiForgetMailSync.pm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/PublicInbox/LeiForgetMailSync.pm (limited to 'lib/PublicInbox/LeiForgetMailSync.pm') diff --git a/lib/PublicInbox/LeiForgetMailSync.pm b/lib/PublicInbox/LeiForgetMailSync.pm new file mode 100644 index 00000000..46dde1a7 --- /dev/null +++ b/lib/PublicInbox/LeiForgetMailSync.pm @@ -0,0 +1,30 @@ +# Copyright (C) 2021 all contributors +# License: AGPL-3.0+ + +# "lei forget-mail-sync" drop synchronization information +# TODO: figure out what to do about "lei index" users having +# dangling references. Perhaps just documenting "lei index" +# use being incompatible with "forget-mail-sync" use is +# sufficient. + +package PublicInbox::LeiForgetMailSync; +use strict; +use v5.10.1; +use PublicInbox::LeiExportKw; + +sub lei_forget_mail_sync { + my ($lei, @folders) = @_; + my $sto = $lei->_lei_store or return; + my $lms = $sto->search->lms or return; + my $err = $lms->arg2folder($lei, \@folders); + $lei->qerr(@{$err->{qerr}}) if $err->{qerr}; + return $lei->fail($err->{fail}) if $err->{fail}; + delete $lms->{dbh}; + $lms->lms_begin; + $lms->forget_folder($_) for @folders; + $lms->lms_commit; +} + +*_complete_forget_mail_sync = \&PublicInbox::LeiExportKw::_complete_export_kw; + +1; -- cgit v1.2.3-24-ge0c7