[PATCH] configure: add --without-api-docs option
[notmuch-archives.git] / 57 / 19316d1a2a7787e96e7af1cf00c3fa5b67c622
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 CE3D16DE0946\r
6  for <notmuch@notmuchmail.org>; Sun, 12 Jun 2016 18:06:47 -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.011\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.011 tagged_above=-999 required=5\r
12  tests=[AWL=-0.000, 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 LPkA8tm9Q8yb for <notmuch@notmuchmail.org>;\r
17  Sun, 12 Jun 2016 18:06:40 -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 9E8B16DE02DB\r
20  for <notmuch@notmuchmail.org>; Sun, 12 Jun 2016 18:06:14 -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 1bCGKG-0003xs-H7; Sun, 12 Jun 2016 21:06:00 -0400\r
24 Received: (nullmailer pid 5682 invoked by uid 1000);\r
25  Mon, 13 Jun 2016 01:06:04 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH 8/8] cli: optionally restore message properties from dump file\r
29 Date: Sun, 12 Jun 2016 22:05:55 -0300\r
30 Message-Id: <1465779955-5539-9-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.8.1\r
32 In-Reply-To: <1465779955-5539-1-git-send-email-david@tethera.net>\r
33 References: <1465779955-5539-1-git-send-email-david@tethera.net>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.20\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38  <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
40  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
45  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Mon, 13 Jun 2016 01:06:47 -0000\r
47 \r
48 This somewhat mimics the config line parsing, except there can be\r
49 arbitrarily many key value pairs, so one more level of looping is\r
50 required.\r
51 ---\r
52  doc/man1/notmuch-restore.rst  | 13 +++++--\r
53  notmuch-restore.c             | 83 +++++++++++++++++++++++++++++++++++++++++--\r
54  test/T610-message-property.sh | 28 +++++++++++++++\r
55  3 files changed, 119 insertions(+), 5 deletions(-)\r
56 \r
57 diff --git a/doc/man1/notmuch-restore.rst b/doc/man1/notmuch-restore.rst\r
58 index 87fa22e..a0c1b3c 100644\r
59 --- a/doc/man1/notmuch-restore.rst\r
60 +++ b/doc/man1/notmuch-restore.rst\r
61 @@ -50,7 +50,7 @@ Supported options for **restore** include\r
62              format, this heuristic, based the fact that batch-tag format\r
63              contains no parentheses, should be accurate.\r
64  \r
65 -    ``--include=(config|tags)``\r
66 +    ``--include=(config|properties|tags)``\r
67  \r
68        Control what kind of metadata is restored.\r
69  \r
70 @@ -60,13 +60,20 @@ Supported options for **restore** include\r
71           with "#@ ", followed by a space seperated key-value pair.\r
72           Both key and value are hex encoded if needed.\r
73  \r
74 +       **properties**\r
75 +\r
76 +         Output per-message (key,value) metadata.  Each line starts\r
77 +         with "#= ", followed by a message id, and a space seperated\r
78 +         list of key=value pairs.  pair.  Ids, keys and values are\r
79 +         hex encoded if needed.\r
80 +\r
81         **tags**\r
82  \r
83           Output per-message metadata, namely tags. See *format* above\r
84           for more details.\r
85  \r
86 -      The default is to restore both tags and configuration\r
87 -      information\r
88 +      The default is to restore all available types of data.  The\r
89 +      option can be specified multiple times to select some subset.\r
90  \r
91      ``--input=``\ <filename>\r
92          Read input from given file instead of stdin.\r
93 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
94 index 371237c..d2ada61 100644\r
95 --- a/notmuch-restore.c\r
96 +++ b/notmuch-restore.c\r
97 @@ -57,6 +57,72 @@ process_config_line (notmuch_database_t *notmuch, const char* line)\r
98      return ret;\r
99  }\r
100  \r
101 +static int\r
102 +process_properties_line (notmuch_database_t *notmuch, const char* line)\r
103 +\r
104 +{\r
105 +    const char *id_p, *tok;\r
106 +    size_t id_len = 0, tok_len = 0;\r
107 +    char *id;\r
108 +\r
109 +    notmuch_message_t *message = NULL;\r
110 +    const char *delim = " \t\n";\r
111 +    int ret = EXIT_FAILURE;\r
112 +\r
113 +    void *local = talloc_new(NULL);\r
114 +\r
115 +    id_p = strtok_len_c (line, delim, &id_len);\r
116 +    id = talloc_strndup (local, id_p, id_len);\r
117 +    if (hex_decode_inplace (id) != HEX_SUCCESS) {\r
118 +       fprintf (stderr, "hex decoding failure on line %s\n", line);\r
119 +       goto DONE;\r
120 +    }\r
121 +\r
122 +    if (print_status_database ("notmuch restore", notmuch,\r
123 +                              notmuch_database_find_message (notmuch, id, &message)))\r
124 +       goto DONE;\r
125 +\r
126 +    if (print_status_database ("notmuch restore", notmuch,\r
127 +                              notmuch_message_remove_all_properties (message)))\r
128 +       goto DONE;\r
129 +\r
130 +    tok = id_p + id_len;\r
131 +\r
132 +    while ((tok = strtok_len_c (tok + tok_len, delim, &tok_len)) != NULL) {\r
133 +       char *key, *value;\r
134 +       size_t off = strcspn (tok, "=");\r
135 +       if (off > tok_len) {\r
136 +           fprintf (stderr, "unparsable token %s\n", tok);\r
137 +           goto DONE;\r
138 +       }\r
139 +\r
140 +       key = talloc_strndup (local, tok, off);\r
141 +       value = talloc_strndup (local, tok+off+1, tok_len - off - 1);\r
142 +\r
143 +       if (hex_decode_inplace (key) != HEX_SUCCESS) {\r
144 +           fprintf (stderr, "hex decoding failure on key %s\n", key);\r
145 +           goto DONE;\r
146 +       }\r
147 +\r
148 +       if (hex_decode_inplace (value) != HEX_SUCCESS) {\r
149 +           fprintf (stderr, "hex decoding failure on value %s\n", value);\r
150 +           goto DONE;\r
151 +       }\r
152 +\r
153 +       if (print_status_database ("notmuch restore", notmuch,\r
154 +                                  notmuch_message_add_property (message, key, value)))\r
155 +       goto DONE;\r
156 +\r
157 +    }\r
158 +\r
159 +    ret = EXIT_SUCCESS;\r
160 +\r
161 + DONE:\r
162 +    talloc_free (local);\r
163 +    return ret;\r
164 +}\r
165 +\r
166 +\r
167  static regex_t regex;\r
168  \r
169  /* Non-zero return indicates an error in retrieving the message,\r
170 @@ -188,6 +254,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
171                                   { 0, 0 } } },\r
172         { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'I',\r
173           (notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },\r
174 +                                 { "properties", DUMP_INCLUDE_PROPERTIES },\r
175                                   { "tags", DUMP_INCLUDE_TAGS} } },\r
176  \r
177         { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
178 @@ -206,7 +273,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
179      notmuch_exit_if_unmatched_db_uuid (notmuch);\r
180  \r
181      if (include == 0) {\r
182 -       include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS;\r
183 +       include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_PROPERTIES | DUMP_INCLUDE_TAGS;\r
184      }\r
185  \r
186      name_for_error = input_file_name ? input_file_name : "stdin";\r
187 @@ -273,13 +340,18 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
188             if (ret)\r
189                 goto DONE;\r
190         }\r
191 +       if ((include & DUMP_INCLUDE_PROPERTIES) && line_len >= 2 && line[0] == '#' && line[1] == '=') {\r
192 +           ret = process_properties_line(notmuch, line+2);\r
193 +           if (ret)\r
194 +               goto DONE;\r
195 +       }\r
196  \r
197      } while ((line_len == 0) ||\r
198              (line[0] == '#') ||\r
199              /* the cast is safe because we checked about for line_len < 0 */\r
200              (strspn (line, " \t\n") == (unsigned)line_len));\r
201  \r
202 -    if (! (include & DUMP_INCLUDE_TAGS)) {\r
203 +    if (! ((include & DUMP_INCLUDE_TAGS) || (include & DUMP_INCLUDE_PROPERTIES))) {\r
204         ret = EXIT_SUCCESS;\r
205         goto DONE;\r
206      }\r
207 @@ -306,6 +378,13 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
208             talloc_free (line_ctx);\r
209  \r
210         line_ctx = talloc_new (config);\r
211 +\r
212 +       if ((include & DUMP_INCLUDE_PROPERTIES) && line_len >= 2 && line[0] == '#' && line[1] == '=') {\r
213 +           ret = process_properties_line(notmuch, line+2);\r
214 +           if (ret)\r
215 +               goto DONE;\r
216 +       }\r
217 +\r
218         if (input_format == DUMP_FORMAT_SUP) {\r
219             ret = parse_sup_line (line_ctx, line, &query_string, tag_ops);\r
220         } else {\r
221 diff --git a/test/T610-message-property.sh b/test/T610-message-property.sh\r
222 index e594979..8952eb7 100755\r
223 --- a/test/T610-message-property.sh\r
224 +++ b/test/T610-message-property.sh\r
225 @@ -209,4 +209,32 @@ EOF\r
226  notmuch dump | grep '^#=' > OUTPUT\r
227  test_expect_equal_file PROPERTIES OUTPUT\r
228  \r
229 +\r
230 +test_begin_subtest "restore missing message property (single line)"\r
231 +notmuch dump | grep '^#=' > BEFORE1\r
232 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
233 +EXPECT0(notmuch_message_remove_property (message, "testkey1", "bob"));\r
234 +EOF\r
235 +notmuch restore < BEFORE1\r
236 +notmuch dump | grep '^#=' > OUTPUT\r
237 +test_expect_equal_file PROPERTIES OUTPUT\r
238 +\r
239 +\r
240 +test_begin_subtest "restore missing message property (full dump)"\r
241 +notmuch dump > BEFORE2\r
242 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
243 +EXPECT0(notmuch_message_remove_property (message, "testkey1", "bob"));\r
244 +EOF\r
245 +notmuch restore < BEFORE2\r
246 +notmuch dump | grep '^#=' > OUTPUT\r
247 +test_expect_equal_file PROPERTIES OUTPUT\r
248 +\r
249 +test_begin_subtest "restore clear extra message property"\r
250 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
251 +EXPECT0(notmuch_message_add_property (message, "testkey1", "charles"));\r
252 +EOF\r
253 +notmuch restore < BEFORE2\r
254 +notmuch dump | grep '^#=' > OUTPUT\r
255 +test_expect_equal_file PROPERTIES OUTPUT\r
256 +\r
257  test_done\r
258 -- \r
259 2.8.1\r
260 \r