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= \ ...@@ -81,6 +81,7 @@ libmh_a_SOURCES= \
81 mh_stream.c\ 81 mh_stream.c\
82 mh_whatnow.c\ 82 mh_whatnow.c\
83 mh_whom.c\ 83 mh_whom.c\
84 seqelim.c\
84 whatnowenv.c 85 whatnowenv.c
85 noinst_HEADERS = mh.h mh_alias_gram.h mh_format.h mh_getopt.h 86 noinst_HEADERS = mh.h mh_alias_gram.h mh_format.h mh_getopt.h
86 87
......
...@@ -382,6 +382,8 @@ int mh_seq_delete (mu_mailbox_t mbox, const char *name, mu_msgset_t mset, ...@@ -382,6 +382,8 @@ int mh_seq_delete (mu_mailbox_t mbox, const char *name, mu_msgset_t mset,
382 int flags); 382 int flags);
383 const char *mh_seq_read (mu_mailbox_t mbox, const char *name, int flags); 383 const char *mh_seq_read (mu_mailbox_t mbox, const char *name, int flags);
384 384
385 void mh_sequences_elim (mu_msgset_t msgset);
386
385 void mh_comp_draft (const char *formfile, const char *draftfile); 387 void mh_comp_draft (const char *formfile, const char *draftfile);
386 int check_draft_disposition (struct mh_whatnow_env *wh, int use_draft); 388 int check_draft_disposition (struct mh_whatnow_env *wh, int use_draft);
387 389
......
...@@ -221,6 +221,8 @@ main (int argc, char **argv) ...@@ -221,6 +221,8 @@ main (int argc, char **argv)
221 221
222 status = mu_msgset_foreach_message (msgset, refile_iterator, NULL); 222 status = mu_msgset_foreach_message (msgset, refile_iterator, NULL);
223 223
224 mh_sequences_elim (msgset);
225
224 mu_mailbox_expunge (mbox); 226 mu_mailbox_expunge (mbox);
225 mu_mailbox_close (mbox); 227 mu_mailbox_close (mbox);
226 mu_mailbox_destroy (&mbox); 228 mu_mailbox_destroy (&mbox);
......
...@@ -31,30 +31,12 @@ rmm (size_t num, mu_message_t msg, void *data) ...@@ -31,30 +31,12 @@ rmm (size_t num, mu_message_t msg, void *data)
31 return 0; 31 return 0;
32 } 32 }
33 33
34 struct seq_closure
35 {
36 mu_msgset_t rmset;
37 int rmflag;
38 };
39
40 static int
41 rmseq (const char *name, const char *value, void *data)
42 {
43 struct seq_closure *s = data;
44 mu_mailbox_t mbox;
45
46 mu_msgset_sget_mailbox (s->rmset, &mbox);
47 mh_seq_delete (mbox, name, s->rmset, s->rmflag);
48 return 0;
49 }
50
51 int 34 int
52 main (int argc, char **argv) 35 main (int argc, char **argv)
53 { 36 {
54 mu_mailbox_t mbox; 37 mu_mailbox_t mbox;
55 mu_msgset_t msgset; 38 mu_msgset_t msgset;
56 int status; 39 int status;
57 struct seq_closure clos;
58 40
59 mh_getopt (&argc, &argv, NULL, MH_GETOPT_DEFAULT_FOLDER, 41 mh_getopt (&argc, &argv, NULL, MH_GETOPT_DEFAULT_FOLDER,
60 args_doc, prog_doc, NULL); 42 args_doc, prog_doc, NULL);
...@@ -65,16 +47,12 @@ main (int argc, char **argv) ...@@ -65,16 +47,12 @@ main (int argc, char **argv)
65 47
66 status = mu_msgset_foreach_message (msgset, rmm, NULL); 48 status = mu_msgset_foreach_message (msgset, rmm, NULL);
67 49
68 clos.rmset = msgset; 50 mh_sequences_elim (msgset);
69 clos.rmflag = 0;
70 mh_global_sequences_iterate (mbox, rmseq, &clos);
71 clos.rmflag = SEQ_PRIVATE;
72 mh_private_sequences_iterate (mbox, rmseq, &clos);
73 51
74 mu_mailbox_expunge (mbox); 52 mu_mailbox_expunge (mbox);
75 mu_mailbox_close (mbox); 53 mu_mailbox_close (mbox);
76 mu_mailbox_destroy (&mbox); 54 mu_mailbox_destroy (&mbox);
77 mh_global_save_state (); 55 mh_global_save_state ();
78 return status; 56 return !!status;
79 } 57 }
80 58
......
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2017 Free Software Foundation, Inc.
3
4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 GNU Mailutils is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <mh.h>
18
19 struct seq_closure
20 {
21 mu_msgset_t rmset;
22 int rmflag;
23 };
24
25 static int
26 seqelim (const char *name, const char *value, void *data)
27 {
28 struct seq_closure *s = data;
29 mu_mailbox_t mbox;
30
31 mu_msgset_sget_mailbox (s->rmset, &mbox);
32 mh_seq_delete (mbox, name, s->rmset, s->rmflag);
33 return 0;
34 }
35
36 /* Eliminate given messages from all sequences */
37 void
38 mh_sequences_elim (mu_msgset_t msgset)
39 {
40 struct seq_closure clos;
41 mu_mailbox_t mbox;
42
43 MU_ASSERT (mu_msgset_sget_mailbox (msgset, &mbox));
44 clos.rmset = msgset;
45 clos.rmflag = 0;
46 mh_global_sequences_iterate (mbox, seqelim, &clos);
47 clos.rmflag = SEQ_PRIVATE;
48 mh_private_sequences_iterate (mbox, seqelim, &clos);
49 }