Commit 1ddc81a1 1ddc81a18a3f1491494ff7ec3a21e1bbcabf265a by Sergey Poznyakoff

refile: eliminate refiled messages from all sequences

* mh/Makefile.am: Add seqelim.c
* mh/mh.h (mh_sequences_elim): New proto.
* mh/seqelim.c: New file.
* mh/refile.c (main): Fixup sequences after refiling.
* mh/rmm.c: Fixup sequences using mh_sequences_elim
1 parent 93a4e6d8
......@@ -81,6 +81,7 @@ libmh_a_SOURCES= \
mh_stream.c\
mh_whatnow.c\
mh_whom.c\
seqelim.c\
whatnowenv.c
noinst_HEADERS = mh.h mh_alias_gram.h mh_format.h mh_getopt.h
......
......@@ -382,6 +382,8 @@ int mh_seq_delete (mu_mailbox_t mbox, const char *name, mu_msgset_t mset,
int flags);
const char *mh_seq_read (mu_mailbox_t mbox, const char *name, int flags);
void mh_sequences_elim (mu_msgset_t msgset);
void mh_comp_draft (const char *formfile, const char *draftfile);
int check_draft_disposition (struct mh_whatnow_env *wh, int use_draft);
......
......@@ -220,7 +220,9 @@ main (int argc, char **argv)
mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
status = mu_msgset_foreach_message (msgset, refile_iterator, NULL);
mh_sequences_elim (msgset);
mu_mailbox_expunge (mbox);
mu_mailbox_close (mbox);
mu_mailbox_destroy (&mbox);
......
......@@ -31,30 +31,12 @@ rmm (size_t num, mu_message_t msg, void *data)
return 0;
}
struct seq_closure
{
mu_msgset_t rmset;
int rmflag;
};
static int
rmseq (const char *name, const char *value, void *data)
{
struct seq_closure *s = data;
mu_mailbox_t mbox;
mu_msgset_sget_mailbox (s->rmset, &mbox);
mh_seq_delete (mbox, name, s->rmset, s->rmflag);
return 0;
}
int
main (int argc, char **argv)
{
mu_mailbox_t mbox;
mu_msgset_t msgset;
int status;
struct seq_closure clos;
mh_getopt (&argc, &argv, NULL, MH_GETOPT_DEFAULT_FOLDER,
args_doc, prog_doc, NULL);
......@@ -64,17 +46,13 @@ main (int argc, char **argv)
mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
status = mu_msgset_foreach_message (msgset, rmm, NULL);
clos.rmset = msgset;
clos.rmflag = 0;
mh_global_sequences_iterate (mbox, rmseq, &clos);
clos.rmflag = SEQ_PRIVATE;
mh_private_sequences_iterate (mbox, rmseq, &clos);
mh_sequences_elim (msgset);
mu_mailbox_expunge (mbox);
mu_mailbox_close (mbox);
mu_mailbox_destroy (&mbox);
mh_global_save_state ();
return status;
return !!status;
}
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2017 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include <mh.h>
struct seq_closure
{
mu_msgset_t rmset;
int rmflag;
};
static int
seqelim (const char *name, const char *value, void *data)
{
struct seq_closure *s = data;
mu_mailbox_t mbox;
mu_msgset_sget_mailbox (s->rmset, &mbox);
mh_seq_delete (mbox, name, s->rmset, s->rmflag);
return 0;
}
/* Eliminate given messages from all sequences */
void
mh_sequences_elim (mu_msgset_t msgset)
{
struct seq_closure clos;
mu_mailbox_t mbox;
MU_ASSERT (mu_msgset_sget_mailbox (msgset, &mbox));
clos.rmset = msgset;
clos.rmflag = 0;
mh_global_sequences_iterate (mbox, seqelim, &clos);
clos.rmflag = SEQ_PRIVATE;
mh_private_sequences_iterate (mbox, seqelim, &clos);
}