* spam-report.el (Module): new module for spam reporting
authorTeodor Zlatanov <tzz@lifelogs.com>
Wed, 16 Apr 2003 16:28:01 +0000 (16:28 +0000)
committerTeodor Zlatanov <tzz@lifelogs.com>
Wed, 16 Apr 2003 16:28:01 +0000 (16:28 +0000)
* gnus.el (spam-process): added
gnus-group-spam-exit-processor-report-gmane to the list of choices
(gnus-install-group-spam-parameters): defined new spam exit processor

* spam.el (autoload): autoload spam-report-gmane when needed
(spam-report-gmane-register-routine): glue for spam-report.el
(spam-group-spam-processor-report-gmane-p): glue for the
gnus-group-spam-exit-processor-report-gmane spam processor
(spam-summary-prepare-exit): check the report-gmane spam processor
and run spam-report-gmane-register-routine if it's active

lisp/ChangeLog
lisp/gnus.el
lisp/spam-report.el [new file with mode: 0644]
lisp/spam.el

index 6e946cc..a65b067 100644 (file)
@@ -1,4 +1,18 @@
 2003-04-16  Teodor Zlatanov  <tzz@lifelogs.com>
+
+       * spam-report.el (Module): new module for spam reporting
+
+       * gnus.el (spam-process): added
+       gnus-group-spam-exit-processor-report-gmane to the list of choices
+       (gnus-install-group-spam-parameters): defined new spam exit processor
+
+       * spam.el (autoload): autoload spam-report-gmane when needed
+       (spam-report-gmane-register-routine): glue for spam-report.el
+       (spam-group-spam-processor-report-gmane-p): glue for the
+       gnus-group-spam-exit-processor-report-gmane spam processor
+       (spam-summary-prepare-exit): check the report-gmane spam processor
+       and run spam-report-gmane-register-routine if it's active
+
        From John Wiegley <johnw@gnu.org>
 
        * spam.el (spam-bogofilter-score): check bogofilter headers before
