Function: rmail-reply

rmail-reply is an interactive and byte-compiled function defined in rmail.el.gz.

Signature

(rmail-reply JUST-SENDER)

Documentation

Reply to the current message.

Normally include Cc: to all other recipients of original message; prefix argument means ignore them. While composing the reply, use M-x mail-yank-original (mail-yank-original) to yank the original message into it.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/mail/rmail.el.gz
(defun rmail-reply (just-sender)
  "Reply to the current message.
Normally include Cc: to all other recipients of original message;
prefix argument means ignore them.  While composing the reply,
use \\[mail-yank-original] to yank the original message into it."
  (interactive "P")
  (if (zerop rmail-current-message)
      (error "There is no message to reply to"))
  (let (from reply-to cc subject date to message-id references
	     ;; resent-to resent-cc resent-reply-to
	     (msgnum rmail-current-message))
    (rmail-apply-in-message
     rmail-current-message
     (lambda ()
       (let ((end (point-max))
             subheader)
         ;; Find the message's real header.
         (search-forward "\n\n" nil 'move)
         (narrow-to-region (point-min) (point))

         (goto-char (point-min))

         ;; If this is an encrypted message, search for other header fields
         ;; inside the encrypted part, and use them instead of the real header.

         ;; First, find a From: field after a plausible section start.
         (when (and (search-forward "\nContent-Type: multipart/encrypted;\n" nil t)
                    (save-restriction
                      (narrow-to-region (point-min) end)
                      (and (search-forward "\nFrom: " nil t)
                           (setq subheader (point)))))
           ;; We found one, so widen up to end of message and go there.
           (narrow-to-region (point-min) end)
           (goto-char subheader)

           ;; Find the start of the inner header.
           (search-backward "\n--")
           (forward-line 2)

           ;; Find the end of it.
           (let ((subheader-start (point)))
             (goto-char subheader)
             (search-forward "\n\n" nil 'move)
             (narrow-to-region subheader-start (point))))

         (setq from (mail-fetch-field "from")
               reply-to (or (mail-fetch-field "mail-reply-to" nil t)
                            (mail-fetch-field "reply-to" nil t)
                            from)
               subject (mail-fetch-field "subject")
               date (mail-fetch-field "date")
               message-id (mail-fetch-field "message-id")
               references (mail-fetch-field "references" nil nil t)
               ;; Bug#512.  It's inappropriate to reply to these addresses.
               ;;resent-reply-to (mail-fetch-field "resent-reply-to" nil t)
               ;;resent-cc (and (not just-sender)
               ;;           (mail-fetch-field "resent-cc" nil t))
               ;;resent-to (or (mail-fetch-field "resent-to" nil t) "")
               ;;resent-subject (mail-fetch-field "resent-subject")
               ;;resent-date (mail-fetch-field "resent-date")
               ;;resent-message-id (mail-fetch-field "resent-message-id")
               )
         (unless just-sender
           (if (mail-fetch-field "mail-followup-to" nil t)
               ;; If this header field is present, use it instead of the
               ;; To and Cc fields.
               (setq to (mail-fetch-field "mail-followup-to" nil t))
             (setq cc (or (mail-fetch-field "cc" nil t) "")
                   to (or (mail-fetch-field "to" nil t) "")))))))
    ;; Merge the resent-to and resent-cc into the to and cc.
    ;; Bug#512.  It's inappropriate to reply to these addresses.
    ;;(if (and resent-to (not (equal resent-to "")))
    ;;    (setq to (if (not (equal to ""))
    ;;                 (concat to ", " resent-to)
    ;;               resent-to)))
    ;;(if (and resent-cc (not (equal resent-cc "")))
    ;;    (setq cc (if (not (equal cc ""))
    ;;                 (concat cc ", " resent-cc)
    ;;               resent-cc)))
    ;; Add `Re: ' to subject if not there already.
    (and (stringp subject)
	 (setq subject (rfc2047-decode-string subject)
	       subject
	       (concat rmail-reply-prefix
		       (if (let ((case-fold-search t))
			     (string-match rmail-reply-regexp subject))
			   (substring subject (match-end 0))
			 subject))))
    (rmail-start-mail
     nil
     ;; Using mail-strip-quoted-names is undesirable with newer mailers
     ;; since they can handle the names unstripped.
     ;; I don't know whether there are other mailers that still
     ;; need the names to be stripped.
;;;     (mail-strip-quoted-names reply-to)
     ;; Remove unwanted names from reply-to, since Mail-Followup-To
     ;; header causes all the names in it to wind up in reply-to, not
     ;; in cc.  But if what's left is an empty list, use the original.
     (let* ((reply-to-list (mail-dont-reply-to reply-to)))
       (if (string= reply-to-list "") reply-to reply-to-list))
     subject
     (rmail-make-in-reply-to-field from date message-id)
     (if just-sender
	 nil
       ;; `mail-dont-reply-to' doesn't need `mail-strip-quoted-names'.
       (let* ((cc-list (mail-dont-reply-to
			(mail-strip-quoted-names
			 (if (null cc) to (concat to ", " cc))))))
	 (if (string= cc-list "") nil cc-list)))
     rmail-buffer
     (list (list 'rmail-mark-message
		 rmail-buffer
		 (with-current-buffer rmail-buffer
		   (aref rmail-msgref-vector msgnum))
		 rmail-answered-attr-index))
     nil
     (if (or references message-id)
	 (list (cons "References" (if references
				      (concat
				       (mapconcat #'identity references " ")
				       " " message-id)
				    message-id)))))))