"Syntax table used when processing mails for statistical analysis.
The important part is which characters are word constituents.")
+(defvar spam-stat-dirty nil
+ "Whether the spam-stat database needs saving.")
+
(defvar spam-stat-buffer nil
"Buffer to use for scoring while splitting.
This is set by hooking into Gnus.")
(set-buffer gnus-original-article-buffer)
(spam-stat-store-current-buffer)))
-(when spam-stat-install-hooks
- (add-hook 'nnmail-prepare-incoming-message-hook
- 'spam-stat-store-current-buffer)
- (add-hook 'gnus-select-article-hook
- 'spam-stat-store-gnus-article-buffer))
-
;; Data -- not using defstruct in order to save space and time
(defvar spam-stat (make-hash-table :test 'equal)
(setq entry (spam-stat-make-entry 0 count)))
(spam-stat-set-score entry (spam-stat-compute-score entry))
(puthash word entry spam-stat)))
- (spam-stat-buffer-words)))
+ (spam-stat-buffer-words))
+ (setq spam-stat-dirty t))
(defun spam-stat-buffer-is-non-spam ()
"Consider current buffer to be a new non-spam mail."
(setq entry (spam-stat-make-entry count 0)))
(spam-stat-set-score entry (spam-stat-compute-score entry))
(puthash word entry spam-stat)))
- (spam-stat-buffer-words)))
+ (spam-stat-buffer-words))
+ (setq spam-stat-dirty t))
(defun spam-stat-buffer-change-to-spam ()
"Consider current buffer no longer normal mail but spam."
(spam-stat-set-bad entry (+ (spam-stat-bad entry) count))
(spam-stat-set-score entry (spam-stat-compute-score entry))
(puthash word entry spam-stat))))
- (spam-stat-buffer-words)))
+ (spam-stat-buffer-words))
+ (setq spam-stat-dirty t))
(defun spam-stat-buffer-change-to-non-spam ()
"Consider current buffer no longer spam but normal mail."
(spam-stat-set-bad entry (- (spam-stat-bad entry) count))
(spam-stat-set-score entry (spam-stat-compute-score entry))
(puthash word entry spam-stat))))
- (spam-stat-buffer-words)))
+ (spam-stat-buffer-words))
+ (setq spam-stat-dirty t))
;; Saving and Loading
-(defun spam-stat-save ()
+(defun spam-stat-save (&optional force)
"Save the `spam-stat' hash table as lisp file."
(interactive)
- (with-temp-buffer
- (let ((standard-output (current-buffer))
- (font-lock-maximum-size 0))
- (insert "(setq spam-stat-ngood "
- (number-to-string spam-stat-ngood)
- " spam-stat-nbad "
- (number-to-string spam-stat-nbad)
- " spam-stat (spam-stat-to-hash-table '(")
- (maphash (lambda (word entry)
- (prin1 (list word
- (spam-stat-good entry)
- (spam-stat-bad entry))))
- spam-stat)
- (insert ")))")
- (write-file spam-stat-file))))
+ (when (or force spam-stat-dirty)
+ (with-temp-buffer
+ (let ((standard-output (current-buffer))
+ (font-lock-maximum-size 0))
+ (insert "(setq spam-stat-ngood "
+ (number-to-string spam-stat-ngood)
+ " spam-stat-nbad "
+ (number-to-string spam-stat-nbad)
+ " spam-stat (spam-stat-to-hash-table '(")
+ (maphash (lambda (word entry)
+ (prin1 (list word
+ (spam-stat-good entry)
+ (spam-stat-bad entry))))
+ spam-stat)
+ (insert ")))")
+ (write-file spam-stat-file)))
+ (setq spam-stat-dirty nil)))
(defun spam-stat-load ()
"Read the `spam-stat' hash table from disk."
- (load-file spam-stat-file))
+ ;; TODO: maybe we should warn the user if spam-stat-dirty is t?
+ (load-file spam-stat-file)
+ (setq spam-stat-dirty nil))
(defun spam-stat-to-hash-table (entries)
"Turn list ENTRIES into a hash table and store as `spam-stat'.
(interactive)
(setq spam-stat (make-hash-table :test 'equal)
spam-stat-ngood 0
- spam-stat-nbad 0))
+ spam-stat-nbad 0)
+ (setq spam-stat-dirty t))
;; Scoring buffers
(remhash key spam-stat)))
spam-stat))
+(defun spam-stat-install-hooks-function ()
+ "Install the spam-stat function hooks"
+ (interactive)
+ (add-hook 'nnmail-prepare-incoming-message-hook
+ 'spam-stat-store-current-buffer)
+ (add-hook 'gnus-select-article-hook
+ 'spam-stat-store-gnus-article-buffer))
+
+(when spam-stat-install-hooks
+ (spam-stat-install-hooks-function))
+
+(defun spam-stat-unload-hook ()
+ "Uninstall the spam-stat function hooks"
+ (interactive)
+ (remove-hook 'nnmail-prepare-incoming-message-hook
+ 'spam-stat-store-current-buffer)
+ (remove-hook 'gnus-select-article-hook
+ 'spam-stat-store-gnus-article-buffer))
+
(provide 'spam-stat)
;;; spam-stat.el ends here