* How to change encoding temporarily? @ 2006-11-17 12:28 ssSslang 2006-11-17 13:16 ` Reiner Steib 0 siblings, 1 reply; 7+ messages in thread From: ssSslang @ 2006-11-17 12:28 UTC (permalink / raw) Hi there! I use Gnus with utf-8 encoding. Now I find the suck microsoft hotmail webmail can't decode my mail correctly. So I must change to another encoding(gbk) when sending mail to those who use hotmail mail box. Everytime I just write in my buffer with: (setq mm-coding-system-priorities '(iso-8859-1 gbk utf-8)) eval it, send mail, and then roll back. I thought of binding these two functions to some keys. But I often forget to do these before sending mail. Is it a hook related to mail address can be use for sending mail? -- ssSslang ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to change encoding temporarily? 2006-11-17 12:28 How to change encoding temporarily? ssSslang @ 2006-11-17 13:16 ` Reiner Steib 2006-11-17 13:46 ` ssSslang 0 siblings, 1 reply; 7+ messages in thread From: Reiner Steib @ 2006-11-17 13:16 UTC (permalink / raw) On Fri, Nov 17 2006, ssSslang wrote: > Is it a hook related to mail address can be use for sending mail? ,----[ M-x apropos-variable RET message.*send.*hook RET ] | message-send-hook | Variable: Hook run before sending messages. | message-send-mail-hook | Variable: Hook run before sending mail messages. | message-send-news-hook | Variable: Hook run before sending news messages. `---- Bye, Reiner. -- ,,, (o o) ---ooO-(_)-Ooo--- | PGP key available | http://rsteib.home.pages.de/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to change encoding temporarily? 2006-11-17 13:16 ` Reiner Steib @ 2006-11-17 13:46 ` ssSslang 2006-11-17 15:53 ` Brep 0 siblings, 1 reply; 7+ messages in thread From: ssSslang @ 2006-11-17 13:46 UTC (permalink / raw) Reiner Steib <reinersteib+gmane@imap.cc> writes: >> Is it a hook related to mail address can be use for sending mail? > > ,----[ M-x apropos-variable RET message.*send.*hook RET ] > | message-send-hook > | Variable: Hook run before sending messages. > | message-send-mail-hook > | Variable: Hook run before sending mail messages. > | message-send-news-hook > | Variable: Hook run before sending news messages. > `---- Thank you, Reiner. I saw these hooks, but they're not related to mail address. Do you mean I should write a function to select the encoding according to the From header, and then bind it to the hook? -- ssSslang ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to change encoding temporarily? 2006-11-17 13:46 ` ssSslang @ 2006-11-17 15:53 ` Brep 2006-11-17 19:33 ` Reiner Steib 0 siblings, 1 reply; 7+ messages in thread From: Brep @ 2006-11-17 15:53 UTC (permalink / raw) ssSslang <sssslang@163.com.removeme> writes: > Thank you, Reiner. I saw these hooks, but they're not related to mail > address. Do you mean I should write a function to select the encoding > according to the From header, and then bind it to the hook? Try this: (add-hook 'message-send-hook 'change-charset) (defun change-charset () (when (message-mail-p) (if (string-match "hotmail" (mail-fetch-field "to")) (setq mm-coding-system-priorities '(iso-8859-1 gbk utf-8)) (setq mm-coding-system-priorities '(iso-8859-1 utf-8))))) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to change encoding temporarily? 2006-11-17 15:53 ` Brep @ 2006-11-17 19:33 ` Reiner Steib 2006-11-17 21:27 ` Zhang Wei 0 siblings, 1 reply; 7+ messages in thread From: Reiner Steib @ 2006-11-17 19:33 UTC (permalink / raw) On Fri, Nov 17 2006, Brep wrote: > ssSslang <sssslang@163.com.removeme> writes: > >> Thank you, Reiner. I saw these hooks, but they're not related to mail >> address. Do you mean I should write a function to select the encoding >> according to the From header, and then bind it to the hook? > > Try this: > > (add-hook 'message-send-hook 'change-charset) > (defun change-charset () > (when (message-mail-p) > (if (string-match "hotmail" (mail-fetch-field "to")) > (setq mm-coding-system-priorities > '(iso-8859-1 gbk utf-8)) > (setq mm-coding-system-priorities > '(iso-8859-1 utf-8))))) 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--- Bye, Reiner. -- ,,, (o o) ---ooO-(_)-Ooo--- | PGP key available | http://rsteib.home.pages.de/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to change encoding temporarily? 2006-11-17 19:33 ` Reiner Steib @ 2006-11-17 21:27 ` Zhang Wei 2006-11-18 6:37 ` ssSslang 0 siblings, 1 reply; 7+ messages in thread From: Zhang Wei @ 2006-11-17 21:27 UTC (permalink / raw) 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--- -- 荣华我已知庄梦 忠愤人将谓杞忧 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to change encoding temporarily? 2006-11-17 21:27 ` Zhang Wei @ 2006-11-18 6:37 ` ssSslang 0 siblings, 0 replies; 7+ messages in thread From: ssSslang @ 2006-11-18 6:37 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-11-18 6:37 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-11-17 12:28 How to change encoding temporarily? ssSslang 2006-11-17 13:16 ` Reiner Steib 2006-11-17 13:46 ` ssSslang 2006-11-17 15:53 ` Brep 2006-11-17 19:33 ` Reiner Steib 2006-11-17 21:27 ` Zhang Wei 2006-11-18 6:37 ` ssSslang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).