unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Edmondson <dme@dme.org>
To: notmuch@notmuchmail.org
Subject: [PATCH v2] notmuch/emacs: Observe the charset of text/html parts, where known.
Date: Thu, 12 Jan 2012 13:31:18 +0000	[thread overview]
Message-ID: <1326375078-2279-1-git-send-email-dme@dme.org> (raw)
In-Reply-To: <1326279001-28427-1-git-send-email-dme@dme.org>

Add the charset of text/html parts to the JSON output of 'notmuch
-show' when it is known. Observe the encoding when rendering such
parts in emacs.
---

Add the charset only for text/html parts to avoid incorrectly
declaring the charset for JSON inline text/plain parts (as they have
already been converted to UTF-8).

 emacs/notmuch-show.el |    3 ++-
 notmuch-show.c        |   19 ++++++++++++++-----
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 5502efd..0354a8e 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -328,7 +328,8 @@ message at DEPTH in the current thread."
 current buffer, if possible."
   (let ((display-buffer (current-buffer)))
     (with-temp-buffer
-      (let ((handle (mm-make-handle (current-buffer) (list content-type))))
+      (let* ((charset (plist-get part :content-charset))
+	     (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))
 	(if (and (mm-inlinable-p handle)
 		 (mm-inlined-p handle))
 	    (let ((content (notmuch-show-get-bodypart-content msg part nth)))
diff --git a/notmuch-show.c b/notmuch-show.c
index 0200b9c..3d05da5 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -675,13 +675,22 @@ 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));
+	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", "*"))
     {
-- 
1.7.7.3

  parent reply	other threads:[~2012-01-12 13:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-11 10:50 [PATCH] notmuch/emacs: Observe the charset of encoded parts, where known David Edmondson
2012-01-11 11:03 ` Tomi Ollila
2012-01-11 18:34 ` Dmitry Kurochkin
2012-01-12 12:00   ` David Edmondson
2012-01-12 14:17     ` Dmitry Kurochkin
2012-01-12 14:42       ` David Edmondson
2012-01-12 14:53         ` Dmitry Kurochkin
2012-01-12 13:31 ` David Edmondson [this message]
2012-01-12 18:49   ` [PATCH v2] notmuch/emacs: Observe the charset of text/html " Austin Clements
2012-01-12 19:14     ` David Edmondson
2012-01-13  9:44       ` [PATCH v3] " David Edmondson
2012-01-13 10:09         ` Tomi Ollila
2012-01-13 23:09         ` Austin Clements
2012-01-14  1:49         ` David Bremner

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=1326375078-2279-1-git-send-email-dme@dme.org \
    --to=dme@dme.org \
    --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).