diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-12-30 19:52:49 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-12-30 20:17:31 +0200 |
commit | a01bb419262e90164a558075e3607fb3b0514443 (patch) | |
tree | 6b034965e51fba477b15d5098a598ee7cfc5e9be /testsuite | |
parent | 26cfa2197d5a2866f1a08c48f94d65504fdef7b1 (diff) | |
download | mailutils-a01bb419262e90164a558075e3607fb3b0514443.tar.gz mailutils-a01bb419262e90164a558075e3607fb3b0514443.tar.bz2 |
Improve msgset interface. Use it in MH.
* libmailutils/msgset/Makefile.am (libmsgset_la_SOURCES): Add new files.
* libmailutils/msgset/addset.c: New file.
* libmailutils/msgset/count.c: New file.
* libmailutils/msgset/foreachmsgno.c: New file.
* libmailutils/msgset/foreachuid.c: New file.
* libmailutils/msgset/isempty.c: New file.
* libmailutils/msgset/subset.c: New file.
* libmailutils/msgset/trans.c: New file.
* libmailutils/msgset/add.c (mu_msgset_add_range): Take fourth argument
specifying the conversion mode. Translate numbers as necessary.
* libmailutils/msgset/foreachmsg.c: Translate numbers as necessary.
* libmailutils/msgset/foreachnum.c: Rewrite.
* libmailutils/msgset/negate.c (_invert_range)
(mu_msgset_add_range): Update calls to mu_msgset_add_range.
* libmailutils/msgset/parse.c (parse_msgnum_env)<mode>: New member.
(parse_msgrange): Update calls to mu_msgset_add_range.
(mu_msgset_parse_imap): Change signature. All callers updated.
* libmailutils/msgset/sub.c (mu_msgset_sub_range): Take fourth argument
specifying the conversion mode. Translate numbers as necessary.
* imap4d/copy.c (imap4d_copy0): Update calls to mu_msgset_create
and mu_msgset_parse_imap.
* imap4d/fetch.c (fetch_thunk): Likewise.
* imap4d/search.c (parse_simple_key): Likewise.
* imap4d/store.c (store_thunk): Likewise.
* include/mailutils/msgset.h (MU_MSGSET_NUM,MU_MSGSET_UID): New defines.
(mu_msgset_add,mu_msgset_sub): New protos.
(mu_msgset_add_range,mu_msgset_sub_range): Take 4 arguments. All callers
changed.
* include/mailutils/sys/msgset.h (_mu_msgset_translate_pair)
(_mu_msgset_translate_range): New protos.
* libmailutils/tests/msgset.c: Reflect the above changes.
* testsuite/msgset.c: Likewise.
* libproto/imap/mbox.c: Update calls to mu_msgset functions.
* mh/mh.h (mh_msgset_t): Remove.
(mh_iterator_fp): Remove typedef.
(mh_msgset_parse): Change signature.
(mh_msgset_member,mh_msgset_reverse,mh_msgset_negate)
(mh_msgset_current,mh_msgset_free,mh_msgset_uids): Remove protos.
(mh_msgset_parse_string): New proto.
(mh_msgset_first_current,mh_msgset_first): New proto.
(mh_iterate: Remove proto. Use mu_msgset_foreach* functions instead.
(mh_seq_add,mh_seq_delete): Change signatures.
* mh/mh_init.c (mh_iterate): Remove.
* mh/mh_msgset.c: Rewrite using mu_msgset_t.
* mh/mh_sequence.c: Likewise.
* mh/anno.c: Use new msgset functions.
* mh/burst.c: Likewise.
* mh/comp.c: Likewise.
* mh/folder.c: Likewise.
* mh/forw.c: Likewise.
* mh/mark.c: Likewise.
* mh/mhn.c: Likewise.
* mh/mhpath.c: Likewise.
* mh/mhseq.c: Likewise.
* mh/pick.c: Likewise.
* mh/refile.c: Likewise.
* mh/repl.c: Likewise.
* mh/rmm.c: Likewise.
* mh/scan.c: Likewise.
* mh/send.c: Likewise.
* mh/sortm.c: Likewise.
* mh/whatnowenv.c: Likewise.
* mh/tests/mark.at: Reflect changes in the format of the saved
sequences, which may contain ranges now.
* mu/imap.c: Update calls to mu_msgset functions.
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/msgset.c | 148 |
1 files changed, 124 insertions, 24 deletions
diff --git a/testsuite/msgset.c b/testsuite/msgset.c index 9e6f53288..8ddc2b138 100644 --- a/testsuite/msgset.c +++ b/testsuite/msgset.c @@ -19,7 +19,7 @@ #include <mailutils/mailutils.h> static void -parse_msgset (char *arg, struct mu_msgrange *range) +parse_msgrange (char *arg, struct mu_msgrange *range) { size_t msgnum; char *p; @@ -52,14 +52,36 @@ parse_msgset (char *arg, struct mu_msgrange *range) range->msg_end = msgnum; } +mu_msgset_t +parse_msgset (const char *arg, mu_mailbox_t mbox, + int create_mode, int parse_mode) +{ + int rc; + mu_msgset_t msgset; + char *end; + + MU_ASSERT (mu_msgset_create (&msgset, mbox, create_mode)); + if (arg) + { + rc = mu_msgset_parse_imap (msgset, parse_mode, arg, &end); + if (rc) + { + mu_error ("mu_msgset_parse_imap: %s near %s", + mu_strerror (rc), end); + exit (1); + } + } + return msgset; +} + int main (int argc, char **argv) { int i; char *msgset_string = NULL; mu_msgset_t msgset; - int rc; - int flags = 0; + int create_mode = MU_MSGSET_NUM; + int parse_mode = MU_MSGSET_NUM; mu_mailbox_t mbox = NULL; mu_set_program_name (argv[0]); @@ -70,14 +92,23 @@ main (int argc, char **argv) if (strcmp (arg, "-h") == 0 || strcmp (arg, "-help") == 0) { - mu_printf ("usage: %s [-msgset=SET] [-add X[:Y]] [-del X:[Y]]...\n", + mu_printf ("usage: %s [-msgset[uid]=SET] [-uid] [-add[uid]=X[:Y]] [-del[uid]=X[:Y]] " + "[-addset[uid]=SET] [-delset[uid]=SET] ...\n", mu_program_name); return 0; } else if (strncmp (arg, "-msgset=", 8) == 0) - msgset_string = arg + 8; + { + parse_mode = MU_MSGSET_NUM; + msgset_string = arg + 8; + } + else if (strncmp (arg, "-msgsetuid=", 11) == 0) + { + parse_mode = MU_MSGSET_UID; + msgset_string = arg + 11; + } else if (strcmp (arg, "-uid") == 0) - flags |= MU_MSGSET_UID; + create_mode = MU_MSGSET_UID; else if (strncmp (arg, "-mailbox=", 9) == 0) { MU_ASSERT (mu_mailbox_create (&mbox, arg + 9)); @@ -87,18 +118,7 @@ main (int argc, char **argv) break; } - MU_ASSERT (mu_msgset_create (&msgset, mbox, flags)); - if (msgset_string) - { - char *end; - rc = mu_msgset_parse_imap (msgset, msgset_string, &end); - if (rc) - { - mu_error ("mu_msgset_parse_imap: %s near %s", - mu_strerror (rc), end); - return 1; - } - } + msgset = parse_msgset (msgset_string, mbox, create_mode, parse_mode); for (; i < argc; i++) { @@ -107,15 +127,95 @@ main (int argc, char **argv) if (strncmp (arg, "-add=", 5) == 0) { - parse_msgset (arg + 5, &range); - MU_ASSERT (mu_msgset_add_range (msgset, range.msg_beg, - range.msg_end)); + parse_msgrange (arg + 5, &range); + MU_ASSERT (mu_msgset_add_range (msgset, + range.msg_beg, range.msg_end, + MU_MSGSET_NUM)); } else if (strncmp (arg, "-sub=", 5) == 0) { - parse_msgset (arg + 5, &range); - MU_ASSERT (mu_msgset_sub_range (msgset, range.msg_beg, - range.msg_end)); + parse_msgrange (arg + 5, &range); + MU_ASSERT (mu_msgset_sub_range (msgset, + range.msg_beg, range.msg_end, + MU_MSGSET_NUM)); + } + else if (strncmp (arg, "-adduid=", 8) == 0) + { + parse_msgrange (arg + 8, &range); + MU_ASSERT (mu_msgset_add_range (msgset, + range.msg_beg, range.msg_end, + MU_MSGSET_UID)); + } + else if (strncmp (arg, "-subuid=", 8) == 0) + { + parse_msgrange (arg + 8, &range); + MU_ASSERT (mu_msgset_sub_range (msgset, + range.msg_beg, range.msg_end, + MU_MSGSET_UID)); + } + else if (strncmp (arg, "-addset", 7) == 0) + { + mu_msgset_t tset; + int m; + + arg += 7; + if (strncmp (arg, "uid", 3) == 0) + { + m = MU_MSGSET_UID; + arg += 3; + } + else + m = MU_MSGSET_NUM; + if (*arg == '=') + arg++; + else + { + mu_error ("unknown option %s", argv[i]); + return 1; + } + + tset = parse_msgset (arg, mbox, m, m); + if (!msgset) + msgset = tset; + else + { + MU_ASSERT (mu_msgset_add (msgset, tset)); + mu_msgset_free (tset); + } + } + else if (strncmp (arg, "-subset=", 8) == 0) + { + mu_msgset_t tset; + int m; + + arg += 7; + if (strncmp (arg, "uid", 3) == 0) + { + m = MU_MSGSET_UID; + arg += 3; + } + else + m = MU_MSGSET_NUM; + if (*arg == '=') + arg++; + else + { + mu_error ("unknown option %s", argv[i]); + return 1; + } + + tset = parse_msgset (arg, mbox, m, m); + + if (!msgset) + { + mu_error ("no initial message set"); + exit (1); + } + else + { + MU_ASSERT (mu_msgset_sub (msgset, tset)); + mu_msgset_free (tset); + } } else if (strcmp (arg, "-neg") == 0) { |