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