aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKatsumi Yamaoka2010-11-18 02:00:00 +0000
committerKatsumi Yamaoka2010-11-18 02:00:00 +0000
commit6568a67db86939bf4067f4b606a3a8adbce9096f (patch)
treec37f1408392acab606a166ba71be9f34f4bf0e72
parentc0f9edcead3abc84d0732d8099dedcfaea89219b (diff)
downloademacs-6568a67db86939bf4067f4b606a3a8adbce9096f.tar.gz
emacs-6568a67db86939bf4067f4b606a3a8adbce9096f.zip
gnus-html.el: Don't display images if gnus-inhibit-images is non-nil.
(gnus-html-wash-images): Don't display images if gnus-inhibit-images is non-nil; register displayer for cid images. (gnus-html-display-image): Work for cid image. (gnus-html-insert-image): Allow arguments. (gnus-html-put-image): Inhibit read-only. (gnus-html-prefetch-images): Don't prefetch images if gnus-inhibit-images is non-nil.
-rw-r--r--lisp/gnus/ChangeLog10
-rw-r--r--lisp/gnus/gnus-html.el150
2 files changed, 92 insertions, 68 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index a22314646f4..7b5fb12361f 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,3 +1,13 @@
12010-11-18 Katsumi Yamaoka <yamaoka@jpl.org>
2
3 * gnus-html.el (gnus-html-wash-images): Don't display images if
4 gnus-inhibit-images is non-nil; register displayer for cid images.
5 (gnus-html-display-image): Work for cid image.
6 (gnus-html-insert-image): Allow arguments.
7 (gnus-html-put-image): Inhibit read-only.
8 (gnus-html-prefetch-images): Don't prefetch images if
9 gnus-inhibit-images is non-nil.
10
12010-11-17 Lars Magne Ingebrigtsen <larsi@gnus.org> 112010-11-17 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 12
3 * shr.el (shr-put-image): Break lines when inserting big pictures. 13 * shr.el (shr-put-image): Break lines when inserting big pictures.
diff --git a/lisp/gnus/gnus-html.el b/lisp/gnus/gnus-html.el
index dc2400c0246..4df9a0fbedc 100644
--- a/lisp/gnus/gnus-html.el
+++ b/lisp/gnus/gnus-html.el
@@ -169,7 +169,7 @@ CHARS is a regexp-like character alternative (e.g., \"[)$]\")."
169 169
170(defun gnus-html-wash-images () 170(defun gnus-html-wash-images ()
171 "Run through current buffer and replace img tags by images." 171 "Run through current buffer and replace img tags by images."
172 (let (tag parameters string start end images url) 172 (let (tag parameters string start end images url alt-text)
173 (goto-char (point-min)) 173 (goto-char (point-min))
174 ;; Search for all the images first. 174 ;; Search for all the images first.
175 (while (re-search-forward "<img_alt \\([^>]*\\)>" nil t) 175 (while (re-search-forward "<img_alt \\([^>]*\\)>" nil t)
@@ -180,81 +180,93 @@ CHARS is a regexp-like character alternative (e.g., \"[)$]\")."
180 (delete-region (match-beginning 0) (match-end 0))) 180 (delete-region (match-beginning 0) (match-end 0)))
181 (setq end (point)) 181 (setq end (point))
182 (when (string-match "src=\"\\([^\"]+\\)" parameters) 182 (when (string-match "src=\"\\([^\"]+\\)" parameters)
183 (setq url (gnus-html-encode-url (match-string 1 parameters)))
184 (gnus-message 8 "gnus-html-wash-tags: fetching image URL %s" url) 183 (gnus-message 8 "gnus-html-wash-tags: fetching image URL %s" url)
185 (if (string-match "^cid:\\(.*\\)" url) 184 (setq url (gnus-html-encode-url (match-string 1 parameters))
185 alt-text (when (string-match "\\(alt\\|title\\)=\"\\([^\"]+\\)"
186 parameters)
187 (xml-substitute-special (match-string 2 parameters))))
188 (gnus-add-text-properties
189 start end
190 (list 'image-url url
191 'image-displayer `(lambda (url start end)
192 (gnus-html-display-image url start end
193 ,alt-text))
194 'gnus-image (list url start end alt-text)))
195 (gnus-overlay-put (gnus-make-overlay start end)
196 'local-map gnus-html-image-map)
197 (if (string-match "\\`cid:" url)
186 ;; URLs with cid: have their content stashed in other 198 ;; URLs with cid: have their content stashed in other
187 ;; parts of the MIME structure, so just insert them 199 ;; parts of the MIME structure, so just insert them
188 ;; immediately. 200 ;; immediately.
189 (let* ((handle (mm-get-content-id 201 (let* ((handle (mm-get-content-id (substring url (match-end 0))))
190 (setq url (match-string 1 url)))) 202 (image (when (and handle
191 (image (when handle 203 (not gnus-inhibit-images))
192 (gnus-create-image 204 (gnus-create-image
193 (mm-with-part handle (buffer-string)) 205 (mm-with-part handle (buffer-string))
194 nil t)))) 206 nil t))))
195 (when image 207 (if image
196 (let ((string (buffer-substring start end))) 208 (progn
197 (delete-region start end) 209 (gnus-put-image
198 (gnus-put-image (gnus-rescale-image 210 (gnus-rescale-image
199 image (gnus-html-maximum-image-size)) 211 image (gnus-html-maximum-image-size))
200 (gnus-string-or string "*") 'cid) 212 (gnus-string-or (prog1
201 (gnus-add-image 'cid image)))) 213 (buffer-substring start end)
214 (delete-region start end))
215 "*")
216 'cid)
217 (gnus-add-image 'cid image))
218 (widget-convert-button
219 'link start end
220 :action 'gnus-html-insert-image
221 :help-echo url
222 :keymap gnus-html-image-map
223 :button-keymap gnus-html-image-map)))
202 ;; Normal, external URL. 224 ;; Normal, external URL.
203 (let ((alt-text 225 (if (or gnus-inhibit-images
204 (when (string-match "\\(alt\\|title\\)=\"\\([^\"]+\\)" 226 (gnus-html-image-url-blocked-p
205 parameters) 227 url
206 (xml-substitute-special (match-string 2 parameters))))) 228 (if (buffer-live-p gnus-summary-buffer)
207 (gnus-put-text-property start end 'image-url url) 229 (with-current-buffer gnus-summary-buffer
208 (gnus-put-text-property 230 (gnus-blocked-images))
209 start end 'image-displayer 231 (gnus-blocked-images))))
210 (lambda (url start end) 232 (widget-convert-button
211 (gnus-html-display-image url start end))) 233 'link start end
212 (if (gnus-html-image-url-blocked-p 234 :action 'gnus-html-insert-image
213 url 235 :help-echo url
214 (if (buffer-live-p gnus-summary-buffer) 236 :keymap gnus-html-image-map
215 (with-current-buffer gnus-summary-buffer 237 :button-keymap gnus-html-image-map)
216 (gnus-blocked-images)) 238 ;; Non-blocked url
217 (gnus-blocked-images))) 239 (let ((width
218 (progn 240 (when (string-match "width=\"?\\([0-9]+\\)" parameters)
219 (widget-convert-button 241 (string-to-number (match-string 1 parameters))))
220 'link start end 242 (height
221 :action 'gnus-html-insert-image 243 (when (string-match "height=\"?\\([0-9]+\\)" parameters)
222 :help-echo url 244 (string-to-number (match-string 1 parameters)))))
223 :keymap gnus-html-image-map 245 ;; Don't fetch images that are really small. They're
224 :button-keymap gnus-html-image-map) 246 ;; probably tracking pictures.
225 (let ((overlay (gnus-make-overlay start end)) 247 (when (and (or (null height)
226 (spec (list url start end alt-text))) 248 (> height 4))
227 (gnus-overlay-put overlay 'local-map gnus-html-image-map) 249 (or (null width)
228 (gnus-overlay-put overlay 'gnus-image spec) 250 (> width 4)))
229 (gnus-put-text-property 251 (gnus-html-display-image url start end alt-text)))))))))
230 start end
231 'gnus-image spec)))
232 ;; Non-blocked url
233 (let ((width
234 (when (string-match "width=\"?\\([0-9]+\\)" parameters)
235 (string-to-number (match-string 1 parameters))))
236 (height
237 (when (string-match "height=\"?\\([0-9]+\\)" parameters)
238 (string-to-number (match-string 1 parameters)))))
239 ;; Don't fetch images that are really small. They're
240 ;; probably tracking pictures.
241 (when (and (or (null height)
242 (> height 4))
243 (or (null width)
244 (> width 4)))
245 (gnus-html-display-image url start end alt-text))))))))))
246 252
247(defun gnus-html-display-image (url start end &optional alt-text) 253(defun gnus-html-display-image (url start end &optional alt-text)
248 "Display image at URL on text from START to END. 254 "Display image at URL on text from START to END.
249Use ALT-TEXT for the image string." 255Use ALT-TEXT for the image string."
250 (if (gnus-html-cache-expired url gnus-html-image-cache-ttl) 256 (or alt-text (setq alt-text "*"))
251 ;; We don't have it, so schedule it for fetching 257 (if (string-match "\\`cid:" url)
252 ;; asynchronously. 258 (let ((handle (mm-get-content-id (substring url (match-end 0)))))
253 (gnus-html-schedule-image-fetching 259 (when handle
254 (current-buffer) 260 (gnus-html-put-image (mm-with-part handle (buffer-string))
255 (list url alt-text)) 261 url alt-text)))
256 ;; It's already cached, so just insert it. 262 (if (gnus-html-cache-expired url gnus-html-image-cache-ttl)
257 (gnus-html-put-image (gnus-html-get-image-data url) url (or alt-text "*")))) 263 ;; We don't have it, so schedule it for fetching
264 ;; asynchronously.
265 (gnus-html-schedule-image-fetching
266 (current-buffer)
267 (list url alt-text))
268 ;; It's already cached, so just insert it.
269 (gnus-html-put-image (gnus-html-get-image-data url) url alt-text))))
258 270
259(defun gnus-html-wash-tags () 271(defun gnus-html-wash-tags ()
260 (let (tag parameters string start end images url) 272 (let (tag parameters string start end images url)
@@ -338,7 +350,7 @@ Use ALT-TEXT for the image string."
338 (replace-match "" t t)) 350 (replace-match "" t t))
339 (mm-url-decode-entities))) 351 (mm-url-decode-entities)))
340 352
341(defun gnus-html-insert-image () 353(defun gnus-html-insert-image (&rest args)
342 "Fetch and insert the image under point." 354 "Fetch and insert the image under point."
343 (interactive) 355 (interactive)
344 (apply 'gnus-html-display-image (get-text-property (point) 'gnus-image))) 356 (apply 'gnus-html-display-image (get-text-property (point) 'gnus-image)))
@@ -437,7 +449,8 @@ Return a string with image data."
437 (save-excursion 449 (save-excursion
438 (goto-char start) 450 (goto-char start)
439 (let ((alt-text (or alt-text 451 (let ((alt-text (or alt-text
440 (buffer-substring-no-properties start end)))) 452 (buffer-substring-no-properties start end)))
453 (inhibit-read-only t))
441 (if (and image 454 (if (and image
442 ;; Kludge to avoid displaying 30x30 gif images, which 455 ;; Kludge to avoid displaying 30x30 gif images, which
443 ;; seems to be a signal of a broken image. 456 ;; seems to be a signal of a broken image.
@@ -498,7 +511,8 @@ Return a string with image data."
498 (while (re-search-forward "<img[^>]+src=[\"']\\(http[^\"']+\\)" nil t) 511 (while (re-search-forward "<img[^>]+src=[\"']\\(http[^\"']+\\)" nil t)
499 (let ((url (gnus-html-encode-url 512 (let ((url (gnus-html-encode-url
500 (mm-url-decode-entities-string (match-string 1))))) 513 (mm-url-decode-entities-string (match-string 1)))))
501 (unless (gnus-html-image-url-blocked-p url blocked-images) 514 (unless (or gnus-inhibit-images
515 (gnus-html-image-url-blocked-p url blocked-images))
502 (when (gnus-html-cache-expired url gnus-html-image-cache-ttl) 516 (when (gnus-html-cache-expired url gnus-html-image-cache-ttl)
503 (gnus-html-schedule-image-fetching nil 517 (gnus-html-schedule-image-fetching nil
504 (list url)))))))))) 518 (list url))))))))))