[PATCH v4 2/3] show: indicate length, encoding of omitted body content
authorMark Walters <markwalters1009@gmail.com>
Sun, 9 Dec 2012 12:56:35 +0000 (12:56 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:53 +0000 (09:51 -0800)
1f/c186f9eba44bdc4400231386ef982f2c4c70d6 [new file with mode: 0644]

diff --git a/1f/c186f9eba44bdc4400231386ef982f2c4c70d6 b/1f/c186f9eba44bdc4400231386ef982f2c4c70d6
new file mode 100644 (file)
index 0000000..d9d3932
--- /dev/null
@@ -0,0 +1,126 @@
+Return-Path: <markwalters1009@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 D93C8431FBC\r
+       for <notmuch@notmuchmail.org>; Sun,  9 Dec 2012 04:56:51 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       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 6bnfQ+mzvRyv for <notmuch@notmuchmail.org>;\r
+       Sun,  9 Dec 2012 04:56:51 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 5D272431FC3\r
+       for <notmuch@notmuchmail.org>; Sun,  9 Dec 2012 04:56:50 -0800 (PST)\r
+Received: by mail-we0-f181.google.com with SMTP id t11so944344wey.26\r
+       for <notmuch@notmuchmail.org>; Sun, 09 Dec 2012 04:56:49 -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=MuL89o8iMJ9QLiyeRpfRkiaik0CYpwP4Py4A4kO8ryU=;\r
+       b=fF8VzdJjZiDb+SCqgcIrASSUSQETzHxTpipei+u/Za5BmONwoWE1gco/PzFt8PaPAp\r
+       VTssXfE90CQRpp7SU1q5w9i4HXVSljb2WEPhOXogj7uY9E8hO9+R5oYW8TBRpXzmPEH5\r
+       UuSjY0OwNZDgYiPGBMCsI2lcfVQauCvpMi5NewFdKn7bmRT4rD7ezaTd+2BS5Mf0C6E2\r
+       2wUnQtJCenjFM2up5L51rgVHYTclRlDCHg25vOwExPoejsJQ7VfEduKLEqjnnCRgppe+\r
+       f0SbjY6QlyDimzVfSHJuj8s+CXbG8ukLvb24svy3ejbuRbisfi4p/vDOdGtjDEmHzgl1\r
+       HMuw==\r
+Received: by 10.216.228.150 with SMTP id f22mr4167859weq.45.1355057809211;\r
+       Sun, 09 Dec 2012 04:56:49 -0800 (PST)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+       by mx.google.com with ESMTPS id bz12sm6802996wib.5.2012.12.09.04.56.47\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sun, 09 Dec 2012 04:56:48 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 2/3] show: indicate length, encoding of omitted body\r
+ content\r
+Date: Sun,  9 Dec 2012 12:56:35 +0000\r
+Message-Id: <1355057796-19260-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1355057796-19260-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1355057796-19260-1-git-send-email-markwalters1009@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: Sun, 09 Dec 2012 12:56:52 -0000\r
+\r
+From: Peter Wang <novalazy@gmail.com>\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 |   14 ++++++++++++++\r
+ 2 files changed, 22 insertions(+), 1 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 a83fef9..4aeb949 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -692,6 +692,20 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
+           sp->map_key (sp, "content");\r
+           sp->string_len (sp, (char *) part_content->data, part_content->len);\r
+           g_object_unref (stream_memory);\r
++      } else {\r
++          GMimeDataWrapper *wrapper = g_mime_part_get_content_object (GMIME_PART (node->part));\r
++          GMimeStream *stream = g_mime_data_wrapper_get_stream (wrapper);\r
++          ssize_t length = g_mime_stream_length (stream);\r
++          const char *cte = g_mime_object_get_header (meta, "content-transfer-encoding");\r
++\r
++          if (length >= 0) {\r
++              sp->map_key (sp, "content-length");\r
++              sp->integer (sp, length);\r
++          }\r
++          if (cte) {\r
++              sp->map_key (sp, "content-transfer-encoding");\r
++              sp->string (sp, cte);\r
++          }\r
+       }\r
+     } else if (GMIME_IS_MULTIPART (node->part)) {\r
+       sp->map_key (sp, "content");\r
+-- \r
+1.7.9.1\r
+\r