1 Return-Path: <tomi.ollila@iki.fi>
\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 36C11431FBD
\r
6 for <notmuch@notmuchmail.org>; Tue, 22 May 2012 06:21:34 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 cbZkpA55rnkM for <notmuch@notmuchmail.org>;
\r
16 Tue, 22 May 2012 06:21:33 -0700 (PDT)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 9AF56431FAE
\r
19 for <notmuch@notmuchmail.org>; Tue, 22 May 2012 06:21:32 -0700 (PDT)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id BBF25100641; Tue, 22 May 2012 16:21:41 +0300 (EEST)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: Michal Sojka <sojkam1@fel.cvut.cz>, Adam Wolfe Gordon <awg+notmuch@xvx.ca>
\r
24 Subject: Re: emacs complains about encoding?
\r
25 In-Reply-To: <871umc1int.fsf@steelpick.2x.cz>
\r
26 References: <20120515194455.B7AD5100646@guru.guru-group.fi>
\r
27 <878vgsbprq.fsf@nikula.org> <m23970bhre.fsf@guru.guru-group.fi>
\r
28 <CAMoJFUungAFPWy0d1Lh+rqmpK--P7MMEwNaewWHR=rbYo+BKsA@mail.gmail.com>
\r
29 <871umc1int.fsf@steelpick.2x.cz>
\r
30 User-Agent: Notmuch/0.13~rc1+40~g96c989b (http://notmuchmail.org) Emacs/23.1.1
\r
31 (x86_64-redhat-linux-gnu)
\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
33 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
34 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
35 Date: Tue, 22 May 2012 16:21:41 +0300
\r
36 Message-ID: <m27gw4nyfu.fsf@guru.guru-group.fi>
\r
38 Content-Type: text/plain; charset=us-ascii
\r
39 Cc: notmuch@notmuchmail.org
\r
40 X-BeenThere: notmuch@notmuchmail.org
\r
41 X-Mailman-Version: 2.1.13
\r
43 List-Id: "Use and development of the notmuch mail system."
\r
44 <notmuch.notmuchmail.org>
\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
48 List-Post: <mailto:notmuch@notmuchmail.org>
\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
51 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
52 X-List-Received-Date: Tue, 22 May 2012 13:21:34 -0000
\r
54 Michal Sojka <sojkam1@fel.cvut.cz> writes:
\r
58 > Adam Wolfe Gordon <awg+notmuch@xvx.ca> writes:
\r
59 >> It turns out it's actually not the emacs side, but an interaction
\r
60 >> between our JSON reply format and emacs.
\r
62 >> The JSON reply (and show) code includes part content for all text/*
\r
63 >> parts except text/html. Because all JSON is required to be UTF-8, it
\r
64 >> handles the encoding itself, puts UTF-8 text in, and omits a
\r
65 >> content-charset field from the output. Emacs passes on the
\r
66 >> content-charset field to mm-display-part-inline if it's available, but
\r
67 >> for text/plain parts it's not, leaving mm-display-part-inline to its
\r
68 >> own devices for figuring out what the charset is. It seems
\r
69 >> mm-display-part-inline correctly figures out that it's UTF-8, and puts
\r
70 >> in the series of ugly \nnn characters because that's what emacs does
\r
71 >> with UTF-8 sometimes.
\r
73 >> In the original reply stuff (pre-JSON reply format) emacs used the
\r
74 >> output of notmuch reply verbatim, so all the charset stuff was handled
\r
75 >> in notmuch. Before f6c170fabca8f39e74705e3813504137811bf162, emacs was
\r
76 >> using the JSON reply format, but was inserting the text itself instead
\r
77 >> of using mm-display-part-inline, so emacs still wasn't trying to do
\r
78 >> any charset manipulation. Using mm-display-part-inline is desirable
\r
79 >> because it lets us handle non-text/plain (e.g. text/html) parts
\r
80 >> correctly in reply, and makes the display more consistent (since we
\r
81 >> use it for show). But, it leads to this problem.
\r
83 >> So, there are a couple of solutions I can see:
\r
85 >> 1) Have the JSON formats include the original content-charset even
\r
86 >> though they're actually outputting UTF-8. Of the solutions I tried,
\r
87 >> this is the best, even though it doesn't sound like a good thing to
\r
90 >> 2) Have the JSON formats include content only if it's actually UTF-8.
\r
91 >> This means that for non-UTF-8 parts (including ASCII parts), the emacs
\r
92 >> interface has to do more work to display the part content, since it
\r
93 >> must fetch it from outside first. When I tried this, it worked but
\r
94 >> caused the \nnn to show up when viewing messages in emacs. I suspect
\r
95 >> this is because it sets a charset for the whole buffer, and can't
\r
96 >> accommodate messages with different charsets in the same buffer
\r
97 >> properly. Reply works correctly, though.
\r
99 >> 3) Have the JSON formats include the charset for all parts, but make
\r
100 >> it UTF-8 for all parts they include content for (since we're actually
\r
101 >> outputting UTF-8). This doesn't seem to fix the problem, even though
\r
102 >> it seems like it should.
\r
104 >> If no one has a better idea or a strong reason not to, I'll send a
\r
105 >> patch for solution (1).
\r
107 > Thank you very much for your analysis. It encouraged me to dig into the
\r
108 > problem and I've found another solution, which might be better than
\r
109 > those you suggested.
\r
111 > I traced what Emacs does with the text inside
\r
112 > notmuch-mm-display-part-inline and the wrong charset conversion happens
\r
113 > deeply in elisp code in mm-with-part called by mm-get-part, which is in
\r
114 > turn called by mm-inline-text. There is a way to make mm-inline-text not
\r
115 > to call mm-get-part, which is to set the charset to 'gnus-decoded. This
\r
116 > sounds like something that applies to our situation, where the part is
\r
119 You've digged deeper than I did... :)
\r
122 > The following patch (apply it with git am -c) solves the problem for me.
\r
123 > However, I'm not sure it is a universal solution. It sets the charset
\r
124 > only if it is not defined in notmuch json output and I'm not sure that
\r
125 > this is correct. text/html parts seem to have charset defined, but as
\r
126 > you wrote that json is always utf-8, so it might be that we need
\r
127 > 'gnus-decoded always, independently of the json output. What do you
\r
130 No -- when non-inlined content is fetched by executing command
\r
131 notmuch show --format=raw --part=n --decrypt id:"<message-id>" the content
\r
132 is received with original charset -- and then mm-* components needs to have
\r
133 correct charset set (well, I think, I have not tested ;).
\r
135 Also, we cannot rely that the json output doesn't contain content-charset
\r
136 information in the future...
\r
138 I'm currently applying this to my build tree whenever I rebuild notmuch for
\r
139 my own use: id:"1337533094-5467-1-git-send-email-tomi.ollila@iki.fi"
\r
142 I think the current plan is to use the same decoding lookup table that
\r
143 notmuch-show is using in reply too. That is good plan for consistency
\r
144 point of view. That just requires some code to be moved from
\r
145 notmuch-show.el to some other file (maybe a new one).
\r
154 > diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
\r
155 > index 7fa441a..8070f05 100644
\r
156 > --- a/emacs/notmuch-lib.el
\r
157 > +++ b/emacs/notmuch-lib.el
\r
158 > @@ -244,7 +244,7 @@ the given type."
\r
159 > current buffer, if possible."
\r
160 > (let ((display-buffer (current-buffer)))
\r
161 > (with-temp-buffer
\r
162 > - (let* ((charset (plist-get part :content-charset))
\r
163 > + (let* ((charset (or (plist-get part :content-charset) 'gnus-decoded))
\r
164 > (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))
\r
165 > ;; If the user wants the part inlined, insert the content and
\r
166 > ;; test whether we are able to inline it (which includes both
\r
167 > _______________________________________________
\r
168 > notmuch mailing list
\r
169 > notmuch@notmuchmail.org
\r
170 > http://notmuchmail.org/mailman/listinfo/notmuch
\r