Function: rmail-mime-entity-segment

rmail-mime-entity-segment is a byte-compiled function defined in rmailmm.el.gz.

Signature

(rmail-mime-entity-segment POS &optional ENTITY)

Documentation

Return a vector describing the displayed region of a MIME-entity at POS.

Optional 2nd argument ENTITY is the MIME-entity at POS. The value is a vector [INDEX HEADER TAGLINE BODY END], where
  INDEX: index into the returned vector indicating where POS is (1..3)
  HEADER: the position of the beginning of a header
  TAGLINE: the position of the beginning of a tag line, including
           the newline that precedes it
  BODY: the position of the beginning of a body
  END: the position of the end of the entity.

Source Code

;; Defined in /usr/src/emacs/lisp/mail/rmailmm.el.gz
(defun rmail-mime-entity-segment (pos &optional entity)
  "Return a vector describing the displayed region of a MIME-entity at POS.
Optional 2nd argument ENTITY is the MIME-entity at POS.
The value is a vector [INDEX HEADER TAGLINE BODY END], where
  INDEX: index into the returned vector indicating where POS is (1..3)
  HEADER: the position of the beginning of a header
  TAGLINE: the position of the beginning of a tag line, including
           the newline that precedes it
  BODY: the position of the beginning of a body
  END: the position of the end of the entity."
  (save-excursion
    (or entity
	(setq entity (get-text-property pos 'rmail-mime-entity)))
    (if (not entity)
	(vector 1 (point) (point) (point) (point))
      (let ((current (aref (rmail-mime-entity-display entity) 0))
	    (beg (if (and (> pos (point-min))
			  (eq (get-text-property (1- pos) 'rmail-mime-entity)
			      entity))
		     (previous-single-property-change pos 'rmail-mime-entity
						      nil (point-min))
		   pos))
	    (index 1)
	    tagline-beg body-beg end)
	(goto-char beg)
	;; If the header is displayed, get past it to the tagline.
	(if (rmail-mime-display-header current)
	    (search-forward "\n\n" nil t))
	(setq tagline-beg (point))
	(if (>= pos tagline-beg)
	    (setq index 2))
	;; If the tagline is displayed, get past it to the body.
	(if (rmail-mime-display-tagline current)
	    ;; The next forward-line call must be in sync with how
	    ;; `rmail-mime-insert-tagline' formats the tagline.  The
	    ;; body begins after the empty line that ends the tagline.
	    (forward-line 3))
	(setq body-beg (point))
	(if (>= pos body-beg)
	    (setq index 3))
	;; If the body is displayed, find its end.
	(if (rmail-mime-display-body current)
	    (let ((tag (aref (rmail-mime-entity-tagline entity) 0))
		  tag2)
	      (setq end (next-single-property-change beg 'rmail-mime-entity
						     nil (point-max)))
	      ;; `tag' is either an empty string or "/n" where n is
	      ;; the number of the part of the multipart MIME message.
	      ;; The loop below finds the next location whose
	      ;; `rmail-mime-entity' property specifies a tag of a
	      ;; different value.
	      (while (and (< end (point-max))
			  (setq entity (get-text-property end 'rmail-mime-entity)
				tag2 (aref (rmail-mime-entity-tagline entity) 0))
			  (and (> (length tag2) 0)
			       (eq (string-match tag tag2) 0)))
		(setq end (next-single-property-change end 'rmail-mime-entity
						       nil (point-max)))))
	  (setq end body-beg))
	(vector index beg tagline-beg body-beg end)))))