[spambayes-dev] Proposal for Emacs script to save spam-nonspam messages for training purposes

Skip Montanaro skip at pobox.com
Mon Aug 25 15:23:42 EDT 2003


    Paul> Thank you for this script. However, it did not run properly in my
    Paul> case. The function "copy-to-spam" saves the current message into
    Paul> "~/tmp/newspam", then marks it for deletion, jumps to the next
    Paul> message and undeletes that message. In my case, the following
    Paul> modification of e.g.  copy-to-spam seems to work:

    Paul> (defun copy-to-spam ()
    Paul>   (interactive)
    Paul>   (let ((vm-move-after-deleting nil))
    Paul>        (vm-save-message (expand-file-name "~/mail/mboxes/newspam")))
    Paul>   (let ((vm-move-after-undeleting t)) (vm-undelete-message 1)))

Thanks for the feedback.  FWIW, I don't use those precise Emacs Lisp
incantations anymore.  I'm not too surprised they didn't work in all
situations.  VM is a fairly complex beast.

Here's what I do now.

    (defun train-as-spam ()
      (interactive)
      (let ((vm-delete-after-saving nil))
        (vm-save-message (expand-file-name "~/tmp/newspam"))
        (vm-add-message-labels "trained" 1))
      (vm-pipe-message-to-command "hammiefilter.py -s >/dev/null" nil))

    (defun train-as-nonspam ()
      (interactive)
      (let ((vm-delete-after-saving nil))
        (vm-save-message (expand-file-name "~/tmp/newham"))
        (vm-add-message-labels "trained" 1))
      (vm-pipe-message-to-command "hammiefilter.py -g >/dev/null" nil))

    (define-key vm-mode-map "ls" 'train-as-spam)
    (define-key vm-summary-mode-map "ls" 'train-as-spam)
    (define-key vm-mode-map "lh" 'train-as-nonspam)
    (define-key vm-summary-mode-map "lh" 'train-as-nonspam)

It changes two things.  One, it tries not to delete the message, so the
problem you encountered should be gone.  Two, it trains on the message.  I
don't think I've encountered any problems in this regard, though it's worth
noting that mail could be arriving at the same time as hammiefilter has the
database open for write.

I'll update the faq.

Skip




More information about the spambayes-dev mailing list