[PATCH 3/4] show: indicate length of omitted body content (text)

Austin Clements amdragon at MIT.EDU
Mon Aug 6 09:50:24 PDT 2012


I'm not sure it's worth updating the text format.  There's already
plenty of disparity between the JSON and text formats, we're
considering deprecating the text format, and, from what I understand,
this might actually break consumers of the text format (the vim
frontend?) since the text format isn't particularly extensible.

Quoth Peter Wang on Aug 05 at  5:22 pm:
> 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);
> +	    }

Same comment about possibly unref'ing wrapper and/or stream.

> +	}
> +	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);


More information about the notmuch mailing list