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
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.
(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)
(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)
--- /dev/null
+;;; 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.
(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"))
(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))
(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
(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