1 ;;; spam.el --- Identifying spam
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Maintainer: Ted Zlatanov <tzz@lifelogs.com>
8 ;; Keywords: network, spam, mail, bogofilter, BBDB, dspam, dig, whitelist, blacklist, gmane, hashcash, spamassassin, bsfilter, ifile, stat, crm114, spamoracle
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;;; This module addresses a few aspects of spam control under Gnus. Page
28 ;;; breaks are used for grouping declarations and documentation relating to
29 ;;; each particular aspect.
31 ;;; The integration with Gnus is not yet complete. See various `FIXME'
32 ;;; comments, below, for supplementary explanations or discussions.
34 ;;; Several TODO items are marked as such
36 ;; TODO: cross-server splitting, remote processing, training through files
40 ;;{{{ compilation directives and autoloads/requires
42 ;; For Emacs <22.2 and XEmacs.
44 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
46 (eval-when-compile (require 'cl))
48 (require 'message) ;for the message-fetch-field functions
50 (require 'gnus-uu) ; because of key prefix issues
51 ;;; for the definitions of group content classification and spam processors
54 (eval-when-compile (require 'spam-report))
55 (eval-when-compile (require 'hashcash))
57 ;; for nnimap-split-download-body-default
58 (eval-when-compile (require 'nnimap))
61 (autoload 'query-dig "dig")
63 ;; autoload spam-report
65 (autoload 'spam-report-gmane "spam-report")
66 (autoload 'spam-report-gmane-spam "spam-report")
67 (autoload 'spam-report-gmane-ham "spam-report")
68 (autoload 'spam-report-resend "spam-report"))
70 ;; autoload gnus-registry
71 (autoload 'gnus-registry-group-count "gnus-registry")
72 (autoload 'gnus-registry-add-group "gnus-registry")
73 (autoload 'gnus-registry-store-extra-entry "gnus-registry")
74 (autoload 'gnus-registry-fetch-extra "gnus-registry")
77 (autoload 'dns-query "dns")
81 ;;{{{ Main parameters.
82 (defvar spam-backends nil
83 "List of spam.el backends with all the pertinent data.
84 Populated by `spam-install-backend-super'.")
92 (defcustom spam-summary-exit-behavior 'default
93 "Exit behavior at the time of summary exit.
94 Note that setting the `spam-use-move' or `spam-use-copy' backends on
95 a group through group/topic parameters overrides this mechanism."
96 :type '(choice (const 'default :tag
97 "Move spam out of all groups. Move ham out of spam groups.")
99 "Move spam out of all groups. Move ham out of all groups.")
100 (const 'move-none :tag
101 "Never move spam or ham out of any groups."))
104 (defcustom spam-directory (nnheader-concat gnus-directory "spam/")
105 "Directory for spam whitelists and blacklists."
109 (defcustom spam-mark-new-messages-in-spam-group-as-spam t
110 "Whether new messages in a spam group should get the spam-mark."
112 ;; :version "22.1" ;; Gnus 5.10.8 / No Gnus 0.3
115 (defcustom spam-log-to-registry nil
116 "Whether spam/ham processing should be logged in the registry."
120 (defcustom spam-split-symbolic-return nil
121 "Whether `spam-split' should work with symbols or group names."
125 (defcustom spam-split-symbolic-return-positive nil
126 "Whether `spam-split' should ALWAYS work with symbols or group names.
127 Do not set this if you use `spam-split' in a fancy split method."
131 (defcustom spam-mark-only-unseen-as-spam t
132 "Whether only unseen articles should be marked as spam in spam groups.
133 When nil, all unread articles in a spam group are marked as
134 spam. Set this if you want to leave an article unread in a spam group
135 without losing it to the automatic spam-marking process."
139 (defcustom spam-mark-ham-unread-before-move-from-spam-group nil
140 "Whether ham should be marked unread before it's moved.
141 The article is moved out of a spam group according to `ham-process-destination'.
142 This variable is an official entry in the international Longest Variable Name
147 (defcustom spam-disable-spam-split-during-ham-respool nil
148 "Whether `spam-split' should be ignored while resplitting ham.
149 This is useful to prevent ham from ending up in the same spam
150 group after the resplit. Don't set this to t if you have `spam-split' as the
151 last rule in your split configuration."
155 (defcustom spam-autodetect-recheck-messages nil
156 "Should spam.el recheck all meessages when autodetecting?
157 Normally this is nil, so only unseen messages will be checked."
161 (defcustom spam-whitelist (expand-file-name "whitelist" spam-directory)
162 "The location of the whitelist.
163 The file format is one regular expression per line.
164 The regular expression is matched against the address."
168 (defcustom spam-blacklist (expand-file-name "blacklist" spam-directory)
169 "The location of the blacklist.
170 The file format is one regular expression per line.
171 The regular expression is matched against the address."
175 (defcustom spam-use-dig t
176 "Whether `query-dig' should be used instead of `dns-query'."
180 (defcustom spam-use-gmane-xref nil
181 "Whether the Gmane spam xref should be used by `spam-split'."
185 (defcustom spam-use-blacklist nil
186 "Whether the blacklist should be used by `spam-split'."
190 (defcustom spam-blacklist-ignored-regexes nil
191 "Regular expressions that the blacklist should ignore."
192 :type '(repeat (regexp :tag "Regular expression to ignore when blacklisting"))
195 (defcustom spam-use-whitelist nil
196 "Whether the whitelist should be used by `spam-split'."
200 (defcustom spam-use-whitelist-exclusive nil
201 "Whether whitelist-exclusive should be used by `spam-split'.
202 Exclusive whitelisting means that all messages from senders not in the whitelist
203 are considered spam."
207 (defcustom spam-use-blackholes nil
208 "Whether blackholes should be used by `spam-split'."
212 (defcustom spam-use-hashcash nil
213 "Whether hashcash payments should be detected by `spam-split'."
217 (defcustom spam-use-regex-headers nil
218 "Whether a header regular expression match should be used by `spam-split'.
219 Also see the variables `spam-regex-headers-spam' and `spam-regex-headers-ham'."
223 (defcustom spam-use-regex-body nil
224 "Whether a body regular expression match should be used by `spam-split'.
225 Also see the variables `spam-regex-body-spam' and `spam-regex-body-ham'."
229 (defcustom spam-use-bogofilter-headers nil
230 "Whether bogofilter headers should be used by `spam-split'.
231 Enable this if you pre-process messages with Bogofilter BEFORE Gnus sees them."
235 (defcustom spam-use-bogofilter nil
236 "Whether bogofilter should be invoked by `spam-split'.
237 Enable this if you want Gnus to invoke Bogofilter on new messages."
241 (defcustom spam-use-bsfilter-headers nil
242 "Whether bsfilter headers should be used by `spam-split'.
243 Enable this if you pre-process messages with Bsfilter BEFORE Gnus sees them."
247 (defcustom spam-use-bsfilter nil
248 "Whether bsfilter should be invoked by `spam-split'.
249 Enable this if you want Gnus to invoke Bsfilter on new messages."
253 (defcustom spam-use-BBDB nil
254 "Whether BBDB should be used by `spam-split'."
258 (defcustom spam-use-BBDB-exclusive nil
259 "Whether BBDB-exclusive should be used by `spam-split'.
260 Exclusive BBDB means that all messages from senders not in the BBDB are
265 (defcustom spam-use-ifile nil
266 "Whether ifile should be used by `spam-split'."
270 (defcustom spam-use-stat nil
271 "Whether `spam-stat' should be used by `spam-split'."
275 (defcustom spam-use-spamoracle nil
276 "Whether spamoracle should be used by `spam-split'."
280 (defcustom spam-use-spamassassin nil
281 "Whether spamassassin should be invoked by `spam-split'.
282 Enable this if you want Gnus to invoke SpamAssassin on new messages."
286 (defcustom spam-use-spamassassin-headers nil
287 "Whether spamassassin headers should be checked by `spam-split'.
288 Enable this if you pre-process messages with SpamAssassin BEFORE Gnus sees
293 (defcustom spam-use-crm114 nil
294 "Whether the CRM114 Mailfilter should be used by `spam-split'."
298 (defcustom spam-install-hooks (or
303 spam-use-whitelist-exclusive
306 spam-use-regex-headers
309 spam-use-bogofilter-headers
310 spam-use-spamassassin
311 spam-use-spamassassin-headers
313 spam-use-bsfilter-headers
315 spam-use-BBDB-exclusive
320 "Whether the spam hooks should be installed.
321 Default to t if one of the spam-use-* variables is set."
325 (defcustom spam-split-group "spam"
326 "Group name where incoming spam should be put by `spam-split'."
330 ;;; TODO: deprecate this variable, it's confusing since it's a list of strings,
331 ;;; not regular expressions
332 (defcustom spam-junk-mailgroups (cons
334 '("mail.junk" "poste.pourriel"))
335 "Mailgroups with spam contents.
336 All unmarked article in such group receive the spam mark on group entry."
337 :type '(repeat (string :tag "Group"))
341 (defcustom spam-gmane-xref-spam-group "gmane.spam.detected"
342 "The group where spam xrefs can be found on Gmane.
343 Only meaningful if you enable `spam-use-gmane-xref'."
347 (defcustom spam-blackhole-servers '("bl.spamcop.net" "relays.ordb.org"
348 "dev.null.dk" "relays.visi.com")
349 "List of blackhole servers.
350 Only meaningful if you enable `spam-use-blackholes'."
351 :type '(repeat (string :tag "Server"))
354 (defcustom spam-blackhole-good-server-regex nil
355 "String matching IP addresses that should not be checked in the blackholes.
356 Only meaningful if you enable `spam-use-blackholes'."
357 :type '(radio (const nil) regexp)
361 '((((class color) (type tty) (background dark))
362 (:foreground "gray80" :background "gray50"))
363 (((class color) (type tty) (background light))
364 (:foreground "gray50" :background "gray80"))
365 (((class color) (background dark))
366 (:foreground "ivory2"))
367 (((class color) (background light))
368 (:foreground "ivory4"))
369 (t :inverse-video t))
370 "Face for spam-marked articles."
372 ;; backward-compatibility alias
373 (put 'spam-face 'face-alias 'spam)
374 (put 'spam-face 'obsolete-face "22.1")
376 (defcustom spam-face 'spam
377 "Face for spam-marked articles."
381 (defcustom spam-regex-headers-spam '("^X-Spam-Flag: YES")
382 "Regular expression for positive header spam matches.
383 Only meaningful if you enable `spam-use-regex-headers'."
384 :type '(repeat (regexp :tag "Regular expression to match spam header"))
387 (defcustom spam-regex-headers-ham '("^X-Spam-Flag: NO")
388 "Regular expression for positive header ham matches.
389 Only meaningful if you enable `spam-use-regex-headers'."
390 :type '(repeat (regexp :tag "Regular expression to match ham header"))
393 (defcustom spam-regex-body-spam '()
394 "Regular expression for positive body spam matches.
395 Only meaningful if you enable `spam-use-regex-body'."
396 :type '(repeat (regexp :tag "Regular expression to match spam body"))
399 (defcustom spam-regex-body-ham '()
400 "Regular expression for positive body ham matches.
401 Only meaningful if you enable `spam-use-regex-body'."
402 :type '(repeat (regexp :tag "Regular expression to match ham body"))
405 (defcustom spam-summary-score-preferred-header nil
406 "Preferred header to use for `spam-summary-score'."
407 :type '(choice :tag "Header name"
408 (symbol :tag "SpamAssassin etc" X-Spam-Status)
409 (symbol :tag "Bogofilter" X-Bogosity)
410 (const :tag "No preference, take best guess." nil))
413 (defgroup spam-ifile nil
414 "Spam ifile configuration."
417 (make-obsolete-variable 'spam-ifile-path 'spam-ifile-program
418 "Gnus 5.10.9 (Emacs 22.1)")
419 (defcustom spam-ifile-program (executable-find "ifile")
420 "Name of the ifile program."
421 :type '(choice (file :tag "Location of ifile")
422 (const :tag "ifile is not installed"))
425 (make-obsolete-variable 'spam-ifile-database-path 'spam-ifile-database
426 "Gnus 5.10.9 (Emacs 22.1)")
427 (defcustom spam-ifile-database nil
428 "File name of the ifile database."
429 :type '(choice (file :tag "Location of the ifile database")
430 (const :tag "Use the default"))
433 (defcustom spam-ifile-spam-category "spam"
434 "Name of the spam ifile category."
438 (defcustom spam-ifile-ham-category nil
439 "Name of the ham ifile category.
440 If nil, the current group name will be used."
441 :type '(choice (string :tag "Use a fixed category")
442 (const :tag "Use the current group name"))
445 (defcustom spam-ifile-all-categories nil
446 "Whether the ifile check will return all categories, or just spam.
447 Set this to t if you want to use the `spam-split' invocation of ifile as
448 your main source of newsgroup names."
452 (defgroup spam-bogofilter nil
453 "Spam bogofilter configuration."
456 (make-obsolete-variable 'spam-bogofilter-path 'spam-bogofilter-program
457 "Gnus 5.10.9 (Emacs 22.1)")
458 (defcustom spam-bogofilter-program (executable-find "bogofilter")
459 "Name of the Bogofilter program."
460 :type '(choice (file :tag "Location of bogofilter")
461 (const :tag "Bogofilter is not installed"))
462 :group 'spam-bogofilter)
464 (defvar spam-bogofilter-valid 'unknown "Is the bogofilter version valid?")
466 (defcustom spam-bogofilter-header "X-Bogosity"
467 "The header that Bogofilter inserts in messages."
469 :group 'spam-bogofilter)
471 (defcustom spam-bogofilter-spam-switch "-s"
472 "The switch that Bogofilter uses to register spam messages."
474 :group 'spam-bogofilter)
476 (defcustom spam-bogofilter-ham-switch "-n"
477 "The switch that Bogofilter uses to register ham messages."
479 :group 'spam-bogofilter)
481 (defcustom spam-bogofilter-spam-strong-switch "-S"
482 "The switch that Bogofilter uses to unregister ham messages."
484 :group 'spam-bogofilter)
486 (defcustom spam-bogofilter-ham-strong-switch "-N"
487 "The switch that Bogofilter uses to unregister spam messages."
489 :group 'spam-bogofilter)
491 (defcustom spam-bogofilter-bogosity-positive-spam-header "^\\(Yes\\|Spam\\)"
492 "The regex on `spam-bogofilter-header' for positive spam identification."
494 :group 'spam-bogofilter)
496 (defcustom spam-bogofilter-database-directory nil
497 "Location of the Bogofilter database.
498 When nil, use the default location."
499 :type '(choice (directory
500 :tag "Location of the Bogofilter database directory")
501 (const :tag "Use the default"))
502 :group 'spam-bogofilter)
504 (defgroup spam-bsfilter nil
505 "Spam bsfilter configuration."
508 (make-obsolete-variable 'spam-bsfilter-path 'spam-bsfilter-program
509 "Gnus 5.10.9 (Emacs 22.1)")
510 (defcustom spam-bsfilter-program (executable-find "bsfilter")
511 "Name of the Bsfilter program."
512 :type '(choice (file :tag "Location of bsfilter")
513 (const :tag "Bsfilter is not installed"))
514 :group 'spam-bsfilter)
516 (defcustom spam-bsfilter-header "X-Spam-Flag"
517 "The header inserted by Bsfilter to flag spam."
519 :group 'spam-bsfilter)
521 (defcustom spam-bsfilter-probability-header "X-Spam-Probability"
522 "The header that Bsfilter inserts in messages."
524 :group 'spam-bsfilter)
526 (defcustom spam-bsfilter-spam-switch "--add-spam"
527 "The switch that Bsfilter uses to register spam messages."
529 :group 'spam-bsfilter)
531 (defcustom spam-bsfilter-ham-switch "--add-clean"
532 "The switch that Bsfilter uses to register ham messages."
534 :group 'spam-bsfilter)
536 (defcustom spam-bsfilter-spam-strong-switch "--sub-spam"
537 "The switch that Bsfilter uses to unregister ham messages."
539 :group 'spam-bsfilter)
541 (defcustom spam-bsfilter-ham-strong-switch "--sub-clean"
542 "The switch that Bsfilter uses to unregister spam messages."
544 :group 'spam-bsfilter)
546 (defcustom spam-bsfilter-database-directory nil
547 "Directory path of the Bsfilter databases."
548 :type '(choice (directory
549 :tag "Location of the Bsfilter database directory")
550 (const :tag "Use the default"))
551 :group 'spam-bsfilter)
553 (defgroup spam-spamoracle nil
554 "Spam spamoracle configuration."
557 (defcustom spam-spamoracle-database nil
558 "Location of spamoracle database file.
559 When nil, use the default spamoracle database."
560 :type '(choice (directory :tag "Location of spamoracle database file.")
561 (const :tag "Use the default"))
562 :group 'spam-spamoracle)
564 (defcustom spam-spamoracle-binary (executable-find "spamoracle")
565 "Location of the spamoracle binary."
566 :type '(choice (directory :tag "Location of the spamoracle binary")
567 (const :tag "Use the default"))
568 :group 'spam-spamoracle)
570 (defgroup spam-spamassassin nil
571 "Spam SpamAssassin configuration."
574 (make-obsolete-variable 'spam-spamassassin-path
575 'spam-spamassassin-program "Gnus 5.10.9 (Emacs 22.1)")
576 (defcustom spam-assassin-program (executable-find "spamassassin")
577 "Name of the spamassassin program.
578 Hint: set this to \"spamc\" if you have spamd running. See the spamc and
579 spamd man pages for more information on these programs."
580 :type '(choice (file :tag "Location of spamc")
581 (const :tag "spamassassin is not installed"))
582 :group 'spam-spamassassin)
584 (defcustom spam-spamassassin-arguments ()
585 "Arguments to pass to the spamassassin executable.
586 This must be a list. For example, `(\"-C\" \"configfile\")'."
587 :type '(restricted-sexp :match-alternatives (listp))
588 :group 'spam-spamassassin)
590 (defcustom spam-spamassassin-spam-flag-header "X-Spam-Flag"
591 "The header inserted by SpamAssassin to flag spam."
593 :group 'spam-spamassassin)
595 (defcustom spam-spamassassin-positive-spam-flag-header "YES"
596 "The regex on `spam-spamassassin-spam-flag-header' for positive spam
599 :group 'spam-spamassassin)
601 (defcustom spam-spamassassin-spam-status-header "X-Spam-Status"
602 "The header inserted by SpamAssassin, giving extended scoring information"
604 :group 'spam-spamassassin)
606 (make-obsolete-variable 'spam-sa-learn-path 'spam-sa-learn-program
607 "Gnus 5.10.9 (Emacs 22.1)")
608 (defcustom spam-sa-learn-program (executable-find "sa-learn")
609 "Name of the sa-learn program."
610 :type '(choice (file :tag "Location of spamassassin")
611 (const :tag "spamassassin is not installed"))
612 :group 'spam-spamassassin)
614 (defcustom spam-sa-learn-rebuild t
615 "Whether sa-learn should rebuild the database every time it is called
616 Enable this if you want sa-learn to rebuild the database automatically. Doing
617 this will slightly increase the running time of the spam registration process.
618 If you choose not to do this, you will have to run \"sa-learn --rebuild\" in
619 order for SpamAssassin to recognize the new registered spam."
621 :group 'spam-spamassassin)
623 (defcustom spam-sa-learn-spam-switch "--spam"
624 "The switch that sa-learn uses to register spam messages."
626 :group 'spam-spamassassin)
628 (defcustom spam-sa-learn-ham-switch "--ham"
629 "The switch that sa-learn uses to register ham messages."
631 :group 'spam-spamassassin)
633 (defcustom spam-sa-learn-unregister-switch "--forget"
634 "The switch that sa-learn uses to unregister messages messages."
636 :group 'spam-spamassassin)
638 (defgroup spam-crm114 nil
639 "Spam CRM114 Mailfilter configuration."
642 (defcustom spam-crm114-program (executable-find "mailfilter.crm")
643 "File path of the CRM114 Mailfilter executable program."
644 :type '(choice (file :tag "Location of CRM114 Mailfilter")
645 (const :tag "CRM114 Mailfilter is not installed"))
648 (defcustom spam-crm114-header "X-CRM114-Status"
649 "The header that CRM114 Mailfilter inserts in messages."
653 (defcustom spam-crm114-spam-switch "--learnspam"
654 "The switch that CRM114 Mailfilter uses to register spam messages."
658 (defcustom spam-crm114-ham-switch "--learnnonspam"
659 "The switch that CRM114 Mailfilter uses to register ham messages."
663 (defcustom spam-crm114-spam-strong-switch "--unlearn"
664 "The switch that CRM114 Mailfilter uses to unregister ham messages."
668 (defcustom spam-crm114-ham-strong-switch "--unlearn"
669 "The switch that CRM114 Mailfilter uses to unregister spam messages."
673 (defcustom spam-crm114-positive-spam-header "^SPAM"
674 "The regex on `spam-crm114-header' for positive spam identification."
678 (defcustom spam-crm114-database-directory nil
679 "Directory path of the CRM114 Mailfilter databases."
680 :type '(choice (directory
681 :tag "Location of the CRM114 Mailfilter database directory")
682 (const :tag "Use the default"))
685 ;;; Key bindings for spam control.
687 (gnus-define-keys gnus-summary-mode-map
688 "St" spam-generic-score
689 "Sx" gnus-summary-mark-as-spam
690 "Mst" spam-generic-score
691 "Msx" gnus-summary-mark-as-spam
692 "\M-d" gnus-summary-mark-as-spam
693 "$" gnus-summary-mark-as-spam)
695 (defvar spam-cache-lookups t
696 "Whether spam.el will try to cache lookups using `spam-caches'.")
698 (defvar spam-caches (make-hash-table
701 "Cache of spam detection entries.")
703 (defvar spam-old-articles nil
704 "List of old ham and spam articles, generated when a group is entered.")
706 (defvar spam-split-disabled nil
707 "If non-nil, `spam-split' is disabled, and always returns nil.")
709 (defvar spam-split-last-successful-check nil
711 `spam-split' will set this to nil or a spam-use-XYZ check if it
714 ;; internal variables for backends
715 ;; TODO: find a way to create these on the fly in spam-install-backend-super
716 (defvar spam-use-copy nil)
717 (defvar spam-use-move nil)
718 (defvar spam-use-gmane nil)
719 (defvar spam-use-resend nil)
723 ;;{{{ convenience functions
725 (defun spam-clear-cache (symbol)
726 "Clear the `spam-caches' entry for a check."
727 (remhash symbol spam-caches))
729 (defun spam-xor (a b)
731 (and (or a b) (not (and a b))))
733 (defun spam-set-difference (list1 list2)
734 "Return a set difference of LIST1 and LIST2.
735 When either list is nil, the other is returned."
736 (if (and list1 list2)
737 ;; we have two non-nil lists
739 (dolist (item (append list1 list2))
740 (when (and (memq item list1) (memq item list2))
741 (setq list1 (delq item list1))
742 (setq list2 (delq item list2))))
743 (append list1 list2))
744 ;; if either of the lists was nil, return the other one
745 (if list1 list1 list2)))
747 (defun spam-group-ham-mark-p (group mark &optional spam)
748 "Checks if MARK is considered a ham mark in GROUP."
749 (when (stringp group)
750 (let* ((marks (spam-group-ham-marks group spam))
751 (marks (if (symbolp mark)
753 (mapcar 'symbol-value marks))))
756 (defun spam-group-spam-mark-p (group mark)
757 "Checks if MARK is considered a spam mark in GROUP."
758 (spam-group-ham-mark-p group mark t))
760 (defun spam-group-ham-marks (group &optional spam)
761 "In GROUP, get all the ham marks."
762 (when (stringp group)
763 (let* ((marks (if spam
764 (gnus-parameter-spam-marks group)
765 (gnus-parameter-ham-marks group)))
767 (marks (if (listp (car marks)) (car marks) marks)))
770 (defun spam-group-spam-marks (group)
771 "In GROUP, get all the spam marks."
772 (spam-group-ham-marks group t))
774 (defun spam-group-spam-contents-p (group)
775 "Is GROUP a spam group?"
776 (if (and (stringp group) (< 0 (length group)))
777 (or (member group spam-junk-mailgroups)
778 (memq 'gnus-group-spam-classification-spam
779 (gnus-parameter-spam-contents group)))
782 (defun spam-group-ham-contents-p (group)
783 "Is GROUP a ham group?"
785 (memq 'gnus-group-spam-classification-ham
786 (gnus-parameter-spam-contents group))
789 (defun spam-classifications ()
790 "Return list of valid classifications"
793 (defun spam-classification-valid-p (classification)
794 "Is CLASSIFICATION a valid spam/ham classification?"
795 (memq classification (spam-classifications)))
797 (defun spam-backend-properties ()
798 "Return list of valid classifications."
799 '(statistical mover check hrf srf huf suf))
801 (defun spam-backend-property-valid-p (property)
802 "Is PROPERTY a valid backend property?"
803 (memq property (spam-backend-properties)))
805 (defun spam-backend-function-type-valid-p (type)
806 (or (eq type 'registration)
807 (eq type 'unregistration)))
809 (defun spam-process-type-valid-p (process-type)
810 (or (eq process-type 'incoming)
811 (eq process-type 'process)))
813 (defun spam-list-articles (articles classification)
814 (let ((mark-check (if (eq classification 'spam)
815 'spam-group-spam-mark-p
816 'spam-group-ham-mark-p))
817 alist mark-cache-yes mark-cache-no)
818 (dolist (article articles)
819 (let ((mark (gnus-summary-article-mark article)))
820 (unless (or (memq mark mark-cache-yes)
821 (memq mark mark-cache-no))
822 (if (funcall mark-check
825 (push mark mark-cache-yes)
826 (push mark mark-cache-no)))
827 (when (memq mark mark-cache-yes)
828 (push article alist))))
833 ;;{{{ backend installation functions and procedures
835 (defun spam-install-backend-super (backend &rest properties)
836 "Install BACKEND for spam.el.
837 Accepts incoming CHECK, ham registration function HRF, spam
838 registration function SRF, ham unregistration function HUF, spam
839 unregistration function SUF, and an indication whether the
840 backend is STATISTICAL."
841 (setq spam-backends (add-to-list 'spam-backends backend))
843 (let ((property (pop properties))
844 (value (pop properties)))
845 (if (spam-backend-property-valid-p property)
846 (put backend property value)
849 "spam-install-backend-super got an invalid property %s"
852 (defun spam-backend-list (&optional type)
853 "Return a list of all the backend symbols, constrained by TYPE.
854 When TYPE is 'non-mover, only non-mover backends are returned.
855 When TYPE is 'mover, only mover backends are returned."
857 (dolist (backend spam-backends)
859 (null type) ;either no type was requested
860 ;; or the type is 'mover and the backend is a mover
863 (spam-backend-mover-p backend))
864 ;; or the type is 'non-mover and the backend is not a mover
867 (not (spam-backend-mover-p backend))))
868 (push backend list)))
871 (defun spam-backend-check (backend)
872 "Get the check function for BACKEND.
873 Each individual check may return nil, t, or a mailgroup name.
874 The value nil means that the check does not yield a decision, and
875 so, that further checks are needed. The value t means that the
876 message is definitely not spam, and that further spam checks
877 should be inhibited. Otherwise, a mailgroup name or the symbol
878 'spam (depending on `spam-split-symbolic-return') is returned where
879 the mail should go, and further checks are also inhibited. The
880 usual mailgroup name is the value of `spam-split-group', meaning
881 that the message is definitely a spam."
882 (get backend 'check))
884 (defun spam-backend-valid-p (backend)
886 (member backend (spam-backend-list)))
888 (defun spam-backend-info (backend)
889 "Return information about BACKEND."
890 (if (spam-backend-valid-p backend)
892 (setq info (format "Backend %s has the following properties:\n"
894 (dolist (property (spam-backend-properties))
895 (setq info (format "%s%s=%s\n"
898 (get backend property))))
900 (gnus-error 5 "spam-backend-info was asked about an invalid backend %s"
903 (defun spam-backend-function (backend classification type)
904 "Get the BACKEND function for CLASSIFICATION and TYPE.
905 TYPE is 'registration or 'unregistration.
906 CLASSIFICATION is 'ham or 'spam."
908 (spam-classification-valid-p classification)
909 (spam-backend-function-type-valid-p type))
912 (format "spam-backend-%s-%s-function"
915 (funcall retrieval backend))
918 "%s was passed invalid backend %s, classification %s, or type %s"
919 "spam-backend-function"
924 (defun spam-backend-article-list-property (classification
925 &optional unregister)
926 "Property name of article list with CLASSIFICATION and UNREGISTER."
927 (let* ((r (if unregister "unregister" "register"))
928 (prop (format "%s-%s" classification r)))
931 (defun spam-backend-get-article-todo-list (backend
933 &optional unregister)
934 "Get the articles to be processed for BACKEND and CLASSIFICATION.
935 With UNREGISTER, get articles to be unregistered.
936 This is a temporary storage function - nothing here persists."
939 (intern (spam-backend-article-list-property classification unregister))))
941 (defun spam-backend-put-article-todo-list (backend classification list &optional unregister)
942 "Set the LIST of articles to be processed for BACKEND and CLASSIFICATION.
943 With UNREGISTER, set articles to be unregistered.
944 This is a temporary storage function - nothing here persists."
947 (intern (spam-backend-article-list-property classification unregister))
950 (defun spam-backend-ham-registration-function (backend)
951 "Get the ham registration function for BACKEND."
954 (defun spam-backend-spam-registration-function (backend)
955 "Get the spam registration function for BACKEND."
958 (defun spam-backend-ham-unregistration-function (backend)
959 "Get the ham unregistration function for BACKEND."
962 (defun spam-backend-spam-unregistration-function (backend)
963 "Get the spam unregistration function for BACKEND."
966 (defun spam-backend-statistical-p (backend)
967 "Is BACKEND statistical?"
968 (get backend 'statistical))
970 (defun spam-backend-mover-p (backend)
971 "Is BACKEND a mover?"
972 (get backend 'mover))
974 (defun spam-install-backend-alias (backend alias)
975 "Add ALIAS to an existing BACKEND.
976 The previous backend settings for ALIAS are erased."
978 ;; install alias with no properties at first
979 (spam-install-backend-super alias)
981 (dolist (property (spam-backend-properties))
982 (put alias property (get backend property))))
984 (defun spam-install-checkonly-backend (backend check)
985 "Install a BACKEND than can only CHECK for spam."
986 (spam-install-backend-super backend 'check check))
988 (defun spam-install-mover-backend (backend hrf srf huf suf)
989 "Install a BACKEND than can move articles at summary exit.
990 Accepts ham registration function HRF, spam registration function
991 SRF, ham unregistration function HUF, spam unregistration
992 function SUF. The backend has no incoming check and can't be
994 (spam-install-backend-super
996 'hrf hrf 'srf srf 'huf huf 'suf suf 'mover t))
998 (defun spam-install-nocheck-backend (backend hrf srf huf suf)
999 "Install a BACKEND than has no check.
1000 Accepts ham registration function HRF, spam registration function
1001 SRF, ham unregistration function HUF, spam unregistration
1002 function SUF. The backend has no incoming check and can't be
1003 statistical (it could be, but in practice that doesn't happen)."
1004 (spam-install-backend-super
1006 'hrf hrf 'srf srf 'huf huf 'suf suf))
1008 (defun spam-install-backend (backend check hrf srf huf suf)
1010 Accepts incoming CHECK, ham registration function HRF, spam
1011 registration function SRF, ham unregistration function HUF, spam
1012 unregistration function SUF. The backend won't be
1013 statistical (use `spam-install-statistical-backend' for that)."
1014 (spam-install-backend-super
1016 'check check 'hrf hrf 'srf srf 'huf huf 'suf suf))
1018 (defun spam-install-statistical-backend (backend check hrf srf huf suf)
1020 Accepts incoming CHECK, ham registration function HRF, spam
1021 registration function SRF, ham unregistration function HUF, spam
1022 unregistration function SUF. The backend will be
1023 statistical (use `spam-install-backend' for non-statistical
1025 (spam-install-backend-super
1027 'check check 'statistical t 'hrf hrf 'srf srf 'huf huf 'suf suf))
1029 (defun spam-install-statistical-checkonly-backend (backend check)
1030 "Install a statistical BACKEND than can only CHECK for spam."
1031 (spam-install-backend-super
1033 'check check 'statistical t))
1037 ;;{{{ backend installations
1038 (spam-install-checkonly-backend 'spam-use-blackholes
1039 'spam-check-blackholes)
1041 (spam-install-checkonly-backend 'spam-use-hashcash
1042 'spam-check-hashcash)
1044 (spam-install-checkonly-backend 'spam-use-spamassassin-headers
1045 'spam-check-spamassassin-headers)
1047 (spam-install-checkonly-backend 'spam-use-bogofilter-headers
1048 'spam-check-bogofilter-headers)
1050 (spam-install-checkonly-backend 'spam-use-bsfilter-headers
1051 'spam-check-bsfilter-headers)
1053 (spam-install-checkonly-backend 'spam-use-gmane-xref
1054 'spam-check-gmane-xref)
1056 (spam-install-checkonly-backend 'spam-use-regex-headers
1057 'spam-check-regex-headers)
1059 (spam-install-statistical-checkonly-backend 'spam-use-regex-body
1060 'spam-check-regex-body)
1062 ;; TODO: NOTE: spam-use-ham-copy is now obsolete, use (ham spam-use-copy) instead
1063 (spam-install-mover-backend 'spam-use-move
1064 'spam-move-ham-routine
1065 'spam-move-spam-routine
1069 (spam-install-nocheck-backend 'spam-use-copy
1070 'spam-copy-ham-routine
1071 'spam-copy-spam-routine
1075 (spam-install-nocheck-backend 'spam-use-gmane
1076 'spam-report-gmane-unregister-routine
1077 'spam-report-gmane-register-routine
1078 'spam-report-gmane-register-routine
1079 'spam-report-gmane-unregister-routine)
1081 (spam-install-nocheck-backend 'spam-use-resend
1082 'spam-report-resend-register-ham-routine
1083 'spam-report-resend-register-routine
1087 (spam-install-backend 'spam-use-BBDB
1089 'spam-BBDB-register-routine
1091 'spam-BBDB-unregister-routine
1094 (spam-install-backend-alias 'spam-use-BBDB 'spam-use-BBDB-exclusive)
1096 (spam-install-backend 'spam-use-blacklist
1097 'spam-check-blacklist
1099 'spam-blacklist-register-routine
1101 'spam-blacklist-unregister-routine)
1103 (spam-install-backend 'spam-use-whitelist
1104 'spam-check-whitelist
1105 'spam-whitelist-register-routine
1107 'spam-whitelist-unregister-routine
1110 (spam-install-statistical-backend 'spam-use-ifile
1112 'spam-ifile-register-ham-routine