0
|
1 ;;; gnus-nocem.el --- NoCeM pseudo-cancellation treatment
|
98
|
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
|
0
|
3
|
|
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
|
|
5 ;; Keywords: news
|
|
6
|
|
7 ;; This file is part of GNU Emacs.
|
|
8
|
|
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
10 ;; it under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 ;; GNU General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Commentary:
|
|
25
|
|
26 ;;; Code:
|
|
27
|
|
28 (require 'gnus)
|
|
29 (require 'nnmail)
|
98
|
30 (require 'gnus-art)
|
|
31 (require 'gnus-sum)
|
|
32 (require 'gnus-range)
|
0
|
33
|
98
|
34 (defgroup gnus-nocem nil
|
|
35 "NoCeM pseudo-cancellation treatment"
|
|
36 :group 'gnus-score)
|
|
37
|
108
|
38 (defcustom gnus-nocem-groups
|
98
|
39 '("news.lists.filters" "news.admin.net-abuse.bulletins"
|
|
40 "alt.nocem.misc" "news.admin.net-abuse.announce")
|
|
41 "List of groups that will be searched for NoCeM messages."
|
|
42 :group 'gnus-nocem
|
|
43 :type '(repeat (string :tag "Group")))
|
0
|
44
|
108
|
45 (defcustom gnus-nocem-issuers
|
98
|
46 '("AutoMoose-1" "Automoose-1" ; CancelMoose[tm]
|
|
47 "rbraver@ohww.norman.ok.us" ; Robert Braver
|
|
48 "clewis@ferret.ocunix.on.ca;" ; Chris Lewis
|
|
49 "jem@xpat.com;" ; Despammer from Korea
|
|
50 "snowhare@xmission.com" ; Benjamin "Snowhare" Franz
|
|
51 "red@redpoll.mrfs.oh.us (Richard E. Depew)"
|
|
52 )
|
|
53 "List of NoCeM issuers to pay attention to."
|
|
54 :group 'gnus-nocem
|
|
55 :type '(repeat string))
|
0
|
56
|
108
|
57 (defcustom gnus-nocem-directory
|
98
|
58 (nnheader-concat gnus-article-save-directory "NoCeM/")
|
|
59 "*Directory where NoCeM files will be stored."
|
|
60 :group 'gnus-nocem
|
|
61 :type 'directory)
|
0
|
62
|
98
|
63 (defcustom gnus-nocem-expiry-wait 15
|
|
64 "*Number of days to keep NoCeM headers in the cache."
|
|
65 :group 'gnus-nocem
|
|
66 :type 'integer)
|
0
|
67
|
98
|
68 (defcustom gnus-nocem-verifyer 'mc-verify
|
0
|
69 "*Function called to verify that the NoCeM message is valid.
|
|
70 One likely value is `mc-verify'. If the function in this variable
|
98
|
71 isn't bound, the message will be used unconditionally."
|
|
72 :group 'gnus-nocem
|
|
73 :type '(radio (function-item mc-verify)
|
|
74 (function :tag "other")))
|
|
75
|
|
76 (defcustom gnus-nocem-liberal-fetch nil
|
|
77 "*If t try to fetch all messages which have @@NCM in the subject.
|
|
78 Otherwise don't fetch messages which have references or whose messsage-id
|
|
79 matches an previously scanned and verified nocem message."
|
|
80 :group 'gnus-nocem
|
|
81 :type 'boolean)
|
0
|
82
|
|
83 ;;; Internal variables
|
|
84
|
|
85 (defvar gnus-nocem-active nil)
|
|
86 (defvar gnus-nocem-alist nil)
|
|
87 (defvar gnus-nocem-touched-alist nil)
|
|
88 (defvar gnus-nocem-hashtb nil)
|
98
|
89 (defvar gnus-nocem-seen-message-ids nil)
|
0
|
90
|
|
91 ;;; Functions
|
|
92
|
|
93 (defun gnus-nocem-active-file ()
|
|
94 (concat (file-name-as-directory gnus-nocem-directory) "active"))
|
|
95
|
|
96 (defun gnus-nocem-cache-file ()
|
|
97 (concat (file-name-as-directory gnus-nocem-directory) "cache"))
|
|
98
|
|
99 (defun gnus-nocem-scan-groups ()
|
|
100 "Scan all NoCeM groups for new NoCeM messages."
|
|
101 (interactive)
|
|
102 (let ((groups gnus-nocem-groups)
|
|
103 group active gactive articles)
|
98
|
104 (gnus-make-directory gnus-nocem-directory)
|
0
|
105 ;; Load any previous NoCeM headers.
|
|
106 (gnus-nocem-load-cache)
|
|
107 ;; Read the active file if it hasn't been read yet.
|
|
108 (and (file-exists-p (gnus-nocem-active-file))
|
|
109 (not gnus-nocem-active)
|
98
|
110 (ignore-errors
|
|
111 (load (gnus-nocem-active-file) t t t)))
|
0
|
112 ;; Go through all groups and see whether new articles have
|
108
|
113 ;; arrived.
|
0
|
114 (while (setq group (pop groups))
|
|
115 (if (not (setq gactive (gnus-activate-group group)))
|
98
|
116 () ; This group doesn't exist.
|
0
|
117 (setq active (nth 1 (assoc group gnus-nocem-active)))
|
|
118 (when (and (not (< (cdr gactive) (car gactive))) ; Empty group.
|
|
119 (or (not active)
|
|
120 (< (cdr active) (cdr gactive))))
|
|
121 ;; Ok, there are new articles in this group, se we fetch the
|
|
122 ;; headers.
|
|
123 (save-excursion
|
|
124 (let ((dependencies (make-vector 10 nil))
|
98
|
125 headers header)
|
|
126 (nnheader-temp-write nil
|
|
127 (setq headers
|
|
128 (if (eq 'nov
|
108
|
129 (gnus-retrieve-headers
|
98
|
130 (setq articles
|
|
131 (gnus-uncompress-range
|
108
|
132 (cons
|
98
|
133 (if active (1+ (cdr active))
|
|
134 (car gactive))
|
|
135 (cdr gactive))))
|
|
136 group))
|
108
|
137 (gnus-get-newsgroup-headers-xover
|
98
|
138 articles nil dependencies)
|
|
139 (gnus-get-newsgroup-headers dependencies)))
|
|
140 (while (setq header (pop headers))
|
|
141 ;; We take a closer look on all articles that have
|
|
142 ;; "@@NCM" in the subject. Unless we already read
|
|
143 ;; this cross posted message. Nocem messages
|
|
144 ;; are not allowed to have references, so we can
|
|
145 ;; ignore scanning followups.
|
|
146 (and (string-match "@@NCM" (mail-header-subject header))
|
|
147 (or gnus-nocem-liberal-fetch
|
100
|
148 (and (or (string= "" (mail-header-references
|
|
149 header))
|
|
150 (null (mail-header-references header)))
|
98
|
151 (not (member (mail-header-message-id header)
|
|
152 gnus-nocem-seen-message-ids))))
|
|
153 (gnus-nocem-check-article group header)))))))
|
0
|
154 (setq gnus-nocem-active
|
98
|
155 (cons (list group gactive)
|
0
|
156 (delq (assoc group gnus-nocem-active)
|
|
157 gnus-nocem-active)))))
|
|
158 ;; Save the results, if any.
|
|
159 (gnus-nocem-save-cache)
|
|
160 (gnus-nocem-save-active)))
|
|
161
|
|
162 (defun gnus-nocem-check-article (group header)
|
|
163 "Check whether the current article is an NCM article and that we want it."
|
|
164 ;; Get the article.
|
|
165 (gnus-message 7 "Checking article %d in %s for NoCeM..."
|
|
166 (mail-header-number header) group)
|
|
167 (let ((date (mail-header-date header))
|
|
168 issuer b e)
|
|
169 (when (or (not date)
|
108
|
170 (nnmail-time-less
|
0
|
171 (nnmail-time-since (nnmail-date-to-time date))
|
|
172 (nnmail-days-to-time gnus-nocem-expiry-wait)))
|
|
173 (gnus-request-article-this-buffer (mail-header-number header) group)
|
2
|
174 (goto-char (point-min))
|
98
|
175 (when (re-search-forward "-----BEGIN PGP MESSAGE-----" nil t)
|
|
176 (delete-region (point-min) (match-beginning 0)))
|
|
177 (when (re-search-forward "-----END PGP MESSAGE-----\n?" nil t)
|
|
178 (delete-region (match-end 0) (point-max)))
|
|
179 (goto-char (point-min))
|
0
|
180 ;; The article has to have proper NoCeM headers.
|
|
181 (when (and (setq b (search-forward "\n@@BEGIN NCM HEADERS\n" nil t))
|
|
182 (setq e (search-forward "\n@@BEGIN NCM BODY\n" nil t)))
|
|
183 ;; We get the name of the issuer.
|
|
184 (narrow-to-region b e)
|
|
185 (setq issuer (mail-fetch-field "issuer"))
|
98
|
186 (widen)
|
|
187 (and (member issuer gnus-nocem-issuers) ; We like her....
|
|
188 (gnus-nocem-verify-issuer issuer) ; She is who she says she is...
|
|
189 (gnus-nocem-enter-article) ; We gobble the message..
|
|
190 (push (mail-header-message-id header) ; But don't come back for
|
|
191 gnus-nocem-seen-message-ids)))))) ; second helpings.
|
|
192
|
0
|
193 (defun gnus-nocem-verify-issuer (person)
|
|
194 "Verify using PGP that the canceler is who she says she is."
|
|
195 (if (fboundp gnus-nocem-verifyer)
|
|
196 (funcall gnus-nocem-verifyer)
|
98
|
197 ;; If we don't have Mailcrypt, then we use the message anyway.
|
0
|
198 t))
|
|
199
|
|
200 (defun gnus-nocem-enter-article ()
|
|
201 "Enter the current article into the NoCeM cache."
|
|
202 (goto-char (point-min))
|
|
203 (let ((b (search-forward "\n@@BEGIN NCM BODY\n" nil t))
|
|
204 (e (search-forward "\n@@END NCM BODY\n" nil t))
|
|
205 (buf (current-buffer))
|
98
|
206 ncm id group)
|
0
|
207 (when (and b e)
|
|
208 (narrow-to-region b (1+ (match-beginning 0)))
|
|
209 (goto-char (point-min))
|
|
210 (while (search-forward "\t" nil t)
|
98
|
211 (cond
|
|
212 ((not (ignore-errors
|
|
213 (setq group (let ((obarray gnus-active-hashtb)) (read buf)))))
|
|
214 ;; An error.
|
|
215 )
|
|
216 ((not (symbolp group))
|
|
217 ;; Ignore invalid entries.
|
|
218 )
|
|
219 ((not (boundp group))
|
|
220 ;; Make sure all entries in the hashtb are bound.
|
|
221 (set group nil))
|
|
222 (t
|
|
223 (when (gnus-gethash (symbol-name group) gnus-newsrc-hashtb)
|
|
224 ;; Valid group.
|
|
225 (beginning-of-line)
|
|
226 (while (= (following-char) ?\t)
|
|
227 (forward-line -1))
|
|
228 (setq id (buffer-substring (point) (1- (search-forward "\t"))))
|
|
229 (unless (gnus-gethash id gnus-nocem-hashtb)
|
|
230 ;; only store if not already present
|
|
231 (gnus-sethash id t gnus-nocem-hashtb)
|
|
232 (push id ncm))
|
|
233 (forward-line 1)
|
|
234 (while (= (following-char) ?\t)
|
|
235 (forward-line 1))))))
|
0
|
236 (when ncm
|
|
237 (setq gnus-nocem-touched-alist t)
|
|
238 (push (cons (let ((time (current-time))) (setcdr (cdr time) nil) time)
|
98
|
239 ncm)
|
|
240 gnus-nocem-alist))
|
|
241 t)))
|
0
|
242
|
|
243 (defun gnus-nocem-load-cache ()
|
|
244 "Load the NoCeM cache."
|
98
|
245 (interactive)
|
0
|
246 (unless gnus-nocem-alist
|
|
247 ;; The buffer doesn't exist, so we create it and load the NoCeM
|
108
|
248 ;; cache.
|
0
|
249 (when (file-exists-p (gnus-nocem-cache-file))
|
|
250 (load (gnus-nocem-cache-file) t t t)
|
|
251 (gnus-nocem-alist-to-hashtb))))
|
108
|
252
|
0
|
253 (defun gnus-nocem-save-cache ()
|
|
254 "Save the NoCeM cache."
|
|
255 (when (and gnus-nocem-alist
|
|
256 gnus-nocem-touched-alist)
|
|
257 (nnheader-temp-write (gnus-nocem-cache-file)
|
98
|
258 (gnus-prin1 `(setq gnus-nocem-alist ',gnus-nocem-alist)))
|
0
|
259 (setq gnus-nocem-touched-alist nil)))
|
|
260
|
|
261 (defun gnus-nocem-save-active ()
|
|
262 "Save the NoCeM active file."
|
|
263 (nnheader-temp-write (gnus-nocem-active-file)
|
98
|
264 (gnus-prin1 `(setq gnus-nocem-active ',gnus-nocem-active))))
|
0
|
265
|
|
266 (defun gnus-nocem-alist-to-hashtb ()
|
|
267 "Create a hashtable from the Message-IDs we have."
|
|
268 (let* ((alist gnus-nocem-alist)
|
|
269 (pprev (cons nil alist))
|
|
270 (prev pprev)
|
|
271 (expiry (nnmail-days-to-time gnus-nocem-expiry-wait))
|
|
272 entry)
|
|
273 (setq gnus-nocem-hashtb (gnus-make-hashtable (* (length alist) 51)))
|
|
274 (while (setq entry (car alist))
|
|
275 (if (not (nnmail-time-less (nnmail-time-since (car entry)) expiry))
|
|
276 ;; This entry has expired, so we remove it.
|
|
277 (setcdr prev (cdr alist))
|
|
278 (setq prev alist)
|
|
279 ;; This is ok, so we enter it into the hashtable.
|
|
280 (setq entry (cdr entry))
|
|
281 (while entry
|
|
282 (gnus-sethash (car entry) t gnus-nocem-hashtb)
|
|
283 (setq entry (cdr entry))))
|
|
284 (setq alist (cdr alist)))))
|
|
285
|
|
286 (gnus-add-shutdown 'gnus-nocem-close 'gnus)
|
|
287
|
|
288 (defun gnus-nocem-close ()
|
|
289 "Clear internal NoCeM variables."
|
|
290 (setq gnus-nocem-alist nil
|
|
291 gnus-nocem-hashtb nil
|
|
292 gnus-nocem-active nil
|
98
|
293 gnus-nocem-touched-alist nil
|
|
294 gnus-nocem-seen-message-ids nil))
|
0
|
295
|
|
296 (defun gnus-nocem-unwanted-article-p (id)
|
|
297 "Say whether article ID in the current group is wanted."
|
|
298 (gnus-gethash id gnus-nocem-hashtb))
|
|
299
|
|
300 (provide 'gnus-nocem)
|
|
301
|
|
302 ;;; gnus-nocem.el ends here
|