X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=notmuch-show.c;h=d3419e4e84741cd3b6faaaef0057b1c5618996e9;hb=4cedb2a3ea77b61a5d8e9fe56e8585d312ee96ca;hp=e6eb625d7f16d907b7722a8d2d3472311c500d88;hpb=15904cde125d317c7e59923104e270c6fbe502f7;p=notmuch diff --git a/notmuch-show.c b/notmuch-show.c index e6eb625d..d3419e4e 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 @@ -1020,10 +1023,10 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) { "mbox", NOTMUCH_FORMAT_MBOX }, { "raw", NOTMUCH_FORMAT_RAW }, { 0, 0 } } }, - { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x', - (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE }, - { "false", EXCLUDE_FALSE }, - { 0, 0 } } }, + { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x', + (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE }, + { "false", EXCLUDE_FALSE }, + { 0, 0 } } }, { NOTMUCH_OPT_KEYWORD, &entire_thread, "entire-thread", 't', (notmuch_keyword_t []){ { "true", ENTIRE_THREAD_TRUE }, { "false", ENTIRE_THREAD_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", '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