[PATCH 2/2] emacs: Fix broken showing of forwarded messages.
[notmuch-archives.git] / dc / 5be09cf18622539ed9e45fb657ecca2c28831d
1 Return-Path: <dme@dme.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 43275429E30\r
6         for <notmuch@notmuchmail.org>; Fri, 13 Jan 2012 01:44:53 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id KFffh0gkvu8q for <notmuch@notmuchmail.org>;\r
16         Fri, 13 Jan 2012 01:44:52 -0800 (PST)\r
17 Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
18         [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 86120431FB6\r
21         for <notmuch@notmuchmail.org>; Fri, 13 Jan 2012 01:44:52 -0800 (PST)\r
22 Received: by werm13 with SMTP id m13so262452wer.26\r
23         for <notmuch@notmuchmail.org>; Fri, 13 Jan 2012 01:44:51 -0800 (PST)\r
24 Received: by 10.216.138.5 with SMTP id z5mr1829205wei.37.1326447891350;\r
25         Fri, 13 Jan 2012 01:44:51 -0800 (PST)\r
26 Received: from hotblack-desiato.hh.sledj.net\r
27         (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
28         by mx.google.com with ESMTPS id v28sm10336422wbo.18.2012.01.13.01.44.49\r
29         (version=TLSv1/SSLv3 cipher=OTHER);\r
30         Fri, 13 Jan 2012 01:44:49 -0800 (PST)\r
31 Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
32         id DEB9B9FDBF; Fri, 13 Jan 2012 09:44:47 +0000 (GMT)\r
33 From: David Edmondson <dme@dme.org>\r
34 To: notmuch@notmuchmail.org\r
35 Subject: [PATCH v3] notmuch/emacs: Observe the charset of text/html parts,\r
36         where known.\r
37 Date: Fri, 13 Jan 2012 09:44:46 +0000\r
38 Message-Id: <1326447886-3622-1-git-send-email-dme@dme.org>\r
39 X-Mailer: git-send-email 1.7.7.3\r
40 In-Reply-To: <cunobu8lolt.fsf@hotblack-desiato.hh.sledj.net>\r
41 References: <cunobu8lolt.fsf@hotblack-desiato.hh.sledj.net>\r
42 X-BeenThere: notmuch@notmuchmail.org\r
43 X-Mailman-Version: 2.1.13\r
44 Precedence: list\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Fri, 13 Jan 2012 09:44:53 -0000\r
55 \r
56 Add the charset of text/html parts to the JSON output of 'notmuch\r
57 -show' when it is known. Observe the encoding when rendering such\r
58 parts in emacs.\r
59 ---\r
60 \r
61 Commentary added.\r
62 \r
63  emacs/notmuch-show.el |    3 ++-\r
64  notmuch-show.c        |   28 +++++++++++++++++++++++-----\r
65  2 files changed, 25 insertions(+), 6 deletions(-)\r
66 \r
67 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
68 index 5502efd..0354a8e 100644\r
69 --- a/emacs/notmuch-show.el\r
70 +++ b/emacs/notmuch-show.el\r
71 @@ -328,7 +328,8 @@ message at DEPTH in the current thread."\r
72  current buffer, if possible."\r
73    (let ((display-buffer (current-buffer)))\r
74      (with-temp-buffer\r
75 -      (let ((handle (mm-make-handle (current-buffer) (list content-type))))\r
76 +      (let* ((charset (plist-get part :content-charset))\r
77 +            (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))\r
78         (if (and (mm-inlinable-p handle)\r
79                  (mm-inlined-p handle))\r
80             (let ((content (notmuch-show-get-bodypart-content msg part nth)))\r
81 diff --git a/notmuch-show.c b/notmuch-show.c\r
82 index 0200b9c..87a1c90 100644\r
83 --- a/notmuch-show.c\r
84 +++ b/notmuch-show.c\r
85 @@ -675,13 +675,31 @@ format_part_content_json (GMimeObject *part)\r
86             printf (", \"filename\": %s", json_quote_str (ctx, filename));\r
87      }\r
88  \r
89 -    if (g_mime_content_type_is_type (content_type, "text", "*") &&\r
90 -       !g_mime_content_type_is_type (content_type, "text", "html"))\r
91 +    if (g_mime_content_type_is_type (content_type, "text", "*"))\r
92      {\r
93 -       show_text_part_content (part, stream_memory);\r
94 -       part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));\r
95 +       /* For non-HTML text/* parts, we include the content in the\r
96 +        * JSON. Since JSON must be Unicode, we handle charset\r
97 +        * decoding here and do not report a charset to the caller.\r
98 +        * For text/html parts, we do not include the content. If a\r
99 +        * caller is interested in text/html parts, it should retrieve\r
100 +        * them separately and they will not be decoded. Since this\r
101 +        * makes charset decoding the responsibility on the caller, we\r
102 +        * report the charset for text/html parts.\r
103 +        */\r
104 +       if (g_mime_content_type_is_type (content_type, "text", "html"))\r
105 +       {\r
106 +           const char *content_charset = g_mime_object_get_content_type_parameter (GMIME_OBJECT (part), "charset");\r
107 +\r
108 +           if (content_charset != NULL)\r
109 +               printf (", \"content-charset\": %s", json_quote_str (ctx, content_charset));\r
110 +       }\r
111 +       else\r
112 +       {\r
113 +           show_text_part_content (part, stream_memory);\r
114 +           part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));\r
115  \r
116 -       printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len));\r
117 +           printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len));\r
118 +       }\r
119      }\r
120      else if (g_mime_content_type_is_type (content_type, "multipart", "*"))\r
121      {\r
122 -- \r
123 1.7.7.3\r
124 \r