;; bbdb-spam: a package for preventing spam entries from getting into ;; the .bbdb file. ;; http://www.deas.harvard.edu/climate/eli/Downloads/rmail-spam-filter/bbdb-spam.el ;; "The following code (which should work in both RMAIL and vm) looks ;; at the time the BBDB entry was created. If you are deleting a mail ;; message from a sender whose BBDB entry was just created, it is ;; assumed that this might be a spam message for which no BBDB entry ;; is desired. In this case the code prompts you to delete the BBDB ;; entry as well. This way you wont be asked next time if to change ;; the entry etc, as it wont be there. You easily can have this code ;; delete the message without prompting you if you are desperate." (defgroup bbdb--spam nil "handle spam in bbdb." :group 'bbdb) (defcustom rsf-auto-delete-spam-bbdb-entries nil "*Non-nil to make sure no entries are made in bbdb for spam emails. This is done in two ways: (1) bbdb is made not to auto-create entries for messages that are deleted by the `rmail-spam-filter', (2) when a message is deleted in rmail, the user is offered to delete the sender's bbdb entry as well if it was created at the same day. Note that Emacs needs to be restarted after setting this option for it to take an effect." :type 'boolean :group 'bbdb-spam ) (defcustom vm-use-spam-filter nil "*Non-nil to activate the rmail spam filter. Specify `rsf-definitions-alist' to define what you consider spam emails." :type 'boolean :group 'bbdb-spam ) (defvar rsf-working-with-vm nil "Non nil when vm is active. for interaction with `rsf-auto-delete-spam-bbdb-entries'") (defun rsf-bbdb-auto-delete-spam-entries () "When user delets a message in RMAIL, this function checks if the bbdb entry was created today, and if it was, it prompts to delete this entry too. This function needs to be called via the `rmail-delete-message-hook' like this: \(add-hook 'rmail-delete-message-hook 'rsf-bbdb-auto-delete-spam-entries)" (interactive) (require 'bbdb-hooks) (if (not rsf-scanning-messages-now) (if (get-buffer "*BBDB*") (save-excursion (set-buffer (get-buffer "*BBDB*")) (if (bbdb-current-record) (if (equal (format-time-string bbdb-time-internal-format (current-time)) (bbdb-record-getprop (bbdb-current-record) 'creation-date)) (bbdb-delete-current-record (bbdb-current-record)))))))) (defun rsf-bbdb-dont-create-entries-for-deleted-messages () "Make sure senderes of messages marked as deleted are not added to bbdb. Works with vm and rmail. Returns nil for deleted messages or for messages in spam-folder. Need to add this as a hook like this: \(setq bbdb/mail-auto-create-p 'rsf-bbdb-dont-create-entries-for-deleted-messages) and this is also used in conjunction with rsf-bbdb-auto-delete-spam-entries. More doc: rsf-bbdb-auto-delete-spam-entries will delete newly created bbdb entries of mail that is deleted. However, if one scrolls back to the deleted messages, then the sender is again added to the bbdb. This function prevents this. Also, don't create entries for messages in the `rsf-file'." (interactive) ;; don't create a bbdb entry if one of the following conditions is satisfied: (let ((dont-create nil)) ;; use this only if appropriate variable is set and if ;; rmail-buffer is set meaning that rmail is active: (if (and rmail-use-spam-filter rmail-buffer) (setq dont-create (or ;; 1) looking at a deleted message: (rmail-message-deleted-p rmail-current-message) ;; 2) looking at messages in rsf-file: (string-match (expand-file-name rsf-file) (expand-file-name (buffer-file-name rmail-buffer))) ))) (if (and vm-use-spam-filter rsf-working-with-vm) (setq dont-create (vm-deleted-flag (car vm-message-pointer)))) (not dont-create))) ;; add a veriable that is set to t when vm is active: (if vm-use-spam-filter (progn (add-hook 'vm-mode-hook 'rsf-working-with-vm-func) (add-hook 'vm-quit-hook 'rsf-not-working-with-vm-func))) (defun rsf-working-with-vm-func () (interactive) (setq rsf-working-with-vm t)) (defun rsf-not-working-with-vm-func () (interactive) (setq rsf-working-with-vm nil)) ;; activate bbdb-anti-spam measures for rmail or vm: (if rsf-auto-delete-spam-bbdb-entries (progn ;; for rmail: (if rmail-use-spam-filter (progn (add-hook 'rmail-delete-message-hook 'rsf-bbdb-auto-delete-spam-entries) (setq bbdb/mail-auto-create-p 'rsf-bbdb-dont-create-entries-for-deleted-messages))) ;; for vm: (if vm-use-spam-filter (progn (defadvice vm-delete-message (before advice-rsf-bbdb-auto-delete-spam-entries activate) (rsf-bbdb-auto-delete-spam-entries)) (setq bbdb/mail-auto-create-p 'rsf-bbdb-dont-create-entries-for-deleted-messages))) )) (defun rsf-bbdb-auto-delete-spam-entries () "When user delets a message in RMAIL, this function checks if the bbdb entry was created today, and if it was, it prompts to delete this entry too. This function needs to be called via the `rmail-delete-message-hook' like this: \(add-hook 'rmail-delete-message-hook 'rsf-bbdb-auto-delete-spam-entries)" (interactive) (require 'bbdb-hooks) (if (not rsf-scanning-messages-now) (if (get-buffer "*BBDB*") (save-excursion (set-buffer (get-buffer "*BBDB*")) (if (bbdb-current-record) (if (equal (format-time-string bbdb-time-internal-format (current-time)) (bbdb-record-getprop (bbdb-current-record) 'creation-date)) (bbdb-delete-current-record (bbdb-current-record))))))))