From af13765c1154f9eaa9b25e69e2565227f896ae48 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Tue, 5 Oct 2010 20:22:19 +0200 Subject: [PATCH] Allow displaying cid: images from shr.el. --- lisp/ChangeLog | 4 ++++ lisp/mm-decode.el | 5 +++++ lisp/shr.el | 20 +++++++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0532694aa..86a155494 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,9 @@ 2010-10-05 Lars Magne Ingebrigtsen + * mm-decode.el (mm-shr): Bind shr-content-function. + + * shr.el (shr-content-function): New variable. + * gnus-sum.el (gnus-article-sort-by-most-recent-date): New function, added for symmetry. diff --git a/lisp/mm-decode.el b/lisp/mm-decode.el index 3db539e2f..28339d769 100644 --- a/lisp/mm-decode.el +++ b/lisp/mm-decode.el @@ -1687,6 +1687,11 @@ If RECURSIVE, search recursively." (let ((article-buffer (current-buffer)) (shr-blocked-images (with-current-buffer gnus-summary-buffer gnus-blocked-images)) + (shr-content-function (lambda (id) + (let ((handle (mm-get-content-id id))) + (when handle + (mm-with-part handle + (buffer-string)))))) charset) (unless handle (setq handle (mm-dissect-buffer t))) diff --git a/lisp/shr.el b/lisp/shr.el index 18dd72dfe..fe228135c 100644 --- a/lisp/shr.el +++ b/lisp/shr.el @@ -52,6 +52,11 @@ fit these criteria." :group 'shr :type 'regexp) +(defvar shr-content-function nil + "If bound, this should be a function that will return the content. +This is used for cid: URLs, and the function is called with the +cid: URL as the argument.") + (defvar shr-folding-mode nil) (defvar shr-state nil) (defvar shr-start nil) @@ -205,6 +210,14 @@ redirects somewhere else." (when (zerop (length alt)) (setq alt "[img]")) (cond + ((and (not shr-inhibit-images) + (string-match "\\`cid:" url)) + (let ((url (substring url (match-end 0))) + image) + (if (or (not shr-content-function) + (not (setq image (funcall shr-content-function url)))) + (insert alt) + (shr-put-image image (point) alt)))) ((or shr-inhibit-images (and shr-blocked-images (string-match shr-blocked-images url))) @@ -570,8 +583,8 @@ Return a string with image data." (string-match "\\([0-9]+\\)%" width)) (aset columns i (/ (string-to-number (match-string 1 width)) - 100.0))))) - (setq i (1+ i)))))) + 100.0)))) + (setq i (1+ i))))))) columns)) (defun shr-count (cont elem) @@ -585,7 +598,8 @@ Return a string with image data." (let ((max 0)) (dolist (row cont) (when (eq (car row) 'tr) - (setq max (max max (shr-count (cdr row) 'td))))) + (setq max (max max (+ (shr-count (cdr row) 'td) + (shr-count (cdr row) 'th)))))) max)) (provide 'shr) -- 2.25.1