Function: mail-insert-from-field

mail-insert-from-field is a byte-compiled function defined in sendmail.el.gz.

Signature

(mail-insert-from-field)

Documentation

Insert the "From:" field of a mail header.

The style of the field is determined by the variable mail-from-style. This function does not perform RFC2047 encoding.

Source Code

;; Defined in /usr/src/emacs/lisp/mail/sendmail.el.gz
(defun mail-insert-from-field ()
  "Insert the \"From:\" field of a mail header.
The style of the field is determined by the variable `mail-from-style'.
This function does not perform RFC2047 encoding."
  (let* ((login user-mail-address)
	 (fullname (user-full-name))
	 (quote-fullname nil))
    (if (string-match "[^\0-\177]" fullname)
	(setq quote-fullname t))
    (cond ((null mail-from-style)
	   (insert "From: " login "\n"))
	  ;; This is deprecated.
	  ((eq mail-from-style 'system-default)
	   nil)
	  ((or (eq mail-from-style 'angles)
	       (and (not (eq mail-from-style 'parens))
		    ;; Use angles if no quoting is needed, or if
		    ;; parens would need quoting too.
		    (or (not (string-match "[^- !#-'*+/-9=?A-Z^-~]" fullname))
			(let ((tmp (concat fullname nil)))
			  (while (string-match "([^()]*)" tmp)
			    (aset tmp (match-beginning 0) ?-)
			    (aset tmp (1- (match-end 0)) ?-))
			  (string-match "[\\()]" tmp)))))
	   (insert "From: " fullname)
	   (let ((fullname-start (+ (point-min) 6))
		 (fullname-end (point-marker)))
	     (goto-char fullname-start)
	     ;; Look for a character that cannot appear unquoted
	     ;; according to RFC 822 (or later).
	     (if (or (re-search-forward "[^- !#-'*+/-9=?A-Z^-~]"
					fullname-end 1)
		     quote-fullname)
		 (progn
		   ;; Quote fullname, escaping specials.
		   (goto-char fullname-start)
		   (insert "\"")
		   (while (re-search-forward "[\"\\]"
					     fullname-end 1)
		     (replace-match "\\\\\\&" t))
		   (insert "\""))))
	   (insert " <" login ">\n"))
	  ;; 'parens or default
	  (t
	   (insert "From: " login " (")
	   (let ((fullname-start (point)))
	     (if quote-fullname
		 (insert "\""))
	     (insert fullname)
	     (if quote-fullname
		 (insert "\""))
	     (let ((fullname-end (point-marker)))
	       (goto-char fullname-start)
	       ;; \ and nonmatching parentheses must be escaped in comments.
	       ;; Escape every instance of ()\ ...
	       (while (re-search-forward "[()\\]" fullname-end 1)
		 (replace-match "\\\\\\&" t))
	       ;; ... then undo escaping of matching parentheses,
	       ;; including matching nested parentheses.
	       (goto-char fullname-start)
	       (while (re-search-forward
		       "\\(\\=\\|[^\\]\\(\\\\\\\\\\)*\\)\\\\(\\(\\([^\\]\\|\\\\\\\\\\)*\\)\\\\)"
		       fullname-end 1)
		 (replace-match "\\1(\\3)" t)
		 (goto-char fullname-start))))
	   (insert ")\n")))))