--- /dev/null
+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 706CB431FAF\r
+ for <notmuch@notmuchmail.org>; Sun, 22 Jul 2012 07:38:10 -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 XrQcWDvBD+K1 for <notmuch@notmuchmail.org>;\r
+ Sun, 22 Jul 2012 07:38:09 -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 1AB93431FB6\r
+ for <notmuch@notmuchmail.org>; Sun, 22 Jul 2012 07:38:08 -0700 (PDT)\r
+Received: by weyt57 with SMTP id t57so4152717wey.26\r
+ for <notmuch@notmuchmail.org>; Sun, 22 Jul 2012 07:38:07 -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:in-reply-to:references;\r
+ bh=WxQV6UtEotngWGGZbw30C4kjGtLNTPAcUGHlh0yhXZY=;\r
+ b=XpZ9LvOj86Bfcm6kM/s8QCAum+DNKRI9xfTUtzqhpZK6S7+xzgacyNMFHyC0fYYJnh\r
+ G4uLUHIIvppO9EgzKL+7TqXVvQIOGiSTTaPXBAafBiuO6eN9d1BsZfQjJKG0uL14swpu\r
+ /MmnH2BptztHf8FyOn5MbaSRWv9ogtCFC+a/BaZvP0ihaXSPlzIcl1pPCo1+93LBh1tk\r
+ pyrEuuImmrx6CcSlPVYJugAv5O9/jptJSZclfSwqwfXy7x+4WRosOfZ8g5vg2rRcJgsK\r
+ 2FBfLb7jzWuvHF25mp46yRugjJJJVewGKeNqRemy20z8snpISxkY5oW61ZEdN0h/Rc5T\r
+ oO1w==\r
+Received: by 10.180.19.169 with SMTP id g9mr40654543wie.9.1342967887808;\r
+ Sun, 22 Jul 2012 07:38:07 -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
+ cu1sm11318472wib.6.2012.07.22.07.38.06 (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Sun, 22 Jul 2012 07:38:06 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/4] cli: show: add --include-text-content=true|false option\r
+Date: Sun, 22 Jul 2012 15:37:56 +0100\r
+Message-Id: <1342967879-20453-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1342967879-20453-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1342967879-20453-1-git-send-email-markwalters1009@gmail.com>\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, 22 Jul 2012 14:38:10 -0000\r
+\r
+Normally notmuch show includes any text/* parts (except text/html) in\r
+the output. This option allows the caller to suppress this behaviour.\r
+\r
+This is used by notmuch-pick.el (although not needed) because it gives\r
+a speed-up of at least a factor of a two; moreover it reduces the\r
+memory usage in emacs hugely.\r
+\r
+This commit just implements it for --format-json. The next commit adds\r
+it for --format=text. The option does not make sense for --format=raw\r
+or --format=mbox.\r
+---\r
+\r
+This patch is a little bigger than I would like but a lot of it is code movement.\r
+\r
+ notmuch-client.h | 3 ++-\r
+ notmuch-reply.c | 2 +-\r
+ notmuch-show.c | 44 +++++++++++++++++++++++++-------------------\r
+ 3 files changed, 28 insertions(+), 21 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 0c17b79..edb356d 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 include_text_content;\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 include_text_content);\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..de21f3b 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, TRUE);\r
+ \r
+ /* End */\r
+ printf ("}\n");\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 8f3c60e..35e3f22 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 include_text_content)\r
+ {\r
+ /* Any changes to the JSON format should be reflected in the file\r
+ * devel/schemata. */\r
+@@ -572,7 +572,7 @@ 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
++ format_part_json (ctx, mime_node_child (node, 0), first, include_text_content);\r
+ \r
+ printf ("]}");\r
+ return;\r
+@@ -623,19 +623,21 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
+ * makes charset decoding the responsibility on the caller, we\r
+ * report the charset for text/html parts.\r
+ */\r
+- if (g_mime_content_type_is_type (content_type, "text", "html")) {\r
+- const char *content_charset = g_mime_object_get_content_type_parameter (meta, "charset");\r
+-\r
+- if (content_charset != NULL)\r
+- printf (", \"content-charset\": %s", json_quote_str (local, content_charset));\r
+- } else if (g_mime_content_type_is_type (content_type, "text", "*")) {\r
+- GMimeStream *stream_memory = g_mime_stream_mem_new ();\r
+- GByteArray *part_content;\r
+- show_text_part_content (node->part, stream_memory, 0);\r
+- part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));\r
+-\r
+- printf (", \"content\": %s", json_quote_chararray (local, (char *) part_content->data, part_content->len));\r
+- g_object_unref (stream_memory);\r
++ if (g_mime_content_type_is_type (content_type, "text", "*")) {\r
++ if (g_mime_content_type_is_type (content_type, "text", "html") || !include_text_content) {\r
++ const char *content_charset = g_mime_object_get_content_type_parameter (meta, "charset");\r
++\r
++ if (content_charset != NULL)\r
++ printf (", \"content-charset\": %s", json_quote_str (local, content_charset));\r
++ } else {\r
++ GMimeStream *stream_memory = g_mime_stream_mem_new ();\r
++ GByteArray *part_content;\r
++ show_text_part_content (node->part, stream_memory, 0);\r
++ part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));\r
++\r
++ printf (", \"content\": %s", json_quote_chararray (local, (char *) part_content->data, part_content->len));\r
++ g_object_unref (stream_memory);\r
++ }\r
+ }\r
+ } else if (GMIME_IS_MULTIPART (node->part)) {\r
+ printf (", \"content\": [");\r
+@@ -652,17 +654,16 @@ 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, include_text_content);\r
+ \r
+ printf ("%s}", terminator);\r
+ }\r
+ \r
+ 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
++ const notmuch_show_params_t *params)\r
+ {\r
+- format_part_json (ctx, node, TRUE);\r
+-\r
++ format_part_json (ctx, node, TRUE, params->include_text_content);\r
+ return NOTMUCH_STATUS_SUCCESS;\r
+ }\r
+ \r
+@@ -1004,6 +1005,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ notmuch_show_params_t params = {\r
+ .part = -1,\r
+ .omit_excluded = TRUE,\r
++ .include_text_content = TRUE,\r
+ .crypto = {\r
+ .verify = FALSE,\r
+ .decrypt = FALSE\r
+@@ -1032,6 +1034,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ { NOTMUCH_OPT_INT, ¶ms.part, "part", 'p', 0 },\r
+ { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 },\r
+ { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.verify, "verify", 'v', 0 },\r
++ { NOTMUCH_OPT_BOOLEAN, ¶ms.include_text_content, "include-text-content", 'h', 0 },\r
+ { 0, 0, 0, 0, 0 }\r
+ };\r
+ \r
+@@ -1086,6 +1089,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ entire_thread = ENTIRE_THREAD_FALSE;\r
+ }\r
+ \r
++ if (!params.include_text_content && (format == &format_mbox || format == &format_raw))\r
++ fprintf (stderr, "Warning: --include_text_content=false only makes sense for format=json and format=text\n");\r
++\r
+ if (entire_thread == ENTIRE_THREAD_TRUE)\r
+ params.entire_thread = TRUE;\r
+ else\r
+-- \r
+1.7.9.1\r
+\r