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) (+ (nth 1 elem) (nth 1 new)))
305 ;; Nope, we have to add a new elem.
306 (gnus-score-set header (if old (cons new old) (list new)))))
307 (gnus-score-set 'touched '(t))))
309 (defun gnus-summary-score-effect (header match type score)
310 "Simulate the effect of a score file entry.
311 HEADER is the header being scored.
312 MATCH is the string we are looking for.
313 TYPE is a flag indicating if it is a regexp or substring.
314 SCORE is the score to add."
315 (interactive (list (completing-read "Header: "
317 (lambda (x) (fboundp (nth 2 x)))
319 (read-string "Match: ")
320 (y-or-n-p "Use regexp match? ")
321 (prefix-numeric-value current-prefix-arg)))
323 (or (and (stringp match) (> (length match) 0))
325 (goto-char (point-min))
326 (let ((regexp (if type
328 (concat "\\`.*" (regexp-quote match) ".*\\'"))))
330 (let ((content (gnus-summary-header header))
331 (case-fold-search t))
333 (if (string-match regexp content)
334 (gnus-summary-raise-score score))))
335 (beginning-of-line 2)))))
337 (defun gnus-summary-score-crossposting (score date)
338 ;; Enter score file entry for current crossposting.
339 ;; SCORE is the score to add.
340 ;; DATE is the expire date.
341 (let ((xref (gnus-summary-header "xref"))
344 (or xref (error "This article is not crossposted"))
345 (while (string-match " \\([^ \t]+\\):" xref start)
346 (setq start (match-end 0))
349 (substring xref (match-beginning 1) (match-end 1)))
350 gnus-newsgroup-name))
351 (gnus-summary-score-entry
352 "xref" (concat " " group ":") nil score date t)))))
354 (defun gnus-summary-temporarily-lower-by-subject (level)
355 "Temporarily lower score by LEVEL for current subject.
356 See `gnus-score-expiry-days'."
358 (gnus-summary-score-entry
359 "subject" (gnus-simplify-subject-re (gnus-summary-header "subject"))
360 nil (- (gnus-score-default level))
361 (current-time-string) t))
363 (defun gnus-summary-temporarily-lower-by-author (level)
364 "Temporarily lower score by LEVEL for current author.
365 See `gnus-score-expiry-days'."
367 (gnus-summary-score-entry
368 "from" (gnus-summary-header "from") nil (- (gnus-score-default level))
369 (current-time-string) t))
371 (defun gnus-summary-temporarily-lower-by-body (level)
372 "Temporarily lower score by LEVEL for a match on the body of the article.
373 See `gnus-score-expiry-days'."
375 (gnus-summary-score-entry
376 "body" "" nil (- (gnus-score-default level)) (current-time-string) t))
378 (defun gnus-summary-temporarily-lower-by-id (level)
379 "Temporarily lower score by LEVEL for current message-id.
380 See `gnus-score-expiry-days'."
382 (gnus-summary-score-entry
383 "message-id" (gnus-summary-header "message-id")
384 nil (- (gnus-score-default level))
385 (current-time-string)))
387 (defun gnus-summary-temporarily-lower-by-xref (level)
388 "Temporarily lower score by LEVEL for current xref.
389 See `gnus-score-expiry-days'."
391 (gnus-summary-score-crossposting
392 (- (gnus-score-default level)) (current-time-string)))
394 (defun gnus-summary-temporarily-lower-by-thread (level)
395 "Temporarily lower score by LEVEL for current thread.
396 See `gnus-score-expiry-days'."
398 (gnus-summary-score-entry
399 "references" (gnus-summary-header "message-id")
400 nil (- (gnus-score-default level)) (current-time-string)))
402 (defun gnus-summary-lower-by-subject (level)
403 "Lower score by LEVEL for current subject."
405 (gnus-summary-score-entry
406 "subject" (gnus-simplify-subject-re (gnus-summary-header "subject"))
407 nil (- (gnus-score-default level))
410 (defun gnus-summary-lower-by-author (level)
411 "Lower score by LEVEL for current author."
413 (gnus-summary-score-entry
414 "from" (gnus-summary-header "from") nil
415 (- (gnus-score-default level)) nil t))
417 (defun gnus-summary-lower-by-body (level)
418 "Lower score by LEVEL for a match on the body of the article."
420 (gnus-summary-score-entry
421 "body" "" nil (- (gnus-score-default level)) nil t))
423 (defun gnus-summary-lower-by-id (level)
424 "Lower score by LEVEL for current message-id."
426 (gnus-summary-score-entry
427 "message-id" (gnus-summary-header "message-id") nil
428 (- (gnus-score-default level)) nil))
430 (defun gnus-summary-lower-by-xref (level)
431 "Lower score by LEVEL for current xref."
433 (gnus-summary-score-crossposting (- (gnus-score-default level)) nil))
435 (defun gnus-summary-lower-followups-to-author (level)
436 "Lower score by LEVEL for all followups to the current author."
438 (gnus-summary-score-entry "followup" (gnus-summary-header "from")
439 nil level (current-time-string) t t))
441 (defun gnus-summary-temporarily-raise-by-subject (level)
442 "Temporarily raise score by LEVEL for current subject.
443 See `gnus-score-expiry-days'."
445 (gnus-summary-score-entry
446 "subject" (gnus-simplify-subject-re (gnus-summary-header "subject"))
447 nil level (current-time-string) t))
449 (defun gnus-summary-temporarily-raise-by-author (level)
450 "Temporarily raise score by LEVEL for current author.
451 See `gnus-score-expiry-days'."
453 (gnus-summary-score-entry
454 "from" (gnus-summary-header "from") nil level (current-time-string) t))
456 (defun gnus-summary-temporarily-raise-by-body (level)
457 "Temporarily raise score by LEVEL for a match on the body of the article.
458 See `gnus-score-expiry-days'."
460 (gnus-summary-score-entry "body" "" nil level (current-time-string) t))
462 (defun gnus-summary-temporarily-raise-by-id (level)
463 "Temporarily raise score by LEVEL for current message-id.
464 See `gnus-score-expiry-days'."
466 (gnus-summary-score-entry
467 "message-id" (gnus-summary-header "message-id")
468 nil level (current-time-string)))
470 (defun gnus-summary-temporarily-raise-by-xref (level)
471 "Temporarily raise score by LEVEL for current xref.
472 See `gnus-score-expiry-days'."
474 (gnus-summary-score-crossposting level (current-time-string)))
476 (defun gnus-summary-temporarily-raise-by-thread (level)
477 "Temporarily raise score by LEVEL for current thread.
478 See `gnus-score-expiry-days'."
480 (gnus-summary-score-entry
481 "references" (gnus-summary-header "message-id")
482 nil level (current-time-string)))
484 (defun gnus-summary-raise-by-subject (level)
485 "Raise score by LEVEL for current subject."
487 (gnus-summary-score-entry
488 "subject" (gnus-simplify-subject-re (gnus-summary-header "subject"))
491 (defun gnus-summary-raise-by-author (level)
492 "Raise score by LEVEL for current author."
494 (gnus-summary-score-entry
495 "from" (gnus-summary-header "from") nil level nil t))
497 (defun gnus-summary-raise-by-body (level)
498 "Raise score by LEVEL for a match on the body of the article."
500 (gnus-summary-score-entry "body" "" nil level nil t))
502 (defun gnus-summary-raise-by-id (level)
503 "Raise score by LEVEL for current message-id."
505 (gnus-summary-score-entry
506 "message-id" (gnus-summary-header "message-id") nil level nil))
508 (defun gnus-summary-raise-by-xref (level)
509 "Raise score by LEVEL for current xref."
511 (gnus-summary-score-crossposting level nil))
513 (defun gnus-summary-raise-followups-to-author (level)
514 "Raise score by LEVEL for all followups to the current author."
516 (gnus-summary-score-entry "followup" (gnus-summary-header "from")
517 nil level (current-time-string) t t))
525 ;; All score code written by Per Abrahamsen <abraham@iesd.auc.dk>.
527 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
528 (defun gnus-score-set-mark-below (score)
529 "Automatically mark articles with score below SCORE as read."
531 (list (or (and current-prefix-arg (prefix-numeric-value current-prefix-arg))
532 (string-to-int (read-string "Mark below: ")))))
533 (setq score (or score gnus-summary-default-score 0))
534 (gnus-score-set 'mark (list score))
535 (gnus-score-set 'touched '(t))
536 (setq gnus-summary-mark-below score)
537 (gnus-summary-update-lines))
539 (defun gnus-score-set-expunge-below (score)
540 "Automatically expunge articles with score below SCORE."
542 (list (or (and current-prefix-arg (prefix-numeric-value current-prefix-arg))
543 (string-to-int (read-string "Expunge below: ")))))
544 (setq score (or score gnus-summary-default-score 0))
545 (gnus-score-set 'expunge (list score))
546 (gnus-score-set 'touched '(t)))
548 (defun gnus-score-set (symbol value &optional alist)
549 ;; Set SYMBOL to VALUE in ALIST.
554 (gnus-score-load (gnus-score-file-name gnus-newsgroup-name))
556 (entry (assoc symbol alist)))
557 (cond ((gnus-score-get 'read-only alist)
558 ;; This is a read-only score file, so we do nothing.
561 (setcdr entry value))
563 (error "Empty alist"))
566 (cons (cons symbol value) (cdr alist)))))))
568 (defun gnus-score-get (symbol &optional alist)
569 ;; Get SYMBOL's definition in ALIST.
575 (gnus-score-file-name gnus-newsgroup-name))
576 gnus-score-alist)))))
578 (defun gnus-score-change-score-file (file)
579 "Change current score alist."
581 (list (completing-read "Score file: " gnus-score-cache)))
582 (setq gnus-current-score-file file)
583 (gnus-score-load-file file)
584 (gnus-set-mode-line 'summary))
586 (defun gnus-score-edit-alist (file)
587 "Edit the current score alist."
588 (interactive (list gnus-current-score-file))
589 (and (buffer-name gnus-summary-buffer) (gnus-score-save))
590 (setq gnus-winconf-edit-score (current-window-configuration))
591 (gnus-configure-windows 'article)
592 (pop-to-buffer (find-file-noselect file))
593 (message (substitute-command-keys
594 "\\<gnus-score-mode-map>\\[gnus-score-edit-done] to save edits"))
597 (defun gnus-score-edit-file (file)
600 (list (read-file-name "Edit score file: " gnus-kill-files-directory)))
601 (and (buffer-name gnus-summary-buffer) (gnus-score-save))
602 (setq gnus-winconf-edit-score (current-window-configuration))
603 (gnus-configure-windows 'article)
604 (pop-to-buffer (find-file-noselect file))
605 (message (substitute-command-keys
606 "\\<gnus-score-mode-map>\\[gnus-score-edit-done] to save edits"))
609 (defun gnus-score-load-file (file)
610 ;; Load score file FILE. Returns a list a retrieved score-alists.
611 (setq gnus-kill-files-directory (or gnus-kill-files-directory "~/News/"))
612 (let* ((file (expand-file-name
613 (or (and (string-match
614 (concat "^" (expand-file-name
615 gnus-kill-files-directory))
616 (expand-file-name file))
618 (concat gnus-kill-files-directory file))))
619 (cached (assoc file gnus-score-cache))
620 (global (member file gnus-internal-global-score-files))
623 ;; The score file was already loaded.
624 (setq alist (cdr cached))
625 ;; We load the score file.
626 (setq gnus-score-alist nil)
627 (setq alist (gnus-score-load-score-alist file))
628 ;; We add '(touched) to the alist to signify that it hasn't been
630 (or (assq 'touched alist) (setq alist (cons (list 'touched nil) alist)))
631 ;; If it is a global score file, we make it read-only.
633 (not (assq 'read-only alist))
634 (setq alist (cons (list 'read-only t) alist)))
636 (setq gnus-score-cache
637 (cons (cons file alist) gnus-score-cache)))
638 ;; If there are actual scores in the alist, we add it to the
639 ;; return value of this function.
640 (if (memq t (mapcar (lambda (e) (stringp (car e))) alist))
641 (setq lists (list alist)))
642 ;; Treat the other possible atoms in the score alist.
643 (let ((mark (car (gnus-score-get 'mark alist)))
644 (expunge (car (gnus-score-get 'expunge alist)))
646 (car (gnus-score-get 'mark-and-expunge alist)))
647 (read-only (gnus-score-get 'read-only alist))
648 (files (gnus-score-get 'files alist))
649 (exclude-files (gnus-score-get 'exclude-files alist))
650 (orphan (gnus-score-get 'orphan alist))
651 (adapt (gnus-score-get 'adapt alist))
652 (eval (gnus-score-get 'eval alist)))
653 ;; We do not respect eval and files atoms from global score
655 (and files (not global)
656 (setq lists (apply 'append lists
657 (mapcar (lambda (file)
658 (gnus-score-load-file file))
660 (and eval (not global) (eval eval))
661 (setq gnus-scores-exclude-files exclude-files)
662 (if orphan (setq gnus-orphan-score (car orphan)))
663 (setq gnus-adaptive-score-alist
665 gnus-default-adaptive-score-alist)
670 (setq gnus-summary-mark-below
671 (or mark mark-and-expunge gnus-summary-mark-below))
672 (setq gnus-summary-expunge-below
673 (or expunge mark-and-expunge gnus-summary-expunge-below)))
674 (setq gnus-current-score-file file)
675 (setq gnus-score-alist alist)
678 (defun gnus-score-load (file)
680 (let ((cache (assoc file gnus-score-cache)))
682 (setq gnus-score-alist (cdr cache))
683 (setq gnus-score-alist nil)
684 (gnus-score-load-score-alist file)
686 (setq gnus-score-alist (copy-alist '((touched nil)))))
687 (setq gnus-score-cache
688 (cons (cons file gnus-score-alist) gnus-score-cache)))))
690 (defun gnus-score-remove-from-cache (file)
691 (setq gnus-score-cache
692 (delq (assoc file gnus-score-cache) gnus-score-cache)))
694 (defun gnus-score-load-score-alist (file)
696 (if (file-readable-p file)
699 (gnus-set-work-buffer)
700 (insert-file-contents file)
701 (goto-char (point-min))
702 ;; Only do the loading if the score file isn't empty.
703 (if (save-excursion (re-search-forward "[()0-9a-zA-Z]" nil t))
706 (read (current-buffer))
709 (message "Problem with score file %s" file)
713 (if (eq (car alist) 'setq)
714 (setq gnus-score-alist (gnus-score-transform-old-to-new alist))
715 (setq gnus-score-alist alist))
716 (setq gnus-score-alist
717 (gnus-score-check-syntax gnus-score-alist file)))
718 (setq gnus-score-alist nil))))
720 (defun gnus-score-check-syntax (alist file)
725 (message "Score file is not a list: %s" file)
731 (while (and a (not err))
732 (cond ((not (listp (car a)))
733 (message "Illegal score element %s in %s" (car a) file)
735 ((and (stringp (car (car a)))
736 (not (listp (nth 1 (car a)))))
737 (message "Illegal header match %s in %s" (nth 1 (car a)) file)
747 (defun gnus-score-transform-old-to-new (alist)
748 (let* ((alist (nth 2 alist))
750 (if (eq (car alist) 'quote)
751 (setq alist (nth 1 alist)))
753 (setq entry (car alist))
754 (if (stringp (car entry))
755 (let ((scor (cdr entry)))
756 (setq out (cons entry out))
759 (list (car (car scor)) (nth 2 (car scor))
760 (and (nth 3 (car scor))
761 (gnus-day-number (nth 3 (car scor))))
762 (if (nth 1 (car scor)) 'r 's)))
763 (setq scor (cdr scor))))
764 (setq out (cons (if (not (listp (cdr entry)))
765 (list (car entry) (cdr entry))
768 (setq alist (cdr alist)))
769 (cons (list 'touched t) (nreverse out))))
771 (defun gnus-score-save ()
772 ;; Save all SCORE information.
773 (let ((cache gnus-score-cache))
775 (setq gnus-score-alist nil)
776 (set-buffer (get-buffer-create "*Score*"))
777 (buffer-disable-undo (current-buffer))
778 (let (entry score file)
780 (setq entry (car cache)
784 (if (or (not (equal (gnus-score-get 'touched score) '(t)))
785 (gnus-score-get 'read-only score)
786 (not (file-writable-p file)))
788 (setq score (delq (assq 'touched score) score))
790 (let (emacs-lisp-mode-hook)
791 (pp score (current-buffer)))
792 (gnus-make-directory (file-name-directory file))
793 (write-region (point-min) (point-max) file nil 'silent))))
794 (kill-buffer (current-buffer)))))
796 (defun gnus-score-headers (score-files)
797 ;; Score `gnus-newsgroup-headers'.
799 ;; PLM: probably this is not the best place to clear orphan-score
800 (setq gnus-orphan-score nil)
801 ;; Load the SCORE files.
803 (if (stringp (car score-files))
804 ;; It is a string, which means that it's a score file name,
805 ;; so we load the score file and add the score alist to
806 ;; the list of alists.
807 (setq scores (nconc (gnus-score-load-file (car score-files)) scores))
808 ;; It is an alist, so we just add it to the list directly.
809 (setq scores (nconc (car score-files) scores)))
810 (setq score-files (cdr score-files)))
811 ;; Prune the score files that are to be excluded, if any.
812 (if (not gnus-scores-exclude-files)
817 (and (setq c (rassq (car s) gnus-score-cache))
818 (member (car c) gnus-scores-exclude-files)
819 (setq scores (delq (car s) scores)))
821 (if (not (and gnus-summary-default-score
823 (> (length gnus-newsgroup-headers)
824 (length gnus-newsgroup-scored))))
826 (let* ((entries gnus-header-index)
827 (now (gnus-day-number (current-time-string)))
828 (expire (- now gnus-score-expiry-days))
829 (headers gnus-newsgroup-headers)
831 (message "Scoring...")
832 ;; Create articles, an alist of the form `(HEADER . SCORE)'.
834 (setq header (car headers)
835 headers (cdr headers))
836 ;; WARNING: The assq makes the function O(N*S) while it could
837 ;; be written as O(N+S), where N is (length gnus-newsgroup-headers)
838 ;; and S is (length gnus-newsgroup-scored).
839 (or (assq (header-number header) gnus-newsgroup-scored)
840 (setq gnus-scores-articles ;Total of 2 * N cons-cells used.
841 (cons (cons header (or gnus-summary-default-score 0))
842 gnus-scores-articles))))
845 (set-buffer (get-buffer-create "*Headers*"))
846 (buffer-disable-undo (current-buffer))
848 (if gnus-orphan-score
850 (setq gnus-score-index
851 (nth 1 (assoc "references" gnus-header-index)))
852 (gnus-score-orphans gnus-orphan-score)))
853 ;; Run each header through the score process.
855 (setq entry (car entries)
857 entries (cdr entries))
858 (setq gnus-score-index (nth 1 (assoc header gnus-header-index)))
859 (if (< 0 (apply 'max (mapcar
861 (length (gnus-score-get header score)))
863 (funcall (nth 2 entry) scores header now expire)))
864 ;; Remove the buffer.
865 (kill-buffer (current-buffer)))
867 ;; Add articles to `gnus-newsgroup-scored'.
868 (while gnus-scores-articles
869 (or (= gnus-summary-default-score (cdr (car gnus-scores-articles)))
870 (setq gnus-newsgroup-scored
871 (cons (cons (header-number
872 (car (car gnus-scores-articles)))
873 (cdr (car gnus-scores-articles)))
874 gnus-newsgroup-scored)))
875 (setq gnus-scores-articles (cdr gnus-scores-articles)))
877 (message "Scoring...done")))))
880 (defun gnus-get-new-thread-ids (articles)
881 (let ((index (nth 1 (assoc "message-id" gnus-header-index)))
882 (refind gnus-score-index)
883 id-list art this tref)
885 (setq art (car articles)
886 this (aref (car art) index)
887 tref (aref (car art) refind)
888 articles (cdr articles))
889 (if (string-equal tref "") ;no references line
890 (setq id-list (cons this id-list))))
893 ;; Orphan functions written by plm@atcmp.nl (Peter Mutsaers).
894 (defun gnus-score-orphans (score)
895 (let ((new-thread-ids (gnus-get-new-thread-ids gnus-scores-articles))
896 (index (nth 1 (assoc "references" gnus-header-index)))
897 alike articles art arts this last this-id)
899 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<)
900 articles gnus-scores-articles)
902 ;;more or less the same as in gnus-score-string
905 (setq art (car articles)
906 this (aref (car art) gnus-score-index)
907 articles (cdr articles))
908 ;;completely skip if this is empty (not a child, so not an orphan)
909 (if (not (string= this ""))
910 (if (equal last this)
911 ;; O(N*H) cons-cells used here, where H is the number of
913 (setq alike (cons art alike))
916 ;; Insert the line, with a text property on the
917 ;; terminating newline refering to the articles with
920 (put-text-property (1- (point)) (point) 'articles alike)))
921 (setq alike (list art)
923 (and last ; Bwadr, duplicate code.
926 (put-text-property (1- (point)) (point) 'articles alike)))
928 ;; PLM: now delete those lines that contain an entry from new-thread-ids
929 (while new-thread-ids
930 (setq this-id (car new-thread-ids)
931 new-thread-ids (cdr new-thread-ids))
932 (goto-char (point-min))
933 (while (search-forward this-id nil t)
934 ;; found a match. remove this line
938 ;; now for each line: update its articles with score by moving to
939 ;; every end-of-line in the buffer and read the articles property
940 (goto-char (point-min))
943 (setq arts (get-text-property (point) 'articles))
947 (setcdr art (+ score (cdr art))))
951 (defun gnus-score-integer (scores header now expire)
952 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
953 alike last this art entries alist articles)
957 (setq alist (car scores)
959 entries (assoc header alist))
960 (while (cdr entries) ;First entry is the header index.
961 (let* ((rest (cdr entries))
964 (type (or (nth 3 kill) '>))
965 (score (or (nth 1 kill) gnus-score-interactive-default-score))
968 (match-func (if (or (eq type '>) (eq type '<) (eq type '<=)
969 (eq type '>=) (eq type '=))
971 (error "Illegal match type: %s" type)))
972 (articles gnus-scores-articles)
974 ;; Instead of doing all the clever stuff that
975 ;; `gnus-score-string' does to minimize searches and stuff,
976 ;; I will assume that people generally will put so few
977 ;; matches on numbers that any cleverness will take more
978 ;; time than one would gain.
980 (and (funcall match-func match
981 (or (aref (car (car articles)) gnus-score-index) 0))
984 (setcdr (car articles) (+ score (cdr (car articles))))))
985 (setq articles (cdr articles)))
986 ;; Update expire date
987 (cond ((null date)) ;Permanent entry.
988 (found ;Match, update date.
989 (gnus-score-set 'touched '(t) alist)
990 (setcar (nthcdr 2 kill) now))
991 ((< date expire) ;Old entry, remove.
992 (gnus-score-set 'touched '(t) alist)
993 (setcdr entries (cdr rest))
994 (setq rest entries)))
995 (setq entries rest))))))
997 (defun gnus-score-date (scores header now expire)
998 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
999 alike last this art entries alist articles)
1003 (setq alist (car scores)
1005 entries (assoc header alist))
1006 (while (cdr entries) ;First entry is the header index.
1007 (let* ((rest (cdr entries))
1009 (match (timezone-make-date-sortable (nth 0 kill)))
1010 (type (or (nth 3 kill) 'before))
1011 (score (or (nth 1 kill) gnus-score-interactive-default-score))
1015 (cond ((eq type 'after) 'string<)
1016 ((eq type 'before) 'gnus-string>)
1017 ((eq type 'at) 'string=)
1018 (t (error "Illegal match type: %s" type))))
1019 (articles gnus-scores-articles)
1021 ;; Instead of doing all the clever stuff that
1022 ;; `gnus-score-string' does to minimize searches and stuff,
1023 ;; I will assume that people generally will put so few
1024 ;; matches on numbers that any cleverness will take more
1025 ;; time than one would gain.
1028 (setq l (aref (car (car articles)) gnus-score-index))
1029 (funcall match-func match (timezone-make-date-sortable l))
1032 (setcdr (car articles) (+ score (cdr (car articles))))))
1033 (setq articles (cdr articles)))
1034 ;; Update expire date
1035 (cond ((null date)) ;Permanent entry.
1036 (found ;Match, update date.
1037 (gnus-score-set 'touched '(t) alist)
1038 (setcar (nthcdr 2 kill) now))
1039 ((< date expire) ;Old entry, remove.
1040 (gnus-score-set 'touched '(t) alist)
1041 (setcdr entries (cdr rest))
1042 (setq rest entries)))
1043 (setq entries rest))))))
1045 (defun gnus-score-body (scores header now expire)
1047 (set-buffer nntp-server-buffer)
1049 (let* ((buffer-read-only nil)
1050 (articles gnus-scores-articles)
1052 (request-func (cond ((string= "head" (downcase header))
1054 ((string= "body" (downcase header))
1056 (t 'gnus-request-article)))
1057 alike last this art entries alist ofunc article)
1058 ;; Not all backends support partial fetching. In that case,
1059 ;; we just fetch the entire article.
1060 (or (gnus-check-backend-function request-func gnus-newsgroup-name)
1062 (setq ofunc request-func)
1063 (setq request-func 'gnus-request-article)))
1065 (setq article (header-number (car (car articles))))
1066 (message "Scoring on article %s..." article)
1067 (if (not (funcall request-func article gnus-newsgroup-name))
1070 (goto-char (point-min))
1071 ;; If just parts of the article is to be searched, but the
1072 ;; backend didn't support partial fetching, we just narrow
1073 ;; to the relevant parts.
1075 (if (eq ofunc 'gnus-request-head)
1078 (or (search-forward "\n\n" nil t) (point-max)))
1080 (or (search-forward "\n\n" nil t) (point))
1082 (setq scores all-scores)
1085 (setq alist (car scores)
1087 entries (assoc header alist))
1088 (while (cdr entries) ;First entry is the header index.
1089 (let* ((rest (cdr entries))
1091 (match (nth 0 kill))
1092 (type (or (nth 3 kill) 's))
1093 (score (or (nth 1 kill)
1094 gnus-score-interactive-default-score))
1098 (not (or (eq type 'R) (eq type 'S)
1099 (eq type 'Regexp) (eq type 'String))))
1101 (cond ((or (eq type 'r) (eq type 'R)
1102 (eq type 'regexp) (eq type 'Regexp))
1104 ((or (eq type 's) (eq type 'S)
1105 (eq type 'string) (eq type 'String))
1108 (error "Illegal match type: %s" type))))
1110 (goto-char (point-min))
1111 (if (funcall search-func match nil t)
1112 ;; Found a match, update scores.
1114 (setcdr (car articles) (+ score (cdr (car articles))))
1116 ;; Update expire date
1117 (cond ((null date)) ;Permanent entry.
1118 (found ;Match, update date.
1119 (gnus-score-set 'touched '(t) alist)
1120 (setcar (nthcdr 2 kill) now))
1121 ((< date expire) ;Old entry, remove.
1122 (gnus-score-set 'touched '(t) alist)
1123 (setcdr entries (cdr rest))
1124 (setq rest entries)))
1125 (setq entries rest)))))
1126 (setq articles (cdr articles)))))))
1130 (defun gnus-score-followup (scores header now expire)
1131 ;; Insert the unique article headers in the buffer.
1132 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
1133 ;; gnus-score-index is used as a free variable.
1134 alike last this art entries alist articles)
1136 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<)
1137 articles gnus-scores-articles)
1141 (setq art (car articles)
1142 this (aref (car art) gnus-score-index)
1143 articles (cdr articles))
1144 (if (equal last this)
1145 (setq alike (cons art alike))
1149 (put-text-property (1- (point)) (point) 'articles alike)))
1150 (setq alike (list art)
1152 (and last ; Bwadr, duplicate code.
1155 (put-text-property (1- (point)) (point) 'articles alike)))
1159 (setq alist (car scores)
1161 entries (assoc header alist))
1162 (while (cdr entries) ;First entry is the header index.
1163 (let* ((rest (cdr entries))
1165 (match (nth 0 kill))
1166 (type (or (nth 3 kill) 's))
1167 (score (or (nth 1 kill) gnus-score-interactive-default-score))
1170 (mt (aref (symbol-name type) 0))
1172 (not (or (= mt ?R) (= mt ?S) (= mt ?E) (= mt ?F))))
1175 (cond ((= dmt ?r) 're-search-forward)
1176 ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward)
1177 (t (error "Illegal match type: %s" type))))
1179 (goto-char (point-min))
1181 (while (funcall search-func match nil t)
1182 (and (= (progn (beginning-of-line) (point))
1183 (match-beginning 0))
1184 (= (progn (end-of-line) (point))
1187 (setq found (setq arts (get-text-property
1188 (point) 'articles)))
1189 ;; Found a match, update scores.
1191 (setq art (car arts)
1193 (gnus-score-add-followups (car art))))))
1194 (while (funcall search-func match nil t)
1196 (setq found (setq arts (get-text-property (point) 'articles)))
1197 ;; Found a match, update scores.
1199 (setq art (car arts)
1201 (gnus-score-add-followups (car art)))))
1202 ;; Update expire date
1203 (cond ((null date)) ;Permanent entry.
1204 (found ;Match, update date.
1205 (gnus-score-set 'touched '(t) alist)
1206 (setcar (nthcdr 2 kill) now))
1207 ((< date expire) ;Old entry, remove.
1208 (gnus-score-set 'touched '(t) alist)
1209 (setcdr entries (cdr rest))
1210 (setq rest entries)))
1211 (setq entries rest))))))
1213 (defun gnus-score-add-followups (article)
1215 (set-buffer gnus-summary-buffer)
1216 (gnus-summary-score-entry
1217 "references" (gnus-get-header-by-number article) 'e nil
1218 (current-time-string) nil)))
1221 (defun gnus-score-string (scores header now expire)
1222 ;; Score ARTICLES according to HEADER in SCORES.
1223 ;; Update matches entries to NOW and remove unmatched entried older
1226 ;; Insert the unique article headers in the buffer.
1227 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
1228 ;; gnus-score-index is used as a free variable.
1229 alike last this art entries alist articles)
1231 ;; Sorting the articles costs os O(N*log N) but will allow us to
1232 ;; only match with each unique header. Thus the actual matching
1233 ;; will be O(M*U) where M is the number of strings to match with,
1234 ;; and U is the number of unique headers. It is assumed (but
1235 ;; untested) this will be a net win because of the large constant
1236 ;; factor involved with string matching.
1237 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<)
1238 articles gnus-scores-articles)
1242 (setq art (car articles)
1243 this (aref (car art) gnus-score-index)
1244 articles (cdr articles))
1245 (if (equal last this)
1246 ;; O(N*H) cons-cells used here, where H is the number of
1248 (setq alike (cons art alike))
1251 ;; Insert the line, with a text property on the
1252 ;; terminating newline refering to the articles with
1255 (put-text-property (1- (point)) (point) 'articles alike)))
1256 (setq alike (list art)
1258 (and last ; Bwadr, duplicate code.
1261 (put-text-property (1- (point)) (point) 'articles alike)))
1265 (setq alist (car scores)
1267 entries (assoc header alist))
1268 (while (cdr entries) ;First entry is the header index.
1269 (let* ((rest (cdr entries))
1271 (match (nth 0 kill))
1272 (type (or (nth 3 kill) 's))
1273 (score (or (nth 1 kill) gnus-score-interactive-default-score))
1276 (mt (aref (symbol-name type) 0))
1278 (not (or (= mt ?R) (= mt ?S) (= mt ?E) (= mt ?F))))
1281 (cond ((= dmt ?r) 're-search-forward)
1282 ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward)
1283 (t (error "Illegal match type: %s" type))))
1285 (goto-char (point-min))
1287 (while (and (not (eobp)) (funcall search-func match nil t))
1288 (and (= (progn (beginning-of-line) (point))
1289 (match-beginning 0))
1290 (= (progn (end-of-line) (point))
1293 (setq found (setq arts (get-text-property
1294 (point) 'articles)))
1295 ;; Found a match, update scores.
1297 (setq art (car arts)
1299 (setcdr art (+ score (cdr art))))
1301 (and (string= match "") (setq match "\n"))
1302 (while (funcall search-func match nil t)
1304 (setq found (setq arts (get-text-property (point) 'articles)))
1305 ;; Found a match, update scores.
1307 (setq art (car arts)
1309 (setcdr art (+ score (cdr art))))))
1310 ;; Update expire date
1311 (cond ((null date)) ;Permanent entry.
1312 (found ;Match, update date.
1313 (gnus-score-set 'touched '(t) alist)
1314 (setcar (nthcdr 2 kill) now))
1315 ((< date expire) ;Old entry, remove.
1316 (gnus-score-set 'touched '(t) alist)
1317 (setcdr entries (cdr rest))
1318 (setq rest entries)))
1319 (setq entries rest))))))
1321 (defun gnus-score-string< (a1 a2)
1322 ;; Compare headers in articles A2 and A2.
1323 ;; The header index used is the free variable `gnus-score-index'.
1324 (string-lessp (aref (car a1) gnus-score-index)
1325 (aref (car a2) gnus-score-index)))
1327 (defun gnus-score-build-cons (article)
1328 ;; Build a `gnus-newsgroup-scored' type cons from ARTICLE.
1329 (cons (header-number (car article)) (cdr article)))
1331 (defconst gnus-header-index
1332 ;; Name to index alist.
1333 '(("number" 0 gnus-score-integer)
1334 ("subject" 1 gnus-score-string)
1335 ("from" 2 gnus-score-string)
1336 ("date" 3 gnus-score-date)
1337 ("message-id" 4 gnus-score-string)
1338 ("references" 5 gnus-score-string)
1339 ("chars" 6 gnus-score-integer)
1340 ("lines" 7 gnus-score-integer)
1341 ("xref" 8 gnus-score-string)
1342 ("head" -1 gnus-score-body)
1343 ("body" -1 gnus-score-body)
1344 ("all" -1 gnus-score-body)
1345 ("followup" 2 gnus-score-followup)))
1347 (defun gnus-current-score-file-nondirectory (&optional score-file)
1348 (let ((score-file (or score-file gnus-current-score-file)))
1350 (gnus-short-group-name (file-name-nondirectory score-file))
1353 (defun gnus-score-adaptive ()
1355 (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist))
1357 (date (current-time-string))
1359 ;; First we transform the adaptive rule alist into something
1360 ;; that's faster to process.
1362 (setq elem (car malist))
1363 (if (symbolp (car elem))
1364 (setcar elem (symbol-value (car elem))))
1365 (setq elem (cdr elem))
1368 (cons (symbol-name (car (car elem))) (cdr (car elem))))
1371 (concat "gnus-header-"
1372 (downcase (symbol-name (car (car elem)))))))
1373 (setq elem (cdr elem)))
1374 (setq malist (cdr malist)))
1375 ;; The we score away.
1376 (goto-char (point-min))
1378 (setq elem (cdr (assq (gnus-summary-article-mark) alist)))
1381 (setq headers (gnus-get-header-by-number
1382 (gnus-summary-article-number)))
1384 (gnus-summary-score-entry
1385 (nth 1 (car elem)) (funcall (car (car elem)) headers)
1386 'e (nth 2 (car elem)) date nil t)
1387 (setq elem (cdr elem))))
1388 (forward-line 1)))))
1390 (defun gnus-score-remove-lines-adaptive (marks)
1392 (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist))
1394 (date (current-time-string))
1396 ;; First we transform the adaptive rule alist into something
1397 ;; that's faster to process.
1399 (setq elem (car malist))
1400 (if (symbolp (car elem))
1401 (setcar elem (symbol-value (car elem))))
1402 (setq elem (cdr elem))
1405 (cons (symbol-name (car (car elem))) (cdr (car elem))))
1408 (concat "gnus-header-"
1409 (downcase (symbol-name (car (car elem)))))))
1410 (setq elem (cdr elem)))
1411 (setq malist (cdr malist)))
1412 ;; The we score away.
1413 (goto-char (point-min))
1414 (while (re-search-forward marks nil t)
1416 (setq elem (cdr (assq (gnus-summary-article-mark) alist)))
1419 (setq headers (gnus-get-header-by-number
1420 (gnus-summary-article-number)))
1422 (gnus-summary-score-entry
1423 (nth 1 (car elem)) (funcall (car (car elem)) headers)
1424 'e (nth 2 (car elem)) date nil t)
1425 (setq elem (cdr elem))))
1426 (delete-region (point) (progn (forward-line 1) (point)))))))
1432 (defvar gnus-score-mode-map nil)
1433 (defvar gnus-score-mode-hook nil)
1435 (if gnus-score-mode-map
1437 (setq gnus-score-mode-map (copy-keymap emacs-lisp-mode-map))
1438 (define-key gnus-score-mode-map "\C-c\C-c" 'gnus-score-edit-done)
1439 (define-key gnus-score-mode-map "\C-c\C-d" 'gnus-score-edit-insert-date))
1441 (defun gnus-score-mode ()
1442 "Mode for editing score files.
1443 This mode is an extended emacs-lisp mode.
1445 \\{gnus-score-mode-map}"
1447 (kill-all-local-variables)
1448 (use-local-map gnus-score-mode-map)
1449 (set-syntax-table emacs-lisp-mode-syntax-table)
1450 (setq major-mode 'gnus-score-mode)
1451 (setq mode-name "Score")
1452 (lisp-mode-variables nil)
1453 (run-hooks 'emacs-lisp-mode-hook 'gnus-score-mode-hook))
1455 (defun gnus-score-edit-insert-date ()
1456 "Insert date in numerical format."
1458 (insert (int-to-string (gnus-day-number (current-time-string)))))
1460 (defun gnus-score-edit-done ()
1461 "Save the score file and return to the summary buffer."
1463 (let ((bufnam (buffer-file-name (current-buffer))))
1465 (kill-buffer (current-buffer))
1466 (and gnus-winconf-edit-score
1467 (set-window-configuration gnus-winconf-edit-score))
1468 (gnus-score-remove-from-cache bufnam)
1469 (gnus-score-load-file bufnam)))
1471 (provide 'gnus-score)
1473 ;;; gnus-score.el ends here