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