]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-show.c
cli: pick the user's address in a group list as from address
[notmuch] / notmuch-show.c
index 603992a612448c8892888580a4fae68f5aa123dc..d14dac976e33d596565721fcd3616e8f12c814f4 100644 (file)
@@ -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");
 
-       printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len));
+           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));
+       }
     }
     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,7 @@ do_show_single (void *ctx,
 
        while (!feof (file)) {
            size = fread (buf, 1, sizeof (buf), file);
-           fwrite (buf, size, 1, stdout);
+           (void) fwrite (buf, size, 1, stdout);
        }
 
        fclose (file);