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