Changes committed gnus/lisp (ChangeLog spam-report.el)

"Reiner Steib" <[email protected]> Mon, 22 Dec 2008 23:06:59 +0100
Newsgroups gmane.emacs.gnus.commits
Message-ID <[email protected]>
Modified: ChangeLog spam-report.el

(spam-report-gmane-max-requests): New constant.
(spam-report-gmane-wait): New variable.
(spam-report-gmane-ham, spam-report-gmane-spam)
(spam-report-url-ping-plain, spam-report-process-queue): Wait only if
spam-report-gmane-wait is non-nil should be sufficient to avoid DOS-ing
the server.


Index: ChangeLog
diff -u gnus/lisp/ChangeLog:7.1952 gnus/lisp/ChangeLog:7.1953
--- ChangeLog:7.1952	Mon Dec 22 22:34:55 2008
+++ ChangeLog	Mon Dec 22 23:06:59 2008
@@ -1,5 +1,12 @@
 2008-12-22  Reiner Steib  <[email protected]>
 
+	* spam-report.el (spam-report-gmane-max-requests): New constant.
+	(spam-report-gmane-wait): New variable.
+	(spam-report-gmane-ham, spam-report-gmane-spam)
+	(spam-report-url-ping-plain, spam-report-process-queue): Wait only if
+	spam-report-gmane-wait is non-nil should be sufficient to avoid DOS-ing
+	the server.
+
 	* nnheader.el (nnheader-read-timeout, nnheader-accept-process-output):
 	Add explanations.
 
Index: spam-report.el
diff -u gnus/lisp/spam-report.el:7.39 gnus/lisp/spam-report.el:7.40
--- spam-report.el:7.39	Wed Jun 11 16:19:44 2008
+++ spam-report.el	Mon Dec 22 23:06:59 2008
@@ -117,17 +117,33 @@
   "Report an article as ham by resending via email."
   (spam-report-resend articles t))
 
+(defconst spam-report-gmane-max-requests 4
+  "Number of reports to send before waiting for a response.")
+
+(defvar spam-report-gmane-wait nil
+  "When non-nil, wait until we get a server response.
+This makes sure we don't DOS the host, if many reports are
+submitted at once.  Internal variable.")
+
 (defun spam-report-gmane-ham (&rest articles)
   "Report ARTICLES as ham (unregister) through Gmane."
   (interactive (gnus-summary-work-articles current-prefix-arg))
-  (dolist (article articles)
-    (spam-report-gmane-internal t article)))
+  (let ((count 0))
+    (dolist (article articles)
+      (setq count (1+ count))
+      (let ((spam-report-gmane-wait
+	     (zerop (% count spam-report-gmane-max-requests))))
+	(spam-report-gmane-internal t article)))))
 
 (defun spam-report-gmane-spam (&rest articles)
   "Report ARTICLES as spam through Gmane."
   (interactive (gnus-summary-work-articles current-prefix-arg))
-  (dolist (article articles)
-    (spam-report-gmane-internal nil article)))
+  (let ((count 0))
+    (dolist (article articles)
+      (setq count (1+ count))
+      (let ((spam-report-gmane-wait
+	     (zerop (% count spam-report-gmane-max-requests))))
+	(spam-report-gmane-internal nil article)))))
 
 ;; `spam-report-gmane' was an interactive entry point, so we should provide an
 ;; alias.
@@ -245,10 +261,14 @@
        tcp-connection
        (format "GET %s HTTP/1.1\nUser-Agent: %s\nHost: %s\n\n"
 	       report spam-report-user-agent host))
-      ;; Wait until we get something so we don't DOS the host. 
-      (while (and (memq (process-status tcp-connection) '(open run))
-		  (zerop (buffer-size)))
-	(accept-process-output tcp-connection)))))
+      ;; Wait until we get something so we don't DOS the host, if
+      ;; `spam-report-gmane-wait' is let-bound to t.
+      (when spam-report-gmane-wait
+	(gnus-message 7 "Waiting for response from %s..." host)
+	(while (and (memq (process-status tcp-connection) '(open run))
+		    (zerop (buffer-size)))
+	  (accept-process-output tcp-connection))
+	(gnus-message 7 "Waiting for response from %s... done" host)))))
 
 ;;;###autoload
 (defun spam-report-process-queue (&optional file keep)
@@ -278,7 +298,12 @@
     (while (and (not (eobp))
 		(re-search-forward
 		 "http://\\([^/]+\\)\\(/.*\\) *$" (point-at-eol) t))
-      (funcall spam-report-url-ping-function (match-string 1) (match-string 2))
+      (let ((spam-report-gmane-wait
+	     (zerop (% (line-number-at-pos) spam-report-gmane-max-requests))))
+	(gnus-message 6 "Reporting %s%s..."
+		      (match-string 1) (match-string 2))
+	(funcall spam-report-url-ping-function
+		 (match-string 1) (match-string 2)))
       (forward-line 1))
     (if (or (eq keep nil)
 	    (and (eq keep 'ask)