Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 706CB431FAF for ; Sun, 22 Jul 2012 07:38:10 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XrQcWDvBD+K1 for ; Sun, 22 Jul 2012 07:38:09 -0700 (PDT) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 1AB93431FB6 for ; Sun, 22 Jul 2012 07:38:08 -0700 (PDT) Received: by weyt57 with SMTP id t57so4152717wey.26 for ; Sun, 22 Jul 2012 07:38:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=WxQV6UtEotngWGGZbw30C4kjGtLNTPAcUGHlh0yhXZY=; b=XpZ9LvOj86Bfcm6kM/s8QCAum+DNKRI9xfTUtzqhpZK6S7+xzgacyNMFHyC0fYYJnh G4uLUHIIvppO9EgzKL+7TqXVvQIOGiSTTaPXBAafBiuO6eN9d1BsZfQjJKG0uL14swpu /MmnH2BptztHf8FyOn5MbaSRWv9ogtCFC+a/BaZvP0ihaXSPlzIcl1pPCo1+93LBh1tk pyrEuuImmrx6CcSlPVYJugAv5O9/jptJSZclfSwqwfXy7x+4WRosOfZ8g5vg2rRcJgsK 2FBfLb7jzWuvHF25mp46yRugjJJJVewGKeNqRemy20z8snpISxkY5oW61ZEdN0h/Rc5T oO1w== Received: by 10.180.19.169 with SMTP id g9mr40654543wie.9.1342967887808; Sun, 22 Jul 2012 07:38:07 -0700 (PDT) Received: from localhost (94-192-233-223.zone6.bethere.co.uk. [94.192.233.223]) by mx.google.com with ESMTPS id cu1sm11318472wib.6.2012.07.22.07.38.06 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 22 Jul 2012 07:38:06 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH 1/4] cli: show: add --include-text-content=true|false option Date: Sun, 22 Jul 2012 15:37:56 +0100 Message-Id: <1342967879-20453-2-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1342967879-20453-1-git-send-email-markwalters1009@gmail.com> References: <1342967879-20453-1-git-send-email-markwalters1009@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Jul 2012 14:38:10 -0000 Normally notmuch show includes any text/* parts (except text/html) in the output. This option allows the caller to suppress this behaviour. This is used by notmuch-pick.el (although not needed) because it gives a speed-up of at least a factor of a two; moreover it reduces the memory usage in emacs hugely. This commit just implements it for --format-json. The next commit adds it for --format=text. The option does not make sense for --format=raw or --format=mbox. --- This patch is a little bigger than I would like but a lot of it is code movement. notmuch-client.h | 3 ++- notmuch-reply.c | 2 +- notmuch-show.c | 44 +++++++++++++++++++++++++------------------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index 0c17b79..edb356d 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -87,6 +87,7 @@ typedef struct notmuch_crypto { typedef struct notmuch_show_params { notmuch_bool_t entire_thread; notmuch_bool_t omit_excluded; + notmuch_bool_t include_text_content; notmuch_bool_t raw; int part; notmuch_crypto_t crypto; @@ -176,7 +177,7 @@ notmuch_status_t show_one_part (const char *filename, int part); void -format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first); +format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notmuch_bool_t include_text_content); void format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply); diff --git a/notmuch-reply.c b/notmuch-reply.c index 3a038ed..de21f3b 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -620,7 +620,7 @@ notmuch_reply_format_json(void *ctx, /* Start the original */ printf (", \"original\": "); - format_part_json (ctx, node, TRUE); + format_part_json (ctx, node, TRUE, TRUE); /* End */ printf ("}\n"); diff --git a/notmuch-show.c b/notmuch-show.c index 8f3c60e..35e3f22 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -559,7 +559,7 @@ format_part_text (const void *ctx, mime_node_t *node, } void -format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first) +format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notmuch_bool_t include_text_content) { /* Any changes to the JSON format should be reflected in the file * devel/schemata. */ @@ -572,7 +572,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first) format_headers_json (ctx, GMIME_MESSAGE (node->part), FALSE); printf (", \"body\": ["); - format_part_json (ctx, mime_node_child (node, 0), first); + format_part_json (ctx, mime_node_child (node, 0), first, include_text_content); printf ("]}"); return; @@ -623,19 +623,21 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first) * makes charset decoding the responsibility on the caller, we * report the charset for text/html parts. */ - if (g_mime_content_type_is_type (content_type, "text", "html")) { - const char *content_charset = g_mime_object_get_content_type_parameter (meta, "charset"); - - if (content_charset != NULL) - printf (", \"content-charset\": %s", json_quote_str (local, content_charset)); - } else if (g_mime_content_type_is_type (content_type, "text", "*")) { - GMimeStream *stream_memory = g_mime_stream_mem_new (); - GByteArray *part_content; - show_text_part_content (node->part, stream_memory, 0); - part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory)); - - printf (", \"content\": %s", json_quote_chararray (local, (char *) part_content->data, part_content->len)); - g_object_unref (stream_memory); + if (g_mime_content_type_is_type (content_type, "text", "*")) { + if (g_mime_content_type_is_type (content_type, "text", "html") || !include_text_content) { + const char *content_charset = g_mime_object_get_content_type_parameter (meta, "charset"); + + if (content_charset != NULL) + printf (", \"content-charset\": %s", json_quote_str (local, content_charset)); + } else { + GMimeStream *stream_memory = g_mime_stream_mem_new (); + GByteArray *part_content; + show_text_part_content (node->part, stream_memory, 0); + part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory)); + + printf (", \"content\": %s", json_quote_chararray (local, (char *) part_content->data, part_content->len)); + g_object_unref (stream_memory); + } } } else if (GMIME_IS_MULTIPART (node->part)) { printf (", \"content\": ["); @@ -652,17 +654,16 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first) talloc_free (local); for (i = 0; i < node->nchildren; i++) - format_part_json (ctx, mime_node_child (node, i), i == 0); + format_part_json (ctx, mime_node_child (node, i), i == 0, include_text_content); printf ("%s}", terminator); } static notmuch_status_t format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent), - unused (const notmuch_show_params_t *params)) + const notmuch_show_params_t *params) { - format_part_json (ctx, node, TRUE); - + format_part_json (ctx, node, TRUE, params->include_text_content); return NOTMUCH_STATUS_SUCCESS; } @@ -1004,6 +1005,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) notmuch_show_params_t params = { .part = -1, .omit_excluded = TRUE, + .include_text_content = TRUE, .crypto = { .verify = FALSE, .decrypt = FALSE @@ -1032,6 +1034,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) { NOTMUCH_OPT_INT, ¶ms.part, "part", 'p', 0 }, { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 }, { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.verify, "verify", 'v', 0 }, + { NOTMUCH_OPT_BOOLEAN, ¶ms.include_text_content, "include-text-content", 'h', 0 }, { 0, 0, 0, 0, 0 } }; @@ -1086,6 +1089,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) entire_thread = ENTIRE_THREAD_FALSE; } + if (!params.include_text_content && (format == &format_mbox || format == &format_raw)) + fprintf (stderr, "Warning: --include_text_content=false only makes sense for format=json and format=text\n"); + if (entire_thread == ENTIRE_THREAD_TRUE) params.entire_thread = TRUE; else -- 1.7.9.1