This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU Mailutils".
http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=74b2971a50804a51f83bea8c49648fe9d2b344c4 The branch, master has been updated via 74b2971a50804a51f83bea8c49648fe9d2b344c4 (commit) from 561ce8ffe3472e298bfef315850fd05d818b9082 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 74b2971a50804a51f83bea8c49648fe9d2b344c4 Author: Sergey Poznyakoff <g...@gnu.org> Date: Wed Jun 15 09:20:04 2016 +0300 Gracefully handle empty mailboxes in mu_msgset_parse_imap * libmailutils/msgset/parse.c (MU_MSGSET_EMPTY): New constant. (parse_msgrange): Don't add any ranges if mode is set to MU_MSGSET_EMPTY. (mu_msgset_parse_imap): Force MU_MSGSET_EMPTY mode if the mailbox is empty. * libmailutils/msgset/print.c (mu_msgset_print): Handle empty message sets. * libmailutils/msgset/trans.c (_mu_msgset_translate_pair): Initialize variable. * libmailutils/tests/Makefile.am (msgset_LDADD): New variable. * libmailutils/tests/msgset.c (parse_msgset): Take mailbox as first argument. (main): New option -mailbox ----------------------------------------------------------------------- Summary of changes: libmailutils/msgset/parse.c | 13 +++++++++++-- libmailutils/msgset/print.c | 2 +- libmailutils/msgset/trans.c | 2 +- libmailutils/tests/Makefile.am | 6 ++++++ libmailutils/tests/msgset.c | 21 ++++++++++++++------- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/libmailutils/msgset/parse.c b/libmailutils/msgset/parse.c index e7ff907..a56c5a3 100644 --- a/libmailutils/msgset/parse.c +++ b/libmailutils/msgset/parse.c @@ -26,6 +26,9 @@ #include <mailutils/msgset.h> #include <mailutils/sys/msgset.h> +/* Special translation mode, indicating that the mailbox is empty */ +#define MU_MSGSET_EMPTY -1 + /* This structure keeps parser state while parsing message set. */ struct parse_msgnum_env { @@ -33,7 +36,7 @@ struct parse_msgnum_env size_t minval; /* Min. sequence number or UID */ size_t maxval; /* Max. sequence number or UID */ mu_msgset_t msgset; /* Message set being built. */ - int mode; /* Operation mode (num/uid) */ + int mode; /* Operation mode (num/uid/dry_run) */ }; /* Get a single message number/UID from env->s and store it into *PN. @@ -96,6 +99,8 @@ parse_msgrange (struct parse_msgnum_env *env) msgrange.msg_beg = tmp; } + if (env->mode == MU_MSGSET_EMPTY) + return 0; return mu_msgset_add_range (env->msgset, msgrange.msg_beg, msgrange.msg_end, env->mode); } @@ -131,7 +136,11 @@ mu_msgset_parse_imap (mu_msgset_t mset, int mode, const char *s, char **end) rc = mu_mailbox_messages_count (mset->mbox, &lastmsgno); if (rc == 0) { - if (mode == MU_MSGSET_UID) + if (lastmsgno == 0) + { + env.mode = MU_MSGSET_EMPTY; + } + else if (mode == MU_MSGSET_UID) { rc = mu_mailbox_translate (mset->mbox, MU_MAILBOX_MSGNO_TO_UID, lastmsgno, &env.maxval); diff --git a/libmailutils/msgset/print.c b/libmailutils/msgset/print.c index 090e0f2..3654ae2 100644 --- a/libmailutils/msgset/print.c +++ b/libmailutils/msgset/print.c @@ -64,7 +64,7 @@ mu_msgset_print (mu_stream_t str, mu_msgset_t mset) int rc; if (mu_list_is_empty (mset->list)) - return MU_ERR_NOENT; + return mu_stream_printf (str, "%s", "nil"); rc = mu_msgset_aggregate (mset); if (rc) return rc; diff --git a/libmailutils/msgset/trans.c b/libmailutils/msgset/trans.c index 8bb929d..77da69c 100644 --- a/libmailutils/msgset/trans.c +++ b/libmailutils/msgset/trans.c @@ -30,7 +30,7 @@ _mu_msgset_translate_pair (mu_msgset_t mset, int mode, if (mode != _MU_MSGSET_MODE (mset->flags) && mset->mbox) { int cmd, rc; - size_t n; + size_t n = 1; size_t beg = *pbeg; size_t end = *pend; diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am index 699d496..63049b8 100644 --- a/libmailutils/tests/Makefile.am +++ b/libmailutils/tests/Makefile.am @@ -69,6 +69,12 @@ noinst_PROGRAMS = \ LDADD = ${MU_LIB_MAILUTILS} +msgset_LDADD = \ + ${MU_LIB_MBOX}\ + ${MU_LIB_MH}\ + ${MU_LIB_MAILDIR}\ + ${MU_LIB_MAILUTILS} + EXTRA_DIST += Encode Decode Wicketfile ## ------------ ## diff --git a/libmailutils/tests/msgset.c b/libmailutils/tests/msgset.c index c93c07a..f91e139 100644 --- a/libmailutils/tests/msgset.c +++ b/libmailutils/tests/msgset.c @@ -53,16 +53,16 @@ parse_msgrange (char *arg, struct mu_msgrange *range) } mu_msgset_t -parse_msgset (const char *arg) +parse_msgset (mu_mailbox_t mbox, const char *arg) { int rc; mu_msgset_t msgset; char *end; - MU_ASSERT (mu_msgset_create (&msgset, NULL, MU_MSGSET_NUM)); + MU_ASSERT (mu_msgset_create (&msgset, mbox, MU_MSGSET_NUM)); if (arg) { - rc = mu_msgset_parse_imap (msgset, MU_MSGSET_NUM, arg, &end); + rc = mu_msgset_parse_imap (msgset, MU_MSGSET_UID, arg, &end); if (rc) { mu_error ("mu_msgset_parse_imap: %s near %s", @@ -79,26 +79,33 @@ main (int argc, char **argv) int i; char *msgset_string = NULL; mu_msgset_t msgset; + mu_mailbox_t mbox = NULL; mu_set_program_name (argv[0]); + mu_register_local_mbox_formats (); for (i = 1; i < argc; i++) { char *arg = argv[i]; if (strcmp (arg, "-h") == 0 || strcmp (arg, "-help") == 0) { - mu_printf ("usage: %s [-msgset=SET] [-add=X[:Y]] [-del=X[:Y]] " + mu_printf ("usage: %s [-mailbox=PATH] [-msgset=SET] [-add=X[:Y]] [-del=X[:Y]] " "[-addset=SET] [-delset=SET] ...\n", mu_program_name); return 0; } else if (strncmp (arg, "-msgset=", 8) == 0) msgset_string = arg + 8; + else if (strncmp (arg, "-mailbox=", 9) == 0) + { + MU_ASSERT (mu_mailbox_create_default (&mbox, arg + 9)); + MU_ASSERT (mu_mailbox_open (mbox, MU_STREAM_READ)); + } else break; } - msgset = parse_msgset (msgset_string); + msgset = parse_msgset (mbox, msgset_string); for (; i < argc; i++) { @@ -119,7 +126,7 @@ main (int argc, char **argv) } else if (strncmp (arg, "-addset=", 8) == 0) { - mu_msgset_t tset = parse_msgset (arg + 8); + mu_msgset_t tset = parse_msgset (mbox, arg + 8); if (!msgset) msgset = tset; else @@ -130,7 +137,7 @@ main (int argc, char **argv) } else if (strncmp (arg, "-subset=", 8) == 0) { - mu_msgset_t tset = parse_msgset (arg + 8); + mu_msgset_t tset = parse_msgset (mbox, arg + 8); if (!msgset) { mu_error ("no initial message set"); hooks/post-receive -- GNU Mailutils _______________________________________________ Commit-mailutils mailing list Commit-mailutils@gnu.org https://lists.gnu.org/mailman/listinfo/commit-mailutils