Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / a7 / 11a065777dd30deeab482f5da7c7c67cad1656
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 CFD176DE092F\r
6  for <notmuch@notmuchmail.org>; Sat, 26 Mar 2016 11:23:55 -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.02\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.02 tagged_above=-999 required=5 tests=[AWL=-0.021,\r
12   HEADER_FROM_DIFFERENT_DOMAINS=0.001] autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id Cr_wlSUFLLqb for <notmuch@notmuchmail.org>;\r
16  Sat, 26 Mar 2016 11:23:48 -0700 (PDT)\r
17 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
18  by arlo.cworth.org (Postfix) with ESMTPS id 579C16DE02D0\r
19  for <notmuch@notmuchmail.org>; Sat, 26 Mar 2016 11:23:22 -0700 (PDT)\r
20 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
21  (envelope-from <bremner@tesseract.cs.unb.ca>)\r
22  id 1ajsTY-0000va-Cg; Sat, 26 Mar 2016 13:58:16 -0400\r
23 Received: (nullmailer pid 8822 invoked by uid 1000);\r
24  Sat, 26 Mar 2016 17:57:27 -0000\r
25 From: David Bremner <david@tethera.net>\r
26 To: notmuch@notmuchmail.org\r
27 Subject: [Patch v2 10/13] CLI: optionally restore config data.\r
28 Date: Sat, 26 Mar 2016 14:57:20 -0300\r
29 Message-Id: <1459015043-8460-11-git-send-email-david@tethera.net>\r
30 X-Mailer: git-send-email 2.6.4\r
31 In-Reply-To: <1459015043-8460-1-git-send-email-david@tethera.net>\r
32 References: <1459015043-8460-1-git-send-email-david@tethera.net>\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.20\r
35 Precedence: list\r
36 List-Id: "Use and development of the notmuch mail system."\r
37  <notmuch.notmuchmail.org>\r
38 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
39  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
41 List-Post: <mailto:notmuch@notmuchmail.org>\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
43 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
44  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
45 X-List-Received-Date: Sat, 26 Mar 2016 18:23:55 -0000\r
46 \r
47 The default to restore config data seems safest, especially since\r
48 currently we have no config data to mess up.\r
49 ---\r
50  doc/man1/notmuch-restore.rst | 18 +++++++++++++++\r
51  notmuch-restore.c            | 53 ++++++++++++++++++++++++++++++++++++++++++++\r
52  test/T590-libconfig.sh       | 11 +++++++++\r
53  3 files changed, 82 insertions(+)\r
54 \r
55 diff --git a/doc/man1/notmuch-restore.rst b/doc/man1/notmuch-restore.rst\r
56 index 362e262..87fa22e 100644\r
57 --- a/doc/man1/notmuch-restore.rst\r
58 +++ b/doc/man1/notmuch-restore.rst\r
59 @@ -50,6 +50,24 @@ Supported options for **restore** include\r
60              format, this heuristic, based the fact that batch-tag format\r
61              contains no parentheses, should be accurate.\r
62  \r
63 +    ``--include=(config|tags)``\r
64 +\r
65 +      Control what kind of metadata is restored.\r
66 +\r
67 +       **config**\r
68 +\r
69 +         Restore configuration data to the database. Each configuration line starts\r
70 +         with "#@ ", followed by a space seperated key-value pair.\r
71 +         Both key and value are hex encoded if needed.\r
72 +\r
73 +       **tags**\r
74 +\r
75 +         Output per-message metadata, namely tags. See *format* above\r
76 +         for more details.\r
77 +\r
78 +      The default is to restore both tags and configuration\r
79 +      information\r
80 +\r
81      ``--input=``\ <filename>\r
82          Read input from given file instead of stdin.\r
83  \r
84 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
85 index 9abc64f..e06fbde 100644\r
86 --- a/notmuch-restore.c\r
87 +++ b/notmuch-restore.c\r
88 @@ -24,6 +24,38 @@\r
89  #include "string-util.h"\r
90  #include "zlib-extra.h"\r
91  \r
92 +static int\r
93 +process_config_line(notmuch_database_t *notmuch, const char* line){\r
94 +    const char *key_p, *val_p;\r
95 +    char *key, *val;\r
96 +    size_t key_len,val_len;\r
97 +    const char *delim=" \t\n";\r
98 +    int ret = EXIT_FAILURE;\r
99 +\r
100 +    void *local = talloc_new(NULL);\r
101 +\r
102 +    key_p = strtok_len_c(line, delim, &key_len);\r
103 +    val_p = strtok_len_c(key_p+key_len, delim, &val_len);\r
104 +\r
105 +    key = talloc_strndup(local, key_p, key_len);\r
106 +    val = talloc_strndup(local, val_p, val_len);\r
107 +    if (hex_decode_inplace (key) != HEX_SUCCESS ||\r
108 +       hex_decode_inplace (val) != HEX_SUCCESS ) {\r
109 +       fprintf (stderr, "hex decoding failure on line %s\n", line);\r
110 +       goto DONE;\r
111 +    }\r
112 +\r
113 +    if (print_status_database ("notmuch restore", notmuch,\r
114 +                              notmuch_database_set_config (notmuch, key, val)))\r
115 +       goto DONE;\r
116 +\r
117 +    ret = EXIT_SUCCESS;\r
118 +\r
119 + DONE:\r
120 +    talloc_free (local);\r
121 +    return ret;\r
122 +}\r
123 +\r
124  static regex_t regex;\r
125  \r
126  /* Non-zero return indicates an error in retrieving the message,\r
127 @@ -137,6 +169,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
128  \r
129      int ret = 0;\r
130      int opt_index;\r
131 +    int include=0;\r
132      int input_format = DUMP_FORMAT_AUTO;\r
133  \r
134      if (notmuch_database_open (notmuch_config_get_database_path (config),\r
135 @@ -152,6 +185,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
136                                   { "batch-tag", DUMP_FORMAT_BATCH_TAG },\r
137                                   { "sup", DUMP_FORMAT_SUP },\r
138                                   { 0, 0 } } },\r
139 +       { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'I',\r
140 +         (notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },\r
141 +                                 { "tags", DUMP_INCLUDE_TAGS} } },\r
142 +\r
143         { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
144         { NOTMUCH_OPT_BOOLEAN,  &accumulate, "accumulate", 'a', 0 },\r
145         { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
146 @@ -167,6 +204,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
147      notmuch_process_shared_options (argv[0]);\r
148      notmuch_exit_if_unmatched_db_uuid (notmuch);\r
149  \r
150 +    if (include == 0) {\r
151 +       include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS;\r
152 +    }\r
153 +\r
154      name_for_error = input_file_name ? input_file_name : "stdin";\r
155  \r
156      if (! accumulate)\r
157 @@ -225,11 +266,23 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
158             ret = EXIT_FAILURE;\r
159             goto DONE;\r
160         }\r
161 +\r
162 +       if ((include & DUMP_INCLUDE_CONFIG) && line_len >= 2 && line[0] == '#' && line[1] == '@') {\r
163 +           ret = process_config_line(notmuch, line+2);\r
164 +           if (ret)\r
165 +               goto DONE;\r
166 +       }\r
167 +\r
168      } while ((line_len == 0) ||\r
169              (line[0] == '#') ||\r
170              /* the cast is safe because we checked about for line_len < 0 */\r
171              (strspn (line, " \t\n") == (unsigned)line_len));\r
172  \r
173 +    if (! (include & DUMP_INCLUDE_TAGS)) {\r
174 +       ret = EXIT_SUCCESS;\r
175 +       goto DONE;\r
176 +    }\r
177 +\r
178      char *p;\r
179      for (p = line; (input_format == DUMP_FORMAT_AUTO) && *p; p++) {\r
180         if (*p == '(')\r
181 diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh\r
182 index 5ea5300..9c1e566 100755\r
183 --- a/test/T590-libconfig.sh\r
184 +++ b/test/T590-libconfig.sh\r
185 @@ -132,4 +132,15 @@ cat <<'EOF' >EXPECTED\r
186  EOF\r
187  test_expect_equal_file EXPECTED OUTPUT\r
188  \r
189 +test_begin_subtest "restore config"\r
190 +notmuch dump --include=config >EXPECTED\r
191 +cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
192 +{\r
193 +    RUN(notmuch_database_set_config (db, "testkey1", "mutatedvalue"));\r
194 +}\r
195 +EOF\r
196 +notmuch restore --include=config <EXPECTED\r
197 +notmuch dump --include=config >OUTPUT\r
198 +test_expect_equal_file EXPECTED OUTPUT\r
199 +\r
200  test_done\r
201 -- \r
202 2.6.4\r
203 \r