Gnus development mailing list
 help / color / mirror / Atom feed
From: Julien Danjou <julien@danjou.info>
To: ding@gnus.org
Cc: Julien Danjou <julien@danjou.info>
Subject: [PATCH] Use `url' rather than curl
Date: Sat, 18 Sep 2010 20:22:42 +0200	[thread overview]
Message-ID: <1284834162-24257-1-git-send-email-julien@danjou.info> (raw)
In-Reply-To: <87eicrmaly.fsf@keller.adm.naquadah.org>

Signed-off-by: Julien Danjou <julien@danjou.info>
---
 lisp/ChangeLog    |    5 ++++
 lisp/gnus-html.el |   55 +++++++++++++++++++++++-----------------------------
 2 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index cf95e15..832458f 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2010-09-18  Julien Danjou  <julien@danjou.info>
+
+	* gnus-html.el (gnus-html-schedule-image-fetching): Use `url' rather
+	than curl to retrieve images.
+
 2010-09-18  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
 	* nnimap.el (nnimap-update-info): Extend the info so that we can set
diff --git a/lisp/gnus-html.el b/lisp/gnus-html.el
index e74fd5b..40b74c2 100644
--- a/lisp/gnus-html.el
+++ b/lisp/gnus-html.el
@@ -33,6 +33,7 @@
 
 (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."
@@ -296,42 +297,34 @@ 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)
-  (when (executable-find "curl")
-    (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))))
-      (gnus-set-process-query-on-exit-flag process nil)
-      (set-process-sentinel process 'gnus-html-curl-sentinel)
-      (gnus-set-process-plist process (list 'images images
-					    'buffer buffer)))))
+  (url-retrieve (caar images)
+                'gnus-html-image-fetched
+                (list buffer images)))
 
 (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))))
+(defun gnus-html-image-fetched (status buffer images)
+  (let ((spec (pop images)))
+    (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))))
+      (let ((file (gnus-html-image-id (car spec))))
+        ;; Search the start of the image data
+        (search-forward "\n\n")
+        ;; Write region (image) silently
+        (write-region (point) (point-max) file nil 1)
+        (kill-buffer)
+        (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)))))
+        (gnus-html-schedule-image-fetching buffer images)))))
 
 (defun gnus-html-put-image (file point string &optional url alt-text)
   (when (gnus-graphic-display-p)
-- 
1.7.1




  parent reply	other threads:[~2010-09-18 18:22 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-18  9:55 gnus-html, url and curl Julien Danjou
2010-09-18 11:50 ` Lars Magne Ingebrigtsen
2010-09-18 13:42   ` Julien Danjou
2010-09-18 14:14     ` Lars Magne Ingebrigtsen
2010-09-18 16:25       ` Steinar Bang
2010-09-18 16:34         ` Lars Magne Ingebrigtsen
2010-09-18 18:22     ` Julien Danjou [this message]
2010-09-18 18:30       ` [PATCH] Use `url' rather than curl Leo
2010-09-18 18:34         ` Julien Danjou
2010-09-18 19:07           ` Leo
2010-09-18 19:12             ` Lars Magne Ingebrigtsen
2010-09-18 19:25               ` Leo
2010-09-18 19:28                 ` Lars Magne Ingebrigtsen
2010-09-18 20:02                   ` Leo
2010-09-18 18:39       ` Lars Magne Ingebrigtsen
2010-09-18 19:08         ` Adam Sjøgren
2010-09-18 20:14       ` [PATCH] " Leo
2010-09-18 20:21         ` Lars Magne Ingebrigtsen
2010-09-18 20:24           ` Leo
2010-09-18 20:44       ` Adam Sjøgren
2010-09-22  1:03 ` gnus-html, url and curl Katsumi Yamaoka
2010-09-22 16:21   ` Lars Magne Ingebrigtsen
2010-09-23  1:29     ` Katsumi Yamaoka
2010-09-23  8:13       ` Robert Pluim
2010-09-23 15:57         ` Lars Magne Ingebrigtsen
2010-09-23 17:42           ` Adam Sjøgren
2010-09-23 17:47             ` Lars Magne Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1284834162-24257-1-git-send-email-julien@danjou.info \
    --to=julien@danjou.info \
    --cc=ding@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).