[RFC2 Patch 5/5] lib: iterator API for message properties
authorDavid Bremner <david@tethera.net>
Mon, 30 May 2016 11:49:59 +0000 (08:49 +2100)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 23:21:55 +0000 (16:21 -0700)
67/c1255a3b19774fadc656cbeca4b60f7935cd89 [new file with mode: 0644]

diff --git a/67/c1255a3b19774fadc656cbeca4b60f7935cd89 b/67/c1255a3b19774fadc656cbeca4b60f7935cd89
new file mode 100644 (file)
index 0000000..109aa83
--- /dev/null
@@ -0,0 +1,237 @@
+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 CF3F46DE02A6\r
+ for <notmuch@notmuchmail.org>; Mon, 30 May 2016 04:50:36 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.012\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5\r
+ tests=[AWL=-0.001, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
+ 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 WHd6c3evKT2p for <notmuch@notmuchmail.org>;\r
+ Mon, 30 May 2016 04:50:29 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id D24B16DE02B0\r
+ for <notmuch@notmuchmail.org>; Mon, 30 May 2016 04:50:13 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1b7Lhr-0000QF-20; Mon, 30 May 2016 07:50:03 -0400\r
+Received: (nullmailer pid 14858 invoked by uid 1000);\r
+ Mon, 30 May 2016 11:50:06 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC2 Patch 5/5] lib: iterator API for message properties\r
+Date: Mon, 30 May 2016 08:49:59 -0300\r
+Message-Id: <1464608999-14774-6-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.8.1\r
+In-Reply-To: <1464608999-14774-1-git-send-email-david@tethera.net>\r
+References: <1463927339-5441-1-git-send-email-david@tethera.net>\r
+ <1464608999-14774-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: Mon, 30 May 2016 11:50:36 -0000\r
+\r
+This is a thin wrapper around the string map iterator API just introduced.\r
+---\r
+ lib/message-property.cc       | 38 +++++++++++++++++++\r
+ lib/notmuch.h                 | 24 ++++++++++++\r
+ test/T610-message-property.sh | 87 +++++++++++++++++++++++++++++++++++++++++++\r
+ 3 files changed, 149 insertions(+)\r
+\r
+diff --git a/lib/message-property.cc b/lib/message-property.cc\r
+index 21348a3..d2e7d9c 100644\r
+--- a/lib/message-property.cc\r
++++ b/lib/message-property.cc\r
+@@ -84,3 +84,41 @@ notmuch_message_remove_property (notmuch_message_t *message, const char *key, co\r
+ {\r
+     return _notmuch_message_modify_property (message, key, value, TRUE);\r
+ }\r
++\r
++notmuch_message_properties_t *\r
++notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact)\r
++{\r
++    notmuch_string_map_t *map;\r
++    map = _notmuch_message_property_map (message);\r
++    return _notmuch_string_map_iterator_create (map, key, exact);\r
++}\r
++\r
++notmuch_bool_t\r
++notmuch_message_properties_valid (notmuch_message_properties_t *properties)\r
++{\r
++    return _notmuch_string_map_iterator_valid (properties);\r
++}\r
++\r
++void\r
++notmuch_message_properties_move_to_next (notmuch_message_properties_t *properties)\r
++{\r
++    return _notmuch_string_map_iterator_move_to_next (properties);\r
++}\r
++\r
++const char *\r
++notmuch_message_properties_key (notmuch_message_properties_t *properties)\r
++{\r
++    return _notmuch_string_map_iterator_key (properties);\r
++}\r
++\r
++const char *\r
++notmuch_message_properties_value (notmuch_message_properties_t *properties)\r
++{\r
++    return _notmuch_string_map_iterator_value (properties);\r
++}\r
++\r
++void\r
++notmuch_message_properties_destroy (notmuch_message_properties_t *properties)\r
++{\r
++    _notmuch_string_map_iterator_destroy (properties);\r
++}\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index c9e654e..b88f47f 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -1665,6 +1665,30 @@ notmuch_message_add_property (notmuch_message_t *message, const char *key, const\r
+ notmuch_status_t\r
+ notmuch_message_remove_property (notmuch_message_t *message, const char *key, const char *value);\r
\r
++typedef struct _notmuch_string_map_iterator notmuch_message_properties_t;\r
++\r
++notmuch_status_t\r
++notmuch_message_remove_property (notmuch_message_t *message, const char *key, const char *value);\r
++\r
++notmuch_message_properties_t *\r
++notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact);\r
++\r
++notmuch_bool_t\r
++notmuch_message_properties_valid (notmuch_message_properties_t *properties);\r
++\r
++void\r
++notmuch_message_properties_move_to_next (notmuch_message_properties_t *properties);\r
++\r
++const char *\r
++notmuch_message_properties_key (notmuch_message_properties_t *properties);\r
++\r
++const char *\r
++notmuch_message_properties_value (notmuch_message_properties_t *properties);\r
++\r
++void\r
++notmuch_message_properties_destroy (notmuch_message_properties_t *properties);\r
++\r
++\r
+ /**\r
+  * Is the given 'tags' iterator pointing at a valid tag.\r
+  *\r
+diff --git a/test/T610-message-property.sh b/test/T610-message-property.sh\r
+index 45ed66b..1617f1a 100755\r
+--- a/test/T610-message-property.sh\r
++++ b/test/T610-message-property.sh\r
+@@ -89,6 +89,93 @@ testkey2 = NULL\r
+ EOF\r
+ test_expect_equal_file EXPECTED OUTPUT\r
\r
++test_begin_subtest "notmuch_message_get_properties: empty list"\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
++{\r
++   notmuch_message_properties_t *list;\r
++   list = notmuch_message_get_properties (message, "nonexistent", TRUE);\r
++   printf("valid = %d\n", notmuch_message_properties_valid (list));\r
++   notmuch_message_properties_destroy (list);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++valid = 0\r
++== stderr ==\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_begin_subtest "notmuch_message_properties: one value"\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
++{\r
++   notmuch_message_properties_t *list;\r
++\r
++   for (list = notmuch_message_get_properties (message, "testkey1", TRUE);\r
++        notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {\r
++      printf("%s\n", notmuch_message_properties_value(list));\r
++   }\r
++   notmuch_message_properties_destroy (list);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++testvalue1\r
++== stderr ==\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_begin_subtest "notmuch_message_properties: multiple values"\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
++{\r
++   notmuch_message_properties_t *list;\r
++   RUN(notmuch_message_add_property (message, "testkey1", "bob"));\r
++   RUN(notmuch_message_add_property (message, "testkey1", "testvalue2"));\r
++   RUN(notmuch_message_add_property (message, "testkey1", "alice"));\r
++\r
++   for (list = notmuch_message_get_properties (message, "testkey1", TRUE);\r
++        notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {\r
++      printf("%s\n", notmuch_message_properties_value(list));\r
++   }\r
++   notmuch_message_properties_destroy (list);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++alice\r
++bob\r
++testvalue1\r
++testvalue2\r
++== stderr ==\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
++test_begin_subtest "notmuch_message_properties: prefix"\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
++{\r
++   notmuch_message_properties_t *list;\r
++   RUN(notmuch_message_add_property (message, "testkey3", "bob3"));\r
++   RUN(notmuch_message_add_property (message, "testkey3", "testvalue3"));\r
++   RUN(notmuch_message_add_property (message, "testkey3", "alice3"));\r
++\r
++   for (list = notmuch_message_get_properties (message, "testkey", FALSE);\r
++        notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {\r
++      printf("%s\n", notmuch_message_properties_value(list));\r
++   }\r
++   notmuch_message_properties_destroy (list);\r
++}\r
++EOF\r
++cat <<'EOF' >EXPECTED\r
++== stdout ==\r
++alice\r
++bob\r
++testvalue1\r
++testvalue2\r
++alice3\r
++bob3\r
++testvalue3\r
++== stderr ==\r
++EOF\r
++test_expect_equal_file EXPECTED OUTPUT\r
\r
\r
+ test_done\r
+-- \r
+2.8.1\r
+\r