--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 5893F6DE1552\r
+ for <notmuch@notmuchmail.org>; Sat, 9 Jan 2016 18:52:29 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.312\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.312 tagged_above=-999 required=5 tests=[AWL=0.239,\r
+ RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id MSgeUzXrL83N for <notmuch@notmuchmail.org>;\r
+ Sat, 9 Jan 2016 18:52:26 -0800 (PST)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id CE2286DE1532\r
+ for <notmuch@notmuchmail.org>; Sat, 9 Jan 2016 18:51:59 -0800 (PST)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1aI66g-0007EF-AC; Sat, 09 Jan 2016 21:51:50 -0500\r
+Received: (nullmailer pid 29652 invoked by uid 1000);\r
+ Sun, 10 Jan 2016 02:51:47 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [WIP patch 5/9] lib: add notmuch_metadata_move_to_next\r
+Date: Sat, 9 Jan 2016 22:51:37 -0400\r
+Message-Id: <1452394301-29499-6-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.6.4\r
+In-Reply-To: <1452394301-29499-1-git-send-email-david@tethera.net>\r
+References: <1452394301-29499-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 10 Jan 2016 02:52:29 -0000\r
+\r
+---\r
+ lib/metadata.cc | 6 ++++++\r
+ lib/notmuch.h | 6 ++++++\r
+ test/T590-metadata.sh | 12 +++++++-----\r
+ 3 files changed, 19 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/lib/metadata.cc b/lib/metadata.cc\r
+index 6236992..a355b75 100644\r
+--- a/lib/metadata.cc\r
++++ b/lib/metadata.cc\r
+@@ -239,3 +239,9 @@ notmuch_metadata_value (notmuch_metadata_t *metadata)\r
+ \r
+ return val;\r
+ }\r
++\r
++void\r
++notmuch_metadata_move_to_next (notmuch_metadata_t *metadata)\r
++{\r
++ (*(metadata->iterator))++;\r
++}\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index dd359c8..b00126d 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -1879,6 +1879,12 @@ notmuch_metadata_key (notmuch_metadata_t *metadata);\r
+ const char *\r
+ notmuch_metadata_value (notmuch_metadata_t *metadata);\r
+ \r
++/**\r
++ * move 'metadata' iterator to the next pair\r
++ */\r
++void\r
++notmuch_metadata_move_to_next (notmuch_metadata_t *metadata);\r
++\r
+ /* @} */\r
+ \r
+ NOTMUCH_END_DECLS\r
+diff --git a/test/T590-metadata.sh b/test/T590-metadata.sh\r
+index d2326d4..4f37c09 100755\r
+--- a/test/T590-metadata.sh\r
++++ b/test/T590-metadata.sh\r
+@@ -55,21 +55,23 @@ testkey2 = testvalue2\r
+ EOF\r
+ test_expect_equal_file EXPECTED OUTPUT\r
+ \r
+-test_begin_subtest "notmuch_database_get_all_metadata first item"\r
++test_begin_subtest "get all metadata in one class"\r
+ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
+ {\r
+ notmuch_metadata_t *meta;\r
+ RUN(notmuch_database_get_all_metadata (db, NOTMUCH_METADATA_CONFIG, &meta));\r
+- printf("valid = %d\n", notmuch_metadata_valid (meta));\r
+- printf("key = %s\n", notmuch_metadata_key (meta));\r
+- printf("val = %s\n", notmuch_metadata_value (meta));\r
++ for (; notmuch_metadata_valid (meta); notmuch_metadata_move_to_next (meta)) {\r
++ printf("key = %s\n", notmuch_metadata_key (meta));\r
++ printf("val = %s\n", notmuch_metadata_value (meta));\r
++ }\r
+ }\r
+ EOF\r
+ cat <<'EOF' >EXPECTED\r
+ == stdout ==\r
+-valid = 1\r
+ key = testkey1\r
+ val = testvalue1\r
++key = testkey2\r
++val = testvalue2\r
+ == stderr ==\r
+ EOF\r
+ test_expect_equal_file EXPECTED OUTPUT\r
+-- \r
+2.6.4\r
+\r