]> diplodocus.org Git - nmh/blob - sbr/seq_del.c
sendsbr.c: Move interface to own file.
[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 #include "seq_nameok.h"
10 #include "error.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;
30
31 if (!seq_nameok (cp))
32 return 0;
33
34 /*
35 * Get the number for this sequence
36 */
37 bool new_seq = true;
38 for (i = 0; i < svector_size (mp->msgattrs); i++) {
39 if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
40 new_seq = false;
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 (!(svector_push_back (mp->msgattrs, strdup (cp)))) {
55 inform("strdup failed");
56 return 0;
57 }
58 }
59 /*
60 * now add sequence bit to all existing messages
61 */
62 for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) {
63 if (does_exist (mp, msgnum))
64 add_sequence (mp, i, msgnum);
65 else
66 clear_sequence (mp, i, msgnum);
67 }
68 } else {
69 if (new_seq) {
70 inform("no such sequence as %s", cp);
71 return 0;
72 }
73 }
74
75 /*
76 * Now clear the bit on all selected messages
77 */
78 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
79 if (is_selected (mp, msgnum))
80 clear_sequence (mp, i, msgnum);
81
82 if (! strcmp (cp, current) &&
83 mp->lowsel <= mp->curmsg && mp->curmsg <= mp->hghsel) {
84 /* Removed current message indication, so reset curmsg. */
85 mp->curmsg = 0;
86 }
87
88 /*
89 * Set the public/private bit for this sequence.
90 */
91 if (public == 1)
92 make_seq_public (mp, i);
93 else if (public == 0)
94 make_seq_private (mp, i);
95 else if (new_seq) {
96 /*
97 * If public == -1, then only set the
98 * public/private bit for new sequences.
99 */
100 if (is_readonly (mp))
101 make_seq_private (mp, i);
102 else
103 make_seq_public (mp, i);
104 }
105
106 mp->msgflags |= SEQMOD;
107 return 1;
108 }
109
110
111 /*
112 * Delete message from sequence.
113 *
114 * If error, return 0, else return 1.
115 */
116
117 int
118 seq_delmsg (struct msgs *mp, char *cp, int msgnum)
119 {
120 size_t i;
121
122 if (!seq_nameok (cp))
123 return 0;
124
125 for (i = 0; i < svector_size (mp->msgattrs); i++) {
126 if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
127 clear_sequence (mp, i, msgnum);
128 mp->msgflags |= SEQMOD;
129 return 1;
130 }
131 }
132
133 inform("no such sequence as %s", cp);
134 return 0;
135 }