]> diplodocus.org Git - nmh/blob - sbr/seq_setunseen.c
new.c: Order two return statements to match comment.
[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 <h/utils.h>
11
12 /*
13 * We scan through the folder and act upon all messages
14 * that are marked with the SELECT_UNSEEN bit.
15 *
16 * If seen == 1, delete messages from unseen sequence.
17 * If seen == 0, add messages to unseen sequence.
18 */
19
20 void
21 seq_setunseen (struct msgs *mp, int seen)
22 {
23 int msgnum;
24 char **ap, *cp, *dp;
25
26 /*
27 * Get the list of sequences for Unseen-Sequence
28 * and split them.
29 */
30 if (!(cp = context_find (usequence)))
31 return;
32 dp = mh_xstrdup(cp);
33 if (!(ap = brkstring (dp, " ", "\n")) || !*ap) {
34 free (dp);
35 return;
36 }
37
38 /*
39 * Now add/delete each message which has the SELECT_UNSEEN
40 * bit set to/from each of these sequences.
41 */
42 for (; *ap; ap++) {
43 if (seen) {
44 /* make sure sequence exists first */
45 if (seq_getnum(mp, *ap) != -1)
46 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
47 if (is_unseen (mp, msgnum))
48 seq_delmsg (mp, *ap, msgnum);
49 } else {
50 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
51 if (is_unseen (mp, msgnum))
52 seq_addmsg (mp, *ap, msgnum, -1, 0);
53 }
54 }
55
56 free (dp);
57 }