- (insert (mm-decode-string text charset))
- (save-window-excursion
- (save-restriction
- (let ((w3-strict-width width)
- ;; Don't let w3 set the global version of
- ;; this variable.
- (fill-column fill-column)
- (url-standalone-mode t))
- (condition-case var
- (w3-region (point-min) (point-max))
- (error
- (message
- "Error while rendering html; showing as text/plain"))))))
- (mm-handle-set-undisplayer
- handle
- `(lambda ()
- (let (buffer-read-only)
- (if (functionp 'remove-specifier)
- (mapcar (lambda (prop)
- (remove-specifier
- (face-property 'default prop)
- (current-buffer)))
- '(background background-pixmap foreground)))
- (delete-region ,(point-min-marker)
- ,(point-max-marker)))))))))
- ((or (equal type "enriched")
- (equal type "richtext"))
- (save-excursion
- (mm-with-unibyte-buffer
- (mm-insert-part handle)
- (save-window-excursion
- (enriched-decode (point-min) (point-max))
- (setq text (buffer-string)))))
- (mm-insert-inline handle text))
- ((equal type "x-vcard")
- (mm-insert-inline
+ (insert (mm-decode-string text charset))))
+ (save-window-excursion
+ (save-restriction
+ (let ((w3-strict-width width)
+ ;; Don't let w3 set the global version of
+ ;; this variable.
+ (fill-column fill-column))
+ (if (or debug-on-error debug-on-quit)
+ (w3-region (point-min) (point-max))
+ (condition-case ()
+ (w3-region (point-min) (point-max))
+ (error
+ (delete-region (point-min) (point-max))
+ (let ((b (point))
+ (charset (mail-content-type-get
+ (mm-handle-type handle) 'charset)))
+ (if (or (eq charset 'gnus-decoded)
+ (eq mail-parse-charset 'gnus-decoded))
+ (save-restriction
+ (narrow-to-region (point) (point))
+ (mm-insert-part handle)
+ (goto-char (point-max)))
+ (insert (mm-decode-string (mm-get-part handle)
+ charset))))
+ (message
+ "Error while rendering html; showing as text/plain")))))))
+ (mm-handle-set-undisplayer
+ handle
+ `(lambda ()
+ (let (buffer-read-only)
+ (if (functionp 'remove-specifier)
+ (mapcar (lambda (prop)
+ (remove-specifier
+ (face-property 'default prop)
+ (current-buffer)))
+ '(background background-pixmap foreground)))
+ (delete-region ,(point-min-marker)
+ ,(point-max-marker)))))))))
+
+(defvar mm-w3m-setup nil
+ "Whether gnus-article-mode has been setup to use emacs-w3m.")
+
+(defun mm-setup-w3m ()
+ "Setup gnus-article-mode to use emacs-w3m."
+ (unless mm-w3m-setup
+ (require 'w3m)
+ (unless (assq 'gnus-article-mode w3m-cid-retrieve-function-alist)
+ (push (cons 'gnus-article-mode 'mm-w3m-cid-retrieve)
+ w3m-cid-retrieve-function-alist))
+ (setq mm-w3m-setup t))
+ (setq w3m-display-inline-images mm-inline-text-html-with-images))
+
+(defun mm-w3m-cid-retrieve-1 (url handle)
+ (if (mm-multiple-handles handle)
+ (dolist (elem handle)
+ (mm-w3m-cid-retrieve-1 url elem))
+ (when (and (listp handle)
+ (equal url (mm-handle-id handle)))
+ (mm-insert-part handle)
+ (throw 'found-handle (mm-handle-media-type handle)))))
+
+(defun mm-w3m-cid-retrieve (url &rest args)
+ "Insert a content pointed by URL if it has the cid: scheme."
+ (when (string-match "\\`cid:" url)
+ (catch 'found-handle
+ (mm-w3m-cid-retrieve-1 (concat "<" (substring url (match-end 0)) ">")
+ (with-current-buffer w3m-current-buffer
+ gnus-article-mime-handles)))))
+
+(defun mm-inline-text-html-render-with-w3m (handle)
+ "Render a text/html part using emacs-w3m."
+ (mm-setup-w3m)
+ (let ((text (mm-get-part handle))
+ (b (point))
+ (charset (mail-content-type-get (mm-handle-type handle) 'charset)))
+ (save-excursion
+ (insert (if charset (mm-decode-string text charset) text))
+ (save-restriction
+ (narrow-to-region b (point))
+ (unless charset
+ (goto-char (point-min))
+ (when (setq charset (w3m-detect-meta-charset))
+ (delete-region (point-min) (point-max))
+ (insert (mm-decode-string text charset))))
+ (let ((w3m-safe-url-regexp mm-w3m-safe-url-regexp)
+ w3m-force-redisplay)
+ (w3m-region (point-min) (point-max) nil charset))
+ (when (and mm-inline-text-html-with-w3m-keymap
+ (boundp 'w3m-minor-mode-map)
+ w3m-minor-mode-map)
+ (add-text-properties
+ (point-min) (point-max)
+ (list 'keymap w3m-minor-mode-map
+ ;; Put the mark meaning this part was rendered by emacs-w3m.
+ 'mm-inline-text-html-with-w3m t))))
+ (mm-handle-set-undisplayer