Re: emacs complains about encoding?
authorTomi Ollila <tomi.ollila@iki.fi>
Tue, 22 May 2012 13:21:41 +0000 (16:21 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:15 +0000 (09:47 -0800)
d5/9b48a7aca1c88bc7f46e3cc0d8939d84555bca [new file with mode: 0644]

diff --git a/d5/9b48a7aca1c88bc7f46e3cc0d8939d84555bca b/d5/9b48a7aca1c88bc7f46e3cc0d8939d84555bca
new file mode 100644 (file)
index 0000000..0ff233a
--- /dev/null
@@ -0,0 +1,170 @@
+Return-Path: <tomi.ollila@iki.fi>\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 36C11431FBD\r
+       for <notmuch@notmuchmail.org>; Tue, 22 May 2012 06:21:34 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       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 cbZkpA55rnkM for <notmuch@notmuchmail.org>;\r
+       Tue, 22 May 2012 06:21:33 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 9AF56431FAE\r
+       for <notmuch@notmuchmail.org>; Tue, 22 May 2012 06:21:32 -0700 (PDT)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+       id BBF25100641; Tue, 22 May 2012 16:21:41 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Michal Sojka <sojkam1@fel.cvut.cz>, Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
+Subject: Re: emacs complains about encoding?\r
+In-Reply-To: <871umc1int.fsf@steelpick.2x.cz>\r
+References: <20120515194455.B7AD5100646@guru.guru-group.fi>\r
+       <878vgsbprq.fsf@nikula.org> <m23970bhre.fsf@guru.guru-group.fi>\r
+       <CAMoJFUungAFPWy0d1Lh+rqmpK--P7MMEwNaewWHR=rbYo+BKsA@mail.gmail.com>\r
+       <871umc1int.fsf@steelpick.2x.cz>\r
+User-Agent: Notmuch/0.13~rc1+40~g96c989b (http://notmuchmail.org) Emacs/23.1.1\r
+       (x86_64-redhat-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Tue, 22 May 2012 16:21:41 +0300\r
+Message-ID: <m27gw4nyfu.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Cc: notmuch@notmuchmail.org\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: Tue, 22 May 2012 13:21:34 -0000\r
+\r
+Michal Sojka <sojkam1@fel.cvut.cz> writes:\r
+\r
+> Hello Adam,\r
+>\r
+> Adam Wolfe Gordon <awg+notmuch@xvx.ca> writes:\r
+>> It turns out it's actually not the emacs side, but an interaction\r
+>> between our JSON reply format and emacs.\r
+>>\r
+>> The JSON reply (and show) code includes part content for all text/*\r
+>> parts except text/html. Because all JSON is required to be UTF-8, it\r
+>> handles the encoding itself, puts UTF-8 text in, and omits a\r
+>> content-charset field from the output. Emacs passes on the\r
+>> content-charset field to mm-display-part-inline if it's available, but\r
+>> for text/plain parts it's not, leaving mm-display-part-inline to its\r
+>> own devices for figuring out what the charset is. It seems\r
+>> mm-display-part-inline correctly figures out that it's UTF-8, and puts\r
+>> in the series of ugly \nnn characters because that's what emacs does\r
+>> with UTF-8 sometimes.\r
+>>\r
+>> In the original reply stuff (pre-JSON reply format) emacs used the\r
+>> output of notmuch reply verbatim, so all the charset stuff was handled\r
+>> in notmuch. Before f6c170fabca8f39e74705e3813504137811bf162, emacs was\r
+>> using the JSON reply format, but was inserting the text itself instead\r
+>> of using mm-display-part-inline, so emacs still wasn't trying to do\r
+>> any charset manipulation. Using mm-display-part-inline is desirable\r
+>> because it lets us handle non-text/plain (e.g. text/html) parts\r
+>> correctly in reply, and makes the display more consistent (since we\r
+>> use it for show). But, it leads to this problem.\r
+>>\r
+>> So, there are a couple of solutions I can see:\r
+>>\r
+>> 1) Have the JSON formats include the original content-charset even\r
+>> though they're actually outputting UTF-8. Of the solutions I tried,\r
+>> this is the best, even though it doesn't sound like a good thing to\r
+>> do.\r
+>>\r
+>> 2) Have the JSON formats include content only if it's actually UTF-8.\r
+>> This means that for non-UTF-8 parts (including ASCII parts), the emacs\r
+>> interface has to do more work to display the part content, since it\r
+>> must fetch it from outside first. When I tried this, it worked but\r
+>> caused the \nnn to show up when viewing messages in emacs. I suspect\r
+>> this is because it sets a charset for the whole buffer, and can't\r
+>> accommodate messages with different charsets in the same buffer\r
+>> properly. Reply works correctly, though.\r
+>>\r
+>> 3) Have the JSON formats include the charset for all parts, but make\r
+>> it UTF-8 for all parts they include content for (since we're actually\r
+>> outputting UTF-8). This doesn't seem to fix the problem, even though\r
+>> it seems like it should.\r
+>>\r
+>> If no one has a better idea or a strong reason not to, I'll send a\r
+>> patch for solution (1).\r
+>\r
+> Thank you very much for your analysis. It encouraged me to dig into the\r
+> problem and I've found another solution, which might be better than\r
+> those you suggested.\r
+>\r
+> I traced what Emacs does with the text inside\r
+> notmuch-mm-display-part-inline and the wrong charset conversion happens\r
+> deeply in elisp code in mm-with-part called by mm-get-part, which is in\r
+> turn called by mm-inline-text. There is a way to make mm-inline-text not\r
+> to call mm-get-part, which is to set the charset to 'gnus-decoded. This\r
+> sounds like something that applies to our situation, where the part is\r
+> already decoded.\r
+\r
+You've digged deeper than I did... :)\r
+\r
+>\r
+> The following patch (apply it with git am -c) solves the problem for me.\r
+> However, I'm not sure it is a universal solution. It sets the charset\r
+> only if it is not defined in notmuch json output and I'm not sure that\r
+> this is correct. text/html parts seem to have charset defined, but as\r
+> you wrote that json is always utf-8, so it might be that we need\r
+> 'gnus-decoded always, independently of the json output. What do you\r
+> think?\r
+\r
+No -- when non-inlined content is fetched by executing command\r
+notmuch show --format=raw --part=n --decrypt id:"<message-id>" the content\r
+is received with original charset -- and then mm-* components needs to have\r
+correct charset set (well, I think, I have not tested ;). \r
+\r
+Also, we cannot rely that the json output doesn't contain content-charset\r
+information in the future...\r
+\r
+I'm currently applying this to my build tree whenever I rebuild notmuch for\r
+my own use: id:"1337533094-5467-1-git-send-email-tomi.ollila@iki.fi"\r
+\r
+\r
+I think the current plan is to use the same decoding lookup table that\r
+notmuch-show is using in reply too. That is good plan for consistency\r
+point of view. That just requires some code to be moved from\r
+notmuch-show.el to some other file (maybe a new one).\r
+\r
+> -Michal\r
+\r
+Tomi\r
+\r
+\r
+>\r
+> ----8<-------\r
+> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+> index 7fa441a..8070f05 100644\r
+> --- a/emacs/notmuch-lib.el\r
+> +++ b/emacs/notmuch-lib.el\r
+> @@ -244,7 +244,7 @@ the given type."\r
+>  current buffer, if possible."\r
+>    (let ((display-buffer (current-buffer)))\r
+>      (with-temp-buffer\r
+> -      (let* ((charset (plist-get part :content-charset))\r
+> +      (let* ((charset (or (plist-get part :content-charset) 'gnus-decoded))\r
+>              (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))\r
+>         ;; If the user wants the part inlined, insert the content and\r
+>         ;; test whether we are able to inline it (which includes both\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r