🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.vm.bug
Article #504

[patch] VM 8.0.12 under Emacs 23: wrong charset for outgoing mail

#504
From: Ulrich Mueller
Date: Tue, 15 Sep 2009 20:44
138 lines
6466 bytes
Hallo Robert,
I hope that you are still around and listen to this channel.

For an outgoing message containing only latin-1 characters, e.g.
German umlauts, VM 8.012 under GNU Emacs 23 (both in their default
configuration) will use "iso-2022-jp" as encoding. That is not a
reasonable default.

The same VM version under GNU Emacs 22 will correctly encode the
message with "iso-8859-1".

Investigating the problem, I've found two problems in function
vm-determine-proper-charset:

1. The keys of vm-mime-mule-coding-to-charset-alist are symbols, not
   strings. So the following assq (occuring in similar form in the
   code four times) will always fail, because vm-coding-system-name
   returns a string:

     (assq (vm-coding-system-name sys)
           vm-mime-mule-coding-to-charset-alist)

   The call to vm-coding-system-name should just be omitted and its
   argument used directly instead.

2. Function vm-charsets-in-region is aliased to find-charset-region.
   In Emacs 23, there really aren't separate character sets any
   more, and find-charset-region will return the first match from
   charset-priority-list. In Emacs's default configuration, this can
   only be a subset of (iso-8859-1 ascii unicode).

   I believe that in Emacs 23 it's much easier to determine the proper
   coding system by calling check-coding-systems-region. The detour
   via character sets seems no longer necessary.

Below I include a patch for vm-mime.el that should fix both problems.
It is against 8.0.12, but should also apply to the current BZR trunk.
(I didn't fix indentation of the code in all cases, in order to keep the
patch small and human-readable.)

Unfortunately, the patch adds yet another case distinction. However,
I don't see how this could be avoided.

Ulrich


--- vm-8.0.12-orig/lisp/vm-mime.el
+++ vm-8.0.12/lisp/vm-mime.el
@@ -1409,7 +1409,6 @@
 
 (defvar buffer-file-coding-system)
 
-;; TODO: integrate with the FSF's unify-8859-on-encoding-mode stuff.
 (defun vm-determine-proper-charset (beg end)
   "Work out what MIME character set to use for sending a message.
 
@@ -1430,6 +1429,28 @@
 	(if (or vm-xemacs-mule-p
 		(and vm-fsfemacs-mule-p enable-multibyte-characters))
 	    ;; Okay, we're on a MULE build.
+	  (if (fboundp 'check-coding-systems-region)
+	      ;; check-coding-systems-region appeared in GNU Emacs 23.
+	      (let* ((preapproved (vm-get-coding-system-priorities))
+		     (ucs-list (vm-get-mime-ucs-list))
+		     (cant-encode (check-coding-systems-region
+				   (point-min) (point-max)
+				   (cons 'us-ascii preapproved))))
+		(if (not (assq 'us-ascii cant-encode))
+		    ;; If there are only ASCII chars, we're done.
+		    "us-ascii"
+		  (while (and preapproved
+			      (assq (car preapproved) cant-encode)
+			      (not (memq (car preapproved) ucs-list)))
+		    (setq preapproved (cdr preapproved)))
+		  (if preapproved
+		      (cadr (assq (car preapproved)
+				  vm-mime-mule-coding-to-charset-alist))
+		    ;; None of the entries in vm-coding-system-priorities
+		    ;; can be used. This can only happen if no universal
+		    ;; coding system is included. Fall back to utf-8.
+		    "utf-8")))
+
 	    (let ((charsets (delq 'ascii
 				  (vm-charsets-in-region (point-min)
 							 (point-max)))))
@@ -1472,9 +1493,7 @@
 				(while preapproved
 				  (if (memq (car preapproved) ucs-list)
 				      (throw 'done 
-					     (car (cdr (assq 
-							(vm-coding-system-name 
-							 (car preapproved))
+					     (car (cdr (assq (car preapproved)
 				      vm-mime-mule-coding-to-charset-alist)))))
 				  (setq preapproved (cdr preapproved)))
 				;; Nothing universal in the preapproved list.
@@ -1488,8 +1507,8 @@
 			    (when (latin-unity-maybe-remap (point-min) 
 							   (point-max) sys 
 							   csets psets t)
-			      (throw 'done (second (assq 
-						    (vm-coding-system-name sys)
+			      (throw 'done
+				     (second (assq sys
 				    vm-mime-mule-coding-to-charset-alist)))))
 			  (setq systems (cdr systems)))
 			(throw 'done nil))
@@ -1511,9 +1530,8 @@
 			    ;; If we encounter a universal character set on
 			    ;; the preapproved list, pass it back.
 			    (if (memq (car preapproved) ucs-list)
-				(throw 'done (second (assq 
-						      (vm-coding-system-name
-						       (car preapproved))
+				(throw 'done
+				       (second (assq (car preapproved)
 				     vm-mime-mule-coding-to-charset-alist))))
 
 			    ;; The preapproved entry isn't universal. Check if
@@ -1549,15 +1567,14 @@
 			    ;; If we encounter a universal character set on
 			    ;; the preapproved list, pass it back.
 			    (when (memq (car preapproved) ucs-list)
-				(throw 'done (second (assq 
-						      (vm-coding-system-name
-						       (car preapproved))
+			      (throw 'done
+				     (second (assq (car preapproved)
 				     vm-mime-mule-coding-to-charset-alist))))
 			    (setq preapproved (cdr preapproved)))))
 		    (throw 'done nil))))
 	       ;; Couldn't do any magic with vm-coding-system-priorities. Pass
 	       ;; back a Japanese iso-2022 MIME character set.
-	       (t (or vm-mime-8bit-composition-charset "iso-2022-jp"))))
+	       (t (or vm-mime-8bit-composition-charset "iso-2022-jp")))))
 	  ;; If we're non-MULE and there are eight bit characters, use a
 	  ;; sensible default.
 	  (goto-char (point-min))
Technical Details
Message-ID: <uy6ogdjjw@a1ihome1.kph.uni-mainz.de>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!news.belwue.de!news.Uni-Mainz.DE!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: a16957f451,e8e2b7caecb1773f,start
X-Google-Attributes: gida16957f451,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!news.belwue.de!news.Uni-Mainz.DE!not-for-mail
From: Ulrich Mueller <ulm@gentoo.org>
Newsgroups: gnu.emacs.vm.bug
Subject: [patch] VM 8.0.12 under Emacs 23: wrong charset for outgoing mail
Date: Tue, 15 Sep 2009 22:44:51 +0200
Organization: Institut fuer Kernphysik, Universitaet Mainz
Lines: 138
Message-ID: <uy6ogdjjw@a1ihome1.kph.uni-mainz.de>
NNTP-Posting-Host: a1ihome1.kph.uni-mainz.de
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news1.zdv.uni-mainz.de 1253047492 28670 134.93.134.75 (15 Sep 2009 20:44:52 GMT)
X-Complaints-To: news@uni-mainz.de
NNTP-Posting-Date: Tue, 15 Sep 2009 20:44:52 +0000 (UTC)
Cancel-Lock: sha1:uB0ATy689e5DOpuZRY71BByYEoc=