emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

imap.el: international/utf-7.el vs. gnus/utf7.el (was: 23.0.50; utf7-dec


From: Reiner Steib
Subject: imap.el: international/utf-7.el vs. gnus/utf7.el (was: 23.0.50; utf7-decode failed with non latin-1 charactor)
Date: Tue, 06 Nov 2007 20:53:08 +0100
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1.50 (gnu/linux)

On Mon, Nov 05 2007, Kenichi Handa wrote:

> Jason Rumney <address@hidden> writes:
>> Probably lisp/international/utf-7.el should be fixed, and the Gnus one
>> dropped.

Please keep in mind the we want to keep the Gnus versions in
Emacs/trunk (Gnus 5.13) and Gnus/trunk (aka No Gnus) in sync.  We want
to keep No Gnus compatible with Emacs 21+ (and XEmacs 21.4+).  So we
need to add some compatibility code.

> I think the right thing is to uncomment all codes for
> utf-7-map in utf-7.el, and modify gnus to use normal
> encode/decode-coding-region/string with utf-7-imap.
>
> I've just committed the former change.  

AFAIKS, `utf-7-encode' also accepts that FROM is a string, but it's
not documented.  Can we rely on this?  Could you document it, please?

> Could someone do the latter change?

A grep through Gnus' sources suggests that it only uses the functions
`utf7-encode' and `utf7-decode' in `imap.el'.

How about the following patch to gnus/utf7.el (untested)?  Could you
suggest a better test instead of `(<= 23 emacs-major-version)'?

Instead of -OLD and -NEW we should use more suitable names or include
the defuns directly.

--8<---------------cut here---------------start------------->8---
--- utf7.el     04 Aug 2007 20:36:34 +0200      1.12
+++ utf7.el     06 Nov 2007 20:42:08 +0100      
@@ -207,7 +207,7 @@
   (mm-decode-coding-region (point-min) (point-max) 'iso-8859-1)
   (mm-enable-multibyte))
 
-(defun utf7-encode (string &optional for-imap)
+(defun utf7-encode-OLD (string &optional for-imap)
   "Encode UTF-7 STRING.  Use IMAP modification if FOR-IMAP is non-nil."
   (let ((default-enable-multibyte-characters t))
     (with-temp-buffer
@@ -215,7 +215,7 @@
       (utf7-encode-internal for-imap)
       (buffer-string))))
 
-(defun utf7-decode (string &optional for-imap)
+(defun utf7-decode-OLD (string &optional for-imap)
   "Decode UTF-7 STRING.  Use IMAP modification if FOR-IMAP is non-nil."
   (let ((default-enable-multibyte-characters nil))
     (with-temp-buffer
@@ -224,6 +224,31 @@
       (mm-enable-multibyte)
       (buffer-string))))
 
+(defun utf7-encode-NEW (string &optional for-imap)
+  (with-temp-buffer
+    ;; (utf-7-encode FROM TO IMAP)
+    ;;
+    ;; `utf-7-encode' also accepts that FROM is a string, but it's not
+    ;; documented.
+    (utf-7-encode string nil for-imap)
+    (buffer-string)))
+
+(defun utf7-decode-NEW (string &optional for-imap)
+  (with-temp-buffer
+    (insert string)
+    (goto-char (point-min))
+    ;; (utf-7-decode LEN IMAP)
+    (utf-7-decode (buffer-size) for-imap)
+    (buffer-string)))
+
+(if (and (require 'utf-7 nil t) ;; Additional test for XEmacs?
+        (<= 23 emacs-major-version)) ;; A feature test would be better
+    (progn
+      (defalias 'utf7-encode 'utf7-encode-NEW)
+      (defalias 'utf7-decode 'utf7-decode-NEW))
+  (defalias 'utf7-encode 'utf7-encode-OLD)
+  (defalias 'utf7-decode 'utf7-decode-OLD))
+
 (provide 'utf7)
 
 ;;; arch-tag: 96078b55-85c7-4161-aed2-932c24b282c7
--8<---------------cut here---------------end--------------->8---

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]