index 6be7385..500425f 100644 (file)
@@ -1810,20 +1810,20 @@ This only makes sense for mail groups."
 When a spam group is entered, all unread articles are marked as spam.")
 
   (defvar gnus-group-spam-exit-processor-ifile "ifile"
-    "The ifile summary exit spam processor.
-Only applicable to spam groups.")
+    "The ifile summary exit spam processor.")
 
   (defvar gnus-group-spam-exit-processor-stat "stat"
-    "The spam-stat summary exit spam processor.
-Only applicable to spam groups.")
+    "The spam-stat summary exit spam processor.")
 
   (defvar gnus-group-spam-exit-processor-bogofilter "bogofilter"
-    "The Bogofilter summary exit spam processor.
-Only applicable to spam groups.")
+    "The Bogofilter summary exit spam processor.")
 
   (defvar gnus-group-spam-exit-processor-blacklist "blacklist"
-    "The Blacklist summary exit spam processor.
-Only applicable to spam groups.")
+    "The Blacklist summary exit spam processor.")
+
+  (defvar gnus-group-spam-exit-processor-report-gmane "report-gmane"
+    "The Gmane reporting summary exit spam processor.
+Only applicable to NNTP groups with articles from Gmane.  See spam-report.el")
 
   (defvar gnus-group-ham-exit-processor-ifile "ifile-ham"
     "The ifile summary exit ham processor.
@@ -1860,6 +1860,7 @@ Only applicable to non-spam (unclassified and ham) groups.")
                                   (variable-item gnus-group-spam-exit-processor-stat)
                                   (variable-item gnus-group-spam-exit-processor-bogofilter)
                                   (variable-item gnus-group-spam-exit-processor-blacklist)
+                                  (variable-item gnus-group-spam-exit-processor-report-gmane)
                                   (variable-item gnus-group-ham-exit-processor-bogofilter)
                                   (variable-item gnus-group-ham-exit-processor-ifile)
                                   (variable-item gnus-group-ham-exit-processor-stat)
@@ -1885,6 +1886,7 @@ for mail groups."
                                      (variable-item gnus-group-spam-exit-processor-stat)
                                      (variable-item gnus-group-spam-exit-processor-bogofilter)
                                      (variable-item gnus-group-spam-exit-processor-blacklist)
+                                     (variable-item gnus-group-spam-exit-processor-report-gmane)
                                      (variable-item gnus-group-ham-exit-processor-bogofilter)
                                      (variable-item gnus-group-ham-exit-processor-ifile)
                                      (variable-item gnus-group-ham-exit-processor-stat)
diff --git a/lisp/spam-report.el b/lisp/spam-report.el
new file mode 100644 (file)
index 0000000..fafb891
--- /dev/null
@@ -0,0 +1,97 @@
+;;; spam-report.el --- Reporting spam
+;; Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+
+;; Author: Teodor Zlatanov <tzz@lifelogs.com>
+;; Keywords: network
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;;; This module addresses a few aspects of spam reporting under Gnus.  Page
+;;; breaks are used for grouping declarations and documentation relating to
+;;; each particular aspect.
+
+;;; Code:
+(require 'gnus)
+(require 'gnus-sum)
+
+(defgroup spam-report nil
+  "Spam reporting configuration.")
+
+(defcustom spam-report-gmane-regex nil
+  "String matching Gmane newsgroups if wanted, e.g. \"^nntp+.*:gmane.\"
+This is probably handled better with group/topic parameters."
+  :type 'regexp
+  :group 'spam-report)
+
+(defcustom spam-report-gmane-spam-header 
+  "^X-Report-Spam: http://\\([^/]+\\)\\(.*\\)$"
+  "String matching Gmane spam-reporting header.  Two match groups are needed."
+  :type 'regexp
+  :group 'spam-report)
+
+(defcustom spam-report-gmane-use-article-number t
+  "Whether the article number (faster!) or the header should be used."
+  :type 'boolean
+  :group 'spam-report)
+
+(defun spam-report-gmane (article)
+  "Report an article as spam through Gmane"
+  (interactive "nEnter the article number: ")
+  (when (and gnus-newsgroup-name
+            (or (null spam-report-gmane-regex)
+                (string-match spam-report-gmane-regex gnus-newsgroup-name)))
+    (gnus-message 6 "Reporting spam article %d to spam.gmane.org..." article)
+      (if spam-report-gmane-use-article-number
+         (spam-report-url-ping "spam.gmane.org" 
+                   (format "/%s:%d"
+                           (gnus-group-real-name gnus-newsgroup-name)
+                           (gnus-summary-article-number)))
+       (with-current-buffer nntp-server-buffer
+         (gnus-request-head article gnus-newsgroup-name)
+         (goto-char (point-min))
+         (if (re-search-forward spam-report-gmane-spam-header nil t)
+             (let* ((host (match-string 1))
+                    (report (match-string 2))
+                    (url (format "http://%s%s" host report)))
+               (gnus-message 10 "Reporting spam through URL %s..." url)
+               (spam-report-url-ping host report))
+           (gnus-message 10 "Could not find X-Report-Spam in article %d..."
+                         article))))))
+
+
+(defun spam-report-url-ping (host report)
+  "Ping a host through HTTP, addressing a specific GET resource"
+  (let ((tcp-connection))
+    (with-temp-buffer
+      (or (setq tcp-connection
+               (open-network-stream 
+                "URL ping"
+                (buffer-name)
+                host
+                80))
+         (error "Could not open connection to %s" host))
+      (set-marker (process-mark tcp-connection) (point-min))
+      (process-send-string tcp-connection
+                          (format "GET %s HTTP/1.1\nHost: %s\n\n"
+                                  report host)))))
+
+(provide 'spam-report)
+
+;;; spam-report.el ends here.
index e39524b..fe437d3 100644 (file)
 (eval-and-compile
   (autoload 'query-dig "dig"))
 
+;; autoload spam-report
+(eval-and-compile
+  (autoload 'spam-report-gmane "spam-report"))
+
 ;; autoload query-dns
 (eval-and-compile
   (autoload 'query-dns "dns"))
@@ -335,6 +339,9 @@ your main source of newsgroup names."
       (member processor (car (gnus-parameter-spam-process group)))
     nil))
 
+(defun spam-group-spam-processor-report-gmane-p (group)
+  (spam-group-processor-p group 'gnus-group-spam-exit-processor-report-gmane))
+
 (defun spam-group-spam-processor-bogofilter-p (group)
   (spam-group-processor-p group 'gnus-group-spam-exit-processor-bogofilter))
 
@@ -394,6 +401,10 @@ your main source of newsgroup names."
       (gnus-message 5 "Registering spam with the blacklist")
       (spam-blacklist-register-routine))
 
+    (when (spam-group-spam-processor-report-gmane-p gnus-newsgroup-name)
+      (gnus-message 5 "Registering spam with the Gmane report")
+      (spam-report-gmane-register-routine))
+
     (if spam-move-spam-nonspam-groups-only      
        (when (not (spam-group-spam-contents-p gnus-newsgroup-name))
          (spam-mark-spam-as-expired-and-move-routine
@@ -961,8 +972,14 @@ Uses `gnus-newsgroup-name' if category is nil (for ham registration)."
           (spam-enter-whitelist from))))))
 
 \f
-;;;; Bogofilter
+;;;; Spam-report glue
+(defun spam-report-gmane-register-routine ()
+  (spam-generic-register-routine
+   'spam-report-gmane
+   nil))
 
+\f
+;;;; Bogofilter
 (defun spam-check-bogofilter-headers (&optional score)
   (let ((header (message-fetch-field spam-bogofilter-header)))
       (when (and header