Function: mm-add-meta-html-tag
mm-add-meta-html-tag is a byte-compiled function defined in
mm-decode.el.gz.
Signature
(mm-add-meta-html-tag HANDLE &optional CHARSET FORCE-CHARSET)
Documentation
Add meta html tag to specify CHARSET of HANDLE in the current buffer.
CHARSET defaults to the one HANDLE specifies. Existing meta tag that specifies charset will not be modified unless FORCE-CHARSET is non-nil. Return t if meta tag is added or replaced.
Source Code
;; Defined in /usr/src/emacs/lisp/gnus/mm-decode.el.gz
(defun mm-add-meta-html-tag (handle &optional charset force-charset)
"Add meta html tag to specify CHARSET of HANDLE in the current buffer.
CHARSET defaults to the one HANDLE specifies. Existing meta tag that
specifies charset will not be modified unless FORCE-CHARSET is non-nil.
Return t if meta tag is added or replaced."
(when (equal (mm-handle-media-type handle) "text/html")
(when (or charset
(setq charset (mail-content-type-get (mm-handle-type handle)
'charset)))
(setq charset (format "\
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">" charset))
(let ((case-fold-search t))
(goto-char (point-min))
(if (re-search-forward "\
<meta\\s-+http-equiv=[\"']?content-type[\"']?\\s-+content=[\"']?\
text/html\\(?:;\\s-*charset=\\([^\t\n\r \"'>]+\\)\\)?[^>]*>" nil t)
(if (and (not force-charset)
(match-beginning 1))
;; Don't modify existing meta tag.
nil
;; Replace it with the one specifying charset.
(replace-match charset)
t)
(if (re-search-forward "<head>\\s-*" nil t)
(insert charset "\n")
(re-search-forward "<html\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
(insert "<head>\n" charset "\n</head>\n"))
t)))))