Gnus development mailing list
 help / color / mirror / Atom feed
From: Reiner Steib <reinersteib+gmane@imap.cc>
Subject: Re: wrong charset in spite of proper format
Date: Thu, 10 Mar 2005 19:53:21 +0100	[thread overview]
Message-ID: <v9u0njtjry.fsf@marauder.physik.uni-ulm.de> (raw)
In-Reply-To: <m3u0nkz6b3.fsf@merlin.emma.line.org>

[-- Attachment #1: Type: text/plain, Size: 936 bytes --]

On Thu, Mar 10 2005, Matthias Andree wrote:

> OK. My complaint is that as a result of Emacs 21.SOME_MINOR_RELEASE not
> providing a particular character set, Gnus display anything else rather
> than falling back to ASCII (where appropriate), masking the unprintables
> and stuffing a status line that reads something like "windows-1251 not
> supported by your emacs, displaying ASCII parts"
[...]
> This is along the lines Simon Josefsson suggested one and a half
> years ago WRT Windows-1252.
>
> It is a shame that such functionality still isn't enabled in the default
> No Gnus after such a long time. :-(

Could you try the following patch? [*] It should automatically do the
setup for windows-125[0137] (which are available in Emacs 21).  If no
charset (or alias) is found, it will print a message.  (Displaying as
ASCII is and replacing unknown chars with `?' is not included.  I'm
not sure how this could be achieved in Gnus.)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: rs-mm-util-auto-charset.patch --]
[-- Type: text/x-patch, Size: 3365 bytes --]

--- mm-util.el	21 Feb 2005 12:42:41 +0100	7.26
+++ mm-util.el	10 Mar 2005 19:31:33 +0100	
@@ -142,6 +142,34 @@
       ;; Is this branch ever actually useful?
       (car (memq cs (mm-get-coding-system-list))))))
 
+(defun mm-codepage-setup (number)
+  "Create a coding system cpNUMBER and an alias for windows-NUMBER.
+The coding system is created using `codepage-setup'.  The alias
+is added to `mm-charset-synonym-alist'."
+  (interactive
+   (let ((completion-ignore-case t)
+	 (candidates (cp-supported-codepages)))
+     (list (completing-read "Setup DOS Codepage: (default 437) " candidates
+			    nil t nil nil "437"))))
+  (let* ((cp (intern (format "cp%s" number)))
+	 (alias (intern (format "windows-%s" number))))
+    (unless (mm-coding-system-p cp)
+      (when (codepage-setup number)
+	(unless (mm-coding-system-p alias)
+	  (add-to-list 'mm-charset-synonym-alist
+		       (cons alias cp)))))))
+
+(defvar mm-charset-eval-alist
+  '(;; (iso-8859-13 . (require 'code-pages))
+    ;; Emacs 21 offers: 1250 1251 1253 1257
+    (windows-1250 . (mm-codepage-setup 1250))
+    (windows-1251 . (mm-codepage-setup 1251))
+    (windows-1253 . (mm-codepage-setup 1253))
+    (windows-1257 . (mm-codepage-setup 1257)))
+  "An alist of \(charset . form\) pairs.
+If an article is encoded in an unknown CHARSET, FORM is evaluated.
+This allows to load additional libraries providing CHARSETS.")
+
 (defvar mm-charset-synonym-alist
   `(
     ;; Not in XEmacs, but it's not a proper MIME charset anyhow.
@@ -175,7 +203,7 @@
 	    '((ks_c_5601-1987 . cp949))
 	  '((ks_c_5601-1987 . euc-kr))))
     )
-  "A mapping from invalid charset names to the real charset names.")
+  "A mapping from unknown or invalid charset names to the real charset names.")
 
 (defvar mm-binary-coding-system
   (cond
@@ -400,6 +428,10 @@
 	(pop alist))
       out)))
 
+;; FIXME: `gnus-message' must be replaced by `message'.  This is just for
+;; testing.
+(autoload 'gnus-message "gnus-util")
+
 (defun mm-charset-to-coding-system (charset &optional lbt)
   "Return coding-system corresponding to CHARSET.
 CHARSET is a symbol naming a MIME charset.
@@ -428,9 +460,26 @@
 ;;; 	 (eq charset (coding-system-get charset 'mime-charset))
 	 )
     charset)
+   ;; Eval expressions from `mm-charset-eval-alist'
+   ((let* ((el (assq charset mm-charset-eval-alist))
+	   (cs (car el))
+	   (form (cdr el)))
+      (and cs
+	   form
+	   ;; Avoid errors...
+	   (condition-case nil (eval form) (error nil))
+	   ;; (message "Failed to eval `%s'" form))
+	   (mm-coding-system-p cs)
+	   (gnus-message 7 "Added charset `%s' via `mm-charset-eval-alist'" cs)
+	   cs)))
    ;; Translate invalid charsets.
    ((let ((cs (cdr (assq charset mm-charset-synonym-alist))))
-      (and cs (mm-coding-system-p cs) cs)))
+      (and cs
+	   (mm-coding-system-p cs)
+	   (gnus-message 7
+	    "Using synonym `%s' from `mm-charset-synonym-alist' for `%s'"
+	    cs charset)
+	   cs)))
    ;; Last resort: search the coding system list for entries which
    ;; have the right mime-charset in case the canonical name isn't
    ;; defined (though it should be).
@@ -442,6 +491,8 @@
 		 (eq charset (or (coding-system-get c :mime-charset)
 				 (coding-system-get c 'mime-charset))))
 	    (setq cs c)))
+      (unless cs
+	(gnus-message 7 "Unknown charset: %s" charset))
       cs))))
 
 (eval-and-compile

[-- Attachment #3: Type: text/plain, Size: 1088 bytes --]


>> [1] More on (X)Emacs, Gnus and charsets (in German):
>>     http://theotp1.physik.uni-ulm.de/~ste/comp/emacs/gnus/draft/
>
> Currently unavailable.

Up again.  (But probably not up to date WRT Emacs 22.)

Bye, Reiner.

[*] I've posted a series of test postings for windows-125* to
    <news:gmane.test>:
    <news:2005-03-10-gmane-windows-1250@marauder.physik.uni-ulm.de>
    <news:2005-03-10-gmane-windows-1251@marauder.physik.uni-ulm.de>
    <news:2005-03-10-gmane-windows-1252@marauder.physik.uni-ulm.de>
    <news:2005-03-10-gmane-windows-1253@marauder.physik.uni-ulm.de>
    <news:2005-03-10-gmane-windows-1254@marauder.physik.uni-ulm.de>
    <news:2005-03-10-gmane-windows-1255@marauder.physik.uni-ulm.de>
    <news:2005-03-10-gmane-windows-1256@marauder.physik.uni-ulm.de>
    <news:2005-03-10-gmane-windows-1257@marauder.physik.uni-ulm.de>
    <news:2005-03-10-gmane-windows-1258@marauder.physik.uni-ulm.de>
    <news:2005-03-10-gmane-windows-1259@marauder.physik.uni-ulm.de>
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

  reply	other threads:[~2005-03-10 18:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-09 13:47 Matthias Andree
2005-03-09 15:24 ` Reiner Steib
2005-03-10  0:35   ` Matthias Andree
2005-03-10 18:53     ` Reiner Steib [this message]
2005-03-10 22:37       ` Miles Bader
2005-03-11 10:05         ` Reiner Steib

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=v9u0njtjry.fsf@marauder.physik.uni-ulm.de \
    --to=reinersteib+gmane@imap.cc \
    --cc=Reiner.Steib@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).