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 CA919431FBD for ; Sat, 15 Dec 2012 15:24:32 -0800 (PST) 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 rHcvmNR0Pw1p for ; Sat, 15 Dec 2012 15:24:32 -0800 (PST) Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 00D8C431FB6 for ; Sat, 15 Dec 2012 15:24:31 -0800 (PST) Received: by mail-pb0-f53.google.com with SMTP id jt11so2925347pbb.26 for ; Sat, 15 Dec 2012 15:24:31 -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=ZqnfGcqVs0ysqH5ESYtLRuWkZTlowtuQGcGSODeMWag=; b=xAbYH05v23uKCBQOHccyOWAg6pUvBgTuFP38IbhElxQSvHx6yTOmuoeGlGbfz3SfsM FodcfIbZnB/S23nULYt12jbOlyPHCzR2LC8bAcwzNQCrAeY5FGnDJfdFsncQ60yc9bTE Rl6NQV1b8mCi6bi9xJ+FQpTMiW50D08c0uwKAuCdtUO/jN+ZItApjqAL+QiZGoViXB0P zsoFT0YGya7L+SvHhdlKSWKyeMpnAACCkTZLPSjm/Q1milPqfb9SKT4YWANSOt8CbScR Bsu4D5MDeIJOy8SasrZRVpIAZAdcZh5VfuobMpbSXftgSmr9qSHbre59cO8s26drnh8P i+Xw== Received: by 10.68.245.37 with SMTP id xl5mr28509661pbc.120.1355613871246; Sat, 15 Dec 2012 15:24:31 -0800 (PST) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id nm2sm5379595pbc.43.2012.12.15.15.24.28 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 15 Dec 2012 15:24:30 -0800 (PST) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH v5b] show: indicate length, encoding of omitted body content Date: Sun, 16 Dec 2012 10:24:23 +1100 Message-Id: <1355613863-3833-1-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1355540805-24937-4-git-send-email-novalazy@gmail.com> References: <1355540805-24937-4-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: Sat, 15 Dec 2012 23:24:32 -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 | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 3 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 6a9278c..2d59865 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -600,14 +600,26 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, } static void -format_omitted_part_meta_sprinter (sprinter_t *sp, GMimeObject *meta) +format_omitted_part_meta_sprinter (sprinter_t *sp, GMimeObject *meta, GMimePart *part) { const char *content_charset = g_mime_object_get_content_type_parameter (meta, "charset"); + const char *cte = g_mime_object_get_header (meta, "content-transfer-encoding"); + GMimeDataWrapper *wrapper = g_mime_part_get_content_object (part); + GMimeStream *stream = g_mime_data_wrapper_get_stream (wrapper); + ssize_t content_length = g_mime_stream_length (stream); if (content_charset != NULL) { sp->map_key (sp, "content-charset"); sp->string (sp, content_charset); } + if (cte != NULL) { + sp->map_key (sp, "content-transfer-encoding"); + sp->string (sp, cte); + } + if (content_length >= 0) { + sp->map_key (sp, "content-length"); + sp->integer (sp, content_length); + } } void @@ -699,7 +711,7 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node, sp->string_len (sp, (char *) part_content->data, part_content->len); g_object_unref (stream_memory); } else { - format_omitted_part_meta_sprinter (sp, meta); + format_omitted_part_meta_sprinter (sp, meta, GMIME_PART (node->part)); } } else if (GMIME_IS_MULTIPART (node->part)) { sp->map_key (sp, "content"); -- 1.7.12.1