[BUG] Saving attachments containing UTF-8 chars

Tomi Ollila tomi.ollila at iki.fi
Mon Oct 29 09:31:42 PDT 2012


On Mon, Oct 29 2012, Michael Stapelberg wrote:

> Hello,
>
> attached you can find a message which seems to trigger a bug somewhere
> in my notmuch setup. The message has been sent to me and includes a
> patchfile, which, when saved using the "w" key in notmuch-emacs, cannot
> be applied.
>
> When using munpack(1) on the raw mail file (I’ve attached rawmail.gz
> just to be sure that the message doesn’t get mangled in some way), the
> unpacked attachment can be attached just fine.
>
> When diff'ing both files, I see that munpack correctly stores the file,
> including the problematic UTF-8 apostrophe:
> 00000200  67 3b 20 64 69 64 6e e2  80 99 74 20 72 65 61 64  |g; didn...t read|
>
> However, the version of the file saved with notmuch contains:
> 00000200  67 3b 20 64 69 64 6e 19  74 20 72 65 61 64 22 20  |g; didn.t read" |
>
> If there is anything I can do to help debugging this (or if there is a
> known fix), please let me know.

I can verify this bug: I copied 'rawmail' to my mail store and attempted
to 'w' the attacment and got the same result (after notmuch new).

The saving code first does
notmuch show --format=raw id:"508953E6.70006 at gmail.com"
which decodes OK on command line, and to the buffer when 
kill-buffer is outcommented in (with-current-notmuch-show-message ...) 
macro.

I attempted a set of trial-&-error tricks to get the attachment
saved "correctly", and at least this seems to do the trick:

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index f273eb4..a6a85c0 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -203,9 +203,11 @@ For example, if you wanted to remove an \"unread\" tag and add a
      (let ((id (notmuch-show-get-message-id)))
        (let ((buf (generate-new-buffer (concat "*notmuch-msg-" id "*"))))
          (with-current-buffer buf
-	    (call-process notmuch-command nil t nil "show" "--format=raw" id)
-           , at body)
-	 (kill-buffer buf)))))
+	   (let ((coding-system-for-read 'no-conversion)
+		 (coding-system-for-write 'no-conversion))
+	     (call-process notmuch-command nil t nil "show" "--format=raw" id)
+	     , at body))))))
+%%	 (kill-buffer buf)))))
 
 (defun notmuch-show-turn-on-visual-line-mode ()
   "Enable Visual Line mode."

---

(kill-buffer is outcommented above for testing purposes)

To test this this needs to me evaluated and then the functions
using this macro (notmuch-show-save-attachments  in this case)

Smart suggestions for proper fix ?

Tomi


More information about the notmuch mailing list