1 ;;; gnus-score.el --- scoring code for Gnus
2 ;; Copyright (C) 1995,96 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 the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl
))
32 (defvar gnus-global-score-files nil
33 "*List of global score files and directories.
34 Set this variable if you want to use people's score files. One entry
35 for each score file or each score file directory. Gnus will decide
36 by itself what score files are applicable to which group.
38 Say you want to use the single score file
39 \"/ftp.ifi.uio.no@ftp:/pub/larsi/ding/score/soc.motss.SCORE\" and all
40 score files in the \"/ftp.some-where:/pub/score\" directory.
42 (setq gnus-global-score-files
43 '(\"/ftp.ifi.uio.no:/pub/larsi/ding/score/soc.motss.SCORE\"
44 \"/ftp.some-where:/pub/score\"))")
46 (defvar gnus-score-file-single-match-alist nil
47 "*Alist mapping regexps to lists of score files.
48 Each element of this alist should be of the form
49 (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... )
51 If the name of a group is matched by REGEXP, the corresponding scorefiles
52 will be used for that group.
53 The first match found is used, subsequent matching entries are ignored (to
54 use multiple matches, see gnus-score-file-multiple-match-alist).
56 These score files are loaded in addition to any files returned by
57 gnus-score-find-score-files-function (which see).")
59 (defvar gnus-score-file-multiple-match-alist nil
60 "*Alist mapping regexps to lists of score files.
61 Each element of this alist should be of the form
62 (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... )
64 If the name of a group is matched by REGEXP, the corresponding scorefiles
65 will be used for that group.
66 If multiple REGEXPs match a group, the score files corresponding to each
67 match will be used (for only one match to be used, see
68 gnus-score-file-single-match-alist).
70 These score files are loaded in addition to any files returned by
71 gnus-score-find-score-files-function (which see).")
73 (defvar gnus-score-file-suffix
"SCORE"
74 "*Suffix of the score files.")
76 (defvar gnus-adaptive-file-suffix
"ADAPT"
77 "*Suffix of the adaptive score files.")
79 (defvar gnus-score-find-score-files-function
'gnus-score-find-bnews
80 "*Function used to find score files.
81 The function will be called with the group name as the argument, and
82 should return a list of score files to apply to that group. The score
83 files do not actually have to exist.
85 Predefined values are:
87 gnus-score-find-single: Only apply the group's own score file.
88 gnus-score-find-hierarchical: Also apply score files from parent groups.
89 gnus-score-find-bnews: Apply score files whose names matches.
91 See the documentation to these functions for more information.
93 This variable can also be a list of functions to be called. Each
94 function should either return a list of score files, or a list of
97 (defvar gnus-score-interactive-default-score
1000
98 "*Scoring commands will raise/lower the score with this number as the default.")
100 (defvar gnus-score-expiry-days
7
101 "*Number of days before unused score file entries are expired.
102 If this variable is nil, no score file entries will be expired.")
104 (defvar gnus-update-score-entry-dates t
105 "*In non-nil, update matching score entry dates.
106 If this variable is nil, then score entries that provide matches
107 will be expired along with non-matching score entries.")
109 (defvar gnus-orphan-score nil
110 "*All orphans get this score added. Set in the score file.")
112 (defvar gnus-default-adaptive-score-alist
113 '((gnus-kill-file-mark)
115 (gnus-read-mark (from 3) (subject 30))
116 (gnus-catchup-mark (subject -
10))
117 (gnus-killed-mark (from -
1) (subject -
20))
118 (gnus-del-mark (from -
2) (subject -
15)))
119 "*Alist of marks and scores.")
121 (defvar gnus-score-mimic-keymap nil
122 "*Have the score entry functions pretend that they are a keymap.")
124 (defvar gnus-score-exact-adapt-limit
10
125 "*Number that says how long a match has to be before using substring matching.
126 When doing adaptive scoring, one normally uses fuzzy or substring
127 matching. However, if the header one matches is short, the possibility
128 for false positives is great, so if the length of the match is less
129 than this variable, exact matching will be used.
131 If this variable is nil, exact matching will always be used.")
133 (defvar gnus-score-uncacheable-files
"ADAPT$"
134 "*All score files that match this regexp will not be cached.")
136 (defvar gnus-score-default-header nil
137 "Default header when entering new scores.
139 Should be one of the following symbols.
152 If nil, the user will be asked for a header.")
154 (defvar gnus-score-default-type nil
155 "Default match type when entering new scores.
157 Should be one of the following symbols.
167 >: greater than number
170 If nil, the user will be asked for a match type.")
172 (defvar gnus-score-default-fold nil
173 "Use case folding for new score file entries iff not nil.")
175 (defvar gnus-score-default-duration nil
176 "Default duration of effect when entering new scores.
178 Should be one of the following symbols.
184 If nil, the user will be asked for a duration.")
186 (defvar gnus-score-after-write-file-function nil
187 "*Function called with the name of the score file just written to disk.")
191 ;; Internal variables.
193 (defvar gnus-internal-global-score-files nil
)
194 (defvar gnus-score-file-list nil
)
196 (defvar gnus-short-name-score-file-cache nil
)
198 (defvar gnus-score-help-winconf nil
)
199 (defvar gnus-adaptive-score-alist gnus-default-adaptive-score-alist
)
200 (defvar gnus-score-trace nil
)
201 (defvar gnus-score-edit-buffer nil
)
203 (defvar gnus-score-alist nil
204 "Alist containing score information.
205 The keys can be symbols or strings. The following symbols are defined.
207 touched: If this alist has been modified.
208 mark: Automatically mark articles below this.
209 expunge: Automatically expunge articles below this.
210 files: List of other score files to load when loading this one.
211 eval: Sexp to be evaluated when the score file is loaded.
213 String entries have the form (HEADER (MATCH TYPE SCORE DATE) ...)
214 where HEADER is the header being scored, MATCH is the string we are
215 looking for, TYPE is a flag indicating whether it should use regexp or
216 substring matching, SCORE is the score to add and DATE is the date
217 of the last successful match.")
219 (defvar gnus-score-cache nil
)
220 (defvar gnus-scores-articles nil
)
221 (defvar gnus-score-index nil
)
224 (defconst gnus-header-index
225 ;; Name to index alist.
226 '(("number" 0 gnus-score-integer
)
227 ("subject" 1 gnus-score-string
)
228 ("from" 2 gnus-score-string
)
229 ("date" 3 gnus-score-date
)
230 ("message-id" 4 gnus-score-string
)
231 ("references" 5 gnus-score-string
)
232 ("chars" 6 gnus-score-integer
)
233 ("lines" 7 gnus-score-integer
)
234 ("xref" 8 gnus-score-string
)
235 ("head" -
1 gnus-score-body
)
236 ("body" -
1 gnus-score-body
)
237 ("all" -
1 gnus-score-body
)
238 ("followup" 2 gnus-score-followup
)
239 ("thread" 5 gnus-score-thread
)))
242 (autoload 'gnus-uu-ctl-map
"gnus-uu" nil nil
'keymap
))
244 ;;; Summary mode score maps.
247 (gnus-summary-score-map "V" gnus-summary-mode-map
)
248 "s" gnus-summary-set-score
249 "a" gnus-summary-score-entry
250 "S" gnus-summary-current-score
251 "c" gnus-score-change-score-file
252 "m" gnus-score-set-mark-below
253 "x" gnus-score-set-expunge-below
254 "R" gnus-summary-rescore
255 "e" gnus-score-edit-current-scores
256 "f" gnus-score-edit-file
257 "F" gnus-score-flush-cache
258 "t" gnus-score-find-trace
259 "C" gnus-score-customize
)
261 ;; Summary score file commands
263 ;; Much modification of the kill (ahem, score) code and lots of the
264 ;; functions are written by Per Abrahamsen <amanda@iesd.auc.dk>.
266 (defun gnus-summary-lower-score (&optional score
)
267 "Make a score entry based on the current article.
268 The user will be prompted for header to score on, match type,
269 permanence, and the string to be used. The numerical prefix will be
272 (gnus-summary-increase-score (- (gnus-score-default score
))))
274 (defvar gnus-score-default-header nil
275 "*The default header to score on when entering a score rule interactively.")
277 (defvar gnus-score-default-type nil
278 "*The default score type to use when entering a score rule interactively.")
280 (defvar gnus-score-default-duration nil
281 "*The default score duration to use on when entering a score rule interactively.")
283 (defun gnus-score-kill-help-buffer ()
284 (when (get-buffer "*Score Help*")
285 (kill-buffer "*Score Help*")
286 (and gnus-score-help-winconf
287 (set-window-configuration gnus-score-help-winconf
))))
289 (defun gnus-summary-increase-score (&optional score
)
290 "Make a score entry based on the current article.
291 The user will be prompted for header to score on, match type,
292 permanence, and the string to be used. The numerical prefix will be
295 (gnus-set-global-variables)
296 (let* ((nscore (gnus-score-default score
))
297 (prefix (if (< nscore
0) ?L ?I
))
298 (increase (> nscore
0))
300 '((?a
"from" nil nil string
)
301 (?s
"subject" nil nil string
)
302 (?b
"body" "" nil body-string
)
303 (?h
"head" "" nil body-string
)
304 (?i
"message-id" nil t string
)
305 (?t
"references" "message-id" nil string
)
306 (?x
"xref" nil nil string
)
307 (?l
"lines" nil nil number
)
308 (?d
"date" nil nil date
)
309 (?f
"followup" nil nil string
)
310 (?T
"thread" nil nil string
)))
312 '((?s s
"substring" string
)
313 (?e e
"exact string" string
)
314 (?f f
"fuzzy string" string
)
315 (?r r
"regexp string" string
)
316 (?z s
"substring" body-string
)
317 (?p s
"regexp string" body-string
)
318 (?b before
"before date" date
)
319 (?a at
"at date" date
)
320 (?n now
"this date" date
)
321 (?
< < "less than number" number
)
322 (?
> > "greater than number" number
)
323 (?
= = "equal to number" number
)))
325 (list (list ?t
(current-time-string) "temporary")
326 '(?p perm
"permanent") '(?i now
"immediate")))
327 (mimic gnus-score-mimic-keymap
)
328 (hchar (and gnus-score-default-header
329 (aref (symbol-name gnus-score-default-header
) 0)))
330 (tchar (and gnus-score-default-type
331 (aref (symbol-name gnus-score-default-type
) 0)))
332 (pchar (and gnus-score-default-duration
333 (aref (symbol-name gnus-score-default-duration
) 0)))
334 entry temporary type match
)
339 ;; First we read the header to score.
344 (message "%c-" prefix
))
345 (message "%s header (%s?): " (if increase
"Increase" "Lower")
346 (mapconcat (lambda (s) (char-to-string (car s
)))
348 (setq hchar
(read-char))
349 (when (or (= hchar ??
) (= hchar ?\C-h
))
351 (gnus-score-insert-help "Match on header" char-to-header
1)))
353 (gnus-score-kill-help-buffer)
354 (unless (setq entry
(assq (downcase hchar
) char-to-header
))
355 (if mimic
(error "%c %c" prefix hchar
) (error "")))
357 (when (/= (downcase hchar
) hchar
)
358 ;; This was a majuscle, so we end reading and set the defaults.
359 (if mimic
(message "%c %c" prefix hchar
) (message ""))
360 (setq tchar
(or tchar ?s
)
361 pchar
(or pchar ?t
)))
363 ;; We continue reading - the type.
367 (sit-for 1) (message "%c %c-" prefix hchar
))
368 (message "%s header '%s' with match type (%s?): "
369 (if increase
"Increase" "Lower")
371 (mapconcat (lambda (s)
372 (if (eq (nth 4 entry
)
374 (char-to-string (car s
))
377 (setq tchar
(read-char))
378 (when (or (= tchar ??
) (= tchar ?\C-h
))
380 (gnus-score-insert-help
384 (if (eq (nth 4 entry
)
390 (gnus-score-kill-help-buffer)
391 (unless (setq type
(nth 1 (assq (downcase tchar
) char-to-type
)))
392 (if mimic
(error "%c %c" prefix hchar
) (error "")))
394 (when (/= (downcase tchar
) tchar
)
395 ;; It was a majuscle, so we end reading and the the default.
396 (if mimic
(message "%c %c %c" prefix hchar tchar
)
398 (setq pchar
(or pchar ?p
)))
400 ;; We continue reading.
404 (sit-for 1) (message "%c %c %c-" prefix hchar tchar
))
405 (message "%s permanence (%s?): " (if increase
"Increase" "Lower")
406 (mapconcat (lambda (s) (char-to-string (car s
)))
408 (setq pchar
(read-char))
409 (when (or (= pchar ??
) (= pchar ?\C-h
))
411 (gnus-score-insert-help "Match permanence" char-to-perm
2)))
413 (gnus-score-kill-help-buffer)
414 (if mimic
(message "%c %c %c" prefix hchar tchar pchar
)
416 (unless (setq temporary
(cadr (assq pchar char-to-perm
)))
418 (error "%c %c %c %c" prefix hchar tchar pchar
)
420 ;; Always kill the score help buffer.
421 (gnus-score-kill-help-buffer))
423 ;; We have all the data, so we enter this score.
424 (setq match
(if (string= (nth 2 entry
) "") ""
425 (gnus-summary-header (or (nth 2 entry
) (nth 1 entry
)))))
427 ;; Modify the match, perhaps.
429 ((equal (nth 1 entry
) "xref")
430 (when (string-match "^Xref: *" match
)
431 (setq match
(substring match
(match-end 0))))
432 (when (string-match "^[^:]* +" match
)
433 (setq match
(substring match
(match-end 0))))))
435 (when (memq type
'(r R regexp Regexp
))
436 (setq match
(regexp-quote match
)))
438 (gnus-summary-score-entry
439 (nth 1 entry
) ; Header
442 (if (eq 's score
) nil score
) ; Score
443 (if (eq 'perm temporary
) ; Temp
446 (not (nth 3 entry
))) ; Prompt
449 (defun gnus-score-insert-help (string alist idx
)
450 (setq gnus-score-help-winconf
(current-window-configuration))
452 (set-buffer (get-buffer-create "*Score Help*"))
453 (buffer-disable-undo (current-buffer))
454 (delete-windows-on (current-buffer))
456 (insert string
":\n\n")
461 ;; find the longest string to display
463 (setq n
(length (nth idx
(car list
))))
466 (setq list
(cdr list
)))
467 (setq max
(+ max
4)) ; %c, `:', SPACE, a SPACE at end
468 (setq n
(/ (1- (window-width)) max
)) ; items per line
469 (setq width
(/ (1- (window-width)) n
)) ; width of each item
470 ;; insert `n' items, each in a field of width `width'
475 (delete-char -
1) ; the `\n' takes a char
477 (setq pad
(- width
3))
478 (setq format
(concat "%c: %-" (int-to-string pad
) "s"))
479 (insert (format format
(caar alist
) (nth idx
(car alist
))))
480 (setq alist
(cdr alist
))
482 ;; display ourselves in a small window at the bottom
483 (gnus-appt-select-lowest-window)
485 (pop-to-buffer "*Score Help*")
486 (let ((window-min-height 1))
487 (shrink-window-if-larger-than-buffer))
488 (select-window (get-buffer-window gnus-summary-buffer
))))
490 (defun gnus-summary-header (header &optional no-err
)
491 ;; Return HEADER for current articles, or error.
492 (let ((article (gnus-summary-article-number))
495 (if (and (setq headers
(gnus-summary-article-header article
))
497 (aref headers
(nth 1 (assoc header gnus-header-index
)))
500 (error "Pseudo-articles can't be scored")))
502 (error "No article on current line")
505 (defun gnus-newsgroup-score-alist ()
507 (let ((param-file (gnus-group-get-parameter
508 gnus-newsgroup-name
'score-file
)))
510 (gnus-score-load param-file
)))
512 (gnus-score-file-name gnus-newsgroup-name
)))
515 (defsubst gnus-score-get
(symbol &optional alist
)
516 ;; Get SYMBOL's definition in ALIST.
520 (gnus-newsgroup-score-alist)))))
522 (defun gnus-summary-score-entry
523 (header match type score date
&optional prompt silent
)
524 "Enter score file entry.
525 HEADER is the header being scored.
526 MATCH is the string we are looking for.
527 TYPE is the match type: substring, regexp, exact, fuzzy.
528 SCORE is the score to add.
529 DATE is the expire date, or nil for no expire, or 'now for immediate expire.
530 If optional argument `PROMPT' is non-nil, allow user to edit match.
531 If optional argument `SILENT' is nil, show effect of score entry."
533 (list (completing-read "Header: "
535 (lambda (x) (fboundp (nth 2 x
)))
537 (read-string "Match: ")
538 (if (y-or-n-p "Use regexp match? ") 'r
's
)
539 (and current-prefix-arg
540 (prefix-numeric-value current-prefix-arg
))
541 (cond ((not (y-or-n-p "Add to score file? "))
543 ((y-or-n-p "Expire kill? ")
544 (current-time-string))
546 ;; Regexp is the default type.
547 (if (eq type t
) (setq type
'r
))
548 ;; Simplify matches...
549 (cond ((or (eq type
'r
) (eq type
's
) (eq type nil
))
550 (setq match
(if match
(gnus-simplify-subject-re match
) "")))
552 (setq match
(gnus-simplify-subject-fuzzy match
))))
553 (let ((score (gnus-score-default score
))
554 (header (downcase header
))
556 (and prompt
(setq match
(read-string
557 (format "Match %s on %s, %s: "
558 (cond ((eq date
'now
)
564 (if (< score
0) "lower" "raise"))
566 (int-to-string match
)
569 ;; If this is an integer comparison, we transform from string to int.
570 (and (eq (nth 2 (assoc header gnus-header-index
)) 'gnus-score-integer
)
571 (setq match
(string-to-int match
)))
573 (unless (eq date
'now
)
574 ;; Add the score entry to the score file.
575 (when (= score gnus-score-interactive-default-score
)
577 (let ((old (gnus-score-get header
))
581 (type (list match score
(and date
(gnus-day-number date
)) type
))
582 (date (list match score
(gnus-day-number date
)))
583 (score (list match score
))
585 ;; We see whether we can collapse some score entries.
586 ;; This isn't quite correct, because there may be more elements
587 ;; later on with the same key that have matching elems... Hm.
589 (setq elem
(assoc match old
))
590 (eq (nth 3 elem
) (nth 3 new
))
591 (or (and (numberp (nth 2 elem
)) (numberp (nth 2 new
)))
592 (and (not (nth 2 elem
)) (not (nth 2 new
)))))
593 ;; Yup, we just add this new score to the old elem.
594 (setcar (cdr elem
) (+ (or (nth 1 elem
)
595 gnus-score-interactive-default-score
)
597 gnus-score-interactive-default-score
)))
598 ;; Nope, we have to add a new elem.
599 (gnus-score-set header
(if old
(cons new old
) (list new
))))
600 (gnus-score-set 'touched
'(t))))
602 ;; Score the current buffer.
604 (if (and (>= (nth 1 (assoc header gnus-header-index
)) 0)
605 (eq (nth 2 (assoc header gnus-header-index
))
607 (gnus-summary-score-effect header match type score
)
608 (gnus-summary-rescore)))
610 ;; Return the new scoring rule.
613 (defun gnus-summary-score-effect (header match type score
)
614 "Simulate the effect of a score file entry.
615 HEADER is the header being scored.
616 MATCH is the string we are looking for.
617 TYPE is a flag indicating if it is a regexp or substring.
618 SCORE is the score to add."
619 (interactive (list (completing-read "Header: "
621 (lambda (x) (fboundp (nth 2 x
)))
623 (read-string "Match: ")
624 (y-or-n-p "Use regexp match? ")
625 (prefix-numeric-value current-prefix-arg
)))
627 (or (and (stringp match
) (> (length match
) 0))
629 (goto-char (point-min))
630 (let ((regexp (cond ((eq type
'f
)
631 (gnus-simplify-subject-fuzzy match
))
635 (concat "\\`" (regexp-quote match
) "\\'"))
637 (regexp-quote match
)))))
639 (let ((content (gnus-summary-header header
'noerr
))
640 (case-fold-search t
))
643 (string-equal (gnus-simplify-subject-fuzzy content
)
645 (string-match regexp content
))
646 (gnus-summary-raise-score score
))))
647 (beginning-of-line 2)))))
649 (defun gnus-summary-score-crossposting (score date
)
650 ;; Enter score file entry for current crossposting.
651 ;; SCORE is the score to add.
652 ;; DATE is the expire date.
653 (let ((xref (gnus-summary-header "xref"))
656 (or xref
(error "This article is not crossposted"))
657 (while (string-match " \\([^ \t]+\\):" xref start
)
658 (setq start
(match-end 0))
661 (substring xref
(match-beginning 1) (match-end 1)))
662 gnus-newsgroup-name
))
663 (gnus-summary-score-entry
664 "xref" (concat " " group
":") nil score date t
)))))
671 ;; All score code written by Per Abrahamsen <abraham@iesd.auc.dk>.
673 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
674 (defun gnus-score-set-mark-below (score)
675 "Automatically mark articles with score below SCORE as read."
677 (list (or (and current-prefix-arg
(prefix-numeric-value current-prefix-arg
))
678 (string-to-int (read-string "Mark below: ")))))
679 (setq score
(or score gnus-summary-default-score
0))
680 (gnus-score-set 'mark
(list score
))
681 (gnus-score-set 'touched
'(t))
682 (setq gnus-summary-mark-below score
)
683 (gnus-score-update-lines))
685 (defun gnus-score-update-lines ()
686 "Update all lines in the summary buffer."
688 (goto-char (point-min))
690 (gnus-summary-update-line)
693 (defun gnus-score-update-all-lines ()
694 "Update all lines in the summary buffer, even the hidden ones."
696 (goto-char (point-min))
699 (when (gnus-summary-show-thread)
700 (push (point) hidden
))
701 (gnus-summary-update-line)
703 ;; Re-hide the hidden threads.
705 (goto-char (pop hidden
))
706 (gnus-summary-hide-thread)))))
708 (defun gnus-score-set-expunge-below (score)
709 "Automatically expunge articles with score below SCORE."
711 (list (or (and current-prefix-arg
(prefix-numeric-value current-prefix-arg
))
712 (string-to-int (read-string "Expunge below: ")))))
713 (setq score
(or score gnus-summary-default-score
0))
714 (gnus-score-set 'expunge
(list score
))
715 (gnus-score-set 'touched
'(t)))
717 (defun gnus-score-followup-article (&optional score
)
718 "Add SCORE to all followups to the article in the current buffer."
720 (setq score
(gnus-score-default score
))
721 (when (gnus-buffer-live-p gnus-summary-buffer
)
723 (set-buffer gnus-summary-buffer
)
725 (goto-char (point-min))
726 (let ((id (mail-fetch-field "message-id")))
728 (gnus-summary-score-entry
729 "references" (concat id
"[ \t]*$") 'r
730 score
(current-time-string) nil t
)))))))
732 (defun gnus-score-followup-thread (&optional score
)
733 "Add SCORE to all later articles in the thread the current buffer is part of."
735 (setq score
(gnus-score-default score
))
736 (when (gnus-buffer-live-p gnus-summary-buffer
)
738 (set-buffer gnus-summary-buffer
)
740 (goto-char (point-min))
741 (let ((id (mail-fetch-field "message-id")))
743 (gnus-summary-score-entry
745 score
(current-time-string))))))))
747 (defun gnus-score-set (symbol value
&optional alist
)
748 ;; Set SYMBOL to VALUE in ALIST.
752 (gnus-newsgroup-score-alist)))
753 (entry (assoc symbol alist
)))
754 (cond ((gnus-score-get 'read-only alist
)
755 ;; This is a read-only score file, so we do nothing.
758 (setcdr entry value
))
760 (error "Empty alist"))
763 (cons (cons symbol value
) (cdr alist
)))))))
765 (defun gnus-summary-raise-score (n)
766 "Raise the score of the current article by N."
768 (gnus-set-global-variables)
769 (gnus-summary-set-score (+ (gnus-summary-article-score)
770 (or n gnus-score-interactive-default-score
))))
772 (defun gnus-summary-set-score (n)
773 "Set the score of the current article to N."
775 (gnus-set-global-variables)
777 (gnus-summary-show-thread)
778 (let ((buffer-read-only nil
))
780 (gnus-summary-update-mark
781 (if (= n
(or gnus-summary-default-score
0)) ?
782 (if (< n
(or gnus-summary-default-score
0))
783 gnus-score-below-mark gnus-score-over-mark
)) 'score
))
784 (let* ((article (gnus-summary-article-number))
785 (score (assq article gnus-newsgroup-scored
)))
786 (if score
(setcdr score n
)
787 (setq gnus-newsgroup-scored
788 (cons (cons article n
) gnus-newsgroup-scored
))))
789 (gnus-summary-update-line)))
791 (defun gnus-summary-current-score ()
792 "Return the score of the current article."
794 (gnus-set-global-variables)
795 (gnus-message 1 "%s" (gnus-summary-article-score)))
797 (defun gnus-score-change-score-file (file)
798 "Change current score alist."
800 (list (read-file-name "Change to score file: " gnus-kill-files-directory
)))
801 (gnus-score-load-file file
)
802 (gnus-set-mode-line 'summary
))
804 (defvar gnus-score-edit-exit-function
)
805 (defun gnus-score-edit-current-scores (file)
806 "Edit the current score alist."
807 (interactive (list gnus-current-score-file
))
808 (let ((winconf (current-window-configuration)))
809 (and (buffer-name gnus-summary-buffer
) (gnus-score-save))
810 (gnus-make-directory (file-name-directory file
))
811 (setq gnus-score-edit-buffer
(find-file-noselect file
))
812 (gnus-configure-windows 'edit-score
)
814 (setq gnus-score-edit-exit-function
'gnus-score-edit-done
)
815 (make-local-variable 'gnus-prev-winconf
)
816 (setq gnus-prev-winconf winconf
))
818 4 (substitute-command-keys
819 "\\<gnus-score-mode-map>\\[gnus-score-edit-exit] to save edits")))
821 (defun gnus-score-edit-file (file)
824 (list (read-file-name "Edit score file: " gnus-kill-files-directory
)))
825 (gnus-make-directory (file-name-directory file
))
826 (and (buffer-name gnus-summary-buffer
) (gnus-score-save))
827 (let ((winconf (current-window-configuration)))
828 (setq gnus-score-edit-buffer
(find-file-noselect file
))
829 (gnus-configure-windows 'edit-score
)
831 (setq gnus-score-edit-exit-function
'gnus-score-edit-done
)
832 (make-local-variable 'gnus-prev-winconf
)
833 (setq gnus-prev-winconf winconf
))
835 4 (substitute-command-keys
836 "\\<gnus-score-mode-map>\\[gnus-score-edit-exit] to save edits")))
838 (defun gnus-score-load-file (file)
839 ;; Load score file FILE. Returns a list a retrieved score-alists.
840 (let* ((file (expand-file-name
841 (or (and (string-match
842 (concat "^" (expand-file-name
843 gnus-kill-files-directory
))
844 (expand-file-name file
))
846 (concat (file-name-as-directory gnus-kill-files-directory
)
848 (cached (assoc file gnus-score-cache
))
849 (global (member file gnus-internal-global-score-files
))
852 ;; The score file was already loaded.
853 (setq alist
(cdr cached
))
854 ;; We load the score file.
855 (setq gnus-score-alist nil
)
856 (setq alist
(gnus-score-load-score-alist file
))
857 ;; We add '(touched) to the alist to signify that it hasn't been
859 (or (assq 'touched alist
) (setq alist
(cons (list 'touched nil
) alist
)))
860 ;; If it is a global score file, we make it read-only.
862 (not (assq 'read-only alist
))
863 (setq alist
(cons (list 'read-only t
) alist
)))
864 (setq gnus-score-cache
865 (cons (cons file alist
) gnus-score-cache
)))
869 ;; Downcase all header names.
870 (when (stringp (caar a
))
871 (setcar (car a
) (downcase (caar a
)))
874 ;; If there are actual scores in the alist, we add it to the
875 ;; return value of this function.
877 (setq lists
(list alist
))))
878 ;; Treat the other possible atoms in the score alist.
879 (let ((mark (car (gnus-score-get 'mark alist
)))
880 (expunge (car (gnus-score-get 'expunge alist
)))
881 (mark-and-expunge (car (gnus-score-get 'mark-and-expunge alist
)))
882 (files (gnus-score-get 'files alist
))
883 (exclude-files (gnus-score-get 'exclude-files alist
))
884 (orphan (car (gnus-score-get 'orphan alist
)))
885 (adapt (gnus-score-get 'adapt alist
))
886 (thread-mark-and-expunge
887 (car (gnus-score-get 'thread-mark-and-expunge alist
)))
888 (adapt-file (car (gnus-score-get 'adapt-file alist
)))
889 (local (gnus-score-get 'local alist
))
890 (eval (car (gnus-score-get 'eval alist
))))
891 ;; We do not respect eval and files atoms from global score
893 (and files
(not global
)
894 (setq lists
(apply 'append lists
895 (mapcar (lambda (file)
896 (gnus-score-load-file file
))
897 (if adapt-file
(cons adapt-file files
)
899 (and eval
(not global
) (eval eval
))
900 ;; We then expand any exclude-file directives.
901 (setq gnus-scores-exclude-files
905 (expand-file-name sfile
(file-name-directory file
)))
906 exclude-files
) gnus-scores-exclude-files
))
910 (set-buffer gnus-summary-buffer
)
912 (and (consp (car local
))
913 (symbolp (caar local
))
915 (make-local-variable (caar local
))
916 (set (caar local
) (nth 1 (car local
)))))
917 (setq local
(cdr local
)))))
918 (if orphan
(setq gnus-orphan-score orphan
))
919 (setq gnus-adaptive-score-alist
920 (cond ((equal adapt
'(t))
921 (setq gnus-newsgroup-adaptive t
)
922 gnus-default-adaptive-score-alist
)
923 ((equal adapt
'(ignore))
924 (setq gnus-newsgroup-adaptive nil
))
926 (setq gnus-newsgroup-adaptive t
)
929 ;;(setq gnus-newsgroup-adaptive gnus-use-adaptive-scoring)
930 gnus-default-adaptive-score-alist
)))
931 (setq gnus-thread-expunge-below
932 (or thread-mark-and-expunge gnus-thread-expunge-below
))
933 (setq gnus-summary-mark-below
934 (or mark mark-and-expunge gnus-summary-mark-below
))
935 (setq gnus-summary-expunge-below
936 (or expunge mark-and-expunge gnus-summary-expunge-below
))
937 (setq gnus-newsgroup-adaptive-score-file
938 (or adapt-file gnus-newsgroup-adaptive-score-file
)))
939 (setq gnus-current-score-file file
)
940 (setq gnus-score-alist alist
)
943 (defun gnus-score-load (file)
945 (let ((cache (assoc file gnus-score-cache
)))
947 (setq gnus-score-alist
(cdr cache
))
948 (setq gnus-score-alist nil
)
949 (gnus-score-load-score-alist file
)
951 (setq gnus-score-alist
(copy-alist '((touched nil
)))))
952 (setq gnus-score-cache
953 (cons (cons file gnus-score-alist
) gnus-score-cache
)))))
955 (defun gnus-score-remove-from-cache (file)
956 (setq gnus-score-cache
957 (delq (assoc file gnus-score-cache
) gnus-score-cache
)))
959 (defun gnus-score-load-score-alist (file)
961 (if (not (file-readable-p file
))
962 (setq gnus-score-alist nil
)
964 (gnus-set-work-buffer)
965 (insert-file-contents file
)
966 (goto-char (point-min))
967 ;; Only do the loading if the score file isn't empty.
968 (when (save-excursion (re-search-forward "[()0-9a-zA-Z]" nil t
))
971 (read (current-buffer))
974 (gnus-message 3 "Problem with score file %s" file
)
978 (if (eq (car alist
) 'setq
)
979 ;; This is an old-style score file.
980 (setq gnus-score-alist
(gnus-score-transform-old-to-new alist
))
981 (setq gnus-score-alist alist
))
982 ;; Check the syntax of the score file.
983 (setq gnus-score-alist
984 (gnus-score-check-syntax gnus-score-alist file
)))))
986 (defun gnus-score-check-syntax (alist file
)
987 "Check the syntax of the score ALIST."
992 (gnus-message 1 "Score file is not a list: %s" file
)
998 (while (and a
(not err
))
1002 ((not (listp (car a
)))
1003 (format "Illegal score element %s in %s" (car a
) file
))
1006 ((not (listp (setq sr
(cdar a
))))
1007 (format "Illegal header match %s in %s" (nth 1 (car a
)) file
))
1009 (setq type
(caar a
))
1010 (while (and sr
(not err
))
1015 ((if (member (downcase type
) '("lines" "chars"))
1016 (not (numberp (car s
)))
1017 (not (stringp (car s
))))
1018 (format "Illegal match %s in %s" (car s
) file
))
1019 ((and (cadr s
) (not (integerp (cadr s
))))
1020 (format "Non-integer score %s in %s" (cadr s
) file
))
1021 ((and (caddr s
) (not (integerp (caddr s
))))
1022 (format "Non-integer date %s in %s" (caddr s
) file
))
1023 ((and (cadddr s
) (not (symbolp (cadddr s
))))
1024 (format "Non-symbol match type %s in %s" (cadddr s
) file
)))))
1030 (gnus-message 3 err
)
1035 (defun gnus-score-transform-old-to-new (alist)
1036 (let* ((alist (nth 2 alist
))
1038 (if (eq (car alist
) 'quote
)
1039 (setq alist
(nth 1 alist
)))
1041 (setq entry
(car alist
))
1042 (if (stringp (car entry
))
1043 (let ((scor (cdr entry
)))
1044 (setq out
(cons entry out
))
1047 (list (caar scor
) (nth 2 (car scor
))
1048 (and (nth 3 (car scor
))
1049 (gnus-day-number (nth 3 (car scor
))))
1050 (if (nth 1 (car scor
)) 'r
's
)))
1051 (setq scor
(cdr scor
))))
1052 (setq out
(cons (if (not (listp (cdr entry
)))
1053 (list (car entry
) (cdr entry
))
1056 (setq alist
(cdr alist
)))
1057 (cons (list 'touched t
) (nreverse out
))))
1059 (defun gnus-score-save ()
1060 ;; Save all score information.
1061 (let ((cache gnus-score-cache
))
1063 (setq gnus-score-alist nil
)
1064 (set-buffer (get-buffer-create "*Score*"))
1065 (buffer-disable-undo (current-buffer))
1066 (let (entry score file
)
1068 (setq entry
(car cache
)
1072 (if (or (not (equal (gnus-score-get 'touched score
) '(t)))
1073 (gnus-score-get 'read-only score
)
1074 (and (file-exists-p file
)
1075 (not (file-writable-p file
))))
1077 (setq score
(setcdr entry
(delq (assq 'touched score
) score
)))
1079 (let (emacs-lisp-mode-hook)
1081 (concat (regexp-quote gnus-adaptive-file-suffix
)
1083 ;; This is an adaptive score file, so we do not run
1084 ;; it through `pp'. These files can get huge, and
1085 ;; are not meant to be edited by human hands.
1086 (prin1 score
(current-buffer))
1087 ;; This is a normal score file, so we print it very
1089 (pp score
(current-buffer))))
1090 (if (not (gnus-make-directory (file-name-directory file
)))
1092 ;; If the score file is empty, we delete it.
1093 (if (zerop (buffer-size))
1095 ;; There are scores, so we write the file.
1096 (when (file-writable-p file
)
1097 (write-region (point-min) (point-max) file nil
'silent
)
1098 (and gnus-score-after-write-file-function
1099 (funcall gnus-score-after-write-file-function file
)))))
1100 (and gnus-score-uncacheable-files
1101 (string-match gnus-score-uncacheable-files file
)
1102 (gnus-score-remove-from-cache file
)))))
1103 (kill-buffer (current-buffer)))))
1105 (defun gnus-score-headers (score-files &optional trace
)
1106 ;; Score `gnus-newsgroup-headers'.
1108 ;; PLM: probably this is not the best place to clear orphan-score
1109 (setq gnus-orphan-score nil
)
1110 (setq gnus-scores-articles nil
)
1111 (setq gnus-scores-exclude-files nil
)
1112 ;; Load the score files.
1114 (if (stringp (car score-files
))
1115 ;; It is a string, which means that it's a score file name,
1116 ;; so we load the score file and add the score alist to
1117 ;; the list of alists.
1118 (setq scores
(nconc (gnus-score-load-file (car score-files
)) scores
))
1119 ;; It is an alist, so we just add it to the list directly.
1120 (setq scores
(nconc (car score-files
) scores
)))
1121 (setq score-files
(cdr score-files
)))
1122 ;; Prune the score files that are to be excluded, if any.
1123 (when gnus-scores-exclude-files
1127 (and (setq c
(rassq (car s
) gnus-score-cache
))
1128 (member (car c
) gnus-scores-exclude-files
)
1129 (setq scores
(delq (car s
) scores
)))
1136 (when (and gnus-summary-default-score
1138 (let* ((entries gnus-header-index
)
1139 (now (gnus-day-number (current-time-string)))
1140 (expire (and gnus-score-expiry-days
1141 (- now gnus-score-expiry-days
)))
1142 (headers gnus-newsgroup-headers
)
1143 (current-score-file gnus-current-score-file
)
1145 (gnus-message 5 "Scoring...")
1146 ;; Create articles, an alist of the form `(HEADER . SCORE)'.
1147 (while (setq header
(pop headers
))
1148 ;; WARNING: The assq makes the function O(N*S) while it could
1149 ;; be written as O(N+S), where N is (length gnus-newsgroup-headers)
1150 ;; and S is (length gnus-newsgroup-scored).
1151 (or (assq (mail-header-number header
) gnus-newsgroup-scored
)
1152 (setq gnus-scores-articles
;Total of 2 * N cons-cells used.
1153 (cons (cons header
(or gnus-summary-default-score
0))
1154 gnus-scores-articles
))))
1157 (set-buffer (get-buffer-create "*Headers*"))
1158 (buffer-disable-undo (current-buffer))
1160 ;; Set the global variant of this variable.
1161 (setq gnus-current-score-file current-score-file
)
1163 (when gnus-orphan-score
1164 (setq gnus-score-index
1165 (nth 1 (assoc "references" gnus-header-index
)))
1166 (gnus-score-orphans gnus-orphan-score
))
1167 ;; Run each header through the score process.
1169 (setq entry
(pop entries
)
1170 header
(nth 0 entry
)
1171 gnus-score-index
(nth 1 (assoc header gnus-header-index
)))
1172 (when (< 0 (apply 'max
(mapcar
1174 (length (gnus-score-get header score
)))
1176 ;; Call the scoring function for this type of "header".
1177 (when (setq new
(funcall (nth 2 entry
) scores header
1180 ;; Remove the buffer.
1181 (kill-buffer (current-buffer)))
1183 ;; Add articles to `gnus-newsgroup-scored'.
1184 (while gnus-scores-articles
1185 (or (= gnus-summary-default-score
(cdar gnus-scores-articles
))
1186 (setq gnus-newsgroup-scored
1187 (cons (cons (mail-header-number
1188 (caar gnus-scores-articles
))
1189 (cdar gnus-scores-articles
))
1190 gnus-newsgroup-scored
)))
1191 (setq gnus-scores-articles
(cdr gnus-scores-articles
)))
1193 (gnus-message 5 "Scoring...done"))))))
1196 (defun gnus-get-new-thread-ids (articles)
1197 (let ((index (nth 1 (assoc "message-id" gnus-header-index
)))
1198 (refind gnus-score-index
)
1199 id-list art this tref
)
1201 (setq art
(car articles
)
1202 this
(aref (car art
) index
)
1203 tref
(aref (car art
) refind
)
1204 articles
(cdr articles
))
1205 (if (string-equal tref
"") ;no references line
1206 (setq id-list
(cons this id-list
))))
1209 ;; Orphan functions written by plm@atcmp.nl (Peter Mutsaers).
1210 (defun gnus-score-orphans (score)
1211 (let ((new-thread-ids (gnus-get-new-thread-ids gnus-scores-articles
))
1212 alike articles art arts this last this-id
)
1214 (setq gnus-scores-articles
(sort gnus-scores-articles
'gnus-score-string
<)
1215 articles gnus-scores-articles
)
1217 ;;more or less the same as in gnus-score-string
1220 (setq art
(car articles
)
1221 this
(aref (car art
) gnus-score-index
)
1222 articles
(cdr articles
))
1223 ;;completely skip if this is empty (not a child, so not an orphan)
1224 (if (not (string= this
""))
1225 (if (equal last this
)
1226 ;; O(N*H) cons-cells used here, where H is the number of
1228 (setq alike
(cons art alike
))
1231 ;; Insert the line, with a text property on the
1232 ;; terminating newline referring to the articles with
1235 (put-text-property (1- (point)) (point) 'articles alike
)))
1236 (setq alike
(list art
)
1238 (and last
; Bwadr, duplicate code.
1241 (put-text-property (1- (point)) (point) 'articles alike
)))
1243 ;; PLM: now delete those lines that contain an entry from new-thread-ids
1244 (while new-thread-ids
1245 (setq this-id
(car new-thread-ids
)
1246 new-thread-ids
(cdr new-thread-ids
))
1247 (goto-char (point-min))
1248 (while (search-forward this-id nil t
)
1249 ;; found a match. remove this line
1253 ;; now for each line: update its articles with score by moving to
1254 ;; every end-of-line in the buffer and read the articles property
1255 (goto-char (point-min))
1258 (setq arts
(get-text-property (point) 'articles
))
1260 (setq art
(car arts
)
1262 (setcdr art
(+ score
(cdr art
))))
1266 (defun gnus-score-integer (scores header now expire
&optional trace
)
1267 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
1272 (setq alist
(car scores
)
1274 entries
(assoc header alist
))
1275 (while (cdr entries
) ;First entry is the header index.
1276 (let* ((rest (cdr entries
))
1278 (match (nth 0 kill
))
1279 (type (or (nth 3 kill
) '>))
1280 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1283 (match-func (if (or (eq type
'>) (eq type
'<) (eq type
'<=)
1284 (eq type
'>=) (eq type
'=))
1286 (error "Illegal match type: %s" type
)))
1287 (articles gnus-scores-articles
))
1288 ;; Instead of doing all the clever stuff that
1289 ;; `gnus-score-string' does to minimize searches and stuff,
1290 ;; I will assume that people generally will put so few
1291 ;; matches on numbers that any cleverness will take more
1292 ;; time than one would gain.
1294 (and (funcall match-func
1295 (or (aref (caar articles
) gnus-score-index
) 0)
1298 (and trace
(setq gnus-score-trace
1301 (car-safe (rassq alist gnus-score-cache
))
1305 (setcdr (car articles
) (+ score
(cdar articles
)))))
1306 (setq articles
(cdr articles
)))
1307 ;; Update expire date
1308 (cond ((null date
)) ;Permanent entry.
1309 ((and found gnus-update-score-entry-dates
) ;Match, update date.
1310 (gnus-score-set 'touched
'(t) alist
)
1311 (setcar (nthcdr 2 kill
) now
))
1312 ((and expire
(< date expire
)) ;Old entry, remove.
1313 (gnus-score-set 'touched
'(t) alist
)
1314 (setcdr entries
(cdr rest
))
1315 (setq rest entries
)))
1316 (setq entries rest
)))))
1319 (defun gnus-score-date (scores header now expire
&optional trace
)
1320 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
1325 (setq alist
(car scores
)
1327 entries
(assoc header alist
))
1328 (while (cdr entries
) ;First entry is the header index.
1329 (let* ((rest (cdr entries
))
1331 (match (timezone-make-date-sortable (nth 0 kill
)))
1332 (type (or (nth 3 kill
) 'before
))
1333 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1337 (cond ((eq type
'after
) 'string
<)
1338 ((eq type
'before
) 'gnus-string
>)
1339 ((eq type
'at
) 'string
=)
1340 (t (error "Illegal match type: %s" type
))))
1341 (articles gnus-scores-articles
)
1343 ;; Instead of doing all the clever stuff that
1344 ;; `gnus-score-string' does to minimize searches and stuff,
1345 ;; I will assume that people generally will put so few
1346 ;; matches on numbers that any cleverness will take more
1347 ;; time than one would gain.
1350 (setq l
(aref (caar articles
) gnus-score-index
))
1351 (funcall match-func match
(timezone-make-date-sortable l
))
1353 (and trace
(setq gnus-score-trace
1356 (car-safe (rassq alist gnus-score-cache
))
1360 (setcdr (car articles
) (+ score
(cdar articles
)))))
1361 (setq articles
(cdr articles
)))
1362 ;; Update expire date
1363 (cond ((null date
)) ;Permanent entry.
1364 ((and found gnus-update-score-entry-dates
) ;Match, update date.
1365 (gnus-score-set 'touched
'(t) alist
)
1366 (setcar (nthcdr 2 kill
) now
))
1367 ((and expire
(< date expire
)) ;Old entry, remove.
1368 (gnus-score-set 'touched
'(t) alist
)
1369 (setcdr entries
(cdr rest
))
1370 (setq rest entries
)))
1371 (setq entries rest
)))))
1374 (defun gnus-score-body (scores header now expire
&optional trace
)
1376 (set-buffer nntp-server-buffer
)
1377 (setq gnus-scores-articles
1378 (sort gnus-scores-articles
1380 (< (mail-header-number (car a1
))
1381 (mail-header-number (car a2
))))))
1383 (let* ((buffer-read-only nil
)
1384 (articles gnus-scores-articles
)
1386 (request-func (cond ((string= "head" header
)
1388 ((string= "body" header
)
1390 (t 'gnus-request-article
)))
1391 entries alist ofunc article last
)
1393 (while (cdr articles
)
1394 (setq articles
(cdr articles
)))
1395 (setq last
(mail-header-number (caar articles
)))
1396 (setq articles gnus-scores-articles
)
1397 ;; Not all backends support partial fetching. In that case,
1398 ;; we just fetch the entire article.
1399 (or (gnus-check-backend-function
1400 (and (string-match "^gnus-" (symbol-name request-func
))
1401 (intern (substring (symbol-name request-func
)
1403 gnus-newsgroup-name
)
1405 (setq ofunc request-func
)
1406 (setq request-func
'gnus-request-article
)))
1408 (setq article
(mail-header-number (caar articles
)))
1409 (gnus-message 7 "Scoring on article %s of %s..." article last
)
1410 (when (funcall request-func article gnus-newsgroup-name
)
1412 (goto-char (point-min))
1413 ;; If just parts of the article is to be searched, but the
1414 ;; backend didn't support partial fetching, we just narrow
1415 ;; to the relevant parts.
1417 (if (eq ofunc
'gnus-request-head
)
1420 (or (search-forward "\n\n" nil t
) (point-max)))
1422 (or (search-forward "\n\n" nil t
) (point))
1424 (setq scores all-scores
)
1427 (setq alist
(car scores
)
1429 entries
(assoc header alist
))
1430 (while (cdr entries
) ;First entry is the header index.
1431 (let* ((rest (cdr entries
))
1433 (match (nth 0 kill
))
1434 (type (or (nth 3 kill
) 's
))
1435 (score (or (nth 1 kill
)
1436 gnus-score-interactive-default-score
))
1440 (not (or (eq type
'R
) (eq type
'S
)
1441 (eq type
'Regexp
) (eq type
'String
))))
1443 (cond ((or (eq type
'r
) (eq type
'R
)
1444 (eq type
'regexp
) (eq type
'Regexp
))
1446 ((or (eq type
's
) (eq type
'S
)
1447 (eq type
'string
) (eq type
'String
))
1450 (error "Illegal match type: %s" type
)))))
1451 (goto-char (point-min))
1452 (if (funcall search-func match nil t
)
1453 ;; Found a match, update scores.
1455 (setcdr (car articles
) (+ score
(cdar articles
)))
1457 (and trace
(setq gnus-score-trace
1461 (rassq alist gnus-score-cache
))
1463 gnus-score-trace
)))))
1464 ;; Update expire date
1466 ((null date
)) ;Permanent entry.
1467 ((and found gnus-update-score-entry-dates
) ;Match, update date.
1468 (gnus-score-set 'touched
'(t) alist
)
1469 (setcar (nthcdr 2 kill
) now
))
1470 ((and expire
(< date expire
)) ;Old entry, remove.
1471 (gnus-score-set 'touched
'(t) alist
)
1472 (setcdr entries
(cdr rest
))
1473 (setq rest entries
)))
1474 (setq entries rest
)))))
1475 (setq articles
(cdr articles
)))))))
1478 (defun gnus-score-followup (scores header now expire
&optional trace thread
)
1479 ;; Insert the unique article headers in the buffer.
1480 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
1481 (current-score-file gnus-current-score-file
)
1483 ;; gnus-score-index is used as a free variable.
1484 alike last this art entries alist articles
1487 ;; Change score file to the adaptive score file. All entries that
1488 ;; this function makes will be put into this file.
1490 (set-buffer gnus-summary-buffer
)
1491 (gnus-score-load-file
1492 (or gnus-newsgroup-adaptive-score-file
1493 (gnus-score-file-name
1494 gnus-newsgroup-name gnus-adaptive-file-suffix
))))
1496 (setq gnus-scores-articles
(sort gnus-scores-articles
'gnus-score-string
<)
1497 articles gnus-scores-articles
)
1501 (setq art
(car articles
)
1502 this
(aref (car art
) gnus-score-index
)
1503 articles
(cdr articles
))
1504 (if (equal last this
)
1505 (setq alike
(cons art alike
))
1509 (put-text-property (1- (point)) (point) 'articles alike
)))
1510 (setq alike
(list art
)
1512 (and last
; Bwadr, duplicate code.
1515 (put-text-property (1- (point)) (point) 'articles alike
)))
1519 (setq alist
(car scores
)
1521 entries
(assoc header alist
))
1522 (while (cdr entries
) ;First entry is the header index.
1523 (let* ((rest (cdr entries
))
1525 (match (nth 0 kill
))
1526 (type (or (nth 3 kill
) 's
))
1527 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1530 (mt (aref (symbol-name type
) 0))
1532 (not (or (= mt ?R
) (= mt ?S
) (= mt ?E
) (= mt ?F
))))
1535 (cond ((= dmt ?r
) 're-search-forward
)
1536 ((or (= dmt ?e
) (= dmt ?s
) (= dmt ?f
)) 'search-forward
)
1537 (t (error "Illegal match type: %s" type
))))
1539 (goto-char (point-min))
1541 (while (funcall search-func match nil t
)
1542 (and (= (progn (beginning-of-line) (point))
1543 (match-beginning 0))
1544 (= (progn (end-of-line) (point))
1547 (setq found
(setq arts
(get-text-property
1548 (point) 'articles
)))
1549 ;; Found a match, update scores.
1551 (setq art
(car arts
)
1553 (gnus-score-add-followups
1554 (car art
) score all-scores thread
))))
1556 (while (funcall search-func match nil t
)
1558 (setq found
(setq arts
(get-text-property (point) 'articles
)))
1559 ;; Found a match, update scores.
1560 (while (setq art
(pop arts
))
1561 (when (setq new
(gnus-score-add-followups
1562 (car art
) score all-scores thread
))
1564 ;; Update expire date
1565 (cond ((null date
)) ;Permanent entry.
1566 ((and found gnus-update-score-entry-dates
) ;Match, update date.
1567 (gnus-score-set 'touched
'(t) alist
)
1568 (setcar (nthcdr 2 kill
) now
))
1569 ((and expire
(< date expire
)) ;Old entry, remove.
1570 (gnus-score-set 'touched
'(t) alist
)
1571 (setcdr entries
(cdr rest
))
1572 (setq rest entries
)))
1573 (setq entries rest
))))
1574 ;; We change the score file back to the previous one.
1576 (set-buffer gnus-summary-buffer
)
1577 (gnus-score-load-file current-score-file
))
1578 (list (cons "references" news
))))
1580 (defun gnus-score-add-followups (header score scores
&optional thread
)
1581 "Add a score entry to the adapt file."
1583 (set-buffer gnus-summary-buffer
)
1584 (let* ((id (mail-header-id header
))
1585 (scores (car scores
))
1587 ;; Don't enter a score if there already is one.
1588 (while (setq entry
(pop scores
))
1589 (and (equal "references" (car entry
))
1590 (or (null (nth 3 (cadr entry
)))
1591 (eq 's
(nth 3 (cadr entry
))))
1595 (gnus-summary-score-entry
1596 (if thread
"thread" "references")
1597 id
's score
(current-time-string) nil t
)))))
1599 (defun gnus-score-string (score-list header now expire
&optional trace
)
1600 ;; Score ARTICLES according to HEADER in SCORE-LIST.
1601 ;; Update matching entries to NOW and remove unmatched entries older
1604 ;; Insert the unique article headers in the buffer.
1605 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
1606 ;; gnus-score-index is used as a free variable.
1607 alike last this art entries alist articles scores fuzzy
)
1609 ;; Sorting the articles costs os O(N*log N) but will allow us to
1610 ;; only match with each unique header. Thus the actual matching
1611 ;; will be O(M*U) where M is the number of strings to match with,
1612 ;; and U is the number of unique headers. It is assumed (but
1613 ;; untested) this will be a net win because of the large constant
1614 ;; factor involved with string matching.
1615 (setq gnus-scores-articles
(sort gnus-scores-articles
'gnus-score-string
<)
1616 articles gnus-scores-articles
)
1620 (setq art
(car articles
)
1621 this
(aref (car art
) gnus-score-index
)
1622 articles
(cdr articles
))
1623 (if (equal last this
)
1624 ;; O(N*H) cons-cells used here, where H is the number of
1626 (setq alike
(cons art alike
))
1629 ;; Insert the line, with a text property on the
1630 ;; terminating newline referring to the articles with
1633 (put-text-property (1- (point)) (point) 'articles alike
)))
1634 (setq alike
(list art
)
1636 (and last
; Bwadr, duplicate code.
1639 (put-text-property (1- (point)) (point) 'articles alike
)))
1641 ;; Find ordinary matches.
1642 (setq scores score-list
)
1644 (setq alist
(car scores
)
1646 entries
(assoc header alist
))
1647 (while (cdr entries
) ;First entry is the header index.
1648 (let* ((rest (cdr entries
))
1650 (match (nth 0 kill
))
1651 (type (or (nth 3 kill
) 's
))
1652 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1655 (mt (aref (symbol-name type
) 0))
1657 (not (or (= mt ?R
) (= mt ?S
) (= mt ?E
) (= mt ?F
))))
1660 (cond ((= dmt ?r
) 're-search-forward
)
1661 ((or (= dmt ?e
) (= dmt ?s
) (= dmt ?f
)) 'search-forward
)
1662 (t (error "Illegal match type: %s" type
))))
1666 ;; Do non-fuzzy matching.
1667 (goto-char (point-min))
1669 ;; Do exact matching.
1670 (while (and (not (eobp))
1671 (funcall search-func match nil t
))
1672 (and (= (progn (beginning-of-line) (point))
1673 (match-beginning 0))
1674 (= (progn (end-of-line) (point))
1677 (setq found
(setq arts
(get-text-property
1678 (point) 'articles
)))
1679 ;; Found a match, update scores.
1682 (setq art
(car arts
)
1684 (setcdr art
(+ score
(cdr art
)))
1685 (setq gnus-score-trace
1689 (rassq alist gnus-score-cache
))
1693 (setq art
(car arts
)
1695 (setcdr art
(+ score
(cdr art
)))))))
1697 ;; Do regexp and substring matching.
1698 (and (string= match
"") (setq match
"\n"))
1699 (while (and (not (eobp))
1700 (funcall search-func match nil t
))
1701 (goto-char (match-beginning 0))
1703 (setq found
(setq arts
(get-text-property (point) 'articles
)))
1704 ;; Found a match, update scores.
1707 (setq art
(pop arts
))
1708 (setcdr art
(+ score
(cdr art
)))
1710 (car-safe (rassq alist gnus-score-cache
))
1714 (setq art
(pop arts
))
1715 (setcdr art
(+ score
(cdr art
)))))
1717 ;; Update expire date
1719 ((null date
)) ;Permanent entry.
1720 ((and found gnus-update-score-entry-dates
) ;Match, update date.
1721 (gnus-score-set 'touched
'(t) alist
)
1722 (setcar (nthcdr 2 kill
) now
))
1723 ((and expire
(< date expire
)) ;Old entry, remove.
1724 (gnus-score-set 'touched
'(t) alist
)
1725 (setcdr entries
(cdr rest
))
1726 (setq rest entries
))))
1727 (setq entries rest
))))
1729 ;; Find fuzzy matches.
1731 (setq scores score-list
)
1732 (gnus-simplify-buffer-fuzzy)
1734 (setq alist
(car scores
)
1736 entries
(assoc header alist
))
1737 (while (cdr entries
) ;First entry is the header index.
1738 (let* ((rest (cdr entries
))
1740 (match (nth 0 kill
))
1741 (type (or (nth 3 kill
) 's
))
1742 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1745 (mt (aref (symbol-name type
) 0))
1746 (case-fold-search (not (= mt ?F
)))
1750 (goto-char (point-min))
1751 (while (and (not (eobp))
1752 (search-forward match nil t
))
1753 (when (and (= (progn (beginning-of-line) (point))
1754 (match-beginning 0))
1755 (= (progn (end-of-line) (point))
1757 (setq found
(setq arts
(get-text-property
1758 (point) 'articles
)))
1759 ;; Found a match, update scores.
1762 (setq art
(pop arts
))
1763 (setcdr art
(+ score
(cdr art
)))
1765 (car-safe (rassq alist gnus-score-cache
))
1769 (setq art
(pop arts
))
1770 (setcdr art
(+ score
(cdr art
))))))
1772 ;; Update expire date
1775 ((null date
)) ;Permanent entry.
1776 ((and found gnus-update-score-entry-dates
) ;Match, update date.
1777 (gnus-score-set 'touched
'(t) alist
)
1778 (setcar (nthcdr 2 kill
) now
))
1779 ((and expire
(< date expire
)) ;Old entry, remove.
1780 (gnus-score-set 'touched
'(t) alist
)
1781 (setcdr entries
(cdr rest
))
1782 (setq rest entries
)))))
1783 (setq entries rest
))))))
1786 (defun gnus-score-string< (a1 a2
)
1787 ;; Compare headers in articles A2 and A2.
1788 ;; The header index used is the free variable `gnus-score-index'.
1789 (string-lessp (aref (car a1
) gnus-score-index
)
1790 (aref (car a2
) gnus-score-index
)))
1792 (defun gnus-score-build-cons (article)
1793 ;; Build a `gnus-newsgroup-scored' type cons from ARTICLE.
1794 (cons (mail-header-number (car article
)) (cdr article
)))
1796 (defun gnus-current-score-file-nondirectory (&optional score-file
)
1797 (let ((score-file (or score-file gnus-current-score-file
)))
1799 (gnus-short-group-name (file-name-nondirectory score-file
))
1802 (defun gnus-score-adaptive ()
1804 (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist
))
1806 (date (current-time-string))
1807 (data gnus-newsgroup-data
)
1809 ;; First we transform the adaptive rule alist into something
1810 ;; that's faster to process.
1812 (setq elem
(car malist
))
1813 (if (symbolp (car elem
))
1814 (setcar elem
(symbol-value (car elem
))))
1815 (setq elem
(cdr elem
))
1818 (cons (if (eq (caar elem
) 'followup
)
1820 (symbol-name (caar elem
)))
1825 (concat "mail-header-"
1826 (if (eq (caar elem
) 'followup
)
1828 (downcase (symbol-name (caar elem
))))))
1830 (setq elem
(cdr elem
)))
1831 (setq malist
(cdr malist
)))
1832 ;; We change the score file to the adaptive score file.
1834 (set-buffer gnus-summary-buffer
)
1835 (gnus-score-load-file
1836 (or gnus-newsgroup-adaptive-score-file
1837 (gnus-score-file-name
1838 gnus-newsgroup-name gnus-adaptive-file-suffix
))))
1839 ;; The we score away.
1841 (setq elem
(cdr (assq (gnus-data-mark (car data
)) alist
)))
1843 (gnus-data-pseudo-p (car data
)))
1845 (when (setq headers
(gnus-data-header (car data
)))
1847 (setq match
(funcall (caar elem
) headers
))
1848 (gnus-summary-score-entry
1849 (nth 1 (car elem
)) match
1853 ((equal (nth 1 (car elem
)) "date")
1856 ;; Whether we use substring or exact matches are controlled
1858 (if (or (not gnus-score-exact-adapt-limit
)
1859 (< (length match
) gnus-score-exact-adapt-limit
))
1861 (if (equal (nth 1 (car elem
)) "subject")
1863 (nth 2 (car elem
)) date nil t
)
1864 (setq elem
(cdr elem
)))))
1865 (setq data
(cdr data
))))))
1867 (defun gnus-score-edit-done ()
1868 (let ((bufnam (buffer-file-name (current-buffer)))
1869 (winconf gnus-prev-winconf
))
1870 (and winconf
(set-window-configuration winconf
))
1871 (gnus-score-remove-from-cache bufnam
)
1872 (gnus-score-load-file bufnam
)))
1874 (defun gnus-score-find-trace ()
1875 "Find all score rules that applies to the current article."
1877 (let ((gnus-newsgroup-headers
1878 (list (gnus-summary-article-header)))
1879 (gnus-newsgroup-scored nil
)
1880 (buf (current-buffer))
1882 (when (get-buffer "*Gnus Scores*")
1884 (set-buffer "*Gnus Scores*")
1886 (setq gnus-score-trace nil
)
1887 (gnus-possibly-score-headers 'trace
)
1888 (if (not (setq trace gnus-score-trace
))
1889 (gnus-error 1 "No score rules apply to the current article.")
1890 (pop-to-buffer "*Gnus Scores*")
1891 (gnus-add-current-to-buffer-list)
1894 (insert (format "%S -> %s\n" (cdar trace
)
1895 (file-name-nondirectory (caar trace
))))
1896 (setq trace
(cdr trace
)))
1897 (goto-char (point-min))
1898 (pop-to-buffer buf
))))
1900 (defun gnus-summary-rescore ()
1901 "Redo the entire scoring process in the current summary."
1904 (setq gnus-score-cache nil
)
1905 (setq gnus-newsgroup-scored nil
)
1906 (gnus-possibly-score-headers)
1907 (gnus-score-update-all-lines))
1909 (defun gnus-score-flush-cache ()
1910 "Flush the cache of score files."
1913 (setq gnus-score-cache nil
1914 gnus-score-alist nil
1915 gnus-short-name-score-file-cache nil
)
1916 (gnus-message 6 "The score cache is now flushed"))
1918 (gnus-add-shutdown 'gnus-score-close
'gnus
)
1920 (defvar gnus-score-file-alist-cache nil
)
1922 (defun gnus-score-close ()
1923 "Clear all internal score variables."
1924 (setq gnus-score-cache nil
1925 gnus-internal-global-score-files nil
1926 gnus-score-file-list nil
1927 gnus-score-file-alist-cache nil
))
1929 ;; Summary score marking commands.
1931 (defun gnus-summary-raise-same-subject-and-select (score)
1932 "Raise articles which has the same subject with SCORE and select the next."
1934 (let ((subject (gnus-summary-article-subject)))
1935 (gnus-summary-raise-score score
)
1936 (while (gnus-summary-find-subject subject
)
1937 (gnus-summary-raise-score score
))
1938 (gnus-summary-next-article t
)))
1940 (defun gnus-summary-raise-same-subject (score)
1941 "Raise articles which has the same subject with SCORE."
1943 (let ((subject (gnus-summary-article-subject)))
1944 (gnus-summary-raise-score score
)
1945 (while (gnus-summary-find-subject subject
)
1946 (gnus-summary-raise-score score
))
1947 (gnus-summary-next-subject 1 t
)))
1949 (defun gnus-score-default (level)
1950 (if level
(prefix-numeric-value level
)
1951 gnus-score-interactive-default-score
))
1953 (defun gnus-summary-raise-thread (&optional score
)
1954 "Raise the score of the articles in the current thread with SCORE."
1956 (setq score
(gnus-score-default score
))
1959 (let ((articles (gnus-summary-articles-in-thread)))
1961 (gnus-summary-goto-subject (car articles
))
1962 (gnus-summary-raise-score score
)
1963 (setq articles
(cdr articles
))))
1965 (let ((gnus-summary-check-current t
))
1966 (or (zerop (gnus-summary-next-subject 1 t
))
1968 (gnus-summary-recenter)
1969 (gnus-summary-position-point)
1970 (gnus-set-mode-line 'summary
))
1972 (defun gnus-summary-lower-same-subject-and-select (score)
1973 "Raise articles which has the same subject with SCORE and select the next."
1975 (gnus-summary-raise-same-subject-and-select (- score
)))
1977 (defun gnus-summary-lower-same-subject (score)
1978 "Raise articles which has the same subject with SCORE."
1980 (gnus-summary-raise-same-subject (- score
)))
1982 (defun gnus-summary-lower-thread (&optional score
)
1983 "Lower score of articles in the current thread with SCORE."
1985 (gnus-summary-raise-thread (- (1- (gnus-score-default score
)))))
1987 ;;; Finding score files.
1989 (defun gnus-score-score-files (group)
1990 "Return a list of all possible score files."
1991 ;; Search and set any global score files.
1992 (and gnus-global-score-files
1993 (or gnus-internal-global-score-files
1994 (gnus-score-search-global-directories gnus-global-score-files
)))
1995 ;; Fix the kill-file dir variable.
1996 (setq gnus-kill-files-directory
1997 (file-name-as-directory gnus-kill-files-directory
))
1998 ;; If we can't read it, there are no score files.
1999 (if (not (file-exists-p (expand-file-name gnus-kill-files-directory
)))
2000 (setq gnus-score-file-list nil
)
2001 (if (not (gnus-use-long-file-name 'not-score
))
2002 ;; We do not use long file names, so we have to do some
2003 ;; directory traversing.
2004 (setq gnus-score-file-list
2006 (or gnus-short-name-score-file-cache
2008 (gnus-message 6 "Finding all score files...")
2009 (setq gnus-short-name-score-file-cache
2010 (gnus-score-score-files-1
2011 gnus-kill-files-directory
))
2012 (gnus-message 6 "Finding all score files...done")))))
2013 ;; We want long file names.
2014 (when (or (not gnus-score-file-list
)
2015 (not (car gnus-score-file-list
))
2016 (gnus-file-newer-than gnus-kill-files-directory
2017 (car gnus-score-file-list
)))
2018 (setq gnus-score-file-list
2019 (cons (nth 5 (file-attributes gnus-kill-files-directory
))
2022 gnus-kill-files-directory t
2023 (gnus-score-file-regexp)))))))
2024 (cdr gnus-score-file-list
)))
2026 (defun gnus-score-score-files-1 (dir)
2027 "Return all possible score files under DIR."
2028 (let ((files (directory-files (expand-file-name dir
) t nil t
))
2029 (regexp (gnus-score-file-regexp))
2031 (while (setq file
(pop files
))
2033 ;; Ignore "." and "..".
2034 ((member (file-name-nondirectory file
) '("." ".."))
2036 ;; Recurse down directories.
2037 ((file-directory-p file
)
2038 (setq out
(nconc (gnus-score-score-files-1 file
) out
)))
2039 ;; Add files to the list of score files.
2040 ((string-match regexp file
)
2043 ;; Return a dummy value.
2044 (list "~/News/this.file.does.not.exist.SCORE"))))
2046 (defun gnus-score-file-regexp ()
2047 "Return a regexp that match all score files."
2048 (concat "\\(" (regexp-quote gnus-score-file-suffix
)
2049 "\\|" (regexp-quote gnus-adaptive-file-suffix
) "\\)\\'"))
2051 (defun gnus-score-find-bnews (group)
2052 "Return a list of score files for GROUP.
2053 The score files are those files in the ~/News/ directory which matches
2054 GROUP using BNews sys file syntax."
2055 (let* ((sfiles (append (gnus-score-score-files group
)
2056 gnus-internal-global-score-files
))
2057 (kill-dir (file-name-as-directory
2058 (expand-file-name gnus-kill-files-directory
)))
2059 (klen (length kill-dir
))
2060 (score-regexp (gnus-score-file-regexp))
2061 (trans (cdr (assq ?
: nnheader-file-name-translation-alist
)))
2062 ofiles not-match regexp
)
2064 (set-buffer (get-buffer-create "*gnus score files*"))
2065 (buffer-disable-undo (current-buffer))
2066 ;; Go through all score file names and create regexp with them
2070 (insert (car sfiles
))
2071 (goto-char (point-min))
2072 ;; First remove the suffix itself.
2073 (when (re-search-forward (concat "." score-regexp
) nil t
)
2074 (replace-match "" t t
)
2075 (goto-char (point-min))
2076 (if (looking-at (regexp-quote kill-dir
))
2077 ;; If the file name was just "SCORE", `klen' is one character
2079 (delete-char (min (1- (point-max)) klen
))
2080 (goto-char (point-max))
2081 (search-backward "/")
2082 (delete-region (1+ (point)) (point-min)))
2083 ;; If short file names were used, we have to translate slashes.
2084 (goto-char (point-min))
2085 (let ((regexp (concat
2086 "[/:" (if trans
(char-to-string trans
) "") "]")))
2087 (while (re-search-forward regexp nil t
)
2088 (replace-match "." t t
)))
2089 ;; Cludge to get rid of "nntp+" problems.
2090 (goto-char (point-min))
2091 (and (looking-at "nn[a-z]+\\+")
2093 (search-forward "+")
2096 ;; Kludge to deal with "++".
2097 (goto-char (point-min))
2098 (while (search-forward "++" nil t
)
2099 (replace-match "\\+\\+" t t
))
2100 ;; Translate "all" to ".*".
2101 (goto-char (point-min))
2102 (while (search-forward "all" nil t
)
2103 (replace-match ".*" t t
))
2104 (goto-char (point-min))
2105 ;; Deal with "not."s.
2106 (if (looking-at "not.")
2109 (setq regexp
(buffer-substring 5 (point-max))))
2110 (setq regexp
(buffer-substring 1 (point-max)))
2111 (setq not-match nil
))
2112 ;; Finally - if this resulting regexp matches the group name,
2113 ;; we add this score file to the list of score files
2114 ;; applicable to this group.
2115 (if (or (and not-match
2116 (not (string-match regexp group
)))
2117 (and (not not-match
)
2118 (string-match regexp group
)))
2119 (setq ofiles
(cons (car sfiles
) ofiles
))))
2120 (setq sfiles
(cdr sfiles
)))
2121 (kill-buffer (current-buffer))
2122 ;; Slight kludge here - the last score file returned should be
2123 ;; the local score file, whether it exists or not. This is so
2124 ;; that any score commands the user enters will go to the right
2125 ;; file, and not end up in some global score file.
2126 (let ((localscore (gnus-score-file-name group
)))
2127 (setq ofiles
(cons localscore
(delete localscore ofiles
))))
2128 (nreverse ofiles
))))
2130 (defun gnus-score-find-single (group)
2131 "Return list containing the score file for GROUP."
2132 (list (or gnus-newsgroup-adaptive-score-file
2133 (gnus-score-file-name group gnus-adaptive-file-suffix
))
2134 (gnus-score-file-name group
)))
2136 (defun gnus-score-find-hierarchical (group)
2137 "Return list of score files for GROUP.
2138 This includes the score file for the group and all its parents."
2139 (let ((all (copy-sequence '(nil)))
2141 (while (string-match "\\." group
(1+ start
))
2142 (setq start
(match-beginning 0))
2143 (setq all
(cons (substring group
0 start
) all
)))
2144 (setq all
(cons group all
))
2146 (mapcar (lambda (newsgroup)
2147 (gnus-score-file-name newsgroup gnus-adaptive-file-suffix
))
2148 (setq all
(nreverse all
)))
2149 (mapcar 'gnus-score-file-name all
))))
2151 (defun gnus-score-find-alist (group)
2152 "Return list of score files for GROUP.
2153 The list is determined from the variable gnus-score-file-alist."
2154 (let ((alist gnus-score-file-multiple-match-alist
)
2156 ;; if this group has been seen before, return the cached entry
2157 (if (setq score-files
(assoc group gnus-score-file-alist-cache
))
2158 (cdr score-files
) ;ensures caching groups with no matches
2159 ;; handle the multiple match alist
2161 (and (string-match (caar alist
) group
)
2163 (nconc score-files
(copy-sequence (cdar alist
)))))
2164 (setq alist
(cdr alist
)))
2165 (setq alist gnus-score-file-single-match-alist
)
2166 ;; handle the single match alist
2168 (and (string-match (caar alist
) group
)
2169 ;; progn used just in case ("regexp") has no files
2170 ;; and score-files is still nil. -sj
2171 ;; this can be construed as a "stop searching here" feature :>
2172 ;; and used to simplify regexps in the single-alist
2175 (nconc score-files
(copy-sequence (cdar alist
))))
2177 (setq alist
(cdr alist
)))
2178 ;; cache the score files
2179 (setq gnus-score-file-alist-cache
2180 (cons (cons group score-files
) gnus-score-file-alist-cache
))
2183 (defun gnus-possibly-score-headers (&optional trace
)
2184 (let ((funcs gnus-score-find-score-files-function
)
2186 ;; Make sure funcs is a list.
2189 (setq funcs
(list funcs
)))
2190 ;; Get the initial score files for this group.
2192 (setq score-files
(gnus-score-find-alist gnus-newsgroup-name
)))
2193 ;; Go through all the functions for finding score files (or actual
2194 ;; scores) and add them to a list.
2196 (when (gnus-functionp (car funcs
))
2198 (nconc score-files
(funcall (car funcs
) gnus-newsgroup-name
))))
2199 (setq funcs
(cdr funcs
)))
2200 ;; Check whether there is a `score-file' group parameter.
2201 (let ((param-file (gnus-group-get-parameter
2202 gnus-newsgroup-name
'score-file
)))
2204 (push param-file score-files
)))
2205 ;; Do the scoring if there are any score files for this group.
2207 (gnus-score-headers score-files trace
))))
2209 (defun gnus-score-file-name (newsgroup &optional suffix
)
2210 "Return the name of a score file for NEWSGROUP."
2211 (let ((suffix (or suffix gnus-score-file-suffix
)))
2212 (nnheader-translate-file-chars
2214 ((or (null newsgroup
)
2215 (string-equal newsgroup
""))
2216 ;; The global score file is placed at top of the directory.
2218 suffix gnus-kill-files-directory
))
2219 ((gnus-use-long-file-name 'not-score
)
2220 ;; Append ".SCORE" to newsgroup name.
2221 (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup
)
2223 gnus-kill-files-directory
))
2225 ;; Place "SCORE" under the hierarchical directory.
2226 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup
)
2228 gnus-kill-files-directory
))))))
2230 (defun gnus-score-search-global-directories (files)
2231 "Scan all global score directories for score files."
2232 ;; Set the variable `gnus-internal-global-score-files' to all
2233 ;; available global score files.
2234 (interactive (list gnus-global-score-files
))
2237 (if (string-match "/$" (car files
))
2238 (setq out
(nconc (directory-files
2240 (concat (gnus-score-file-regexp) "$"))))
2241 (setq out
(cons (car files
) out
)))
2242 (setq files
(cdr files
)))
2243 (setq gnus-internal-global-score-files out
)))
2245 (defun gnus-score-default-fold-toggle ()
2246 "Toggle folding for new score file entries."
2248 (setq gnus-score-default-fold
(not gnus-score-default-fold
))
2249 (if gnus-score-default-fold
2250 (gnus-message 1 "New score file entries will be case insensitive.")
2251 (gnus-message 1 "New score file entries will be case sensitive.")))
2253 (provide 'gnus-score
)
2255 ;;; gnus-score.el ends here