X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-show.c;h=c674e2506ff73270f4e43cd3937078ad3aa1b38b;hp=603992a612448c8892888580a4fae68f5aa123dc;hb=18947b95cd1668d1b98f7ea4196e97b050599f7d;hpb=61f0a5b8ee2adf540106a09c5f83fe634da6beb3 diff --git a/notmuch-show.c b/notmuch-show.c index 603992a6..c674e250 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -255,7 +255,9 @@ _extract_email_address (const void *ctx, const char *from) email = talloc_strdup (ctx, email); DONE: - /* XXX: How to free addresses here? */ + if (addresses) + g_object_unref (addresses); + return email; } @@ -469,9 +471,12 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out) /* This result can be NULL for things like "unknown-8bit". * Don't set a NULL filter as that makes GMime print * annoying assertion-failure messages on stderr. */ - if (charset_filter) + if (charset_filter) { g_mime_stream_filter_add (GMIME_STREAM_FILTER (stream_filter), charset_filter); + g_object_unref (charset_filter); + } + } wrapper = g_mime_part_get_content_object (GMIME_PART (part)); @@ -670,13 +675,31 @@ format_part_content_json (GMimeObject *part) printf (", \"filename\": %s", json_quote_str (ctx, filename)); } - if (g_mime_content_type_is_type (content_type, "text", "*") && - !g_mime_content_type_is_type (content_type, "text", "html")) + if (g_mime_content_type_is_type (content_type, "text", "*")) { - show_text_part_content (part, stream_memory); - part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory)); + /* For non-HTML text parts, we include the content in the + * JSON. Since JSON must be Unicode, we handle charset + * decoding here and do not report a charset to the caller. + * For text/html parts, we do not include the content. If a + * caller is interested in text/html parts, it should retrieve + * them separately and they will not be decoded. Since this + * makes charset decoding the responsibility on the caller, we + * report the charset for text/html parts. + */ + if (g_mime_content_type_is_type (content_type, "text", "html")) + { + const char *content_charset = g_mime_object_get_content_type_parameter (GMIME_OBJECT (part), "charset"); + + if (content_charset != NULL) + printf (", \"content-charset\": %s", json_quote_str (ctx, content_charset)); + } + else + { + show_text_part_content (part, stream_memory); + part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory)); - printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len)); + printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len)); + } } else if (g_mime_content_type_is_type (content_type, "multipart", "*")) { @@ -753,8 +776,7 @@ show_message (void *ctx, } if (format->part_content) - show_message_body (notmuch_message_get_filename (message), - format, params); + show_message_body (message, format, params); if (params->part <= 0) { fputs (format->body_end, stdout); @@ -861,7 +883,17 @@ do_show_single (void *ctx, while (!feof (file)) { size = fread (buf, 1, sizeof (buf), file); - fwrite (buf, size, 1, stdout); + if (ferror (file)) { + fprintf (stderr, "Error: Read failed from %s\n", filename); + fclose (file); + return 1; + } + + if (fwrite (buf, size, 1, stdout) != 1) { + fprintf (stderr, "Error: Write failed\n"); + fclose (file); + return 1; + } } fclose (file);