]> diplodocus.org Git - nmh/blob - sbr/seq_setunseen.c
Improve fmttest output
[nmh] / sbr / seq_setunseen.c
1 /* seq_setunseen.c -- add/delete all messages which have the SELECT_UNSEEN
2 * -- bit set to/from the Unseen-Sequence
3 *
4 * This code is Copyright (c) 2002, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
7 */
8
9 #include "h/mh.h"
10 #include "seq_setunseen.h"
11 #include "context_find.h"
12 #include "brkstring.h"
13 #include "seq_getnum.h"
14 #include "seq_del.h"
15 #include "seq_add.h"
16 #include "h/utils.h"
17
18 /*
19 * We scan through the folder and act upon all messages
20 * that are marked with the SELECT_UNSEEN bit.
21 *
22 * If seen == 1, delete messages from unseen sequence.
23 * If seen == 0, add messages to unseen sequence.
24 */
25
26 void
27 seq_setunseen (struct msgs *mp, int seen)
28 {
29 int msgnum;
30 char **ap, *cp, *dp;
31
32 /*
33 * Get the list of sequences for Unseen-Sequence
34 * and split them.
35 */
36 if (!(cp = context_find (usequence)))
37 return;
38 dp = mh_xstrdup(cp);
39 if (!(ap = brkstring (dp, " ", "\n")) || !*ap) {
40 free (dp);
41 return;
42 }
43
44 /*
45 * Now add/delete each message which has the SELECT_UNSEEN
46 * bit set to/from each of these sequences.
47 */
48 for (; *ap; ap++) {
49 if (seen) {
50 /* make sure sequence exists first */
51 if (seq_getnum(mp, *ap) != -1)
52 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
53 if (is_unseen (mp, msgnum))
54 seq_delmsg (mp, *ap, msgnum);
55 } else {
56 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
57 if (is_unseen (mp, msgnum))
58 seq_addmsg (mp, *ap, msgnum, -1, 0);
59 }
60 }
61
62 free (dp);
63 }