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