From: Peter Wang Date: Wed, 8 Aug 2012 12:27:51 +0000 (+1000) Subject: [PATCH v2 2/3] show: indicate length, encoding of omitted body content X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=f9da5cd0d0664a1eac476996e15e6149b2bba317;p=notmuch-archives.git [PATCH v2 2/3] show: indicate length, encoding of omitted body content --- diff --git a/4f/e27af17077e60dada448347cca77d65d01dada b/4f/e27af17077e60dada448347cca77d65d01dada new file mode 100644 index 000000000..de5a44010 --- /dev/null +++ b/4f/e27af17077e60dada448347cca77d65d01dada @@ -0,0 +1,124 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 967CF431FC4 + for ; Wed, 8 Aug 2012 05:28:25 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.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 FD9d60CSRvMX for ; + Wed, 8 Aug 2012 05:28:24 -0700 (PDT) +Received: from mail-yw0-f53.google.com (mail-yw0-f53.google.com + [209.85.213.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id C0C37431FBD + for ; Wed, 8 Aug 2012 05:28:24 -0700 (PDT) +Received: by yhp3 with SMTP id 3so871195yhp.26 + for ; Wed, 08 Aug 2012 05:28:24 -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:in-reply-to:references; + bh=+6el5QPikyaRHb8vgWyrFFSMafDBv36k5Jubb3Yx4G4=; + b=oCmcSjoF+2YaYXUFY1lzbl6YHZf5bewvmSInt05OzN/0wvvHFcwHejnaiU47XLAuac + XopjBoAgfjoxbCCGUaa3/oEGh+nXynJfTRW+VFQg/61ammxqGyAh3snxN+HNA52jKoXO + NB5/S1zaRvu4Y9H+vUo97sY0kjxFaXbdr9XwTjDYOiCdr1Z4aOgXpLgb6+/jzN2gb4kl + LA9tqAysMNifyaN43LkcFv0JKkXJUQV4Xxyzneh9LdiD/neTBwOeW0soEx0nB0UlqmqV + 9P3tqG5lLkcEHcmAUguAvKmGWYN8eN5kS3YzCG5NK91Ml6h6hI8MS09riCjcBfxM0qt1 + 17rQ== +Received: by 10.66.74.67 with SMTP id r3mr16407380pav.1.1344428903822; + Wed, 08 Aug 2012 05:28:23 -0700 (PDT) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id ng8sm13320094pbc.13.2012.08.08.05.28.21 + (version=TLSv1/SSLv3 cipher=OTHER); + Wed, 08 Aug 2012 05:28:22 -0700 (PDT) +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: [PATCH v2 2/3] show: indicate length, encoding of omitted body + content +Date: Wed, 8 Aug 2012 22:27:51 +1000 +Message-Id: <1344428872-12374-3-git-send-email-novalazy@gmail.com> +X-Mailer: git-send-email 1.7.4.4 +In-Reply-To: <1344428872-12374-1-git-send-email-novalazy@gmail.com> +References: <1344428872-12374-1-git-send-email-novalazy@gmail.com> +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: Wed, 08 Aug 2012 12:28:25 -0000 + +If a leaf part's body content is omitted, return the encoded length and +transfer encoding in --format=json output. This information may be used +by the consumer, e.g. to decide whether to download a large attachment +over a slow link. + +Returning the _encoded_ content length is more efficient than returning +the _decoded_ content length. Returning the transfer encoding allows +the consumer to estimate the decoded content length. +--- + devel/schemata | 9 ++++++++- + notmuch-show.c | 14 ++++++++++++++ + 2 files changed, 22 insertions(+), 1 deletions(-) + +diff --git a/devel/schemata b/devel/schemata +index 9cb25f5..094b9a5 100644 +--- a/devel/schemata ++++ b/devel/schemata +@@ -69,7 +69,14 @@ part = { + # A leaf part's body content is optional, but may be included if + # it can be correctly encoded as a string. Consumers should use + # this in preference to fetching the part content separately. +- content?: string ++ content?: string, ++ # If a leaf part's body content is not included, the length of ++ # the encoded content (in bytes) may be given instead. ++ content-length?: int, ++ # If a leaf part's body content is not included, its transfer encoding ++ # may be given. Using this and the encoded content length, it is ++ # possible for the consumer to estimate the decoded content length. ++ content-transfer-encoding?: string + } + + # The headers of a message or part (format_headers_json with reply = FALSE) +diff --git a/notmuch-show.c b/notmuch-show.c +index 3556293..83535c7 100644 +--- a/notmuch-show.c ++++ b/notmuch-show.c +@@ -664,6 +664,20 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node, + sp->map_key (sp, "content"); + sp->string_len (sp, (char *) part_content->data, part_content->len); + g_object_unref (stream_memory); ++ } else { ++ GMimeDataWrapper *wrapper = g_mime_part_get_content_object (GMIME_PART (node->part)); ++ GMimeStream *stream = g_mime_data_wrapper_get_stream (wrapper); ++ ssize_t length = g_mime_stream_length (stream); ++ const char *cte = g_mime_object_get_header (meta, "content-transfer-encoding"); ++ ++ if (length >= 0) { ++ sp->map_key (sp, "content-length"); ++ sp->integer (sp, length); ++ } ++ if (cte) { ++ sp->map_key (sp, "content-transfer-encoding"); ++ sp->string (sp, cte); ++ } + } + } else if (GMIME_IS_MULTIPART (node->part)) { + sp->map_key (sp, "content"); +-- +1.7.4.4 +