Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 93A59429E25 for ; Thu, 12 Jan 2012 05:31:24 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id s517Rn4Kr4W8 for ; Thu, 12 Jan 2012 05:31:24 -0800 (PST) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id D5B81431FB6 for ; Thu, 12 Jan 2012 05:31:23 -0800 (PST) Received: by werm12 with SMTP id m12so1588653wer.26 for ; Thu, 12 Jan 2012 05:31:22 -0800 (PST) Received: by 10.216.209.99 with SMTP id r77mr1515265weo.25.1326375082599; Thu, 12 Jan 2012 05:31:22 -0800 (PST) Received: from hotblack-desiato.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25]) by mx.google.com with ESMTPS id gf8sm5748909wbb.11.2012.01.12.05.31.20 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 12 Jan 2012 05:31:21 -0800 (PST) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id BBE76A029E; Thu, 12 Jan 2012 13:31:19 +0000 (GMT) From: David Edmondson 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 Message-Id: <1326375078-2279-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1326279001-28427-1-git-send-email-dme@dme.org> References: <1326279001-28427-1-git-send-email-dme@dme.org> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jan 2012 13:31:24 -0000 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