aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Jasper2014-10-20 21:47:51 +0200
committerUlf Jasper2014-10-20 21:47:51 +0200
commit9d9bcb5020987f07dd2b9ab994f8826c07182829 (patch)
tree51f48d0c169eee0b25146e51052ed442288468c0
parent56dfc811b4b93afca1a387cb08349057bb496d91 (diff)
downloademacs-9d9bcb5020987f07dd2b9ab994f8826c07182829.tar.gz
emacs-9d9bcb5020987f07dd2b9ab994f8826c07182829.zip
Newsticker: fix broken image download via url-retrieve, again.
* lisp/net/newst-backend.el (newsticker--image-download-by-url-callback): Make this function actually work: Check status properly, then save image.
-rw-r--r--lisp/ChangeLog2
-rw-r--r--lisp/net/newst-backend.el48
2 files changed, 25 insertions, 25 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 187953b41d3..2336366cd45 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -2,7 +2,7 @@
2 2
3 * net/newst-backend.el 3 * net/newst-backend.el
4 (newsticker--image-download-by-url-callback): Make this function 4 (newsticker--image-download-by-url-callback): Make this function
5 actually work: First save image then check status. 5 actually work: Check status properly, then save image.
6 6
72014-10-20 Stefan Monnier <monnier@iro.umontreal.ca> 72014-10-20 Stefan Monnier <monnier@iro.umontreal.ca>
8 8
diff --git a/lisp/net/newst-backend.el b/lisp/net/newst-backend.el
index a8b0d1b7d62..00d595c977f 100644
--- a/lisp/net/newst-backend.el
+++ b/lisp/net/newst-backend.el
@@ -1806,7 +1806,7 @@ download it from URL first."
1806 (if (and (file-exists-p image-name) 1806 (if (and (file-exists-p image-name)
1807 (time-less-p (current-time) 1807 (time-less-p (current-time)
1808 (time-add (nth 5 (file-attributes image-name)) 1808 (time-add (nth 5 (file-attributes image-name))
1809 (seconds-to-time 86400)))) 1809 (seconds-to-time 86400))))
1810 (newsticker--debug-msg "%s: Getting image for %s skipped" 1810 (newsticker--debug-msg "%s: Getting image for %s skipped"
1811 (format-time-string "%A, %H:%M" (current-time)) 1811 (format-time-string "%A, %H:%M" (current-time))
1812 feed-name) 1812 feed-name)
@@ -1905,29 +1905,29 @@ STATUS is the return status as delivered by `url-retrieve'.
1905FEED-NAME is the name of the feed that the news were retrieved 1905FEED-NAME is the name of the feed that the news were retrieved
1906from. 1906from.
1907The image is saved in DIRECTORY as FILENAME." 1907The image is saved in DIRECTORY as FILENAME."
1908 (let ((buf (get-buffer-create (concat " *newsticker-url-image-" feed-name "-" 1908 (let ((do-save
1909 directory "*"))) 1909 (or (not status)
1910 (result (string-to-multibyte (buffer-string)))) 1910 (let ((status-type (car status))
1911 (set-buffer buf) 1911 (status-details (cdr status)))
1912 (erase-buffer) 1912 (cond ((eq status-type :redirect)
1913 (insert result) 1913 ;; don't care about redirects
1914 ;; remove MIME header 1914 t)
1915 (goto-char (point-min)) 1915 ((eq status-type :error)
1916 (search-forward "\n\n") 1916 ;; silently ignore errors
1917 (delete-region (point-min) (point)) 1917 nil))))))
1918 ;; save 1918 (when do-save
1919 (newsticker--image-save buf directory filename)) 1919 (let ((buf (get-buffer-create (concat " *newsticker-url-image-" feed-name "-"
1920 (when status 1920 directory "*")))
1921 (let ((status-type (car status)) 1921 (result (string-to-multibyte (buffer-string))))
1922 (status-details (cdr status))) 1922 (set-buffer buf)
1923 (cond ((eq status-type :redirect) 1923 (erase-buffer)
1924 ;; don't care about redirects 1924 (insert result)
1925 ) 1925 ;; remove MIME header
1926 ((eq status-type :error) 1926 (goto-char (point-min))
1927 (message "%s: Error while retrieving image from %s: %s: \"%s\"" 1927 (search-forward "\n\n")
1928 (format-time-string "%A, %H:%M" (current-time)) 1928 (delete-region (point-min) (point))
1929 feed-name 1929 ;; save
1930 (car status-details) (cdr status-details))))))) 1930 (newsticker--image-save buf directory filename)))))
1931 1931
1932(defun newsticker--insert-image (img string) 1932(defun newsticker--insert-image (img string)
1933 "Insert IMG with STRING at point." 1933 "Insert IMG with STRING at point."