From: Peter Wang <novalazy@gmail.com> 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