diff options
author | Peter Wang <novalazy@gmail.com> | 2012-12-16 10:24:23 +1100 |
---|---|---|
committer | David Bremner <bremner@debian.org> | 2012-12-17 09:10:35 -0400 |
commit | b96ba6326af442edfdad59e5e42ea42892cd3c6b (patch) | |
tree | a41fa759c3db924e080b30671983ec7a3a883a26 /notmuch-show.c | |
parent | 35860e00d1a1f1c4116b03a23c2bbeb0089aa4a1 (diff) |
show: indicate length, encoding of omitted body content
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.
Diffstat (limited to 'notmuch-show.c')
-rw-r--r-- | notmuch-show.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/notmuch-show.c b/notmuch-show.c index 7234caa7..cbfc2d1c 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"); |