]> diplodocus.org Git - nmh/blob - sbr/seq_del.c
Various IMAP protocol improvements
[nmh] / sbr / seq_del.c
1 /* seq_del.c -- delete message(s) from a sequence
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
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 unsigned int i;
27 int msgnum;
28
29 if (!seq_nameok (cp))
30 return 0;
31
32 /*
33 * Get the number for this sequence
34 */
35 bool new_seq = true;
36 for (i = 0; i < svector_size (mp->msgattrs); i++) {
37 if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
38 new_seq = false;
39 break;
40 }
41 }
42
43 /*
44 * If the zero flag is set, first add all existing
45 * messages in this folder to the sequence.
46 */
47 if (zero) {
48 /*
49 * create the sequence, if necessary
50 */
51 if (new_seq) {
52 if (!(svector_push_back (mp->msgattrs, strdup (cp)))) {
53 inform("strdup failed");
54 return 0;
55 }
56 }
57 /*
58 * now add sequence bit to all existing messages
59 */
60 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) {
61 if (does_exist (mp, msgnum))
62 add_sequence (mp, i, msgnum);
63 else
64 clear_sequence (mp, i, msgnum);
65 }
66 } else {
67 if (new_seq) {
68 inform("no such sequence as %s", cp);
69 return 0;
70 }
71 }
72
73 /*
74 * Now clear the bit on all selected messages
75 */
76 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
77 if (is_selected (mp, msgnum))
78 clear_sequence (mp, i, msgnum);
79
80 if (! strcmp (cp, current) &&
81 mp->lowsel <= mp->curmsg && mp->curmsg <= mp->hghsel) {
82 /* Removed current message indication, so reset curmsg. */
83 mp->curmsg = 0;
84 }
85
86 /*
87 * Set the public/private bit for this sequence.
88 */
89 if (public == 1)
90 make_seq_public (mp, i);
91 else if (public == 0)
92 make_seq_private (mp, i);
93 else if (new_seq) {
94 /*
95 * If public == -1, then only set the
96 * public/private bit for new sequences.
97 */
98 if (is_readonly (mp))
99 make_seq_private (mp, i);
100 else
101 make_seq_public (mp, i);
102 }
103
104 mp->msgflags |= SEQMOD;
105 return 1;
106 }
107
108
109 /*
110 * Delete message from sequence.
111 *
112 * If error, return 0, else return 1.
113 */
114
115 int
116 seq_delmsg (struct msgs *mp, char *cp, int msgnum)
117 {
118 size_t i;
119
120 if (!seq_nameok (cp))
121 return 0;
122
123 for (i = 0; i < svector_size (mp->msgattrs); i++) {
124 if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
125 clear_sequence (mp, i, msgnum);
126 mp->msgflags |= SEQMOD;
127 return 1;
128 }
129 }
130
131 inform("no such sequence as %s", cp);
132 return 0;
133 }