1 ;;; gnus-score --- scoring code for Gnus
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Author: Per Abrahamsen <amanda@iesd.auc.dk>
5 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
30 (defvar gnus-score-expiry-days 7
31 "*Number of days before unused score file entries are expired.")
33 (defvar gnus-orphan-score nil
34 "*All orphans get this score added. Set in the score file.")
36 (defvar gnus-default-adaptive-score-alist
38 (gnus-ticked-mark (from 4))
39 (gnus-dormant-mark (from 5))
40 (gnus-del-mark (from -4) (subject -1))
41 (gnus-read-mark (from 4) (subject 2))
42 (gnus-expirable-mark (from -1) (subject -1))
43 (gnus-killed-mark (from -1) (subject -3))
45 (gnus-catchup-mark (from -1) (subject -1)))
46 "*Alist of marks and scores.")
50 ;; Internal variables.
52 (defvar gnus-current-score-file nil)
54 (defvar gnus-adaptive-score-alist gnus-default-adaptive-score-alist)
56 (defvar gnus-score-alist nil
57 "Alist containing score information.
58 The keys can be symbols or strings. The following symbols are defined.
60 touched: If this alist has been modified.
61 mark: Automatically mark articles below this.
62 expunge: Automatically expunge articles below this.
63 files: List of other SCORE files to load when loading this one.
64 eval: Sexp to be evaluated when the score file is loaded.
66 String entries have the form (HEADER (MATCH TYPE SCORE DATE) ...)
67 where HEADER is the header being scored, MATCH is the string we are
68 looking for, TYPE is a flag indicating whether it should use regexp or
69 substring matching, SCORE is the score to add and DATE is the date
70 of the last succesful match.")
72 (defvar gnus-score-cache nil)
73 (defvar gnus-scores-articles nil)
74 (defvar gnus-scores-exclude-files nil)
75 (defvar gnus-header-index nil)
76 (defvar gnus-score-index nil)
78 (defvar gnus-winconf-edit-score nil)
80 (autoload 'gnus-uu-ctl-map "gnus-uu" nil nil 'keymap)
82 ;;; Summary mode score maps.
84 (defvar gnus-summary-score-map nil)
85 (defvar gnus-summary-increase-map nil)
86 (defvar gnus-summary-inc-subject-map nil)
87 (defvar gnus-summary-inc-author-map nil)
88 (defvar gnus-summary-inc-body-map nil)
89 (defvar gnus-summary-inc-id-map nil)
90 (defvar gnus-summary-inc-xref-map nil)
91 (defvar gnus-summary-inc-thread-map nil)
92 (defvar gnus-summary-inc-fol-map nil)
93 (defvar gnus-summary-lower-map nil)
94 (defvar gnus-summary-low-subject-map nil)
95 (defvar gnus-summary-low-author-map nil)
96 (defvar gnus-summary-low-body-map nil)
97 (defvar gnus-summary-low-id-map nil)
98 (defvar gnus-summary-low-xref-map nil)
99 (defvar gnus-summary-low-thread-map nil)
100 (defvar gnus-summary-low-fol-map nil)
102 (define-prefix-command 'gnus-summary-score-map)
103 (define-key gnus-summary-various-map "S" 'gnus-summary-score-map)
104 (define-key gnus-summary-score-map "s" 'gnus-summary-set-score)
105 (define-key gnus-summary-score-map "c" 'gnus-score-change-score-file)
106 (define-key gnus-summary-score-map "m" 'gnus-score-set-mark-below)
107 (define-key gnus-summary-score-map "x" 'gnus-score-set-expunge-below)
108 (define-key gnus-summary-score-map "e" 'gnus-score-edit-alist)
109 (define-key gnus-summary-score-map "f" 'gnus-score-edit-file)
112 (define-prefix-command 'gnus-summary-increase-map)
113 (define-key gnus-summary-mode-map "I" gnus-summary-increase-map)
115 (define-key gnus-summary-increase-map "i" 'gnus-summary-raise-same-subject-and-select)
116 (define-key gnus-summary-increase-map "I" 'gnus-summary-raise-same-subject)
117 (define-key gnus-summary-increase-map "\C-i" 'gnus-summary-raise-score)
119 (define-prefix-command 'gnus-summary-inc-subject-map)
120 (define-key gnus-summary-increase-map "s" gnus-summary-inc-subject-map)
121 (define-key gnus-summary-increase-map "S" 'gnus-summary-temporarily-raise-by-subject)
122 (define-key gnus-summary-inc-subject-map "s" 'gnus-summary-temporarily-raise-by-subject)
123 (define-key gnus-summary-inc-subject-map "S" 'gnus-summary-raise-by-subject)
124 (define-key gnus-summary-inc-subject-map "t" 'gnus-summary-temporarily-raise-by-subject)
125 (define-key gnus-summary-inc-subject-map "p" 'gnus-summary-raise-by-subject)
127 (define-prefix-command 'gnus-summary-inc-author-map)
128 (define-key gnus-summary-increase-map "a" 'gnus-summary-inc-author-map)
129 (define-key gnus-summary-increase-map "A" 'gnus-summary-temporarily-raise-by-author)
130 (define-key gnus-summary-inc-author-map "a" 'gnus-summary-temporarily-raise-by-author)
131 (define-key gnus-summary-inc-author-map "A" 'gnus-summary-raise-by-author)
132 (define-key gnus-summary-inc-author-map "t" 'gnus-summary-temporarily-raise-by-author)
133 (define-key gnus-summary-inc-author-map "p" 'gnus-summary-raise-by-author)
135 (define-prefix-command 'gnus-summary-inc-body-map)
136 (define-key gnus-summary-increase-map "b" 'gnus-summary-inc-body-map)
137 (define-key gnus-summary-increase-map "B" 'gnus-summary-temporarily-raise-by-body)
138 (define-key gnus-summary-inc-body-map "b" 'gnus-summary-temporarily-raise-by-body)
139 (define-key gnus-summary-inc-body-map "B" 'gnus-summary-raise-by-body)
140 (define-key gnus-summary-inc-body-map "t" 'gnus-summary-temporarily-raise-by-body)
141 (define-key gnus-summary-inc-body-map "p" 'gnus-summary-raise-by-body)
143 (define-prefix-command 'gnus-summary-inc-id-map)
144 (define-key gnus-summary-increase-map "i" 'gnus-summary-inc-id-map)
145 (define-key gnus-summary-increase-map "I" 'gnus-summary-temporarily-raise-by-id)
146 (define-key gnus-summary-inc-id-map "i" 'gnus-summary-temporarily-raise-by-id)
147 (define-key gnus-summary-inc-id-map "I" 'gnus-summary-raise-by-id)
148 (define-key gnus-summary-inc-id-map "t" 'gnus-summary-temporarily-raise-by-id)
149 (define-key gnus-summary-inc-id-map "p" 'gnus-summary-raise-by-id)
151 (define-prefix-command 'gnus-summary-inc-thread-map)
152 (define-key gnus-summary-increase-map "t" 'gnus-summary-inc-thread-map)
153 (define-key gnus-summary-increase-map "T" 'gnus-summary-temporarily-raise-by-thread)
154 (define-key gnus-summary-inc-thread-map "t" 'gnus-summary-temporarily-raise-by-thread)
155 (define-key gnus-summary-inc-thread-map "T" 'gnus-summary-raise-by-thread)
156 (define-key gnus-summary-inc-thread-map "t" 'gnus-summary-temporarily-raise-by-thread)
157 (define-key gnus-summary-inc-thread-map "p" 'gnus-summary-raise-by-thread)
159 (define-prefix-command 'gnus-summary-inc-xref-map)
160 (define-key gnus-summary-increase-map "x" 'gnus-summary-inc-xref-map)
161 (define-key gnus-summary-increase-map "X" 'gnus-summary-temporarily-raise-by-xref)
162 (define-key gnus-summary-inc-xref-map "x" 'gnus-summary-temporarily-raise-by-xref)
163 (define-key gnus-summary-inc-xref-map "X" 'gnus-summary-raise-by-xref)
164 (define-key gnus-summary-inc-xref-map "t" 'gnus-summary-temporarily-raise-by-xref)
165 (define-key gnus-summary-inc-xref-map "p" 'gnus-summary-raise-by-xref)
167 (define-prefix-command 'gnus-summary-inc-fol-map)
168 (define-key gnus-summary-increase-map "f" 'gnus-summary-inc-fol-map)
169 (define-key gnus-summary-increase-map "F" 'gnus-summary-raise-followups-to-author)
170 (define-key gnus-summary-inc-fol-map "f" 'gnus-summary-raise-followups-to-author)
171 (define-key gnus-summary-inc-fol-map "F" 'gnus-summary-raise-followups-to-author)
172 (define-key gnus-summary-inc-fol-map "t" 'gnus-summary-raise-followups-to-author)
173 (define-key gnus-summary-inc-fol-map "p" 'gnus-summary-raise-followups-to-author)
176 (define-prefix-command 'gnus-summary-lower-map)
177 (define-key gnus-summary-mode-map "L" 'gnus-summary-lower-map)
179 (define-key gnus-summary-lower-map "l" 'gnus-summary-lower-same-subject-and-select)
180 (define-key gnus-summary-lower-map "L" 'gnus-summary-lower-same-subject)
181 (define-key gnus-summary-lower-map "\C-l" 'gnus-summary-lower-score)
183 (define-prefix-command 'gnus-summary-low-subject-map)
184 (define-key gnus-summary-lower-map "s" 'gnus-summary-low-subject-map)
185 (define-key gnus-summary-lower-map "S" 'gnus-summary-temporarily-lower-by-subject)
186 (define-key gnus-summary-low-subject-map "s" 'gnus-summary-temporarily-lower-by-subject)
187 (define-key gnus-summary-low-subject-map "S" 'gnus-summary-lower-by-subject)
188 (define-key gnus-summary-low-subject-map "t" 'gnus-summary-temporarily-lower-by-subject)
189 (define-key gnus-summary-low-subject-map "p" 'gnus-summary-lower-by-subject)
191 (define-prefix-command 'gnus-summary-low-body-map)
192 (define-key gnus-summary-lower-map "b" 'gnus-summary-low-body-map)
193 (define-key gnus-summary-lower-map "B" 'gnus-summary-temporarily-lower-by-body)
194 (define-key gnus-summary-low-body-map "b" 'gnus-summary-temporarily-lower-by-body)
195 (define-key gnus-summary-low-body-map "B" 'gnus-summary-lower-by-body)
196 (define-key gnus-summary-low-body-map "t" 'gnus-summary-temporarily-lower-by-body)
197 (define-key gnus-summary-low-body-map "p" 'gnus-summary-lower-by-body)
199 (define-prefix-command 'gnus-summary-low-author-map)
200 (define-key gnus-summary-lower-map "a" 'gnus-summary-low-author-map)
201 (define-key gnus-summary-lower-map "A" 'gnus-summary-temporarily-lower-by-author)
202 (define-key gnus-summary-low-author-map "a" 'gnus-summary-temporarily-lower-by-author)
203 (define-key gnus-summary-low-author-map "A" 'gnus-summary-lower-by-author)
204 (define-key gnus-summary-low-author-map "t" 'gnus-summary-temporarily-lower-by-author)
205 (define-key gnus-summary-low-author-map "p" 'gnus-summary-lower-by-author)
207 (define-prefix-command 'gnus-summary-low-id-map)
208 (define-key gnus-summary-lower-map "i" 'gnus-summary-low-id-map)
209 (define-key gnus-summary-lower-map "I" 'gnus-summary-temporarily-lower-by-id)
210 (define-key gnus-summary-low-id-map "i" 'gnus-summary-temporarily-lower-by-id)
211 (define-key gnus-summary-low-id-map "I" 'gnus-summary-lower-by-id)
212 (define-key gnus-summary-low-id-map "t" 'gnus-summary-temporarily-lower-by-id)
213 (define-key gnus-summary-low-id-map "p" 'gnus-summary-lower-by-id)
215 (define-prefix-command 'gnus-summary-low-thread-map)
216 (define-key gnus-summary-lower-map "t" 'gnus-summary-low-thread-map)
217 (define-key gnus-summary-lower-map "T" 'gnus-summary-temporarily-lower-by-thread)
218 (define-key gnus-summary-low-thread-map "t" 'gnus-summary-temporarily-lower-by-thread)
219 (define-key gnus-summary-low-thread-map "T" 'gnus-summary-lower-by-thread)
220 (define-key gnus-summary-low-thread-map "t" 'gnus-summary-temporarily-lower-by-thread)
221 (define-key gnus-summary-low-thread-map "p" 'gnus-summary-lower-by-thread)
223 (define-prefix-command 'gnus-summary-low-xref-map)
224 (define-key gnus-summary-lower-map "x" 'gnus-summary-low-xref-map)
225 (define-key gnus-summary-lower-map "X" 'gnus-summary-temporarily-lower-by-xref)
226 (define-key gnus-summary-low-xref-map "x" 'gnus-summary-temporarily-lower-by-xref)
227 (define-key gnus-summary-low-xref-map "X" 'gnus-summary-lower-by-xref)
228 (define-key gnus-summary-low-xref-map "t" 'gnus-summary-temporarily-lower-by-xref)
229 (define-key gnus-summary-low-xref-map "p" 'gnus-summary-lower-by-xref)
231 (define-prefix-command 'gnus-summary-low-fol-map)
232 (define-key gnus-summary-lower-map "f" 'gnus-summary-low-fol-map)
233 (define-key gnus-summary-lower-map "F" 'gnus-summary-lower-followups-to-author)
234 (define-key gnus-summary-low-fol-map "f" 'gnus-summary-lower-followups-to-author)
235 (define-key gnus-summary-low-fol-map "F" 'gnus-summary-lower-followups-to-author)
236 (define-key gnus-summary-low-fol-map "t" 'gnus-summary-lower-followups-to-author)
237 (define-key gnus-summary-low-fol-map "p" 'gnus-summary-lower-followups-to-author)
240 ;; Summary score file commands
242 ;; Much modification of the kill (ahem, score) code and lots of the
243 ;; functions are written by Per Abrahamsen <amanda@iesd.auc.dk>.
245 (defun gnus-summary-header (header)
246 ;; Return HEADER for current articles, or error.
247 (let ((article (gnus-summary-article-number)))
249 (aref (gnus-get-header-by-number article)
250 (nth 1 (assoc header gnus-header-index)))
251 (error "No article on current line"))))
253 (defun gnus-summary-score-entry
254 (header match type score date &optional prompt silent)
255 "Enter score file entry.
256 HEADER is the header being scored.
257 MATCH is the string we are looking for.
258 TYPE is a flag indicating if it is a regexp or substring.
259 SCORE is the score to add.
260 DATE is the expire date."
262 (list (completing-read "Header: "
264 (lambda (x) (fboundp (nth 2 x)))
266 (read-string "Match: ")
267 (y-or-n-p "Use regexp match? ")
268 (prefix-numeric-value current-prefix-arg)
269 (if (y-or-n-p "Expire kill? ")
270 (current-time-string)
272 (let ((score (gnus-score-default score))
273 (header (downcase header)))
274 (and prompt (setq match (read-string
275 (format "Match %s on %s, %s: "
276 (if date "temp" "permanent")
278 (if (< score 0) "lower" "raise"))
280 (and (>= (nth 1 (assoc header gnus-header-index)) 0)
282 (gnus-summary-score-effect header match type score))
283 (and (= score gnus-score-interactive-default-score)
285 (let ((new (cond (type
286 (list match score (and date (gnus-day-number date)) type))
288 (list match score (gnus-day-number date)))
293 (old (gnus-score-get header))
295 ;; We see whether we can collapse some score entries.
296 ;; This isn't quite correct, because there may be more elements
297 ;; later on with the same key that have matching elems... Hm.
299 (setq elem (assoc match old))
300 (eq (nth 3 elem) (nth 3 new))
301 (or (and (numberp (nth 2 elem)) (numberp (nth 2 new)))
302 (and (not (nth 2 elem)) (not (nth 2 new)))))
303 ;; Yup, we just add this new score to the old elem.
304 (setcar (cdr elem) (+ (or (nth 1 elem)
305 gnus-score-interactive-default-score)
307 gnus-score-interactive-default-score)))
308 ;; Nope, we have to add a new elem.
309 (gnus-score-set header (if old (cons new old) (list new)))))
310 (gnus-score-set 'touched '(t))))
312 (defun gnus-summary-score-effect (header match type score)
313 "Simulate the effect of a score file entry.
314 HEADER is the header being scored.
315 MATCH is the string we are looking for.
316 TYPE is a flag indicating if it is a regexp or substring.
317 SCORE is the score to add."
318 (interactive (list (completing-read "Header: "
320 (lambda (x) (fboundp (nth 2 x)))
322 (read-string "Match: ")
323 (y-or-n-p "Use regexp match? ")
324 (prefix-numeric-value current-prefix-arg)))
326 (or (and (stringp match) (> (length match) 0))
328 (goto-char (point-min))
329 (let ((regexp (if type
331 (concat "\\`.*" (regexp-quote match) ".*\\'"))))
333 (let ((content (gnus-summary-header header))
334 (case-fold-search t))
336 (if (string-match regexp content)
337 (gnus-summary-raise-score score))))
338 (beginning-of-line 2)))))
340 (defun gnus-summary-score-crossposting (score date)
341 ;; Enter score file entry for current crossposting.
342 ;; SCORE is the score to add.
343 ;; DATE is the expire date.
344 (let ((xref (gnus-summary-header "xref"))
347 (or xref (error "This article is not crossposted"))
348 (while (string-match " \\([^ \t]+\\):" xref start)
349 (setq start (match-end 0))
352 (substring xref (match-beginning 1) (match-end 1)))
353 gnus-newsgroup-name))
354 (gnus-summary-score-entry
355 "xref" (concat " " group ":") nil score date t)))))
357 (defun gnus-summary-temporarily-lower-by-subject (level)
358 "Temporarily lower score by LEVEL for current subject.
359 See `gnus-score-expiry-days'."
361 (gnus-summary-score-entry
362 "subject" (gnus-simplify-subject-re (gnus-summary-header "subject"))
363 nil (- (gnus-score-default level))
364 (current-time-string) t))
366 (defun gnus-summary-temporarily-lower-by-author (level)
367 "Temporarily lower score by LEVEL for current author.
368 See `gnus-score-expiry-days'."
370 (gnus-summary-score-entry
371 "from" (gnus-summary-header "from") nil (- (gnus-score-default level))
372 (current-time-string) t))
374 (defun gnus-summary-temporarily-lower-by-body (level)
375 "Temporarily lower score by LEVEL for a match on the body of the article.
376 See `gnus-score-expiry-days'."
378 (gnus-summary-score-entry
379 "body" "" nil (- (gnus-score-default level)) (current-time-string) t))
381 (defun gnus-summary-temporarily-lower-by-id (level)
382 "Temporarily lower score by LEVEL for current message-id.
383 See `gnus-score-expiry-days'."
385 (gnus-summary-score-entry
386 "message-id" (gnus-summary-header "message-id")
387 nil (- (gnus-score-default level))
388 (current-time-string)))
390 (defun gnus-summary-temporarily-lower-by-xref (level)
391 "Temporarily lower score by LEVEL for current xref.
392 See `gnus-score-expiry-days'."
394 (gnus-summary-score-crossposting
395 (- (gnus-score-default level)) (current-time-string)))
397 (defun gnus-summary-temporarily-lower-by-thread (level)
398 "Temporarily lower score by LEVEL for current thread.
399 See `gnus-score-expiry-days'."
401 (gnus-summary-score-entry
402 "references" (gnus-summary-header "message-id")
403 nil (- (gnus-score-default level)) (current-time-string)))
405 (defun gnus-summary-lower-by-subject (level)
406 "Lower score by LEVEL for current subject."
408 (gnus-summary-score-entry
409 "subject" (gnus-simplify-subject-re (gnus-summary-header "subject"))
410 nil (- (gnus-score-default level))
413 (defun gnus-summary-lower-by-author (level)
414 "Lower score by LEVEL for current author."
416 (gnus-summary-score-entry
417 "from" (gnus-summary-header "from") nil
418 (- (gnus-score-default level)) nil t))
420 (defun gnus-summary-lower-by-body (level)
421 "Lower score by LEVEL for a match on the body of the article."
423 (gnus-summary-score-entry
424 "body" "" nil (- (gnus-score-default level)) nil t))
426 (defun gnus-summary-lower-by-id (level)
427 "Lower score by LEVEL for current message-id."
429 (gnus-summary-score-entry
430 "message-id" (gnus-summary-header "message-id") nil
431 (- (gnus-score-default level)) nil))
433 (defun gnus-summary-lower-by-xref (level)
434 "Lower score by LEVEL for current xref."
436 (gnus-summary-score-crossposting (- (gnus-score-default level)) nil))
438 (defun gnus-summary-lower-followups-to-author (level)
439 "Lower score by LEVEL for all followups to the current author."
441 (gnus-summary-score-entry
442 "followup" (gnus-summary-header "from")
443 nil (gnus-score-default level) (current-time-string) t t))
445 (defun gnus-summary-temporarily-raise-by-subject (level)
446 "Temporarily raise score by LEVEL for current subject.
447 See `gnus-score-expiry-days'."
449 (gnus-summary-score-entry
450 "subject" (gnus-simplify-subject-re (gnus-summary-header "subject"))
451 nil level (current-time-string) t))
453 (defun gnus-summary-temporarily-raise-by-author (level)
454 "Temporarily raise score by LEVEL for current author.
455 See `gnus-score-expiry-days'."
457 (gnus-summary-score-entry
458 "from" (gnus-summary-header "from") nil level (current-time-string) t))
460 (defun gnus-summary-temporarily-raise-by-body (level)
461 "Temporarily raise score by LEVEL for a match on the body of the article.
462 See `gnus-score-expiry-days'."
464 (gnus-summary-score-entry "body" "" nil level (current-time-string) t))
466 (defun gnus-summary-temporarily-raise-by-id (level)
467 "Temporarily raise score by LEVEL for current message-id.
468 See `gnus-score-expiry-days'."
470 (gnus-summary-score-entry
471 "message-id" (gnus-summary-header "message-id")
472 nil level (current-time-string)))
474 (defun gnus-summary-temporarily-raise-by-xref (level)
475 "Temporarily raise score by LEVEL for current xref.
476 See `gnus-score-expiry-days'."
478 (gnus-summary-score-crossposting level (current-time-string)))
480 (defun gnus-summary-temporarily-raise-by-thread (level)
481 "Temporarily raise score by LEVEL for current thread.
482 See `gnus-score-expiry-days'."
484 (gnus-summary-score-entry
485 "references" (gnus-summary-header "message-id")
486 nil level (current-time-string)))
488 (defun gnus-summary-raise-by-subject (level)
489 "Raise score by LEVEL for current subject."
491 (gnus-summary-score-entry
492 "subject" (gnus-simplify-subject-re (gnus-summary-header "subject"))
495 (defun gnus-summary-raise-by-author (level)
496 "Raise score by LEVEL for current author."
498 (gnus-summary-score-entry
499 "from" (gnus-summary-header "from") nil level nil t))
501 (defun gnus-summary-raise-by-body (level)
502 "Raise score by LEVEL for a match on the body of the article."
504 (gnus-summary-score-entry "body" "" nil level nil t))
506 (defun gnus-summary-raise-by-id (level)
507 "Raise score by LEVEL for current message-id."
509 (gnus-summary-score-entry
510 "message-id" (gnus-summary-header "message-id") nil level nil))
512 (defun gnus-summary-raise-by-xref (level)
513 "Raise score by LEVEL for current xref."
515 (gnus-summary-score-crossposting level nil))
517 (defun gnus-summary-raise-followups-to-author (level)
518 "Raise score by LEVEL for all followups to the current author."
520 (gnus-summary-score-entry
521 "followup" (gnus-summary-header "from")
522 nil (gnus-score-default level) (current-time-string) t t))
530 ;; All score code written by Per Abrahamsen <abraham@iesd.auc.dk>.
532 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
533 (defun gnus-score-set-mark-below (score)
534 "Automatically mark articles with score below SCORE as read."
536 (list (or (and current-prefix-arg (prefix-numeric-value current-prefix-arg))
537 (string-to-int (read-string "Mark below: ")))))
538 (setq score (or score gnus-summary-default-score 0))
539 (gnus-score-set 'mark (list score))
540 (gnus-score-set 'touched '(t))
541 (setq gnus-summary-mark-below score)
542 (gnus-summary-update-lines))
544 (defun gnus-score-set-expunge-below (score)
545 "Automatically expunge articles with score below SCORE."
547 (list (or (and current-prefix-arg (prefix-numeric-value current-prefix-arg))
548 (string-to-int (read-string "Expunge below: ")))))
549 (setq score (or score gnus-summary-default-score 0))
550 (gnus-score-set 'expunge (list score))
551 (gnus-score-set 'touched '(t)))
553 (defun gnus-score-set (symbol value &optional alist)
554 ;; Set SYMBOL to VALUE in ALIST.
559 (gnus-score-load (gnus-score-file-name gnus-newsgroup-name))
561 (entry (assoc symbol alist)))
562 (cond ((gnus-score-get 'read-only alist)
563 ;; This is a read-only score file, so we do nothing.
566 (setcdr entry value))
568 (error "Empty alist"))
571 (cons (cons symbol value) (cdr alist)))))))
573 (defun gnus-score-get (symbol &optional alist)
574 ;; Get SYMBOL's definition in ALIST.
580 (gnus-score-file-name gnus-newsgroup-name))
581 gnus-score-alist)))))
583 (defun gnus-score-change-score-file (file)
584 "Change current score alist."
586 (list (completing-read "Score file: " gnus-score-cache)))
587 (setq gnus-current-score-file file)
588 (gnus-score-load-file file)
589 (gnus-set-mode-line 'summary))
591 (defun gnus-score-edit-alist (file)
592 "Edit the current score alist."
593 (interactive (list gnus-current-score-file))
594 (and (buffer-name gnus-summary-buffer) (gnus-score-save))
595 (setq gnus-winconf-edit-score (current-window-configuration))
596 (gnus-configure-windows 'article)
597 (pop-to-buffer (find-file-noselect file))
598 (message (substitute-command-keys
599 "\\<gnus-score-mode-map>\\[gnus-score-edit-done] to save edits"))
602 (defun gnus-score-edit-file (file)
605 (list (read-file-name "Edit score file: " gnus-kill-files-directory)))
606 (and (buffer-name gnus-summary-buffer) (gnus-score-save))
607 (setq gnus-winconf-edit-score (current-window-configuration))
608 (gnus-configure-windows 'article)
609 (pop-to-buffer (find-file-noselect file))
610 (message (substitute-command-keys
611 "\\<gnus-score-mode-map>\\[gnus-score-edit-done] to save edits"))
614 (defun gnus-score-load-file (file)
615 ;; Load score file FILE. Returns a list a retrieved score-alists.
616 (setq gnus-kill-files-directory (or gnus-kill-files-directory "~/News/"))
617 (let* ((file (expand-file-name
618 (or (and (string-match
619 (concat "^" (expand-file-name
620 gnus-kill-files-directory))
621 (expand-file-name file))
623 (concat gnus-kill-files-directory file))))
624 (cached (assoc file gnus-score-cache))
625 (global (member file gnus-internal-global-score-files))
628 ;; The score file was already loaded.
629 (setq alist (cdr cached))
630 ;; We load the score file.
631 (setq gnus-score-alist nil)
632 (setq alist (gnus-score-load-score-alist file))
633 ;; We add '(touched) to the alist to signify that it hasn't been
635 (or (assq 'touched alist) (setq alist (cons (list 'touched nil) alist)))
636 ;; If it is a global score file, we make it read-only.
638 (not (assq 'read-only alist))
639 (setq alist (cons (list 'read-only t) alist)))
641 (setq gnus-score-cache
642 (cons (cons file alist) gnus-score-cache)))
643 ;; If there are actual scores in the alist, we add it to the
644 ;; return value of this function.
645 (if (memq t (mapcar (lambda (e) (stringp (car e))) alist))
646 (setq lists (list alist)))
647 ;; Treat the other possible atoms in the score alist.
648 (let ((mark (car (gnus-score-get 'mark alist)))
649 (expunge (car (gnus-score-get 'expunge alist)))
651 (car (gnus-score-get 'mark-and-expunge alist)))
652 (read-only (gnus-score-get 'read-only alist))
653 (files (gnus-score-get 'files alist))
654 (exclude-files (gnus-score-get 'exclude-files alist))
655 (orphan (car (gnus-score-get 'orphan alist)))
656 (adapt (gnus-score-get 'adapt alist))
657 (eval (gnus-score-get 'eval alist)))
658 ;; We do not respect eval and files atoms from global score
660 (and files (not global)
661 (setq lists (apply 'append lists
662 (mapcar (lambda (file)
663 (gnus-score-load-file file))
665 (and eval (not global) (eval eval))
666 (setq gnus-scores-exclude-files exclude-files)
667 (if orphan (setq gnus-orphan-score (car orphan)))
668 (setq gnus-adaptive-score-alist
669 (cond ((equal adapt '(t))
670 gnus-default-adaptive-score-alist)
671 ((equal adapt '(ignore))
676 gnus-default-adaptive-score-alist)))
677 (setq gnus-summary-mark-below
678 (or mark mark-and-expunge gnus-summary-mark-below))
679 (setq gnus-summary-expunge-below
680 (or expunge mark-and-expunge gnus-summary-expunge-below)))
681 (setq gnus-current-score-file file)
682 (setq gnus-score-alist alist)
685 (defun gnus-score-load (file)
687 (let ((cache (assoc file gnus-score-cache)))
689 (setq gnus-score-alist (cdr cache))
690 (setq gnus-score-alist nil)
691 (gnus-score-load-score-alist file)
693 (setq gnus-score-alist (copy-alist '((touched nil)))))
694 (setq gnus-score-cache
695 (cons (cons file gnus-score-alist) gnus-score-cache)))))
697 (defun gnus-score-remove-from-cache (file)
698 (setq gnus-score-cache
699 (delq (assoc file gnus-score-cache) gnus-score-cache)))
701 (defun gnus-score-load-score-alist (file)
703 (if (file-readable-p file)
706 (gnus-set-work-buffer)
707 (insert-file-contents file)
708 (goto-char (point-min))
709 ;; Only do the loading if the score file isn't empty.
710 (if (save-excursion (re-search-forward "[()0-9a-zA-Z]" nil t))
713 (read (current-buffer))
716 (message "Problem with score file %s" file)
720 (if (eq (car alist) 'setq)
721 (setq gnus-score-alist (gnus-score-transform-old-to-new alist))
722 (setq gnus-score-alist alist))
723 (setq gnus-score-alist
724 (gnus-score-check-syntax gnus-score-alist file)))
725 (setq gnus-score-alist nil))))
727 (defun gnus-score-check-syntax (alist file)
732 (message "Score file is not a list: %s" file)
738 (while (and a (not err))
739 (cond ((not (listp (car a)))
740 (message "Illegal score element %s in %s" (car a) file)
742 ((and (stringp (car (car a)))
743 (not (listp (nth 1 (car a)))))
744 (message "Illegal header match %s in %s" (nth 1 (car a)) file)
754 (defun gnus-score-transform-old-to-new (alist)
755 (let* ((alist (nth 2 alist))
757 (if (eq (car alist) 'quote)
758 (setq alist (nth 1 alist)))
760 (setq entry (car alist))
761 (if (stringp (car entry))
762 (let ((scor (cdr entry)))
763 (setq out (cons entry out))
766 (list (car (car scor)) (nth 2 (car scor))
767 (and (nth 3 (car scor))
768 (gnus-day-number (nth 3 (car scor))))
769 (if (nth 1 (car scor)) 'r 's)))
770 (setq scor (cdr scor))))
771 (setq out (cons (if (not (listp (cdr entry)))
772 (list (car entry) (cdr entry))
775 (setq alist (cdr alist)))
776 (cons (list 'touched t) (nreverse out))))
778 (defun gnus-score-save ()
779 ;; Save all SCORE information.
780 (let ((cache gnus-score-cache))
782 (setq gnus-score-alist nil)
783 (set-buffer (get-buffer-create "*Score*"))
784 (buffer-disable-undo (current-buffer))
785 (let (entry score file)
787 (setq entry (car cache)
791 (if (or (not (equal (gnus-score-get 'touched score) '(t)))
792 (gnus-score-get 'read-only score)
793 (not (file-writable-p file)))
795 (setq score (setcdr entry (delq (assq 'touched score) score)))
797 (let (emacs-lisp-mode-hook)
798 (pp score (current-buffer)))
799 (gnus-make-directory (file-name-directory file))
800 (write-region (point-min) (point-max) file nil 'silent))))
801 (kill-buffer (current-buffer)))))
803 (defun gnus-score-headers (score-files)
804 ;; Score `gnus-newsgroup-headers'.
806 ;; PLM: probably this is not the best place to clear orphan-score
807 (setq gnus-orphan-score nil)
808 ;; Load the SCORE files.
810 (if (stringp (car score-files))
811 ;; It is a string, which means that it's a score file name,
812 ;; so we load the score file and add the score alist to
813 ;; the list of alists.
814 (setq scores (nconc (gnus-score-load-file (car score-files)) scores))
815 ;; It is an alist, so we just add it to the list directly.
816 (setq scores (nconc (car score-files) scores)))
817 (setq score-files (cdr score-files)))
818 ;; Prune the score files that are to be excluded, if any.
819 (if (not gnus-scores-exclude-files)
824 (and (setq c (rassq (car s) gnus-score-cache))
825 (member (car c) gnus-scores-exclude-files)
826 (setq scores (delq (car s) scores)))
828 (if (not (and gnus-summary-default-score
830 (> (length gnus-newsgroup-headers)
831 (length gnus-newsgroup-scored))))
833 (let* ((entries gnus-header-index)
834 (now (gnus-day-number (current-time-string)))
835 (expire (- now gnus-score-expiry-days))
836 (headers gnus-newsgroup-headers)
838 (message "Scoring...")
839 ;; Create articles, an alist of the form `(HEADER . SCORE)'.
841 (setq header (car headers)
842 headers (cdr headers))
843 ;; WARNING: The assq makes the function O(N*S) while it could
844 ;; be written as O(N+S), where N is (length gnus-newsgroup-headers)
845 ;; and S is (length gnus-newsgroup-scored).
846 (or (assq (header-number header) gnus-newsgroup-scored)
847 (setq gnus-scores-articles ;Total of 2 * N cons-cells used.
848 (cons (cons header (or gnus-summary-default-score 0))
849 gnus-scores-articles))))
852 (set-buffer (get-buffer-create "*Headers*"))
853 (buffer-disable-undo (current-buffer))
855 (if gnus-orphan-score
857 (setq gnus-score-index
858 (nth 1 (assoc "references" gnus-header-index)))
859 (gnus-score-orphans gnus-orphan-score)))
860 ;; Run each header through the score process.
862 (setq entry (car entries)
864 entries (cdr entries))
865 (setq gnus-score-index (nth 1 (assoc header gnus-header-index)))
866 (if (< 0 (apply 'max (mapcar
868 (length (gnus-score-get header score)))
870 (funcall (nth 2 entry) scores header now expire)))
871 ;; Remove the buffer.
872 (kill-buffer (current-buffer)))
874 ;; Add articles to `gnus-newsgroup-scored'.
875 (while gnus-scores-articles
876 (or (= gnus-summary-default-score (cdr (car gnus-scores-articles)))
877 (setq gnus-newsgroup-scored
878 (cons (cons (header-number
879 (car (car gnus-scores-articles)))
880 (cdr (car gnus-scores-articles)))
881 gnus-newsgroup-scored)))
882 (setq gnus-scores-articles (cdr gnus-scores-articles)))
884 (message "Scoring...done")))))
887 (defun gnus-get-new-thread-ids (articles)
888 (let ((index (nth 1 (assoc "message-id" gnus-header-index)))
889 (refind gnus-score-index)
890 id-list art this tref)
892 (setq art (car articles)
893 this (aref (car art) index)
894 tref (aref (car art) refind)
895 articles (cdr articles))
896 (if (string-equal tref "") ;no references line
897 (setq id-list (cons this id-list))))
900 ;; Orphan functions written by plm@atcmp.nl (Peter Mutsaers).
901 (defun gnus-score-orphans (score)
902 (let ((new-thread-ids (gnus-get-new-thread-ids gnus-scores-articles))
903 (index (nth 1 (assoc "references" gnus-header-index)))
904 alike articles art arts this last this-id)
906 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<)
907 articles gnus-scores-articles)
909 ;;more or less the same as in gnus-score-string
912 (setq art (car articles)
913 this (aref (car art) gnus-score-index)
914 articles (cdr articles))
915 ;;completely skip if this is empty (not a child, so not an orphan)
916 (if (not (string= this ""))
917 (if (equal last this)
918 ;; O(N*H) cons-cells used here, where H is the number of
920 (setq alike (cons art alike))
923 ;; Insert the line, with a text property on the
924 ;; terminating newline refering to the articles with
927 (put-text-property (1- (point)) (point) 'articles alike)))
928 (setq alike (list art)
930 (and last ; Bwadr, duplicate code.
933 (put-text-property (1- (point)) (point) 'articles alike)))
935 ;; PLM: now delete those lines that contain an entry from new-thread-ids
936 (while new-thread-ids
937 (setq this-id (car new-thread-ids)
938 new-thread-ids (cdr new-thread-ids))
939 (goto-char (point-min))
940 (while (search-forward this-id nil t)
941 ;; found a match. remove this line
945 ;; now for each line: update its articles with score by moving to
946 ;; every end-of-line in the buffer and read the articles property
947 (goto-char (point-min))
950 (setq arts (get-text-property (point) 'articles))
954 (setcdr art (+ score (cdr art))))
958 (defun gnus-score-integer (scores header now expire)
959 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
960 alike last this art entries alist articles)
964 (setq alist (car scores)
966 entries (assoc header alist))
967 (while (cdr entries) ;First entry is the header index.
968 (let* ((rest (cdr entries))
971 (type (or (nth 3 kill) '>))
972 (score (or (nth 1 kill) gnus-score-interactive-default-score))
975 (match-func (if (or (eq type '>) (eq type '<) (eq type '<=)
976 (eq type '>=) (eq type '=))
978 (error "Illegal match type: %s" type)))
979 (articles gnus-scores-articles)
981 ;; Instead of doing all the clever stuff that
982 ;; `gnus-score-string' does to minimize searches and stuff,
983 ;; I will assume that people generally will put so few
984 ;; matches on numbers that any cleverness will take more
985 ;; time than one would gain.
987 (and (funcall match-func match
988 (or (aref (car (car articles)) gnus-score-index) 0))
991 (setcdr (car articles) (+ score (cdr (car articles))))))
992 (setq articles (cdr articles)))
993 ;; Update expire date
994 (cond ((null date)) ;Permanent entry.
995 (found ;Match, update date.
996 (gnus-score-set 'touched '(t) alist)
997 (setcar (nthcdr 2 kill) now))
998 ((< date expire) ;Old entry, remove.
999 (gnus-score-set 'touched '(t) alist)
1000 (setcdr entries (cdr rest))
1001 (setq rest entries)))
1002 (setq entries rest))))))
1004 (defun gnus-score-date (scores header now expire)
1005 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
1006 alike last this art entries alist articles)
1010 (setq alist (car scores)
1012 entries (assoc header alist))
1013 (while (cdr entries) ;First entry is the header index.
1014 (let* ((rest (cdr entries))
1016 (match (timezone-make-date-sortable (nth 0 kill)))
1017 (type (or (nth 3 kill) 'before))
1018 (score (or (nth 1 kill) gnus-score-interactive-default-score))
1022 (cond ((eq type 'after) 'string<)
1023 ((eq type 'before) 'gnus-string>)
1024 ((eq type 'at) 'string=)
1025 (t (error "Illegal match type: %s" type))))
1026 (articles gnus-scores-articles)
1028 ;; Instead of doing all the clever stuff that
1029 ;; `gnus-score-string' does to minimize searches and stuff,
1030 ;; I will assume that people generally will put so few
1031 ;; matches on numbers that any cleverness will take more
1032 ;; time than one would gain.
1035 (setq l (aref (car (car articles)) gnus-score-index))
1036 (funcall match-func match (timezone-make-date-sortable l))
1039 (setcdr (car articles) (+ score (cdr (car articles))))))
1040 (setq articles (cdr articles)))
1041 ;; Update expire date
1042 (cond ((null date)) ;Permanent entry.
1043 (found ;Match, update date.
1044 (gnus-score-set 'touched '(t) alist)
1045 (setcar (nthcdr 2 kill) now))
1046 ((< date expire) ;Old entry, remove.
1047 (gnus-score-set 'touched '(t) alist)
1048 (setcdr entries (cdr rest))
1049 (setq rest entries)))
1050 (setq entries rest))))))
1052 (defun gnus-score-body (scores header now expire)
1054 (set-buffer nntp-server-buffer)
1056 (let* ((buffer-read-only nil)
1057 (articles gnus-scores-articles)
1059 (request-func (cond ((string= "head" (downcase header))
1061 ((string= "body" (downcase header))
1063 (t 'gnus-request-article)))
1064 alike last this art entries alist ofunc article)
1065 ;; Not all backends support partial fetching. In that case,
1066 ;; we just fetch the entire article.
1067 (or (gnus-check-backend-function request-func gnus-newsgroup-name)
1069 (setq ofunc request-func)
1070 (setq request-func 'gnus-request-article)))
1072 (setq article (header-number (car (car articles))))
1073 (message "Scoring on article %s..." article)
1074 (if (not (funcall request-func article gnus-newsgroup-name))
1077 (goto-char (point-min))
1078 ;; If just parts of the article is to be searched, but the
1079 ;; backend didn't support partial fetching, we just narrow
1080 ;; to the relevant parts.
1082 (if (eq ofunc 'gnus-request-head)
1085 (or (search-forward "\n\n" nil t) (point-max)))
1087 (or (search-forward "\n\n" nil t) (point))
1089 (setq scores all-scores)
1092 (setq alist (car scores)
1094 entries (assoc header alist))
1095 (while (cdr entries) ;First entry is the header index.
1096 (let* ((rest (cdr entries))
1098 (match (nth 0 kill))
1099 (type (or (nth 3 kill) 's))
1100 (score (or (nth 1 kill)
1101 gnus-score-interactive-default-score))
1105 (not (or (eq type 'R) (eq type 'S)
1106 (eq type 'Regexp) (eq type 'String))))
1108 (cond ((or (eq type 'r) (eq type 'R)
1109 (eq type 'regexp) (eq type 'Regexp))
1111 ((or (eq type 's) (eq type 'S)
1112 (eq type 'string) (eq type 'String))
1115 (error "Illegal match type: %s" type))))
1117 (goto-char (point-min))
1118 (if (funcall search-func match nil t)
1119 ;; Found a match, update scores.
1121 (setcdr (car articles) (+ score (cdr (car articles))))
1123 ;; Update expire date
1124 (cond ((null date)) ;Permanent entry.
1125 (found ;Match, update date.
1126 (gnus-score-set 'touched '(t) alist)
1127 (setcar (nthcdr 2 kill) now))
1128 ((< date expire) ;Old entry, remove.
1129 (gnus-score-set 'touched '(t) alist)
1130 (setcdr entries (cdr rest))
1131 (setq rest entries)))
1132 (setq entries rest)))))
1133 (setq articles (cdr articles)))))))
1137 (defun gnus-score-followup (scores header now expire)
1138 ;; Insert the unique article headers in the buffer.
1139 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
1140 ;; gnus-score-index is used as a free variable.
1141 alike last this art entries alist articles)
1143 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<)
1144 articles gnus-scores-articles)
1148 (setq art (car articles)
1149 this (aref (car art) gnus-score-index)
1150 articles (cdr articles))
1151 (if (equal last this)
1152 (setq alike (cons art alike))
1156 (put-text-property (1- (point)) (point) 'articles alike)))
1157 (setq alike (list art)
1159 (and last ; Bwadr, duplicate code.
1162 (put-text-property (1- (point)) (point) 'articles alike)))
1166 (setq alist (car scores)
1168 entries (assoc header alist))
1169 (while (cdr entries) ;First entry is the header index.
1170 (let* ((rest (cdr entries))
1172 (match (nth 0 kill))
1173 (type (or (nth 3 kill) 's))
1174 (score (or (nth 1 kill) gnus-score-interactive-default-score))
1177 (mt (aref (symbol-name type) 0))
1179 (not (or (= mt ?R) (= mt ?S) (= mt ?E) (= mt ?F))))
1182 (cond ((= dmt ?r) 're-search-forward)
1183 ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward)
1184 (t (error "Illegal match type: %s" type))))
1186 (goto-char (point-min))
1188 (while (funcall search-func match nil t)
1189 (and (= (progn (beginning-of-line) (point))
1190 (match-beginning 0))
1191 (= (progn (end-of-line) (point))
1194 (setq found (setq arts (get-text-property
1195 (point) 'articles)))
1196 ;; Found a match, update scores.
1198 (setq art (car arts)
1200 (gnus-score-add-followups (car art) score)))))
1201 (while (funcall search-func match nil t)
1203 (setq found (setq arts (get-text-property (point) 'articles)))
1204 ;; Found a match, update scores.
1206 (setq art (car arts)
1208 (gnus-score-add-followups (car art) score))))
1209 ;; Update expire date
1210 (cond ((null date)) ;Permanent entry.
1211 (found ;Match, update date.
1212 (gnus-score-set 'touched '(t) alist)
1213 (setcar (nthcdr 2 kill) now))
1214 ((< date expire) ;Old entry, remove.
1215 (gnus-score-set 'touched '(t) alist)
1216 (setcdr entries (cdr rest))
1217 (setq rest entries)))
1218 (setq entries rest))))))
1220 (defun gnus-score-add-followups (header score)
1222 (set-buffer gnus-summary-buffer)
1223 (gnus-summary-score-entry
1224 "references" (header-id header) 's score
1225 (current-time-string) nil t)))
1228 (defun gnus-score-string (scores header now expire)
1229 ;; Score ARTICLES according to HEADER in SCORES.
1230 ;; Update matches entries to NOW and remove unmatched entried older
1233 ;; Insert the unique article headers in the buffer.
1234 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
1235 ;; gnus-score-index is used as a free variable.
1236 alike last this art entries alist articles)
1238 ;; Sorting the articles costs os O(N*log N) but will allow us to
1239 ;; only match with each unique header. Thus the actual matching
1240 ;; will be O(M*U) where M is the number of strings to match with,
1241 ;; and U is the number of unique headers. It is assumed (but
1242 ;; untested) this will be a net win because of the large constant
1243 ;; factor involved with string matching.
1244 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<)
1245 articles gnus-scores-articles)
1249 (setq art (car articles)
1250 this (aref (car art) gnus-score-index)
1251 articles (cdr articles))
1252 (if (equal last this)
1253 ;; O(N*H) cons-cells used here, where H is the number of
1255 (setq alike (cons art alike))
1258 ;; Insert the line, with a text property on the
1259 ;; terminating newline refering to the articles with
1262 (put-text-property (1- (point)) (point) 'articles alike)))
1263 (setq alike (list art)
1265 (and last ; Bwadr, duplicate code.
1268 (put-text-property (1- (point)) (point) 'articles alike)))
1272 (setq alist (car scores)
1274 entries (assoc header alist))
1275 (while (cdr entries) ;First entry is the header index.
1276 (let* ((rest (cdr entries))
1278 (match (nth 0 kill))
1279 (type (or (nth 3 kill) 's))
1280 (score (or (nth 1 kill) gnus-score-interactive-default-score))
1283 (mt (aref (symbol-name type) 0))
1285 (not (or (= mt ?R) (= mt ?S) (= mt ?E) (= mt ?F))))
1288 (cond ((= dmt ?r) 're-search-forward)
1289 ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward)
1290 (t (error "Illegal match type: %s" type))))
1292 (goto-char (point-min))
1294 (while (and (not (eobp))
1295 (funcall search-func match nil t))
1296 (and (= (progn (beginning-of-line) (point))
1297 (match-beginning 0))
1298 (= (progn (end-of-line) (point))
1301 (setq found (setq arts (get-text-property
1302 (point) 'articles)))
1303 ;; Found a match, update scores.
1305 (setq art (car arts)
1307 (setcdr art (+ score (cdr art))))))
1309 (and (string= match "") (setq match "\n"))
1310 (while (funcall search-func match nil t)
1312 (setq found (setq arts (get-text-property (point) 'articles)))
1313 ;; Found a match, update scores.
1315 (setq art (car arts)
1317 (setcdr art (+ score (cdr art))))))
1318 ;; Update expire date
1319 (cond ((null date)) ;Permanent entry.
1320 (found ;Match, update date.
1321 (gnus-score-set 'touched '(t) alist)
1322 (setcar (nthcdr 2 kill) now))
1323 ((< date expire) ;Old entry, remove.
1324 (gnus-score-set 'touched '(t) alist)
1325 (setcdr entries (cdr rest))
1326 (setq rest entries)))
1327 (setq entries rest))))))
1329 (defun gnus-score-string< (a1 a2)
1330 ;; Compare headers in articles A2 and A2.
1331 ;; The header index used is the free variable `gnus-score-index'.
1332 (string-lessp (aref (car a1) gnus-score-index)
1333 (aref (car a2) gnus-score-index)))
1335 (defun gnus-score-build-cons (article)
1336 ;; Build a `gnus-newsgroup-scored' type cons from ARTICLE.
1337 (cons (header-number (car article)) (cdr article)))
1339 (defconst gnus-header-index
1340 ;; Name to index alist.
1341 '(("number" 0 gnus-score-integer)
1342 ("subject" 1 gnus-score-string)
1343 ("from" 2 gnus-score-string)
1344 ("date" 3 gnus-score-date)
1345 ("message-id" 4 gnus-score-string)
1346 ("references" 5 gnus-score-string)
1347 ("chars" 6 gnus-score-integer)
1348 ("lines" 7 gnus-score-integer)
1349 ("xref" 8 gnus-score-string)
1350 ("head" -1 gnus-score-body)
1351 ("body" -1 gnus-score-body)
1352 ("all" -1 gnus-score-body)
1353 ("followup" 2 gnus-score-followup)))
1355 (defun gnus-current-score-file-nondirectory (&optional score-file)
1356 (let ((score-file (or score-file gnus-current-score-file)))
1358 (gnus-short-group-name (file-name-nondirectory score-file))
1361 (defun gnus-score-adaptive ()
1363 (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist))
1365 (date (current-time-string))
1367 ;; First we transform the adaptive rule alist into something
1368 ;; that's faster to process.
1370 (setq elem (car malist))
1371 (if (symbolp (car elem))
1372 (setcar elem (symbol-value (car elem))))
1373 (setq elem (cdr elem))
1376 (cons (symbol-name (car (car elem))) (cdr (car elem))))
1379 (concat "gnus-header-"
1380 (downcase (symbol-name (car (car elem)))))))
1381 (setq elem (cdr elem)))
1382 (setq malist (cdr malist)))
1383 ;; The we score away.
1384 (goto-char (point-min))
1386 (setq elem (cdr (assq (gnus-summary-article-mark) alist)))
1389 (setq headers (gnus-get-header-by-number
1390 (gnus-summary-article-number)))
1392 (gnus-summary-score-entry
1393 (nth 1 (car elem)) (funcall (car (car elem)) headers)
1394 's (nth 2 (car elem)) date nil t)
1395 (setq elem (cdr elem))))
1396 (forward-line 1)))))
1398 (defun gnus-score-remove-lines-adaptive (marks)
1400 (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist))
1402 (date (current-time-string))
1404 ;; First we transform the adaptive rule alist into something
1405 ;; that's faster to process.
1407 (setq elem (car malist))
1408 (if (symbolp (car elem))
1409 (setcar elem (symbol-value (car elem))))
1410 (setq elem (cdr elem))
1413 (cons (symbol-name (car (car elem))) (cdr (car elem))))
1416 (concat "gnus-header-"
1417 (downcase (symbol-name (car (car elem)))))))
1418 (setq elem (cdr elem)))
1419 (setq malist (cdr malist)))
1420 ;; The we score away.
1421 (goto-char (point-min))
1422 (while (re-search-forward marks nil t)
1424 (setq elem (cdr (assq (gnus-summary-article-mark) alist)))
1427 (setq headers (gnus-get-header-by-number
1428 (gnus-summary-article-number)))
1430 (gnus-summary-score-entry
1431 (nth 1 (car elem)) (funcall (car (car elem)) headers)
1432 'e (nth 2 (car elem)) date nil t)
1433 (setq elem (cdr elem))))
1434 (delete-region (point) (progn (forward-line 1) (point)))))))
1440 (defvar gnus-score-mode-map nil)
1441 (defvar gnus-score-mode-hook nil)
1443 (if gnus-score-mode-map
1445 (setq gnus-score-mode-map (copy-keymap emacs-lisp-mode-map))
1446 (define-key gnus-score-mode-map "\C-c\C-c" 'gnus-score-edit-done)
1447 (define-key gnus-score-mode-map "\C-c\C-d" 'gnus-score-edit-insert-date))
1449 (defun gnus-score-mode ()
1450 "Mode for editing score files.
1451 This mode is an extended emacs-lisp mode.
1453 \\{gnus-score-mode-map}"
1455 (kill-all-local-variables)
1456 (use-local-map gnus-score-mode-map)
1457 (set-syntax-table emacs-lisp-mode-syntax-table)
1458 (setq major-mode 'gnus-score-mode)
1459 (setq mode-name "Score")
1460 (lisp-mode-variables nil)
1461 (run-hooks 'emacs-lisp-mode-hook 'gnus-score-mode-hook))
1463 (defun gnus-score-edit-insert-date ()
1464 "Insert date in numerical format."
1466 (insert (int-to-string (gnus-day-number (current-time-string)))))
1468 (defun gnus-score-edit-done ()
1469 "Save the score file and return to the summary buffer."
1471 (let ((bufnam (buffer-file-name (current-buffer))))
1473 (kill-buffer (current-buffer))
1474 (and gnus-winconf-edit-score
1475 (set-window-configuration gnus-winconf-edit-score))
1476 (gnus-score-remove-from-cache bufnam)
1477 (gnus-score-load-file bufnam)))
1479 (provide 'gnus-score)
1481 ;;; gnus-score.el ends here