comparison lisp/gnus/spam-stat.el @ 105274:506031e65b65

* spam-stat.el (spam-stat-load): Fix typo in message.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 29 Sep 2009 02:20:21 +0000
parents a9dc0e7c3f2b
children 66d2db8735aa
comparison
equal deleted inserted replaced
105273:b9edaeacd0e7 105274:506031e65b65
178 :type 'hook 178 :type 'hook
179 :group 'spam-stat) 179 :group 'spam-stat)
180 180
181 (defcustom spam-stat-score-buffer-user-functions nil 181 (defcustom spam-stat-score-buffer-user-functions nil
182 "List of additional scoring functions. 182 "List of additional scoring functions.
183 Called one by one on the buffer. 183 Called one by one on the buffer.
184 184
185 If all of these functions return non-nil answers, these numerical 185 If all of these functions return non-nil answers, these numerical
186 answers are added to the computed spam stat score on the buffer. If 186 answers are added to the computed spam stat score on the buffer. If
187 you defun such functions, make sure they don't return the buffer in a 187 you defun such functions, make sure they don't return the buffer in a
188 narrowed state or such: use, for example, `save-excursion'. Each of 188 narrowed state or such: use, for example, `save-excursion'. Each of
440 (cond (spam-stat-dirty (message "Spam stat not loaded: spam-stat-dirty t")) 440 (cond (spam-stat-dirty (message "Spam stat not loaded: spam-stat-dirty t"))
441 ((or (not (boundp 'spam-stat-last-saved-at)) 441 ((or (not (boundp 'spam-stat-last-saved-at))
442 (null spam-stat-last-saved-at) 442 (null spam-stat-last-saved-at)
443 (not (equal spam-stat-last-saved-at 443 (not (equal spam-stat-last-saved-at
444 (nth 5 (file-attributes spam-stat-file))))) 444 (nth 5 (file-attributes spam-stat-file)))))
445 (progn 445 (progn
446 (load-file spam-stat-file) 446 (load-file spam-stat-file)
447 (setq spam-stat-dirty nil 447 (setq spam-stat-dirty nil
448 spam-stat-last-saved-at 448 spam-stat-last-saved-at
449 (nth 5 (file-attributes spam-stat-file))))) 449 (nth 5 (file-attributes spam-stat-file)))))
450 (t (message "Spam stat file not loaded: no change in disk.."))))) 450 (t (message "Spam stat file not loaded: no change in disk.")))))
451 451
452 (defun spam-stat-to-hash-table (entries) 452 (defun spam-stat-to-hash-table (entries)
453 "Turn list ENTRIES into a hash table and store as `spam-stat'. 453 "Turn list ENTRIES into a hash table and store as `spam-stat'.
454 Every element in ENTRIES has the form \(WORD GOOD BAD) where WORD is 454 Every element in ENTRIES has the form \(WORD GOOD BAD) where WORD is
455 the word string, NGOOD is the number of good mails it has appeared in, 455 the word string, NGOOD is the number of good mails it has appeared in,
501 result)) 501 result))
502 502
503 (defun spam-stat-score-buffer () 503 (defun spam-stat-score-buffer ()
504 "Return a score describing the spam-probability for this buffer. 504 "Return a score describing the spam-probability for this buffer.
505 Add user supplied modifications if supplied." 505 Add user supplied modifications if supplied."
506 (interactive) ; helps in debugging. 506 (interactive) ; helps in debugging.
507 (setq spam-stat-score-data (spam-stat-buffer-words-with-scores)) 507 (setq spam-stat-score-data (spam-stat-buffer-words-with-scores))
508 (let* ((probs (mapcar 'cadr spam-stat-score-data)) 508 (let* ((probs (mapcar 'cadr spam-stat-score-data))
509 (prod (apply #'* probs)) 509 (prod (apply #'* probs))
510 (score0 510 (score0
511 (/ prod (+ prod (apply #'* (mapcar #'(lambda (x) (- 1 x)) 511 (/ prod (+ prod (apply #'* (mapcar #'(lambda (x) (- 1 x))
512 probs))))) 512 probs)))))
513 (score1s 513 (score1s
514 (condition-case 514 (condition-case
515 spam-stat-error-holder 515 spam-stat-error-holder
516 (spam-stat-score-buffer-user score0) 516 (spam-stat-score-buffer-user score0)
517 (error nil))) 517 (error nil)))
518 (ans 518 (ans
519 (if score1s (+ score0 score1s) score0))) 519 (if score1s (+ score0 score1s) score0)))
520 (when (interactive-p) 520 (when (interactive-p)
521 (message "%S" ans)) 521 (message "%S" ans))
522 ans)) 522 ans))
523 523
524 (defun spam-stat-score-buffer-user (&rest args) 524 (defun spam-stat-score-buffer-user (&rest args)
525 (let* ((scores 525 (let* ((scores
526 (mapcar 526 (mapcar
527 (lambda (fn) 527 (lambda (fn)
528 (apply fn args)) 528 (apply fn args))
529 spam-stat-score-buffer-user-functions))) 529 spam-stat-score-buffer-user-functions)))
530 (if (memq nil scores) nil 530 (if (memq nil scores) nil
531 (apply #'+ scores)))) 531 (apply #'+ scores))))
532 532
533 (defun spam-stat-split-fancy () 533 (defun spam-stat-split-fancy ()
534 "Return the name of the spam group if the current mail is spam. 534 "Return the name of the spam group if the current mail is spam.
535 Use this function on `nnmail-split-fancy'. If you are interested in 535 Use this function on `nnmail-split-fancy'. If you are interested in