[PATCH 2/9] lib: private string map (associative array) API
[notmuch-archives.git] / 1f / c186f9eba44bdc4400231386ef982f2c4c70d6
1 Return-Path: <markwalters1009@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id D93C8431FBC\r
6         for <notmuch@notmuchmail.org>; Sun,  9 Dec 2012 04:56:51 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id 6bnfQ+mzvRyv for <notmuch@notmuchmail.org>;\r
18         Sun,  9 Dec 2012 04:56:51 -0800 (PST)\r
19 Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
20         [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id 5D272431FC3\r
23         for <notmuch@notmuchmail.org>; Sun,  9 Dec 2012 04:56:50 -0800 (PST)\r
24 Received: by mail-we0-f181.google.com with SMTP id t11so944344wey.26\r
25         for <notmuch@notmuchmail.org>; Sun, 09 Dec 2012 04:56:49 -0800 (PST)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
28         bh=MuL89o8iMJ9QLiyeRpfRkiaik0CYpwP4Py4A4kO8ryU=;\r
29         b=fF8VzdJjZiDb+SCqgcIrASSUSQETzHxTpipei+u/Za5BmONwoWE1gco/PzFt8PaPAp\r
30         VTssXfE90CQRpp7SU1q5w9i4HXVSljb2WEPhOXogj7uY9E8hO9+R5oYW8TBRpXzmPEH5\r
31         UuSjY0OwNZDgYiPGBMCsI2lcfVQauCvpMi5NewFdKn7bmRT4rD7ezaTd+2BS5Mf0C6E2\r
32         2wUnQtJCenjFM2up5L51rgVHYTclRlDCHg25vOwExPoejsJQ7VfEduKLEqjnnCRgppe+\r
33         f0SbjY6QlyDimzVfSHJuj8s+CXbG8ukLvb24svy3ejbuRbisfi4p/vDOdGtjDEmHzgl1\r
34         HMuw==\r
35 Received: by 10.216.228.150 with SMTP id f22mr4167859weq.45.1355057809211;\r
36         Sun, 09 Dec 2012 04:56:49 -0800 (PST)\r
37 Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
38         by mx.google.com with ESMTPS id bz12sm6802996wib.5.2012.12.09.04.56.47\r
39         (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Sun, 09 Dec 2012 04:56:48 -0800 (PST)\r
41 From: Mark Walters <markwalters1009@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v4 2/3] show: indicate length, encoding of omitted body\r
44  content\r
45 Date: Sun,  9 Dec 2012 12:56:35 +0000\r
46 Message-Id: <1355057796-19260-3-git-send-email-markwalters1009@gmail.com>\r
47 X-Mailer: git-send-email 1.7.9.1\r
48 In-Reply-To: <1355057796-19260-1-git-send-email-markwalters1009@gmail.com>\r
49 References: <1355057796-19260-1-git-send-email-markwalters1009@gmail.com>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Sun, 09 Dec 2012 12:56:52 -0000\r
63 \r
64 From: Peter Wang <novalazy@gmail.com>\r
65 \r
66 If a leaf part's body content is omitted, return the encoded length and\r
67 transfer encoding in --format=json output.  This information may be used\r
68 by the consumer, e.g. to decide whether to download a large attachment\r
69 over a slow link.\r
70 \r
71 Returning the _encoded_ content length is more efficient than returning\r
72 the _decoded_ content length.  Returning the transfer encoding allows\r
73 the consumer to estimate the decoded content length.\r
74 ---\r
75  devel/schemata |    9 ++++++++-\r
76  notmuch-show.c |   14 ++++++++++++++\r
77  2 files changed, 22 insertions(+), 1 deletions(-)\r
78 \r
79 diff --git a/devel/schemata b/devel/schemata\r
80 index d1ab983..7d167be 100644\r
81 --- a/devel/schemata\r
82 +++ b/devel/schemata\r
83 @@ -75,7 +75,14 @@ part = {\r
84      # A leaf part's body content is optional, but may be included if\r
85      # it can be correctly encoded as a string.  Consumers should use\r
86      # this in preference to fetching the part content separately.\r
87 -    content?:       string\r
88 +    content?:       string,\r
89 +    # If a leaf part's body content is not included, the length of\r
90 +    # the encoded content (in bytes) may be given instead.\r
91 +    content-length?: int,\r
92 +    # If a leaf part's body content is not included, its transfer encoding\r
93 +    # may be given.  Using this and the encoded content length, it is\r
94 +    # possible for the consumer to estimate the decoded content length.\r
95 +    content-transfer-encoding?: string\r
96  }\r
97  \r
98  # The headers of a message or part (format_headers_sprinter with reply = FALSE)\r
99 diff --git a/notmuch-show.c b/notmuch-show.c\r
100 index a83fef9..4aeb949 100644\r
101 --- a/notmuch-show.c\r
102 +++ b/notmuch-show.c\r
103 @@ -692,6 +692,20 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
104             sp->map_key (sp, "content");\r
105             sp->string_len (sp, (char *) part_content->data, part_content->len);\r
106             g_object_unref (stream_memory);\r
107 +       } else {\r
108 +           GMimeDataWrapper *wrapper = g_mime_part_get_content_object (GMIME_PART (node->part));\r
109 +           GMimeStream *stream = g_mime_data_wrapper_get_stream (wrapper);\r
110 +           ssize_t length = g_mime_stream_length (stream);\r
111 +           const char *cte = g_mime_object_get_header (meta, "content-transfer-encoding");\r
112 +\r
113 +           if (length >= 0) {\r
114 +               sp->map_key (sp, "content-length");\r
115 +               sp->integer (sp, length);\r
116 +           }\r
117 +           if (cte) {\r
118 +               sp->map_key (sp, "content-transfer-encoding");\r
119 +               sp->string (sp, cte);\r
120 +           }\r
121         }\r
122      } else if (GMIME_IS_MULTIPART (node->part)) {\r
123         sp->map_key (sp, "content");\r
124 -- \r
125 1.7.9.1\r
126 \r