40b84746d42df5f26109024422e6a7168d11d650
[mmh] / sbr / seq_msgstats.c
1 /*
2 ** seq_msgstats -- message and sequence manipulation and folder attributes
3 **
4 ** (These functions had once been macros in h/mh.h)
5 */
6
7 #include <h/mh.h>
8
9 static void
10 assert_msg_range(struct msgs *mp, int msgnum)
11 {
12         if (msgnum < mp->lowoff || msgnum > mp->hghoff) {
13                 adios(NULL, "Bug: message out of bounds");
14         }
15 }
16
17
18 void
19 add_sequence(struct msgs *mp, int seqnum, int msgnum)
20 {
21         assert_msg_range(mp, msgnum);
22         mp->msgstats[msgnum - mp->lowoff] |= (1 << (FFATTRSLOT + seqnum));
23 }
24
25 void
26 clear_msg_flags(struct msgs *mp, int msgnum)
27 {
28         assert_msg_range(mp, msgnum);
29         mp->msgstats[msgnum - mp->lowoff] = 0;
30 }
31
32 void
33 clear_sequence(struct msgs *mp, int seqnum, int msgnum)
34 {
35         assert_msg_range(mp, msgnum);
36         mp->msgstats[msgnum - mp->lowoff] &= ~(1 << (FFATTRSLOT + seqnum));
37 }
38
39 void
40 copy_msg_flags(struct msgs *mp, int dstmsg, int srcmsg)
41 {
42         assert_msg_range(mp, srcmsg);
43         assert_msg_range(mp, dstmsg);
44         mp->msgstats[dstmsg - mp->lowoff] = mp->msgstats[srcmsg - mp->lowoff];
45 }
46
47 seqset_t
48 does_exist(struct msgs *mp, int msgnum)
49 {
50         assert_msg_range(mp, msgnum);
51         return mp->msgstats[msgnum - mp->lowoff] & EXISTS;
52 }
53
54 void
55 get_msg_flags(struct msgs *mp, seqset_t *dst, int msgnum)
56 {
57         assert_msg_range(mp, msgnum);
58         *dst = mp->msgstats[msgnum - mp->lowoff];
59 }
60
61 seqset_t
62 in_sequence(struct msgs *mp, int seqnum, int msgnum)
63 {
64         assert_msg_range(mp, msgnum);
65         return mp->msgstats[msgnum - mp->lowoff] & (1 << (FFATTRSLOT + seqnum));
66 }
67
68 seqset_t
69 is_selected(struct msgs *mp, int msgnum)
70 {
71         assert_msg_range(mp, msgnum);
72         return mp->msgstats[msgnum - mp->lowoff] & SELECTED;
73 }
74
75 seqset_t
76 is_unseen(struct msgs *mp, int msgnum)
77 {
78         assert_msg_range(mp, msgnum);
79         return mp->msgstats[msgnum - mp->lowoff] & SELECT_UNSEEN;
80 }
81
82 void
83 set_exists(struct msgs *mp, int msgnum)
84 {
85         assert_msg_range(mp, msgnum);
86         mp->msgstats[msgnum - mp->lowoff] |= EXISTS;
87 }
88
89 void
90 set_msg_flags(struct msgs *mp, seqset_t *src, int msgnum)
91 {
92         assert_msg_range(mp, msgnum);
93         mp->msgstats[msgnum - mp->lowoff] = *src;
94 }
95
96 void
97 set_selected(struct msgs *mp, int msgnum)
98 {
99         assert_msg_range(mp, msgnum);
100         mp->msgstats[msgnum - mp->lowoff] |= SELECTED;
101 }
102
103 void
104 set_unseen(struct msgs *mp, int msgnum)
105 {
106         assert_msg_range(mp, msgnum);
107         mp->msgstats[msgnum - mp->lowoff] |= SELECT_UNSEEN;
108 }
109
110 void
111 unset_exists(struct msgs *mp, int msgnum)
112 {
113         assert_msg_range(mp, msgnum);
114         mp->msgstats[msgnum - mp->lowoff] &= ~EXISTS;
115 }
116
117 void
118 unset_selected(struct msgs *mp, int msgnum)
119 {
120         assert_msg_range(mp, msgnum);
121         mp->msgstats[msgnum - mp->lowoff] &= ~SELECTED;
122 }
123
124 void
125 unset_unseen(struct msgs *mp, int msgnum)
126 {
127         assert_msg_range(mp, msgnum);
128         mp->msgstats[msgnum - mp->lowoff] &= ~SELECT_UNSEEN;
129 }
130
131
132 /*
133 **  private/public sequences
134 */
135
136 int
137 is_seq_private(struct msgs *mp, int seqnum)
138 {
139         return mp->attrstats & (1 << (FFATTRSLOT + seqnum));
140 }
141
142 void
143 make_seq_public(struct msgs *mp, int seqnum)
144 {
145         mp->attrstats &= ~(1 << (FFATTRSLOT + seqnum));
146 }
147 void
148 make_seq_private(struct msgs *mp, int seqnum)
149 {
150         mp->attrstats |= (1 << (FFATTRSLOT + seqnum));
151 }
152 void
153 make_all_public(struct msgs *mp)
154 {
155         mp->attrstats = 0;
156 }
157
158
159 /*
160 ** folder attributes
161 */
162
163 void
164 clear_folder_flags(struct msgs *mp)
165 {
166         mp->msgflags = 0;
167 }
168
169 int
170 is_readonly(struct msgs *mp)
171 {
172         return mp->msgflags & READONLY;
173 }
174 void
175 set_readonly(struct msgs *mp)
176 {
177         mp->msgflags |= READONLY;
178 }
179
180 int
181 other_files(struct msgs *mp)
182 {
183         return mp->msgflags & OTHERS;
184 }
185 void
186 set_other_files(struct msgs *mp)
187 {
188         mp->msgflags |= OTHERS;
189 }