Mercurial > emacs
comparison lisp/mail/rmail-spam-filter.el @ 54002:e712b82ead1a
(vm-use-spam-filter)
(rsf-min-region-length-added-to-spam-list): New variables.
(rsf-bbdb-auto-delete-spam-bbdb-entries): Renamed from
rmail-bbdb-auto-delete-spam-entries. Added cc: to recipients for
spam testing. Don't delete spam message if automatic deletion
after output via variable rmail-delete-after-output is turned on.
(rsf-bbdb-dont-create-entries-for-deleted-messages): Renamed from
rsf-bbdb-dont-create-entries-for-spam.
(check-field): New function, extracted from code in
rmail-spam-filter to ease addition of header fields like
content-type.
(message-content-type): New variable to check the content-type:
field added, also in defcustom of rsf-definitions-alist.
(rmail-spam-filter): Replace repeated test code for header fields
by calls to check-field; change the call to
rmail-output-to-rmail-file such that rmail-current-message stays
the same to avoid wrong deletion of unseen flags.
(rsf-add-contents-type): New function to convert old format
of rmail-spam-definitions-alist into new one.
Changed prefixes of all variables and functions from
rmail-spam-filter- or spam-filter- or rmail-spam- to rsf-.
author | Eli Zaretskii <eliz@is.elta.co.il> |
---|---|
date | Mon, 16 Feb 2004 18:05:42 +0000 |
parents | 2a4fc5c14ddd |
children | d69a48d76be3 |
comparison
equal
deleted
inserted
replaced
54001:1bf19a8a6747 | 54002:e712b82ead1a |
---|---|
1 ;;; rmail-spam-filter.el --- spam filter for rmail, the emacs mail reader. | 1 ;;; rmail-spam-filter.el --- spam filter for rmail, the emacs mail reader. |
2 | 2 |
3 ;; Copyright (C) 2002 Free Software Foundation, Inc. | 3 ;; Copyright (C) 2002 |
4 | 4 ;; Free Software Foundation, Inc. |
5 ;; Keywords: email, spam, filter, rmail | 5 ;; Keywords: email, spam, filter, rmail |
6 ;; Author: Eli Tziperman <eli AT deas.harvard.edu> | 6 ;; Author: Eli Tziperman <eli AT deas.harvard.edu> |
7 | 7 |
8 ;; This file is part of GNU Emacs. | 8 ;; This file is part of GNU Emacs. |
9 | 9 |
26 ;;; ----------- | 26 ;;; ----------- |
27 | 27 |
28 ;;; Automatically recognize and delete junk email before it is | 28 ;;; Automatically recognize and delete junk email before it is |
29 ;;; displayed in rmail/rmail-summary. Spam emails are defined by | 29 ;;; displayed in rmail/rmail-summary. Spam emails are defined by |
30 ;;; specifying one or more of the sender, subject and contents. | 30 ;;; specifying one or more of the sender, subject and contents. |
31 ;;; URL: http://deas.harvard.edu/climate/eli/Downloads/rmail-spam-filter/ | 31 ;;; URL: http://www.weizmann.ac.il/~eli/Downloads/rmail-spam-filter/ |
32 | 32 |
33 ;;; Usage: | 33 ;;; Usage: |
34 ;;; ------ | 34 ;;; ------ |
35 | 35 |
36 ;;; put in your .emacs: | 36 ;;; put in your .emacs: |
81 ;;; messages that are deleted by the rmail-spam-filter, (b) when a | 81 ;;; messages that are deleted by the rmail-spam-filter, (b) when a |
82 ;;; message is deleted in rmail, the user is offered to delete the | 82 ;;; message is deleted in rmail, the user is offered to delete the |
83 ;;; sender's bbdb entry as well _if_ it was created at the same day. | 83 ;;; sender's bbdb entry as well _if_ it was created at the same day. |
84 | 84 |
85 (require 'rmail) | 85 (require 'rmail) |
86 (require 'rmailsum) | 86 (if (> emacs-major-version 20) |
87 (require 'rmailsum) | |
88 (if (not (fboundp 'rmail-make-summary-line)) (load-library "rmailsum"))) | |
87 | 89 |
88 ;; For find-if and other cool common lisp functions we may want to use. | 90 ;; For find-if and other cool common lisp functions we may want to use. |
89 (eval-when-compile | 91 (eval-when-compile |
90 (require 'cl)) | 92 (require 'cl)) |
91 | 93 |
92 (defgroup rmail-spam-filter nil | 94 (defgroup rmail-spam-filter nil |
93 "Spam filter for RMAIL, the mail reader for Emacs." | 95 "Spam filter for RMAIL, the mail reader for Emacs." |
94 :group 'rmail) | 96 :group 'rmail) |
95 | 97 |
96 ;;;###autoload | |
97 (defcustom rmail-use-spam-filter nil | 98 (defcustom rmail-use-spam-filter nil |
98 "*Non-nil to activate the rmail spam filter. | 99 "*Non-nil to activate the rmail spam filter. |
99 Specify `rsf-definitions-alist' to define what you consider spam | 100 Specify `rsf-definitions-alist' to define what you consider spam |
100 emails." | 101 emails." |
101 :type 'boolean | 102 :type 'boolean |
212 "Non nil when rmail-spam-filter scans messages, | 213 "Non nil when rmail-spam-filter scans messages, |
213 for interaction with `rsf-bbdb-auto-delete-spam-entries'") | 214 for interaction with `rsf-bbdb-auto-delete-spam-entries'") |
214 | 215 |
215 ;; the advantage over the automatic filter definitions is the AND conjunction | 216 ;; the advantage over the automatic filter definitions is the AND conjunction |
216 ;; of in-one-definition-elements | 217 ;; of in-one-definition-elements |
217 (defun rsf-check-field (field-symbol message-data definition result) | 218 (defun check-field (field-symbol message-data definition result) |
218 "Check if field-symbol is in `rsf-definitions-alist'. | 219 "Check if field-symbol is in `rsf-definitions-alist'. |
219 Capture maybe-spam and this-is-a-spam-email in a cons in result, | 220 Capture maybe-spam and this-is-a-spam-email in a cons in result, |
220 where maybe-spam is in first and this-is-a-spam-email is in rest. | 221 where maybe-spam is in first and this-is-a-spam-email is in rest. |
221 The values are returned by destructively changing result. | 222 The values are returned by destructively changing result. |
222 If FIELD-SYMBOL field does not exist AND is not specified, | 223 If FIELD-SYMBOL field does not exist AND is not specified, |
311 (setq exit-while-loop t | 312 (setq exit-while-loop t |
312 maybe-spam nil | 313 maybe-spam nil |
313 this-is-a-spam-email nil)) | 314 this-is-a-spam-email nil)) |
314 | 315 |
315 ;; maybe-spam is in first, this-is-a-spam-email in rest, this | 316 ;; maybe-spam is in first, this-is-a-spam-email in rest, this |
316 ;; simplifies the call to rsf-check-field | 317 ;; simplifies the call to check-field |
317 (setq maybe-spam (cons maybe-spam this-is-a-spam-email)) | 318 (setq maybe-spam (cons maybe-spam this-is-a-spam-email)) |
318 | 319 |
319 ;; scan all elements of the list rsf-definitions-alist | 320 ;; scan all elements of the list rsf-definitions-alist |
320 (while (and | 321 (while (and |
321 (< num-element num-spam-definition-elements) | 322 (< num-element num-spam-definition-elements) |
342 ;; loop to make the whole thing more flexible | 343 ;; loop to make the whole thing more flexible |
343 ;; if sender field is not specified in message being | 344 ;; if sender field is not specified in message being |
344 ;; scanned, AND if "from" field does not appear in spam | 345 ;; scanned, AND if "from" field does not appear in spam |
345 ;; definitions for this element, this may still be spam | 346 ;; definitions for this element, this may still be spam |
346 ;; due to another element... | 347 ;; due to another element... |
347 (rsf-check-field 'from message-sender definition maybe-spam) | 348 (check-field 'from message-sender definition maybe-spam) |
348 ;; next, if spam was not ruled out already, check recipients: | 349 ;; next, if spam was not ruled out already, check recipients: |
349 (rsf-check-field 'to message-recipients definition maybe-spam) | 350 (check-field 'to message-recipients definition maybe-spam) |
350 ;; next, if spam was not ruled out already, check subject: | 351 ;; next, if spam was not ruled out already, check subject: |
351 (rsf-check-field 'subject message-subject definition maybe-spam) | 352 (check-field 'subject message-subject definition maybe-spam) |
352 ;; next, if spam was not ruled out already, check content-type: | 353 ;; next, if spam was not ruled out already, check content-type: |
353 (rsf-check-field 'content-type message-content-type | 354 (check-field 'content-type message-content-type |
354 definition maybe-spam) | 355 definition maybe-spam) |
355 ;; next, if spam was not ruled out already, check | 356 ;; next, if spam was not ruled out already, check |
356 ;; contents: if contents field is not specified, this may | 357 ;; contents: if contents field is not specified, this may |
357 ;; still be spam due to another element... | 358 ;; still be spam due to another element... |
358 (rsf-check-field 'contents | 359 (check-field 'contents |
359 (buffer-substring | 360 (buffer-substring |
360 (rmail-msgbeg msg) (rmail-msgend msg)) | 361 (rmail-msgbeg msg) (rmail-msgend msg)) |
361 definition maybe-spam) | 362 definition maybe-spam) |
362 | 363 |
363 ;; if the search in rsf-definitions-alist found | 364 ;; if the search in rsf-definitions-alist found |
629 spam menu")) | 630 spam menu")) |
630 )))) | 631 )))) |
631 | 632 |
632 (provide 'rmail-spam-filter) | 633 (provide 'rmail-spam-filter) |
633 | 634 |
634 ;;; arch-tag: 03e1d45d-b72f-4dd7-8f04-e7fd78249746 | |
635 ;;; rmail-spam-fitler ends here | 635 ;;; rmail-spam-fitler ends here |