[PATCH v5b] show: indicate length, encoding of omitted body content
authorPeter Wang <novalazy@gmail.com>
Sat, 15 Dec 2012 23:24:23 +0000 (10:24 +1100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:21 +0000 (09:52 -0800)
02/857900888d13edd827d2e328bef7c92fc61da9 [new file with mode: 0644]

diff --git a/02/857900888d13edd827d2e328bef7c92fc61da9 b/02/857900888d13edd827d2e328bef7c92fc61da9
new file mode 100644 (file)
index 0000000..9dfda81
--- /dev/null
@@ -0,0 +1,139 @@
+Return-Path: <novalazy@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id CA919431FBD\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:24:32 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id rHcvmNR0Pw1p for <notmuch@notmuchmail.org>;\r
+       Sat, 15 Dec 2012 15:24:32 -0800 (PST)\r
+Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com\r
+       [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 00D8C431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:24:31 -0800 (PST)\r
+Received: by mail-pb0-f53.google.com with SMTP id jt11so2925347pbb.26\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:24:31 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=ZqnfGcqVs0ysqH5ESYtLRuWkZTlowtuQGcGSODeMWag=;\r
+       b=xAbYH05v23uKCBQOHccyOWAg6pUvBgTuFP38IbhElxQSvHx6yTOmuoeGlGbfz3SfsM\r
+       FodcfIbZnB/S23nULYt12jbOlyPHCzR2LC8bAcwzNQCrAeY5FGnDJfdFsncQ60yc9bTE\r
+       Rl6NQV1b8mCi6bi9xJ+FQpTMiW50D08c0uwKAuCdtUO/jN+ZItApjqAL+QiZGoViXB0P\r
+       zsoFT0YGya7L+SvHhdlKSWKyeMpnAACCkTZLPSjm/Q1milPqfb9SKT4YWANSOt8CbScR\r
+       Bsu4D5MDeIJOy8SasrZRVpIAZAdcZh5VfuobMpbSXftgSmr9qSHbre59cO8s26drnh8P\r
+       i+Xw==\r
+Received: by 10.68.245.37 with SMTP id xl5mr28509661pbc.120.1355613871246;\r
+       Sat, 15 Dec 2012 15:24:31 -0800 (PST)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+       [220.233.42.215])\r
+       by mx.google.com with ESMTPS id nm2sm5379595pbc.43.2012.12.15.15.24.28\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 15 Dec 2012 15:24:30 -0800 (PST)\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v5b] show: indicate length, encoding of omitted body content\r
+Date: Sun, 16 Dec 2012 10:24:23 +1100\r
+Message-Id: <1355613863-3833-1-git-send-email-novalazy@gmail.com>\r
+X-Mailer: git-send-email 1.7.12.1\r
+In-Reply-To: <1355540805-24937-4-git-send-email-novalazy@gmail.com>\r
+References: <1355540805-24937-4-git-send-email-novalazy@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 15 Dec 2012 23:24:32 -0000\r
+\r
+If a leaf part's body content is omitted, return the encoded length and\r
+transfer encoding in --format=json output.  This information may be used\r
+by the consumer, e.g. to decide whether to download a large attachment\r
+over a slow link.\r
+\r
+Returning the _encoded_ content length is more efficient than returning\r
+the _decoded_ content length.  Returning the transfer encoding allows\r
+the consumer to estimate the decoded content length.\r
+---\r
+ devel/schemata |  9 ++++++++-\r
+ notmuch-show.c | 16 ++++++++++++++--\r
+ 2 files changed, 22 insertions(+), 3 deletions(-)\r
+\r
+diff --git a/devel/schemata b/devel/schemata\r
+index d1ab983..7d167be 100644\r
+--- a/devel/schemata\r
++++ b/devel/schemata\r
+@@ -75,7 +75,14 @@ part = {\r
+     # A leaf part's body content is optional, but may be included if\r
+     # it can be correctly encoded as a string.  Consumers should use\r
+     # this in preference to fetching the part content separately.\r
+-    content?:       string\r
++    content?:       string,\r
++    # If a leaf part's body content is not included, the length of\r
++    # the encoded content (in bytes) may be given instead.\r
++    content-length?: int,\r
++    # If a leaf part's body content is not included, its transfer encoding\r
++    # may be given.  Using this and the encoded content length, it is\r
++    # possible for the consumer to estimate the decoded content length.\r
++    content-transfer-encoding?: string\r
+ }\r
\r
+ # The headers of a message or part (format_headers_sprinter with reply = FALSE)\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 6a9278c..2d59865 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -600,14 +600,26 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+ }\r
\r
+ static void\r
+-format_omitted_part_meta_sprinter (sprinter_t *sp, GMimeObject *meta)\r
++format_omitted_part_meta_sprinter (sprinter_t *sp, GMimeObject *meta, GMimePart *part)\r
+ {\r
+     const char *content_charset = g_mime_object_get_content_type_parameter (meta, "charset");\r
++    const char *cte = g_mime_object_get_header (meta, "content-transfer-encoding");\r
++    GMimeDataWrapper *wrapper = g_mime_part_get_content_object (part);\r
++    GMimeStream *stream = g_mime_data_wrapper_get_stream (wrapper);\r
++    ssize_t content_length = g_mime_stream_length (stream);\r
\r
+     if (content_charset != NULL) {\r
+       sp->map_key (sp, "content-charset");\r
+       sp->string (sp, content_charset);\r
+     }\r
++    if (cte != NULL) {\r
++      sp->map_key (sp, "content-transfer-encoding");\r
++      sp->string (sp, cte);\r
++    }\r
++    if (content_length >= 0) {\r
++      sp->map_key (sp, "content-length");\r
++      sp->integer (sp, content_length);\r
++    }\r
+ }\r
\r
+ void\r
+@@ -699,7 +711,7 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+           sp->string_len (sp, (char *) part_content->data, part_content->len);\r
+           g_object_unref (stream_memory);\r
+       } else {\r
+-          format_omitted_part_meta_sprinter (sp, meta);\r
++          format_omitted_part_meta_sprinter (sp, meta, GMIME_PART (node->part));\r
+       }\r
+     } else if (GMIME_IS_MULTIPART (node->part)) {\r
+       sp->map_key (sp, "content");\r
+-- \r
+1.7.12.1\r
+\r