mhl and mhbuild ignore to long lines
[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 #include <h/utils.h>
12
13 /*
14 ** We scan through the folder and act upon all messages
15 ** that are marked with the SELECT_UNSEEN bit.
16 **
17 ** Either add messages to or (if doadd is false) delete messages from
18 ** the unseen sequence(s).
19 */
20 void
21 seq_setunseen(struct msgs *mp, int doadd)
22 {
23         int n;
24         char **ap, *cp, *dp;
25
26         if (mp->lowmsg == 0) {
27                 return;
28         }
29
30         /*
31         ** Get the list of sequences for Unseen-Sequence
32         ** and split them.
33         */
34         if ((cp = context_find(usequence))) {
35                 dp = mh_xstrdup(cp);
36         } else {
37                 /* not set in profile, thus use the default */
38                 dp = mh_xstrdup(seq_unseen);
39         }
40         if (!(ap = brkstring(dp, " ", "\n")) || !*ap) {
41                 /* contains no sequence name, i.e. we're finished */
42                 mh_free0(&dp);
43                 return;
44         }
45
46         /*
47         ** Now add/delete each message which has the SELECT_UNSEEN
48         ** bit set to/from each of these sequences.
49         */
50         for (; *ap; ap++) {
51                 if (doadd) {
52                         for (n = mp->lowmsg; n <= mp->hghmsg; n++) {
53                                 if (is_unseen(mp, n)) {
54                                         seq_addmsg(mp, *ap, n, -1, 0);
55                                 }
56                         }
57                 } else {
58                         /* make sure sequence exists first */
59                         if (seq_getnum(mp, *ap) != -1) {
60                                 for (n = mp->lowsel; n <= mp->hghsel; n++) {
61                                         if (is_unseen(mp, n)) {
62                                                 seq_delmsg(mp, *ap, n);
63                                         }
64                                 }
65                         }
66                 }
67         }
68
69         mh_free0(&dp);
70 }