e628393221d73ea3772941a91a92c8dc737a2046
[mmh] / sbr / seq_setunseen.c
1 /*
2 ** seq_setunseen.c -- add/delete all messages which have the SELECT_UNSEEN
3 **                 -- bit set to/from the Unseen-Sequence
4 **
5 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
6 ** COPYRIGHT file in the root directory of the nmh distribution for
7 ** complete copyright information.
8 */
9
10 #include <h/mh.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 ** Either add messages to or (if doadd is false) delete messages from
17 ** the unseen sequence(s).
18 */
19 void
20 seq_setunseen(struct msgs *mp, int doadd)
21 {
22         int n;
23         char **ap, *cp, *dp;
24
25         /*
26         ** Get the list of sequences for Unseen-Sequence
27         ** and split them.
28         */
29         if ((cp = context_find(usequence))) {
30                 dp = getcpy(cp);
31         } else {
32                 /* not set in profile, thus use the default */
33                 dp = getcpy(seq_unseen);
34         }
35         if (!(ap = brkstring(dp, " ", "\n")) || !*ap) {
36                 /* contains no sequence name, i.e. we're finished */
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 (doadd) {
47                         for (n = mp->lowmsg; n <= mp->hghmsg; n++) {
48                                 if (is_unseen(mp, n)) {
49                                         seq_addmsg(mp, *ap, n, -1, 0);
50                                 }
51                         }
52                 } else {
53                         /* make sure sequence exists first */
54                         if (seq_getnum(mp, *ap) != -1) {
55                                 for (n = mp->lowsel; n <= mp->hghsel; n++) {
56                                         if (is_unseen(mp, n)) {
57                                                 seq_delmsg(mp, *ap, n);
58                                         }
59                                 }
60                         }
61                 }
62         }
63
64         free(dp);
65 }