+(cond
+ ((or (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))))