1 ;;; gnus-score.el --- scoring code for Gnus
2 ;; Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
4 ;; Author: Per Abrahamsen <amanda@iesd.auc.dk>
5 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
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.
29 (eval-when-compile (require 'cl
))
31 (eval-when-compile (require 'cl
))
39 (defcustom gnus-global-score-files nil
40 "List of global score files and directories.
41 Set this variable if you want to use people's score files. One entry
42 for each score file or each score file directory. Gnus will decide
43 by itself what score files are applicable to which group.
45 Say you want to use the single score file
46 \"/ftp.gnus.org@ftp:/pub/larsi/ding/score/soc.motss.SCORE\" and all
47 score files in the \"/ftp.some-where:/pub/score\" directory.
49 (setq gnus-global-score-files
50 '(\"/ftp.gnus.org:/pub/larsi/ding/score/soc.motss.SCORE\"
51 \"/ftp.some-where:/pub/score\"))"
52 :group
'gnus-score-files
55 (defcustom gnus-score-file-single-match-alist nil
56 "Alist mapping regexps to lists of score files.
57 Each element of this alist should be of the form
58 (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... )
60 If the name of a group is matched by REGEXP, the corresponding scorefiles
61 will be used for that group.
62 The first match found is used, subsequent matching entries are ignored (to
63 use multiple matches, see gnus-score-file-multiple-match-alist).
65 These score files are loaded in addition to any files returned by
66 gnus-score-find-score-files-function (which see)."
67 :group
'gnus-score-files
68 :type
'(repeat (cons regexp
(repeat file
))))
70 (defcustom gnus-score-file-multiple-match-alist nil
71 "Alist mapping regexps to lists of score files.
72 Each element of this alist should be of the form
73 (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... )
75 If the name of a group is matched by REGEXP, the corresponding scorefiles
76 will be used for that group.
77 If multiple REGEXPs match a group, the score files corresponding to each
78 match will be used (for only one match to be used, see
79 gnus-score-file-single-match-alist).
81 These score files are loaded in addition to any files returned by
82 gnus-score-find-score-files-function (which see)."
83 :group
'gnus-score-files
84 :type
'(repeat (cons regexp
(repeat file
))))
86 (defcustom gnus-score-file-suffix
"SCORE"
87 "Suffix of the score files."
88 :group
'gnus-score-files
91 (defcustom gnus-adaptive-file-suffix
"ADAPT"
92 "Suffix of the adaptive score files."
93 :group
'gnus-score-files
94 :group
'gnus-score-adapt
97 (defcustom gnus-score-find-score-files-function
'gnus-score-find-bnews
98 "Function used to find score files.
99 The function will be called with the group name as the argument, and
100 should return a list of score files to apply to that group. The score
101 files do not actually have to exist.
103 Predefined values are:
105 gnus-score-find-single: Only apply the group's own score file.
106 gnus-score-find-hierarchical: Also apply score files from parent groups.
107 gnus-score-find-bnews: Apply score files whose names matches.
109 See the documentation to these functions for more information.
111 This variable can also be a list of functions to be called. Each
112 function should either return a list of score files, or a list of
115 If functions other than these pre-defined functions are used,
116 the `a' symbolic prefix to the score commands will always use
118 :group
'gnus-score-files
119 :type
'(radio (function-item gnus-score-find-single
)
120 (function-item gnus-score-find-hierarchical
)
121 (function-item gnus-score-find-bnews
)
122 (function :tag
"Other")))
124 (defcustom gnus-score-interactive-default-score
1000
125 "*Scoring commands will raise/lower the score with this number as the default."
126 :group
'gnus-score-default
127 :type
'(choice (const nil
)
130 (defcustom gnus-score-expiry-days
7
131 "*Number of days before unused score file entries are expired.
132 If this variable is nil, no score file entries will be expired."
133 :group
'gnus-score-expire
134 :type
'(choice (const :tag
"never" nil
)
137 (defcustom gnus-update-score-entry-dates t
138 "*In non-nil, update matching score entry dates.
139 If this variable is nil, then score entries that provide matches
140 will be expired along with non-matching score entries."
141 :group
'gnus-score-expire
144 (defcustom gnus-orphan-score nil
145 "*All orphans get this score added. Set in the score file."
146 :group
'gnus-score-default
147 :type
'(choice (const nil
)
150 (defcustom gnus-decay-scores nil
151 "*If non-nil, decay non-permanent scores."
152 :group
'gnus-score-decay
155 (defcustom gnus-decay-score-function
'gnus-decay-score
156 "*Function called to decay a score.
157 It is called with one parameter -- the score to be decayed."
158 :group
'gnus-score-decay
159 :type
'(radio (function-item gnus-decay-score
)
160 (function :tag
"Other")))
162 (defcustom gnus-score-decay-constant
3
163 "*Decay all \"small\" scores with this amount."
164 :group
'gnus-score-decay
167 (defcustom gnus-score-decay-scale
.05
168 "*Decay all \"big\" scores with this factor."
169 :group
'gnus-score-decay
172 (defcustom gnus-home-score-file nil
173 "Variable to control where interactive score entries are to go.
177 This file file will be used as the home score file.
180 The result of this function will be used as the home score file.
181 The function will be passed the name of the group as its
185 The elements in this list can be:
187 * `(regexp file-name ...)'
188 If the `regexp' matches the group name, the first `file-name' will
189 will be used as the home score file. (Multiple filenames are
190 allowed so that one may use gnus-score-file-single-match-alist to
194 If the function returns non-nil, the result will be used
195 as the home score file. The function will be passed the
196 name of the group as its parameter.
198 * A string. Use the string as the home score file.
200 The list will be traversed from the beginning towards the end looking
202 :group
'gnus-score-files
203 :type
'(choice string
204 (repeat (choice string
205 (cons regexp
(repeat file
))
206 (function :value fun
)))
207 (function :value fun
)))
209 (defcustom gnus-home-adapt-file nil
210 "Variable to control where new adaptive score entries are to go.
211 This variable allows the same syntax as `gnus-home-score-file'."
212 :group
'gnus-score-adapt
213 :group
'gnus-score-files
214 :type
'(choice string
215 (repeat (choice string
216 (cons regexp
(repeat file
))
217 (function :value fun
)))
218 (function :value fun
)))
220 (defcustom gnus-default-adaptive-score-alist
221 '((gnus-kill-file-mark)
223 (gnus-read-mark (from 3) (subject 30))
224 (gnus-catchup-mark (subject -
10))
225 (gnus-killed-mark (from -
1) (subject -
20))
226 (gnus-del-mark (from -
2) (subject -
15)))
227 "*Alist of marks and scores."
228 :group
'gnus-score-adapt
229 :type
'(repeat (cons (symbol :tag
"Mark")
230 (repeat (list (choice :tag
"Header"
233 (symbol :tag
"other"))
234 (integer :tag
"Score"))))))
236 (defcustom gnus-ignored-adaptive-words nil
237 "List of words to be ignored when doing adaptive word scoring."
238 :group
'gnus-score-adapt
239 :type
'(repeat string
))
241 (defcustom gnus-default-ignored-adaptive-words
242 '("a" "i" "the" "to" "of" "and" "in" "is" "it" "for" "that" "if" "you"
243 "this" "be" "on" "with" "not" "have" "are" "or" "as" "from" "can"
244 "but" "by" "at" "an" "will" "no" "all" "was" "do" "there" "my" "one"
245 "so" "we" "they" "what" "would" "any" "which" "about" "get" "your"
246 "use" "some" "me" "then" "name" "like" "out" "when" "up" "time"
247 "other" "more" "only" "just" "end" "also" "know" "how" "new" "should"
248 "been" "than" "them" "he" "who" "make" "may" "people" "these" "now"
249 "their" "here" "into" "first" "could" "way" "had" "see" "work" "well"
250 "were" "two" "very" "where" "while" "us" "because" "good" "same"
251 "even" "much" "most" "many" "such" "long" "his" "over" "last" "since"
252 "right" "before" "our" "without" "too" "those" "why" "must" "part"
253 "being" "current" "back" "still" "go" "point" "value" "each" "did"
254 "both" "true" "off" "say" "another" "state" "might" "under" "start"
256 "*Default list of words to be ignored when doing adaptive word scoring."
257 :group
'gnus-score-adapt
258 :type
'(repeat string
))
260 (defcustom gnus-default-adaptive-word-score-alist
261 `((,gnus-read-mark .
30)
262 (,gnus-catchup-mark . -
10)
263 (,gnus-killed-mark . -
20)
264 (,gnus-del-mark . -
15))
265 "*Alist of marks and scores."
266 :group
'gnus-score-adapt
267 :type
'(repeat (cons (character :tag
"Mark")
268 (integer :tag
"Score"))))
270 (defcustom gnus-adaptive-word-minimum nil
271 "If a number, this is the minimum score value that can be assigned to a word."
272 :group
'gnus-score-adapt
273 :type
'(choice (const nil
) integer
))
275 (defcustom gnus-adaptive-word-no-group-words nil
276 "If t, don't adaptively score words included in the group name."
277 :group
'gnus-score-adapt
280 (defcustom gnus-score-mimic-keymap nil
281 "*Have the score entry functions pretend that they are a keymap."
282 :group
'gnus-score-default
285 (defcustom gnus-score-exact-adapt-limit
10
286 "*Number that says how long a match has to be before using substring matching.
287 When doing adaptive scoring, one normally uses fuzzy or substring
288 matching. However, if the header one matches is short, the possibility
289 for false positives is great, so if the length of the match is less
290 than this variable, exact matching will be used.
292 If this variable is nil, exact matching will always be used."
293 :group
'gnus-score-adapt
294 :type
'(choice (const nil
) integer
))
296 (defcustom gnus-score-uncacheable-files
"ADAPT$"
297 "All score files that match this regexp will not be cached."
298 :group
'gnus-score-adapt
299 :group
'gnus-score-files
302 (defcustom gnus-score-default-header nil
303 "Default header when entering new scores.
305 Should be one of the following symbols.
318 If nil, the user will be asked for a header."
319 :group
'gnus-score-default
320 :type
'(choice (const :tag
"from" a
)
321 (const :tag
"subject" s
)
322 (const :tag
"body" b
)
323 (const :tag
"head" h
)
324 (const :tag
"message-id" i
)
325 (const :tag
"references" t
)
326 (const :tag
"xref" x
)
327 (const :tag
"lines" l
)
328 (const :tag
"date" d
)
329 (const :tag
"followup" f
)
330 (const :tag
"ask" nil
)))
332 (defcustom gnus-score-default-type nil
333 "Default match type when entering new scores.
335 Should be one of the following symbols.
345 >: greater than number
348 If nil, the user will be asked for a match type."
349 :group
'gnus-score-default
350 :type
'(choice (const :tag
"substring" s
)
351 (const :tag
"exact string" e
)
352 (const :tag
"fuzzy string" f
)
353 (const :tag
"regexp string" r
)
354 (const :tag
"before date" b
)
355 (const :tag
"after date" a
)
356 (const :tag
"this date" n
)
357 (const :tag
"less than number" <)
358 (const :tag
"greater than number" >)
359 (const :tag
"equal than number" =)
360 (const :tag
"ask" nil
)))
362 (defcustom gnus-score-default-fold nil
363 "Use case folding for new score file entries iff not nil."
364 :group
'gnus-score-default
367 (defcustom gnus-score-default-duration nil
368 "Default duration of effect when entering new scores.
370 Should be one of the following symbols.
376 If nil, the user will be asked for a duration."
377 :group
'gnus-score-default
378 :type
'(choice (const :tag
"temporary" t
)
379 (const :tag
"permanent" p
)
380 (const :tag
"immediate" i
)
381 (const :tag
"ask" nil
)))
383 (defcustom gnus-score-after-write-file-function nil
384 "Function called with the name of the score file just written to disk."
385 :group
'gnus-score-files
388 (defcustom gnus-score-thread-simplify nil
389 "If non-nil, subjects will simplified as in threading."
390 :group
'gnus-score-various
395 ;; Internal variables.
397 (defvar gnus-adaptive-word-syntax-table
398 (let ((table (copy-syntax-table (standard-syntax-table)))
399 (numbers '(?
0 ?
1 ?
2 ?
3 ?
4 ?
5 ?
6 ?
7 ?
8 ?
9)))
401 (modify-syntax-entry (pop numbers
) " " table
))
402 (modify-syntax-entry ?
' "w" table
)
404 "Syntax table used when doing adaptive word scoring.")
406 (defvar gnus-scores-exclude-files nil
)
407 (defvar gnus-internal-global-score-files nil
)
408 (defvar gnus-score-file-list nil
)
410 (defvar gnus-short-name-score-file-cache nil
)
412 (defvar gnus-score-help-winconf nil
)
413 (defvar gnus-adaptive-score-alist gnus-default-adaptive-score-alist
)
414 (defvar gnus-adaptive-word-score-alist gnus-default-adaptive-word-score-alist
)
415 (defvar gnus-score-trace nil
)
416 (defvar gnus-score-edit-buffer nil
)
418 (defvar gnus-score-alist nil
419 "Alist containing score information.
420 The keys can be symbols or strings. The following symbols are defined.
422 touched: If this alist has been modified.
423 mark: Automatically mark articles below this.
424 expunge: Automatically expunge articles below this.
425 files: List of other score files to load when loading this one.
426 eval: Sexp to be evaluated when the score file is loaded.
428 String entries have the form (HEADER (MATCH TYPE SCORE DATE) ...)
429 where HEADER is the header being scored, MATCH is the string we are
430 looking for, TYPE is a flag indicating whether it should use regexp or
431 substring matching, SCORE is the score to add and DATE is the date
432 of the last successful match.")
434 (defvar gnus-score-cache nil
)
435 (defvar gnus-scores-articles nil
)
436 (defvar gnus-score-index nil
)
439 (defconst gnus-header-index
440 ;; Name to index alist.
441 '(("number" 0 gnus-score-integer
)
442 ("subject" 1 gnus-score-string
)
443 ("from" 2 gnus-score-string
)
444 ("date" 3 gnus-score-date
)
445 ("message-id" 4 gnus-score-string
)
446 ("references" 5 gnus-score-string
)
447 ("chars" 6 gnus-score-integer
)
448 ("lines" 7 gnus-score-integer
)
449 ("xref" 8 gnus-score-string
)
450 ("head" -
1 gnus-score-body
)
451 ("body" -
1 gnus-score-body
)
452 ("all" -
1 gnus-score-body
)
453 ("followup" 2 gnus-score-followup
)
454 ("thread" 5 gnus-score-thread
)))
456 ;;; Summary mode score maps.
458 (gnus-define-keys (gnus-summary-score-map "V" gnus-summary-mode-map
)
459 "s" gnus-summary-set-score
460 "S" gnus-summary-current-score
461 "c" gnus-score-change-score-file
462 "C" gnus-score-customize
463 "m" gnus-score-set-mark-below
464 "x" gnus-score-set-expunge-below
465 "R" gnus-summary-rescore
466 "e" gnus-score-edit-current-scores
467 "f" gnus-score-edit-file
468 "F" gnus-score-flush-cache
469 "t" gnus-score-find-trace
470 "w" gnus-score-find-favourite-words
)
472 ;; Summary score file commands
474 ;; Much modification of the kill (ahem, score) code and lots of the
475 ;; functions are written by Per Abrahamsen <amanda@iesd.auc.dk>.
477 (defun gnus-summary-lower-score (&optional score symp
)
478 "Make a score entry based on the current article.
479 The user will be prompted for header to score on, match type,
480 permanence, and the string to be used. The numerical prefix will be
482 (interactive (gnus-interactive "P\ny"))
483 (gnus-summary-increase-score (- (gnus-score-default score
)) symp
))
485 (defun gnus-score-kill-help-buffer ()
486 (when (get-buffer "*Score Help*")
487 (kill-buffer "*Score Help*")
488 (when gnus-score-help-winconf
489 (set-window-configuration gnus-score-help-winconf
))))
491 (defun gnus-summary-increase-score (&optional score symp
)
492 "Make a score entry based on the current article.
493 The user will be prompted for header to score on, match type,
494 permanence, and the string to be used. The numerical prefix will be
496 (interactive (gnus-interactive "P\ny"))
497 (let* ((nscore (gnus-score-default score
))
498 (prefix (if (< nscore
0) ?L ?I
))
499 (increase (> nscore
0))
501 '((?a
"from" nil nil string
)
502 (?s
"subject" nil nil string
)
503 (?b
"body" "" nil body-string
)
504 (?h
"head" "" nil body-string
)
505 (?i
"message-id" nil t string
)
506 (?r
"references" "message-id" nil string
)
507 (?x
"xref" nil nil string
)
508 (?l
"lines" nil nil number
)
509 (?d
"date" nil nil date
)
510 (?f
"followup" nil nil string
)
511 (?t
"thread" "message-id" nil string
)))
513 '((?s s
"substring" string
)
514 (?e e
"exact string" string
)
515 (?f f
"fuzzy string" string
)
516 (?r r
"regexp string" string
)
517 (?z s
"substring" body-string
)
518 (?p r
"regexp string" body-string
)
519 (?b before
"before date" date
)
520 (?a after
"after date" date
)
521 (?n at
"this date" date
)
522 (?
< < "less than number" number
)
523 (?
> > "greater than number" number
)
524 (?
= = "equal to number" number
)))
525 (current-score-file gnus-current-score-file
)
527 (list (list ?t
(current-time-string) "temporary")
528 '(?p perm
"permanent") '(?i now
"immediate")))
529 (mimic gnus-score-mimic-keymap
)
530 (hchar (and gnus-score-default-header
531 (aref (symbol-name gnus-score-default-header
) 0)))
532 (tchar (and gnus-score-default-type
533 (aref (symbol-name gnus-score-default-type
) 0)))
534 (pchar (and gnus-score-default-duration
535 (aref (symbol-name gnus-score-default-duration
) 0)))
536 entry temporary type match
)
541 ;; First we read the header to score.
546 (message "%c-" prefix
))
547 (message "%s header (%s?): " (if increase
"Increase" "Lower")
548 (mapconcat (lambda (s) (char-to-string (car s
)))
550 (setq hchar
(read-char))
551 (when (or (= hchar ??
) (= hchar ?\C-h
))
553 (gnus-score-insert-help "Match on header" char-to-header
1)))
555 (gnus-score-kill-help-buffer)
556 (unless (setq entry
(assq (downcase hchar
) char-to-header
))
557 (if mimic
(error "%c %c" prefix hchar
)
558 (error "Illegal header type")))
560 (when (/= (downcase hchar
) hchar
)
561 ;; This was a majuscule, so we end reading and set the defaults.
562 (if mimic
(message "%c %c" prefix hchar
) (message ""))
563 (setq tchar
(or tchar ?s
)
564 pchar
(or pchar ?t
)))
569 (if (eq (nth 4 entry
)
573 ;; We continue reading - the type.
577 (sit-for 1) (message "%c %c-" prefix hchar
))
578 (message "%s header '%s' with match type (%s?): "
579 (if increase
"Increase" "Lower")
581 (mapconcat (lambda (s) (char-to-string (car s
)))
583 (setq tchar
(read-char))
584 (when (or (= tchar ??
) (= tchar ?\C-h
))
586 (gnus-score-insert-help "Match type" legal-types
2)))
588 (gnus-score-kill-help-buffer)
589 (unless (setq type
(nth 1 (assq (downcase tchar
) legal-types
)))
590 (if mimic
(error "%c %c" prefix hchar
)
591 (error "Illegal match type"))))
593 (when (/= (downcase tchar
) tchar
)
594 ;; It was a majuscule, so we end reading and use the default.
595 (if mimic
(message "%c %c %c" prefix hchar tchar
)
597 (setq pchar
(or pchar ?t
)))
599 ;; We continue reading.
603 (sit-for 1) (message "%c %c %c-" prefix hchar tchar
))
604 (message "%s permanence (%s?): " (if increase
"Increase" "Lower")
605 (mapconcat (lambda (s) (char-to-string (car s
)))
607 (setq pchar
(read-char))
608 (when (or (= pchar ??
) (= pchar ?\C-h
))
610 (gnus-score-insert-help "Match permanence" char-to-perm
2)))
612 (gnus-score-kill-help-buffer)
613 (if mimic
(message "%c %c %c" prefix hchar tchar pchar
)
615 (unless (setq temporary
(cadr (assq pchar char-to-perm
)))
616 ;; Deal with der(r)ided superannuated paradigms.
617 (when (and (eq (1+ prefix
) 77)
618 (eq (+ hchar
12) 109)
620 (eq (- pchar
4) 111))
623 (error "%c %c %c %c" prefix hchar tchar pchar
)
624 (error "Illegal match duration"))))
625 ;; Always kill the score help buffer.
626 (gnus-score-kill-help-buffer))
628 ;; We have all the data, so we enter this score.
629 (setq match
(if (string= (nth 2 entry
) "") ""
630 (gnus-summary-header (or (nth 2 entry
) (nth 1 entry
)))))
632 ;; Modify the match, perhaps.
634 ((equal (nth 1 entry
) "xref")
635 (when (string-match "^Xref: *" match
)
636 (setq match
(substring match
(match-end 0))))
637 (when (string-match "^[^:]* +" match
)
638 (setq match
(substring match
(match-end 0))))))
640 (when (memq type
'(r R regexp Regexp
))
641 (setq match
(regexp-quote match
)))
643 ;; Change score file to the "all.SCORE" file.
646 (set-buffer gnus-summary-buffer
)
647 (gnus-score-load-file
648 ;; This is a kludge; yes...
650 ((eq gnus-score-find-score-files-function
651 'gnus-score-find-hierarchical
)
652 (gnus-score-file-name ""))
653 ((eq gnus-score-find-score-files-function
'gnus-score-find-single
)
656 (gnus-score-file-name "all"))))))
658 (gnus-summary-score-entry
659 (nth 1 entry
) ; Header
662 (if (eq score
's
) nil score
) ; Score
663 (if (eq temporary
'perm
) ; Temp
666 (not (nth 3 entry
))) ; Prompt
669 ;; We change the score file back to the previous one.
671 (set-buffer gnus-summary-buffer
)
672 (gnus-score-load-file current-score-file
)))))
674 (defun gnus-score-insert-help (string alist idx
)
675 (setq gnus-score-help-winconf
(current-window-configuration))
677 (set-buffer (gnus-get-buffer-create "*Score Help*"))
678 (buffer-disable-undo (current-buffer))
679 (delete-windows-on (current-buffer))
681 (insert string
":\n\n")
686 ;; find the longest string to display
688 (setq n
(length (nth idx
(car list
))))
691 (setq list
(cdr list
)))
692 (setq max
(+ max
4)) ; %c, `:', SPACE, a SPACE at end
693 (setq n
(/ (1- (window-width)) max
)) ; items per line
694 (setq width
(/ (1- (window-width)) n
)) ; width of each item
695 ;; insert `n' items, each in a field of width `width'
700 (delete-char -
1) ; the `\n' takes a char
702 (setq pad
(- width
3))
703 (setq format
(concat "%c: %-" (int-to-string pad
) "s"))
704 (insert (format format
(caar alist
) (nth idx
(car alist
))))
705 (setq alist
(cdr alist
))
707 ;; display ourselves in a small window at the bottom
708 (gnus-appt-select-lowest-window)
710 (pop-to-buffer "*Score Help*")
711 (let ((window-min-height 1))
712 (shrink-window-if-larger-than-buffer))
713 (select-window (get-buffer-window gnus-summary-buffer
))))
715 (defun gnus-summary-header (header &optional no-err
)
716 ;; Return HEADER for current articles, or error.
717 (let ((article (gnus-summary-article-number))
720 (if (and (setq headers
(gnus-summary-article-header article
))
722 (aref headers
(nth 1 (assoc header gnus-header-index
)))
725 (error "Pseudo-articles can't be scored")))
727 (error "No article on current line")
730 (defun gnus-newsgroup-score-alist ()
732 (let ((param-file (gnus-group-find-parameter
733 gnus-newsgroup-name
'score-file
)))
735 (gnus-score-load param-file
)))
737 (gnus-score-file-name gnus-newsgroup-name
)))
740 (defsubst gnus-score-get
(symbol &optional alist
)
741 ;; Get SYMBOL's definition in ALIST.
745 (gnus-newsgroup-score-alist)))))
747 (defun gnus-summary-score-entry (header match type score date
748 &optional prompt silent
)
749 "Enter score file entry.
750 HEADER is the header being scored.
751 MATCH is the string we are looking for.
752 TYPE is the match type: substring, regexp, exact, fuzzy.
753 SCORE is the score to add.
754 DATE is the expire date, or nil for no expire, or 'now for immediate expire.
755 If optional argument `PROMPT' is non-nil, allow user to edit match.
756 If optional argument `SILENT' is nil, show effect of score entry."
757 ;; Regexp is the default type.
760 ;; Simplify matches...
761 (cond ((or (eq type
'r
) (eq type
's
) (eq type nil
))
762 (setq match
(if match
(gnus-simplify-subject-re match
) "")))
764 (setq match
(gnus-simplify-subject-fuzzy match
))))
765 (let ((score (gnus-score-default score
))
766 (header (format "%s" (downcase header
)))
769 (setq match
(read-string
770 (format "Match %s on %s, %s: "
771 (cond ((eq date
'now
)
777 (if (< score
0) "lower" "raise"))
779 (int-to-string match
)
782 ;; Get rid of string props.
783 (setq match
(format "%s" match
))
785 ;; If this is an integer comparison, we transform from string to int.
786 (when (eq (nth 2 (assoc header gnus-header-index
)) 'gnus-score-integer
)
787 (setq match
(string-to-int match
)))
789 (unless (eq date
'now
)
790 ;; Add the score entry to the score file.
791 (when (= score gnus-score-interactive-default-score
)
793 (let ((old (gnus-score-get header
))
799 (and date
(if (numberp date
) date
800 (gnus-day-number date
)))
802 (date (list match score
(gnus-day-number date
)))
803 (score (list match score
))
805 ;; We see whether we can collapse some score entries.
806 ;; This isn't quite correct, because there may be more elements
807 ;; later on with the same key that have matching elems... Hm.
809 (setq elem
(assoc match old
))
810 (eq (nth 3 elem
) (nth 3 new
))
811 (or (and (numberp (nth 2 elem
)) (numberp (nth 2 new
)))
812 (and (not (nth 2 elem
)) (not (nth 2 new
)))))
813 ;; Yup, we just add this new score to the old elem.
814 (setcar (cdr elem
) (+ (or (nth 1 elem
)
815 gnus-score-interactive-default-score
)
817 gnus-score-interactive-default-score
)))
818 ;; Nope, we have to add a new elem.
819 (gnus-score-set header
(if old
(cons new old
) (list new
)) nil t
))
820 (gnus-score-set 'touched
'(t))))
822 ;; Score the current buffer.
824 (if (and (>= (nth 1 (assoc header gnus-header-index
)) 0)
825 (eq (nth 2 (assoc header gnus-header-index
))
827 (gnus-summary-score-effect header match type score
)
828 (gnus-summary-rescore)))
830 ;; Return the new scoring rule.
833 (defun gnus-summary-score-effect (header match type score
)
834 "Simulate the effect of a score file entry.
835 HEADER is the header being scored.
836 MATCH is the string we are looking for.
837 TYPE is the score type.
838 SCORE is the score to add."
839 (interactive (list (completing-read "Header: "
841 (lambda (x) (fboundp (nth 2 x
)))
843 (read-string "Match: ")
844 (y-or-n-p "Use regexp match? ")
845 (prefix-numeric-value current-prefix-arg
)))
847 (unless (and (stringp match
) (> (length match
) 0))
849 (goto-char (point-min))
850 (let ((regexp (cond ((eq type
'f
)
851 (gnus-simplify-subject-fuzzy match
))
855 (concat "\\`" (regexp-quote match
) "\\'"))
857 (regexp-quote match
)))))
859 (let ((content (gnus-summary-header header
'noerr
))
860 (case-fold-search t
))
862 (when (if (eq type
'f
)
863 (string-equal (gnus-simplify-subject-fuzzy content
)
865 (string-match regexp content
))
866 (gnus-summary-raise-score score
))))
867 (beginning-of-line 2))))
868 (gnus-set-mode-line 'summary
))
870 (defun gnus-summary-score-crossposting (score date
)
871 ;; Enter score file entry for current crossposting.
872 ;; SCORE is the score to add.
873 ;; DATE is the expire date.
874 (let ((xref (gnus-summary-header "xref"))
878 (error "This article is not crossposted"))
879 (while (string-match " \\([^ \t]+\\):" xref start
)
880 (setq start
(match-end 0))
883 (substring xref
(match-beginning 1) (match-end 1)))
884 gnus-newsgroup-name
))
885 (gnus-summary-score-entry
886 "xref" (concat " " group
":") nil score date t
)))))
893 ;; All score code written by Per Abrahamsen <abraham@iesd.auc.dk>.
895 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
896 (defun gnus-score-set-mark-below (score)
897 "Automatically mark articles with score below SCORE as read."
899 (list (or (and current-prefix-arg
(prefix-numeric-value current-prefix-arg
))
900 (string-to-int (read-string "Mark below: ")))))
901 (setq score
(or score gnus-summary-default-score
0))
902 (gnus-score-set 'mark
(list score
))
903 (gnus-score-set 'touched
'(t))
904 (setq gnus-summary-mark-below score
)
905 (gnus-score-update-lines))
907 (defun gnus-score-update-lines ()
908 "Update all lines in the summary buffer."
910 (goto-char (point-min))
912 (gnus-summary-update-line)
915 (defun gnus-score-update-all-lines ()
916 "Update all lines in the summary buffer, even the hidden ones."
918 (goto-char (point-min))
921 (when (gnus-summary-show-thread)
922 (push (point) hidden
))
923 (gnus-summary-update-line)
925 ;; Re-hide the hidden threads.
927 (goto-char (pop hidden
))
928 (gnus-summary-hide-thread)))))
930 (defun gnus-score-set-expunge-below (score)
931 "Automatically expunge articles with score below SCORE."
933 (list (or (and current-prefix-arg
(prefix-numeric-value current-prefix-arg
))
934 (string-to-int (read-string "Set expunge below: ")))))
935 (setq score
(or score gnus-summary-default-score
0))
936 (gnus-score-set 'expunge
(list score
))
937 (gnus-score-set 'touched
'(t)))
939 (defun gnus-score-followup-article (&optional score
)
940 "Add SCORE to all followups to the article in the current buffer."
942 (setq score
(gnus-score-default score
))
943 (when (gnus-buffer-live-p gnus-summary-buffer
)
946 (message-narrow-to-headers)
947 (let ((id (mail-fetch-field "message-id")))
949 (set-buffer gnus-summary-buffer
)
950 (gnus-summary-score-entry
951 "references" (concat id
"[ \t]*$") 'r
952 score
(current-time-string) nil t
)))))))
954 (defun gnus-score-followup-thread (&optional score
)
955 "Add SCORE to all later articles in the thread the current buffer is part of."
957 (setq score
(gnus-score-default score
))
958 (when (gnus-buffer-live-p gnus-summary-buffer
)
961 (goto-char (point-min))
962 (let ((id (mail-fetch-field "message-id")))
964 (set-buffer gnus-summary-buffer
)
965 (gnus-summary-score-entry
967 score
(current-time-string))))))))
969 (defun gnus-score-set (symbol value
&optional alist warn
)
970 ;; Set SYMBOL to VALUE in ALIST.
974 (gnus-newsgroup-score-alist)))
975 (entry (assoc symbol alist
)))
976 (cond ((gnus-score-get 'read-only alist
)
977 ;; This is a read-only score file, so we do nothing.
979 (gnus-message 4 "Note: read-only score file; entry discarded")))
981 (setcdr entry value
))
983 (error "Empty alist"))
986 (cons (cons symbol value
) (cdr alist
)))))))
988 (defun gnus-summary-raise-score (n)
989 "Raise the score of the current article by N."
991 (gnus-summary-set-score (+ (gnus-summary-article-score)
992 (or n gnus-score-interactive-default-score
))))
994 (defun gnus-summary-set-score (n)
995 "Set the score of the current article to N."
998 (gnus-summary-show-thread)
999 (let ((buffer-read-only nil
))
1001 (gnus-summary-update-mark
1002 (if (= n
(or gnus-summary-default-score
0)) ?
1003 (if (< n
(or gnus-summary-default-score
0))
1004 gnus-score-below-mark gnus-score-over-mark
))
1006 (let* ((article (gnus-summary-article-number))
1007 (score (assq article gnus-newsgroup-scored
)))
1008 (if score
(setcdr score n
)
1009 (push (cons article n
) gnus-newsgroup-scored
)))
1010 (gnus-summary-update-line)))
1012 (defun gnus-summary-current-score ()
1013 "Return the score of the current article."
1015 (gnus-message 1 "%s" (gnus-summary-article-score)))
1017 (defun gnus-score-change-score-file (file)
1018 "Change current score alist."
1020 (list (read-file-name "Change to score file: " gnus-kill-files-directory
)))
1021 (gnus-score-load-file file
)
1022 (gnus-set-mode-line 'summary
))
1024 (defvar gnus-score-edit-exit-function
)
1025 (defun gnus-score-edit-current-scores (file)
1026 "Edit the current score alist."
1027 (interactive (list gnus-current-score-file
))
1028 (if (not gnus-current-score-file
)
1029 (error "No current score file")
1030 (let ((winconf (current-window-configuration)))
1031 (when (buffer-name gnus-summary-buffer
)
1033 (gnus-make-directory (file-name-directory file
))
1034 (setq gnus-score-edit-buffer
(find-file-noselect file
))
1035 (gnus-configure-windows 'edit-score
)
1037 (setq gnus-score-edit-exit-function
'gnus-score-edit-done
)
1038 (make-local-variable 'gnus-prev-winconf
)
1039 (setq gnus-prev-winconf winconf
))
1041 4 (substitute-command-keys
1042 "\\<gnus-score-mode-map>\\[gnus-score-edit-exit] to save edits"))))
1044 (defun gnus-score-edit-file (file)
1045 "Edit a score file."
1047 (list (read-file-name "Edit score file: " gnus-kill-files-directory
)))
1048 (gnus-make-directory (file-name-directory file
))
1049 (when (buffer-name gnus-summary-buffer
)
1051 (let ((winconf (current-window-configuration)))
1052 (setq gnus-score-edit-buffer
(find-file-noselect file
))
1053 (gnus-configure-windows 'edit-score
)
1055 (setq gnus-score-edit-exit-function
'gnus-score-edit-done
)
1056 (make-local-variable 'gnus-prev-winconf
)
1057 (setq gnus-prev-winconf winconf
))
1059 4 (substitute-command-keys
1060 "\\<gnus-score-mode-map>\\[gnus-score-edit-exit] to save edits")))
1062 (defun gnus-score-load-file (file)
1063 ;; Load score file FILE. Returns a list a retrieved score-alists.
1064 (let* ((file (expand-file-name
1065 (or (and (string-match
1066 (concat "^" (regexp-quote
1068 gnus-kill-files-directory
)))
1069 (expand-file-name file
))
1071 (concat (file-name-as-directory gnus-kill-files-directory
)
1073 (cached (assoc file gnus-score-cache
))
1074 (global (member file gnus-internal-global-score-files
))
1077 ;; The score file was already loaded.
1078 (setq alist
(cdr cached
))
1079 ;; We load the score file.
1080 (setq gnus-score-alist nil
)
1081 (setq alist
(gnus-score-load-score-alist file
))
1082 ;; We add '(touched) to the alist to signify that it hasn't been
1084 (unless (assq 'touched alist
)
1085 (push (list 'touched nil
) alist
))
1086 ;; If it is a global score file, we make it read-only.
1088 (not (assq 'read-only alist
))
1089 (push (list 'read-only t
) alist
))
1090 (push (cons file alist
) gnus-score-cache
))
1094 ;; Downcase all header names.
1097 (setcar (car a
) (downcase (caar a
)))
1099 ;; Advanced scoring.
1103 ;; If there are actual scores in the alist, we add it to the
1104 ;; return value of this function.
1106 (setq lists
(list alist
))))
1107 ;; Treat the other possible atoms in the score alist.
1108 (let ((mark (car (gnus-score-get 'mark alist
)))
1109 (expunge (car (gnus-score-get 'expunge alist
)))
1110 (mark-and-expunge (car (gnus-score-get 'mark-and-expunge alist
)))
1111 (files (gnus-score-get 'files alist
))
1112 (exclude-files (gnus-score-get 'exclude-files alist
))
1113 (orphan (car (gnus-score-get 'orphan alist
)))
1114 (adapt (gnus-score-get 'adapt alist
))
1115 (thread-mark-and-expunge
1116 (car (gnus-score-get 'thread-mark-and-expunge alist
)))
1117 (adapt-file (car (gnus-score-get 'adapt-file alist
)))
1118 (local (gnus-score-get 'local alist
))
1119 (decay (car (gnus-score-get 'decay alist
)))
1120 (eval (car (gnus-score-get 'eval alist
))))
1121 ;; Perform possible decays.
1122 (when (and gnus-decay-scores
1123 (or cached
(file-exists-p file
))
1125 (gnus-decay-scores alist decay
)))
1126 (gnus-score-set 'touched
'(t) alist
)
1127 (gnus-score-set 'decay
(list (gnus-time-to-day (current-time))) alist
))
1128 ;; We do not respect eval and files atoms from global score
1130 (when (and files
(not global
))
1131 (setq lists
(apply 'append lists
1132 (mapcar (lambda (file)
1133 (gnus-score-load-file file
))
1134 (if adapt-file
(cons adapt-file files
)
1136 (when (and eval
(not global
))
1138 ;; We then expand any exclude-file directives.
1139 (setq gnus-scores-exclude-files
1146 (expand-file-name sfile
(file-name-directory file
))
1147 (expand-file-name sfile gnus-kill-files-directory
)))
1149 gnus-scores-exclude-files
))
1152 (set-buffer gnus-summary-buffer
)
1154 (and (consp (car local
))
1155 (symbolp (caar local
))
1157 (make-local-variable (caar local
))
1158 (set (caar local
) (nth 1 (car local
)))))
1159 (setq local
(cdr local
)))))
1161 (setq gnus-orphan-score orphan
))
1162 (setq gnus-adaptive-score-alist
1163 (cond ((equal adapt
'(t))
1164 (setq gnus-newsgroup-adaptive t
)
1165 gnus-default-adaptive-score-alist
)
1166 ((equal adapt
'(ignore))
1167 (setq gnus-newsgroup-adaptive nil
))
1169 (setq gnus-newsgroup-adaptive t
)
1172 ;;(setq gnus-newsgroup-adaptive gnus-use-adaptive-scoring)
1173 gnus-default-adaptive-score-alist
)))
1174 (setq gnus-thread-expunge-below
1175 (or thread-mark-and-expunge gnus-thread-expunge-below
))
1176 (setq gnus-summary-mark-below
1177 (or mark mark-and-expunge gnus-summary-mark-below
))
1178 (setq gnus-summary-expunge-below
1179 (or expunge mark-and-expunge gnus-summary-expunge-below
))
1180 (setq gnus-newsgroup-adaptive-score-file
1181 (or adapt-file gnus-newsgroup-adaptive-score-file
)))
1182 (setq gnus-current-score-file file
)
1183 (setq gnus-score-alist alist
)
1186 (defun gnus-score-load (file)
1188 (let ((cache (assoc file gnus-score-cache
)))
1190 (setq gnus-score-alist
(cdr cache
))
1191 (setq gnus-score-alist nil
)
1192 (gnus-score-load-score-alist file
)
1193 (unless gnus-score-alist
1194 (setq gnus-score-alist
(copy-alist '((touched nil
)))))
1195 (push (cons file gnus-score-alist
) gnus-score-cache
))))
1197 (defun gnus-score-remove-from-cache (file)
1198 (setq gnus-score-cache
1199 (delq (assoc file gnus-score-cache
) gnus-score-cache
)))
1201 (defun gnus-score-load-score-alist (file)
1204 (if (not (file-readable-p file
))
1205 ;; Couldn't read file.
1206 (setq gnus-score-alist nil
)
1209 (gnus-set-work-buffer)
1210 (insert-file-contents file
)
1211 (goto-char (point-min))
1212 ;; Only do the loading if the score file isn't empty.
1213 (when (save-excursion (re-search-forward "[()0-9a-zA-Z]" nil t
))
1216 (read (current-buffer))
1218 (gnus-error 3.2 "Problem with score file %s" file
))))))
1222 ;; Bogus score file.
1223 (error "Invalid syntax with score file %s" file
))
1224 ((eq (car alist
) 'setq
)
1225 ;; This is an old-style score file.
1226 (setq gnus-score-alist
(gnus-score-transform-old-to-new alist
)))
1228 (setq gnus-score-alist alist
)))
1229 ;; Check the syntax of the score file.
1230 (setq gnus-score-alist
1231 (gnus-score-check-syntax gnus-score-alist file
)))))
1233 (defun gnus-score-check-syntax (alist file
)
1234 "Check the syntax of the score ALIST."
1238 ((not (consp alist
))
1239 (gnus-message 1 "Score file is not a list: %s" file
)
1245 (while (and a
(not err
))
1249 ((not (listp (car a
)))
1250 (format "Illegal score element %s in %s" (car a
) file
))
1253 ((not (listp (setq sr
(cdar a
))))
1254 (format "Illegal header match %s in %s" (nth 1 (car a
)) file
))
1256 (setq type
(caar a
))
1257 (while (and sr
(not err
))
1262 ((if (member (downcase type
) '("lines" "chars"))
1263 (not (numberp (car s
)))
1264 (not (stringp (car s
))))
1265 (format "Illegal match %s in %s" (car s
) file
))
1266 ((and (cadr s
) (not (integerp (cadr s
))))
1267 (format "Non-integer score %s in %s" (cadr s
) file
))
1268 ((and (caddr s
) (not (integerp (caddr s
))))
1269 (format "Non-integer date %s in %s" (caddr s
) file
))
1270 ((and (cadddr s
) (not (symbolp (cadddr s
))))
1271 (format "Non-symbol match type %s in %s" (cadddr s
) file
)))))
1277 (gnus-message 3 err
)
1282 (defun gnus-score-transform-old-to-new (alist)
1283 (let* ((alist (nth 2 alist
))
1285 (when (eq (car alist
) 'quote
)
1286 (setq alist
(nth 1 alist
)))
1288 (setq entry
(car alist
))
1289 (if (stringp (car entry
))
1290 (let ((scor (cdr entry
)))
1294 (list (caar scor
) (nth 2 (car scor
))
1295 (and (nth 3 (car scor
))
1296 (gnus-day-number (nth 3 (car scor
))))
1297 (if (nth 1 (car scor
)) 'r
's
)))
1298 (setq scor
(cdr scor
))))
1299 (push (if (not (listp (cdr entry
)))
1300 (list (car entry
) (cdr entry
))
1303 (setq alist
(cdr alist
)))
1304 (cons (list 'touched t
) (nreverse out
))))
1306 (defun gnus-score-save ()
1307 ;; Save all score information.
1308 (let ((cache gnus-score-cache
)
1311 (setq gnus-score-alist nil
)
1312 (nnheader-set-temp-buffer " *Gnus Scores*")
1315 (setq entry
(pop cache
)
1318 (if (or (not (equal (gnus-score-get 'touched score
) '(t)))
1319 (gnus-score-get 'read-only score
)
1320 (and (file-exists-p file
)
1321 (not (file-writable-p file
))))
1323 (setq score
(setcdr entry
(gnus-delete-alist 'touched score
)))
1325 (let (emacs-lisp-mode-hook)
1327 (concat (regexp-quote gnus-adaptive-file-suffix
) "$")
1329 ;; This is an adaptive score file, so we do not run
1330 ;; it through `pp'. These files can get huge, and
1331 ;; are not meant to be edited by human hands.
1333 ;; This is a normal score file, so we print it very
1335 (let ((lisp-mode-syntax-table score-mode-syntax-table
))
1336 (pp score
(current-buffer)))))
1337 (gnus-make-directory (file-name-directory file
))
1338 ;; If the score file is empty, we delete it.
1339 (if (zerop (buffer-size))
1341 ;; There are scores, so we write the file.
1342 (when (file-writable-p file
)
1343 (gnus-write-buffer file
)
1344 (when gnus-score-after-write-file-function
1345 (funcall gnus-score-after-write-file-function file
)))))
1346 (and gnus-score-uncacheable-files
1347 (string-match gnus-score-uncacheable-files file
)
1348 (gnus-score-remove-from-cache file
)))
1349 (kill-buffer (current-buffer)))))
1351 (defun gnus-score-load-files (score-files)
1352 "Load all score files in SCORE-FILES."
1353 ;; Load the score files.
1356 (if (stringp (car score-files
))
1357 ;; It is a string, which means that it's a score file name,
1358 ;; so we load the score file and add the score alist to
1359 ;; the list of alists.
1360 (setq scores
(nconc (gnus-score-load-file (car score-files
)) scores
))
1361 ;; It is an alist, so we just add it to the list directly.
1362 (setq scores
(nconc (car score-files
) scores
)))
1363 (setq score-files
(cdr score-files
)))
1364 ;; Prune the score files that are to be excluded, if any.
1365 (when gnus-scores-exclude-files
1369 (and (setq c
(rassq (car s
) gnus-score-cache
))
1370 (member (car c
) gnus-scores-exclude-files
)
1371 (setq scores
(delq (car s
) scores
)))
1375 (defun gnus-score-headers (score-files &optional trace
)
1376 ;; Score `gnus-newsgroup-headers'.
1378 ;; PLM: probably this is not the best place to clear orphan-score
1379 (setq gnus-orphan-score nil
1380 gnus-scores-articles nil
1381 gnus-scores-exclude-files nil
1382 scores
(gnus-score-load-files score-files
))
1388 (when (and gnus-summary-default-score
1390 (let* ((entries gnus-header-index
)
1391 (now (gnus-day-number (current-time-string)))
1392 (expire (and gnus-score-expiry-days
1393 (- now gnus-score-expiry-days
)))
1394 (headers gnus-newsgroup-headers
)
1395 (current-score-file gnus-current-score-file
)
1397 (gnus-message 5 "Scoring...")
1398 ;; Create articles, an alist of the form `(HEADER . SCORE)'.
1399 (while (setq header
(pop headers
))
1400 ;; WARNING: The assq makes the function O(N*S) while it could
1401 ;; be written as O(N+S), where N is (length gnus-newsgroup-headers)
1402 ;; and S is (length gnus-newsgroup-scored).
1403 (unless (assq (mail-header-number header
) gnus-newsgroup-scored
)
1404 (setq gnus-scores-articles
;Total of 2 * N cons-cells used.
1405 (cons (cons header
(or gnus-summary-default-score
0))
1406 gnus-scores-articles
))))
1409 (set-buffer (gnus-get-buffer-create "*Headers*"))
1410 (buffer-disable-undo (current-buffer))
1411 (when (gnus-buffer-live-p gnus-summary-buffer
)
1412 (message-clone-locals gnus-summary-buffer
))
1414 ;; Set the global variant of this variable.
1415 (setq gnus-current-score-file current-score-file
)
1417 (when gnus-orphan-score
1418 (setq gnus-score-index
1419 (nth 1 (assoc "references" gnus-header-index
)))
1420 (gnus-score-orphans gnus-orphan-score
))
1421 ;; Run each header through the score process.
1423 (setq entry
(pop entries
)
1424 header
(nth 0 entry
)
1425 gnus-score-index
(nth 1 (assoc header gnus-header-index
)))
1426 (when (< 0 (apply 'max
(mapcar
1428 (length (gnus-score-get header score
)))
1430 ;; Call the scoring function for this type of "header".
1431 (when (setq new
(funcall (nth 2 entry
) scores header
1434 ;; Remove the buffer.
1435 (kill-buffer (current-buffer)))
1437 ;; Add articles to `gnus-newsgroup-scored'.
1438 (while gnus-scores-articles
1439 (when (or (/= gnus-summary-default-score
1440 (cdar gnus-scores-articles
))
1442 (push (cons (mail-header-number (caar gnus-scores-articles
))
1443 (cdar gnus-scores-articles
))
1444 gnus-newsgroup-scored
))
1445 (setq gnus-scores-articles
(cdr gnus-scores-articles
)))
1448 (while (setq score
(pop scores
))
1450 (when (listp (caar score
))
1451 (gnus-score-advanced (car score
) trace
))
1454 (gnus-message 5 "Scoring...done"))))))
1457 (defun gnus-get-new-thread-ids (articles)
1458 (let ((index (nth 1 (assoc "message-id" gnus-header-index
)))
1459 (refind gnus-score-index
)
1460 id-list art this tref
)
1462 (setq art
(car articles
)
1463 this
(aref (car art
) index
)
1464 tref
(aref (car art
) refind
)
1465 articles
(cdr articles
))
1466 (when (string-equal tref
"") ;no references line
1467 (push this id-list
)))
1470 ;; Orphan functions written by plm@atcmp.nl (Peter Mutsaers).
1471 (defun gnus-score-orphans (score)
1472 (let ((new-thread-ids (gnus-get-new-thread-ids gnus-scores-articles
))
1473 alike articles art arts this last this-id
)
1475 (setq gnus-scores-articles
(sort gnus-scores-articles
'gnus-score-string
<)
1476 articles gnus-scores-articles
)
1478 ;;more or less the same as in gnus-score-string
1481 (setq art
(car articles
)
1482 this
(aref (car art
) gnus-score-index
)
1483 articles
(cdr articles
))
1484 ;;completely skip if this is empty (not a child, so not an orphan)
1485 (when (not (string= this
""))
1486 (if (equal last this
)
1487 ;; O(N*H) cons-cells used here, where H is the number of
1491 ;; Insert the line, with a text property on the
1492 ;; terminating newline referring to the articles with
1495 (put-text-property (1- (point)) (point) 'articles alike
))
1496 (setq alike
(list art
)
1498 (when last
; Bwadr, duplicate code.
1500 (put-text-property (1- (point)) (point) 'articles alike
))
1502 ;; PLM: now delete those lines that contain an entry from new-thread-ids
1503 (while new-thread-ids
1504 (setq this-id
(car new-thread-ids
)
1505 new-thread-ids
(cdr new-thread-ids
))
1506 (goto-char (point-min))
1507 (while (search-forward this-id nil t
)
1508 ;; found a match. remove this line
1512 ;; now for each line: update its articles with score by moving to
1513 ;; every end-of-line in the buffer and read the articles property
1514 (goto-char (point-min))
1517 (setq arts
(get-text-property (point) 'articles
))
1519 (setq art
(car arts
)
1521 (setcdr art
(+ score
(cdr art
))))
1525 (defun gnus-score-integer (scores header now expire
&optional trace
)
1526 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
1531 (setq alist
(car scores
)
1533 entries
(assoc header alist
))
1534 (while (cdr entries
) ;First entry is the header index.
1535 (let* ((rest (cdr entries
))
1537 (match (nth 0 kill
))
1538 (type (or (nth 3 kill
) '>))
1539 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1542 (match-func (if (or (eq type
'>) (eq type
'<) (eq type
'<=)
1543 (eq type
'>=) (eq type
'=))
1545 (error "Illegal match type: %s" type
)))
1546 (articles gnus-scores-articles
))
1547 ;; Instead of doing all the clever stuff that
1548 ;; `gnus-score-string' does to minimize searches and stuff,
1549 ;; I will assume that people generally will put so few
1550 ;; matches on numbers that any cleverness will take more
1551 ;; time than one would gain.
1553 (when (funcall match-func
1554 (or (aref (caar articles
) gnus-score-index
) 0)
1557 (push (cons (car-safe (rassq alist gnus-score-cache
)) kill
)
1560 (setcdr (car articles
) (+ score
(cdar articles
))))
1561 (setq articles
(cdr articles
)))
1562 ;; Update expire date
1563 (cond ((null date
)) ;Permanent entry.
1564 ((and found gnus-update-score-entry-dates
) ;Match, update date.
1565 (gnus-score-set 'touched
'(t) alist
)
1566 (setcar (nthcdr 2 kill
) now
))
1567 ((and expire
(< date expire
)) ;Old entry, remove.
1568 (gnus-score-set 'touched
'(t) alist
)
1569 (setcdr entries
(cdr rest
))
1570 (setq rest entries
)))
1571 (setq entries rest
)))))
1574 (defun gnus-score-date (scores header now expire
&optional trace
)
1575 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
1576 entries alist match match-func article
)
1580 (setq alist
(car scores
)
1582 entries
(assoc header alist
))
1583 (while (cdr entries
) ;First entry is the header index.
1584 (let* ((rest (cdr entries
))
1586 (type (or (nth 3 kill
) 'before
))
1587 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1590 (articles gnus-scores-articles
)
1594 (setq match-func
'string
<
1595 match
(gnus-date-iso8601 (nth 0 kill
))))
1597 (setq match-func
'gnus-string
>
1598 match
(gnus-date-iso8601 (nth 0 kill
))))
1600 (setq match-func
'string
=
1601 match
(gnus-date-iso8601 (nth 0 kill
))))
1603 (setq match-func
'string-match
1604 match
(nth 0 kill
)))
1605 (t (error "Illegal match type: %s" type
)))
1606 ;; Instead of doing all the clever stuff that
1607 ;; `gnus-score-string' does to minimize searches and stuff,
1608 ;; I will assume that people generally will put so few
1609 ;; matches on numbers that any cleverness will take more
1610 ;; time than one would gain.
1611 (while (setq article
(pop articles
))
1613 (setq l
(aref (car article
) gnus-score-index
))
1614 (funcall match-func match
(gnus-date-iso8601 l
)))
1616 (push (cons (car-safe (rassq alist gnus-score-cache
)) kill
)
1619 (setcdr article
(+ score
(cdr article
)))))
1620 ;; Update expire date
1621 (cond ((null date
)) ;Permanent entry.
1622 ((and found gnus-update-score-entry-dates
) ;Match, update date.
1623 (gnus-score-set 'touched
'(t) alist
)
1624 (setcar (nthcdr 2 kill
) now
))
1625 ((and expire
(< date expire
)) ;Old entry, remove.
1626 (gnus-score-set 'touched
'(t) alist
)
1627 (setcdr entries
(cdr rest
))
1628 (setq rest entries
)))
1629 (setq entries rest
)))))
1632 (defun gnus-score-body (scores header now expire
&optional trace
)
1634 (setq gnus-scores-articles
1635 (sort gnus-scores-articles
1637 (< (mail-header-number (car a1
))
1638 (mail-header-number (car a2
))))))
1639 (set-buffer nntp-server-buffer
)
1641 (let* ((buffer-read-only nil
)
1642 (articles gnus-scores-articles
)
1644 (request-func (cond ((string= "head" header
)
1646 ((string= "body" header
)
1648 (t 'gnus-request-article
)))
1649 entries alist ofunc article last
)
1651 (setq last
(mail-header-number (caar (last articles
))))
1652 ;; Not all backends support partial fetching. In that case,
1653 ;; we just fetch the entire article.
1654 (unless (gnus-check-backend-function
1655 (and (string-match "^gnus-" (symbol-name request-func
))
1656 (intern (substring (symbol-name request-func
)
1658 gnus-newsgroup-name
)
1659 (setq ofunc request-func
)
1660 (setq request-func
'gnus-request-article
))
1662 (setq article
(mail-header-number (caar articles
)))
1663 (gnus-message 7 "Scoring article %s of %s..." article last
)
1664 (when (funcall request-func article gnus-newsgroup-name
)
1666 (goto-char (point-min))
1667 ;; If just parts of the article is to be searched, but the
1668 ;; backend didn't support partial fetching, we just narrow
1669 ;; to the relevant parts.
1671 (if (eq ofunc
'gnus-request-head
)
1674 (or (search-forward "\n\n" nil t
) (point-max)))
1676 (or (search-forward "\n\n" nil t
) (point))
1678 (setq scores all-scores
)
1681 (setq alist
(pop scores
)
1682 entries
(assoc header alist
))
1683 (while (cdr entries
) ;First entry is the header index.
1684 (let* ((rest (cdr entries
))
1686 (match (nth 0 kill
))
1687 (type (or (nth 3 kill
) 's
))
1688 (score (or (nth 1 kill
)
1689 gnus-score-interactive-default-score
))
1693 (not (or (eq type
'R
) (eq type
'S
)
1694 (eq type
'Regexp
) (eq type
'String
))))
1696 (cond ((or (eq type
'r
) (eq type
'R
)
1697 (eq type
'regexp
) (eq type
'Regexp
))
1699 ((or (eq type
's
) (eq type
'S
)
1700 (eq type
'string
) (eq type
'String
))
1703 (error "Illegal match type: %s" type
)))))
1704 (goto-char (point-min))
1705 (when (funcall search-func match nil t
)
1706 ;; Found a match, update scores.
1707 (setcdr (car articles
) (+ score
(cdar articles
)))
1711 (cons (car-safe (rassq alist gnus-score-cache
)) kill
)
1713 ;; Update expire date
1716 ((null date
)) ;Permanent entry.
1717 ((and found gnus-update-score-entry-dates
)
1718 ;; Match, update date.
1719 (gnus-score-set 'touched
'(t) alist
)
1720 (setcar (nthcdr 2 kill
) now
))
1721 ((and expire
(< date expire
)) ;Old entry, remove.
1722 (gnus-score-set 'touched
'(t) alist
)
1723 (setcdr entries
(cdr rest
))
1724 (setq rest entries
))))
1725 (setq entries rest
)))))
1726 (setq articles
(cdr articles
)))))))
1729 (defun gnus-score-thread (scores header now expire
&optional trace
)
1730 (gnus-score-followup scores header now expire trace t
))
1732 (defun gnus-score-followup (scores header now expire
&optional trace thread
)
1733 ;; Insert the unique article headers in the buffer.
1734 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
1735 (current-score-file gnus-current-score-file
)
1737 ;; gnus-score-index is used as a free variable.
1738 alike last this art entries alist articles
1741 ;; Change score file to the adaptive score file. All entries that
1742 ;; this function makes will be put into this file.
1744 (set-buffer gnus-summary-buffer
)
1745 (gnus-score-load-file
1746 (or gnus-newsgroup-adaptive-score-file
1747 (gnus-score-file-name
1748 gnus-newsgroup-name gnus-adaptive-file-suffix
))))
1750 (setq gnus-scores-articles
(sort gnus-scores-articles
'gnus-score-string
<)
1751 articles gnus-scores-articles
)
1755 (setq art
(car articles
)
1756 this
(aref (car art
) gnus-score-index
)
1757 articles
(cdr articles
))
1758 (if (equal last this
)
1762 (put-text-property (1- (point)) (point) 'articles alike
))
1763 (setq alike
(list art
)
1765 (when last
; Bwadr, duplicate code.
1767 (put-text-property (1- (point)) (point) 'articles alike
))
1771 (setq alist
(car scores
)
1773 entries
(assoc header alist
))
1774 (while (cdr entries
) ;First entry is the header index.
1775 (let* ((rest (cdr entries
))
1777 (match (nth 0 kill
))
1778 (type (or (nth 3 kill
) 's
))
1779 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1782 (mt (aref (symbol-name type
) 0))
1784 (not (or (= mt ?R
) (= mt ?S
) (= mt ?E
) (= mt ?F
))))
1787 (cond ((= dmt ?r
) 're-search-forward
)
1788 ((or (= dmt ?e
) (= dmt ?s
) (= dmt ?f
)) 'search-forward
)
1789 (t (error "Illegal match type: %s" type
))))
1791 (goto-char (point-min))
1793 (while (funcall search-func match nil t
)
1794 (and (= (progn (beginning-of-line) (point))
1795 (match-beginning 0))
1796 (= (progn (end-of-line) (point))
1799 (setq found
(setq arts
(get-text-property
1800 (point) 'articles
)))
1801 ;; Found a match, update scores.
1803 (setq art
(car arts
)
1805 (gnus-score-add-followups
1806 (car art
) score all-scores thread
))))
1808 (while (funcall search-func match nil t
)
1810 (setq found
(setq arts
(get-text-property (point) 'articles
)))
1811 ;; Found a match, update scores.
1812 (while (setq art
(pop arts
))
1813 (when (setq new
(gnus-score-add-followups
1814 (car art
) score all-scores thread
))
1816 ;; Update expire date
1817 (cond ((null date
)) ;Permanent entry.
1818 ((and found gnus-update-score-entry-dates
) ;Match, update date.
1819 (gnus-score-set 'touched
'(t) alist
)
1820 (setcar (nthcdr 2 kill
) now
))
1821 ((and expire
(< date expire
)) ;Old entry, remove.
1822 (gnus-score-set 'touched
'(t) alist
)
1823 (setcdr entries
(cdr rest
))
1824 (setq rest entries
)))
1825 (setq entries rest
))))
1826 ;; We change the score file back to the previous one.
1828 (set-buffer gnus-summary-buffer
)
1829 (gnus-score-load-file current-score-file
))
1830 (list (cons "references" news
))))
1832 (defun gnus-score-add-followups (header score scores
&optional thread
)
1833 "Add a score entry to the adapt file."
1835 (set-buffer gnus-summary-buffer
)
1836 (let* ((id (mail-header-id header
))
1837 (scores (car scores
))
1839 ;; Don't enter a score if there already is one.
1840 (while (setq entry
(pop scores
))
1841 (and (equal "references" (car entry
))
1842 (or (null (nth 3 (cadr entry
)))
1843 (eq 's
(nth 3 (cadr entry
))))
1847 (gnus-summary-score-entry
1848 (if thread
"thread" "references")
1849 id
's score
(current-time-string) nil t
)))))
1851 (defun gnus-score-string (score-list header now expire
&optional trace
)
1852 ;; Score ARTICLES according to HEADER in SCORE-LIST.
1853 ;; Update matching entries to NOW and remove unmatched entries older
1856 ;; Insert the unique article headers in the buffer.
1857 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
1858 ;; gnus-score-index is used as a free variable.
1859 (simplify (and gnus-score-thread-simplify
1860 (string= "subject" header
)))
1861 alike last this art entries alist articles
1862 fuzzies arts words kill
)
1864 ;; Sorting the articles costs os O(N*log N) but will allow us to
1865 ;; only match with each unique header. Thus the actual matching
1866 ;; will be O(M*U) where M is the number of strings to match with,
1867 ;; and U is the number of unique headers. It is assumed (but
1868 ;; untested) this will be a net win because of the large constant
1869 ;; factor involved with string matching.
1870 (setq gnus-scores-articles
(sort gnus-scores-articles
'gnus-score-string
<)
1871 articles gnus-scores-articles
)
1874 (while (setq art
(pop articles
))
1875 (setq this
(aref (car art
) gnus-score-index
))
1877 (setq this
(gnus-map-function gnus-simplify-subject-functions this
)))
1878 (if (equal last this
)
1879 ;; O(N*H) cons-cells used here, where H is the number of
1883 ;; Insert the line, with a text property on the
1884 ;; terminating newline referring to the articles with
1887 (put-text-property (1- (point)) (point) 'articles alike
))
1888 (setq alike
(list art
)
1890 (when last
; Bwadr, duplicate code.
1892 (put-text-property (1- (point)) (point) 'articles alike
))
1894 ;; Go through all the score alists and pick out the entries
1897 (setq alist
(pop score-list
)
1898 ;; There's only one instance of this header for
1899 ;; each score alist.
1900 entries
(assoc header alist
))
1901 (while (cdr entries
) ;First entry is the header index.
1902 (let* ((kill (cadr entries
))
1903 (type (or (nth 3 kill
) 's
))
1904 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1907 (mt (aref (symbol-name type
) 0))
1908 (case-fold-search (not (memq mt
'(?R ?S ?E ?F
))))
1910 ; Assume user already simplified regexp and fuzzies
1911 (match (if (and simplify
(not (memq dmt
'(?f ?r
))))
1913 gnus-simplify-subject-functions
1917 (cond ((= dmt ?r
) 're-search-forward
)
1918 ((or (= dmt ?e
) (= dmt ?s
) (= dmt ?f
)) 'search-forward
)
1920 (t (error "Illegal match type: %s" type
)))))
1922 ;; Fuzzy matches. We save these for later.
1924 (push (cons entries alist
) fuzzies
)
1925 (setq entries
(cdr entries
)))
1926 ;; Word matches. Save these for even later.
1928 (push (cons entries alist
) words
)
1929 (setq entries
(cdr entries
)))
1932 ;; Do exact matching.
1933 (goto-char (point-min))
1934 (while (and (not (eobp))
1935 (funcall search-func match nil t
))
1936 ;; Is it really exact?
1938 (= (gnus-point-at-bol) (match-beginning 0))
1941 (setq found
(setq arts
(get-text-property
1942 (point) 'articles
)))
1943 ;; Found a match, update scores.
1945 (while (setq art
(pop arts
))
1946 (setcdr art
(+ score
(cdr art
)))
1949 (car-safe (rassq alist gnus-score-cache
))
1952 (while (setq art
(pop arts
))
1953 (setcdr art
(+ score
(cdr art
)))))))
1955 ;; Update expiry date
1957 (setq entries
(cdr entries
))
1961 (setq entries
(cdr entries
)))
1962 ;; We have a match, so we update the date.
1963 ((and found gnus-update-score-entry-dates
)
1964 (gnus-score-set 'touched
'(t) alist
)
1965 (setcar (nthcdr 2 kill
) now
)
1966 (setq entries
(cdr entries
)))
1967 ;; This entry has expired, so we remove it.
1968 ((and expire
(< date expire
))
1969 (gnus-score-set 'touched
'(t) alist
)
1970 (setcdr entries
(cddr entries
)))
1971 ;; No match; go to next entry.
1973 (setq entries
(cdr entries
))))))
1974 ;; Regexp and substring matching.
1976 (goto-char (point-min))
1977 (when (string= match
"")
1979 (while (and (not (eobp))
1980 (funcall search-func match nil t
))
1981 (goto-char (match-beginning 0))
1983 (setq found
(setq arts
(get-text-property (point) 'articles
)))
1984 ;; Found a match, update scores.
1986 (while (setq art
(pop arts
))
1987 (setcdr art
(+ score
(cdr art
)))
1988 (push (cons (car-safe (rassq alist gnus-score-cache
)) kill
)
1990 (while (setq art
(pop arts
))
1991 (setcdr art
(+ score
(cdr art
)))))
1993 ;; Update expiry date
1995 (setq entries
(cdr entries
))
1999 (setq entries
(cdr entries
)))
2000 ;; We have a match, so we update the date.
2001 ((and found gnus-update-score-entry-dates
)
2002 (gnus-score-set 'touched
'(t) alist
)
2003 (setcar (nthcdr 2 kill
) now
)
2004 (setq entries
(cdr entries
)))
2005 ;; This entry has expired, so we remove it.
2006 ((and expire
(< date expire
))
2007 (gnus-score-set 'touched
'(t) alist
)
2008 (setcdr entries
(cddr entries
)))
2009 ;; No match; go to next entry.
2011 (setq entries
(cdr entries
))))))))))
2013 ;; Find fuzzy matches.
2015 ;; Simplify the entire buffer for easy matching.
2016 (gnus-simplify-buffer-fuzzy)
2017 (while (setq kill
(cadaar fuzzies
))
2018 (let* ((match (nth 0 kill
))
2020 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
2022 (mt (aref (symbol-name type
) 0))
2023 (case-fold-search (not (= mt ?F
)))
2025 (goto-char (point-min))
2026 (while (and (not (eobp))
2027 (search-forward match nil t
))
2028 (when (and (= (gnus-point-at-bol) (match-beginning 0))
2030 (setq found
(setq arts
(get-text-property (point) 'articles
)))
2032 (while (setq art
(pop arts
))
2033 (setcdr art
(+ score
(cdr art
)))
2035 (car-safe (rassq (cdar fuzzies
) gnus-score-cache
))
2038 ;; Found a match, update scores.
2039 (while (setq art
(pop arts
))
2040 (setcdr art
(+ score
(cdr art
))))))
2042 ;; Update expiry date
2048 ;; Match, update date.
2049 ((and found gnus-update-score-entry-dates
)
2050 (gnus-score-set 'touched
'(t) (cdar fuzzies
))
2051 (setcar (nthcdr 2 kill
) now
))
2052 ;; Old entry, remove.
2053 ((and expire
(< date expire
))
2054 (gnus-score-set 'touched
'(t) (cdar fuzzies
))
2055 (setcdr (caar fuzzies
) (cddaar fuzzies
)))))
2056 (setq fuzzies
(cdr fuzzies
)))))
2059 ;; Enter all words into the hashtb.
2060 (let ((hashtb (gnus-make-hashtable
2061 (* 10 (count-lines (point-min) (point-max))))))
2062 (gnus-enter-score-words-into-hashtb hashtb
)
2063 (while (setq kill
(cadaar words
))
2064 (let* ((score (or (nth 1 kill
) gnus-score-interactive-default-score
))
2067 (when (setq arts
(intern-soft (nth 0 kill
) hashtb
))
2068 (setq arts
(symbol-value arts
))
2071 (while (setq art
(pop arts
))
2072 (setcdr art
(+ score
(cdr art
)))
2074 (car-safe (rassq (cdar words
) gnus-score-cache
))
2077 ;; Found a match, update scores.
2078 (while (setq art
(pop arts
))
2079 (setcdr art
(+ score
(cdr art
))))))
2080 ;; Update expiry date
2086 ;; Match, update date.
2087 ((and found gnus-update-score-entry-dates
)
2088 (gnus-score-set 'touched
'(t) (cdar words
))
2089 (setcar (nthcdr 2 kill
) now
))
2090 ;; Old entry, remove.
2091 ((and expire
(< date expire
))
2092 (gnus-score-set 'touched
'(t) (cdar words
))
2093 (setcdr (caar words
) (cddaar words
)))))
2094 (setq words
(cdr words
))))))
2097 (defun gnus-enter-score-words-into-hashtb (hashtb)
2098 ;; Find all the words in the buffer and enter them into
2100 (let ((syntab (syntax-table))
2102 (goto-char (point-min))
2105 (set-syntax-table gnus-adaptive-word-syntax-table
)
2106 (while (re-search-forward "\\b\\w+\\b" nil t
)
2109 (setq word
(downcase (buffer-substring
2110 (match-beginning 0) (match-end 0))))
2114 (append (get-text-property (gnus-point-at-eol) 'articles
) val
)
2116 (set-syntax-table syntab
))
2117 ;; Make all the ignorable words ignored.
2118 (let ((ignored (append gnus-ignored-adaptive-words
2119 (if gnus-adaptive-word-no-group-words
2120 (message-tokenize-header
2121 (gnus-group-real-name gnus-newsgroup-name
)
2123 gnus-default-ignored-adaptive-words
)))
2125 (gnus-sethash (pop ignored
) nil hashtb
)))))
2127 (defun gnus-score-string< (a1 a2
)
2128 ;; Compare headers in articles A2 and A2.
2129 ;; The header index used is the free variable `gnus-score-index'.
2130 (string-lessp (aref (car a1
) gnus-score-index
)
2131 (aref (car a2
) gnus-score-index
)))
2133 (defun gnus-current-score-file-nondirectory (&optional score-file
)
2134 (let ((score-file (or score-file gnus-current-score-file
)))
2136 (gnus-short-group-name (file-name-nondirectory score-file
))
2139 (defun gnus-score-adaptive ()
2140 "Create adaptive score rules for this newsgroup."
2141 (when gnus-newsgroup-adaptive
2142 ;; We change the score file to the adaptive score file.
2144 (set-buffer gnus-summary-buffer
)
2145 (gnus-score-load-file
2146 (or gnus-newsgroup-adaptive-score-file
2147 (gnus-home-score-file gnus-newsgroup-name t
)
2148 (gnus-score-file-name
2149 gnus-newsgroup-name gnus-adaptive-file-suffix
))))
2150 ;; Perform ordinary line scoring.
2151 (when (or (not (listp gnus-newsgroup-adaptive
))
2152 (memq 'line gnus-newsgroup-adaptive
))
2154 (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist
))
2156 (date (current-time-string))
2157 (data gnus-newsgroup-data
)
2158 elem headers match func
)
2159 ;; First we transform the adaptive rule alist into something
2160 ;; that's faster to process.
2162 (setq elem
(car malist
))
2163 (when (symbolp (car elem
))
2164 (setcar elem
(symbol-value (car elem
))))
2165 (setq elem
(cdr elem
))
2170 (concat "mail-header-"
2171 (if (eq (caar elem
) 'followup
)
2173 (downcase (symbol-name (caar elem
))))))))
2175 (cons (if (eq (caar elem
) 'followup
)
2177 (symbol-name (caar elem
)))
2182 (setq elem
(cdr elem
)))
2183 (setq malist
(cdr malist
)))
2184 ;; Then we score away.
2186 (setq elem
(cdr (assq (gnus-data-mark (car data
)) alist
)))
2188 (gnus-data-pseudo-p (car data
)))
2190 (when (setq headers
(gnus-data-header (car data
)))
2192 (setq match
(funcall (caar elem
) headers
))
2193 (gnus-summary-score-entry
2194 (nth 1 (car elem
)) match
2198 ((equal (nth 1 (car elem
)) "date")
2201 ;; Whether we use substring or exact matches is
2203 (if (or (not gnus-score-exact-adapt-limit
)
2204 (< (length match
) gnus-score-exact-adapt-limit
))
2206 (if (equal (nth 1 (car elem
)) "subject")
2208 (nth 2 (car elem
)) date nil t
)
2209 (setq elem
(cdr elem
)))))
2210 (setq data
(cdr data
))))))
2212 ;; Perform adaptive word scoring.
2213 (when (and (listp gnus-newsgroup-adaptive
)
2214 (memq 'word gnus-newsgroup-adaptive
))
2215 (nnheader-temp-write nil
2216 (let* ((hashtb (gnus-make-hashtable 1000))
2217 (date (gnus-day-number (current-time-string)))
2218 (data gnus-newsgroup-data
)
2219 (syntab (syntax-table))
2223 (set-syntax-table gnus-adaptive-word-syntax-table
)
2224 ;; Go through all articles.
2225 (while (setq d
(pop data
))
2227 (not (gnus-data-pseudo-p d
))
2231 gnus-adaptive-word-score-alist
))))
2232 ;; This article has a mark that should lead to
2233 ;; adaptive word rules, so we insert the subject
2234 ;; and find all words in that string.
2235 (insert (mail-header-subject (gnus-data-header d
)))
2236 (downcase-region (point-min) (point-max))
2237 (goto-char (point-min))
2238 (while (re-search-forward "\\b\\w+\\b" nil t
)
2239 ;; Put the word and score into the hashtb.
2240 (setq val
(gnus-gethash (setq word
(match-string 0))
2242 (setq val
(+ score
(or val
0)))
2243 (if (and gnus-adaptive-word-minimum
2244 (< val gnus-adaptive-word-minimum
))
2245 (setq val gnus-adaptive-word-minimum
))
2246 (gnus-sethash word val hashtb
))
2248 (set-syntax-table syntab
))
2249 ;; Make all the ignorable words ignored.
2250 (let ((ignored (append gnus-ignored-adaptive-words
2251 (if gnus-adaptive-word-no-group-words
2252 (message-tokenize-header
2253 (gnus-group-real-name
2254 gnus-newsgroup-name
)
2256 gnus-default-ignored-adaptive-words
)))
2258 (gnus-sethash (pop ignored
) nil hashtb
)))
2259 ;; Now we have all the words and scores, so we
2260 ;; add these rules to the ADAPT file.
2261 (set-buffer gnus-summary-buffer
)
2264 (when (symbol-value word
)
2265 (gnus-summary-score-entry
2266 "subject" (symbol-name word
) 'w
(symbol-value word
)
2270 (defun gnus-score-edit-done ()
2271 (let ((bufnam (buffer-file-name (current-buffer)))
2272 (winconf gnus-prev-winconf
))
2274 (set-window-configuration winconf
))
2275 (gnus-score-remove-from-cache bufnam
)
2276 (gnus-score-load-file bufnam
)))
2278 (defun gnus-score-find-trace ()
2279 "Find all score rules that applies to the current article."
2281 (let ((old-scored gnus-newsgroup-scored
))
2282 (let ((gnus-newsgroup-headers
2283 (list (gnus-summary-article-header)))
2284 (gnus-newsgroup-scored nil
)
2287 (nnheader-set-temp-buffer "*Score Trace*"))
2288 (setq gnus-score-trace nil
)
2289 (gnus-possibly-score-headers 'trace
)
2290 (if (not (setq trace gnus-score-trace
))
2292 1 "No score rules apply to the current article (default score %d)."
2293 gnus-summary-default-score
)
2294 (set-buffer "*Score Trace*")
2296 (insert (format "%S -> %s\n" (cdar trace
)
2298 (file-name-nondirectory (caar trace
))
2299 "(non-file rule)")))
2300 (setq trace
(cdr trace
)))
2301 (goto-char (point-min))
2302 (gnus-configure-windows 'score-trace
)))
2303 (set-buffer gnus-summary-buffer
)
2304 (setq gnus-newsgroup-scored old-scored
)))
2306 (defun gnus-score-find-favourite-words ()
2307 "List words used in scoring."
2309 (let ((alists (gnus-score-load-files (gnus-all-score-files)))
2310 alist rule rules kill
)
2311 ;; Go through all the score alists for this group
2312 ;; and find all `w' rules.
2313 (while (setq alist
(pop alists
))
2314 (while (setq rule
(pop alist
))
2315 (when (and (stringp (car rule
))
2316 (equal "subject" (downcase (pop rule
))))
2317 (while (setq kill
(pop rule
))
2318 (when (memq (nth 3 kill
) '(w W word Word
))
2319 (push (cons (or (nth 1 kill
)
2320 gnus-score-interactive-default-score
)
2323 (setq rules
(sort rules
(lambda (r1 r2
)
2324 (string-lessp (cdr r1
) (cdr r2
)))))
2325 ;; Add up words that have appeared several times.
2328 (if (equal (cdar r
) (cdadr r
))
2330 (setcar (car r
) (+ (caar r
) (caadr r
)))
2331 (setcdr r
(cddr r
)))
2333 ;; Insert the words.
2334 (nnheader-set-temp-buffer "*Score Words*")
2335 (if (not (setq rules
(sort rules
(lambda (r1 r2
) (> (car r1
) (car r2
))))))
2336 (gnus-error 3 "No word score rules")
2338 (insert (format "%-5d: %s\n" (caar rules
) (cdar rules
)))
2340 (goto-char (point-min))
2341 (gnus-configure-windows 'score-words
))))
2343 (defun gnus-summary-rescore ()
2344 "Redo the entire scoring process in the current summary."
2347 (setq gnus-score-cache nil
)
2348 (setq gnus-newsgroup-scored nil
)
2349 (gnus-possibly-score-headers)
2350 (gnus-score-update-all-lines))
2352 (defun gnus-score-flush-cache ()
2353 "Flush the cache of score files."
2356 (setq gnus-score-cache nil
2357 gnus-score-alist nil
2358 gnus-short-name-score-file-cache nil
)
2359 (gnus-message 6 "The score cache is now flushed"))
2361 (gnus-add-shutdown 'gnus-score-close
'gnus
)
2363 (defvar gnus-score-file-alist-cache nil
)
2365 (defun gnus-score-close ()
2366 "Clear all internal score variables."
2367 (setq gnus-score-cache nil
2368 gnus-internal-global-score-files nil
2369 gnus-score-file-list nil
2370 gnus-score-file-alist-cache nil
))
2372 ;; Summary score marking commands.
2374 (defun gnus-summary-raise-same-subject-and-select (score)
2375 "Raise articles which has the same subject with SCORE and select the next."
2377 (let ((subject (gnus-summary-article-subject)))
2378 (gnus-summary-raise-score score
)
2379 (while (gnus-summary-find-subject subject
)
2380 (gnus-summary-raise-score score
))
2381 (gnus-summary-next-article t
)))
2383 (defun gnus-summary-raise-same-subject (score)
2384 "Raise articles which has the same subject with SCORE."
2386 (let ((subject (gnus-summary-article-subject)))
2387 (gnus-summary-raise-score score
)
2388 (while (gnus-summary-find-subject subject
)
2389 (gnus-summary-raise-score score
))
2390 (gnus-summary-next-subject 1 t
)))
2392 (defun gnus-score-default (level)
2393 (if level
(prefix-numeric-value level
)
2394 gnus-score-interactive-default-score
))
2396 (defun gnus-summary-raise-thread (&optional score
)
2397 "Raise the score of the articles in the current thread with SCORE."
2399 (setq score
(gnus-score-default score
))
2402 (let ((articles (gnus-summary-articles-in-thread)))
2404 (gnus-summary-goto-subject (car articles
))
2405 (gnus-summary-raise-score score
)
2406 (setq articles
(cdr articles
))))
2408 (let ((gnus-summary-check-current t
))
2409 (unless (zerop (gnus-summary-next-subject 1 t
))
2411 (gnus-summary-recenter)
2412 (gnus-summary-position-point)
2413 (gnus-set-mode-line 'summary
))
2415 (defun gnus-summary-lower-same-subject-and-select (score)
2416 "Raise articles which has the same subject with SCORE and select the next."
2418 (gnus-summary-raise-same-subject-and-select (- score
)))
2420 (defun gnus-summary-lower-same-subject (score)
2421 "Raise articles which has the same subject with SCORE."
2423 (gnus-summary-raise-same-subject (- score
)))
2425 (defun gnus-summary-lower-thread (&optional score
)
2426 "Lower score of articles in the current thread with SCORE."
2428 (gnus-summary-raise-thread (- (1- (gnus-score-default score
)))))
2430 ;;; Finding score files.
2432 (defun gnus-score-score-files (group)
2433 "Return a list of all possible score files."
2434 ;; Search and set any global score files.
2435 (when gnus-global-score-files
2436 (unless gnus-internal-global-score-files
2437 (gnus-score-search-global-directories gnus-global-score-files
)))
2438 ;; Fix the kill-file dir variable.
2439 (setq gnus-kill-files-directory
2440 (file-name-as-directory gnus-kill-files-directory
))
2441 ;; If we can't read it, there are no score files.
2442 (if (not (file-exists-p (expand-file-name gnus-kill-files-directory
)))
2443 (setq gnus-score-file-list nil
)
2444 (if (not (gnus-use-long-file-name 'not-score
))
2445 ;; We do not use long file names, so we have to do some
2446 ;; directory traversing.
2447 (setq gnus-score-file-list
2449 (or gnus-short-name-score-file-cache
2451 (gnus-message 6 "Finding all score files...")
2452 (setq gnus-short-name-score-file-cache
2453 (gnus-score-score-files-1
2454 gnus-kill-files-directory
))
2455 (gnus-message 6 "Finding all score files...done")))))
2456 ;; We want long file names.
2457 (when (or (not gnus-score-file-list
)
2458 (not (car gnus-score-file-list
))
2459 (gnus-file-newer-than gnus-kill-files-directory
2460 (car gnus-score-file-list
)))
2461 (setq gnus-score-file-list
2462 (cons (nth 5 (file-attributes gnus-kill-files-directory
))
2465 gnus-kill-files-directory t
2466 (gnus-score-file-regexp)))))))
2467 (cdr gnus-score-file-list
)))
2469 (defun gnus-score-score-files-1 (dir)
2470 "Return all possible score files under DIR."
2471 (let ((files (list (expand-file-name dir
)))
2472 (regexp (gnus-score-file-regexp))
2473 (case-fold-search nil
)
2475 (while (setq file
(pop files
))
2477 ;; Ignore "." and "..".
2478 ((member (file-name-nondirectory file
) '("." ".."))
2480 ;; Add subtrees of directory to also be searched.
2481 ((and (file-directory-p file
)
2482 (not (member (file-truename file
) seen
)))
2483 (push (file-truename file
) seen
)
2484 (setq files
(nconc (directory-files file t nil t
) files
)))
2485 ;; Add files to the list of score files.
2486 ((string-match regexp file
)
2489 ;; Return a dummy value.
2490 (list "~/News/this.file.does.not.exist.SCORE"))))
2492 (defun gnus-score-file-regexp ()
2493 "Return a regexp that match all score files."
2494 (concat "\\(" (regexp-quote gnus-score-file-suffix
)
2495 "\\|" (regexp-quote gnus-adaptive-file-suffix
) "\\)\\'"))
2497 (defun gnus-score-find-bnews (group)
2498 "Return a list of score files for GROUP.
2499 The score files are those files in the ~/News/ directory which matches
2500 GROUP using BNews sys file syntax."
2501 (let* ((sfiles (append (gnus-score-score-files group
)
2502 gnus-internal-global-score-files
))
2503 (kill-dir (file-name-as-directory
2504 (expand-file-name gnus-kill-files-directory
)))
2505 (klen (length kill-dir
))
2506 (score-regexp (gnus-score-file-regexp))
2507 (trans (cdr (assq ?
: nnheader-file-name-translation-alist
)))
2508 ofiles not-match regexp
)
2510 (set-buffer (gnus-get-buffer-create "*gnus score files*"))
2511 (buffer-disable-undo (current-buffer))
2512 ;; Go through all score file names and create regexp with them
2516 (insert (car sfiles
))
2517 (goto-char (point-min))
2518 ;; First remove the suffix itself.
2519 (when (re-search-forward (concat "." score-regexp
) nil t
)
2520 (replace-match "" t t
)
2521 (goto-char (point-min))
2522 (if (looking-at (regexp-quote kill-dir
))
2523 ;; If the file name was just "SCORE", `klen' is one character
2525 (delete-char (min (1- (point-max)) klen
))
2526 (goto-char (point-max))
2527 (search-backward "/")
2528 (delete-region (1+ (point)) (point-min)))
2529 ;; If short file names were used, we have to translate slashes.
2530 (goto-char (point-min))
2531 (let ((regexp (concat
2532 "[/:" (if trans
(char-to-string trans
) "") "]")))
2533 (while (re-search-forward regexp nil t
)
2534 (replace-match "." t t
)))
2535 ;; Kludge to get rid of "nntp+" problems.
2536 (goto-char (point-min))
2537 (when (looking-at "nn[a-z]+\\+")
2538 (search-forward "+")
2542 ;; Kludge to deal with "++".
2543 (while (search-forward "+" nil t
)
2544 (replace-match "\\+" t t
))
2545 ;; Translate "all" to ".*".
2546 (goto-char (point-min))
2547 (while (search-forward "all" nil t
)
2548 (replace-match ".*" t t
))
2549 (goto-char (point-min))
2550 ;; Deal with "not."s.
2551 (if (looking-at "not.")
2554 (setq regexp
(concat "^" (buffer-substring 5 (point-max)) "$")))
2555 (setq regexp
(concat "^" (buffer-substring 1 (point-max)) "$"))
2556 (setq not-match nil
))
2557 ;; Finally - if this resulting regexp matches the group name,
2558 ;; we add this score file to the list of score files
2559 ;; applicable to this group.
2560 (when (or (and not-match
2561 (not (string-match regexp group
)))
2562 (and (not not-match
)
2563 (string-match regexp group
)))
2564 (push (car sfiles
) ofiles
)))
2565 (setq sfiles
(cdr sfiles
)))
2566 (kill-buffer (current-buffer))
2567 ;; Slight kludge here - the last score file returned should be
2568 ;; the local score file, whether it exists or not. This is so
2569 ;; that any score commands the user enters will go to the right
2570 ;; file, and not end up in some global score file.
2571 (let ((localscore (gnus-score-file-name group
)))
2572 (setq ofiles
(cons localscore
(delete localscore ofiles
))))
2573 (gnus-sort-score-files (nreverse ofiles
)))))
2575 (defun gnus-score-find-single (group)
2576 "Return list containing the score file for GROUP."
2577 (list (or gnus-newsgroup-adaptive-score-file
2578 (gnus-score-file-name group gnus-adaptive-file-suffix
))
2579 (gnus-score-file-name group
)))
2581 (defun gnus-score-find-hierarchical (group)
2582 "Return list of score files for GROUP.
2583 This includes the score file for the group and all its parents."
2584 (let* ((prefix (gnus-group-real-prefix group
))
2586 (group (gnus-group-real-name group
))
2588 (while (string-match "\\." group
(1+ start
))
2589 (setq start
(match-beginning 0))
2590 (push (substring group
0 start
) all
))
2594 (mapcar (lambda (group)
2595 (gnus-score-file-name group gnus-adaptive-file-suffix
))
2596 (setq all
(nreverse all
)))
2597 (mapcar 'gnus-score-file-name all
)))
2598 (if (equal prefix
"")
2602 (nnheader-translate-file-chars
2603 (concat (file-name-directory file
) prefix
2604 (file-name-nondirectory file
))))
2607 (defun gnus-score-file-rank (file)
2608 "Return a number that says how specific score FILE is.
2609 Destroys the current buffer."
2610 (if (member file gnus-internal-global-score-files
)
2613 (concat "^" (regexp-quote
2615 (file-name-as-directory gnus-kill-files-directory
))))
2617 (setq file
(substring file
(match-end 0))))
2619 (goto-char (point-min))
2622 (while (re-search-forward "[./]" nil t
)
2623 (push (buffer-substring beg
(1- (point)))
2626 (setq elems
(delete "all" elems
))
2629 (defun gnus-sort-score-files (files)
2630 "Sort FILES so that the most general files come first."
2631 (nnheader-temp-write nil
2635 (cons (inline (gnus-score-file-rank file
)) file
))
2638 (lambda (f) (cdr f
))
2639 (sort alist
'car-less-than-car
)))))
2641 (defun gnus-score-find-alist (group)
2642 "Return list of score files for GROUP.
2643 The list is determined from the variable gnus-score-file-alist."
2644 (let ((alist gnus-score-file-multiple-match-alist
)
2646 ;; if this group has been seen before, return the cached entry
2647 (if (setq score-files
(assoc group gnus-score-file-alist-cache
))
2648 (cdr score-files
) ;ensures caching groups with no matches
2649 ;; handle the multiple match alist
2651 (when (string-match (caar alist
) group
)
2653 (nconc score-files
(copy-sequence (cdar alist
)))))
2654 (setq alist
(cdr alist
)))
2655 (setq alist gnus-score-file-single-match-alist
)
2656 ;; handle the single match alist
2658 (when (string-match (caar alist
) group
)
2659 ;; progn used just in case ("regexp") has no files
2660 ;; and score-files is still nil. -sj
2661 ;; this can be construed as a "stop searching here" feature :>
2662 ;; and used to simplify regexps in the single-alist
2664 (nconc score-files
(copy-sequence (cdar alist
))))
2666 (setq alist
(cdr alist
)))
2667 ;; cache the score files
2668 (push (cons group score-files
) gnus-score-file-alist-cache
)
2671 (defun gnus-all-score-files (&optional group
)
2672 "Return a list of all score files for the current group."
2673 (let ((funcs gnus-score-find-score-files-function
)
2674 (group (or group gnus-newsgroup-name
))
2677 ;; Make sure funcs is a list.
2680 (setq funcs
(list funcs
)))
2681 ;; Get the initial score files for this group.
2683 (setq score-files
(nreverse (gnus-score-find-alist group
))))
2684 ;; Add any home adapt files.
2685 (let ((home (gnus-home-score-file group t
)))
2687 (push home score-files
)
2688 (setq gnus-newsgroup-adaptive-score-file home
)))
2689 ;; Check whether there is a `adapt-file' group parameter.
2690 (let ((param-file (gnus-group-find-parameter group
'adapt-file
)))
2692 (push param-file score-files
)
2693 (setq gnus-newsgroup-adaptive-score-file param-file
)))
2694 ;; Go through all the functions for finding score files (or actual
2695 ;; scores) and add them to a list.
2697 (when (gnus-functionp (car funcs
))
2699 (nconc score-files
(nreverse (funcall (car funcs
) group
)))))
2700 (setq funcs
(cdr funcs
)))
2701 ;; Add any home score files.
2702 (let ((home (gnus-home-score-file group
)))
2704 (push home score-files
)))
2705 ;; Check whether there is a `score-file' group parameter.
2706 (let ((param-file (gnus-group-find-parameter group
'score-file
)))
2708 (push param-file score-files
)))
2709 ;; Expand all files names.
2710 (let ((files score-files
))
2712 (when (stringp (car files
))
2713 (setcar files
(expand-file-name
2714 (car files
) gnus-kill-files-directory
)))
2716 (setq score-files
(nreverse score-files
))
2717 ;; Remove any duplicate score files.
2718 (while (and score-files
2719 (member (car score-files
) (cdr score-files
)))
2721 (let ((files score-files
))
2723 (if (member (cadr files
) (cddr files
))
2724 (setcdr files
(cddr files
))
2726 ;; Do the scoring if there are any score files for this group.
2729 (defun gnus-possibly-score-headers (&optional trace
)
2730 "Do scoring if scoring is required."
2731 (let ((score-files (gnus-all-score-files)))
2733 (gnus-score-headers score-files trace
))))
2735 (defun gnus-score-file-name (newsgroup &optional suffix
)
2736 "Return the name of a score file for NEWSGROUP."
2737 (let ((suffix (or suffix gnus-score-file-suffix
)))
2738 (nnheader-translate-file-chars
2740 ((or (null newsgroup
)
2741 (string-equal newsgroup
""))
2742 ;; The global score file is placed at top of the directory.
2743 (expand-file-name suffix gnus-kill-files-directory
))
2744 ((gnus-use-long-file-name 'not-score
)
2745 ;; Append ".SCORE" to newsgroup name.
2746 (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup
)
2748 gnus-kill-files-directory
))
2750 ;; Place "SCORE" under the hierarchical directory.
2751 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup
)
2753 gnus-kill-files-directory
))))))
2755 (defun gnus-score-search-global-directories (files)
2756 "Scan all global score directories for score files."
2757 ;; Set the variable `gnus-internal-global-score-files' to all
2758 ;; available global score files.
2759 (interactive (list gnus-global-score-files
))
2762 ;; #### /$ Unix-specific?
2763 (if (string-match "/$" (car files
))
2764 (setq out
(nconc (directory-files
2766 (concat (gnus-score-file-regexp) "$"))))
2767 (push (car files
) out
))
2768 (setq files
(cdr files
)))
2769 (setq gnus-internal-global-score-files out
)))
2771 (defun gnus-score-default-fold-toggle ()
2772 "Toggle folding for new score file entries."
2774 (setq gnus-score-default-fold
(not gnus-score-default-fold
))
2775 (if gnus-score-default-fold
2776 (gnus-message 1 "New score file entries will be case insensitive.")
2777 (gnus-message 1 "New score file entries will be case sensitive.")))
2779 ;;; Home score file.
2781 (defun gnus-home-score-file (group &optional adapt
)
2782 "Return the home score file for GROUP.
2783 If ADAPT, return the home adaptive file instead."
2784 (let ((list (if adapt gnus-home-adapt-file gnus-home-score-file
))
2786 ;; Make sure we have a list.
2787 (unless (listp list
)
2788 (setq list
(list list
)))
2789 ;; Go through the list and look for matches.
2790 (while (and (not found
)
2791 (setq elem
(pop list
)))
2798 ((gnus-functionp elem
)
2799 (funcall elem group
))
2802 (when (string-match (gnus-globalify-regexp (car elem
)) group
)
2803 (replace-match (cadr elem
) t nil group
))))))
2805 (nnheader-concat gnus-kill-files-directory found
))))
2807 (defun gnus-hierarchial-home-score-file (group)
2808 "Return the score file of the top-level hierarchy of GROUP."
2809 (if (string-match "^[^.]+\\." group
)
2810 (concat (match-string 0 group
) gnus-score-file-suffix
)
2811 ;; Group name without any dots.
2812 (concat group
(if (gnus-use-long-file-name 'not-score
) "." "/")
2813 gnus-score-file-suffix
)))
2815 (defun gnus-hierarchial-home-adapt-file (group)
2816 "Return the adapt file of the top-level hierarchy of GROUP."
2817 (if (string-match "^[^.]+\\." group
)
2818 (concat (match-string 0 group
) gnus-adaptive-file-suffix
)
2819 ;; Group name without any dots.
2820 (concat group
(if (gnus-use-long-file-name 'not-score
) "." "/")
2821 gnus-adaptive-file-suffix
)))
2823 (defun gnus-current-home-score-file (group)
2824 "Return the \"current\" regular score file."
2825 (car (nreverse (gnus-score-find-alist group
))))
2831 (defun gnus-decay-score (score)
2832 "Decay SCORE according to `gnus-score-decay-constant' and `gnus-score-decay-scale'."
2835 (* (if (< score
0) -
1 1)
2837 (max gnus-score-decay-constant
2839 gnus-score-decay-scale
)))))))
2841 (defun gnus-decay-scores (alist day
)
2842 "Decay non-permanent scores in ALIST."
2843 (let ((times (- (gnus-time-to-day (current-time)) day
))
2844 kill entry updated score n
)
2845 (unless (zerop times
) ;Done decays today already?
2846 (while (setq entry
(pop alist
))
2847 (when (stringp (car entry
))
2848 (setq entry
(cdr entry
))
2849 (while (setq kill
(pop entry
))
2852 (setq score
(or (nth 1 kill
)
2853 gnus-score-interactive-default-score
)
2855 (while (natnump (decf n
))
2856 (setq score
(funcall gnus-decay-score-function score
)))
2857 (setcdr kill
(cons score
2858 (cdr (cdr kill
)))))))))
2859 ;; Return whether this score file needs to be saved. By Je-haysuss!
2862 (defun gnus-score-regexp-bad-p (regexp)
2863 "Test whether REGEXP is safe for Gnus scoring.
2864 A regexp is unsafe if it matches newline or a buffer boundary.
2866 If the regexp is good, return nil. If the regexp is bad, return a
2867 cons cell (SYM . STRING), where the symbol SYM is `new' or `bad'.
2868 In the `new' case, the string is a safe replacement for REGEXP.
2869 In the `bad' case, the string is a unsafe subexpression of REGEXP,
2870 and we do not have a simple replacement to suggest.
2872 See `(Gnus)Scoring Tips' for examples of good regular expressions."
2873 (let (case-fold-search)
2875 ;; First, try a relatively fast necessary condition.
2876 ;; Notice ranges (like [^:] or [\t-\r]), \s>, \Sw, \W, \', \`:
2877 (string-match "\n\\|\\\\[SsW`']\\|\\[\\^\\|[\0-\n]-" regexp
)
2878 ;; Now break the regexp into tokens, and check each:
2879 (let ((tail regexp
) ; remaining regexp to check
2881 bad
; nil, or bad subexpression
2882 new
; nil, or replacement regexp so far
2883 end
) ; length of current token
2884 (while (and (not bad
)
2886 "\\`\\(\\\\[sS]?.\\|\\[\\^?]?[^]]*]\\|[^\\]\\)"
2888 (setq end
(match-end 0)
2889 tok
(substring tail
0 end
)
2890 tail
(substring tail end
))
2891 (if;; Is token `bad' (matching newline or buffer ends)?
2892 (or (member tok
'("\n" "\\W" "\\`" "\\'"))
2893 ;; This next handles "[...]", "\\s.", and "\\S.":
2894 (and (> end
2) (string-match tok
"\n")))
2896 ;; Try to suggest a replacement for tok ...
2897 (cond ((string-equal tok
"\\`") "^") ; or "\\(^\\)"
2898 ((string-equal tok
"\\'") "$") ; or "\\($\\)"
2899 ((string-match "\\[\\^" tok
) ; very common
2900 (concat (substring tok
0 -
1) "\n]")))))
2905 ;; good prefix so far:
2906 (substring regexp
0 (- (+ (length tail
) end
))))
2908 ;; No replacement idea, so give up:
2910 ;; tok is good, may need to extend new
2911 (and new
(setq new
(concat new tok
)))))
2912 ;; Now return a value:
2914 (bad (cons 'bad bad
))
2915 (new (cons 'new new
))
2919 (provide 'gnus-score
)
2921 ;;; gnus-score.el ends here