]> git.notmuchmail.org Git - notmuch/commitdiff
cli: add --body=true|false option to notmuch-show.c
authorMark Walters <markwalters1009@gmail.com>
Tue, 24 Jul 2012 18:23:27 +0000 (19:23 +0100)
committerDavid Bremner <bremner@debian.org>
Tue, 24 Jul 2012 18:29:22 +0000 (15:29 -0300)
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
notmuch-reply.c
notmuch-show.c

index 0c17b7910cca72e3ea44f87305a43f39a6a826ba..f9307989878b4724de489f6862bea2763e4595d2 100644 (file)
@@ -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);
index 3a038ed75a06c0a4f76a847f344fec4c94641d53..de21f3b2e8660755ee38b3cd8b2c83e8a586cbfc 100644 (file)
@@ -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");
index 8f3c60e9882cd7aae718a8c27a50cc8cfe999569..d3419e4e84741cd3b6faaaef0057b1c5618996e9 100644 (file)
@@ -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, &params.part, "part", 'p', 0 },
        { NOTMUCH_OPT_BOOLEAN, &params.crypto.decrypt, "decrypt", 'd', 0 },
        { NOTMUCH_OPT_BOOLEAN, &params.crypto.verify, "verify", 'v', 0 },
+       { NOTMUCH_OPT_BOOLEAN, &params.output_body, "body", 'b', 0 },
        { 0, 0, 0, 0, 0 }
     };
 
@@ -1086,6 +1090,16 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
            entire_thread = ENTIRE_THREAD_FALSE;
     }
 
+    if (!params.output_body) {
+       if (params.part > 0) {
+           fprintf (stderr, "Warning: --body=false is incompatible with --part > 0. Disabling.\n");
+           params.output_body = TRUE;
+       } else {
+           if (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