summaryrefslogtreecommitdiff
path: root/mail
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2002-12-29 13:36:35 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2002-12-29 13:36:35 +0000
commit7d40862926661727a43b70ac8db876bf42b3d0ca (patch)
treedd0ec2e6259aea56b1437bef893f3b2896b2b9e7 /mail
parent450bb3283ddfe3aa5021147ba0d2bb33251d43e1 (diff)
downloadmailutils-7d40862926661727a43b70ac8db876bf42b3d0ca.tar.gz
mailutils-7d40862926661727a43b70ac8db876bf42b3d0ca.tar.bz2
(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.
Diffstat (limited to 'mail')
-rw-r--r--mail/mail.h15
-rw-r--r--mail/util.c85
2 files changed, 41 insertions, 59 deletions
diff --git a/mail/mail.h b/mail/mail.h
index cfaa5148d..8a8bf2d23 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -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));
diff --git a/mail/util.c b/mail/util.c
index 303656bfe..05087a642 100644
--- a/mail/util.c
+++ b/mail/util.c
@@ -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)
- status = 1;
- /* Bail out if we receive an interrupt. */
- if (ml_got_interrupt () != 0)
- break;
+ 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;
-
- if (msgset_parse (argc, argv, &list))
- return 1;
-
- realcursor = cursor;
-
- for (mp = list; mp; mp = mp->next)
+ msgset_t msgspec = { 0 };
+ int count = 0;
+
+ msgspec.next = NULL;
+ msgspec.npart = 0;
+ msgspec.msg_part = &low;
+ for (; low <= high; low++)
{
- cursor = mp->msg_part[0];
- /* NOTE: Should we bail on error also? */
- if (escfunc (1, argv, env) != 0)
- status = 1;
- /* Bail out if we receive an interrupt. */
- if (ml_got_interrupt () != 0)
- break;
+ message_t mesg;
+
+ if (util_get_message (mbox, low, &mesg, flags) == 0)
+ {
+ 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;
}
/*

Return to:

Send suggestions and report system problems to the System administrator.