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