X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=elmo%2Futf7.el;h=30fdb7491c29faf3d9f37a0246a9f9a418a7ff37;hb=824fe18b2ad090f609041a4af11de484bdb7e3a8;hp=c6081e8d6ec5dd8d930483869bffba2850e748aa;hpb=a3d69085be30f08bf55db949762641e8689f3776;p=elisp%2Fwanderlust.git diff --git a/elmo/utf7.el b/elmo/utf7.el index c6081e8..30fdb74 100644 --- a/elmo/utf7.el +++ b/elmo/utf7.el @@ -91,8 +91,23 @@ (concat utf7-direct-encoding-chars "+\\~") "Character ranges which do not need escaping in the IMAP variant of UTF-7.") -(defconst utf7-utf-16-coding-system (and (fboundp 'find-coding-system) - (find-coding-system 'utf-16-be)) + +(eval-and-compile + (defun utf7-find-coding-system-without-bom (cs) + (and (fboundp 'find-coding-system) + (find-coding-system cs) + ;; Avoid versions with BOM. + (= 2 (length (encode-coding-string "a" cs))) + cs))) + +(defconst utf7-utf-16-coding-system + (or + ;; Emacs 22, Emacs 23 + (utf7-find-coding-system-without-bom 'utf-16be) + ;; + (utf7-find-coding-system-without-bom 'utf-16-be) + ;; Mule-UCS + (utf7-find-coding-system-without-bom 'utf-16-be-no-signature)) "Coding system which encodes big endian UTF-16.") (defsubst utf7-imap-get-pad-length (len modulus) @@ -196,13 +211,11 @@ Use IMAP modification if FOR-IMAP is non-nil." utf7-utf-16-coding-system) (set-buffer-multibyte nil) (goto-char (point-min)) - ;; Remove BOM (Big-endian UTF-16 FE FF) + ;; Remove BOM (Big-endian UTF-16 FE FF) for Mule-UCS (while (re-search-forward "\376\377" nil t) - (delete-region (match-beginning 0)(match-end 0)))) + (delete-region (match-beginning 0) (match-end 0)))) (lambda () (goto-char (point-min)) - ;; Add BOM (Big-endian UTF-16 FE FF) - (insert "\376\377") (decode-coding-region (point-min) (point-max) utf7-utf-16-coding-system)))))