(util_msglist_command, util_msglist_esccmd): Removed.
(util_foreach_msg,util_range_msg): New functions. Iterate across message set or range calling given function for each message.
Showing
2 changed files
with
32 additions
and
50 deletions
... | @@ -144,10 +144,11 @@ struct message_set | ... | @@ -144,10 +144,11 @@ struct message_set |
144 | number */ | 144 | number */ |
145 | }; | 145 | }; |
146 | 146 | ||
147 | typedef int (*msg_handler_t) __P((msgset_t *mp, message_t mesg, void *data)); | ||
148 | |||
147 | /* Global variables and constants*/ | 149 | /* Global variables and constants*/ |
148 | extern mailbox_t mbox; | 150 | extern mailbox_t mbox; |
149 | extern unsigned int cursor; | 151 | extern unsigned int cursor; |
150 | extern unsigned int realcursor; | ||
151 | extern size_t total; | 152 | extern size_t total; |
152 | extern FILE *ofile; | 153 | extern FILE *ofile; |
153 | extern int interactive; | 154 | extern int interactive; |
... | @@ -172,7 +173,7 @@ extern int mail_file __P ((int argc, char **argv)); | ... | @@ -172,7 +173,7 @@ extern int mail_file __P ((int argc, char **argv)); |
172 | extern int mail_folders __P ((int argc, char **argv)); | 173 | extern int mail_folders __P ((int argc, char **argv)); |
173 | extern int mail_followup __P ((int argc, char **argv)); | 174 | extern int mail_followup __P ((int argc, char **argv)); |
174 | extern int mail_from __P ((int argc, char **argv)); | 175 | extern int mail_from __P ((int argc, char **argv)); |
175 | extern int mail_from0 __P((int msgno, int verbose)); | 176 | extern int mail_from0 __P((msgset_t *mspec, message_t msg, void *data)); |
176 | extern int mail_headers __P ((int argc, char **argv)); | 177 | extern int mail_headers __P ((int argc, char **argv)); |
177 | extern int mail_hold __P ((int argc, char **argv)); | 178 | extern int mail_hold __P ((int argc, char **argv)); |
178 | extern int mail_help __P ((int argc, char **argv)); | 179 | extern int mail_help __P ((int argc, char **argv)); |
... | @@ -258,10 +259,12 @@ extern int msgset_member __P ((msgset_t *set, size_t n)); | ... | @@ -258,10 +259,12 @@ extern int msgset_member __P ((msgset_t *set, size_t n)); |
258 | extern msgset_t *msgset_negate __P((msgset_t *set)); | 259 | extern msgset_t *msgset_negate __P((msgset_t *set)); |
259 | 260 | ||
260 | extern int util_do_command __P ((const char *cmd, ...)); | 261 | extern int util_do_command __P ((const char *cmd, ...)); |
261 | extern int util_msglist_command __P ((function_t *func, int argc, char **argv, int set_cursor)); | 262 | |
262 | extern int util_msglist_esccmd | 263 | extern int util_foreach_msg __P((int argc, char **argv, int flags, |
263 | __P ((int (*escfunc) __P ((int, char **, compose_env_t *)), | 264 | msg_handler_t func, void *data)); |
264 | int argc, char **argv, compose_env_t *env, int set_cursor)); | 265 | extern int util_range_msg __P((size_t low, size_t high, int flags, |
266 | msg_handler_t func, void *data)); | ||
267 | |||
265 | extern function_t* util_command_get __P ((const char *cmd)); | 268 | extern function_t* util_command_get __P ((const char *cmd)); |
266 | extern char *util_stripwhite __P ((char *string)); | 269 | extern char *util_stripwhite __P ((char *string)); |
267 | extern struct mail_command_entry util_find_entry __P ((const struct mail_command_entry *table, const char *cmd)); | 270 | extern struct mail_command_entry util_find_entry __P ((const struct mail_command_entry *table, const char *cmd)); | ... | ... |
... | @@ -155,18 +155,9 @@ util_do_command (const char *c, ...) | ... | @@ -155,18 +155,9 @@ util_do_command (const char *c, ...) |
155 | return status; | 155 | return status; |
156 | } | 156 | } |
157 | 157 | ||
158 | /* | ||
159 | * runs a function repeatedly on a msglist | ||
160 | * func is the function to run | ||
161 | * argc is the number of arguments inculding the command and msglist | ||
162 | * argv is the list of strings containing the command and msglist | ||
163 | * set_cursor means whether the function should set the cursor to | ||
164 | * the number of the last message processed. If set_cursor = 0, the | ||
165 | * cursor is not altered. | ||
166 | */ | ||
167 | |||
168 | int | 158 | int |
169 | util_msglist_command (function_t *func, int argc, char **argv, int set_cursor) | 159 | util_foreach_msg (int argc, char **argv, int flags, |
160 | msg_handler_t func, void *data) | ||
170 | { | 161 | { |
171 | msgset_t *list = NULL, *mp; | 162 | msgset_t *list = NULL, *mp; |
172 | int status = 0; | 163 | int status = 0; |
... | @@ -174,60 +165,48 @@ util_msglist_command (function_t *func, int argc, char **argv, int set_cursor) | ... | @@ -174,60 +165,48 @@ util_msglist_command (function_t *func, int argc, char **argv, int set_cursor) |
174 | if (msgset_parse (argc, argv, &list)) | 165 | if (msgset_parse (argc, argv, &list)) |
175 | return 1; | 166 | return 1; |
176 | 167 | ||
177 | realcursor = cursor; | ||
178 | |||
179 | for (mp = list; mp; mp = mp->next) | 168 | for (mp = list; mp; mp = mp->next) |
180 | { | 169 | { |
181 | cursor = mp->msg_part[0]; | 170 | message_t mesg; |
182 | /* NOTE: Should we bail on error also? */ | 171 | |
183 | if (func (1, argv) != 0) | 172 | if (util_get_message (mbox, mp->msg_part[0], &mesg, flags) == 0) |
173 | { | ||
174 | if (func (mp, mesg, data) != 0) | ||
184 | status = 1; | 175 | status = 1; |
185 | /* Bail out if we receive an interrupt. */ | 176 | /* Bail out if we receive an interrupt. */ |
186 | if (ml_got_interrupt () != 0) | 177 | if (ml_got_interrupt () != 0) |
187 | break; | 178 | break; |
188 | } | 179 | } |
180 | } | ||
189 | msgset_free (list); | 181 | msgset_free (list); |
190 | 182 | ||
191 | if (set_cursor) | ||
192 | realcursor = cursor; | ||
193 | else | ||
194 | cursor = realcursor; | ||
195 | return status; | 183 | return status; |
196 | } | 184 | } |
197 | 185 | ||
198 | /* Same as util_msglis_command but the function comes from the escape | ||
199 | cmd table, so will have a different argument signature. */ | ||
200 | int | 186 | int |
201 | util_msglist_esccmd (int (*escfunc) | 187 | util_range_msg (size_t low, size_t high, int flags, |
202 | __P ((int, char **, compose_env_t *)), | 188 | msg_handler_t func, void *data) |
203 | int argc, char **argv, compose_env_t *env, | ||
204 | int set_cursor) | ||
205 | { | 189 | { |
206 | msgset_t *list = NULL, *mp; | 190 | msgset_t msgspec = { 0 }; |
207 | int status = 0; | 191 | int count = 0; |
208 | 192 | ||
209 | if (msgset_parse (argc, argv, &list)) | 193 | msgspec.next = NULL; |
210 | return 1; | 194 | msgspec.npart = 0; |
211 | 195 | msgspec.msg_part = &low; | |
212 | realcursor = cursor; | 196 | for (; low <= high; low++) |
197 | { | ||
198 | message_t mesg; | ||
213 | 199 | ||
214 | for (mp = list; mp; mp = mp->next) | 200 | if (util_get_message (mbox, low, &mesg, flags) == 0) |
215 | { | 201 | { |
216 | cursor = mp->msg_part[0]; | 202 | count ++; |
217 | /* NOTE: Should we bail on error also? */ | 203 | func (&msgspec, mesg, data) ; |
218 | if (escfunc (1, argv, env) != 0) | ||
219 | status = 1; | ||
220 | /* Bail out if we receive an interrupt. */ | 204 | /* Bail out if we receive an interrupt. */ |
221 | if (ml_got_interrupt () != 0) | 205 | if (ml_got_interrupt () != 0) |
222 | break; | 206 | break; |
223 | } | 207 | } |
224 | msgset_free (list); | 208 | } |
225 | 209 | return count; | |
226 | if (set_cursor) | ||
227 | realcursor = cursor; | ||
228 | else | ||
229 | cursor = realcursor; | ||
230 | return status; | ||
231 | } | 210 | } |
232 | 211 | ||
233 | /* | 212 | /* | ... | ... |
-
Please register or sign in to post a comment