Function: rmail-mime-insert-html

rmail-mime-insert-html is a byte-compiled function defined in rmailmm.el.gz.

Signature

(rmail-mime-insert-html ENTITY)

Documentation

Decode, render, and insert html from MIME-entity ENTITY.

Source Code

;; Defined in /usr/src/emacs/lisp/mail/rmailmm.el.gz
(defun rmail-mime-insert-html (entity)
  "Decode, render, and insert html from MIME-entity ENTITY."
  (let ((body (rmail-mime-entity-body entity))
	(transfer-encoding (rmail-mime-entity-transfer-encoding entity))
	(charset (cdr (assq 'charset (cdr (rmail-mime-entity-type entity)))))
	(buffer (current-buffer))
	(case-fold-search t)
	coding-system)
    (if charset (setq coding-system (coding-system-from-name charset)))
    (or (and coding-system (coding-system-p coding-system))
	(setq coding-system 'undecided))
    (with-temp-buffer
      (set-buffer-multibyte nil)
      (setq buffer-undo-list t)
      (insert-buffer-substring rmail-mime-mbox-buffer
			       (aref body 0) (aref body 1))
      (cond ((string= transfer-encoding "base64")
	     (ignore-errors (base64-decode-region (point-min) (point-max))))
	    ((string= transfer-encoding "quoted-printable")
	     (quoted-printable-decode-region (point-min) (point-max))))
      ;; Some broken MUAs state the charset only in the HTML <head>,
      ;; so if we don't have a non-trivial coding-system at this
      ;; point, make one last attempt to find it there.
      (if (eq coding-system 'undecided)
	  (save-excursion
	    (goto-char (point-min))
	    (when (re-search-forward
		   "^<html><head><meta[^;]*; charset=\\([-a-zA-Z0-9]+\\)"
		   nil t)
	      (setq coding-system (coding-system-from-name (match-string 1)))
	      (or (and coding-system (coding-system-p coding-system))
		  (setq coding-system 'undecided)))
	    ;; Finally, let them manually force decoding if they know it.
	    (if (and (eq coding-system 'undecided)
		     (not (null coding-system-for-read)))
		(setq coding-system coding-system-for-read))))
      (decode-coding-region (point-min) (point) coding-system)
      (if (and
	   (or (not rmail-mime-coding-system) (consp rmail-mime-coding-system))
	   (not (eq (coding-system-base coding-system) 'us-ascii)))
	  (setq rmail-mime-coding-system coding-system))
      ;; Convert html in temporary buffer to text and insert in original buffer
      (let ((source-buffer (current-buffer)))
	(with-current-buffer buffer
	  (let ((start (point)))
	    (if rmail-mime-render-html-function
		(funcall rmail-mime-render-html-function source-buffer)
	      (insert-buffer-substring source-buffer))
	    (rmail-mime-fix-inserted-faces start)))))))