Gnus -- minor build / warning fixes [OK For Upstream]
[gnus] / lisp / gnus-html.el
index acc018f..f23acf1 100644 (file)
@@ -1,6 +1,6 @@
 ;;; gnus-html.el --- Render HTML in a buffer.
 
-;; Copyright (C) 2010, 2011  Free Software Foundation, Inc.
+;; Copyright (C) 2010-2016 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)
@@ -169,8 +174,7 @@ CHARS is a regexp-like character alternative (e.g., \"[)$]\")."
 
 (defun gnus-html-wash-images ()
   "Run through current buffer and replace img tags by images."
-  (let (tag parameters string start end images url alt-text
-           inhibit-images blocked-images)
+  (let (parameters start end url alt-text inhibit-images blocked-images)
     (if (buffer-live-p gnus-summary-buffer)
        (with-current-buffer gnus-summary-buffer
          (setq inhibit-images gnus-inhibit-images
@@ -215,16 +219,16 @@ CHARS is a regexp-like character alternative (e.g., \"[)$]\")."
                             (mm-with-part handle (buffer-string))
                             nil t))))
              (if image
-                 (progn
-                   (gnus-put-image
-                    (gnus-rescale-image
-                     image (gnus-html-maximum-image-size))
-                    (gnus-string-or (prog1
-                                        (buffer-substring start end)
-                                      (delete-region start end))
-                                    "*")
-                    'cid)
-                   (gnus-add-image 'cid image))
+                 (gnus-add-image
+                  'cid
+                  (gnus-put-image
+                   (gnus-rescale-image
+                    image (gnus-html-maximum-image-size))
+                   (gnus-string-or (prog1
+                                       (buffer-substring start end)
+                                     (delete-region start end))
+                                   "*")
+                   'cid))
                (widget-convert-button
                 'link start end
                 :action 'gnus-html-insert-image
@@ -274,7 +278,7 @@ Use ALT-TEXT for the image string."
       (gnus-html-put-image (gnus-html-get-image-data url) url alt-text))))
 
 (defun gnus-html-wash-tags ()
-  (let (tag parameters string start end images url)
+  (let (tag parameters start end url)
     (gnus-html-pre-wash)
     (gnus-html-wash-images)
 
@@ -302,12 +306,12 @@ Use ALT-TEXT for the image string."
          (gnus-article-add-button start end
                                   'browse-url (mm-url-decode-entities-string url)
                                   url)
-         (let ((overlay (gnus-make-overlay start end)))
-           (gnus-overlay-put overlay 'evaporate t)
-           (gnus-overlay-put overlay 'gnus-button-url url)
+         (let ((overlay (make-overlay start end)))
+           (overlay-put overlay 'evaporate t)
+           (overlay-put overlay 'gnus-button-url url)
            (gnus-put-text-property start end 'gnus-string url)
            (when gnus-article-mouse-face
-             (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))))
+             (overlay-put overlay 'mouse-face gnus-article-mouse-face)))))
        ;; The upper-case IMG_ALT is apparently just an artifact that
        ;; should be deleted.
        ((equal tag "IMG_ALT")
@@ -315,19 +319,19 @@ Use ALT-TEXT for the image string."
        ;; w3m does not normalize the case
        ((or (equal tag "b")
             (equal tag "B"))
-        (gnus-overlay-put (gnus-make-overlay start end) 'face 'gnus-emphasis-bold))
+        (overlay-put (make-overlay start end) 'face 'gnus-emphasis-bold))
        ((or (equal tag "u")
             (equal tag "U"))
-        (gnus-overlay-put (gnus-make-overlay start end) 'face 'gnus-emphasis-underline))
+        (overlay-put (make-overlay start end) 'face 'gnus-emphasis-underline))
        ((or (equal tag "i")
             (equal tag "I"))
-        (gnus-overlay-put (gnus-make-overlay start end) 'face 'gnus-emphasis-italic))
+        (overlay-put (make-overlay start end) 'face 'gnus-emphasis-italic))
        ((or (equal tag "s")
             (equal tag "S"))
-        (gnus-overlay-put (gnus-make-overlay start end) 'face 'gnus-emphasis-strikethru))
+        (overlay-put (make-overlay start end) 'face 'gnus-emphasis-strikethru))
        ((or (equal tag "ins")
             (equal tag "INS"))
-        (gnus-overlay-put (gnus-make-overlay start end) 'face 'gnus-emphasis-underline))
+        (overlay-put (make-overlay start end) 'face 'gnus-emphasis-underline))
        ;; Handle different UL types
        ((equal tag "_SYMBOL")
         (when (string-match "TYPE=\\(.+\\)" parameters)
@@ -386,29 +390,28 @@ Use ALT-TEXT for the image string."
   "Retrieve IMAGE, and place it into BUFFER on arrival."
   (gnus-message 8 "gnus-html-schedule-image-fetching: buffer %s, image %s"
                 buffer image)
-  (let ((args (list (car image)
-                   'gnus-html-image-fetched
-                   (list buffer image))))
-    (when (> (length (if (featurep 'xemacs)
-                        (cdr (split-string (function-arglist 'url-retrieve)))
-                      (help-function-arglist 'url-retrieve)))
-            4)
-      (setq args (nconc args (list t))))
+  (if (fboundp 'url-queue-retrieve)
+      (url-queue-retrieve (car image)
+                         'gnus-html-image-fetched
+                         (list buffer image) t t)
     (ignore-errors
-      (push (apply #'url-retrieve args) gnus-buffers))))
+      (url-retrieve (car image)
+                   'gnus-html-image-fetched
+                   (list buffer image)))))
 
 (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)
@@ -435,6 +438,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)
@@ -484,8 +490,14 @@ Return a string with image data."
                     (gnus-put-text-property start (point)
                                            'gnus-alt-text alt-text)
                     (when url
-                      (gnus-put-text-property start (point)
-                                             'image-url url))
+                     (gnus-add-text-properties
+                      start (point)
+                      `(image-url
+                        ,url
+                        image-displayer
+                        (lambda (url start end)
+                          (gnus-html-display-image url start end
+                                                   ,alt-text)))))
                     (gnus-add-image 'external image)
                     t)
                 ;; Bad image, try to show something else