--- /dev/null
+Return-Path: <dme@dme.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 43275429E30\r
+ for <notmuch@notmuchmail.org>; Fri, 13 Jan 2012 01:44:53 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id KFffh0gkvu8q for <notmuch@notmuchmail.org>;\r
+ Fri, 13 Jan 2012 01:44:52 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+ [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 86120431FB6\r
+ for <notmuch@notmuchmail.org>; Fri, 13 Jan 2012 01:44:52 -0800 (PST)\r
+Received: by werm13 with SMTP id m13so262452wer.26\r
+ for <notmuch@notmuchmail.org>; Fri, 13 Jan 2012 01:44:51 -0800 (PST)\r
+Received: by 10.216.138.5 with SMTP id z5mr1829205wei.37.1326447891350;\r
+ Fri, 13 Jan 2012 01:44:51 -0800 (PST)\r
+Received: from hotblack-desiato.hh.sledj.net\r
+ (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
+ by mx.google.com with ESMTPS id v28sm10336422wbo.18.2012.01.13.01.44.49\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Fri, 13 Jan 2012 01:44:49 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+ id DEB9B9FDBF; Fri, 13 Jan 2012 09:44:47 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3] notmuch/emacs: Observe the charset of text/html parts,\r
+ where known.\r
+Date: Fri, 13 Jan 2012 09:44:46 +0000\r
+Message-Id: <1326447886-3622-1-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <cunobu8lolt.fsf@hotblack-desiato.hh.sledj.net>\r
+References: <cunobu8lolt.fsf@hotblack-desiato.hh.sledj.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 13 Jan 2012 09:44:53 -0000\r
+\r
+Add the charset of text/html parts to the JSON output of 'notmuch\r
+-show' when it is known. Observe the encoding when rendering such\r
+parts in emacs.\r
+---\r
+\r
+Commentary added.\r
+\r
+ emacs/notmuch-show.el | 3 ++-\r
+ notmuch-show.c | 28 +++++++++++++++++++++++-----\r
+ 2 files changed, 25 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 5502efd..0354a8e 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -328,7 +328,8 @@ message at DEPTH in the current thread."\r
+ current buffer, if possible."\r
+ (let ((display-buffer (current-buffer)))\r
+ (with-temp-buffer\r
+- (let ((handle (mm-make-handle (current-buffer) (list content-type))))\r
++ (let* ((charset (plist-get part :content-charset))\r
++ (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))\r
+ (if (and (mm-inlinable-p handle)\r
+ (mm-inlined-p handle))\r
+ (let ((content (notmuch-show-get-bodypart-content msg part nth)))\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 0200b9c..87a1c90 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -675,13 +675,31 @@ format_part_content_json (GMimeObject *part)\r
+ printf (", \"filename\": %s", json_quote_str (ctx, filename));\r
+ }\r
+ \r
+- if (g_mime_content_type_is_type (content_type, "text", "*") &&\r
+- !g_mime_content_type_is_type (content_type, "text", "html"))\r
++ if (g_mime_content_type_is_type (content_type, "text", "*"))\r
+ {\r
+- show_text_part_content (part, stream_memory);\r
+- part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));\r
++ /* For non-HTML text/* parts, we include the content in the\r
++ * JSON. Since JSON must be Unicode, we handle charset\r
++ * decoding here and do not report a charset to the caller.\r
++ * For text/html parts, we do not include the content. If a\r
++ * caller is interested in text/html parts, it should retrieve\r
++ * them separately and they will not be decoded. Since this\r
++ * makes charset decoding the responsibility on the caller, we\r
++ * report the charset for text/html parts.\r
++ */\r
++ if (g_mime_content_type_is_type (content_type, "text", "html"))\r
++ {\r
++ const char *content_charset = g_mime_object_get_content_type_parameter (GMIME_OBJECT (part), "charset");\r
++\r
++ if (content_charset != NULL)\r
++ printf (", \"content-charset\": %s", json_quote_str (ctx, content_charset));\r
++ }\r
++ else\r
++ {\r
++ show_text_part_content (part, stream_memory);\r
++ part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));\r
+ \r
+- printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len));\r
++ printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len));\r
++ }\r
+ }\r
+ else if (g_mime_content_type_is_type (content_type, "multipart", "*"))\r
+ {\r
+-- \r
+1.7.7.3\r
+\r