]> git.notmuchmail.org Git - notmuch/commitdiff
show: indicate length, encoding of omitted body content
authorPeter Wang <novalazy@gmail.com>
Sat, 15 Dec 2012 23:24:23 +0000 (10:24 +1100)
committerDavid Bremner <bremner@debian.org>
Mon, 17 Dec 2012 13:10:35 +0000 (09:10 -0400)
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
notmuch-show.c

index 292f2876868063f4b8a54aae0be33cd46b457cbe..2405756e43a724ca3f2d2fc576710afc34e8046f 100644 (file)
@@ -77,7 +77,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.
     # 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)
 }
 
 # The headers of a message or part (format_headers_sprinter with reply = FALSE)
index 7234caa7827ab15c35ea66d7b371dfbdd0ae0bc6..cbfc2d1cb6efb28a4202c5053fd6d22d0ad58b69 100644 (file)
@@ -600,14 +600,26 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
 }
 
 static void
 }
 
 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 *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 (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
 }
 
 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 {
            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");
        }
     } else if (GMIME_IS_MULTIPART (node->part)) {
        sp->map_key (sp, "content");