forked from wanderlust/semi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmime-shr.el
71 lines (54 loc) · 2.27 KB
/
mime-shr.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
;;; mime-shr.el --- mime-view content filter using shr for html
;; Copyright (C) 2012 Kazuhiro Ito
;; Author: Kazuhiro Ito <[email protected]>
;; Keywords: HTML, MIME, multimedia, mail, news
;; This file is part of SEMI (Suite of Emacs MIME Interfaces).
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Code:
(eval-and-compile
(require 'shr nil t))
(require 'mime)
(defcustom mime-shr-blocked-images "."
"Images of which URLs match this regexp are blocked. Nil means the value of shr-blocked-images is used."
:group 'mime-view
:type '(choice regexp (const nil)))
(defvar mime-shr-root-entity nil)
(make-variable-buffer-local 'mime-shr-root-entity)
(defun mime-shr-preview-text/html (entity situation)
(let ((dom (with-temp-buffer
(mime-insert-text-content entity)
(libxml-parse-html-region (point-min) (point-max))))
(shr-content-function 'mime-shr-cid-retrieve)
(shr-blocked-images (or mime-shr-blocked-images
shr-blocked-images)))
(setq mime-shr-root-entity (mime-find-root-entity entity))
(goto-char (point-max))
(shr-insert-document dom))
;; Workaround to delete garbage overlay.
(let ((overlays (overlays-in (point-min) (point-max))))
(while overlays
(when (eq (overlay-start (car overlays))
(overlay-end (car overlays)))
(delete-overlay (car overlays)))
(setq overlays (cdr overlays)))))
(defun mime-shr-cid-retrieve (url)
(let ((entity (mime-find-entity-from-content-id
(mime-uri-parse-cid (concat "cid:" url))
mime-shr-root-entity)))
(when entity
(mime-entity-content entity))))
;;; @ end
;;;
(provide 'mime-shr)
;;; mime-shr.el ends here