Function: utf7-encode-internal

utf7-encode-internal is a byte-compiled function defined in utf7.el.gz.

Signature

(utf7-encode-internal &optional FOR-IMAP)

Documentation

Encode text in (temporary) buffer as UTF-7.

Use IMAP modification if FOR-IMAP is non-nil.

Source Code

;; Defined in /usr/src/emacs/lisp/international/utf7.el.gz
(defun utf7-encode-internal (&optional for-imap)
  "Encode text in (temporary) buffer as UTF-7.
Use IMAP modification if FOR-IMAP is non-nil."
  (let ((start (point-min))
	(end (point-max)))
    (narrow-to-region start end)
    (goto-char start)
    (let* ((esc-char (if for-imap ?& ?+))
	   (direct-encoding-chars
	    (if for-imap utf7-imap-direct-encoding-chars
	      utf7-direct-encoding-chars))
	   (not-direct-encoding-chars (concat "^" direct-encoding-chars)))
      (while (not (eobp))
	(skip-chars-forward direct-encoding-chars)
	(unless (eobp)
	  (insert esc-char)
	  (let ((p (point))
		(fc (following-char))
		(run-length
		 (skip-chars-forward not-direct-encoding-chars)))
	    (if (and (= fc esc-char)
		     (= run-length 1))	; Lone esc-char?
		(delete-char -1)        ; Now there's one too many
	      (utf7-fragment-encode p (point) for-imap))
	    (insert "-")))))))