[RFC2 Patch 5/5] lib: iterator API for message properties
[notmuch-archives.git] / 67 / c1255a3b19774fadc656cbeca4b60f7935cd89
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.012\r
10 X-Spam-Level: \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
13  autolearn=disabled\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
37 Precedence: list\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
48 \r
49 This is a thin wrapper around the string map iterator API just introduced.\r
50 ---\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
55 \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
61  {\r
62      return _notmuch_message_modify_property (message, key, value, TRUE);\r
63  }\r
64 +\r
65 +notmuch_message_properties_t *\r
66 +notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact)\r
67 +{\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
71 +}\r
72 +\r
73 +notmuch_bool_t\r
74 +notmuch_message_properties_valid (notmuch_message_properties_t *properties)\r
75 +{\r
76 +    return _notmuch_string_map_iterator_valid (properties);\r
77 +}\r
78 +\r
79 +void\r
80 +notmuch_message_properties_move_to_next (notmuch_message_properties_t *properties)\r
81 +{\r
82 +    return _notmuch_string_map_iterator_move_to_next (properties);\r
83 +}\r
84 +\r
85 +const char *\r
86 +notmuch_message_properties_key (notmuch_message_properties_t *properties)\r
87 +{\r
88 +    return _notmuch_string_map_iterator_key (properties);\r
89 +}\r
90 +\r
91 +const char *\r
92 +notmuch_message_properties_value (notmuch_message_properties_t *properties)\r
93 +{\r
94 +    return _notmuch_string_map_iterator_value (properties);\r
95 +}\r
96 +\r
97 +void\r
98 +notmuch_message_properties_destroy (notmuch_message_properties_t *properties)\r
99 +{\r
100 +    _notmuch_string_map_iterator_destroy (properties);\r
101 +}\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
107  notmuch_status_t\r
108  notmuch_message_remove_property (notmuch_message_t *message, const char *key, const char *value);\r
109  \r
110 +typedef struct _notmuch_string_map_iterator notmuch_message_properties_t;\r
111 +\r
112 +notmuch_status_t\r
113 +notmuch_message_remove_property (notmuch_message_t *message, const char *key, const char *value);\r
114 +\r
115 +notmuch_message_properties_t *\r
116 +notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact);\r
117 +\r
118 +notmuch_bool_t\r
119 +notmuch_message_properties_valid (notmuch_message_properties_t *properties);\r
120 +\r
121 +void\r
122 +notmuch_message_properties_move_to_next (notmuch_message_properties_t *properties);\r
123 +\r
124 +const char *\r
125 +notmuch_message_properties_key (notmuch_message_properties_t *properties);\r
126 +\r
127 +const char *\r
128 +notmuch_message_properties_value (notmuch_message_properties_t *properties);\r
129 +\r
130 +void\r
131 +notmuch_message_properties_destroy (notmuch_message_properties_t *properties);\r
132 +\r
133 +\r
134  /**\r
135   * Is the given 'tags' iterator pointing at a valid tag.\r
136   *\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
142  EOF\r
143  test_expect_equal_file EXPECTED OUTPUT\r
144  \r
145 +test_begin_subtest "notmuch_message_get_properties: empty list"\r
146 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
147 +{\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
152 +}\r
153 +EOF\r
154 +cat <<'EOF' >EXPECTED\r
155 +== stdout ==\r
156 +valid = 0\r
157 +== stderr ==\r
158 +EOF\r
159 +test_expect_equal_file EXPECTED OUTPUT\r
160 +\r
161 +test_begin_subtest "notmuch_message_properties: one value"\r
162 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
163 +{\r
164 +   notmuch_message_properties_t *list;\r
165 +\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
169 +   }\r
170 +   notmuch_message_properties_destroy (list);\r
171 +}\r
172 +EOF\r
173 +cat <<'EOF' >EXPECTED\r
174 +== stdout ==\r
175 +testvalue1\r
176 +== stderr ==\r
177 +EOF\r
178 +test_expect_equal_file EXPECTED OUTPUT\r
179 +\r
180 +test_begin_subtest "notmuch_message_properties: multiple values"\r
181 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
182 +{\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
187 +\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
191 +   }\r
192 +   notmuch_message_properties_destroy (list);\r
193 +}\r
194 +EOF\r
195 +cat <<'EOF' >EXPECTED\r
196 +== stdout ==\r
197 +alice\r
198 +bob\r
199 +testvalue1\r
200 +testvalue2\r
201 +== stderr ==\r
202 +EOF\r
203 +test_expect_equal_file EXPECTED OUTPUT\r
204 +\r
205 +test_begin_subtest "notmuch_message_properties: prefix"\r
206 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
207 +{\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
212 +\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
216 +   }\r
217 +   notmuch_message_properties_destroy (list);\r
218 +}\r
219 +EOF\r
220 +cat <<'EOF' >EXPECTED\r
221 +== stdout ==\r
222 +alice\r
223 +bob\r
224 +testvalue1\r
225 +testvalue2\r
226 +alice3\r
227 +bob3\r
228 +testvalue3\r
229 +== stderr ==\r
230 +EOF\r
231 +test_expect_equal_file EXPECTED OUTPUT\r
232  \r
233  \r
234  test_done\r
235 -- \r
236 2.8.1\r
237 \r