00387314ef15bff9a52badf32ed2c1af6e76a91c
[gnus] / lisp / spam-stat.el
1 ;;; spam-stat.el --- detecting spam based on statistics
2
3 ;; Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
4
5 ;; Author: Alex Schroeder <alex@gnu.org>
6 ;; Keywords: network
7 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SpamStat
8
9 ;; This file is part of GNU Emacs.
10
11 ;; This is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; This is distributed in the hope that it will be useful, but WITHOUT
17 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 ;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
19 ;; License for more details.
20
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.
25
26 ;;; Commentary:
27
28 ;; This implements spam analysis according to Paul Graham in "A Plan
29 ;; for Spam".  The basis for all this is a statistical distribution of
30 ;; words for your spam and non-spam mails.  We need this information
31 ;; in a hash-table so that the analysis can use the information when
32 ;; looking at your mails.  Therefore, before you begin, you need tons
33 ;; of mails (Graham uses 4000 non-spam and 4000 spam mails for his
34 ;; experiments).
35 ;;
36 ;; The main interface to using spam-stat, are the following functions:
37 ;;
38 ;; `spam-stat-buffer-is-spam' -- called in a buffer, that buffer is
39 ;; considered to be a new spam mail; use this for new mail that has
40 ;; not been processed before
41 ;;
42 ;; `spam-stat-buffer-is-non-spam' -- called in a buffer, that buffer
43 ;; is considered to be a new non-spam mail; use this for new mail that
44 ;; has not been processed before
45 ;;
46 ;; `spam-stat-buffer-change-to-spam' -- called in a buffer, that
47 ;; buffer is no longer considered to be normal mail but spam; use this
48 ;; to change the status of a mail that has already been processed as
49 ;; non-spam
50 ;;
51 ;; `spam-stat-buffer-change-to-non-spam' -- called in a buffer, that
52 ;; buffer is no longer considered to be spam but normal mail; use this
53 ;; to change the status of a mail that has already been processed as
54 ;; spam
55 ;;
56 ;; `spam-stat-save' -- save the hash table to the file; the filename
57 ;; used is stored in the variable `spam-stat-file'
58 ;;
59 ;; `spam-stat-load' -- load the hash table from a file; the filename
60 ;; used is stored in the variable `spam-stat-file'
61 ;;
62 ;; `spam-stat-score-word' -- return the spam score for a word
63 ;;
64 ;; `spam-stat-score-buffer' -- return the spam score for a buffer
65 ;;
66 ;; `spam-stat-split-fancy' -- for fancy mail splitting; add
67 ;; the rule (: spam-stat-split-fancy) to `nnmail-split-fancy'
68 ;;
69 ;; This requires the following in your ~/.gnus file:
70 ;;
71 ;; (require 'spam-stat)
72 ;; (spam-stat-load)
73
74 ;;; Testing:
75
76 ;; Typical test will involve calls to the following functions:
77 ;;
78 ;; Reset: (spam-stat-reset)
79 ;; Learn spam: (spam-stat-process-spam-directory "~/Mail/mail/spam")
80 ;; Learn non-spam: (spam-stat-process-non-spam-directory "~/Mail/mail/misc")
81 ;; Save table: (spam-stat-save)
82 ;; File size: (nth 7 (file-attributes spam-stat-file))
83 ;; Number of words: (hash-table-count spam-stat)
84 ;; Test spam: (spam-stat-test-directory "~/Mail/mail/spam")
85 ;; Test non-spam: (spam-stat-test-directory "~/Mail/mail/misc")
86 ;; Reduce table size: (spam-stat-reduce-size)
87 ;; Save table: (spam-stat-save)
88 ;; File size: (nth 7 (file-attributes spam-stat-file))
89 ;; Number of words: (hash-table-count spam-stat)
90 ;; Test spam: (spam-stat-test-directory "~/Mail/mail/spam")
91 ;; Test non-spam: (spam-stat-test-directory "~/Mail/mail/misc")
92
93 ;;; Dictionary Creation:
94
95 ;; Typically, you will filter away mailing lists etc. using specific
96 ;; rules in `nnmail-split-fancy'.  Somewhere among these rules, you
97 ;; will filter spam.  Here is how you would create your dictionary:
98
99 ;; Reset: (spam-stat-reset)
100 ;; Learn spam: (spam-stat-process-spam-directory "~/Mail/mail/spam")
101 ;; Learn non-spam: (spam-stat-process-non-spam-directory "~/Mail/mail/misc")
102 ;; Repeat for any other non-spam group you need...
103 ;; Reduce table size: (spam-stat-reduce-size)
104 ;; Save table: (spam-stat-save)
105
106 ;;; Todo:
107
108 ;; Speed it up.  Integrate with Gnus such that it uses spam and expiry
109 ;; marks to call the appropriate functions when leaving the summary
110 ;; buffer and saves the hash table when leaving Gnus.  More testing:
111 ;; More mails, disabling SpamAssassin, double checking algorithm, find
112 ;; improved algorithm.
113
114 ;;; Thanks:
115
116 ;; Ted Zlatanov <tzz@lifelogs.com>
117 ;; Jesper Harder <harder@myrealbox.com>
118 ;; Dan Schmidt <dfan@dfan.org>
119 ;; Lasse Rasinen <lrasinen@iki.fi>
120 ;; Milan Zamazal <pdm@zamazal.org>
121
122 \f
123
124 ;;; Code:
125 (require 'mail-parse)
126
127 (defgroup spam-stat nil
128   "Statistical spam detection for Emacs.
129 Use the functions to build a dictionary of words and their statistical
130 distribution in spam and non-spam mails.  Then use a function to determine
131 whether a buffer contains spam or not."
132   :group 'gnus)
133
134 (defcustom spam-stat-file "~/.spam-stat.el"
135   "File used to save and load the dictionary.
136 See `spam-stat-to-hash-table' for the format of the file."
137   :type 'file
138   :group 'spam-stat)
139
140 (defcustom spam-stat-install-hooks t
141   "Whether spam-stat should install its hooks in Gnus.
142 This is set to nil if you use spam-stat through spam.el."
143   :type 'boolean
144   :group 'spam-stat)
145
146 (defcustom spam-stat-unknown-word-score 0.2
147   "The score to use for unknown words.
148 Also used for words that don't appear often enough."
149   :type 'number
150   :group 'spam-stat)
151
152 (defcustom spam-stat-max-word-length 15
153   "Only words shorter than this will be considered."
154   :type 'integer
155   :group 'spam-stat)
156
157 (defcustom spam-stat-max-buffer-length 10240
158   "Only the beginning of buffers will be analyzed.
159 This variable says how many characters this will be."
160   :type 'integer
161   :group 'spam-stat)
162
163 (defcustom spam-stat-split-fancy-spam-group "mail.spam"
164   "Name of the group where spam should be stored.
165 If `spam-stat-split-fancy' is used in fancy splitting rules.  Has
166 no effect when spam-stat is invoked through spam.el."
167   :type 'string
168   :group 'spam-stat)
169
170 (defcustom spam-stat-split-fancy-spam-threshhold 0.9
171   "Spam score threshold in spam-stat-split-fancy."
172   :type 'number
173   :group 'spam-stat)
174
175 (defcustom spam-stat-washing-hook nil
176   "Hook applied to each message before analysis."
177   :type 'hook
178   :group 'spam-stat)
179
180 (defcustom spam-stat-process-directory-age 90
181   "Max. age of files to be processed in directory, in days.
182 When using `spam-stat-process-spam-directory' or
183 `spam-stat-process-non-spam-directory', only files that have
184 been touched in this many days will be considered.  Without
185 this filter, re-training spam-stat with several thousand messages
186 will start to take a very long time.")
187
188 (defvar spam-stat-syntax-table
189   (let ((table (copy-syntax-table text-mode-syntax-table)))
190     (modify-syntax-entry ?- "w" table)
191     (modify-syntax-entry ?_ "w" table)
192     (modify-syntax-entry ?. "w" table)
193     (modify-syntax-entry ?! "w" table)
194     (modify-syntax-entry ?? "w" table)
195     (modify-syntax-entry ?+ "w" table)
196     table)
197   "Syntax table used when processing mails for statistical analysis.
198 The important part is which characters are word constituents.")
199
200 (defvar spam-stat-dirty nil
201   "Whether the spam-stat database needs saving.")
202
203 (defvar spam-stat-buffer nil
204   "Buffer to use for scoring while splitting.
205 This is set by hooking into Gnus.")
206
207 (defvar spam-stat-buffer-name " *spam stat buffer*"
208   "Name of the `spam-stat-buffer'.")
209
210 (defvar spam-stat-coding-system
211   (if (mm-coding-system-p 'emacs-mule) 'emacs-mule 'raw-text)
212   "Coding system used for `spam-stat-file'.")
213
214 ;; Hooking into Gnus
215
216 (defun spam-stat-store-current-buffer ()
217   "Store a copy of the current buffer in `spam-stat-buffer'."
218   (let ((buf (current-buffer)))
219     (with-current-buffer (get-buffer-create spam-stat-buffer-name)
220       (erase-buffer)
221       (insert-buffer-substring buf)
222       (setq spam-stat-buffer (current-buffer)))))
223
224 (defun spam-stat-store-gnus-article-buffer ()
225   "Store a copy of the current article in `spam-stat-buffer'.
226 This uses `gnus-article-buffer'."
227   (with-current-buffer gnus-original-article-buffer
228     (spam-stat-store-current-buffer)))
229
230 ;; Data -- not using defstruct in order to save space and time
231
232 (defvar spam-stat (make-hash-table :test 'equal)
233   "Hash table used to store the statistics.
234 Use `spam-stat-load' to load the file.
235 Every word is used as a key in this table.  The value is a vector.
236 Use `spam-stat-ngood', `spam-stat-nbad', `spam-stat-good',
237 `spam-stat-bad', and `spam-stat-score' to access this vector.")
238
239 (defvar spam-stat-ngood 0
240   "The number of good mails in the dictionary.")
241
242 (defvar spam-stat-nbad 0
243   "The number of bad mails in the dictionary.")
244
245 (defsubst spam-stat-good (entry)
246   "Return the number of times this word belongs to good mails."
247   (aref entry 0))
248
249 (defsubst spam-stat-bad (entry)
250   "Return the number of times this word belongs to bad mails."
251   (aref entry 1))
252
253 (defsubst spam-stat-score (entry)
254   "Set the score of this word."
255   (if entry
256       (aref entry 2)
257     spam-stat-unknown-word-score))
258
259 (defsubst spam-stat-set-good (entry value)
260   "Set the number of times this word belongs to good mails."
261   (aset entry 0 value))
262
263 (defsubst spam-stat-set-bad (entry value)
264   "Set the number of times this word belongs to bad mails."
265   (aset entry 1 value))
266
267 (defsubst spam-stat-set-score (entry value)
268   "Set the score of this word."
269   (aset entry 2 value))
270
271 (defsubst spam-stat-make-entry (good bad)
272   "Return a vector with the given properties."
273   (let ((entry (vector good bad nil)))
274     (spam-stat-set-score entry (spam-stat-compute-score entry))
275     entry))
276
277 ;; Computing
278
279 (defun spam-stat-compute-score (entry)
280   "Compute the score of this word.  1.0 means spam."
281    ;; promote all numbers to floats for the divisions
282    (let* ((g (* 2.0 (spam-stat-good entry)))
283           (b (float (spam-stat-bad entry))))
284      (cond ((< (+ g b) 5)
285             .2)
286            ((= 0 spam-stat-ngood)
287             .99)
288            ((= 0 spam-stat-nbad)
289             .01)
290            (t
291             (max .01
292                  (min .99 (/ (/ b spam-stat-nbad)
293                              (+ (/ g spam-stat-ngood)
294                                 (/ b spam-stat-nbad)))))))))
295
296 ;; Parsing
297
298 (defmacro with-spam-stat-max-buffer-size (&rest body)
299   "Narrow the buffer down to the first 4k characters, then evaluate BODY."
300   `(save-restriction
301      (when (> (- (point-max)
302                  (point-min))
303               spam-stat-max-buffer-length)
304        (narrow-to-region (point-min)
305                          (+ (point-min) spam-stat-max-buffer-length)))
306      ,@body))
307
308 (defun spam-stat-buffer-words ()
309   "Return a hash table of words and number of occurrences in the buffer."
310   (run-hooks 'spam-stat-washing-hook)
311   (with-spam-stat-max-buffer-size
312    (with-syntax-table spam-stat-syntax-table
313      (goto-char (point-min))
314      (let ((result (make-hash-table :test 'equal))
315            word count)
316        (while (re-search-forward "\\w+" nil t)
317          (setq word (match-string-no-properties 0)
318                count (1+ (gethash word result 0)))
319          (when (< (length word) spam-stat-max-word-length)
320            (puthash word count result)))
321        result))))
322
323 (defun spam-stat-buffer-is-spam ()
324   "Consider current buffer to be a new spam mail."
325   (setq spam-stat-nbad (1+ spam-stat-nbad))
326   (maphash
327    (lambda (word count)
328      (let ((entry (gethash word spam-stat)))
329        (if entry
330            (spam-stat-set-bad entry (+ count (spam-stat-bad entry)))
331          (setq entry (spam-stat-make-entry 0 count)))
332        (spam-stat-set-score entry (spam-stat-compute-score entry))
333        (puthash word entry spam-stat)))
334    (spam-stat-buffer-words))
335   (setq spam-stat-dirty t))
336
337 (defun spam-stat-buffer-is-non-spam ()
338   "Consider current buffer to be a new non-spam mail."
339   (setq spam-stat-ngood (1+ spam-stat-ngood))
340   (maphash
341    (lambda (word count)
342      (let ((entry (gethash word spam-stat)))
343        (if entry
344            (spam-stat-set-good entry (+ count (spam-stat-good entry)))
345          (setq entry (spam-stat-make-entry count 0)))
346        (spam-stat-set-score entry (spam-stat-compute-score entry))
347        (puthash word entry spam-stat)))
348    (spam-stat-buffer-words))
349   (setq spam-stat-dirty t))
350
351 (defun spam-stat-buffer-change-to-spam ()
352   "Consider current buffer no longer normal mail but spam."
353   (setq spam-stat-nbad (1+ spam-stat-nbad)
354         spam-stat-ngood (1- spam-stat-ngood))
355   (maphash
356    (lambda (word count)
357      (let ((entry (gethash word spam-stat)))
358        (if (not entry)
359            (gnus-message 8 "This buffer has unknown words in it")
360          (spam-stat-set-good entry (- (spam-stat-good entry) count))
361          (spam-stat-set-bad entry (+ (spam-stat-bad entry) count))
362          (spam-stat-set-score entry (spam-stat-compute-score entry))
363          (puthash word entry spam-stat))))
364    (spam-stat-buffer-words))
365   (setq spam-stat-dirty t))
366
367 (defun spam-stat-buffer-change-to-non-spam ()
368   "Consider current buffer no longer spam but normal mail."
369   (setq spam-stat-nbad (1- spam-stat-nbad)
370         spam-stat-ngood (1+ spam-stat-ngood))
371   (maphash
372    (lambda (word count)
373      (let ((entry (gethash word spam-stat)))
374        (if (not entry)
375            (gnus-message 8 "This buffer has unknown words in it")
376          (spam-stat-set-good entry (+ (spam-stat-good entry) count))
377          (spam-stat-set-bad entry (- (spam-stat-bad entry) count))
378          (spam-stat-set-score entry (spam-stat-compute-score entry))
379          (puthash word entry spam-stat))))
380    (spam-stat-buffer-words))
381   (setq spam-stat-dirty t))
382
383 ;; Saving and Loading
384
385 (defun spam-stat-save (&optional force)
386   "Save the `spam-stat' hash table as Lisp file.
387 With a prefix argument save unconditionally."
388   (interactive "P")
389   (when (or force spam-stat-dirty)
390     (let ((coding-system-for-write spam-stat-coding-system))
391       (with-temp-file spam-stat-file
392         (let ((standard-output (current-buffer))
393               (font-lock-maximum-size 0))
394           (insert (format ";-*- coding: %s; -*-\n" spam-stat-coding-system))
395           (insert (format "(setq spam-stat-ngood %d spam-stat-nbad %d
396 spam-stat (spam-stat-to-hash-table '(" spam-stat-ngood spam-stat-nbad))
397           (maphash (lambda (word entry)
398                      (prin1 (list word
399                                   (spam-stat-good entry)
400                                   (spam-stat-bad entry))))
401                    spam-stat)
402           (insert ")))"))))
403         (setq spam-stat-dirty nil)))
404
405 (defun spam-stat-load ()
406   "Read the `spam-stat' hash table from disk."
407   ;; TODO: maybe we should warn the user if spam-stat-dirty is t?
408   (let ((coding-system-for-read spam-stat-coding-system))
409     (load-file spam-stat-file))
410   (setq spam-stat-dirty nil))
411
412 (defun spam-stat-to-hash-table (entries)
413   "Turn list ENTRIES into a hash table and store as `spam-stat'.
414 Every element in ENTRIES has the form \(WORD GOOD BAD) where WORD is
415 the word string, NGOOD is the number of good mails it has appeared in,
416 NBAD is the number of bad mails it has appeared in, GOOD is the number
417 of times it appeared in good mails, and BAD is the number of times it
418 has appeared in bad mails."
419   (let ((table (make-hash-table :size (length entries)
420                                 :test 'equal)))
421     (mapc (lambda (l)
422             (puthash (car l)
423                      (spam-stat-make-entry (nth 1 l) (nth 2 l))
424                      table))
425           entries)
426     table))
427
428 (defun spam-stat-reset ()
429   "Reset `spam-stat' to an empty hash-table.
430 This deletes all the statistics."
431   (interactive)
432   (setq spam-stat (make-hash-table :test 'equal)
433         spam-stat-ngood 0
434         spam-stat-nbad 0)
435   (setq spam-stat-dirty t))
436
437 ;; Scoring buffers
438
439 (defvar spam-stat-score-data nil
440   "Raw data used in the last run of `spam-stat-score-buffer'.")
441
442 (defsubst spam-stat-score-word (word)
443   "Return score for WORD.
444 The default score for unknown words is stored in
445 `spam-stat-unknown-word-score'."
446   (spam-stat-score (gethash word spam-stat)))
447
448 (defun spam-stat-buffer-words-with-scores ()
449   "Process current buffer, return the 15 most conspicuous words.
450 These are the words whose spam-stat differs the most from 0.5.
451 The list returned contains elements of the form \(WORD SCORE DIFF),
452 where DIFF is the difference between SCORE and 0.5."
453   (let (result word score)
454     (maphash (lambda (word ignore)
455                (setq score (spam-stat-score-word word)
456                      result (cons (list word score (abs (- score 0.5)))
457                                   result)))
458              (spam-stat-buffer-words))
459     (setq result (sort result (lambda (a b) (< (nth 2 b) (nth 2 a)))))
460     (setcdr (nthcdr 14 result) nil)
461     result))
462
463 (defun spam-stat-score-buffer ()
464   "Return a score describing the spam-probability for this buffer."
465   (setq spam-stat-score-data (spam-stat-buffer-words-with-scores))
466   (let* ((probs (mapcar 'cadr spam-stat-score-data))
467          (prod (apply #'* probs)))
468     (/ prod (+ prod (apply #'* (mapcar #'(lambda (x) (- 1 x))
469                                        probs))))))
470
471 (defun spam-stat-split-fancy ()
472   "Return the name of the spam group if the current mail is spam.
473 Use this function on `nnmail-split-fancy'.  If you are interested in
474 the raw data used for the last run of `spam-stat-score-buffer',
475 check the variable `spam-stat-score-data'."
476   (condition-case var
477       (progn
478         (set-buffer spam-stat-buffer)
479         (goto-char (point-min))
480         (when (> (spam-stat-score-buffer) spam-stat-split-fancy-spam-threshhold)
481           (when (boundp 'nnmail-split-trace)
482             (mapc (lambda (entry)
483                     (push entry nnmail-split-trace))
484                   spam-stat-score-data))
485           spam-stat-split-fancy-spam-group))
486     (error (message "Error in spam-stat-split-fancy: %S" var)
487            nil)))
488
489 ;; Testing
490
491 (defun spam-stat-strip-xref ()
492   "Strip the the Xref header."
493   (save-restriction
494     (mail-narrow-to-head)
495     (when (re-search-forward "^Xref:.*\n" nil t)
496       (delete-region (match-beginning 0) (match-end 0)))))
497
498 (defun spam-stat-process-directory (dir func)
499   "Process all the regular files in directory DIR using function FUNC."
500   (let* ((files (directory-files dir t "^[^.]"))
501          (max (/ (length files) 100.0))
502          (count 0))
503     (with-temp-buffer
504       (dolist (f files)
505         (when (and (file-readable-p f)
506                    (file-regular-p f)
507                    (> (nth 7 (file-attributes f)) 0)
508                    (< (time-to-number-of-days (time-since (nth 5 (file-attributes f))))
509                       spam-stat-process-directory-age))
510           (setq count (1+ count))
511           (message "Reading %s: %.2f%%" dir (/ count max))
512           (insert-file-contents-literally f)
513           (spam-stat-strip-xref)
514           (funcall func)
515           (erase-buffer))))))
516
517 (defun spam-stat-process-spam-directory (dir)
518   "Process all the regular files in directory DIR as spam."
519   (interactive "D")
520   (spam-stat-process-directory dir 'spam-stat-buffer-is-spam))
521
522 (defun spam-stat-process-non-spam-directory (dir)
523   "Process all the regular files in directory DIR as non-spam."
524   (interactive "D")
525   (spam-stat-process-directory dir 'spam-stat-buffer-is-non-spam))
526
527 (defun spam-stat-count ()
528   "Return size of `spam-stat'."
529   (interactive)
530   (hash-table-count spam-stat))
531
532 (defun spam-stat-test-directory (dir &optional verbose)
533   "Test all the regular files in directory DIR for spam.
534 If the result is 1.0, then all files are considered spam.
535 If the result is 0.0, non of the files is considered spam.
536 You can use this to determine error rates.
537
538 If VERBOSE is non-nil display names of files detected as spam or
539 non-spam in a temporary buffer.  If it is the symbol `ham',
540 display non-spam files; otherwise display spam files."
541   (interactive "DDirectory: ")
542   (let* ((files (directory-files dir t "^[^.]"))
543          display-files
544          buffer-score
545          (total (length files))
546          (score 0.0); float
547          (max (/ total 100.0)); float
548          (count 0))
549     (with-temp-buffer
550       (dolist (f files)
551         (when (and (file-readable-p f)
552                    (file-regular-p f)
553                    (> (nth 7 (file-attributes f)) 0))
554           (setq count (1+ count))
555           (message "Reading %.2f%%, score %.2f"
556                    (/ count max) (/ score count))
557           (insert-file-contents-literally f)
558           (setq buffer-score (spam-stat-score-buffer))
559           (when (> buffer-score 0.9)
560             (setq score (1+ score)))
561           (when verbose
562             (if (> buffer-score 0.9)
563                 (unless (eq verbose 'ham) (push f display-files))
564               (when (eq verbose 'ham) (push f display-files))))
565           (erase-buffer))))
566     (when display-files
567       (with-output-to-temp-buffer "*spam-stat results*"
568         (dolist (file display-files)
569           (princ file)
570           (terpri))))
571     (message "Final score: %d / %d = %f" score total (/ score total))))
572
573 ;; Shrinking the dictionary
574
575 (defun spam-stat-reduce-size (&optional count)
576   "Reduce the size of `spam-stat'.
577 This removes all words that occur less than COUNT from the dictionary.
578 COUNT defaults to 5"
579   (interactive)
580   (setq count (or count 5))
581   (maphash (lambda (key entry)
582              (when (< (+ (spam-stat-good entry)
583                          (spam-stat-bad entry))
584                       count)
585                (remhash key spam-stat)))
586            spam-stat)
587   (setq spam-stat-dirty t))
588
589 (defun spam-stat-install-hooks-function ()
590   "Install the spam-stat function hooks."
591   (interactive)
592   (add-hook 'nnmail-prepare-incoming-message-hook
593             'spam-stat-store-current-buffer)
594   (add-hook 'gnus-select-article-hook
595             'spam-stat-store-gnus-article-buffer))
596
597 (when spam-stat-install-hooks
598   (spam-stat-install-hooks-function))
599
600 (defun spam-stat-unload-hook ()
601   "Uninstall the spam-stat function hooks."
602   (interactive)
603   (remove-hook 'nnmail-prepare-incoming-message-hook
604                'spam-stat-store-current-buffer)
605   (remove-hook 'gnus-select-article-hook
606                'spam-stat-store-gnus-article-buffer))
607
608 (provide 'spam-stat)
609
610 ;;; spam-stat.el ends here