X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=elmo%2Futf7.el;h=1000d68cd71a31a451872a00958a0f613738e6de;hb=a5bcb1f0eb41b558a6b4ed277047adc6b8676a2a;hp=81e66ee9e9cf2994dfd3062504c15306fbc8c927;hpb=1e366a559be4aec4ad4d3cf3e954b8e62a20d2f3;p=elisp%2Fwanderlust.git diff --git a/elmo/utf7.el b/elmo/utf7.el index 81e66ee..1000d68 100644 --- a/elmo/utf7.el +++ b/elmo/utf7.el @@ -86,9 +86,50 @@ "Return required length of padding for IMAP modified base64 fragment." (mod (- len) modulus)) -(static-cond +(cond + ((or (and (fboundp 'find-coding-system) + (find-coding-system 'utf-7)) + (module-installed-p 'un-define)) + (defun utf7-fragment-decode (start end &optional imap) + "Decode base64 encoded fragment from START to END of UTF-7 text in buffer. +Use IMAP modification if IMAP is non-nil." + (require 'un-define) + (save-restriction + (narrow-to-region start end) + (goto-char (point-min)) + (insert "+") + (when imap + (goto-char start) + (while (search-forward "," nil 'move-to-end) (replace-match "/"))) + (decode-coding-region (point-min) (point-max) 'utf-7))) + + (defun utf7-fragment-encode (start end &optional imap) + "Encode text from START to END in buffer as UTF-7 escape fragment. +Use IMAP modification if IMAP is non-nil." + (require 'un-define) + (let ((buffer (current-buffer)) + encoded-string) + (setq encoded-string + (with-temp-buffer + (insert-buffer-substring buffer start end) + (encode-coding-region (point-min) + (point-max) 'utf-7) + (goto-char (point-min)) + (when imap + (skip-chars-forward "+") + (delete-region (point-min) (point)) + (insert "&") + (while (search-forward "/" nil t) + (replace-match ","))) + (skip-chars-forward "^= \t\n" (point-max)) + (delete-region (point) (point-max)) + (buffer-string))) + (delete-region start end) + (insert encoded-string)))) ((and (featurep 'xemacs) - (module-installed-p 'xemacs-ucs)) + (or (and (fboundp 'find-coding-system) + (find-coding-system 'utf-8)) + (module-installed-p 'xemacs-ucs))) (defun utf7-fragment-decode (start end &optional imap) "Decode base64 encoded fragment from START to END of UTF-7 text in buffer. Use IMAP modification if IMAP is non-nil." @@ -105,7 +146,7 @@ Use IMAP modification if IMAP is non-nil." utf7-utf7-to-utf8-program t (current-buffer))) (decode-coding-region (point-min) (point-max) 'utf-8))) - + (defun utf7-fragment-encode (start end &optional imap) "Decode base64 encoded fragment from START to END of UTF-7 text in buffer. Use IMAP modification if IMAP is non-nil." @@ -136,54 +177,17 @@ Use IMAP modification if IMAP is non-nil." (buffer-string))) (delete-region start end) (insert encoded-string)))) - ((module-installed-p 'un-define) ;; Emacs - (defun utf7-fragment-decode (start end &optional imap) - "Decode base64 encoded fragment from START to END of UTF-7 text in buffer. -Use IMAP modification if IMAP is non-nil." - (require 'un-define) - (save-restriction - (narrow-to-region start end) - (goto-char (point-min)) - (insert "+") - (when imap - (goto-char start) - (while (search-forward "," nil 'move-to-end) (replace-match "/"))) - (decode-coding-region (point-min) (point-max) 'utf-7) - )) - - (defun utf7-fragment-encode (start end &optional imap) - "Encode text from START to END in buffer as UTF-7 escape fragment. -Use IMAP modification if IMAP is non-nil." - (require 'un-define) - (let ((buffer (current-buffer)) - encoded-string) - (setq encoded-string - (with-temp-buffer - (insert-buffer-substring buffer start end) - (encode-coding-region (point-min) - (point-max) 'utf-7) - (goto-char (point-min)) - (when imap - (skip-chars-forward "+") - (delete-region (point-min) (point)) - (insert "&") - (while (search-forward "/" nil t) - (replace-match ","))) - (skip-chars-forward "^= \t\n" (point-max)) - (delete-region (point) (point-max)) - (buffer-string))) - (delete-region start end) - (insert encoded-string)))) (t - ;; Define as null function. (defun utf7-fragment-decode (start end &optional imap) "Encode text from START to END in buffer as UTF-7 escape fragment. Use IMAP modification if IMAP is non-nil." + ;; Define as a null function. ) (defun utf7-fragment-encode (start end &optional imap) "Encode text from START to END in buffer as UTF-7 escape fragment. Use IMAP modification if IMAP is non-nil." + ;; Define as a null function. ))) (defun utf7-encode-region (start end &optional imap)