annotate lisp/gnus/spam-report.el @ 88192:f2fae8754f34

(rmail-process-new-messages): Don't require rmailkwd here, do it at toplevel instead.
author Henrik Enberg <henrik.enberg@telia.com>
date Tue, 17 Jan 2006 21:33:12 +0000
parents d7ddb3e565de
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88155
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
1 ;;; spam-report.el --- Reporting spam
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
2
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
3 ;; Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
4
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
5 ;; Author: Teodor Zlatanov <tzz@lifelogs.com>
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
6 ;; Keywords: network
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
7
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
9
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
13 ;; any later version.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
14
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
18 ;; GNU General Public License for more details.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
19
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
23 ;; Boston, MA 02110-1301, USA.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
24
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
25 ;;; Commentary:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
26
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
27 ;;; This module addresses a few aspects of spam reporting under Gnus. Page
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
28 ;;; breaks are used for grouping declarations and documentation relating to
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
29 ;;; each particular aspect.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
30
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
31 ;;; Code:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
32 (require 'gnus)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
33 (require 'gnus-sum)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
34
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
35 (eval-and-compile
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
36 (autoload 'mm-url-insert "mm-url"))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
37
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
38 (defgroup spam-report nil
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
39 "Spam reporting configuration."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
40 :group 'mail
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
41 :group 'news)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
42
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
43 (defcustom spam-report-gmane-regex nil
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
44 "Regexp matching Gmane newsgroups, e.g. \"^nntp\\+.*:gmane\\.\"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
45 If you are using spam.el, consider setting gnus-spam-process-newsgroups
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
46 or the gnus-group-spam-exit-processor-report-gmane group/topic parameter
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
47 instead."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
48 :type '(radio (const nil)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
49 (regexp :value "^nntp\+.*:gmane\."))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
50 :group 'spam-report)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
51
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
52 (defcustom spam-report-gmane-use-article-number t
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
53 "Whether the article number (faster!) or the header should be used."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
54 :type 'boolean
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
55 :group 'spam-report)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
56
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
57 (defcustom spam-report-url-ping-function
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
58 'spam-report-url-ping-plain
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
59 "Function to use for url ping spam reporting.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
60 The function must accept the arguments `host' and `report'."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
61 :type '(choice
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
62 (const :tag "Connect directly"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
63 spam-report-url-ping-plain)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
64 (const :tag "Use the external program specified in `mm-url-program'"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
65 spam-report-url-ping-mm-url)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
66 (const :tag "Store request URLs in `spam-report-requests-file'"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
67 spam-report-url-to-file)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
68 (function :tag "User defined function" nil))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
69 :group 'spam-report)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
70
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
71 (defcustom spam-report-requests-file
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
72 (nnheader-concat gnus-directory "spam/" "spam-report-requests.url")
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
73 ;; Is there a convention for the extension of such a file?
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
74 ;; Should we use `spam-directory'?
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
75 "File where spam report request are stored."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
76 :type 'file
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
77 :group 'spam-report)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
78
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
79 (defvar spam-report-url-ping-temp-agent-function nil
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
80 "Internal variable for `spam-report-agentize' and `spam-report-deagentize'.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
81 This variable will store the value of `spam-report-url-ping-function' from
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
82 before `spam-report-agentize' was run, so that `spam-report-deagentize' can
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
83 undo that change.")
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
84
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
85 (defun spam-report-gmane (&rest articles)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
86 "Report an article as spam through Gmane"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
87 (dolist (article articles)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
88 (when (and gnus-newsgroup-name
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
89 (or (null spam-report-gmane-regex)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
90 (string-match spam-report-gmane-regex gnus-newsgroup-name)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
91 (gnus-message 6 "Reporting spam article %d to spam.gmane.org..." article)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
92 (if spam-report-gmane-use-article-number
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
93 (spam-report-url-ping
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
94 "spam.gmane.org"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
95 (format "/%s:%d"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
96 (gnus-group-real-name gnus-newsgroup-name)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
97 article))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
98 (with-current-buffer nntp-server-buffer
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
99 (gnus-request-head article gnus-newsgroup-name)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
100 (let ((case-fold-search t)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
101 field host report url)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
102 ;; First check for X-Report-Spam because it's more specific to
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
103 ;; spam reporting than Archived-At. OTOH, all new articles on
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
104 ;; Gmane don't have X-Report-Spam anymore (unless Lars changes his
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
105 ;; mind :-)).
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
106 ;;
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
107 ;; There might be more than one Archived-At header so we need to
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
108 ;; find (and transform) the one related to Gmane.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
109 (setq field (or (gnus-fetch-field "X-Report-Spam")
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
110 (gnus-fetch-field "Archived-At")))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
111 (setq host (progn
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
112 (string-match
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
113 (concat "http://\\([a-z]+\\.gmane\\.org\\)"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
114 "\\(/[^:/]+[:/][0-9]+\\)")
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
115 field)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
116 (match-string 1 field)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
117 (setq report (match-string 2 field))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
118 (when (string-equal "permalink.gmane.org" host)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
119 (setq host "spam.gmane.org")
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
120 (setq report (gnus-replace-in-string
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
121 report "/\\([0-9]+\\)$" ":\\1")))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
122 (setq url (format "http://%s%s" host report))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
123 (if (not (and host report url))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
124 (gnus-message
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
125 3 "Could not find a spam report header in article %d..."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
126 article)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
127 (gnus-message 7 "Reporting spam through URL %s..." url)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
128 (spam-report-url-ping host report))))))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
129
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
130 (defun spam-report-url-ping (host report)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
131 "Ping a host through HTTP, addressing a specific GET resource using
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
132 the function specified by `spam-report-url-ping-function'."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
133 ;; Example:
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
134 ;; host: "spam.gmane.org"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
135 ;; report: "/gmane.some.group:123456"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
136 (funcall spam-report-url-ping-function host report))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
137
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
138 (defun spam-report-url-ping-plain (host report)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
139 "Ping a host through HTTP, addressing a specific GET resource."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
140 (let ((tcp-connection))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
141 (with-temp-buffer
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
142 (or (setq tcp-connection
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
143 (open-network-stream
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
144 "URL ping"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
145 (buffer-name)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
146 host
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
147 80))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
148 (error "Could not open connection to %s" host))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
149 (set-marker (process-mark tcp-connection) (point-min))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
150 (process-send-string
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
151 tcp-connection
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
152 (format "GET %s HTTP/1.1\nUser-Agent: %s (spam-report.el)\nHost: %s\n\n"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
153 report (gnus-extended-version) host)))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
154
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
155 ;;;###autoload
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
156 (defun spam-report-process-queue (&optional file keep)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
157 "Report all queued requests from `spam-report-requests-file'.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
158
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
159 If FILE is given, use it instead of `spam-report-requests-file'.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
160 If KEEP is t, leave old requests in the file. If KEEP is the
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
161 symbol `ask', query before flushing the queue file."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
162 (interactive
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
163 (list (read-file-name
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
164 "File: "
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
165 (file-name-directory spam-report-requests-file)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
166 spam-report-requests-file
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
167 nil
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
168 (file-name-nondirectory spam-report-requests-file))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
169 current-prefix-arg))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
170 (if (eq spam-report-url-ping-function 'spam-report-url-to-file)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
171 (error (concat "Cannot process requests when "
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
172 "`spam-report-url-ping-function' is "
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
173 "`spam-report-url-to-file'."))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
174 (gnus-message 7 "Processing requests using `%s'."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
175 spam-report-url-ping-function))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
176 (or file (setq file spam-report-requests-file))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
177 (save-excursion
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
178 (set-buffer (find-file-noselect file))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
179 (goto-char (point-min))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
180 (while (and (not (eobp))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
181 (re-search-forward
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
182 "http://\\([^/]+\\)\\(/.*\\) *$" (gnus-point-at-eol) t))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
183 (funcall spam-report-url-ping-function (match-string 1) (match-string 2))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
184 (forward-line 1))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
185 (if (or (eq keep nil)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
186 (and (eq keep 'ask)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
187 (y-or-n-p
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
188 (format
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
189 "Flush requests from `%s'? " (current-buffer)))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
190 (progn
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
191 (gnus-message 7 "Flushing request file `%s'"
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
192 spam-report-requests-file)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
193 (erase-buffer)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
194 (save-buffer)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
195 (kill-buffer (current-buffer)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
196 (gnus-message 7 "Keeping requests in `%s'" spam-report-requests-file))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
197
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
198 ;;;###autoload
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
199 (defun spam-report-url-ping-mm-url (host report)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
200 "Ping a host through HTTP, addressing a specific GET resource. Use
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
201 the external program specified in `mm-url-program' to connect to
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
202 server."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
203 (with-temp-buffer
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
204 (let ((url (format "http://%s%s" host report)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
205 (mm-url-insert url t))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
206
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
207 ;;;###autoload
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
208 (defun spam-report-url-to-file (host report)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
209 "Collect spam report requests in `spam-report-requests-file'.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
210 Customize `spam-report-url-ping-function' to use this function."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
211 (let ((url (format "http://%s%s" host report))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
212 (file spam-report-requests-file))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
213 (gnus-make-directory (file-name-directory file))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
214 (gnus-message 9 "Writing URL `%s' to file `%s'" url file)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
215 (with-temp-buffer
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
216 (insert url)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
217 (newline)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
218 (append-to-file (point-min) (point-max) file))))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
219
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
220 ;;;###autoload
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
221 (defun spam-report-agentize ()
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
222 "Add spam-report support to the Agent.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
223 Spam reports will be queued with \\[spam-report-url-to-file] when
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
224 the Agent is unplugged, and will be submitted in a batch when the
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
225 Agent is plugged."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
226 (interactive)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
227 (add-hook 'gnus-agent-plugged-hook 'spam-report-plug-agent)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
228 (add-hook 'gnus-agent-unplugged-hook 'spam-report-unplug-agent))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
229
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
230 ;;;###autoload
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
231 (defun spam-report-deagentize ()
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
232 "Remove spam-report support from the Agent.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
233 Spam reports will be queued with the method used when
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
234 \\[spam-report-agentize] was run."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
235 (interactive)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
236 (remove-hook 'gnus-agent-plugged-hook 'spam-report-plug-agent)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
237 (remove-hook 'gnus-agent-unplugged-hook 'spam-report-unplug-agent))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
238
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
239 (defun spam-report-plug-agent ()
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
240 "Adjust spam report settings for plugged state.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
241 Process queued spam reports."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
242 ;; Process the queue, unless the user only wanted to report to a file
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
243 ;; anyway.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
244 (unless (equal spam-report-url-ping-temp-agent-function
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
245 'spam-report-url-to-file)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
246 (spam-report-process-queue))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
247 ;; Set the reporting function, if we have memorized something otherwise,
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
248 ;; stick with plain URL reporting.
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
249 (setq spam-report-url-ping-function
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
250 (or spam-report-url-ping-temp-agent-function
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
251 'spam-report-url-ping-plain)))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
252
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
253 (defun spam-report-unplug-agent ()
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
254 "Restore spam report settings for unplugged state."
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
255 ;; save the old value
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
256 (setq spam-report-url-ping-temp-agent-function
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
257 spam-report-url-ping-function)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
258 ;; store all reports to file
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
259 (setq spam-report-url-ping-function
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
260 'spam-report-url-to-file))
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
261
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
262 (provide 'spam-report)
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
263
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
264 ;;; arch-tag: f6683295-ec89-4ab5-8803-8cc842293022
d7ddb3e565de sync with trunk
Henrik Enberg <henrik.enberg@telia.com>
parents:
diff changeset
265 ;;; spam-report.el ends here.