From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/4] cli: add --body=true|false option to notmuch-show.c
Date: Mon, 23 Jul 2012 17:17:18 +0100 [thread overview]
Message-ID: <1343060241-18283-2-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1343060241-18283-1-git-send-email-markwalters1009@gmail.com>
This option allows the caller to suppress the output of the bodies of
the messages. Currently this is only implemented for format=json.
This is used by notmuch-pick.el (although not needed) because it gives
a speed-up of at least a factor of a two (and in some cases a speed up
of more than a factor of 8); moreover it reduces the memory usage in
emacs hugely.
---
notmuch-client.h | 3 ++-
notmuch-reply.c | 2 +-
notmuch-show.c | 23 +++++++++++++++--------
3 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/notmuch-client.h b/notmuch-client.h
index 0c17b79..f930798 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 output_body;
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 output_body);
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..c2ad4fb 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 output_body)
{
/* Any changes to the JSON format should be reflected in the file
* devel/schemata. */
@@ -571,10 +571,12 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)
printf ("\"headers\": ");
format_headers_json (ctx, GMIME_MESSAGE (node->part), FALSE);
- printf (", \"body\": [");
- format_part_json (ctx, mime_node_child (node, 0), first);
-
- printf ("]}");
+ if (output_body) {
+ printf (", \"body\": [");
+ format_part_json (ctx, mime_node_child (node, 0), first, TRUE);
+ printf ("]");
+ }
+ printf ("}");
return;
}
@@ -652,16 +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, TRUE);
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->output_body);
return NOTMUCH_STATUS_SUCCESS;
}
@@ -1004,6 +1006,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
notmuch_show_params_t params = {
.part = -1,
.omit_excluded = TRUE,
+ .output_body = TRUE,
.crypto = {
.verify = FALSE,
.decrypt = FALSE
@@ -1032,6 +1035,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.output_body, "body", 'h', 0 },
{ 0, 0, 0, 0, 0 }
};
@@ -1086,6 +1090,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
entire_thread = ENTIRE_THREAD_FALSE;
}
+ if (!params.output_body && format != &format_json)
+ fprintf (stderr,"Warning: --body=false only implemented for format=json\n");
+
if (entire_thread == ENTIRE_THREAD_TRUE)
params.entire_thread = TRUE;
else
--
1.7.9.1
next prev parent reply other threads:[~2012-07-23 16:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-23 16:17 [PATCH 0/4] Add a --body option to notmuch show Mark Walters
2012-07-23 16:17 ` Mark Walters [this message]
2012-07-23 16:43 ` [PATCH 1/4] cli: add --body=true|false option to notmuch-show.c Austin Clements
2012-07-23 16:17 ` [PATCH 2/4] test: add tests for the new --body=true|false option Mark Walters
2012-07-23 16:17 ` [PATCH 3/4] man: update man page " Mark Walters
2012-07-23 16:52 ` Austin Clements
2012-07-23 16:17 ` [PATCH 4/4] schemata: update for " Mark Walters
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343060241-18283-2-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).