1 ;;; gnus-score.el --- scoring code for Gnus
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <amanda@iesd.auc.dk>
6 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
32 (defvar gnus-score-expiry-days
7
33 "*Number of days before unused score file entries are expired.")
35 (defvar gnus-orphan-score nil
36 "*All orphans get this score added. Set in the score file.")
38 (defvar gnus-default-adaptive-score-alist
39 '((gnus-kill-file-mark)
41 (gnus-read-mark (from 3) (subject 30))
42 (gnus-catchup-mark (subject -
10))
43 (gnus-killed-mark (from -
1) (subject -
20))
44 (gnus-del-mark (from -
2) (subject -
15)))
45 "*Alist of marks and scores.")
47 (defvar gnus-score-mimic-keymap nil
48 "*Have the score entry functions pretend that they are a keymap.")
50 (defvar gnus-score-exact-adapt-limit
10
51 "*Number that says how long a match has to be before using substring matching.
52 When doing adaptive scoring, one normally uses fuzzy or substring
53 matching. However, if the header one matches is short, the possibility
54 for false positives is great, so if the length of the match is less
55 than this variable, exact matching will be used.
57 If this variable is nil, exact matching will always be used.")
61 ;; Internal variables.
63 (defvar gnus-score-help-winconf nil
)
64 (defvar gnus-adaptive-score-alist gnus-default-adaptive-score-alist
)
65 (defvar gnus-score-trace nil
)
66 (defvar gnus-score-edit-buffer nil
)
68 (defvar gnus-score-alist nil
69 "Alist containing score information.
70 The keys can be symbols or strings. The following symbols are defined.
72 touched: If this alist has been modified.
73 mark: Automatically mark articles below this.
74 expunge: Automatically expunge articles below this.
75 files: List of other score files to load when loading this one.
76 eval: Sexp to be evaluated when the score file is loaded.
78 String entries have the form (HEADER (MATCH TYPE SCORE DATE) ...)
79 where HEADER is the header being scored, MATCH is the string we are
80 looking for, TYPE is a flag indicating whether it should use regexp or
81 substring matching, SCORE is the score to add and DATE is the date
82 of the last successful match.")
84 (defvar gnus-score-cache nil
)
85 (defvar gnus-scores-articles nil
)
86 (defvar gnus-header-index nil
)
87 (defvar gnus-score-index nil
)
90 (autoload 'gnus-uu-ctl-map
"gnus-uu" nil nil
'keymap
)
91 (autoload 'appt-select-lowest-window
"appt.el"))
93 ;;; Summary mode score maps.
95 (defvar gnus-summary-score-map nil
)
97 (define-prefix-command 'gnus-summary-score-map
)
98 (define-key gnus-summary-mode-map
"V" 'gnus-summary-score-map
)
99 (define-key gnus-summary-score-map
"s" 'gnus-summary-set-score
)
100 (define-key gnus-summary-score-map
"a" 'gnus-summary-score-entry
)
101 (define-key gnus-summary-score-map
"S" 'gnus-summary-current-score
)
102 (define-key gnus-summary-score-map
"c" 'gnus-score-change-score-file
)
103 (define-key gnus-summary-score-map
"m" 'gnus-score-set-mark-below
)
104 (define-key gnus-summary-score-map
"x" 'gnus-score-set-expunge-below
)
105 (define-key gnus-summary-score-map
"e" 'gnus-score-edit-alist
)
106 (define-key gnus-summary-score-map
"f" 'gnus-score-edit-file
)
107 (define-key gnus-summary-score-map
"t" 'gnus-score-find-trace
)
108 (define-key gnus-summary-score-map
"C" 'gnus-score-customize
)
112 ;; Summary score file commands
114 ;; Much modification of the kill (ahem, score) code and lots of the
115 ;; functions are written by Per Abrahamsen <amanda@iesd.auc.dk>.
117 (defun gnus-summary-lower-score (&optional score
)
118 "Make a score entry based on the current article.
119 The user will be prompted for header to score on, match type,
120 permanence, and the string to be used. The numerical prefix will be
123 (gnus-summary-increase-score (- (gnus-score-default score
))))
125 (defun gnus-summary-increase-score (&optional score
)
126 "Make a score entry based on the current article.
127 The user will be prompted for header to score on, match type,
128 permanence, and the string to be used. The numerical prefix will be
131 (gnus-set-global-variables)
132 (let* ((nscore (gnus-score-default score
))
133 (prefix (if (< nscore
0) ?L ?I
))
134 (increase (> nscore
0))
136 '((?a
"from" nil nil string
)
137 (?s
"subject" nil nil string
)
138 (?b
"body" "" nil body-string
)
139 (?h
"head" "" nil body-string
)
140 (?i
"message-id" nil t string
)
141 (?t
"references" "message-id" t string
)
142 (?x
"xref" nil nil string
)
143 (?l
"lines" nil nil number
)
144 (?d
"date" nil nil date
)
145 (?f
"followup" nil nil string
)))
147 '((?s s
"substring" string
)
148 (?e e
"exact string" string
)
149 (?f f
"fuzzy string" string
)
150 (?r r
"regexp string" string
)
151 (?s s
"substring" body-string
)
152 (?r s
"regexp string" body-string
)
153 (?b before
"before date" date
)
154 (?a at
"at date" date
)
155 (?n now
"this date" date
)
156 (?
< < "less than number" number
)
157 (?
> > "greater than number" number
)
158 (?
= = "equal to number" number
)))
160 (list (list ?t
(current-time-string) "temporary")
161 '(?p perm
"permanent") '(?i now
"immediate")))
162 (mimic gnus-score-mimic-keymap
)
163 hchar entry temporary tchar pchar end type
)
164 ;; First we read the header to score.
169 (message "%c-" prefix
))
170 (message "%s header (%s?): " (if increase
"Increase" "Lower")
171 (mapconcat (lambda (s) (char-to-string (car s
)))
173 (setq hchar
(read-char))
174 (if (not (or (= hchar ??
) (= hchar ?\C-h
)))
177 (gnus-score-insert-help "Match on header" char-to-header
1)))
179 (and (get-buffer "*Score Help*")
181 (kill-buffer "*Score Help*")
182 (and gnus-score-help-winconf
183 (set-window-configuration gnus-score-help-winconf
))))
185 (or (setq entry
(assq (downcase hchar
) char-to-header
))
189 (if mimic
(message "%c %c" prefix hchar
) (message ""))))
190 (if (or end
(/= (downcase hchar
) hchar
))
192 ;; This was a majuscle, so we end reading and set the defaults.
193 (if mimic
(message "%c %c" prefix hchar
) (message ""))
195 temporary
(current-time-string)))
197 ;; We continue reading - the type.
202 (message "%c %c-" prefix hchar
))
203 (message "%s header '%s' with match type (%s?): "
204 (if increase
"Increase" "Lower")
206 (mapconcat (lambda (s)
207 (if (eq (nth 4 entry
)
209 (char-to-string (car s
))
212 (setq tchar
(read-char))
213 (if (not (or (= tchar ??
) (= tchar ?\C-h
)))
216 (gnus-score-insert-help "Match type" char-to-type
2)))
218 (and (get-buffer "*Score Help*")
220 (and gnus-score-help-winconf
221 (set-window-configuration gnus-score-help-winconf
))
222 (kill-buffer "*Score Help*")))
224 (or (setq type
(nth 1 (assq (downcase tchar
) char-to-type
)))
227 (if mimic
(message "%c %c" prefix hchar
) (message ""))
229 (if (or end
(/= (downcase tchar
) tchar
))
231 ;; It was a majuscle, so we end reading and the the default.
232 (if mimic
(message "%c %c %c" prefix hchar tchar
)
234 (setq temporary
(current-time-string)))
236 ;; We continue reading.
241 (message "%c %c %c-" prefix hchar tchar
))
242 (message "%s permanence (%s?): " (if increase
"Increase" "Lower")
243 (mapconcat (lambda (s) (char-to-string (car s
)))
245 (setq pchar
(read-char))
246 (if (not (or (= pchar ??
) (= pchar ?\C-h
)))
249 (gnus-score-insert-help "Match permanence" char-to-perm
2)))
251 (and (get-buffer "*Score Help*")
253 (and gnus-score-help-winconf
254 (set-window-configuration gnus-score-help-winconf
))
255 (kill-buffer "*Score Help*")))
257 (if mimic
(message "%c %c %c" prefix hchar tchar pchar
)
259 (if (setq temporary
(nth 1 (assq pchar char-to-perm
)))
264 (message "%c %c %c %c" prefix hchar tchar pchar
)
267 ;; We have all the data, so we enter this score.
270 (gnus-summary-score-entry
271 (nth 1 entry
) ; Header
272 (if (string= (nth 2 entry
) "") ""
273 (gnus-summary-header (or (nth 2 entry
) (nth 1 entry
)))) ; Match
275 (if (eq 's score
) nil score
) ; Score
276 (if (eq 'perm temporary
) ; Temp
279 (not (nth 3 entry
))) ; Prompt
282 (defun gnus-score-insert-help (string alist idx
)
283 (setq gnus-score-help-winconf
(current-window-configuration))
285 (set-buffer (get-buffer-create "*Score Help*"))
286 (buffer-disable-undo (current-buffer))
287 (delete-windows-on (current-buffer))
289 (insert string
":\n\n")
294 ;; find the longest string to display
296 (setq n
(length (nth idx
(car list
))))
299 (setq list
(cdr list
)))
300 (setq max
(+ max
4)) ; %c, `:', SPACE, a SPACE at end
301 (setq n
(/ (window-width) max
)) ; items per line
302 (setq width
(/ (window-width) n
)) ; width of each item
303 ;; insert `n' items, each in a field of width `width'
308 (delete-char -
1) ; the `\n' takes a char
310 (setq pad
(- width
3))
311 (setq format
(concat "%c: %-" (int-to-string pad
) "s"))
312 (insert (format format
(car (car alist
)) (nth idx
(car alist
))))
313 (setq alist
(cdr alist
))
315 ;; display ourselves in a small window at the bottom
316 (appt-select-lowest-window)
318 (pop-to-buffer "*Score Help*")
319 (shrink-window-if-larger-than-buffer)
320 (select-window (get-buffer-window gnus-summary-buffer
))))
322 (defun gnus-summary-header (header &optional no-err
)
323 ;; Return HEADER for current articles, or error.
324 (let ((article (gnus-summary-article-number))
327 (if (and (setq headers
(gnus-get-header-by-number article
))
329 (aref headers
(nth 1 (assoc header gnus-header-index
)))
332 (error "Pseudo-articles can't be scored")))
334 (error "No article on current line")
337 (defun gnus-summary-score-entry
338 (header match type score date
&optional prompt silent
)
339 "Enter score file entry.
340 HEADER is the header being scored.
341 MATCH is the string we are looking for.
342 TYPE is the match type: substring, regexp, exact, fuzzy.
343 SCORE is the score to add.
344 DATE is the expire date, or nil for no expire, or 'now for immediate expire.
345 If optional argument `PROMPT' is non-nil, allow user to edit match.
346 If optional argument `SILENT' is nil, show effect of score entry."
348 (list (completing-read "Header: "
350 (lambda (x) (fboundp (nth 2 x
)))
352 (read-string "Match: ")
353 (if (y-or-n-p "Use regexp match? ") 'r
's
)
354 (and current-prefix-arg
355 (prefix-numeric-value current-prefix-arg
))
356 (cond ((not (y-or-n-p "Add to score file? "))
358 ((y-or-n-p "Expire kill? ")
359 (current-time-string))
361 ;; Regexp is the default type.
362 (if (eq type t
) (setq type
'r
))
363 ;; Simplify matches...
364 (cond ((or (eq type
'r
) (eq type
's
) (eq type nil
))
365 (setq match
(if match
(gnus-simplify-subject-re match
) "")))
367 (setq match
(gnus-simplify-subject-fuzzy match
))))
368 (let ((score (gnus-score-default score
))
369 (header (downcase header
)))
370 (and prompt
(setq match
(read-string
371 (format "Match %s on %s, %s: "
372 (cond ((eq date
'now
)
378 (if (< score
0) "lower" "raise"))
380 (int-to-string match
)
382 (and (>= (nth 1 (assoc header gnus-header-index
)) 0)
383 (eq (nth 2 (assoc header gnus-header-index
)) 'gnus-score-string
)
385 (gnus-summary-score-effect header match type score
))
387 ;; If this is an integer comparison, we transform from string to int.
388 (and (eq (nth 2 (assoc header gnus-header-index
)) 'gnus-score-integer
)
389 (setq match
(string-to-int match
)))
393 (and (= score gnus-score-interactive-default-score
)
397 (list match score
(and date
(gnus-day-number date
)) type
))
399 (list match score
(gnus-day-number date
)))
404 (old (gnus-score-get header
))
406 ;; We see whether we can collapse some score entries.
407 ;; This isn't quite correct, because there may be more elements
408 ;; later on with the same key that have matching elems... Hm.
410 (setq elem
(assoc match old
))
411 (eq (nth 3 elem
) (nth 3 new
))
412 (or (and (numberp (nth 2 elem
)) (numberp (nth 2 new
)))
413 (and (not (nth 2 elem
)) (not (nth 2 new
)))))
414 ;; Yup, we just add this new score to the old elem.
415 (setcar (cdr elem
) (+ (or (nth 1 elem
)
416 gnus-score-interactive-default-score
)
418 gnus-score-interactive-default-score
)))
419 ;; Nope, we have to add a new elem.
420 (gnus-score-set header
(if old
(cons new old
) (list new
)))))
421 (gnus-score-set 'touched
'(t)))))
423 (defun gnus-summary-score-effect (header match type score
)
424 "Simulate the effect of a score file entry.
425 HEADER is the header being scored.
426 MATCH is the string we are looking for.
427 TYPE is a flag indicating if it is a regexp or substring.
428 SCORE is the score to add."
429 (interactive (list (completing-read "Header: "
431 (lambda (x) (fboundp (nth 2 x
)))
433 (read-string "Match: ")
434 (y-or-n-p "Use regexp match? ")
435 (prefix-numeric-value current-prefix-arg
)))
437 (or (and (stringp match
) (> (length match
) 0))
439 (goto-char (point-min))
440 (let ((regexp (cond ((eq type
'f
)
441 (gnus-simplify-subject-fuzzy match
))
443 (t (concat "\\`.*" (regexp-quote match
) ".*\\'")))))
445 (let ((content (gnus-summary-header header
'noerr
))
446 (case-fold-search t
))
449 (string-equal (gnus-simplify-subject-fuzzy content
)
451 (string-match regexp content
))
452 (gnus-summary-raise-score score
))))
453 (beginning-of-line 2)))))
455 (defun gnus-summary-score-crossposting (score date
)
456 ;; Enter score file entry for current crossposting.
457 ;; SCORE is the score to add.
458 ;; DATE is the expire date.
459 (let ((xref (gnus-summary-header "xref"))
462 (or xref
(error "This article is not crossposted"))
463 (while (string-match " \\([^ \t]+\\):" xref start
)
464 (setq start
(match-end 0))
467 (substring xref
(match-beginning 1) (match-end 1)))
468 gnus-newsgroup-name
))
469 (gnus-summary-score-entry
470 "xref" (concat " " group
":") nil score date t
)))))
477 ;; All score code written by Per Abrahamsen <abraham@iesd.auc.dk>.
479 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
480 (defun gnus-score-set-mark-below (score)
481 "Automatically mark articles with score below SCORE as read."
483 (list (or (and current-prefix-arg
(prefix-numeric-value current-prefix-arg
))
484 (string-to-int (read-string "Mark below: ")))))
485 (setq score
(or score gnus-summary-default-score
0))
486 (gnus-score-set 'mark
(list score
))
487 (gnus-score-set 'touched
'(t))
488 (setq gnus-summary-mark-below score
)
489 (gnus-summary-update-lines))
491 (defun gnus-score-set-expunge-below (score)
492 "Automatically expunge articles with score below SCORE."
494 (list (or (and current-prefix-arg
(prefix-numeric-value current-prefix-arg
))
495 (string-to-int (read-string "Expunge below: ")))))
496 (setq score
(or score gnus-summary-default-score
0))
497 (gnus-score-set 'expunge
(list score
))
498 (gnus-score-set 'touched
'(t)))
500 (defun gnus-score-set (symbol value
&optional alist
)
501 ;; Set SYMBOL to VALUE in ALIST.
506 (gnus-score-load (gnus-score-file-name gnus-newsgroup-name
))
508 (entry (assoc symbol alist
)))
509 (cond ((gnus-score-get 'read-only alist
)
510 ;; This is a read-only score file, so we do nothing.
513 (setcdr entry value
))
515 (error "Empty alist"))
518 (cons (cons symbol value
) (cdr alist
)))))))
520 (defun gnus-score-get (symbol &optional alist
)
521 ;; Get SYMBOL's definition in ALIST.
527 (gnus-score-file-name gnus-newsgroup-name
))
528 gnus-score-alist
)))))
530 (defun gnus-score-change-score-file (file)
531 "Change current score alist."
533 (list (read-file-name "Edit score file: " gnus-kill-files-directory
)))
534 (gnus-score-load-file file
)
535 (gnus-set-mode-line 'summary
))
537 (defun gnus-score-edit-alist (file)
538 "Edit the current score alist."
539 (interactive (list gnus-current-score-file
))
540 (let ((winconf (current-window-configuration)))
541 (and (buffer-name gnus-summary-buffer
) (gnus-score-save))
542 (setq gnus-score-edit-buffer
(find-file-noselect file
))
543 (gnus-configure-windows 'edit-score
)
545 (make-local-variable 'gnus-prev-winconf
)
546 (setq gnus-prev-winconf winconf
))
548 4 (substitute-command-keys
549 "\\<gnus-score-mode-map>\\[gnus-score-edit-done] to save edits")))
551 (defun gnus-score-edit-file (file)
554 (list (read-file-name "Edit score file: " gnus-kill-files-directory
)))
555 (and (buffer-name gnus-summary-buffer
) (gnus-score-save))
556 (let ((winconf (current-window-configuration)))
557 (setq gnus-score-edit-buffer
(find-file-noselect file
))
558 (gnus-configure-windows 'edit-score
)
560 (make-local-variable 'gnus-prev-winconf
)
561 (setq gnus-prev-winconf winconf
))
563 4 (substitute-command-keys
564 "\\<gnus-score-mode-map>\\[gnus-score-edit-done] to save edits")))
566 (defun gnus-score-load-file (file)
567 ;; Load score file FILE. Returns a list a retrieved score-alists.
568 (setq gnus-kill-files-directory
(or gnus-kill-files-directory
"~/News/"))
569 (let* ((file (expand-file-name
570 (or (and (string-match
571 (concat "^" (expand-file-name
572 gnus-kill-files-directory
))
573 (expand-file-name file
))
575 (concat gnus-kill-files-directory file
))))
576 (cached (assoc file gnus-score-cache
))
577 (global (member file gnus-internal-global-score-files
))
580 ;; The score file was already loaded.
581 (setq alist
(cdr cached
))
582 ;; We load the score file.
583 (setq gnus-score-alist nil
)
584 (setq alist
(gnus-score-load-score-alist file
))
585 ;; We add '(touched) to the alist to signify that it hasn't been
587 (or (assq 'touched alist
) (setq alist
(cons (list 'touched nil
) alist
)))
588 ;; If it is a global score file, we make it read-only.
590 (not (assq 'read-only alist
))
591 (setq alist
(cons (list 'read-only t
) alist
)))
593 (setq gnus-score-cache
594 (cons (cons file alist
) gnus-score-cache
)))
595 ;; If there are actual scores in the alist, we add it to the
596 ;; return value of this function.
597 (if (memq t
(mapcar (lambda (e) (stringp (car e
))) alist
))
598 (setq lists
(list alist
)))
599 ;; Treat the other possible atoms in the score alist.
600 (let ((mark (car (gnus-score-get 'mark alist
)))
601 (expunge (car (gnus-score-get 'expunge alist
)))
602 (mark-and-expunge (car (gnus-score-get 'mark-and-expunge alist
)))
603 (files (gnus-score-get 'files alist
))
604 (exclude-files (gnus-score-get 'exclude-files alist
))
605 (orphan (car (gnus-score-get 'orphan alist
)))
606 (adapt (gnus-score-get 'adapt alist
))
607 (local (gnus-score-get 'local alist
))
608 (eval (car (gnus-score-get 'eval alist
))))
609 ;; We do not respect eval and files atoms from global score
611 (and files
(not global
)
612 (setq lists
(apply 'append lists
613 (mapcar (lambda (file)
614 (gnus-score-load-file file
))
616 (and eval
(not global
) (eval eval
))
617 ;; We then expand any exclude-file directives.
618 (setq gnus-scores-exclude-files
622 (expand-file-name sfile
(file-name-directory file
)))
623 exclude-files
) gnus-scores-exclude-files
))
627 (set-buffer gnus-summary-buffer
)
629 (and (consp (car local
))
630 (symbolp (car (car local
)))
632 (make-local-variable (car (car local
)))
633 (set (car (car local
)) (nth 1 (car local
)))))
634 (setq local
(cdr local
)))))
635 (if orphan
(setq gnus-orphan-score orphan
))
636 (setq gnus-adaptive-score-alist
637 (cond ((equal adapt
'(t))
638 (setq gnus-newsgroup-adaptive t
)
639 gnus-default-adaptive-score-alist
)
640 ((equal adapt
'(ignore))
641 (setq gnus-newsgroup-adaptive nil
))
643 (setq gnus-newsgroup-adaptive t
)
646 ;;(setq gnus-newsgroup-adaptive gnus-use-adaptive-scoring)
647 gnus-default-adaptive-score-alist
)))
648 (setq gnus-summary-mark-below
649 (or mark mark-and-expunge gnus-summary-mark-below
))
650 (setq gnus-summary-expunge-below
651 (or expunge mark-and-expunge gnus-summary-expunge-below
)))
652 (setq gnus-current-score-file file
)
653 (setq gnus-score-alist alist
)
656 (defun gnus-score-load (file)
658 (let ((cache (assoc file gnus-score-cache
)))
660 (setq gnus-score-alist
(cdr cache
))
661 (setq gnus-score-alist nil
)
662 (gnus-score-load-score-alist file
)
664 (setq gnus-score-alist
(copy-alist '((touched nil
)))))
665 (setq gnus-score-cache
666 (cons (cons file gnus-score-alist
) gnus-score-cache
)))))
668 (defun gnus-score-remove-from-cache (file)
669 (setq gnus-score-cache
670 (delq (assoc file gnus-score-cache
) gnus-score-cache
)))
672 (defun gnus-score-load-score-alist (file)
674 (if (file-readable-p file
)
677 (gnus-set-work-buffer)
678 (insert-file-contents file
)
679 (goto-char (point-min))
680 ;; Only do the loading if the score file isn't empty.
681 (if (save-excursion (re-search-forward "[()0-9a-zA-Z]" nil t
))
684 (read (current-buffer))
687 (gnus-message 3 "Problem with score file %s" file
)
691 (if (eq (car alist
) 'setq
)
692 (setq gnus-score-alist
(gnus-score-transform-old-to-new alist
))
693 (setq gnus-score-alist alist
))
694 (setq gnus-score-alist
695 (gnus-score-check-syntax gnus-score-alist file
)))
696 (setq gnus-score-alist nil
))))
698 (defun gnus-score-check-syntax (alist file
)
703 (gnus-message 1 "Score file is not a list: %s" file
)
709 (while (and a
(not err
))
710 (cond ((not (listp (car a
)))
711 (gnus-message 3 "Illegal score element %s in %s" (car a
) file
)
713 ((and (stringp (car (car a
)))
714 (not (listp (nth 1 (car a
)))))
715 (gnus-message 3 "Illegal header match %s in %s" (nth 1 (car a
)) file
)
725 (defun gnus-score-transform-old-to-new (alist)
726 (let* ((alist (nth 2 alist
))
728 (if (eq (car alist
) 'quote
)
729 (setq alist
(nth 1 alist
)))
731 (setq entry
(car alist
))
732 (if (stringp (car entry
))
733 (let ((scor (cdr entry
)))
734 (setq out
(cons entry out
))
737 (list (car (car scor
)) (nth 2 (car scor
))
738 (and (nth 3 (car scor
))
739 (gnus-day-number (nth 3 (car scor
))))
740 (if (nth 1 (car scor
)) 'r
's
)))
741 (setq scor
(cdr scor
))))
742 (setq out
(cons (if (not (listp (cdr entry
)))
743 (list (car entry
) (cdr entry
))
746 (setq alist
(cdr alist
)))
747 (cons (list 'touched t
) (nreverse out
))))
749 (defun gnus-score-save ()
750 ;; Save all score information.
751 (let ((cache gnus-score-cache
))
753 (setq gnus-score-alist nil
)
754 (set-buffer (get-buffer-create "*Score*"))
755 (buffer-disable-undo (current-buffer))
756 (let (entry score file
)
758 (setq entry
(car cache
)
762 (if (or (not (equal (gnus-score-get 'touched score
) '(t)))
763 (gnus-score-get 'read-only score
)
764 (and (file-exists-p file
)
765 (not (file-writable-p file
))))
767 (setq score
(setcdr entry
(delq (assq 'touched score
) score
)))
769 (let (emacs-lisp-mode-hook)
770 (if (string-match (concat gnus-adaptive-file-suffix
"$") file
)
771 ;; This is an adaptive score file, so we do not run
772 ;; it through `pp'. These files can get huge, and
773 ;; are not meant to be edited by human hands.
774 (insert (format "%S" score
))
775 ;; This is a normal score file, so we print it very
777 (pp score
(current-buffer))))
778 (if (not (gnus-make-directory (file-name-directory file
)))
780 ;; If the score file is empty, we delete it.
781 (if (zerop (buffer-size))
783 ;; There are scores, so we write the file.
784 (and (file-writable-p file
)
785 (write-region (point-min) (point-max)
786 file nil
'silent
)))))))
787 (kill-buffer (current-buffer)))))
789 (defun gnus-score-headers (score-files &optional trace
)
790 ;; Score `gnus-newsgroup-headers'.
792 ;; PLM: probably this is not the best place to clear orphan-score
793 (setq gnus-orphan-score nil
)
794 (setq gnus-scores-articles nil
)
795 (setq gnus-scores-exclude-files nil
)
796 ;; Load the score files.
798 (if (stringp (car score-files
))
799 ;; It is a string, which means that it's a score file name,
800 ;; so we load the score file and add the score alist to
801 ;; the list of alists.
802 (setq scores
(nconc (gnus-score-load-file (car score-files
)) scores
))
803 ;; It is an alist, so we just add it to the list directly.
804 (setq scores
(nconc (car score-files
) scores
)))
805 (setq score-files
(cdr score-files
)))
806 ;; Prune the score files that are to be excluded, if any.
807 (if (not gnus-scores-exclude-files
)
812 (and (setq c
(rassq (car s
) gnus-score-cache
))
813 (member (car c
) gnus-scores-exclude-files
)
814 (setq scores
(delq (car s
) scores
)))
816 (if (not (and gnus-summary-default-score
818 (> (length gnus-newsgroup-headers
)
819 (length gnus-newsgroup-scored
))))
821 (let* ((entries gnus-header-index
)
822 (now (gnus-day-number (current-time-string)))
823 (expire (- now gnus-score-expiry-days
))
824 (headers gnus-newsgroup-headers
)
825 (current-score-file gnus-current-score-file
)
827 (gnus-message 5 "Scoring...")
828 ;; Create articles, an alist of the form `(HEADER . SCORE)'.
830 (setq header
(car headers
)
831 headers
(cdr headers
))
832 ;; WARNING: The assq makes the function O(N*S) while it could
833 ;; be written as O(N+S), where N is (length gnus-newsgroup-headers)
834 ;; and S is (length gnus-newsgroup-scored).
835 (or (assq (mail-header-number header
) gnus-newsgroup-scored
)
836 (setq gnus-scores-articles
;Total of 2 * N cons-cells used.
837 (cons (cons header
(or gnus-summary-default-score
0))
838 gnus-scores-articles
))))
841 (set-buffer (get-buffer-create "*Headers*"))
842 (buffer-disable-undo (current-buffer))
844 ;; Set the global variant of this variable.
845 (setq gnus-current-score-file current-score-file
)
847 (if gnus-orphan-score
849 (setq gnus-score-index
850 (nth 1 (assoc "references" gnus-header-index
)))
851 (gnus-score-orphans gnus-orphan-score
)))
852 ;; Run each header through the score process.
854 (setq entry
(car entries
)
856 entries
(cdr entries
))
857 (setq gnus-score-index
(nth 1 (assoc header gnus-header-index
)))
858 (if (< 0 (apply 'max
(mapcar
860 (length (gnus-score-get header score
)))
862 (funcall (nth 2 entry
) scores header now expire trace
)))
863 ;; Remove the buffer.
864 (kill-buffer (current-buffer)))
866 ;; Add articles to `gnus-newsgroup-scored'.
867 (while gnus-scores-articles
868 (or (= gnus-summary-default-score
(cdr (car gnus-scores-articles
)))
869 (setq gnus-newsgroup-scored
870 (cons (cons (mail-header-number
871 (car (car gnus-scores-articles
)))
872 (cdr (car gnus-scores-articles
)))
873 gnus-newsgroup-scored
)))
874 (setq gnus-scores-articles
(cdr gnus-scores-articles
)))
876 (gnus-message 5 "Scoring...done")))))
879 (defun gnus-get-new-thread-ids (articles)
880 (let ((index (nth 1 (assoc "message-id" gnus-header-index
)))
881 (refind gnus-score-index
)
882 id-list art this tref
)
884 (setq art
(car articles
)
885 this
(aref (car art
) index
)
886 tref
(aref (car art
) refind
)
887 articles
(cdr articles
))
888 (if (string-equal tref
"") ;no references line
889 (setq id-list
(cons this id-list
))))
892 ;; Orphan functions written by plm@atcmp.nl (Peter Mutsaers).
893 (defun gnus-score-orphans (score)
894 (let ((new-thread-ids (gnus-get-new-thread-ids gnus-scores-articles
))
895 alike articles art arts this last this-id
)
897 (setq gnus-scores-articles
(sort gnus-scores-articles
'gnus-score-string
<)
898 articles gnus-scores-articles
)
900 ;;more or less the same as in gnus-score-string
903 (setq art
(car articles
)
904 this
(aref (car art
) gnus-score-index
)
905 articles
(cdr articles
))
906 ;;completely skip if this is empty (not a child, so not an orphan)
907 (if (not (string= this
""))
908 (if (equal last this
)
909 ;; O(N*H) cons-cells used here, where H is the number of
911 (setq alike
(cons art alike
))
914 ;; Insert the line, with a text property on the
915 ;; terminating newline referring to the articles with
918 (put-text-property (1- (point)) (point) 'articles alike
)))
919 (setq alike
(list art
)
921 (and last
; Bwadr, duplicate code.
924 (put-text-property (1- (point)) (point) 'articles alike
)))
926 ;; PLM: now delete those lines that contain an entry from new-thread-ids
927 (while new-thread-ids
928 (setq this-id
(car new-thread-ids
)
929 new-thread-ids
(cdr new-thread-ids
))
930 (goto-char (point-min))
931 (while (search-forward this-id nil t
)
932 ;; found a match. remove this line
936 ;; now for each line: update its articles with score by moving to
937 ;; every end-of-line in the buffer and read the articles property
938 (goto-char (point-min))
941 (setq arts
(get-text-property (point) 'articles
))
945 (setcdr art
(+ score
(cdr art
))))
949 (defun gnus-score-integer (scores header now expire
&optional trace
)
950 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
955 (setq alist
(car scores
)
957 entries
(assoc header alist
))
958 (while (cdr entries
) ;First entry is the header index.
959 (let* ((rest (cdr entries
))
962 (type (or (nth 3 kill
) '>))
963 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
966 (match-func (if (or (eq type
'>) (eq type
'<) (eq type
'<=)
967 (eq type
'>=) (eq type
'=))
969 (error "Illegal match type: %s" type
)))
970 (articles gnus-scores-articles
))
971 ;; Instead of doing all the clever stuff that
972 ;; `gnus-score-string' does to minimize searches and stuff,
973 ;; I will assume that people generally will put so few
974 ;; matches on numbers that any cleverness will take more
975 ;; time than one would gain.
977 (and (funcall match-func
978 (or (aref (car (car articles
)) gnus-score-index
) 0)
981 (and trace
(setq gnus-score-trace
982 (cons (cons (car (car articles
)) kill
)
985 (setcdr (car articles
) (+ score
(cdr (car articles
))))))
986 (setq articles
(cdr articles
)))
987 ;; Update expire date
988 (cond ((null date
)) ;Permanent entry.
989 (found ;Match, update date.
990 (gnus-score-set 'touched
'(t) alist
)
991 (setcar (nthcdr 2 kill
) now
))
992 ((< date expire
) ;Old entry, remove.
993 (gnus-score-set 'touched
'(t) alist
)
994 (setcdr entries
(cdr rest
))
995 (setq rest entries
)))
996 (setq entries rest
))))))
998 (defun gnus-score-date (scores header now expire
&optional trace
)
999 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
1004 (setq alist
(car scores
)
1006 entries
(assoc header alist
))
1007 (while (cdr entries
) ;First entry is the header index.
1008 (let* ((rest (cdr entries
))
1010 (match (timezone-make-date-sortable (nth 0 kill
)))
1011 (type (or (nth 3 kill
) 'before
))
1012 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1016 (cond ((eq type
'after
) 'string
<)
1017 ((eq type
'before
) 'gnus-string
>)
1018 ((eq type
'at
) 'string
=)
1019 (t (error "Illegal match type: %s" type
))))
1020 (articles gnus-scores-articles
)
1022 ;; Instead of doing all the clever stuff that
1023 ;; `gnus-score-string' does to minimize searches and stuff,
1024 ;; I will assume that people generally will put so few
1025 ;; matches on numbers that any cleverness will take more
1026 ;; time than one would gain.
1029 (setq l
(aref (car (car articles
)) gnus-score-index
))
1030 (funcall match-func match
(timezone-make-date-sortable l
))
1032 (and trace
(setq gnus-score-trace
1033 (cons (cons (car (car articles
)) kill
)
1036 (setcdr (car articles
) (+ score
(cdr (car articles
))))))
1037 (setq articles
(cdr articles
)))
1038 ;; Update expire date
1039 (cond ((null date
)) ;Permanent entry.
1040 (found ;Match, update date.
1041 (gnus-score-set 'touched
'(t) alist
)
1042 (setcar (nthcdr 2 kill
) now
))
1043 ((< date expire
) ;Old entry, remove.
1044 (gnus-score-set 'touched
'(t) alist
)
1045 (setcdr entries
(cdr rest
))
1046 (setq rest entries
)))
1047 (setq entries rest
))))))
1049 (defun gnus-score-body (scores header now expire
&optional trace
)
1051 (set-buffer nntp-server-buffer
)
1053 (let* ((buffer-read-only nil
)
1054 (articles gnus-scores-articles
)
1055 (last (mail-header-number (car (car gnus-scores-articles
))))
1057 (request-func (cond ((string= "head" (downcase header
))
1059 ((string= "body" (downcase header
))
1061 (t 'gnus-request-article
)))
1062 entries alist ofunc article
)
1063 ;; Not all backends support partial fetching. In that case,
1064 ;; we just fetch the entire article.
1065 (or (gnus-check-backend-function
1066 (and (string-match "^gnus-" (symbol-name request-func
))
1067 (intern (substring (symbol-name request-func
)
1069 gnus-newsgroup-name
)
1071 (setq ofunc request-func
)
1072 (setq request-func
'gnus-request-article
)))
1074 (setq article
(mail-header-number (car (car articles
))))
1075 (gnus-message 7 "Scoring on article %s of %s..." article last
)
1076 (if (not (funcall request-func article gnus-newsgroup-name
))
1079 (goto-char (point-min))
1080 ;; If just parts of the article is to be searched, but the
1081 ;; backend didn't support partial fetching, we just narrow
1082 ;; to the relevant parts.
1084 (if (eq ofunc
'gnus-request-head
)
1087 (or (search-forward "\n\n" nil t
) (point-max)))
1089 (or (search-forward "\n\n" nil t
) (point))
1091 (setq scores all-scores
)
1094 (setq alist
(car scores
)
1096 entries
(assoc header alist
))
1097 (while (cdr entries
) ;First entry is the header index.
1098 (let* ((rest (cdr entries
))
1100 (match (nth 0 kill
))
1101 (type (or (nth 3 kill
) 's
))
1102 (score (or (nth 1 kill
)
1103 gnus-score-interactive-default-score
))
1107 (not (or (eq type
'R
) (eq type
'S
)
1108 (eq type
'Regexp
) (eq type
'String
))))
1110 (cond ((or (eq type
'r
) (eq type
'R
)
1111 (eq type
'regexp
) (eq type
'Regexp
))
1113 ((or (eq type
's
) (eq type
'S
)
1114 (eq type
'string
) (eq type
'String
))
1117 (error "Illegal match type: %s" type
)))))
1118 (goto-char (point-min))
1119 (if (funcall search-func match nil t
)
1120 ;; Found a match, update scores.
1122 (setcdr (car articles
) (+ score
(cdr (car articles
))))
1124 (and trace
(setq gnus-score-trace
1125 (cons (cons (car (car articles
)) kill
)
1126 gnus-score-trace
)))))
1127 ;; Update expire date
1128 (cond ((null date
)) ;Permanent entry.
1129 (found ;Match, update date.
1130 (gnus-score-set 'touched
'(t) alist
)
1131 (setcar (nthcdr 2 kill
) now
))
1132 ((< date expire
) ;Old entry, remove.
1133 (gnus-score-set 'touched
'(t) alist
)
1134 (setcdr entries
(cdr rest
))
1135 (setq rest entries
)))
1136 (setq entries rest
)))))
1137 (setq articles
(cdr articles
)))))))
1141 (defun gnus-score-followup (scores header now expire
&optional trace
)
1142 ;; Insert the unique article headers in the buffer.
1143 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
1144 (current-score-file gnus-current-score-file
)
1146 ;; gnus-score-index is used as a free variable.
1147 alike last this art entries alist articles
)
1149 ;; Change score file to the adaptive score file. All entries that
1150 ;; this function makes will be put into this file.
1151 (gnus-score-load-file (gnus-score-file-name
1152 gnus-newsgroup-name gnus-adaptive-file-suffix
))
1154 (setq gnus-scores-articles
(sort gnus-scores-articles
'gnus-score-string
<)
1155 articles gnus-scores-articles
)
1159 (setq art
(car articles
)
1160 this
(aref (car art
) gnus-score-index
)
1161 articles
(cdr articles
))
1162 (if (equal last this
)
1163 (setq alike
(cons art alike
))
1167 (put-text-property (1- (point)) (point) 'articles alike
)))
1168 (setq alike
(list art
)
1170 (and last
; Bwadr, duplicate code.
1173 (put-text-property (1- (point)) (point) 'articles alike
)))
1177 (setq alist
(car scores
)
1179 entries
(assoc header alist
))
1180 (while (cdr entries
) ;First entry is the header index.
1181 (let* ((rest (cdr entries
))
1183 (match (nth 0 kill
))
1184 (type (or (nth 3 kill
) 's
))
1185 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1188 (mt (aref (symbol-name type
) 0))
1190 (not (or (= mt ?R
) (= mt ?S
) (= mt ?E
) (= mt ?F
))))
1193 (cond ((= dmt ?r
) 're-search-forward
)
1194 ((or (= dmt ?e
) (= dmt ?s
) (= dmt ?f
)) 'search-forward
)
1195 (t (error "Illegal match type: %s" type
))))
1197 (goto-char (point-min))
1199 (while (funcall search-func match nil t
)
1200 (and (= (progn (beginning-of-line) (point))
1201 (match-beginning 0))
1202 (= (progn (end-of-line) (point))
1205 (setq found
(setq arts
(get-text-property
1206 (point) 'articles
)))
1207 ;; Found a match, update scores.
1209 (setq art
(car arts
)
1211 (gnus-score-add-followups
1212 (car art
) score all-scores
)))))
1213 (while (funcall search-func match nil t
)
1215 (setq found
(setq arts
(get-text-property (point) 'articles
)))
1216 ;; Found a match, update scores.
1218 (setq art
(car arts
)
1220 (gnus-score-add-followups (car art
) score all-scores
))))
1221 ;; Update expire date
1222 (cond ((null date
)) ;Permanent entry.
1223 (found ;Match, update date.
1224 (gnus-score-set 'touched
'(t) alist
)
1225 (setcar (nthcdr 2 kill
) now
))
1226 ((< date expire
) ;Old entry, remove.
1227 (gnus-score-set 'touched
'(t) alist
)
1228 (setcdr entries
(cdr rest
))
1229 (setq rest entries
)))
1230 (setq entries rest
))))
1231 ;; We change the score file back to the previous one.
1232 (gnus-score-load-file current-score-file
)))
1234 (defun gnus-score-add-followups (header score scores
)
1236 (set-buffer gnus-summary-buffer
)
1237 (let* ((id (mail-header-id header
))
1238 (scores (car scores
))
1240 ;; Don't enter a score if there already is one.
1242 (setq entry
(car scores
))
1243 (and (equal "references" (car entry
))
1244 (or (null (nth 3 (car (cdr entry
))))
1245 (eq 's
(nth 3 (car (cdr entry
)))))
1247 (if (assoc id entry
)
1249 (setq scores
(cdr scores
)))
1251 (gnus-summary-score-entry
1252 "references" id
's score
(current-time-string) nil t
)))))
1255 (defun gnus-score-string (score-list header now expire
&optional trace
)
1256 ;; Score ARTICLES according to HEADER in SCORE-LIST.
1257 ;; Update matching entries to NOW and remove unmatched entries older
1260 ;; Insert the unique article headers in the buffer.
1261 (let ((gnus-score-index (nth 1 (assoc header gnus-header-index
)))
1262 ;; gnus-score-index is used as a free variable.
1263 alike last this art entries alist articles scores fuzzy
)
1265 ;; Sorting the articles costs os O(N*log N) but will allow us to
1266 ;; only match with each unique header. Thus the actual matching
1267 ;; will be O(M*U) where M is the number of strings to match with,
1268 ;; and U is the number of unique headers. It is assumed (but
1269 ;; untested) this will be a net win because of the large constant
1270 ;; factor involved with string matching.
1271 (setq gnus-scores-articles
(sort gnus-scores-articles
'gnus-score-string
<)
1272 articles gnus-scores-articles
)
1276 (setq art
(car articles
)
1277 this
(aref (car art
) gnus-score-index
)
1278 articles
(cdr articles
))
1279 (if (equal last this
)
1280 ;; O(N*H) cons-cells used here, where H is the number of
1282 (setq alike
(cons art alike
))
1285 ;; Insert the line, with a text property on the
1286 ;; terminating newline referring to the articles with
1289 (put-text-property (1- (point)) (point) 'articles alike
)))
1290 (setq alike
(list art
)
1292 (and last
; Bwadr, duplicate code.
1295 (put-text-property (1- (point)) (point) 'articles alike
)))
1297 ;; Find ordinary matches.
1298 (setq scores score-list
)
1300 (setq alist
(car scores
)
1302 entries
(assoc header alist
))
1303 (while (cdr entries
) ;First entry is the header index.
1304 (let* ((rest (cdr entries
))
1306 (match (nth 0 kill
))
1307 (type (or (nth 3 kill
) 's
))
1308 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1311 (mt (aref (symbol-name type
) 0))
1313 (not (or (= mt ?R
) (= mt ?S
) (= mt ?E
) (= mt ?F
))))
1316 (cond ((= dmt ?r
) 're-search-forward
)
1317 ((or (= dmt ?e
) (= dmt ?s
) (= dmt ?f
)) 'search-forward
)
1318 (t (error "Illegal match type: %s" type
))))
1322 (goto-char (point-min))
1324 (while (and (not (eobp))
1325 (funcall search-func match nil t
))
1326 (and (= (progn (beginning-of-line) (point))
1327 (match-beginning 0))
1328 (= (progn (end-of-line) (point))
1331 (setq found
(setq arts
(get-text-property
1332 (point) 'articles
)))
1333 ;; Found a match, update scores.
1336 (setq art
(car arts
)
1338 (setcdr art
(+ score
(cdr art
)))
1339 (setq gnus-score-trace
1340 (cons (cons (mail-header-number
1344 (setq art
(car arts
)
1346 (setcdr art
(+ score
(cdr art
)))))))
1348 (and (string= match
"") (setq match
"\n"))
1349 (while (and (not (eobp))
1350 (funcall search-func match nil t
))
1351 (goto-char (match-beginning 0))
1353 (setq found
(setq arts
(get-text-property (point) 'articles
)))
1354 ;; Found a match, update scores.
1357 (setq art
(car arts
)
1359 (setcdr art
(+ score
(cdr art
)))
1360 (setq gnus-score-trace
1361 (cons (cons (mail-header-number (car art
)) kill
)
1364 (setq art
(car arts
)
1366 (setcdr art
(+ score
(cdr art
)))))
1368 ;; Update expire date
1369 (cond ((null date
)) ;Permanent entry.
1370 (found ;Match, update date.
1371 (gnus-score-set 'touched
'(t) alist
)
1372 (setcar (nthcdr 2 kill
) now
))
1373 ((< date expire
) ;Old entry, remove.
1374 (gnus-score-set 'touched
'(t) alist
)
1375 (setcdr entries
(cdr rest
))
1376 (setq rest entries
))))
1377 (setq entries rest
))))
1379 ;; Find fuzzy matches.
1380 (setq scores
(and fuzzy score-list
))
1381 (if fuzzy
(gnus-simplify-buffer-fuzzy))
1383 (setq alist
(car scores
)
1385 entries
(assoc header alist
))
1386 (while (cdr entries
) ;First entry is the header index.
1387 (let* ((rest (cdr entries
))
1389 (match (nth 0 kill
))
1390 (type (or (nth 3 kill
) 's
))
1391 (score (or (nth 1 kill
) gnus-score-interactive-default-score
))
1394 (mt (aref (symbol-name type
) 0))
1396 (not (or (= mt ?R
) (= mt ?S
) (= mt ?E
) (= mt ?F
))))
1399 (cond ((= dmt ?r
) 're-search-forward
)
1400 ((or (= dmt ?e
) (= dmt ?s
) (= dmt ?f
)) 'search-forward
)
1401 (t (error "Illegal match type: %s" type
))))
1405 (goto-char (point-min))
1406 (while (and (not (eobp))
1407 (funcall search-func match nil t
))
1408 (and (= (progn (beginning-of-line) (point))
1409 (match-beginning 0))
1410 (= (progn (end-of-line) (point))
1413 (setq found
(setq arts
(get-text-property
1414 (point) 'articles
)))
1415 ;; Found a match, update scores.
1418 (setq art
(car arts
)
1420 (setcdr art
(+ score
(cdr art
)))
1421 (setq gnus-score-trace
1422 (cons (cons (mail-header-number
1426 (setq art
(car arts
)
1428 (setcdr art
(+ score
(cdr art
)))))))
1430 ;; Update expire date
1431 (cond ((null date
)) ;Permanent entry.
1432 (found ;Match, update date.
1433 (gnus-score-set 'touched
'(t) alist
)
1434 (setcar (nthcdr 2 kill
) now
))
1435 ((< date expire
) ;Old entry, remove.
1436 (gnus-score-set 'touched
'(t) alist
)
1437 (setcdr entries
(cdr rest
))
1438 (setq rest entries
))))
1439 (setq entries rest
))))))
1441 (defun gnus-score-string< (a1 a2
)
1442 ;; Compare headers in articles A2 and A2.
1443 ;; The header index used is the free variable `gnus-score-index'.
1444 (string-lessp (aref (car a1
) gnus-score-index
)
1445 (aref (car a2
) gnus-score-index
)))
1447 (defun gnus-score-build-cons (article)
1448 ;; Build a `gnus-newsgroup-scored' type cons from ARTICLE.
1449 (cons (mail-header-number (car article
)) (cdr article
)))
1451 (defconst gnus-header-index
1452 ;; Name to index alist.
1453 '(("number" 0 gnus-score-integer
)
1454 ("subject" 1 gnus-score-string
)
1455 ("from" 2 gnus-score-string
)
1456 ("date" 3 gnus-score-date
)
1457 ("message-id" 4 gnus-score-string
)
1458 ("references" 5 gnus-score-string
)
1459 ("chars" 6 gnus-score-integer
)
1460 ("lines" 7 gnus-score-integer
)
1461 ("xref" 8 gnus-score-string
)
1462 ("head" -
1 gnus-score-body
)
1463 ("body" -
1 gnus-score-body
)
1464 ("all" -
1 gnus-score-body
)
1465 ("followup" 2 gnus-score-followup
)))
1467 (defun gnus-current-score-file-nondirectory (&optional score-file
)
1468 (let ((score-file (or score-file gnus-current-score-file
)))
1470 (gnus-short-group-name (file-name-nondirectory score-file
))
1473 (defun gnus-score-adaptive ()
1475 (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist
))
1477 (date (current-time-string))
1479 ;; First we transform the adaptive rule alist into something
1480 ;; that's faster to process.
1482 (setq elem
(car malist
))
1483 (if (symbolp (car elem
))
1484 (setcar elem
(symbol-value (car elem
))))
1485 (setq elem
(cdr elem
))
1488 (cons (symbol-name (car (car elem
))) (cdr (car elem
))))
1491 (concat "gnus-header-"
1492 (downcase (symbol-name (car (car elem
)))))))
1493 (setq elem
(cdr elem
)))
1494 (setq malist
(cdr malist
)))
1495 ;; We change the score file to the adaptive score file.
1496 (gnus-score-load-file (gnus-score-file-name
1497 gnus-newsgroup-name gnus-adaptive-file-suffix
))
1498 ;; The we score away.
1499 (goto-char (point-min))
1501 (setq elem
(cdr (assq (gnus-summary-article-mark) alist
)))
1503 (get-text-property (point) 'gnus-pseudo
))
1505 (setq headers
(gnus-get-header-by-number
1506 (gnus-summary-article-number)))
1507 (while (and elem headers
)
1508 (setq match
(funcall (car (car elem
)) headers
))
1509 (gnus-summary-score-entry
1510 (nth 1 (car elem
)) match
1514 ((equal (nth 1 (car elem
)) "date")
1517 ;; Whether we use substring or exact matches are controlled
1519 (if (or (not gnus-score-exact-adapt-limit
)
1520 (< (length match
) gnus-score-exact-adapt-limit
))
1522 (if (equal (nth 1 (car elem
)) "subject")
1524 (nth 2 (car elem
)) date nil t
)
1525 (setq elem
(cdr elem
))))
1526 (forward-line 1)))))
1528 (defun gnus-score-remove-lines-adaptive (marks)
1530 (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist
))
1532 (date (current-time-string))
1533 (cur-score gnus-current-score-file
)
1535 ;; First we transform the adaptive rule alist into something
1536 ;; that's faster to process.
1538 (setq elem
(car malist
))
1539 (if (symbolp (car elem
))
1540 (setcar elem
(symbol-value (car elem
))))
1541 (setq elem
(cdr elem
))
1544 (cons (symbol-name (car (car elem
))) (cdr (car elem
))))
1547 (concat "gnus-header-"
1548 (downcase (symbol-name (car (car elem
)))))))
1549 (setq elem
(cdr elem
)))
1550 (setq malist
(cdr malist
)))
1551 ;; The we score away.
1552 (goto-char (point-min))
1553 ;; We change the score file to the adaptive score file.
1554 (gnus-score-load-file (gnus-score-file-name
1555 gnus-newsgroup-name gnus-adaptive-file-suffix
))
1556 (while (re-search-forward marks nil t
)
1558 (setq elem
(cdr (assq (gnus-summary-article-mark) alist
)))
1560 (get-text-property (gnus-point-at-bol) 'gnus-pseudo
))
1562 (setq headers
(gnus-get-header-by-number
1563 (gnus-summary-article-number)))
1565 (setq match
(funcall (car (car elem
)) headers
))
1566 (gnus-summary-score-entry
1567 (nth 1 (car elem
)) match
1568 (if (or (not gnus-score-exact-adapt-limit
)
1569 (< (length match
) gnus-score-exact-adapt-limit
))
1571 (nth 2 (car elem
)) date nil t
)
1572 (setq elem
(cdr elem
))))
1573 (delete-region (point) (progn (forward-line 1) (point))))
1574 ;; Switch back to the old score file.
1575 (gnus-score-load-file cur-score
))))
1581 (defvar gnus-score-mode-map nil
)
1582 (defvar gnus-score-mode-hook nil
)
1584 (if gnus-score-mode-map
1586 (setq gnus-score-mode-map
(copy-keymap emacs-lisp-mode-map
))
1587 (define-key gnus-score-mode-map
"\C-c\C-c" 'gnus-score-edit-done
)
1588 (define-key gnus-score-mode-map
"\C-c\C-d" 'gnus-score-edit-insert-date
))
1590 (defun gnus-score-mode ()
1591 "Mode for editing score files.
1592 This mode is an extended emacs-lisp mode.
1594 \\{gnus-score-mode-map}"
1596 (kill-all-local-variables)
1597 (use-local-map gnus-score-mode-map
)
1598 (set-syntax-table emacs-lisp-mode-syntax-table
)
1599 (setq major-mode
'gnus-score-mode
)
1600 (setq mode-name
"Score")
1601 (lisp-mode-variables nil
)
1602 (run-hooks 'emacs-lisp-mode-hook
'gnus-score-mode-hook
))
1604 (defun gnus-score-edit-insert-date ()
1605 "Insert date in numerical format."
1607 (insert (int-to-string (gnus-day-number (current-time-string)))))
1609 (defun gnus-score-edit-done ()
1610 "Save the score file and return to the summary buffer."
1612 (let ((bufnam (buffer-file-name (current-buffer)))
1613 (winconf gnus-prev-winconf
))
1614 (gnus-make-directory (file-name-directory (buffer-file-name)))
1616 (kill-buffer (current-buffer))
1617 (gnus-score-remove-from-cache bufnam
)
1618 (gnus-score-load-file bufnam
)
1619 (and winconf
(set-window-configuration winconf
))))
1621 (defun gnus-score-find-trace ()
1622 "Find all score rules applied to this article."
1624 (let ((gnus-newsgroup-headers
1625 (list (gnus-get-header-by-number (gnus-summary-article-number))))
1626 (gnus-newsgroup-scored nil
)
1627 (buf (current-buffer))
1629 (setq gnus-score-trace nil
)
1630 (gnus-possibly-score-headers 'trace
)
1631 (or (setq trace gnus-score-trace
)
1632 (error "No score rules apply to the current article."))
1633 (pop-to-buffer "*Gnus Scores*")
1634 (gnus-add-current-to-buffer-list)
1637 (insert (format "%S\n" (cdr (car trace
))))
1638 (setq trace
(cdr trace
)))
1639 (goto-char (point-min))
1640 (pop-to-buffer buf
)))
1643 (provide 'gnus-score
)
1645 ;;; gnus-score.el ends here