Add/update copyright notice in all source code files.
[mmh] / sbr / seq_setunseen.c
1
2 /*
3  * seq_setunseen.c -- add/delete all messages which have the SELECT_UNSEEN
4  *                 -- bit set to/from the Unseen-Sequence
5  *
6  * $Id$
7  *
8  * This code is Copyright (c) 2002, by the authors of nmh.  See the
9  * COPYRIGHT file in the root directory of the nmh distribution for
10  * complete copyright information.
11  */
12
13 #include <h/mh.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         dp = getcpy (cp);
35         if (!(ap = brkstring (dp, " ", "\n")) || !*ap) {
36             free (dp);
37             return;
38         }
39     } else {
40         return;
41     }
42
43     /*
44      * Now add/delete each message which has the SELECT_UNSEEN
45      * bit set to/from each of these sequences.
46      */
47     for (; *ap; ap++) {
48         if (seen) {
49             /* make sure sequence exists first */
50             if (seq_getnum(mp, *ap) != -1)
51                 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
52                     if (is_unseen (mp, msgnum))
53                         seq_delmsg (mp, *ap, msgnum);
54         } else {
55             for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
56                 if (is_unseen (mp, msgnum))
57                     seq_addmsg (mp, *ap, msgnum, -1, 0);
58         }
59     }
60
61     free (dp);
62 }