aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2010-10-05 22:43:06 +0000
committerKatsumi Yamaoka2010-10-05 22:43:06 +0000
commit130e977f46b869b229e7b95dd3bda8506a8323a4 (patch)
treef24381eed4f1a29acd360e6c4a772ecd41a4fcfd
parentbd8fadca2740ff8da308845199799641f25c3934 (diff)
downloademacs-130e977f46b869b229e7b95dd3bda8506a8323a4.tar.gz
emacs-130e977f46b869b229e7b95dd3bda8506a8323a4.zip
Merge changes made in Gnus trunk.
mm-decode.el (mm-shr): Bind shr-blocked-images to gnus-blocked-images. shr.el (shr-tag-table): Put all the images after the table. shr.el (shr-tag-table): Really inhibit images inside the table. shr.el (shr-collect-overlays): Copy over overlays from the TD elements to the main document. nnimap.el (nnimap-request-newgroups): Return success. gnus-group.el (gnus-group-make-group): Doc fix. nnir.el (nnir-retrieve-headers): Don't bug out on invalid data. gnus-sum.el (gnus-article-sort-by-most-recent-date): New function, added for symmetry. mm-decode.el (mm-shr): Allow displaying cid: images from shr.el. shr.el (shr-insert-table): Bind free variable. gnus-art.el (gnus-blocked-images): Move variable here. mm-decode.el (mm-shr): Require shr. shr.el (shr-tag-img): Shorten ALT texts and allow them to be line-broken. shr.el (shr-tag-img): Ignore image fetching errors. shr.el (shr-overlays-in-region): Compute overlay positions correctly. gnus-html.el (gnus-html-schedule-image-fetching): Protect against invalid URLs.
-rw-r--r--lisp/gnus/ChangeLog41
-rw-r--r--lisp/gnus/gnus-art.el6
-rw-r--r--lisp/gnus/gnus-group.el5
-rw-r--r--lisp/gnus/gnus-html.el9
-rw-r--r--lisp/gnus/gnus-sum.el8
-rw-r--r--lisp/gnus/mm-decode.el9
-rw-r--r--lisp/gnus/nnimap.el3
-rw-r--r--lisp/gnus/nnir.el38
-rw-r--r--lisp/gnus/shr.el95
9 files changed, 168 insertions, 46 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index 241c8148dc1..1217f548a6a 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,3 +1,41 @@
12010-10-05 Lars Magne Ingebrigtsen <larsi@gnus.org>
2
3 * gnus-html.el (gnus-html-schedule-image-fetching): Protect against
4 invalid URLs.
5
6 * shr.el (shr-tag-img): Shorten ALT texts and allow them to be
7 line-broken.
8 (shr-tag-img): Ignore image fetching errors.
9 (shr-overlays-in-region): Compute overlay positions correctly.
10
11 * mm-decode.el (mm-shr): Require shr.
12
13 * gnus-art.el (gnus-blocked-images): Move variable here.
14
15 * shr.el (shr-insert-table): Bind free variable.
16
17 * mm-decode.el (mm-shr): Bind shr-content-function.
18
19 * shr.el (shr-content-function): New variable.
20
21 * gnus-sum.el (gnus-article-sort-by-most-recent-date): New function,
22 added for symmetry.
23
24 * nnir.el (nnir-retrieve-headers): Don't bug out on invalid data.
25
26 * gnus-group.el (gnus-group-make-group): Doc fix.
27
28 * nnimap.el (nnimap-request-newgroups): Return success.
29
30 * shr.el (shr-find-elements): New function.
31 (shr-tag-table): Put all the images after the table.
32 (shr-tag-table): Really inhibit images inside the table.
33 (shr-collect-overlays): Copy over overlays from the TD elements to the
34 main document.
35
36 * mm-decode.el (mm-shr): Bind shr-blocked-images to
37 gnus-blocked-images.
38
12010-10-05 Julien Danjou <julien@danjou.info> 392010-10-05 Julien Danjou <julien@danjou.info>
2 40
3 * gnus-html.el (gnus-html-wash-images): Rescale image from cid too. 41 * gnus-html.el (gnus-html-wash-images): Rescale image from cid too.
@@ -41,6 +79,9 @@
41 79
422010-10-04 Lars Magne Ingebrigtsen <larsi@gnus.org> 802010-10-04 Lars Magne Ingebrigtsen <larsi@gnus.org>
43 81
82 * nnimap.el (nnimap-open-connection): Give an error if nnimap-stream is
83 unknown.
84
44 * shr.el (shr-tag-blockquote): Ensure paragraph after quote, too. 85 * shr.el (shr-tag-blockquote): Ensure paragraph after quote, too.
45 (shr-get-image-data): Ensure against the cache file missing. 86 (shr-get-image-data): Ensure against the cache file missing.
46 87
diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index d96df61a1f8..d7dcf901713 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -1639,6 +1639,12 @@ This requires GNU Libidn, and by default only enabled if it is found."
1639 :group 'gnus-article 1639 :group 'gnus-article
1640 :type 'boolean) 1640 :type 'boolean)
1641 1641
1642(defcustom gnus-blocked-images "."
1643 "Images that have URLs matching this regexp will be blocked."
1644 :version "24.1"
1645 :group 'gnus-art
1646 :type 'regexp)
1647
1642;;; Internal variables 1648;;; Internal variables
1643 1649
1644(defvar gnus-english-month-names 1650(defvar gnus-english-month-names
diff --git a/lisp/gnus/gnus-group.el b/lisp/gnus/gnus-group.el
index d9e36ae6eae..a700b5ee8cf 100644
--- a/lisp/gnus/gnus-group.el
+++ b/lisp/gnus/gnus-group.el
@@ -2651,7 +2651,10 @@ The user will be prompted for GROUP."
2651 "Add a new newsgroup. 2651 "Add a new newsgroup.
2652The user will be prompted for a NAME, for a select METHOD, and an 2652The user will be prompted for a NAME, for a select METHOD, and an
2653ADDRESS. NAME should be a human-readable string (i.e., not be encoded 2653ADDRESS. NAME should be a human-readable string (i.e., not be encoded
2654even if it contains non-ASCII characters) unless ENCODED is non-nil." 2654even if it contains non-ASCII characters) unless ENCODED is non-nil.
2655
2656If the backend supports it, the group will also be created on the
2657server."
2655 (interactive 2658 (interactive
2656 (list 2659 (list
2657 (gnus-read-group "Group name: ") 2660 (gnus-read-group "Group name: ")
diff --git a/lisp/gnus/gnus-html.el b/lisp/gnus/gnus-html.el
index d30b574b55e..a21c4784d80 100644
--- a/lisp/gnus/gnus-html.el
+++ b/lisp/gnus/gnus-html.el
@@ -57,12 +57,6 @@
57 :group 'gnus-art 57 :group 'gnus-art
58 :type 'integer) 58 :type 'integer)
59 59
60(defcustom gnus-blocked-images "."
61 "Images that have URLs matching this regexp will be blocked."
62 :version "24.1"
63 :group 'gnus-art
64 :type 'regexp)
65
66(defcustom gnus-max-image-proportion 0.9 60(defcustom gnus-max-image-proportion 0.9
67 "How big pictures displayed are in relation to the window they're in. 61 "How big pictures displayed are in relation to the window they're in.
68A value of 0.7 means that they are allowed to take up 70% of the 62A value of 0.7 means that they are allowed to take up 70% of the
@@ -371,7 +365,8 @@ Use ALT-TEXT for the image string."
371 (help-function-arglist 'url-retrieve))) 365 (help-function-arglist 'url-retrieve)))
372 4) 366 4)
373 (setq args (nconc args (list t)))) 367 (setq args (nconc args (list t))))
374 (apply #'url-retrieve args))) 368 (ignore-errors
369 (apply #'url-retrieve args))))
375 370
376(defun gnus-html-image-fetched (status buffer image) 371(defun gnus-html-image-fetched (status buffer image)
377 "Callback function called when image has been fetched." 372 "Callback function called when image has been fetched."
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index a0e38d4f4f5..484837f7ff9 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -4985,6 +4985,10 @@ Unscored articles will be counted as having a score of zero."
4985 (t 4985 (t
4986 (gnus-thread-total-score-1 (list thread))))) 4986 (gnus-thread-total-score-1 (list thread)))))
4987 4987
4988(defun gnus-article-sort-by-most-recent-number (h1 h2)
4989 "Sort articles by number."
4990 (gnus-article-sort-by-number h1 h2))
4991
4988(defun gnus-thread-sort-by-most-recent-number (h1 h2) 4992(defun gnus-thread-sort-by-most-recent-number (h1 h2)
4989 "Sort threads such that the thread with the most recently arrived article comes first." 4993 "Sort threads such that the thread with the most recently arrived article comes first."
4990 (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2))) 4994 (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
@@ -4995,6 +4999,10 @@ Unscored articles will be counted as having a score of zero."
4995 (mail-header-number header)) 4999 (mail-header-number header))
4996 (message-flatten-list thread)))) 5000 (message-flatten-list thread))))
4997 5001
5002(defun gnus-article-sort-by-most-recent-date (h1 h2)
5003 "Sort articles by number."
5004 (gnus-article-sort-by-date h1 h2))
5005
4998(defun gnus-thread-sort-by-most-recent-date (h1 h2) 5006(defun gnus-thread-sort-by-most-recent-date (h1 h2)
4999 "Sort threads such that the thread with the most recently dated article comes first." 5007 "Sort threads such that the thread with the most recently dated article comes first."
5000 (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2))) 5008 (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
diff --git a/lisp/gnus/mm-decode.el b/lisp/gnus/mm-decode.el
index edbd252c3c8..70b735a70f9 100644
--- a/lisp/gnus/mm-decode.el
+++ b/lisp/gnus/mm-decode.el
@@ -1684,7 +1684,16 @@ If RECURSIVE, search recursively."
1684(declare-function shr-insert-document "shr" (dom)) 1684(declare-function shr-insert-document "shr" (dom))
1685 1685
1686(defun mm-shr (handle) 1686(defun mm-shr (handle)
1687 ;; Require since we bind its variables.
1688 (require 'shr)
1687 (let ((article-buffer (current-buffer)) 1689 (let ((article-buffer (current-buffer))
1690 (shr-blocked-images (with-current-buffer gnus-summary-buffer
1691 gnus-blocked-images))
1692 (shr-content-function (lambda (id)
1693 (let ((handle (mm-get-content-id id)))
1694 (when handle
1695 (mm-with-part handle
1696 (buffer-string))))))
1688 charset) 1697 charset)
1689 (unless handle 1698 (unless handle
1690 (setq handle (mm-dissect-buffer t))) 1699 (setq handle (mm-dissect-buffer t)))
diff --git a/lisp/gnus/nnimap.el b/lisp/gnus/nnimap.el
index c3c25cbf194..d56e2f4b76e 100644
--- a/lisp/gnus/nnimap.el
+++ b/lisp/gnus/nnimap.el
@@ -926,7 +926,8 @@ textual parts.")
926 (nnimap-get-groups))) 926 (nnimap-get-groups)))
927 (unless (assoc group nnimap-current-infos) 927 (unless (assoc group nnimap-current-infos)
928 ;; Insert dummy numbers here -- they don't matter. 928 ;; Insert dummy numbers here -- they don't matter.
929 (insert (format "%S 0 1 y\n" group)))))) 929 (insert (format "%S 0 1 y\n" group))))
930 t))
930 931
931(deffoo nnimap-retrieve-group-data-early (server infos) 932(deffoo nnimap-retrieve-group-data-early (server infos)
932 (when (nnimap-possibly-change-group nil server) 933 (when (nnimap-possibly-change-group nil server)
diff --git a/lisp/gnus/nnir.el b/lisp/gnus/nnir.el
index baba9e0098a..7a5380c52bb 100644
--- a/lisp/gnus/nnir.el
+++ b/lisp/gnus/nnir.el
@@ -792,40 +792,30 @@ and show thread that contains this article."
792 (if nnir-get-article-nov-override-function 792 (if nnir-get-article-nov-override-function
793 (setq novitem (funcall nnir-get-article-nov-override-function 793 (setq novitem (funcall nnir-get-article-nov-override-function
794 artitem)) 794 artitem))
795 ;; else, set novitem through nnheader-parse-nov/nnheader-parse-head 795 ;; else, set novitem through nnheader-parse-nov/nnheader-parse-head
796 (case (setq foo (gnus-retrieve-headers (list artno) 796 (case (setq foo (gnus-retrieve-headers (list artno)
797 artfullgroup nil)) 797 artfullgroup nil))
798 (nov 798 (nov
799 (goto-char (point-min)) 799 (goto-char (point-min))
800 (setq novitem (nnheader-parse-nov)) 800 (setq novitem (nnheader-parse-nov)))
801 (unless novitem
802 (pop-to-buffer nntp-server-buffer)
803 (error
804 "nnheader-parse-nov returned nil for article %s in group %s"
805 artno artfullgroup)))
806 (headers 801 (headers
807 (goto-char (point-min)) 802 (goto-char (point-min))
808 (setq novitem (nnheader-parse-head)) 803 (setq novitem (nnheader-parse-head)))
809 (unless novitem
810 (pop-to-buffer nntp-server-buffer)
811 (error
812 "nnheader-parse-head returned nil for article %s in group %s"
813 artno artfullgroup)))
814 (t (error "Unknown header type %s while requesting article %s of group %s" 804 (t (error "Unknown header type %s while requesting article %s of group %s"
815 foo artno artfullgroup))))) 805 foo artno artfullgroup)))))
816 ;; replace article number in original group with article number 806 ;; replace article number in original group with article number
817 ;; in nnir group 807 ;; in nnir group
818 (mail-header-set-number novitem art) 808 (when novitem
819 (mail-header-set-from novitem 809 (mail-header-set-number novitem art)
820 (mail-header-from novitem)) 810 (mail-header-set-from novitem
821 (mail-header-set-subject 811 (mail-header-from novitem))
822 novitem 812 (mail-header-set-subject
823 (format "[%d: %s/%d] %s" 813 novitem
824 artrsv artgroup artno 814 (format "[%d: %s/%d] %s"
825 (mail-header-subject novitem))) 815 artrsv artgroup artno
826 ;;-(mail-header-set-extra novitem nil) 816 (mail-header-subject novitem)))
827 (push novitem novdata) 817 (push novitem novdata)
828 (setq artlist (cdr artlist))) 818 (setq artlist (cdr artlist))))
829 (setq novdata (nreverse novdata)) 819 (setq novdata (nreverse novdata))
830 (set-buffer nntp-server-buffer) (erase-buffer) 820 (set-buffer nntp-server-buffer) (erase-buffer)
831 (mapc 'nnheader-insert-nov novdata) 821 (mapc 'nnheader-insert-nov novdata)
diff --git a/lisp/gnus/shr.el b/lisp/gnus/shr.el
index f905bf5ac05..2d5d4d623fb 100644
--- a/lisp/gnus/shr.el
+++ b/lisp/gnus/shr.el
@@ -52,10 +52,16 @@ fit these criteria."
52 :group 'shr 52 :group 'shr
53 :type 'regexp) 53 :type 'regexp)
54 54
55(defvar shr-content-function nil
56 "If bound, this should be a function that will return the content.
57This is used for cid: URLs, and the function is called with the
58cid: URL as the argument.")
59
55(defvar shr-folding-mode nil) 60(defvar shr-folding-mode nil)
56(defvar shr-state nil) 61(defvar shr-state nil)
57(defvar shr-start nil) 62(defvar shr-start nil)
58(defvar shr-indentation 0) 63(defvar shr-indentation 0)
64(defvar shr-inhibit-images nil)
59 65
60(defvar shr-width 70) 66(defvar shr-width 70)
61 67
@@ -204,16 +210,30 @@ redirects somewhere else."
204 (when (zerop (length alt)) 210 (when (zerop (length alt))
205 (setq alt "[img]")) 211 (setq alt "[img]"))
206 (cond 212 (cond
207 ((and shr-blocked-images 213 ((and (not shr-inhibit-images)
208 (string-match shr-blocked-images url)) 214 (string-match "\\`cid:" url))
209 (insert alt)) 215 (let ((url (substring url (match-end 0)))
216 image)
217 (if (or (not shr-content-function)
218 (not (setq image (funcall shr-content-function url))))
219 (insert alt)
220 (shr-put-image image (point) alt))))
221 ((or shr-inhibit-images
222 (and shr-blocked-images
223 (string-match shr-blocked-images url)))
224 (setq shr-start (point))
225 (let ((shr-state 'space))
226 (if (> (length alt) 8)
227 (shr-insert (substring alt 0 8))
228 (shr-insert alt))))
210 ((url-is-cached (browse-url-url-encode-chars url "[&)$ ]")) 229 ((url-is-cached (browse-url-url-encode-chars url "[&)$ ]"))
211 (shr-put-image (shr-get-image-data url) (point) alt)) 230 (shr-put-image (shr-get-image-data url) (point) alt))
212 (t 231 (t
213 (insert alt) 232 (insert alt)
214 (url-retrieve url 'shr-image-fetched 233 (ignore-errors
215 (list (current-buffer) start (point-marker)) 234 (url-retrieve url 'shr-image-fetched
216 t))) 235 (list (current-buffer) start (point-marker))
236 t))))
217 (insert " ") 237 (insert " ")
218 (put-text-property start (point) 'keymap shr-map) 238 (put-text-property start (point) 'keymap shr-map)
219 (put-text-property start (point) 'shr-alt alt) 239 (put-text-property start (point) 'shr-alt alt)
@@ -411,11 +431,23 @@ Return a string with image data."
411 (shr-ensure-paragraph) 431 (shr-ensure-paragraph)
412 (setq cont (or (cdr (assq 'tbody cont)) 432 (setq cont (or (cdr (assq 'tbody cont))
413 cont)) 433 cont))
414 (let* ((columns (shr-column-specs cont)) 434 (let* ((shr-inhibit-images t)
435 (columns (shr-column-specs cont))
415 (suggested-widths (shr-pro-rate-columns columns)) 436 (suggested-widths (shr-pro-rate-columns columns))
416 (sketch (shr-make-table cont suggested-widths)) 437 (sketch (shr-make-table cont suggested-widths))
417 (sketch-widths (shr-table-widths sketch (length suggested-widths)))) 438 (sketch-widths (shr-table-widths sketch (length suggested-widths))))
418 (shr-insert-table (shr-make-table cont sketch-widths t) sketch-widths))) 439 (shr-insert-table (shr-make-table cont sketch-widths t) sketch-widths))
440 (dolist (elem (shr-find-elements cont 'img))
441 (shr-tag-img (cdr elem))))
442
443(defun shr-find-elements (cont type)
444 (let (result)
445 (dolist (elem cont)
446 (cond ((eq (car elem) type)
447 (push elem result))
448 ((consp (cdr elem))
449 (setq result (nconc (shr-find-elements (cdr elem) type) result)))))
450 (nreverse result)))
419 451
420(defun shr-insert-table (table widths) 452(defun shr-insert-table (table widths)
421 (shr-insert-table-ruler widths) 453 (shr-insert-table-ruler widths)
@@ -430,11 +462,20 @@ Return a string with image data."
430 (insert "|\n")) 462 (insert "|\n"))
431 (dolist (column row) 463 (dolist (column row)
432 (goto-char start) 464 (goto-char start)
433 (let ((lines (split-string (nth 2 column) "\n"))) 465 (let ((lines (split-string (nth 2 column) "\n"))
466 (overlay-lines (nth 3 column))
467 overlay overlay-line)
434 (dolist (line lines) 468 (dolist (line lines)
469 (setq overlay-line (pop overlay-lines))
435 (when (> (length line) 0) 470 (when (> (length line) 0)
436 (end-of-line) 471 (end-of-line)
437 (insert line "|") 472 (insert line "|")
473 (dolist (overlay overlay-line)
474 (let ((o (make-overlay (- (point) (nth 0 overlay) 1)
475 (- (point) (nth 1 overlay) 1)))
476 (properties (nth 2 overlay)))
477 (while properties
478 (overlay-put o (pop properties) (pop properties)))))
438 (forward-line 1))) 479 (forward-line 1)))
439 ;; Add blank lines at padding at the bottom of the TD, 480 ;; Add blank lines at padding at the bottom of the TD,
440 ;; possibly. 481 ;; possibly.
@@ -495,7 +536,34 @@ Return a string with image data."
495 (when (> (- width (current-column)) 0) 536 (when (> (- width (current-column)) 0)
496 (insert (make-string (- width (current-column)) ? ))) 537 (insert (make-string (- width (current-column)) ? )))
497 (forward-line 1))) 538 (forward-line 1)))
498 (list max (count-lines (point-min) (point-max)) (buffer-string))))) 539 (list max
540 (count-lines (point-min) (point-max))
541 (buffer-string)
542 (and fill
543 (shr-collect-overlays))))))
544
545(defun shr-collect-overlays ()
546 (save-excursion
547 (goto-char (point-min))
548 (let ((overlays nil))
549 (while (not (eobp))
550 (push (shr-overlays-in-region (point) (line-end-position))
551 overlays)
552 (forward-line 1))
553 (nreverse overlays))))
554
555(defun shr-overlays-in-region (start end)
556 (let (result)
557 (dolist (overlay (overlays-in start end))
558 (push (list (if (> start (overlay-start overlay))
559 (- end start)
560 (- end (overlay-start overlay)))
561 (if (< end (overlay-end overlay))
562 0
563 (- end (overlay-end overlay)))
564 (overlay-properties overlay))
565 result))
566 (nreverse result)))
499 567
500(defun shr-pro-rate-columns (columns) 568(defun shr-pro-rate-columns (columns)
501 (let ((total-percentage 0) 569 (let ((total-percentage 0)
@@ -523,8 +591,8 @@ Return a string with image data."
523 (string-match "\\([0-9]+\\)%" width)) 591 (string-match "\\([0-9]+\\)%" width))
524 (aset columns i 592 (aset columns i
525 (/ (string-to-number (match-string 1 width)) 593 (/ (string-to-number (match-string 1 width))
526 100.0))))) 594 100.0))))
527 (setq i (1+ i)))))) 595 (setq i (1+ i)))))))
528 columns)) 596 columns))
529 597
530(defun shr-count (cont elem) 598(defun shr-count (cont elem)
@@ -538,7 +606,8 @@ Return a string with image data."
538 (let ((max 0)) 606 (let ((max 0))
539 (dolist (row cont) 607 (dolist (row cont)
540 (when (eq (car row) 'tr) 608 (when (eq (car row) 'tr)
541 (setq max (max max (shr-count (cdr row) 'td))))) 609 (setq max (max max (+ (shr-count (cdr row) 'td)
610 (shr-count (cdr row) 'th))))))
542 max)) 611 max))
543 612
544(provide 'shr) 613(provide 'shr)