[PATCH 3/4] show: indicate length of omitted body content (text)
Peter Wang
novalazy at gmail.com
Sun Aug 5 00:22:24 PDT 2012
If a leaf part's body content is omitted, return the content length in
--format=text output, for parity with --format=json output.
---
notmuch-show.c | 23 +++++++++++++++++++----
1 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/notmuch-show.c b/notmuch-show.c
index 5c54257..cde8a1e 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -488,9 +488,17 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
GMIME_OBJECT (node->envelope_part) : node->part;
GMimeContentType *content_type = g_mime_object_get_content_type (meta);
const notmuch_bool_t leaf = GMIME_IS_PART (node->part);
+ notmuch_bool_t leaf_text_part = FALSE;
const char *part_type;
int i;
+ if (leaf &&
+ g_mime_content_type_is_type (content_type, "text", "*") &&
+ !g_mime_content_type_is_type (content_type, "text", "html"))
+ {
+ leaf_text_part = TRUE;
+ }
+
if (node->envelope_file) {
notmuch_message_t *message = node->envelope_file;
@@ -519,7 +527,16 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
printf (", Filename: %s", filename);
if (cid)
printf (", Content-id: %s", cid);
- printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));
+ printf (", Content-type: %s", g_mime_content_type_to_string (content_type));
+ if (leaf && !leaf_text_part) {
+ 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);
+ if (length >= 0) {
+ printf (", Content-length: %ld", length);
+ }
+ }
+ printf ("\n");
}
if (GMIME_IS_MESSAGE (node->part)) {
@@ -547,9 +564,7 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
}
if (leaf) {
- if (g_mime_content_type_is_type (content_type, "text", "*") &&
- !g_mime_content_type_is_type (content_type, "text", "html"))
- {
+ if (leaf_text_part) {
GMimeStream *stream_stdout = g_mime_stream_file_new (stdout);
g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
show_text_part_content (node->part, stream_stdout, 0);
--
1.7.4.4
More information about the notmuch
mailing list