[PATCH v3 04/10] notmuch-dump: add --format=(notmuch|sup)
authorDavid Bremner <david@tethera.net>
Sun, 15 Jan 2012 01:40:18 +0000 (21:40 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:42:10 +0000 (09:42 -0800)
77/f2334b0d8018113b248e4717fbc1297ad49e7c [new file with mode: 0644]

diff --git a/77/f2334b0d8018113b248e4717fbc1297ad49e7c b/77/f2334b0d8018113b248e4717fbc1297ad49e7c
new file mode 100644 (file)
index 0000000..9f420dd
--- /dev/null
@@ -0,0 +1,179 @@
+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 olra.theworths.org (Postfix) with ESMTP id 75C2B414395\r
+       for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 17:40:59 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 9vgB10xBdI2A for <notmuch@notmuchmail.org>;\r
+       Sat, 14 Jan 2012 17:40:58 -0800 (PST)\r
+Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 3BCB941439B\r
+       for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 17:40:52 -0800 (PST)\r
+Received: from zancas.localnet\r
+       (fctnnbsc36w-156034076032.pppoe-dynamic.High-Speed.nb.bellaliant.net\r
+       [156.34.76.32]) (authenticated bits=0)\r
+       by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id q0F1efRY008570\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
+       Sat, 14 Jan 2012 21:40:44 -0400\r
+Received: from bremner by zancas.localnet with local (Exim 4.77)\r
+       (envelope-from <bremner@tethera.net>)\r
+       id 1RmF5N-00042p-7r; Sat, 14 Jan 2012 21:40:41 -0400\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 04/10] notmuch-dump: add --format=(notmuch|sup)\r
+Date: Sat, 14 Jan 2012 21:40:18 -0400\r
+Message-Id: <1326591624-15493-5-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <1326591624-15493-1-git-send-email-david@tethera.net>\r
+References: <874nwxbkhr.fsf@zancas.localnet>\r
+       <1326591624-15493-1-git-send-email-david@tethera.net>\r
+Cc: David Bremner <bremner@debian.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://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: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 15 Jan 2012 01:40:59 -0000\r
+\r
+From: David Bremner <bremner@debian.org>\r
+\r
+sup is the old format, and remains the default.\r
+\r
+Each line of the notmuch format is "msg_id tag tag...tag" where each\r
+space seperated token is 'hex-encoded' to remove troubling characters.\r
+In particular this format won't have the same problem with e.g. spaces\r
+in message-ids or tags; they will be round-trip-able.\r
+---\r
+ dump-restore-private.h |   12 ++++++++++++\r
+ notmuch-dump.c         |   47 +++++++++++++++++++++++++++++++++++++++--------\r
+ 2 files changed, 51 insertions(+), 8 deletions(-)\r
+ create mode 100644 dump-restore-private.h\r
+\r
+diff --git a/dump-restore-private.h b/dump-restore-private.h\r
+new file mode 100644\r
+index 0000000..34a5022\r
+--- /dev/null\r
++++ b/dump-restore-private.h\r
+@@ -0,0 +1,12 @@\r
++#ifndef DUMP_RESTORE_PRIVATE_H\r
++#define DUMP_RESTORE_PRIVATE_H\r
++\r
++#include "hex-escape.h"\r
++#include "command-line-arguments.h"\r
++\r
++typedef enum dump_formats {\r
++    DUMP_FORMAT_SUP,\r
++    DUMP_FORMAT_NOTMUCH\r
++} dump_format_t;\r
++\r
++#endif\r
+diff --git a/notmuch-dump.c b/notmuch-dump.c\r
+index a735875..0231db2 100644\r
+--- a/notmuch-dump.c\r
++++ b/notmuch-dump.c\r
+@@ -19,6 +19,7 @@\r
+  */\r
\r
+ #include "notmuch-client.h"\r
++#include "dump-restore-private.h"\r
\r
+ int\r
+ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
+@@ -44,9 +45,15 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
+     char *output_file_name = NULL;\r
+     int opt_index;\r
\r
++    int output_format = DUMP_FORMAT_SUP;\r
++\r
+     notmuch_opt_desc_t options[] = {\r
+-      { NOTMUCH_OPT_POSITION, &output_file_name, 0, 0, 0  },\r
+-      { 0, 0, 0, 0, 0 }\r
++      { NOTMUCH_OPT_KEYWORD, &output_format, "format", 'f',\r
++        (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },\r
++                                { "notmuch", DUMP_FORMAT_NOTMUCH },\r
++                                {0, 0} } },\r
++      { NOTMUCH_OPT_POSITION, &output_file_name, 0, 0, 0 },\r
++      { 0,                    0,                 0, 0, 0 }\r
+     };\r
\r
+     opt_index = parse_arguments (argc, argv, options, 1);\r
+@@ -85,29 +92,53 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
+      */\r
+     notmuch_query_set_sort (query, NOTMUCH_SORT_UNSORTED);\r
\r
++    char *buffer = NULL;\r
++    size_t buffer_size = 0;\r
++\r
+     for (messages = notmuch_query_search_messages (query);\r
+        notmuch_messages_valid (messages);\r
+        notmuch_messages_move_to_next (messages))\r
+     {\r
+       int first = 1;\r
+-      message = notmuch_messages_get (messages);\r
++      const char *message_id;\r
\r
+-      fprintf (output,\r
+-               "%s (", notmuch_message_get_message_id (message));\r
++      message = notmuch_messages_get (messages);\r
++      message_id = notmuch_message_get_message_id (message);\r
++\r
++      if (output_format == DUMP_FORMAT_SUP) {\r
++          fprintf (output, "%s (", message_id);\r
++      } else {\r
++          if (hex_encode (notmuch, message_id,\r
++                          &buffer, &buffer_size) != HEX_SUCCESS)\r
++              return 1;\r
++          fprintf (output, "%s ", buffer);\r
++      }\r
\r
+       for (tags = notmuch_message_get_tags (message);\r
+            notmuch_tags_valid (tags);\r
+            notmuch_tags_move_to_next (tags))\r
+       {\r
++          const char *tag_str = notmuch_tags_get (tags);\r
++\r
+           if (! first)\r
+-              fprintf (output, " ");\r
++              fputs (" ", output);\r
\r
+-          fprintf (output, "%s", notmuch_tags_get (tags));\r
++          if (output_format == DUMP_FORMAT_SUP) {\r
++              fputs (tag_str, output);\r
++          } else {\r
++              if (hex_encode (notmuch, tag_str,\r
++                              &buffer, &buffer_size) != HEX_SUCCESS)\r
++                  return 1;\r
\r
++              fputs (buffer, output);\r
++          }\r
+           first = 0;\r
+       }\r
\r
+-      fprintf (output, ")\n");\r
++      if (output_format == DUMP_FORMAT_SUP)\r
++          fputs (")\n", output);\r
++      else\r
++          fputs ("\n", output);\r
\r
+       notmuch_message_destroy (message);\r
+     }\r
+-- \r
+1.7.7.3\r
+\r