1 Return-Path: <markwalters1009@gmail.com>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 706CB431FAF
\r
6 for <notmuch@notmuchmail.org>; Sun, 22 Jul 2012 07:38:10 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,
\r
14 RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
15 Received: from olra.theworths.org ([127.0.0.1])
\r
16 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id XrQcWDvBD+K1 for <notmuch@notmuchmail.org>;
\r
18 Sun, 22 Jul 2012 07:38:09 -0700 (PDT)
\r
19 Received: from mail-we0-f181.google.com (mail-we0-f181.google.com
\r
20 [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
21 (No client certificate requested)
\r
22 by olra.theworths.org (Postfix) with ESMTPS id 1AB93431FB6
\r
23 for <notmuch@notmuchmail.org>; Sun, 22 Jul 2012 07:38:08 -0700 (PDT)
\r
24 Received: by weyt57 with SMTP id t57so4152717wey.26
\r
25 for <notmuch@notmuchmail.org>; Sun, 22 Jul 2012 07:38:07 -0700 (PDT)
\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
27 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
\r
28 bh=WxQV6UtEotngWGGZbw30C4kjGtLNTPAcUGHlh0yhXZY=;
\r
29 b=XpZ9LvOj86Bfcm6kM/s8QCAum+DNKRI9xfTUtzqhpZK6S7+xzgacyNMFHyC0fYYJnh
\r
30 G4uLUHIIvppO9EgzKL+7TqXVvQIOGiSTTaPXBAafBiuO6eN9d1BsZfQjJKG0uL14swpu
\r
31 /MmnH2BptztHf8FyOn5MbaSRWv9ogtCFC+a/BaZvP0ihaXSPlzIcl1pPCo1+93LBh1tk
\r
32 pyrEuuImmrx6CcSlPVYJugAv5O9/jptJSZclfSwqwfXy7x+4WRosOfZ8g5vg2rRcJgsK
\r
33 2FBfLb7jzWuvHF25mp46yRugjJJJVewGKeNqRemy20z8snpISxkY5oW61ZEdN0h/Rc5T
\r
35 Received: by 10.180.19.169 with SMTP id g9mr40654543wie.9.1342967887808;
\r
36 Sun, 22 Jul 2012 07:38:07 -0700 (PDT)
\r
37 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.
\r
38 [94.192.233.223]) by mx.google.com with ESMTPS id
\r
39 cu1sm11318472wib.6.2012.07.22.07.38.06 (version=TLSv1/SSLv3 cipher=OTHER);
\r
40 Sun, 22 Jul 2012 07:38:06 -0700 (PDT)
\r
41 From: Mark Walters <markwalters1009@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [PATCH 1/4] cli: show: add --include-text-content=true|false option
\r
44 Date: Sun, 22 Jul 2012 15:37:56 +0100
\r
45 Message-Id: <1342967879-20453-2-git-send-email-markwalters1009@gmail.com>
\r
46 X-Mailer: git-send-email 1.7.9.1
\r
47 In-Reply-To: <1342967879-20453-1-git-send-email-markwalters1009@gmail.com>
\r
48 References: <1342967879-20453-1-git-send-email-markwalters1009@gmail.com>
\r
49 X-BeenThere: notmuch@notmuchmail.org
\r
50 X-Mailman-Version: 2.1.13
\r
52 List-Id: "Use and development of the notmuch mail system."
\r
53 <notmuch.notmuchmail.org>
\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
57 List-Post: <mailto:notmuch@notmuchmail.org>
\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
61 X-List-Received-Date: Sun, 22 Jul 2012 14:38:10 -0000
\r
63 Normally notmuch show includes any text/* parts (except text/html) in
\r
64 the output. This option allows the caller to suppress this behaviour.
\r
66 This is used by notmuch-pick.el (although not needed) because it gives
\r
67 a speed-up of at least a factor of a two; moreover it reduces the
\r
68 memory usage in emacs hugely.
\r
70 This commit just implements it for --format-json. The next commit adds
\r
71 it for --format=text. The option does not make sense for --format=raw
\r
75 This patch is a little bigger than I would like but a lot of it is code movement.
\r
77 notmuch-client.h | 3 ++-
\r
78 notmuch-reply.c | 2 +-
\r
79 notmuch-show.c | 44 +++++++++++++++++++++++++-------------------
\r
80 3 files changed, 28 insertions(+), 21 deletions(-)
\r
82 diff --git a/notmuch-client.h b/notmuch-client.h
\r
83 index 0c17b79..edb356d 100644
\r
84 --- a/notmuch-client.h
\r
85 +++ b/notmuch-client.h
\r
86 @@ -87,6 +87,7 @@ typedef struct notmuch_crypto {
\r
87 typedef struct notmuch_show_params {
\r
88 notmuch_bool_t entire_thread;
\r
89 notmuch_bool_t omit_excluded;
\r
90 + notmuch_bool_t include_text_content;
\r
93 notmuch_crypto_t crypto;
\r
94 @@ -176,7 +177,7 @@ notmuch_status_t
\r
95 show_one_part (const char *filename, int part);
\r
98 -format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first);
\r
99 +format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notmuch_bool_t include_text_content);
\r
102 format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply);
\r
103 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
104 index 3a038ed..de21f3b 100644
\r
105 --- a/notmuch-reply.c
\r
106 +++ b/notmuch-reply.c
\r
107 @@ -620,7 +620,7 @@ notmuch_reply_format_json(void *ctx,
\r
108 /* Start the original */
\r
109 printf (", \"original\": ");
\r
111 - format_part_json (ctx, node, TRUE);
\r
112 + format_part_json (ctx, node, TRUE, TRUE);
\r
116 diff --git a/notmuch-show.c b/notmuch-show.c
\r
117 index 8f3c60e..35e3f22 100644
\r
118 --- a/notmuch-show.c
\r
119 +++ b/notmuch-show.c
\r
120 @@ -559,7 +559,7 @@ format_part_text (const void *ctx, mime_node_t *node,
\r
124 -format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
\r
125 +format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notmuch_bool_t include_text_content)
\r
127 /* Any changes to the JSON format should be reflected in the file
\r
128 * devel/schemata. */
\r
129 @@ -572,7 +572,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
\r
130 format_headers_json (ctx, GMIME_MESSAGE (node->part), FALSE);
\r
132 printf (", \"body\": [");
\r
133 - format_part_json (ctx, mime_node_child (node, 0), first);
\r
134 + format_part_json (ctx, mime_node_child (node, 0), first, include_text_content);
\r
138 @@ -623,19 +623,21 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
\r
139 * makes charset decoding the responsibility on the caller, we
\r
140 * report the charset for text/html parts.
\r
142 - if (g_mime_content_type_is_type (content_type, "text", "html")) {
\r
143 - const char *content_charset = g_mime_object_get_content_type_parameter (meta, "charset");
\r
145 - if (content_charset != NULL)
\r
146 - printf (", \"content-charset\": %s", json_quote_str (local, content_charset));
\r
147 - } else if (g_mime_content_type_is_type (content_type, "text", "*")) {
\r
148 - GMimeStream *stream_memory = g_mime_stream_mem_new ();
\r
149 - GByteArray *part_content;
\r
150 - show_text_part_content (node->part, stream_memory, 0);
\r
151 - part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));
\r
153 - printf (", \"content\": %s", json_quote_chararray (local, (char *) part_content->data, part_content->len));
\r
154 - g_object_unref (stream_memory);
\r
155 + if (g_mime_content_type_is_type (content_type, "text", "*")) {
\r
156 + if (g_mime_content_type_is_type (content_type, "text", "html") || !include_text_content) {
\r
157 + const char *content_charset = g_mime_object_get_content_type_parameter (meta, "charset");
\r
159 + if (content_charset != NULL)
\r
160 + printf (", \"content-charset\": %s", json_quote_str (local, content_charset));
\r
162 + GMimeStream *stream_memory = g_mime_stream_mem_new ();
\r
163 + GByteArray *part_content;
\r
164 + show_text_part_content (node->part, stream_memory, 0);
\r
165 + part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));
\r
167 + printf (", \"content\": %s", json_quote_chararray (local, (char *) part_content->data, part_content->len));
\r
168 + g_object_unref (stream_memory);
\r
171 } else if (GMIME_IS_MULTIPART (node->part)) {
\r
172 printf (", \"content\": [");
\r
173 @@ -652,17 +654,16 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
\r
174 talloc_free (local);
\r
176 for (i = 0; i < node->nchildren; i++)
\r
177 - format_part_json (ctx, mime_node_child (node, i), i == 0);
\r
178 + format_part_json (ctx, mime_node_child (node, i), i == 0, include_text_content);
\r
180 printf ("%s}", terminator);
\r
183 static notmuch_status_t
\r
184 format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent),
\r
185 - unused (const notmuch_show_params_t *params))
\r
186 + const notmuch_show_params_t *params)
\r
188 - format_part_json (ctx, node, TRUE);
\r
190 + format_part_json (ctx, node, TRUE, params->include_text_content);
\r
191 return NOTMUCH_STATUS_SUCCESS;
\r
194 @@ -1004,6 +1005,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
195 notmuch_show_params_t params = {
\r
197 .omit_excluded = TRUE,
\r
198 + .include_text_content = TRUE,
\r
202 @@ -1032,6 +1034,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
203 { NOTMUCH_OPT_INT, ¶ms.part, "part", 'p', 0 },
\r
204 { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 },
\r
205 { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.verify, "verify", 'v', 0 },
\r
206 + { NOTMUCH_OPT_BOOLEAN, ¶ms.include_text_content, "include-text-content", 'h', 0 },
\r
210 @@ -1086,6 +1089,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
211 entire_thread = ENTIRE_THREAD_FALSE;
\r
214 + if (!params.include_text_content && (format == &format_mbox || format == &format_raw))
\r
215 + fprintf (stderr, "Warning: --include_text_content=false only makes sense for format=json and format=text\n");
\r
217 if (entire_thread == ENTIRE_THREAD_TRUE)
\r
218 params.entire_thread = TRUE;
\r