From: Damien E. <erc...@re...> - 2004-12-05 09:54:37
|
Hi folks, I jumped on a network the other day which doesn't use any English, and their server messages (such as MOTD and LIST messages) are sent using a 7bit character encoding (iso-2022-jp). You can test it if you want want by going to irc.2ch.net. Unfortunately it seems like ERC can't cope with foreign characters in the server messages yet - at least not on my setup. I hacked up a quick patch to fix the problem for me, and thought someone might be interested. It's probably not suitable for inclusion in ERC yet, but I wanted to know if anyone has thought of a better way to support foreign characters in this context. Note that I changed the TOPIC handler since I thought a more generalised solution would be better - which means that after the patch is applied /topic messages won't be customisable on a per-channel basis, until erc-decode-server-message-string is improved. Any thoughts? Damien --- erc-backend.el 10 Nov 2004 17:01:42 +0900 1.15 +++ erc-backend.el 05 Dec 2004 18:39:31 +0900 @@ -110,6 +110,19 @@ (command-args '() :type list) (contents "" :type string)) +(defvar erc-delayed-decoding-responses '("PRIVMSG" "NOTICE") + "A list of responses which handle character decoding by themselves") + +(defun erc-decode-server-message-string (str msg) + "Decode a server message if a separate handler won't do it later. +This is useful for /lists, /topics etc on international networks. +It could modify target based on the network or other information in +the future." + (let ((target nil)) ; NYI + (if (member (erc-response.command msg) erc-delayed-decoding-responses) + str + (erc-decode-string-from-target str target)))) + (defun erc-parse-server-response (proc string) "Parse and act upon a complete line from an IRC server. PROC is the process (connection) from which STRING was received. @@ -135,15 +148,19 @@ (while (and posn (not (eq (aref string posn) ?:))) - (push (let* ((bposn posn) - (eposn (string-match " " string bposn))) - (setq posn (and eposn - (string-match "[^ ]" string eposn))) - (substring string bposn eposn)) - (erc-response.command-args msg))) + (push + (erc-decode-server-message-string + (let* ((bposn posn) + (eposn (string-match " " string bposn))) + (setq posn (and eposn + (string-match "[^ ]" string eposn))) + (substring string bposn eposn)) msg) + (erc-response.command-args msg))) (when posn - (let ((str (substring string (1+ posn)))) - (push str (erc-response.command-args msg)))) + (let ((str (substring string (1+ posn)))) + (push + (erc-decode-server-message-string str msg) + (erc-response.command-args msg)))) (setf (erc-response.contents msg) (first (erc-response.command-args msg))) @@ -665,8 +682,7 @@ (define-erc-response-handler (TOPIC) nil nil (let* ((ch (first (erc-response.command-args parsed))) - (topic (erc-trim-string (erc-decode-string-from-target - (erc-response.contents parsed) ch))) + (topic (erc-trim-string (erc-response.contents parsed))) (time (format-time-string "%T %m/%d/%y" (current-time)))) (multiple-value-bind (nick login host) (erc-parse-user (erc-response.sender parsed)) |