Prefetch and html washing additions.
[gnus] / lisp / gnus-html.el
index 8bfbaaa..f921b7b 100644 (file)
 
 (eval-when-compile (require 'cl))
 (eval-when-compile (require 'mm-decode))
+
+(require 'gnus-art)
 (require 'mm-url)
+(require 'url)
 
 (defcustom gnus-html-cache-directory (nnheader-concat gnus-directory "html-cache/")
   "Where Gnus will cache images it downloads from the web."
@@ -111,6 +114,7 @@ fit these criteria."
                                 "-I" "UTF-8"
                                 "-O" "UTF-8"
                                 "-o" "ext_halfdump=1"
+                                 "-o" "display_ins_del=2"
                                 "-o" "pre_conv=1"
                                 "-t" (format "%s" tab-width)
                                 "-cols" (format "%s" gnus-html-frame-width)
@@ -250,6 +254,38 @@ fit these criteria."
        ;; should be deleted.
        ((equal tag "IMG_ALT")
        (delete-region start end))
+       ;; 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))
+       ((or (equal tag "u")
+            (equal tag "U"))
+        (gnus-overlay-put (gnus-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))
+       ((or (equal tag "s")
+            (equal tag "S"))
+        (gnus-overlay-put (gnus-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))
+       ;; Handle different UL types
+       ((equal tag "_SYMBOL")
+        (when (string-match "TYPE=\\(.+\\)" parameters)
+          (let ((type (string-to-number (match-string 1 parameters))))
+            (delete-region start end)
+            (cond ((= type 33) (insert " "))
+                  ((= type 34) (insert " "))
+                  ((= type 35) (insert " "))
+                  ((= type 36) (insert " "))
+                  ((= type 37) (insert " "))
+                  ((= type 38) (insert " "))
+                  ((= type 39) (insert " "))
+                  ((= type 40) (insert " "))
+                  ((= type 42) (insert " "))
+                  ((= type 43) (insert " "))
+                  (t (insert " "))))))
        ;; Whatever.  Just ignore the tag.
        (t
        ))
@@ -288,41 +324,35 @@ fit these criteria."
 (defun gnus-html-schedule-image-fetching (buffer images)
   (gnus-message 8 "gnus-html-schedule-image-fetching: buffer %s, images %s"
                 buffer images)
-  (let* ((url (caar images))
-        (process (start-process
-                  "images" nil "curl"
-                  "-s" "--create-dirs"
-                  "--location"
-                  "--max-time" "60"
-                  "-o" (gnus-html-image-id url)
-                  (mm-url-decode-entities-string url))))
-    (process-kill-without-query process)
-    (set-process-sentinel process 'gnus-html-curl-sentinel)
-    (gnus-set-process-plist process (list 'images images
-                                         'buffer buffer))))
+  (dolist (image images)
+    (ignore-errors
+      (url-retrieve (car image)
+                   'gnus-html-image-fetched
+                   (list buffer image)))))
 
 (defun gnus-html-image-id (url)
   (expand-file-name (sha1 url) gnus-html-cache-directory))
 
-(defun gnus-html-curl-sentinel (process event)
-  (when (string-match "finished" event)
-    (let* ((images (gnus-process-get process 'images))
-          (buffer (gnus-process-get process 'buffer))
-          (spec (pop images))
-          (file (gnus-html-image-id (car spec))))
-      (when (and (buffer-live-p buffer)
-                ;; If the position of the marker is 1, then that
-                ;; means that the text it was in has been deleted;
-                ;; i.e., that the user has selected a different
-                ;; article before the image arrived.
-                (not (= (marker-position (cadr spec)) (point-min))))
-       (with-current-buffer buffer
-         (let ((inhibit-read-only t)
-               (string (buffer-substring (cadr spec) (caddr spec))))
-           (delete-region (cadr spec) (caddr spec))
-           (gnus-html-put-image file (cadr spec) string))))
-      (when images
-       (gnus-html-schedule-image-fetching buffer images)))))
+(defun gnus-html-image-fetched (status buffer image)
+  (let ((file (gnus-html-image-id (car image))))
+    ;; Search the start of the image data
+    (search-forward "\n\n")
+    ;; Write region (image data) silently
+    (write-region (point) (point-max) file nil 1)
+    (kill-buffer)
+    (when (and (buffer-live-p buffer)
+               ;; If the `image' has no marker, do not replace anything
+               (cadr image)
+               ;; If the position of the marker is 1, then that
+               ;; means that the text it was in has been deleted;
+               ;; i.e., that the user has selected a different
+               ;; article before the image arrived.
+               (not (= (marker-position (cadr image)) (point-min))))
+      (with-current-buffer buffer
+        (let ((inhibit-read-only t)
+              (string (buffer-substring (cadr image) (caddr image))))
+          (delete-region (cadr image) (caddr image))
+          (gnus-html-put-image file (cadr image) (car image) string))))))
 
 (defun gnus-html-put-image (file point string &optional url alt-text)
   (when (gnus-graphic-display-p)
@@ -440,26 +470,17 @@ This only works if the article in question is HTML."
 
 ;;;###autoload
 (defun gnus-html-prefetch-images (summary)
-  (let (blocked-images urls)
-    (when (buffer-live-p summary)
-      (with-current-buffer summary
-       (setq blocked-images gnus-blocked-images))
+  (when (buffer-live-p summary)
+    (let ((blocked-images (with-current-buffer summary
+                            gnus-blocked-images)))
       (save-match-data
        (while (re-search-forward "<img.*src=[\"']\\([^\"']+\\)" nil t)
          (let ((url (match-string 1)))
            (unless (gnus-html-image-url-blocked-p url blocked-images)
               (unless (file-exists-p (gnus-html-image-id url))
-                (push (mm-url-decode-entities-string url) urls)
-                (push (gnus-html-image-id url) urls)
-                (push "-o" urls)))))
-       (let ((process
-              (apply 'start-process
-                     "images" nil "curl"
-                     "-s" "--create-dirs"
-                     "--location"
-                     "--max-time" "60"
-                     urls)))
-         (process-kill-without-query process))))))
+                (ignore-errors
+                  (url-retrieve (mm-url-decode-entities-string url)
+                                'gnus-html-image-fetched))))))))))
 
 (provide 'gnus-html)