[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to change encoding temporarily?
From: |
Zhang Wei |
Subject: |
Re: How to change encoding temporarily? |
Date: |
Sat, 18 Nov 2006 05:27:08 +0800 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/23.0.0 (gnu/linux) |
Reiner Steib <reinersteib+gmane@imap.cc> writes:
> I'd suggest something like this (barely tested):
>
> --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)
> (when (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") "")))
> (set (make-local-variable 'mm-coding-system-priorities)
> '(iso-8859-1 gbk utf-8)))))
> --8<---------------cut here---------------end--------------->8---
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.
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.
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---
--
荣华我已知庄梦
忠愤人将谓杞忧