(if charset
;; Add a meta html tag to specify charset.
(mm-with-unibyte-buffer
- (insert (with-current-buffer (mm-handle-buffer handle)
- (if (eq charset 'gnus-decoded)
- (mm-encode-coding-string
- (buffer-string)
- (setq charset 'utf-8))
- (buffer-string))))
- (setq charset (format "\
-<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">"
- charset))
+ (insert
+ (if (eq charset 'gnus-decoded)
+ (mm-encode-coding-string (mm-get-part handle)
+ (setq charset 'utf-8))
+ (mm-get-part handle)))
(goto-char (point-min))
(let ((case-fold-search t))
- (cond (;; Don't modify existing meta tag.
- (re-search-forward "\
-<meta[\t\n\r ]+http-equiv=\"content-type\"[^>]+>"
- nil t))
- ((re-search-forward "<head>[\t\n\r ]*" nil t)
- (insert charset "\n"))
- (t
- (re-search-forward "\
-<html\\(?:[\t\n\r ]+[^>]+\\|[\t\n\r ]*\\)>[\t\n\r ]*"
- nil t)
- (insert "<head>\n" charset "\n</head>\n"))))
+ (if (re-search-forward "\
+<meta[\t\n\r ]+http-equiv=\"content-type\"[^>]+>" nil t)
+ nil ;; Don't modify existing meta tag.
+ (setq charset (format "\
+<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">" charset))
+ (if (re-search-forward "<head>[\t\n\r ]*" nil t)
+ (insert charset "\n")
+ (re-search-forward "\
+<html\\(?:[\t\n\r ]+[^>]+\\|[\t\n\r ]*\\)>[\t\n\r ]*" nil t)
+ (insert "<head>\n" charset "\n</head>\n"))))
(mm-write-region (point-min) (point-max)
tmp-file nil nil nil 'binary t))
(mm-save-part-to-file handle tmp-file))