Function: rmail-edit-update-headers
rmail-edit-update-headers is a byte-compiled function defined in
rmailedit.el.gz.
Signature
(rmail-edit-update-headers HEADER-DIFF)
Documentation
Edit the mail headers in the buffer based on HEADER-DIFF.
HEADER-DIFF should be a return value from rmail-edit-diff-headers.
Source Code
;; Defined in /usr/src/emacs/lisp/mail/rmailedit.el.gz
(defun rmail-edit-update-headers (header-diff)
"Edit the mail headers in the buffer based on HEADER-DIFF.
HEADER-DIFF should be a return value from `rmail-edit-diff-headers'."
(let ((buf-headers (rmail-edit-headers-alist nil t)))
;; Change all the fields scheduled for being changed.
(dolist (chg (nth 2 header-diff))
(let* ((match (assoc (cdar chg) buf-headers))
(end (marker-position (nth 2 match))))
(goto-char end)
;; Insert the new, then delete the old.
;; That avoids collapsing markers.
(insert-before-markers (cddr chg))
(delete-region (nth 1 match) end)
;; Remove the old field from BUF-HEADERS.
(setq buf-headers (delq match buf-headers))
;; Update BUF-HEADERS to show the changed field.
(push (list (cddr chg) (point-marker)
(copy-marker (- (point) (length (cddr chg))))
(point-marker))
buf-headers)))
;; Delete all the fields scheduled for deletion.
;; We do deletion after changes
;; because when two fields look alike and get replaced by one,
;; the first of them is considered changed
;; and the second is considered deleted.
(dolist (del (nth 1 header-diff))
(let ((match (assoc (cdr del) buf-headers)))
(delete-region (nth 1 match) (nth 2 match))))
;; Insert all the fields scheduled for insertion.
(dolist (ins (nth 0 header-diff))
(let* ((new (cadr ins))
(after (car ins))
(match (assoc (cdr after) buf-headers)))
(goto-char (if match (nth 2 match) (point-min)))
(insert (cdr new))
;; Update BUF-HEADERS to show the inserted field.
(push (list (cdr new)
(copy-marker (- (point) (length (cdr new))))
(point-marker))
buf-headers)))
;; Disconnect the markers
(dolist (hdr buf-headers)
(set-marker (nth 1 hdr) nil)
(set-marker (nth 2 hdr) nil))))