Function: rmail-copy-headers

rmail-copy-headers is a byte-compiled function defined in rmail.el.gz.

Signature

(rmail-copy-headers BEG END &optional IGNORED-HEADERS)

Documentation

Copy displayed header fields to the message viewer buffer.

BEG and END marks the start and end positions of the message in the mbox buffer. If the optional argument IGNORED-HEADERS is non-nil, ignore all header fields whose names match that regexp. Otherwise, if rmail-displayed-headers is non-nil, copy only those header fields whose names match that regexp. Otherwise, copy all header fields whose names do not match rmail-ignored-headers (unless they also match rmail-nonignored-headers). Moves point in the message viewer buffer to the end of the headers.

Source Code

;; Defined in /usr/src/emacs/lisp/mail/rmail.el.gz
(defun rmail-copy-headers (beg _end &optional ignored-headers)
  "Copy displayed header fields to the message viewer buffer.
BEG and END marks the start and end positions of the message in
the mbox buffer.  If the optional argument IGNORED-HEADERS is
non-nil, ignore all header fields whose names match that regexp.
Otherwise, if `rmail-displayed-headers' is non-nil, copy only
those header fields whose names match that regexp.  Otherwise,
copy all header fields whose names do not match
`rmail-ignored-headers' (unless they also match
`rmail-nonignored-headers').  Moves point in the message viewer
buffer to the end of the headers."
  (let ((header-start-regexp "\n[^ \t]")
	lim)
    (with-current-buffer rmail-buffer
      (when (search-forward "\n\n" nil t)
	(forward-char -1)
	(save-restriction
	  ;; Put point right after the From header line.
	  (narrow-to-region beg (point))
	  (goto-char (point-min))
	  (unless (re-search-forward header-start-regexp nil t)
	    (rmail-error-bad-format))
	  (forward-char -1)
	  (cond
	   ;; Handle the case where all headers should be copied.
	   ((eq rmail-header-style 'full)
	    (prepend-to-buffer rmail-view-buffer beg (point-max))
	    ;; rmail-show-message-1 expects this function to leave point
	    ;; at the end of the headers.

	    (let ((len (- (point-max) beg)))
	      (with-current-buffer rmail-view-buffer
		(goto-char (1+ len)))))

	   ;; Handle the case where the headers matching the displayed
	   ;; headers regexp should be copied.
	   ((and rmail-displayed-headers (null ignored-headers))
	    (while (not (eobp))
	      (save-excursion
		(setq lim (if (re-search-forward header-start-regexp nil t)
			      (1+ (match-beginning 0))
			    (point-max))))
	      (when (looking-at rmail-displayed-headers)
		(append-to-buffer rmail-view-buffer (point) lim))
	      (goto-char lim)))
	   ;; Handle the ignored headers.
	   ((or ignored-headers (setq ignored-headers rmail-ignored-headers))
	    (while (and ignored-headers (not (eobp)))
	      (save-excursion
		(setq lim (if (re-search-forward header-start-regexp nil t)
			      (1+ (match-beginning 0))
			    (point-max))))
	      (if (and (looking-at ignored-headers)
		       (not (and rmail-nonignored-headers
				 (looking-at rmail-nonignored-headers))))
		  (goto-char lim)
		(append-to-buffer rmail-view-buffer (point) lim)
		(goto-char lim))))
	   (t (error "No headers selected for display!"))))))))