Re: [Patch v2 07/17] notmuch-dump: add --format=(batch-tag|sup)
authorJani Nikula <jani@nikula.org>
Fri, 30 Nov 2012 23:37:19 +0000 (01:37 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:14 +0000 (09:51 -0800)
91/74cab3195a06cc399eaf7e660fa20c76648a60 [new file with mode: 0644]

diff --git a/91/74cab3195a06cc399eaf7e660fa20c76648a60 b/91/74cab3195a06cc399eaf7e660fa20c76648a60
new file mode 100644 (file)
index 0000000..8223d41
--- /dev/null
@@ -0,0 +1,208 @@
+Return-Path: <jani@nikula.org>\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 80958431FAE\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 15:37:28 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 nbDGbLS05XxI for <notmuch@notmuchmail.org>;\r
+       Fri, 30 Nov 2012 15:37:24 -0800 (PST)\r
+Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
+       [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id CF581431FAF\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 15:37:23 -0800 (PST)\r
+Received: by mail-lb0-f181.google.com with SMTP id ge1so976616lbb.26\r
+       for <notmuch@notmuchmail.org>; Fri, 30 Nov 2012 15:37:22 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
+       :message-id:mime-version:content-type:x-gm-message-state;\r
+       bh=aGY7tumjfDKNLlBKh+QA7jViXLnCvdeOKyMUdWVxOSo=;\r
+       b=ANF2zQAdzwfdHRkUnI5upBzWgc83NMxN4YTk3/4a8DjEl1q7mShffiSS7LH1l9mAKe\r
+       Zka7UcKqTbqK6QFYSpWldYKB2FDDhmgLJCf/z0r7iKj/RrZWz7BTcF/5H+FvBHAaU4DF\r
+       dNQbfuf8hH4hkj5F+Q+4OdDtMyOkrQP+0ihaeCBa8zkHcsu4bckZRkmi5S8o+869ylG5\r
+       9y6ZgqITHCxCTyDtteFr09KAmWn/rnEIwasF/xf3yu/LV1Wa9CTu15PtYLknMeHqpNOm\r
+       F/+kTRD7jGcZkT5sGzDXKo0VnjJ/46CwKGCywhzPq1YufkkWB4Gr6mK23Vi+ZEKojLeU\r
+       ClEQ==\r
+Received: by 10.112.25.168 with SMTP id d8mr1513108lbg.62.1354318642317;\r
+       Fri, 30 Nov 2012 15:37:22 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.\r
+       [80.223.81.27])\r
+       by mx.google.com with ESMTPS id q2sm2581307lbd.14.2012.11.30.15.37.20\r
+       (version=SSLv3 cipher=OTHER); Fri, 30 Nov 2012 15:37:21 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: david@tethera.net, notmuch@notmuchmail.org\r
+Subject: Re: [Patch v2 07/17] notmuch-dump: add --format=(batch-tag|sup)\r
+In-Reply-To: <1353792017-31459-8-git-send-email-david@tethera.net>\r
+References: <1353792017-31459-1-git-send-email-david@tethera.net>\r
+       <1353792017-31459-8-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.14+124~g3b17402 (http://notmuchmail.org) Emacs/23.4.1\r
+       (i686-pc-linux-gnu)\r
+Date: Sat, 01 Dec 2012 01:37:19 +0200\r
+Message-ID: <87ip8maci8.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQlvcGtYDemL1cPY0KSExPODMlyXdIQUNAj8xDHQ6HrTCMEx/4FVRGcbXEHN6omMRuzpT8+z\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: Fri, 30 Nov 2012 23:37:28 -0000\r
+\r
+On Sat, 24 Nov 2012, david@tethera.net wrote:\r
+> From: David Bremner <bremner@debian.org>\r
+>\r
+> sup is the old format, and remains the default, at least until\r
+> restore is converted to parse this format.\r
+>\r
+> Each line of the batch- format is valid for notmuch tag, (with the\r
+> "notmuch tag" omitted from the front of the line). The dump format\r
+> only uses query strings of a single message-id.\r
+\r
+Valid for notmuch tag except for the hex encoding and empty set of tags.\r
+\r
+> Each space seperated tag/message-id is 'hex-encoded' to remove\r
+> troubling characters.  In particular this format won't have the same\r
+> problem with e.g. spaces in message-ids or tags; they will be\r
+> round-trip-able.\r
+> ---\r
+>  dump-restore-private.h |   13 +++++++++++++\r
+>  notmuch-dump.c         |   42 ++++++++++++++++++++++++++++++++++++------\r
+>  2 files changed, 49 insertions(+), 6 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..896a004\r
+> --- /dev/null\r
+> +++ b/dump-restore-private.h\r
+> @@ -0,0 +1,13 @@\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_AUTO,\r
+> +    DUMP_FORMAT_BATCH_TAG,\r
+> +    DUMP_FORMAT_SUP\r
+> +} dump_format_t;\r
+> +\r
+> +#endif\r
+> diff --git a/notmuch-dump.c b/notmuch-dump.c\r
+> index 88f598a..045ca9e 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
+> @@ -43,7 +44,13 @@ 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_KEYWORD, &output_format, "format", 'f',\r
+> +      (notmuch_keyword_t []){ { "sup", DUMP_FORMAT_SUP },\r
+> +                              { "batch-tag", DUMP_FORMAT_BATCH_TAG },\r
+> +                              { 0, 0 } } },\r
+>      { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0  },\r
+>      { 0, 0, 0, 0, 0 }\r
+>      };\r
+> @@ -83,27 +90,50 @@ 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
+>      int first = 1;\r
+> +    const char *message_id;\r
+> +\r
+>      message = notmuch_messages_get (messages);\r
+> +    message_id = notmuch_message_get_message_id (message);\r
+>  \r
+> -    fprintf (output,\r
+> -             "%s (", notmuch_message_get_message_id (message));\r
+> +    if (output_format == DUMP_FORMAT_SUP) {\r
+> +        fprintf (output, "%s (", message_id);\r
+> +    }\r
+>  \r
+>      for (tags = notmuch_message_get_tags (message);\r
+>           notmuch_tags_valid (tags);\r
+>           notmuch_tags_move_to_next (tags)) {\r
+> -        if (! first)\r
+> -            fprintf (output, " ");\r
+> +        const char *tag_str = notmuch_tags_get (tags);\r
+>  \r
+> -        fprintf (output, "%s", notmuch_tags_get (tags));\r
+> +        if (! first)\r
+> +            fputs (" ", output);\r
+>  \r
+>          first = 0;\r
+> +\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
+Maybe hex_encode errors would deserve an error message. Ditto below.\r
+\r
+Otherwise LGTM.\r
+\r
+BR,\r
+Jani.\r
+\r
+> +            fprintf (output, "+%s", buffer);\r
+> +        }\r
+>      }\r
+>  \r
+> -    fprintf (output, ")\n");\r
+> +    if (output_format == DUMP_FORMAT_SUP) {\r
+> +        fputs (")\n", output);\r
+> +    } else {\r
+> +        if (hex_encode (notmuch, message_id,\r
+> +                        &buffer, &buffer_size) != HEX_SUCCESS)\r
+> +            return 1;\r
+> +        fprintf (output, " -- id:%s\n", buffer);\r
+> +    }\r
+>  \r
+>      notmuch_message_destroy (message);\r
+>      }\r
+> -- \r
+> 1.7.10.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r