Commit 7d408629 7d40862926661727a43b70ac8db876bf42b3d0ca by Sergey Poznyakoff

(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.
1 parent 450bb328
......@@ -144,10 +144,11 @@ struct message_set
number */
};
typedef int (*msg_handler_t) __P((msgset_t *mp, message_t mesg, void *data));
/* Global variables and constants*/
extern mailbox_t mbox;
extern unsigned int cursor;
extern unsigned int realcursor;
extern size_t total;
extern FILE *ofile;
extern int interactive;
......@@ -172,7 +173,7 @@ extern int mail_file __P ((int argc, char **argv));
extern int mail_folders __P ((int argc, char **argv));
extern int mail_followup __P ((int argc, char **argv));
extern int mail_from __P ((int argc, char **argv));
extern int mail_from0 __P((int msgno, int verbose));
extern int mail_from0 __P((msgset_t *mspec, message_t msg, void *data));
extern int mail_headers __P ((int argc, char **argv));
extern int mail_hold __P ((int argc, char **argv));
extern int mail_help __P ((int argc, char **argv));
......@@ -258,10 +259,12 @@ extern int msgset_member __P ((msgset_t *set, size_t n));
extern msgset_t *msgset_negate __P((msgset_t *set));
extern int util_do_command __P ((const char *cmd, ...));
extern int util_msglist_command __P ((function_t *func, int argc, char **argv, int set_cursor));
extern int util_msglist_esccmd
__P ((int (*escfunc) __P ((int, char **, compose_env_t *)),
int argc, char **argv, compose_env_t *env, int set_cursor));
extern int util_foreach_msg __P((int argc, char **argv, int flags,
msg_handler_t func, void *data));
extern int util_range_msg __P((size_t low, size_t high, int flags,
msg_handler_t func, void *data));
extern function_t* util_command_get __P ((const char *cmd));
extern char *util_stripwhite __P ((char *string));
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, ...)
return status;
}
/*
* runs a function repeatedly on a msglist
* func is the function to run
* argc is the number of arguments inculding the command and msglist
* argv is the list of strings containing the command and msglist
* set_cursor means whether the function should set the cursor to
* the number of the last message processed. If set_cursor = 0, the
* cursor is not altered.
*/
int
util_msglist_command (function_t *func, int argc, char **argv, int set_cursor)
util_foreach_msg (int argc, char **argv, int flags,
msg_handler_t func, void *data)
{
msgset_t *list = NULL, *mp;
int status = 0;
......@@ -174,60 +165,48 @@ util_msglist_command (function_t *func, int argc, char **argv, int set_cursor)
if (msgset_parse (argc, argv, &list))
return 1;
realcursor = cursor;
for (mp = list; mp; mp = mp->next)
{
cursor = mp->msg_part[0];
/* NOTE: Should we bail on error also? */
if (func (1, argv) != 0)
message_t mesg;
if (util_get_message (mbox, mp->msg_part[0], &mesg, flags) == 0)
{
if (func (mp, mesg, data) != 0)
status = 1;
/* Bail out if we receive an interrupt. */
if (ml_got_interrupt () != 0)
break;
}
}
msgset_free (list);
if (set_cursor)
realcursor = cursor;
else
cursor = realcursor;
return status;
}
/* Same as util_msglis_command but the function comes from the escape
cmd table, so will have a different argument signature. */
int
util_msglist_esccmd (int (*escfunc)
__P ((int, char **, compose_env_t *)),
int argc, char **argv, compose_env_t *env,
int set_cursor)
util_range_msg (size_t low, size_t high, int flags,
msg_handler_t func, void *data)
{
msgset_t *list = NULL, *mp;
int status = 0;
msgset_t msgspec = { 0 };
int count = 0;
if (msgset_parse (argc, argv, &list))
return 1;
realcursor = cursor;
msgspec.next = NULL;
msgspec.npart = 0;
msgspec.msg_part = &low;
for (; low <= high; low++)
{
message_t mesg;
for (mp = list; mp; mp = mp->next)
if (util_get_message (mbox, low, &mesg, flags) == 0)
{
cursor = mp->msg_part[0];
/* NOTE: Should we bail on error also? */
if (escfunc (1, argv, env) != 0)
status = 1;
count ++;
func (&msgspec, mesg, data) ;
/* Bail out if we receive an interrupt. */
if (ml_got_interrupt () != 0)
break;
}
msgset_free (list);
if (set_cursor)
realcursor = cursor;
else
cursor = realcursor;
return status;
}
return count;
}
/*
......