-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmime-shr.el
85 lines (67 loc) · 2.89 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;;; mime-shr.el --- mime-view content filter using shr for html -*- lexical-binding: t -*-
;; 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-allowed-images nil
"Images of which URLs match this regexp are displayed.
When nil, it means the value of `shr-allowed-images' is used.
This variable doesn't take effect on Emacs 28 and earlier."
:group 'mime-view
:type '(choice regexp (const nil)))
(defcustom mime-shr-blocked-images "."
"Images of which URLs match this regexp are blocked.
When nil, it means the value of `shr-blocked-images' is used.
This has higher piority than `mime-shr-allowed-images'."
:group 'mime-view
:type '(choice regexp (const nil)))
(defvar-local mime-shr-root-entity nil)
(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-allowed-images (or mime-shr-allowed-images
(when (boundp 'shr-allowed-images)
shr-allowed-images)))
(shr-blocked-images (or mime-shr-blocked-images
shr-blocked-images)))
(setq mime-shr-root-entity (mime-find-root-entity entity))
(save-restriction
;; shr-insert-document may insert document before current point.
;; Cf. https://github.com/wanderlust/semi/issues/11
(narrow-to-region (point-max) (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