lisp/ChangeLog: Fix date
[gnus] / lisp / gnus-html.el
index a4c4fa5..b706de7 100644 (file)
@@ -1,6 +1,6 @@
 ;;; gnus-html.el --- Render HTML in a buffer.
 
-;; Copyright (C) 2010-201 Free Software Foundation, Inc.
+;; Copyright (C) 2010-2015 Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;; Keywords: html, web
 (require 'url-cache)
 (require 'xml)
 (require 'browse-url)
+(require 'mm-util)
 (eval-and-compile (unless (featurep 'xemacs) (require 'help-fns)))
 
 (defcustom gnus-html-image-cache-ttl (days-to-time 7)
   "Time used to determine if we should use images from the cache."
   :version "24.1"
   :group 'gnus-art
-  :type 'integer)
+  ;; FIXME hardly the friendliest type.  The allowed value is actually
+  ;; any time value, but we are assuming no-one cares about USEC and
+  ;; PSEC here.  It would be better to eg make it a number of minutes.
+  :type '(list integer integer))
 
 (defcustom gnus-html-image-automatic-caching t
   "Whether automatically cache retrieve images."
@@ -135,7 +139,8 @@ CHARS is a regexp-like character alternative (e.g., \"[)$]\")."
                 (charset (mail-content-type-get (mm-handle-type handle)
                                                 'charset)))
            (when (and charset
-                      (setq charset (mm-charset-to-coding-system charset))
+                      (setq charset (mm-charset-to-coding-system
+                                     charset nil t))
                       (not (eq charset 'ascii)))
              (insert (prog1
                          (mm-decode-coding-string (buffer-string) charset)
@@ -389,7 +394,7 @@ Use ALT-TEXT for the image string."
   (if (fboundp 'url-queue-retrieve)
       (url-queue-retrieve (car image)
                          'gnus-html-image-fetched
-                         (list buffer image) t)
+                         (list buffer image) t t)
     (ignore-errors
       (url-retrieve (car image)
                    'gnus-html-image-fetched
@@ -398,15 +403,16 @@ Use ALT-TEXT for the image string."
 (defun gnus-html-image-fetched (status buffer image)
   "Callback function called when image has been fetched."
   (unless (plist-get status :error)
-    (when gnus-html-image-automatic-caching
-      (url-store-in-cache (current-buffer)))
     (when (and (or (search-forward "\n\n" nil t)
                    (search-forward "\r\n\r\n" nil t))
-               (buffer-live-p buffer))
-      (let ((data (buffer-substring (point) (point-max))))
-        (with-current-buffer buffer
-          (let ((inhibit-read-only t))
-            (gnus-html-put-image data (car image) (cadr image)))))))
+              (not (eobp)))
+      (when gnus-html-image-automatic-caching
+       (url-store-in-cache (current-buffer)))
+      (when (buffer-live-p buffer)
+       (let ((data (buffer-substring (point) (point-max))))
+         (with-current-buffer buffer
+           (let ((inhibit-read-only t))
+             (gnus-html-put-image data (car image) (cadr image))))))))
   (kill-buffer (current-buffer)))
 
 (defun gnus-html-get-image-data (url)
@@ -433,6 +439,9 @@ Return a string with image data."
      (truncate (* gnus-max-image-proportion
                   (- (nth 3 edges) (nth 1 edges)))))))
 
+;; Behind display-graphic-p test.
+(declare-function image-size "image.c" (spec &optional pixels frame))
+
 (defun gnus-html-put-image (data url &optional alt-text)
   "Put an image with DATA from URL and optional ALT-TEXT."
   (when (gnus-graphic-display-p)
@@ -488,7 +497,7 @@ Return a string with image data."
                         ,url
                         image-displayer
                         (lambda (url start end)
-                          (gnus-html-display-image ,url ,start ,(point)
+                          (gnus-html-display-image url start end
                                                    ,alt-text)))))
                     (gnus-add-image 'external image)
                     t)