1 Return-Path: <bremner@tethera.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id CF3F46DE02A6
\r
6 for <notmuch@notmuchmail.org>; Mon, 30 May 2016 04:50:36 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.001, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]
\r
14 Received: from arlo.cworth.org ([127.0.0.1])
\r
15 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id WHd6c3evKT2p for <notmuch@notmuchmail.org>;
\r
17 Mon, 30 May 2016 04:50:29 -0700 (PDT)
\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
19 by arlo.cworth.org (Postfix) with ESMTPS id D24B16DE02B0
\r
20 for <notmuch@notmuchmail.org>; Mon, 30 May 2016 04:50:13 -0700 (PDT)
\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
22 (envelope-from <bremner@tethera.net>)
\r
23 id 1b7Lhr-0000QF-20; Mon, 30 May 2016 07:50:03 -0400
\r
24 Received: (nullmailer pid 14858 invoked by uid 1000);
\r
25 Mon, 30 May 2016 11:50:06 -0000
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [RFC2 Patch 5/5] lib: iterator API for message properties
\r
29 Date: Mon, 30 May 2016 08:49:59 -0300
\r
30 Message-Id: <1464608999-14774-6-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.8.1
\r
32 In-Reply-To: <1464608999-14774-1-git-send-email-david@tethera.net>
\r
33 References: <1463927339-5441-1-git-send-email-david@tethera.net>
\r
34 <1464608999-14774-1-git-send-email-david@tethera.net>
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.20
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Mon, 30 May 2016 11:50:36 -0000
\r
49 This is a thin wrapper around the string map iterator API just introduced.
\r
51 lib/message-property.cc | 38 +++++++++++++++++++
\r
52 lib/notmuch.h | 24 ++++++++++++
\r
53 test/T610-message-property.sh | 87 +++++++++++++++++++++++++++++++++++++++++++
\r
54 3 files changed, 149 insertions(+)
\r
56 diff --git a/lib/message-property.cc b/lib/message-property.cc
\r
57 index 21348a3..d2e7d9c 100644
\r
58 --- a/lib/message-property.cc
\r
59 +++ b/lib/message-property.cc
\r
60 @@ -84,3 +84,41 @@ notmuch_message_remove_property (notmuch_message_t *message, const char *key, co
\r
62 return _notmuch_message_modify_property (message, key, value, TRUE);
\r
65 +notmuch_message_properties_t *
\r
66 +notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact)
\r
68 + notmuch_string_map_t *map;
\r
69 + map = _notmuch_message_property_map (message);
\r
70 + return _notmuch_string_map_iterator_create (map, key, exact);
\r
74 +notmuch_message_properties_valid (notmuch_message_properties_t *properties)
\r
76 + return _notmuch_string_map_iterator_valid (properties);
\r
80 +notmuch_message_properties_move_to_next (notmuch_message_properties_t *properties)
\r
82 + return _notmuch_string_map_iterator_move_to_next (properties);
\r
86 +notmuch_message_properties_key (notmuch_message_properties_t *properties)
\r
88 + return _notmuch_string_map_iterator_key (properties);
\r
92 +notmuch_message_properties_value (notmuch_message_properties_t *properties)
\r
94 + return _notmuch_string_map_iterator_value (properties);
\r
98 +notmuch_message_properties_destroy (notmuch_message_properties_t *properties)
\r
100 + _notmuch_string_map_iterator_destroy (properties);
\r
102 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
103 index c9e654e..b88f47f 100644
\r
104 --- a/lib/notmuch.h
\r
105 +++ b/lib/notmuch.h
\r
106 @@ -1665,6 +1665,30 @@ notmuch_message_add_property (notmuch_message_t *message, const char *key, const
\r
108 notmuch_message_remove_property (notmuch_message_t *message, const char *key, const char *value);
\r
110 +typedef struct _notmuch_string_map_iterator notmuch_message_properties_t;
\r
113 +notmuch_message_remove_property (notmuch_message_t *message, const char *key, const char *value);
\r
115 +notmuch_message_properties_t *
\r
116 +notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact);
\r
119 +notmuch_message_properties_valid (notmuch_message_properties_t *properties);
\r
122 +notmuch_message_properties_move_to_next (notmuch_message_properties_t *properties);
\r
125 +notmuch_message_properties_key (notmuch_message_properties_t *properties);
\r
128 +notmuch_message_properties_value (notmuch_message_properties_t *properties);
\r
131 +notmuch_message_properties_destroy (notmuch_message_properties_t *properties);
\r
135 * Is the given 'tags' iterator pointing at a valid tag.
\r
137 diff --git a/test/T610-message-property.sh b/test/T610-message-property.sh
\r
138 index 45ed66b..1617f1a 100755
\r
139 --- a/test/T610-message-property.sh
\r
140 +++ b/test/T610-message-property.sh
\r
141 @@ -89,6 +89,93 @@ testkey2 = NULL
\r
143 test_expect_equal_file EXPECTED OUTPUT
\r
145 +test_begin_subtest "notmuch_message_get_properties: empty list"
\r
146 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
148 + notmuch_message_properties_t *list;
\r
149 + list = notmuch_message_get_properties (message, "nonexistent", TRUE);
\r
150 + printf("valid = %d\n", notmuch_message_properties_valid (list));
\r
151 + notmuch_message_properties_destroy (list);
\r
154 +cat <<'EOF' >EXPECTED
\r
159 +test_expect_equal_file EXPECTED OUTPUT
\r
161 +test_begin_subtest "notmuch_message_properties: one value"
\r
162 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
164 + notmuch_message_properties_t *list;
\r
166 + for (list = notmuch_message_get_properties (message, "testkey1", TRUE);
\r
167 + notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {
\r
168 + printf("%s\n", notmuch_message_properties_value(list));
\r
170 + notmuch_message_properties_destroy (list);
\r
173 +cat <<'EOF' >EXPECTED
\r
178 +test_expect_equal_file EXPECTED OUTPUT
\r
180 +test_begin_subtest "notmuch_message_properties: multiple values"
\r
181 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
183 + notmuch_message_properties_t *list;
\r
184 + RUN(notmuch_message_add_property (message, "testkey1", "bob"));
\r
185 + RUN(notmuch_message_add_property (message, "testkey1", "testvalue2"));
\r
186 + RUN(notmuch_message_add_property (message, "testkey1", "alice"));
\r
188 + for (list = notmuch_message_get_properties (message, "testkey1", TRUE);
\r
189 + notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {
\r
190 + printf("%s\n", notmuch_message_properties_value(list));
\r
192 + notmuch_message_properties_destroy (list);
\r
195 +cat <<'EOF' >EXPECTED
\r
203 +test_expect_equal_file EXPECTED OUTPUT
\r
205 +test_begin_subtest "notmuch_message_properties: prefix"
\r
206 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
\r
208 + notmuch_message_properties_t *list;
\r
209 + RUN(notmuch_message_add_property (message, "testkey3", "bob3"));
\r
210 + RUN(notmuch_message_add_property (message, "testkey3", "testvalue3"));
\r
211 + RUN(notmuch_message_add_property (message, "testkey3", "alice3"));
\r
213 + for (list = notmuch_message_get_properties (message, "testkey", FALSE);
\r
214 + notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {
\r
215 + printf("%s\n", notmuch_message_properties_value(list));
\r
217 + notmuch_message_properties_destroy (list);
\r
220 +cat <<'EOF' >EXPECTED
\r
231 +test_expect_equal_file EXPECTED OUTPUT
\r