1 ;;; gnus-score.el --- 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.")
48 (defvar gnus-score-mimic-keymap nil
49 "*Have the score entry functions pretend that they are a keymap.")
51 (defvar gnus-score-exact-adapt-limit nil
52 "*Number that says how long a match has to be before using substring matching.
53 When doing adaptive scoring, one normally uses substring matching.
54 However, if the header one matches is short, the possibility for false
55 positives is great, so if the length of the match is less than this
56 variable, exact matching will be used.
58 If this variable is nil, which it is by default, exact matching will
63 ;; Internal variables.
65 (defvar gnus-adaptive-score-alist gnus-default-adaptive-score-alist)
67 (defvar gnus-score-trace nil)
69 (defvar gnus-score-alist nil
70 "Alist containing score information.
71 The keys can be symbols or strings. The following symbols are defined.
73 touched: If this alist has been modified.
74 mark: Automatically mark articles below this.
75 expunge: Automatically expunge articles below this.
76 files: List of other SCORE files to load when loading this one.
77 eval: Sexp to be evaluated when the score file is loaded.
79 String entries have the form (HEADER (MATCH TYPE SCORE DATE) ...)
80 where HEADER is the header being scored, MATCH is the string we are
81 looking for, TYPE is a flag indicating whether it should use regexp or
82 substring matching, SCORE is the score to add and DATE is the date
83 of the last succesful match.")
85 (defvar gnus-score-cache nil)
86 (defvar gnus-scores-articles nil)
87 (defvar gnus-scores-exclude-files nil)
88 (defvar gnus-header-index nil)
89 (defvar gnus-score-index nil)
91 (autoload 'gnus-uu-ctl-map "gnus-uu" nil nil 'keymap)
93 ;;; Summary mode score maps.
95 (defvar gnus-summary-score-map nil)
97 (define-prefix-command 'gnus-summary-score-map)
98 (define-key gnus-summary-various-map "S" 'gnus-summary-score-map)
99 (define-key gnus-summary-score-map "s" 'gnus-summary-set-score)
100 (define-key gnus-summary-score-map "a" 'gnus-summary-score-entry)
101 (define-key gnus-summary-score-map "S" 'gnus-summary-current-score)
102 (define-key gnus-summary-score-map "c" 'gnus-score-change-score-file)
103 (define-key gnus-summary-score-map "m" 'gnus-score-set-mark-below)
104 (define-key gnus-summary-score-map "x" 'gnus-score-set-expunge-below)
105 (define-key gnus-summary-score-map "e" 'gnus-score-edit-alist)
106 (define-key gnus-summary-score-map "f" 'gnus-score-edit-file)
107 (define-key gnus-summary-score-map "t" 'gnus-score-find-trace)
108 (define-key gnus-summary-score-map "C" 'gnus-score-customize)
112 ;; Summary score file commands
114 ;; Much modification of the kill (ahem, score) code and lots of the
115 ;; functions are written by Per Abrahamsen <amanda@iesd.auc.dk>.
117 (defun gnus-summary-lower-score (score)
119 (gnus-summary-increase-score (- (gnus-score-default score))))
121 (defun gnus-summary-increase-score (score)
123 (gnus-set-global-variables)
124 (let* ((nscore (gnus-score-default score))
125 (prefix (if (< nscore 0) ?L ?I))
126 (increase (> nscore 0))
128 '((?a "from" nil nil string)
129 (?s "subject" nil nil string)
130 (?b "body" "" nil string)
131 (?h "head" "" nil string)
132 (?i "message-id" nil t string)
133 (?t "references" "message-id" t string)
134 (?x "xref" nil nil string)
135 (?l "lines" nil nil number)
136 (?d "date" nil nil date)
137 (?f "followup" nil nil string)))
139 '((?s s "substring" string)
140 (?e e "exact string" string)
141 (?f f "fuzzy string" string)
142 (?r r "regexp string" string)
143 (?b before "before date" date)
144 (?a at "at date" date)
145 (?n now "this date" date)
146 (?< < "less than number" number)
147 (?> > "greater than number" number)
148 (?= = "equal to number" number)))
150 (list (list ?t (current-time-string) "temporary")
151 '(?p perm "permanent") '(?i now "immediate")))
152 (mimic gnus-score-mimic-keymap)
153 hchar entry temporary tchar pchar end type)
154 ;; First we read the header to score.
159 (message "%c-" prefix))
160 (message "%s header (%s?): " (if increase "Increase" "Lower")
161 (mapconcat (lambda (s) (char-to-string (car s)))
163 (setq hchar (read-char))
164 (if (not (or (= hchar ??) (= hchar ?\C-h)))
167 (gnus-score-insert-help "Match on header" char-to-header 1)))
169 (and (get-buffer "*Score Help*")
171 (delete-windows-on "*Score Help*")
172 (kill-buffer "*Score Help*")))
174 (or (setq entry (assq (downcase hchar) char-to-header))
178 (if mimic (message "%c %c" prefix hchar) (message ""))))
179 (if (or end (/= (downcase hchar) hchar))
181 ;; This was a majuscle, so we end reading and set the defaults.
182 (if mimic (message "%c %c" prefix hchar) (message ""))
184 temporary (current-time-string)))
186 ;; We continue reading - the type.
191 (message "%c %c-" prefix hchar))
192 (message "%s header '%s' with match type (%s?): "
193 (if increase "Increase" "Lower")
195 (mapconcat (lambda (s)
196 (if (eq (nth 4 entry)
198 (char-to-string (car s))
201 (setq tchar (read-char))
202 (if (not (or (= tchar ??) (= tchar ?\C-h)))
205 (gnus-score-insert-help "Match type" char-to-type 2)))
207 (and (get-buffer "*Score Help*")
209 (delete-windows-on "*Score Help*")
210 (kill-buffer "*Score Help*")))
212 (or (setq type (nth 1 (assq (downcase tchar) char-to-type)))
215 (if mimic (message "%c %c" prefix hchar) (message ""))
217 (if (or end (/= (downcase tchar) tchar))
219 ;; It was a majuscle, so we end reading and the the default.
220 (if mimic (message "%c %c %c" prefix hchar tchar)
222 (setq temporary (current-time-string)))
224 ;; We continue reading.
229 (message "%c %c %c-" prefix hchar tchar))
230 (message "%s permanence (%s?): " (if increase "Increase" "Lower")
231 (mapconcat (lambda (s) (char-to-string (car s)))
233 (setq pchar (read-char))
234 (if (not (or (= pchar ??) (= pchar ?\C-h)))
237 (gnus-score-insert-help "Match permanence" char-to-perm 2)))
239 (and (get-buffer "*Score Help*")
241 (delete-windows-on "*Score Help*")
242 (kill-buffer "*Score Help*")))
244 (if mimic (message "%c %c %c" prefix hchar tchar pchar)
246 (if (setq temporary (nth 1 (assq pchar char-to-perm)))
251 (message "%c %c %c %c" prefix hchar tchar pchar)
253 ;; We have all the data, so we enter this score.
256 (gnus-summary-score-entry
257 (nth 1 entry) ; Header
258 (gnus-summary-header (or (nth 2 entry) (nth 1 entry))) ; Match
260 (if (eq 's score) nil score) ; Score
261 (if (eq 'perm temporary) ; Temp
264 (not (nth 3 entry))) ; Prompt
267 (defun gnus-score-insert-help (string alist idx)
269 (pop-to-buffer "*Score Help*")
270 (buffer-disable-undo (current-buffer))
272 (insert string ":\n\n")
274 (insert (format " %c: %s\n" (car (car alist)) (nth idx (car alist))))
275 (setq alist (cdr alist)))))
277 (defun gnus-summary-header (header)
278 ;; Return HEADER for current articles, or error.
279 (let ((article (gnus-summary-article-number)))
281 (aref (gnus-get-header-by-number article)
282 (nth 1 (assoc header gnus-header-index)))
283 (error "No article on current line"))))
285 (defun gnus-summary-score-entry
286 (header match type score date &optional prompt silent)
287 "Enter score file entry.
288 HEADER is the header being scored.
289 MATCH is the string we are looking for.
290 TYPE is a flag indicating if it is a regexp or substring.
291 SCORE is the score to add.
292 DATE is the expire date, or nil for no expire, or 'now for immediate expire.
293 If optional argument `PROMPT' is non-nil, allow user to edit match.
294 If optional argument `SILENT' is nil, show effect of score entry."
296 (list (completing-read "Header: "
298 (lambda (x) (fboundp (nth 2 x)))
300 (read-string "Match: ")
301 (if (y-or-n-p "Use regexp match? ") 'r 's)
302 (and current-prefix-arg
303 (prefix-numeric-value current-prefix-arg))
304 (cond ((not (y-or-n-p "Add to SCORE file? "))
306 ((y-or-n-p "Expire kill? ")
307 (current-time-string))
309 (if (or (eq type 'r) (eq type 's))
310 (setq match (gnus-simplify-subject-re match)))
311 (let ((score (gnus-score-default score))
312 (header (downcase header)))
313 (and prompt (setq match (read-string
314 (format "Match %s on %s, %s: "
315 (cond ((eq date 'now)
321 (if (< score 0) "lower" "raise"))
323 (int-to-string match)
325 (and (>= (nth 1 (assoc header gnus-header-index)) 0)
326 (eq (nth 2 (assoc header gnus-header-index))
329 (gnus-summary-score-effect header match type score))
332 (and (= score gnus-score-interactive-default-score)
336 (list (gnus-simplify-subject-fuzzy match)
337 score (and date (gnus-day-number date)) type))
339 (list match score (and date (gnus-day-number date)) type))
341 (list match score (gnus-day-number date)))
346 (old (gnus-score-get header))
348 ;; We see whether we can collapse some score entries.
349 ;; This isn't quite correct, because there may be more elements
350 ;; later on with the same key that have matching elems... Hm.
352 (setq elem (assoc match old))
353 (eq (nth 3 elem) (nth 3 new))
354 (or (and (numberp (nth 2 elem)) (numberp (nth 2 new)))
355 (and (not (nth 2 elem)) (not (nth 2 new)))))
356 ;; Yup, we just add this new score to the old elem.
357 (setcar (cdr elem) (+ (or (nth 1 elem)
358 gnus-score-interactive-default-score)
360 gnus-score-interactive-default-score)))
361 ;; Nope, we have to add a new elem.
362 (gnus-score-set header (if old (cons new old) (list new)))))
363 (gnus-score-set 'touched '(t)))))
365 (defun gnus-summary-score-effect (header match type score)
366 "Simulate the effect of a score file entry.
367 HEADER is the header being scored.
368 MATCH is the string we are looking for.
369 TYPE is a flag indicating if it is a regexp or substring.
370 SCORE is the score to add."
371 (interactive (list (completing-read "Header: "
373 (lambda (x) (fboundp (nth 2 x)))
375 (read-string "Match: ")
376 (y-or-n-p "Use regexp match? ")
377 (prefix-numeric-value current-prefix-arg)))
379 (or (and (stringp match) (> (length match) 0))
381 (goto-char (point-min))
382 (let ((regexp (cond ((eq type 'f)
383 (gnus-simplify-subject-fuzzy match))
385 (t (concat "\\`.*" (regexp-quote match) ".*\\'")))))
387 (let ((content (gnus-summary-header header))
388 (case-fold-search t))
391 (string-equal (gnus-simplify-subject-fuzzy content)
393 (string-match regexp content))
394 (gnus-summary-raise-score score))))
395 (beginning-of-line 2)))))
397 (defun gnus-summary-score-crossposting (score date)
398 ;; Enter score file entry for current crossposting.
399 ;; SCORE is the score to add.
400 ;; DATE is the expire date.
401 (let ((xref (gnus-summary-header "xref"))
404 (or xref (error "This article is not crossposted"))
405 (while (string-match " \\([^ \t]+\\):" xref start)
406 (setq start (match-end 0))
409 (substring xref (match-beginning 1) (match-end 1)))
410 gnus-newsgroup-name))
411 (gnus-summary-score-entry
412 "xref" (concat " " group ":") nil score date t)))))
419 ;; All score code written by Per Abrahamsen <abraham@iesd.auc.dk>.
421 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
422 (defun gnus-score-set-mark-below (score)
423 "Automatically mark articles with score below SCORE as read."
425 (list (or (and current-prefix-arg (prefix-numeric-value current-prefix-arg))
426 (string-to-int (read-string "Mark below: ")))))
427 (setq score (or score gnus-summary-default-score 0))
428 (gnus-score-set 'mark (list score))
429 (gnus-score-set 'touched '(t))
430 (setq gnus-summary-mark-below score)
431 (gnus-summary-update-lines))
433 (defun gnus-score-set-expunge-below (score)
434 "Automatically expunge articles with score below SCORE."
436 (list (or (and current-prefix-arg (prefix-numeric-value current-prefix-arg))
437 (string-to-int (read-string "Expunge below: ")))))
438 (setq score (or score gnus-summary-default-score 0))
439 (gnus-score-set 'expunge (list score))
440 (gnus-score-set 'touched '(t)))
442 (defun gnus-score-set (symbol value &optional alist)
443 ;; Set SYMBOL to VALUE in ALIST.
448 (gnus-score-load (gnus-score-file-name gnus-newsgroup-name))
450 (entry (assoc symbol alist)))
451 (cond ((gnus-score-get 'read-only alist)
452 ;; This is a read-only score file, so we do nothing.
455 (setcdr entry value))
457 (error "Empty alist"))
460 (cons (cons symbol value) (cdr alist)))))))
462 (defun gnus-score-get (symbol &optional alist)
463 ;; Get SYMBOL's definition in ALIST.
469 (gnus-score-file-name gnus-newsgroup-name))
470 gnus-score-alist)))))
472 (defun gnus-score-change-score-file (file)
473 "Change current score alist."
474 (interactive (list (completing-read "Score file: " gnus-score-cache)))
475 (gnus-score-load-file file)
476 (gnus-set-mode-line 'summary))
478 (defun gnus-score-edit-alist (file)
479 "Edit the current score alist."
480 (interactive (list gnus-current-score-file))
481 (let ((winconf (current-window-configuration)))
482 (and (buffer-name gnus-summary-buffer) (gnus-score-save))
483 (gnus-configure-windows 'article)
484 (pop-to-buffer (find-file-noselect file))
486 (make-local-variable 'gnus-prev-winconf)
487 (setq gnus-prev-winconf winconf))
489 4 (substitute-command-keys
490 "\\<gnus-score-mode-map>\\[gnus-score-edit-done] to save edits")))
492 (defun gnus-score-edit-file (file)
495 (list (read-file-name "Edit score file: " gnus-kill-files-directory)))
496 (and (buffer-name gnus-summary-buffer) (gnus-score-save))
497 (let ((winconf (current-window-configuration)))
498 (gnus-configure-windows 'article)
499 (pop-to-buffer (find-file-noselect file))
501 (make-local-variable 'gnus-prev-winconf)
502 (setq gnus-prev-winconf winconf))
504 4 (substitute-command-keys
505 "\\<gnus-score-mode-map>\\[gnus-score-edit-done] to save edits")))
507 (defun gnus-score-load-file (file)
508 ;; Load score file FILE. Returns a list a retrieved score-alists.
509 (setq gnus-kill-files-directory (or gnus-kill-files-directory "~/News/"))
510 (let* ((file (expand-file-name
511 (or (and (string-match
512 (concat "^" (expand-file-name
513 gnus-kill-files-directory))
514 (expand-file-name file))
516 (concat gnus-kill-files-directory file))))
517 (cached (assoc file gnus-score-cache))
518 (global (member file gnus-internal-global-score-files))
521 ;; The score file was already loaded.
522 (setq alist (cdr cached))
523 ;; We load the score file.
524 (setq gnus-score-alist nil)
525 (setq alist (gnus-score-load-score-alist file))
526 ;; We add '(touched) to the alist to signify that it hasn't been
528 (or (assq 'touched alist) (setq alist (cons (list 'touched nil) alist)))
529 ;; If it is a global score file, we make it read-only.
531 (not (assq 'read-only alist))
532 (setq alist (cons (list 'read-only t) alist)))
534 (setq gnus-score-cache
535 (cons (cons file alist) gnus-score-cache)))
536 ;; If there are actual scores in the alist, we add it to the
537 ;; return value of this function.
538 (if (memq t (mapcar (lambda (e) (stringp (car e))) alist))
539 (setq lists (list alist)))
540 ;; Treat the other possible atoms in the score alist.
541 (let ((mark (car (gnus-score-get 'mark alist)))
542 (expunge (car (gnus-score-get 'expunge alist)))
543 (mark-and-expunge (car (gnus-score-get 'mark-and-expunge alist)))
544 (read-only (gnus-score-get 'read-only alist))
545 (files (gnus-score-get 'files alist))
546 (exclude-files (gnus-score-get 'exclude-files alist))
547 (orphan (car (gnus-score-get 'orphan alist)))
548 (adapt (gnus-score-get 'adapt alist))
549 (local (gnus-score-get 'local alist))
550 (eval (car (gnus-score-get 'eval alist))))
551 ;; We do not respect eval and files atoms from global score
553 (and files (not global)
554 (setq lists (apply 'append lists
555 (mapcar (lambda (file)
556 (gnus-score-load-file file))
558 (and eval (not global) (eval eval))
559 (setq gnus-scores-exclude-files exclude-files)
563 (set-buffer gnus-summary-buffer)
565 (and (consp (car local))
566 (symbolp (car (car local)))
568 (make-local-variable (car (car local)))
569 (set (car (car local)) (nth 1 (car local)))))
570 (setq local (cdr local)))))
571 (if orphan (setq gnus-orphan-score orphan))
572 (setq gnus-adaptive-score-alist
573 (cond ((equal adapt '(t))
574 (setq gnus-newsgroup-adaptive t)
575 gnus-default-adaptive-score-alist)
576 ((equal adapt '(ignore))
577 (setq gnus-newsgroup-adaptive nil))
579 (setq gnus-newsgroup-adaptive t)
582 (setq gnus-newsgroup-adaptive gnus-use-adaptive-scoring)
583 gnus-default-adaptive-score-alist)))
584 (setq gnus-summary-mark-below
585 (or mark mark-and-expunge gnus-summary-mark-below))
586 (setq gnus-summary-expunge-below
587 (or expunge mark-and-expunge gnus-summary-expunge-below)))
588 (setq gnus-current-score-file file)
589 (setq gnus-score-alist alist)
592 (defun gnus-score-load (file)
594 (let ((cache (assoc file gnus-score-cache)))
596 (setq gnus-score-alist (cdr cache))
597 (setq gnus-score-alist nil)
598 (gnus-score-load-score-alist file)
600 (setq gnus-score-alist (copy-alist '((touched nil)))))
601 (setq gnus-score-cache
602 (cons (cons file gnus-score-alist) gnus-score-cache)))))
604 (defun gnus-score-remove-from-cache (file)
605 (setq gnus-score-cache
606 (delq (assoc file gnus-score-cache) gnus-score-cache)))
608 (defun gnus-score-load-score-alist (file)
610 (if (file-readable-p file)
613 (gnus-set-work-buffer)
614 (insert-file-contents file)
615 (goto-char (point-min))
616 ;; Only do the loading if the score file isn't empty.
617 (if (save-excursion (re-search-forward "[()0-9a-zA-Z]" nil t))
620 (read (current-buffer))
623 (gnus-message 3 "Problem with score file %s" file)
627 (if (eq (car alist) 'setq)
628 (setq gnus-score-alist (gnus-score-transform-old-to-new alist))
629 (setq gnus-score-alist alist))
630 (setq gnus-score-alist
631 (gnus-score-check-syntax gnus-score-alist file)))
632 (setq gnus-score-alist nil))))
634 (defun gnus-score-check-syntax (alist file)
639 (gnus-message 1 "Score file is not a list: %s" file)
645 (while (and a (not err))
646 (cond ((not (listp (car a)))
647 (gnus-message 3 "Illegal score element %s in %s" (car a) file)
649 ((and (stringp (car (car a)))
650 (not (listp (nth 1 (car a)))))
651 (gnus-message 3 "Illegal header match %s in %s" (nth 1 (car a)) file)
661 (defun gnus-score-transform-old-to-new (alist)
662 (let* ((alist (nth 2 alist))
664 (if (eq (car alist) 'quote)
665 (setq alist (nth 1 alist)))
667 (setq entry (car alist))
668 (if (stringp (car entry))
669 (let ((scor (cdr entry)))
670 (setq out (cons entry out))
673 (list (car (car scor)) (nth 2 (car scor))
674 (and (nth 3 (car scor))
675 (gnus-day-number (nth 3 (car scor))))
676 (if (nth 1 (car scor)) 'r 's)))
677 (setq scor (cdr scor))))
678 (setq out (cons (if (not (listp (cdr entry)))
679 (list (car entry) (cdr entry))
682 (setq alist (cdr alist)))
683 (cons (list 'touched t) (nreverse out))))
685 (defun gnus-score-save ()
686 ;; Save all SCORE information.
687 (let ((cache gnus-score-cache))
689 (setq gnus-score-alist nil)
690 (set-buffer (get-buffer-create "*Score*"))
691 (buffer-disable-undo (current-buffer))
692 (let (entry score file)
694 (setq entry (car cache)
698 (if (or (not (equal (gnus-score-get 'touched score) '(t)))
699 (gnus-score-get 'read-only score)
700 (and (file-exists-p file)
701 (not (file-writable-p file))))
703 (setq score (setcdr entry (delq (assq 'touched score) score)))
705 (let (emacs-lisp-mode-hook)
706 (if (string-match (concat gnus-adaptive-file-suffix "$") file)
707 ;; This is an adaptive score file, so we do not run
708 ;; it through `pp'. These files can get huge, and
709 ;; are not meant to be edited by human hands.
710 (insert (format "%S" score))
711 ;; This is a normal score file, so we print it very
713 (pp score (current-buffer))))
714 (gnus-make-directory (file-name-directory file))
715 (write-region (point-min) (point-max) file nil 'silent))))
716 (kill-buffer (current-buffer)))))
718 (defun gnus-score-headers (score-files &optional trace)
719 ;; Score `gnus-newsgroup-headers'.
721 ;; PLM: probably this is not the best place to clear orphan-score
722 (setq gnus-orphan-score nil)
723 ;; Load the SCORE files.
725 (if (stringp (car score-files))
726 ;; It is a string, which means that it's a score file name,
727 ;; so we load the score file and add the score alist to
728 ;; the list of alists.
729 (setq scores (nconc (gnus-score-load-file (car score-files)) scores))
730 ;; It is an alist, so we just add it to the list directly.
731 (setq scores (nconc (car score-files) scores)))
732 (setq score-files (cdr score-files)))
733 ;; Prune the score files that are to be excluded, if any.
734 (if (not gnus-scores-exclude-files)
739 (and (setq c (rassq (car s) gnus-score-cache))
740 (member (car c) gnus-scores-exclude-files)
741 (setq scores (delq (car s) scores)))
743 (if (not (and gnus-summary-default-score
745 (> (length gnus-newsgroup-headers)
746 (length gnus-newsgroup-scored))))
748 (let* ((entries gnus-header-index)
749 (now (gnus-day-number (current-time-string)))
750 (expire (- now gnus-score-expiry-days))
751 (headers gnus-newsgroup-headers)
752 (current-score-file gnus-current-score-file)
754 (gnus-message 5 "Scoring...")
755 ;; Create articles, an alist of the form `(HEADER . SCORE)'.
757 (setq header (car headers)
758 headers (cdr headers))
759 ;; WARNING: The assq makes the function O(N*S) while it could
760 ;; be written as O(N+S), where N is (length gnus-newsgroup-headers)
761 ;; and S is (length gnus-newsgroup-scored).
762 (or (assq (header-number header) gnus-newsgroup-scored)
763 (setq gnus-scores-articles ;Total of 2 * N cons-cells used.
764 (cons (cons header (or gnus-summary-default-score 0))
765 gnus-scores-articles))))
768 (set-buffer (get-buffer-create "*Headers*"))
769 (buffer-disable-undo (current-buffer))
771 ;; Set the global variant of this variable.
772 (setq gnus-current-score-file current-score-file)
774 (if gnus-orphan-score
776 (setq gnus-score-index
777 (nth 1 (assoc "references" gnus-header-index)))
778 (gnus-score-orphans gnus-orphan-score)))
779 ;; Run each header through the score process.
781 (setq entry (car entries)
783 entries (cdr entries))
784 (setq gnus-score-index (nth 1 (assoc header gnus-header-index)))
785 (if (< 0 (apply 'max (mapcar
787 (length (gnus-score-get header score)))
789 (funcall (nth 2 entry) scores header now expire trace)))
790 ;; Remove the buffer.
791 (kill-buffer (current-buffer)))
793 ;; Add articles to `gnus-newsgroup-scored'.
794 (while gnus-scores-articles
795 (or (= gnus-summary-default-score (cdr (car gnus-scores-articles)))
796 (setq gnus-newsgroup-scored
797 (cons (cons (header-number
798 (car (car gnus-scores-articles)))
799 (cdr (car gnus-scores-articles)))
800 gnus-newsgroup-scored)))
801 (setq gnus-scores-articles (cdr gnus-scores-articles)))
803 (gnus-message 5 "Scoring...done")))))
806 (defun gnus-get-new-thread-ids (articles)
807 (let ((index (nth 1 (assoc "message-id" gnus-header-index)))
808 (refind gnus-score-index)
809 id-list art this tref)
811 (setq art (car articles)
812 this (aref (car art) index)
813 tref (aref (car art) refind)
814 articles (cdr articles))
815 (if (string-equal tref "") ;no references line
816 (setq id-list (cons this id-list))))
819 ;; Orphan functions written by plm@atcmp.nl (Peter Mutsaers).
820 (defun gnus-score-orphans (score)
821 (let ((new-thread-ids (gnus-get-new-thread-ids gnus-scores-articles))
822 (index (nth 1 (assoc "references" gnus-header-index)))
823 alike articles art arts this last this-id)
825 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<)
826 articles gnus-scores-articles)
828 ;;more or less the same as in gnus-score-string
831 (setq art (car articles)
832 this (aref (car art) gnus-score-index)
833 articles (cdr articles))
834 ;;completely skip if this is empty (not a child, so not an orphan)
835 (if (not (string= this ""))
836 (if (equal last this)
837 ;; O(N*H) cons-cells used here, where H is the number of
839 (setq alike (cons art alike))
842 ;; Insert the line, with a text property on the
843 ;; terminating newline refering to the articles with
846 (put-text-property (1- (point)) (point) 'articles alike)))
847 (setq alike (list art)
849 (and last ; Bwadr, duplicate code.
852 (put-text-property (1- (point)) (point) 'articles alike)))
854 ;; PLM: now delete those lines that contain an entry from new-thread-ids
855 (while new-thread-ids
856 (setq this-id (car new-thread-ids)
857 new-thread-ids (cdr new-thread-ids))
858 (goto-char (point-min))
859 (while (search-forward this-id nil t)
860 ;; found a match. remove this line
864 ;; now for each line: update its articles with score by moving to
865 ;; every end-of-line in the buffer and read the articles property
866 (goto-char (point-min))
869 (setq arts (get-text-property (point) 'articles))
873 (setcdr art (+ score (cdr art))))
877 (defun gnus-score-integer (scores header now expire &optional trace)
878 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
879 alike last this art entries alist articles)
883 (setq alist (car scores)
885 entries (assoc header alist))
886 (while (cdr entries) ;First entry is the header index.
887 (let* ((rest (cdr entries))
890 (type (or (nth 3 kill) '>))
891 (score (or (nth 1 kill) gnus-score-interactive-default-score))
894 (match-func (if (or (eq type '>) (eq type '<) (eq type '<=)
895 (eq type '>=) (eq type '=))
897 (error "Illegal match type: %s" type)))
898 (articles gnus-scores-articles)
900 ;; Instead of doing all the clever stuff that
901 ;; `gnus-score-string' does to minimize searches and stuff,
902 ;; I will assume that people generally will put so few
903 ;; matches on numbers that any cleverness will take more
904 ;; time than one would gain.
906 (and (funcall match-func
907 (or (aref (car (car articles)) gnus-score-index) 0)
910 (and trace (setq gnus-score-trace
911 (cons (cons (car (car articles)) kill)
914 (setcdr (car articles) (+ score (cdr (car articles))))))
915 (setq articles (cdr articles)))
916 ;; Update expire date
917 (cond ((null date)) ;Permanent entry.
918 (found ;Match, update date.
919 (gnus-score-set 'touched '(t) alist)
920 (setcar (nthcdr 2 kill) now))
921 ((< date expire) ;Old entry, remove.
922 (gnus-score-set 'touched '(t) alist)
923 (setcdr entries (cdr rest))
924 (setq rest entries)))
925 (setq entries rest))))))
927 (defun gnus-score-date (scores header now expire &optional trace)
928 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
929 alike last this art entries alist articles)
933 (setq alist (car scores)
935 entries (assoc header alist))
936 (while (cdr entries) ;First entry is the header index.
937 (let* ((rest (cdr entries))
939 (match (timezone-make-date-sortable (nth 0 kill)))
940 (type (or (nth 3 kill) 'before))
941 (score (or (nth 1 kill) gnus-score-interactive-default-score))
945 (cond ((eq type 'after) 'string<)
946 ((eq type 'before) 'gnus-string>)
947 ((eq type 'at) 'string=)
948 (t (error "Illegal match type: %s" type))))
949 (articles gnus-scores-articles)
951 ;; Instead of doing all the clever stuff that
952 ;; `gnus-score-string' does to minimize searches and stuff,
953 ;; I will assume that people generally will put so few
954 ;; matches on numbers that any cleverness will take more
955 ;; time than one would gain.
958 (setq l (aref (car (car articles)) gnus-score-index))
959 (funcall match-func match (timezone-make-date-sortable l))
961 (and trace (setq gnus-score-trace
962 (cons (cons (car (car articles)) kill)
965 (setcdr (car articles) (+ score (cdr (car articles))))))
966 (setq articles (cdr articles)))
967 ;; Update expire date
968 (cond ((null date)) ;Permanent entry.
969 (found ;Match, update date.
970 (gnus-score-set 'touched '(t) alist)
971 (setcar (nthcdr 2 kill) now))
972 ((< date expire) ;Old entry, remove.
973 (gnus-score-set 'touched '(t) alist)
974 (setcdr entries (cdr rest))
975 (setq rest entries)))
976 (setq entries rest))))))
978 (defun gnus-score-body (scores header now expire &optional trace)
980 (set-buffer nntp-server-buffer)
982 (let* ((buffer-read-only nil)
983 (articles gnus-scores-articles)
985 (gnus-last-element (car gnus-scores-articles))))
987 (request-func (cond ((string= "head" (downcase header))
989 ((string= "body" (downcase header))
991 (t 'gnus-request-article)))
992 alike last this art entries alist ofunc article)
993 ;; Not all backends support partial fetching. In that case,
994 ;; we just fetch the entire article.
995 (or (gnus-check-backend-function request-func gnus-newsgroup-name)
997 (setq ofunc request-func)
998 (setq request-func 'gnus-request-article)))
1000 (setq article (header-number (car (car articles))))
1001 (gnus-message 7 "Scoring on article %s of %s..." article last)
1002 (if (not (funcall request-func article gnus-newsgroup-name))
1005 (goto-char (point-min))
1006 ;; If just parts of the article is to be searched, but the
1007 ;; backend didn't support partial fetching, we just narrow
1008 ;; to the relevant parts.
1010 (if (eq ofunc 'gnus-request-head)
1013 (or (search-forward "\n\n" nil t) (point-max)))
1015 (or (search-forward "\n\n" nil t) (point))
1017 (setq scores all-scores)
1020 (setq alist (car scores)
1022 entries (assoc header alist))
1023 (while (cdr entries) ;First entry is the header index.
1024 (let* ((rest (cdr entries))
1026 (match (nth 0 kill))
1027 (type (or (nth 3 kill) 's))
1028 (score (or (nth 1 kill)
1029 gnus-score-interactive-default-score))
1033 (not (or (eq type 'R) (eq type 'S)
1034 (eq type 'Regexp) (eq type 'String))))
1036 (cond ((or (eq type 'r) (eq type 'R)
1037 (eq type 'regexp) (eq type 'Regexp))
1039 ((or (eq type 's) (eq type 'S)
1040 (eq type 'string) (eq type 'String))
1043 (error "Illegal match type: %s" type))))
1045 (goto-char (point-min))
1046 (if (funcall search-func match nil t)
1047 ;; Found a match, update scores.
1049 (setcdr (car articles) (+ score (cdr (car articles))))
1051 (and trace (setq gnus-score-trace
1052 (cons (cons (car (car articles)) kill)
1053 gnus-score-trace)))))
1054 ;; Update expire date
1055 (cond ((null date)) ;Permanent entry.
1056 (found ;Match, update date.
1057 (gnus-score-set 'touched '(t) alist)
1058 (setcar (nthcdr 2 kill) now))
1059 ((< date expire) ;Old entry, remove.
1060 (gnus-score-set 'touched '(t) alist)
1061 (setcdr entries (cdr rest))
1062 (setq rest entries)))
1063 (setq entries rest)))))
1064 (setq articles (cdr articles)))))))
1068 (defun gnus-score-followup (scores header now expire &optional trace)
1069 ;; Insert the unique article headers in the buffer.
1070 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
1071 (current-score-file gnus-current-score-file)
1072 ;; gnus-score-index is used as a free variable.
1073 alike last this art entries alist articles)
1075 ;; Change score file to the adaptive score file. All entries that
1076 ;; this function makes will be put into this file.
1077 (gnus-score-load-file (gnus-score-file-name
1078 gnus-newsgroup-name gnus-adaptive-file-suffix))
1080 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<)
1081 articles gnus-scores-articles)
1085 (setq art (car articles)
1086 this (aref (car art) gnus-score-index)
1087 articles (cdr articles))
1088 (if (equal last this)
1089 (setq alike (cons art alike))
1093 (put-text-property (1- (point)) (point) 'articles alike)))
1094 (setq alike (list art)
1096 (and last ; Bwadr, duplicate code.
1099 (put-text-property (1- (point)) (point) 'articles alike)))
1103 (setq alist (car scores)
1105 entries (assoc header alist))
1106 (while (cdr entries) ;First entry is the header index.
1107 (let* ((rest (cdr entries))
1109 (match (nth 0 kill))
1110 (type (or (nth 3 kill) 's))
1111 (score (or (nth 1 kill) gnus-score-interactive-default-score))
1114 (mt (aref (symbol-name type) 0))
1116 (not (or (= mt ?R) (= mt ?S) (= mt ?E) (= mt ?F))))
1119 (cond ((= dmt ?r) 're-search-forward)
1120 ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward)
1121 (t (error "Illegal match type: %s" type))))
1123 (goto-char (point-min))
1125 (while (funcall search-func match nil t)
1126 (and (= (progn (beginning-of-line) (point))
1127 (match-beginning 0))
1128 (= (progn (end-of-line) (point))
1131 (setq found (setq arts (get-text-property
1132 (point) 'articles)))
1133 ;; Found a match, update scores.
1135 (setq art (car arts)
1137 (gnus-score-add-followups (car art) score)))))
1138 (while (funcall search-func match nil t)
1140 (setq found (setq arts (get-text-property (point) 'articles)))
1141 ;; Found a match, update scores.
1143 (setq art (car arts)
1145 (gnus-score-add-followups (car art) score))))
1146 ;; Update expire date
1147 (cond ((null date)) ;Permanent entry.
1148 (found ;Match, update date.
1149 (gnus-score-set 'touched '(t) alist)
1150 (setcar (nthcdr 2 kill) now))
1151 ((< date expire) ;Old entry, remove.
1152 (gnus-score-set 'touched '(t) alist)
1153 (setcdr entries (cdr rest))
1154 (setq rest entries)))
1155 (setq entries rest))))
1156 ;; We change the score file back to the previous one.
1157 (gnus-score-load-file current-score-file)))
1159 (defun gnus-score-add-followups (header score)
1161 (set-buffer gnus-summary-buffer)
1162 (let ((id (header-id header))
1163 (score gnus-score-alist)
1165 ;; Don't enter a score if there already is one.
1167 (and (equal "references" (car (car score)))
1168 (or (null (nth 3 (car score)))
1169 (eq 's (nth 3 (car score))))
1171 (or (assoc id (car score))
1174 (setq score (cdr score)))
1176 (gnus-summary-score-entry
1177 "references" id 's score (current-time-string) nil t)))))
1180 (defun gnus-score-string (score-list header now expire &optional trace)
1181 ;; Score ARTICLES according to HEADER in SCORE-LIST.
1182 ;; Update matches entries to NOW and remove unmatched entried older
1185 ;; Insert the unique article headers in the buffer.
1186 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index)))
1187 ;; gnus-score-index is used as a free variable.
1188 alike last this art entries alist articles scores fuzzy)
1190 ;; Sorting the articles costs os O(N*log N) but will allow us to
1191 ;; only match with each unique header. Thus the actual matching
1192 ;; will be O(M*U) where M is the number of strings to match with,
1193 ;; and U is the number of unique headers. It is assumed (but
1194 ;; untested) this will be a net win because of the large constant
1195 ;; factor involved with string matching.
1196 (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<)
1197 articles gnus-scores-articles)
1201 (setq art (car articles)
1202 this (aref (car art) gnus-score-index)
1203 articles (cdr articles))
1204 (if (equal last this)
1205 ;; O(N*H) cons-cells used here, where H is the number of
1207 (setq alike (cons art alike))
1210 ;; Insert the line, with a text property on the
1211 ;; terminating newline refering to the articles with
1214 (put-text-property (1- (point)) (point) 'articles alike)))
1215 (setq alike (list art)
1217 (and last ; Bwadr, duplicate code.
1220 (put-text-property (1- (point)) (point) 'articles alike)))
1222 ;; Find ordinary matches.
1223 (setq scores score-list)
1225 (setq alist (car scores)
1227 entries (assoc header alist))
1228 (while (cdr entries) ;First entry is the header index.
1229 (let* ((rest (cdr entries))
1231 (match (nth 0 kill))
1232 (type (or (nth 3 kill) 's))
1233 (score (or (nth 1 kill) gnus-score-interactive-default-score))
1236 (mt (aref (symbol-name type) 0))
1238 (not (or (= mt ?R) (= mt ?S) (= mt ?E) (= mt ?F))))
1241 (cond ((= dmt ?r) 're-search-forward)
1242 ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward)
1243 (t (error "Illegal match type: %s" type))))
1247 (goto-char (point-min))
1249 (while (and (not (eobp))
1250 (funcall search-func match nil t))
1251 (and (= (progn (beginning-of-line) (point))
1252 (match-beginning 0))
1253 (= (progn (end-of-line) (point))
1256 (setq found (setq arts (get-text-property
1257 (point) 'articles)))
1258 ;; Found a match, update scores.
1261 (setq art (car arts)
1263 (setcdr art (+ score (cdr art)))
1264 (setq gnus-score-trace
1265 (cons (cons (header-number
1269 (setq art (car arts)
1271 (setcdr art (+ score (cdr art)))))))
1273 (and (string= match "") (setq match "\n"))
1274 (while (funcall search-func match nil t)
1276 (setq found (setq arts (get-text-property (point) 'articles)))
1277 ;; Found a match, update scores.
1280 (setq art (car arts)
1282 (setcdr art (+ score (cdr art)))
1283 (setq gnus-score-trace
1284 (cons (cons (header-number (car art)) kill)
1287 (setq art (car arts)
1289 (setcdr art (+ score (cdr art)))))))
1290 ;; Update expire date
1291 (cond ((null date)) ;Permanent entry.
1292 (found ;Match, update date.
1293 (gnus-score-set 'touched '(t) alist)
1294 (setcar (nthcdr 2 kill) now))
1295 ((< date expire) ;Old entry, remove.
1296 (gnus-score-set 'touched '(t) alist)
1297 (setcdr entries (cdr rest))
1298 (setq rest entries))))
1299 (setq entries rest))))
1301 ;; Find fuzzy matches.
1302 (setq scores (and fuzzy score-list))
1303 (if fuzzy (gnus-simplify-buffer-fuzzy))
1305 (setq alist (car scores)
1307 entries (assoc header alist))
1308 (while (cdr entries) ;First entry is the header index.
1309 (let* ((rest (cdr entries))
1311 (match (nth 0 kill))
1312 (type (or (nth 3 kill) 's))
1313 (score (or (nth 1 kill) gnus-score-interactive-default-score))
1316 (mt (aref (symbol-name type) 0))
1318 (not (or (= mt ?R) (= mt ?S) (= mt ?E) (= mt ?F))))
1321 (cond ((= dmt ?r) 're-search-forward)
1322 ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward)
1323 (t (error "Illegal match type: %s" type))))
1327 (goto-char (point-min))
1328 (while (and (not (eobp))
1329 (funcall search-func match nil t))
1330 (and (= (progn (beginning-of-line) (point))
1331 (match-beginning 0))
1332 (= (progn (end-of-line) (point))
1335 (setq found (setq arts (get-text-property
1336 (point) 'articles)))
1337 ;; Found a match, update scores.
1339 (setq art (car arts)
1341 (setcdr art (+ score (cdr art))))))
1343 ;; Update expire date
1344 (cond ((null date)) ;Permanent entry.
1345 (found ;Match, update date.
1346 (gnus-score-set 'touched '(t) alist)
1347 (setcar (nthcdr 2 kill) now))
1348 ((< date expire) ;Old entry, remove.
1349 (gnus-score-set 'touched '(t) alist)
1350 (setcdr entries (cdr rest))
1351 (setq rest entries))))
1352 (setq entries rest))))))
1354 (defun gnus-score-string< (a1 a2)
1355 ;; Compare headers in articles A2 and A2.
1356 ;; The header index used is the free variable `gnus-score-index'.
1357 (string-lessp (aref (car a1) gnus-score-index)
1358 (aref (car a2) gnus-score-index)))
1360 (defun gnus-score-build-cons (article)
1361 ;; Build a `gnus-newsgroup-scored' type cons from ARTICLE.
1362 (cons (header-number (car article)) (cdr article)))
1364 (defconst gnus-header-index
1365 ;; Name to index alist.
1366 '(("number" 0 gnus-score-integer)
1367 ("subject" 1 gnus-score-string)
1368 ("from" 2 gnus-score-string)
1369 ("date" 3 gnus-score-date)
1370 ("message-id" 4 gnus-score-string)
1371 ("references" 5 gnus-score-string)
1372 ("chars" 6 gnus-score-integer)
1373 ("lines" 7 gnus-score-integer)
1374 ("xref" 8 gnus-score-string)
1375 ("head" -1 gnus-score-body)
1376 ("body" -1 gnus-score-body)
1377 ("all" -1 gnus-score-body)
1378 ("followup" 2 gnus-score-followup)))
1380 (defun gnus-current-score-file-nondirectory (&optional score-file)
1381 (let ((score-file (or score-file gnus-current-score-file)))
1383 (gnus-short-group-name (file-name-nondirectory score-file))
1386 (defun gnus-score-adaptive ()
1388 (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist))
1390 (date (current-time-string))
1392 ;; First we transform the adaptive rule alist into something
1393 ;; that's faster to process.
1395 (setq elem (car malist))
1396 (if (symbolp (car elem))
1397 (setcar elem (symbol-value (car elem))))
1398 (setq elem (cdr elem))
1401 (cons (symbol-name (car (car elem))) (cdr (car elem))))
1404 (concat "gnus-header-"
1405 (downcase (symbol-name (car (car elem)))))))
1406 (setq elem (cdr elem)))
1407 (setq malist (cdr malist)))
1408 ;; We change the score file to the adaptive score file.
1409 (gnus-score-load-file (gnus-score-file-name
1410 gnus-newsgroup-name gnus-adaptive-file-suffix))
1411 ;; The we score away.
1412 (goto-char (point-min))
1414 (setq elem (cdr (assq (gnus-summary-article-mark) alist)))
1416 (get-text-property (point) 'gnus-pseudo))
1418 (setq headers (gnus-get-header-by-number
1419 (gnus-summary-article-number)))
1420 (while (and elem headers)
1421 (setq match (funcall (car (car elem)) headers))
1422 (gnus-summary-score-entry
1423 (nth 1 (car elem)) match
1424 ;; Whether we use regexp or exact matches are controlled
1426 (if (or (not gnus-score-exact-adapt-limit)
1427 (< (length match) gnus-score-exact-adapt-limit))
1429 (nth 2 (car elem)) date nil t)
1430 (setq elem (cdr elem))))
1431 (forward-line 1)))))
1433 (defun gnus-score-remove-lines-adaptive (marks)
1435 (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist))
1437 (date (current-time-string))
1438 (cur-score gnus-current-score-file)
1440 ;; First we transform the adaptive rule alist into something
1441 ;; that's faster to process.
1443 (setq elem (car malist))
1444 (if (symbolp (car elem))
1445 (setcar elem (symbol-value (car elem))))
1446 (setq elem (cdr elem))
1449 (cons (symbol-name (car (car elem))) (cdr (car elem))))
1452 (concat "gnus-header-"
1453 (downcase (symbol-name (car (car elem)))))))
1454 (setq elem (cdr elem)))
1455 (setq malist (cdr malist)))
1456 ;; The we score away.
1457 (goto-char (point-min))
1458 ;; We change the score file to the adaptive score file.
1459 (gnus-score-load-file (gnus-score-file-name
1460 gnus-newsgroup-name gnus-adaptive-file-suffix))
1461 (while (re-search-forward marks nil t)
1463 (setq elem (cdr (assq (gnus-summary-article-mark) alist)))
1465 (get-text-property (gnus-point-at-bol) 'gnus-pseudo))
1467 (setq headers (gnus-get-header-by-number
1468 (gnus-summary-article-number)))
1470 (setq match (funcall (car (car elem)) headers))
1471 (gnus-summary-score-entry
1472 (nth 1 (car elem)) match
1473 (if (or (not gnus-score-exact-adapt-limit)
1474 (< (length match) gnus-score-exact-adapt-limit))
1476 (nth 2 (car elem)) date nil t)
1477 (setq elem (cdr elem))))
1478 (delete-region (point) (progn (forward-line 1) (point))))
1479 ;; Switch back to the old score file.
1480 (gnus-score-load-file cur-score))))
1486 (defvar gnus-score-mode-map nil)
1487 (defvar gnus-score-mode-hook nil)
1489 (if gnus-score-mode-map
1491 (setq gnus-score-mode-map (copy-keymap emacs-lisp-mode-map))
1492 (define-key gnus-score-mode-map "\C-c\C-c" 'gnus-score-edit-done)
1493 (define-key gnus-score-mode-map "\C-c\C-d" 'gnus-score-edit-insert-date))
1495 (defun gnus-score-mode ()
1496 "Mode for editing score files.
1497 This mode is an extended emacs-lisp mode.
1499 \\{gnus-score-mode-map}"
1501 (kill-all-local-variables)
1502 (use-local-map gnus-score-mode-map)
1503 (set-syntax-table emacs-lisp-mode-syntax-table)
1504 (setq major-mode 'gnus-score-mode)
1505 (setq mode-name "Score")
1506 (lisp-mode-variables nil)
1507 (run-hooks 'emacs-lisp-mode-hook 'gnus-score-mode-hook))
1509 (defun gnus-score-edit-insert-date ()
1510 "Insert date in numerical format."
1512 (insert (int-to-string (gnus-day-number (current-time-string)))))
1514 (defun gnus-score-edit-done ()
1515 "Save the score file and return to the summary buffer."
1517 (let ((bufnam (buffer-file-name (current-buffer)))
1518 (winconf gnus-prev-winconf))
1519 (gnus-make-directory (file-name-directory (buffer-file-name)))
1521 (kill-buffer (current-buffer))
1522 (gnus-score-remove-from-cache bufnam)
1523 (gnus-score-load-file bufnam)
1524 (and winconf (set-window-configuration winconf))))
1526 (defun gnus-score-find-trace ()
1527 "Find all score rules applied to this article."
1529 (let ((gnus-newsgroup-headers
1530 (list (gnus-get-header-by-number (gnus-summary-article-number))))
1531 (gnus-newsgroup-scored nil)
1532 (buf (current-buffer))
1534 (setq gnus-score-trace nil)
1535 (gnus-possibly-score-headers 'trace)
1536 (pop-to-buffer "*Gnus Scores*")
1538 (setq trace gnus-score-trace)
1540 (error "No score rules apply to the current article."))
1542 (insert (format "%S\n" (cdr (car trace))))
1543 (setq trace (cdr trace)))
1544 (goto-char (point-min))
1545 (pop-to-buffer buf)))
1548 (provide 'gnus-score)
1550 ;;; gnus-score.el ends here