From: Peter Wang <novalazy@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 2/3] show: indicate length, encoding of omitted body content
Date: Wed, 8 Aug 2012 22:27:51 +1000 [thread overview]
Message-ID: <1344428872-12374-3-git-send-email-novalazy@gmail.com> (raw)
In-Reply-To: <1344428872-12374-1-git-send-email-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 9cb25f5..094b9a5 100644
--- a/devel/schemata
+++ b/devel/schemata
@@ -69,7 +69,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_json with reply = FALSE)
diff --git a/notmuch-show.c b/notmuch-show.c
index 3556293..83535c7 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -664,6 +664,20 @@ format_part_json (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.4.4
next prev parent reply other threads:[~2012-08-08 12:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-08 12:27 [PATCH v2 0/3] indicate length of omitted body content Peter Wang
2012-08-08 12:27 ` [PATCH v2 1/3] test: normalize only message filenames in show json Peter Wang
2012-08-08 12:27 ` Peter Wang [this message]
2012-08-08 12:27 ` [PATCH v2 3/3] test: conform to content length, encoding fields Peter Wang
2012-10-20 2:21 ` Ethan Glasser-Camp
2012-10-21 3:03 ` Peter Wang
2012-10-21 3:04 ` [PATCH v3] " Peter Wang
2012-10-21 12:53 ` Ethan Glasser-Camp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1344428872-12374-3-git-send-email-novalazy@gmail.com \
--to=novalazy@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).