Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

2 views
Skip to first unread message

Ulrich Mueller

unread,
Sep 15, 2009, 4:44:51 PM9/15/09
to
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))

Uday S Reddy

unread,
Nov 19, 2009, 1:53:50 PM11/19/09
to
Ulrich Mueller wrote:

> 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.)

These patches have now been applied to version 8.1, revision 592.
Thanks Ulrich!

Cheers,
Uday

blueman

unread,
Nov 22, 2009, 4:09:14 AM11/22/09
to

Where can I find version 8.1 or is it still pre-release?

blueman

unread,
Nov 22, 2009, 4:10:28 AM11/22/09
to
Uday S Reddy <uDOTsD...@cs.bham.ac.uk> writes:

Where can I find version 8.1 or is it still pre-release??

Uday S Reddy

unread,
Nov 22, 2009, 5:16:55 AM11/22/09
to
blueman wrote:

>
> Where can I find version 8.1 or is it still pre-release?

It is pre-release I am afraid. I am in the process of applying various
patches that have been submitted including Rob's own updates to version 8.0.

The current version is at
http://bazaar.launchpad.net/~reddyuday/viewmail/8.1
and you have to pull it through bazaar. The README file tells you how.

Ulrich Mueller and I are in the process of setting up a separate
project/branch under launchpad, which might be more suitable as a
permanent home for VM.

Stay tuned.

Cheers,
Uday

0 new messages