]> diplodocus.org Git - nmh/blob - sbr/seq_del.c
Just reworded the bit about '%s' being safe not to quote (it's only safe not to
[nmh] / sbr / seq_del.c
1
2 /*
3 * seq_del.c -- delete message(s) from a sequence
4 *
5 * $Id$
6 */
7
8 #include <h/mh.h>
9
10
11 /*
12 * Delete all SELECTED messages from sequence
13 *
14 * If public == 1, make sequence public.
15 * If public == 0, make sequence private.
16 * If public == -1, leave the public/private bit alone for existing
17 * sequences. For new sequences, set this bit based
18 * on its readonly status.
19 *
20 * If error, return 0, else return 1.
21 */
22
23 int
24 seq_delsel (struct msgs *mp, char *cp, int public, int zero)
25 {
26 int i, msgnum, new_seq = 1;
27
28 if (!seq_nameok (cp))
29 return 0;
30
31 /*
32 * Get the number for this sequence
33 */
34 for (i = 0; mp->msgattrs[i]; i++) {
35 if (!strcmp (mp->msgattrs[i], cp)) {
36 new_seq = 0;
37 break;
38 }
39 }
40
41 /*
42 * If the zero flag is set, first add all existing
43 * messages in this folder to the sequence.
44 */
45 if (zero) {
46 /*
47 * create the sequence, if necessary
48 */
49 if (new_seq) {
50 if (i >= NUMATTRS) {
51 advise (NULL, "only %d sequences allowed (no room for %s)!", NUMATTRS, cp);
52 return 0;
53 }
54 if (!(mp->msgattrs[i] = strdup (cp))) {
55 advise (NULL, "strdup failed");
56 return 0;
57 }
58 mp->msgattrs[i + 1] = NULL;
59 }
60 /*
61 * now add sequence bit to all existing messages
62 */
63 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) {
64 if (does_exist (mp, msgnum))
65 add_sequence (mp, i, msgnum);
66 else
67 clear_sequence (mp, i, msgnum);
68 }
69 } else {
70 if (new_seq) {
71 advise (NULL, "no such sequence as %s", cp);
72 return 0;
73 }
74 }
75
76 /*
77 * Now clear the bit on all selected messages
78 */
79 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
80 if (is_selected (mp, msgnum))
81 clear_sequence (mp, i, msgnum);
82
83 /*
84 * Set the public/private bit for this sequence.
85 */
86 if (public == 1)
87 make_seq_public (mp, i);
88 else if (public == 0)
89 make_seq_private (mp, i);
90 else if (new_seq) {
91 /*
92 * If public == -1, then only set the
93 * public/private bit for new sequences.
94 */
95 if (is_readonly (mp))
96 make_seq_private (mp, i);
97 else
98 make_seq_public (mp, i);
99 }
100
101 mp->msgflags |= SEQMOD;
102 return 1;
103 }
104
105
106 /*
107 * Delete message from sequence.
108 *
109 * If error, return 0, else return 1.
110 */
111
112 int
113 seq_delmsg (struct msgs *mp, char *cp, int msgnum)
114 {
115 int i;
116
117 if (!seq_nameok (cp))
118 return 0;
119
120 for (i = 0; mp->msgattrs[i]; i++) {
121 if (!strcmp (mp->msgattrs[i], cp)) {
122 clear_sequence (mp, i, msgnum);
123 mp->msgflags |= SEQMOD;
124 return 1;
125 }
126 }
127
128 advise (NULL, "no such sequence as %s", cp);
129 return 0;
130 }