[PATCH] cli: add --headers_only option to notmuch-show.c
authorMark Walters <markwalters1009@gmail.com>
Sat, 30 Jun 2012 07:33:15 +0000 (08:33 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:54 +0000 (09:47 -0800)
f5/ef53c1451fafed73e4dbc86d84e0db3ff7ff04 [new file with mode: 0644]

diff --git a/f5/ef53c1451fafed73e4dbc86d84e0db3ff7ff04 b/f5/ef53c1451fafed73e4dbc86d84e0db3ff7ff04
new file mode 100644 (file)
index 0000000..a4ae00c
--- /dev/null
@@ -0,0 +1,197 @@
+Return-Path: <markwalters1009@gmail.com>\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 6A483431FAF\r
+       for <notmuch@notmuchmail.org>; Sat, 30 Jun 2012 00:33:32 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       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 6G9G+crUFEFL for <notmuch@notmuchmail.org>;\r
+       Sat, 30 Jun 2012 00:33:31 -0700 (PDT)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 6B0BB431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 30 Jun 2012 00:33:31 -0700 (PDT)\r
+Received: by werl57 with SMTP id l57so922344wer.26\r
+       for <notmuch@notmuchmail.org>; Sat, 30 Jun 2012 00:33:30 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer;\r
+       bh=x4T7AkT4AOjCLXoge9fwPyfjgdUTULi64dPfTY0MIfI=;\r
+       b=NRxxH8GkEfCLvpzXWsGPCzzWKzYblBwDipwDp/Hxo7pECkxipxW9JAwzcTzWHlGDGP\r
+       61Vk+zVR42tXVKrGQr0APy/qoTtKEZD9ff4DJt9ewx07k5RRHfcnUNTUqPqde3ITc2va\r
+       OXLuhauuukIGwTuM+pQz63ldHPTZajy8UfPdigFToaW6b8idXQHZ2HVsSkYRi1eAN9ot\r
+       g1QYFbZ9xnDTj5gQFFjvyGAojcZyEtG3cXJ/qipkbT/LFry7u1utOS5BExviQoM1atmL\r
+       Dt9jiETwCCStAif90hPMh2EaNwpjduH9QF2KejkVJc6Q1kGe8LBNHdvOerPPcc0imyqW\r
+       fbaQ==\r
+Received: by 10.216.4.147 with SMTP id 19mr2087808wej.109.1341041610006;\r
+       Sat, 30 Jun 2012 00:33:30 -0700 (PDT)\r
+Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
+ [94.192.233.223])     by mx.google.com with ESMTPS id\r
+ bg10sm18467913wib.9.2012.06.30.00.33.27       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 30 Jun 2012 00:33:28 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] cli: add --headers_only option to notmuch-show.c\r
+Date: Sat, 30 Jun 2012 08:33:15 +0100\r
+Message-Id: <1341041595-5858-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\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: Sat, 30 Jun 2012 07:33:32 -0000\r
+\r
+This option just outputs the headers of a message (i.e. it omits the\r
+bodies). Currently this is only implemented for format=json.\r
+\r
+This is used by notmuch-pick.el (although not needed) because it gives a\r
+speed-up of at least a factor of a two; moreover it reduces the memory\r
+usage in emacs hugely.\r
+---\r
+\r
+Currently notmuch-show outputs on a thread includes all headers and\r
+all text/plain parts (more precisely all text/* except text/html): the\r
+client has to fetch any other parts it wants.\r
+\r
+This patch allows notmuch show to just output the headers: omitting\r
+all the body parts. Jamie suggested in\r
+id:"87zk80ilt9.fsf@servo.finestructure.net" that we always omit all\r
+body parts and leave it to the client to fetch them. \r
+\r
+My feeling is that this could make some uses much slower (a view\r
+expressed by Peter in id:"20120620110139.GA2356@hili.localdomain").\r
+\r
+What do people think?\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+ notmuch-client.h |    3 ++-\r
+ notmuch-reply.c  |    2 +-\r
+ notmuch-show.c   |   15 +++++++++++----\r
+ 3 files changed, 14 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 0c17b79..17efde2 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -87,6 +87,7 @@ typedef struct notmuch_crypto {\r
+ typedef struct notmuch_show_params {\r
+     notmuch_bool_t entire_thread;\r
+     notmuch_bool_t omit_excluded;\r
++    notmuch_bool_t headers_only;\r
+     notmuch_bool_t raw;\r
+     int part;\r
+     notmuch_crypto_t crypto;\r
+@@ -176,7 +177,7 @@ notmuch_status_t\r
+ show_one_part (const char *filename, int part);\r
\r
+ void\r
+-format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first);\r
++format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notmuch_bool_t headers_only);\r
\r
+ void\r
+ format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply);\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index 3a038ed..07c3bef 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -620,7 +620,7 @@ notmuch_reply_format_json(void *ctx,\r
+     /* Start the original */\r
+     printf (", \"original\": ");\r
\r
+-    format_part_json (ctx, node, TRUE);\r
++    format_part_json (ctx, node, TRUE, FALSE);\r
\r
+     /* End */\r
+     printf ("}\n");\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 8f3c60e..195e318 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -559,7 +559,7 @@ format_part_text (const void *ctx, mime_node_t *node,\r
+ }\r
\r
+ void\r
+-format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
++format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notmuch_bool_t headers_only)\r
+ {\r
+     /* Any changes to the JSON format should be reflected in the file\r
+      * devel/schemata. */\r
+@@ -572,7 +572,8 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
+       format_headers_json (ctx, GMIME_MESSAGE (node->part), FALSE);\r
\r
+       printf (", \"body\": [");\r
+-      format_part_json (ctx, mime_node_child (node, 0), first);\r
++      if (!headers_only)\r
++          format_part_json (ctx, mime_node_child (node, 0), first, FALSE);\r
\r
+       printf ("]}");\r
+       return;\r
+@@ -652,7 +653,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
+     talloc_free (local);\r
\r
+     for (i = 0; i < node->nchildren; i++)\r
+-      format_part_json (ctx, mime_node_child (node, i), i == 0);\r
++      format_part_json (ctx, mime_node_child (node, i), i == 0, FALSE);\r
\r
+     printf ("%s}", terminator);\r
+ }\r
+@@ -661,7 +662,7 @@ static notmuch_status_t\r
+ format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent),\r
+                       unused (const notmuch_show_params_t *params))\r
+ {\r
+-    format_part_json (ctx, node, TRUE);\r
++    format_part_json (ctx, node, TRUE, params->headers_only);\r
\r
+     return NOTMUCH_STATUS_SUCCESS;\r
+ }\r
+@@ -1010,6 +1011,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+       }\r
+     };\r
+     int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;\r
++    notmuch_bool_t headers_only = FALSE;\r
+     int exclude = EXCLUDE_TRUE;\r
+     int entire_thread = ENTIRE_THREAD_DEFAULT;\r
\r
+@@ -1032,6 +1034,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+       { NOTMUCH_OPT_INT, &params.part, "part", 'p', 0 },\r
+       { NOTMUCH_OPT_BOOLEAN, &params.crypto.decrypt, "decrypt", 'd', 0 },\r
+       { NOTMUCH_OPT_BOOLEAN, &params.crypto.verify, "verify", 'v', 0 },\r
++      { NOTMUCH_OPT_BOOLEAN, &headers_only, "headers-only", 'h', 0 },\r
+       { 0, 0, 0, 0, 0 }\r
+     };\r
\r
+@@ -1086,6 +1089,10 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+           entire_thread = ENTIRE_THREAD_FALSE;\r
+     }\r
\r
++    if (headers_only && format != &format_json)\r
++      fprintf (stderr,"Warning: --headers-only only implemented for format=json\n");\r
++    params.headers_only = headers_only;\r
++\r
+     if (entire_thread == ENTIRE_THREAD_TRUE)\r
+       params.entire_thread = TRUE;\r
+     else\r
+-- \r
+1.7.9.1\r
+\r