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 D93C8431FBC for ; Sun, 9 Dec 2012 04:56:51 -0800 (PST) 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 6bnfQ+mzvRyv for ; Sun, 9 Dec 2012 04:56:51 -0800 (PST) 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 5D272431FC3 for ; Sun, 9 Dec 2012 04:56:50 -0800 (PST) Received: by mail-we0-f181.google.com with SMTP id t11so944344wey.26 for ; Sun, 09 Dec 2012 04:56:49 -0800 (PST) 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=MuL89o8iMJ9QLiyeRpfRkiaik0CYpwP4Py4A4kO8ryU=; b=fF8VzdJjZiDb+SCqgcIrASSUSQETzHxTpipei+u/Za5BmONwoWE1gco/PzFt8PaPAp VTssXfE90CQRpp7SU1q5w9i4HXVSljb2WEPhOXogj7uY9E8hO9+R5oYW8TBRpXzmPEH5 UuSjY0OwNZDgYiPGBMCsI2lcfVQauCvpMi5NewFdKn7bmRT4rD7ezaTd+2BS5Mf0C6E2 2wUnQtJCenjFM2up5L51rgVHYTclRlDCHg25vOwExPoejsJQ7VfEduKLEqjnnCRgppe+ f0SbjY6QlyDimzVfSHJuj8s+CXbG8ukLvb24svy3ejbuRbisfi4p/vDOdGtjDEmHzgl1 HMuw== Received: by 10.216.228.150 with SMTP id f22mr4167859weq.45.1355057809211; Sun, 09 Dec 2012 04:56:49 -0800 (PST) Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) by mx.google.com with ESMTPS id bz12sm6802996wib.5.2012.12.09.04.56.47 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 09 Dec 2012 04:56:48 -0800 (PST) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH v4 2/3] show: indicate length, encoding of omitted body content Date: Sun, 9 Dec 2012 12:56:35 +0000 Message-Id: <1355057796-19260-3-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1355057796-19260-1-git-send-email-markwalters1009@gmail.com> References: <1355057796-19260-1-git-send-email-markwalters1009@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: Sun, 09 Dec 2012 12:56:52 -0000 From: Peter Wang 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 d1ab983..7d167be 100644 --- a/devel/schemata +++ b/devel/schemata @@ -75,7 +75,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_sprinter with reply = FALSE) diff --git a/notmuch-show.c b/notmuch-show.c index a83fef9..4aeb949 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -692,6 +692,20 @@ format_part_sprinter (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.9.1