From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 6A483431FAF for ; Sat, 30 Jun 2012 00:33:32 -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 6G9G+crUFEFL for ; Sat, 30 Jun 2012 00:33:31 -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 6B0BB431FAE for ; Sat, 30 Jun 2012 00:33:31 -0700 (PDT) Received: by werl57 with SMTP id l57so922344wer.26 for ; Sat, 30 Jun 2012 00:33:30 -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; bh=x4T7AkT4AOjCLXoge9fwPyfjgdUTULi64dPfTY0MIfI=; b=NRxxH8GkEfCLvpzXWsGPCzzWKzYblBwDipwDp/Hxo7pECkxipxW9JAwzcTzWHlGDGP 61Vk+zVR42tXVKrGQr0APy/qoTtKEZD9ff4DJt9ewx07k5RRHfcnUNTUqPqde3ITc2va OXLuhauuukIGwTuM+pQz63ldHPTZajy8UfPdigFToaW6b8idXQHZ2HVsSkYRi1eAN9ot g1QYFbZ9xnDTj5gQFFjvyGAojcZyEtG3cXJ/qipkbT/LFry7u1utOS5BExviQoM1atmL Dt9jiETwCCStAif90hPMh2EaNwpjduH9QF2KejkVJc6Q1kGe8LBNHdvOerPPcc0imyqW fbaQ== Received: by 10.216.4.147 with SMTP id 19mr2087808wej.109.1341041610006; Sat, 30 Jun 2012 00:33:30 -0700 (PDT) Received: from localhost (94-192-233-223.zone6.bethere.co.uk. [94.192.233.223]) by mx.google.com with ESMTPS id bg10sm18467913wib.9.2012.06.30.00.33.27 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 30 Jun 2012 00:33:28 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH] cli: add --headers_only option to notmuch-show.c Date: Sat, 30 Jun 2012 08:33:15 +0100 Message-Id: <1341041595-5858-1-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.9.1 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: Sat, 30 Jun 2012 07:33:32 -0000 This option just outputs the headers of a message (i.e. it omits the bodies). 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; moreover it reduces the memory usage in emacs hugely. --- Currently notmuch-show outputs on a thread includes all headers and all text/plain parts (more precisely all text/* except text/html): the client has to fetch any other parts it wants. This patch allows notmuch show to just output the headers: omitting all the body parts. Jamie suggested in id:"87zk80ilt9.fsf@servo.finestructure.net" that we always omit all body parts and leave it to the client to fetch them. My feeling is that this could make some uses much slower (a view expressed by Peter in id:"20120620110139.GA2356@hili.localdomain"). What do people think? Best wishes Mark notmuch-client.h | 3 ++- notmuch-reply.c | 2 +- notmuch-show.c | 15 +++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index 0c17b79..17efde2 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 headers_only; 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 headers_only); 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..07c3bef 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, FALSE); /* End */ printf ("}\n"); diff --git a/notmuch-show.c b/notmuch-show.c index 8f3c60e..195e318 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 headers_only) { /* Any changes to the JSON format should be reflected in the file * devel/schemata. */ @@ -572,7 +572,8 @@ 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); + if (!headers_only) + format_part_json (ctx, mime_node_child (node, 0), first, FALSE); printf ("]}"); return; @@ -652,7 +653,7 @@ 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, FALSE); printf ("%s}", terminator); } @@ -661,7 +662,7 @@ 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)) { - format_part_json (ctx, node, TRUE); + format_part_json (ctx, node, TRUE, params->headers_only); return NOTMUCH_STATUS_SUCCESS; } @@ -1010,6 +1011,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) } }; int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED; + notmuch_bool_t headers_only = FALSE; int exclude = EXCLUDE_TRUE; int entire_thread = ENTIRE_THREAD_DEFAULT; @@ -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, &headers_only, "headers-only", 'h', 0 }, { 0, 0, 0, 0, 0 } }; @@ -1086,6 +1089,10 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) entire_thread = ENTIRE_THREAD_FALSE; } + if (headers_only && format != &format_json) + fprintf (stderr,"Warning: --headers-only only implemented for format=json\n"); + params.headers_only = headers_only; + if (entire_thread == ENTIRE_THREAD_TRUE) params.entire_thread = TRUE; else -- 1.7.9.1