Re: charsets

Katsumi Yamaoka <[email protected]> Fri, 07 Dec 2007 20:05:08 +0900
Newsgroups gmane.mail.emacs.mime.japanese,gmane.mail.wanderlust.general
Organization Emacsen advocacy group
Message-ID <[email protected]>
--=-=-=

>>>>> In [Wanderlust English : No.02240] Dmitri Minaev wrote:
> Hi,

> How  do I define  the charset  for the  messages I  send?  I  have the
> following code  in .wl (partially  borrowed from .gnus  and, probably,
> irrelevant):

> (setq wl-mime-charset 'koi8-r
>       default-mime-charset 'koi8-r
>       wl-folder-mime-charset-alist '(("^-fido7.*" . koi8-r)))
> (put-charset-property 'cyrillic-iso8859-5 'preferred-coding-system 'koi8-r)
> (setq mm-body-charset-encoding-alist '((koi8-r . 8bit)))

`mm-body-charset-encoding-alist' is for Gnus, not for Wanderlust.

> The  messages  sent to  fido7.*  newsgroups  have  the correct  header
> (Content-Type:  text/plain;  charset=koi8-r), but  the  content is  in
> UTF-8.

> Thanks.

> --
> Dmitri Minaev
> Russian history blog: http://minaev.blogspot.com

Could you try this workaround?  To do it, put this Lisp form in
your ~/.emacs file of ~/.wl.el file.

;--8<---------------cut here---------------start------------->8---
(defadvice mime-encode-region (around use-unibyte-buffer
				      (start end encoding) activate)
  "Use unibyte buffer while encoding."
  (let ((string (prog1
		    (buffer-substring start end)
		  (delete-region (goto-char start) end))))
    (insert (with-temp-buffer
	      (set-buffer-multibyte nil)
	      (insert (string-as-unibyte string))
	      (setq start (point-min)
		    end (point-max))
	      ad-do-it
	      (buffer-string)))))
;--8<---------------cut here---------------end--------------->8---

FLIM developers, I found a strange behavior with the Q encoder
defined in mel-q-ccl.el.  `mime-encode-region' seems to run in a
unibyte buffer when encoding a message to send.  If I use Emacs
23.0.60 (i.e. Emacs Unicode-2 that Dmitri uses too), it doesn't
work for "quoted-printable" as follows:


--=-=-=
Content-Type: text/plain; charset=koi8-r
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

(with-temp-buffer
  (set-buffer-multibyte t)
  (insert (string-to-multibyte
	   (encode-coding-string "=D2=D5=D3=D3=CB=C9=CA" 'koi8-r)))
  (mime-encode-region (point-min) (point-max) "quoted-printable")
  (buffer-string))
 =3D> "\322\325\323\323\313\311\312"

--=-=-=
Content-Disposition: inline


The remote cause of this problem looks like a multibyte buffer,
so I tried making it run in a unibyte buffer.  This doesn't
happen through Emacs 21 to 23.0.50.

Regards,

--=-=-=--