--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id DBA066DE137E\r
+ for <notmuch@notmuchmail.org>; Sat, 23 Jan 2016 07:00:14 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.31\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.31 tagged_above=-999 required=5 tests=[AWL=0.241, \r
+ RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id aALqoui491bC for <notmuch@notmuchmail.org>;\r
+ Sat, 23 Jan 2016 07:00:13 -0800 (PST)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 735976DE091B\r
+ for <notmuch@notmuchmail.org>; Sat, 23 Jan 2016 07:00:12 -0800 (PST)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1aMzf3-00016G-Au; Sat, 23 Jan 2016 09:59:33 -0500\r
+Received: (nullmailer pid 4051 invoked by uid 1000);\r
+ Sat, 23 Jan 2016 15:00:07 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 5/5] CLI: optionally restore config data.\r
+Date: Sat, 23 Jan 2016 10:59:58 -0400\r
+Message-Id: <1453561198-2893-6-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.6.4\r
+In-Reply-To: <1453561198-2893-1-git-send-email-david@tethera.net>\r
+References: <1453561198-2893-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 23 Jan 2016 15:00:14 -0000\r
+\r
+Like the corresponding change to dump, this needs documentation\r
+---\r
+ notmuch-restore.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ test/T590-libconfig.sh | 11 +++++++++++\r
+ 2 files changed, 64 insertions(+)\r
+\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index 9abc64f..e06fbde 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -24,6 +24,38 @@\r
+ #include "string-util.h"\r
+ #include "zlib-extra.h"\r
+ \r
++static int\r
++process_config_line(notmuch_database_t *notmuch, const char* line){\r
++ const char *key_p, *val_p;\r
++ char *key, *val;\r
++ size_t key_len,val_len;\r
++ const char *delim=" \t\n";\r
++ int ret = EXIT_FAILURE;\r
++\r
++ void *local = talloc_new(NULL);\r
++\r
++ key_p = strtok_len_c(line, delim, &key_len);\r
++ val_p = strtok_len_c(key_p+key_len, delim, &val_len);\r
++\r
++ key = talloc_strndup(local, key_p, key_len);\r
++ val = talloc_strndup(local, val_p, val_len);\r
++ if (hex_decode_inplace (key) != HEX_SUCCESS ||\r
++ hex_decode_inplace (val) != HEX_SUCCESS ) {\r
++ fprintf (stderr, "hex decoding failure on line %s\n", line);\r
++ goto DONE;\r
++ }\r
++\r
++ if (print_status_database ("notmuch restore", notmuch,\r
++ notmuch_database_set_config (notmuch, key, val)))\r
++ goto DONE;\r
++\r
++ ret = EXIT_SUCCESS;\r
++\r
++ DONE:\r
++ talloc_free (local);\r
++ return ret;\r
++}\r
++\r
+ static regex_t regex;\r
+ \r
+ /* Non-zero return indicates an error in retrieving the message,\r
+@@ -137,6 +169,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
+ \r
+ int ret = 0;\r
+ int opt_index;\r
++ int include=0;\r
+ int input_format = DUMP_FORMAT_AUTO;\r
+ \r
+ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
+@@ -152,6 +185,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
+ { "batch-tag", DUMP_FORMAT_BATCH_TAG },\r
+ { "sup", DUMP_FORMAT_SUP },\r
+ { 0, 0 } } },\r
++ { NOTMUCH_OPT_KEYWORD_FLAGS, &include, "include", 'I',\r
++ (notmuch_keyword_t []){ { "config", DUMP_INCLUDE_CONFIG },\r
++ { "tags", DUMP_INCLUDE_TAGS} } },\r
++\r
+ { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
+ { NOTMUCH_OPT_BOOLEAN, &accumulate, "accumulate", 'a', 0 },\r
+ { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },\r
+@@ -167,6 +204,10 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
+ notmuch_process_shared_options (argv[0]);\r
+ notmuch_exit_if_unmatched_db_uuid (notmuch);\r
+ \r
++ if (include == 0) {\r
++ include = DUMP_INCLUDE_CONFIG | DUMP_INCLUDE_TAGS;\r
++ }\r
++\r
+ name_for_error = input_file_name ? input_file_name : "stdin";\r
+ \r
+ if (! accumulate)\r
+@@ -225,11 +266,23 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
+ ret = EXIT_FAILURE;\r
+ goto DONE;\r
+ }\r
++\r
++ if ((include & DUMP_INCLUDE_CONFIG) && line_len >= 2 && line[0] == '#' && line[1] == '@') {\r
++ ret = process_config_line(notmuch, line+2);\r
++ if (ret)\r
++ goto DONE;\r
++ }\r
++\r
+ } while ((line_len == 0) ||\r
+ (line[0] == '#') ||\r
+ /* the cast is safe because we checked about for line_len < 0 */\r
+ (strspn (line, " \t\n") == (unsigned)line_len));\r
+ \r
++ if (! (include & DUMP_INCLUDE_TAGS)) {\r
++ ret = EXIT_SUCCESS;\r
++ goto DONE;\r
++ }\r
++\r
+ char *p;\r
+ for (p = line; (input_format == DUMP_FORMAT_AUTO) && *p; p++) {\r
+ if (*p == '(')\r
+diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh\r
+index 5ea5300..9c1e566 100755\r
+--- a/test/T590-libconfig.sh\r
++++ b/test/T590-libconfig.sh\r
+@@ -132,4 +132,15 @@ cat <<'EOF' >EXPECTED\r
+ EOF\r
+ test_expect_equal_file EXPECTED OUTPUT\r
+ \r
++test_begin_subtest "restore config"\r
++notmuch dump --include=config >EXPECTED\r
++cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}\r
++{\r
++ RUN(notmuch_database_set_config (db, "testkey1", "mutatedvalue"));\r
++}\r
++EOF\r
++notmuch restore --include=config <EXPECTED\r
++notmuch dump --include=config >OUTPUT\r
++test_expect_equal_file EXPECTED OUTPUT\r
++\r
+ test_done\r
+-- \r
+2.6.4\r
+\r