[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to change encoding temporarily?
From: |
ssSslang |
Subject: |
Re: How to change encoding temporarily? |
Date: |
Sat, 18 Nov 2006 14:37:50 +0800 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/23.0.0 (windows-nt) |
Thank you!
Zhang Wei <id.brep@gmail.com> writes:
> Good argument, but there's two subtle details should be point out,
> first, we couldn't do this:
>
> (set (make-local-variable 'mm-coding-system-priorities)
> '(iso-8859-1 gbk utf-8))
>
> It's a good idea to make a variable buffer local before change
> it's value, but perhaps gnus makes a new buffer for the encoded
> message, so if we don't change the global value of
> `mm-coding-system-priorities', it won't take effect.
I did a test. Zhang Wei is right. The local variable is not work.
> second, if we send mail through a SMTP server, be careful with
> the message-send-mail-function, set it like this:
>
> (setq message-send-mail-function 'message-smtpmail-send-it)
>
> not,
>
> (setq message-send-mail-function 'smtpmail-send-it)
>
> otherwise the `message-send-mail-hook' won't run.
I use msmtp to send message, so it needn't to be changed. Thank you all
the same.
> so something like this should cope with the problem:
>
> --8<---------------cut here---------------start------------->8---
> (setq sssslang-message-change-charset-regexp "@hotmail\\.com\\>")
> (setq mm-coding-system-priorities '(iso-8859-1 utf-8))
> (add-hook 'message-send-mail-hook 'sssslang-message-change-charset)
> (defun sssslang-message-change-charset ()
> (save-restriction
> (message-narrow-to-headers)
> (if (or (string-match sssslang-message-change-charset-regexp
> (or (message-fetch-field "to") ""))
> (string-match sssslang-message-change-charset-regexp
> (or (message-fetch-field "cc") ""))
> (string-match sssslang-message-change-charset-regexp
> (or (message-fetch-field "bcc") "")))
> (setq mm-coding-system-priorities
> '(iso-8859-1 gbk utf-8))
> (setq mm-coding-system-priorities
> '(iso-8859-1 utf-8)))))
> --8<---------------cut here---------------end--------------->8---
The truth is that when I first try this code, the GCCed mail's head
displays the gbk encoding, but, there's always a but, :) my hotmail mail
box also get a utf8 encoded mail. Then I go through the message.el to
find the reason(unfortunately, I know little about elisp), I saw the
follow two lines:
(message-fix-before-sending)
(run-hooks 'message-send-hook)
I remembered someone said Gnus holding text as utf8 and then convert to
another encoding before sending. So I look over the
(message-fix-before-sending) and guess this is the convert code. So I
exchanged the two lines and add the sssslang-message-change-charset to
the message-send-hook(because I cannot find the message-send-mail-hook).
It then works. I know this is a dirty way, so please let me know the
better solutions.
--
ssSslang