1 ;;; spam.el --- Identifying spam
2 ;; Copyright (C) 2002 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;;; This module addresses a few aspects of spam control under Gnus. Page
27 ;;; breaks are used for grouping declarations and documentation relating to
28 ;;; each particular aspect.
30 ;;; The integration with Gnus is not yet complete. See various `FIXME'
31 ;;; comments, below, for supplementary explanations or discussions.
33 ;;; Several TODO items are marked as such
39 (require 'gnus-uu) ; because of key prefix issues
40 (require 'gnus) ; for the definitions of group content classification and spam processors
41 (require 'message) ;for the message-fetch-field functions
43 ;; autoload executable-find
45 ;; executable-find is not autoloaded in Emacs 20
46 (autoload 'executable-find "executable"))
50 (autoload 'query-dig "dig"))
54 (autoload 'query-dns "dns"))
59 "Spam configuration.")
61 (defcustom spam-directory "~/News/spam/"
62 "Directory for spam whitelists and blacklists."
66 (defcustom spam-move-spam-nonspam-groups-only t
67 "Whether spam should be moved in non-spam groups only.
68 When nil, only ham and unclassified groups will have their spam moved
69 to the spam-process-destination. When t, spam will also be moved from
74 (defcustom spam-whitelist (expand-file-name "whitelist" spam-directory)
75 "The location of the whitelist.
76 The file format is one regular expression per line.
77 The regular expression is matched against the address."
81 (defcustom spam-blacklist (expand-file-name "blacklist" spam-directory)
82 "The location of the blacklist.
83 The file format is one regular expression per line.
84 The regular expression is matched against the address."
88 (defcustom spam-use-dig t
89 "Whether query-dig should be used instead of query-dns."
93 (defcustom spam-use-blacklist nil
94 "Whether the blacklist should be used by spam-split."
98 (defcustom spam-use-whitelist nil
99 "Whether the whitelist should be used by spam-split."
103 (defcustom spam-use-blackholes nil
104 "Whether blackholes should be used by spam-split."
108 (defcustom spam-use-bogofilter-headers nil
109 "Whether bogofilter headers should be used by spam-split.
110 Enable this if you pre-process messages with Bogofilter BEFORE Gnus sees them."
114 (defcustom spam-use-bogofilter nil
115 "Whether bogofilter should be invoked by spam-split.
116 Enable this if you want Gnus to invoke Bogofilter on new messages."
120 (defcustom spam-use-BBDB nil
121 "Whether BBDB should be used by spam-split."
125 (defcustom spam-use-ifile nil
126 "Whether ifile should be used by spam-split."
130 (defcustom spam-use-stat nil
131 "Whether spam-stat should be used by spam-split."
135 (defcustom spam-split-group "spam"
136 "Group name where incoming spam should be put by spam-split."
140 (defcustom spam-junk-mailgroups (cons spam-split-group '("mail.junk" "poste.pourriel"))
141 "Mailgroups with spam contents.
142 All unmarked article in such group receive the spam mark on group entry."
143 :type '(repeat (string :tag "Group"))
146 (defcustom spam-blackhole-servers '("bl.spamcop.net" "relays.ordb.org"
147 "dev.null.dk" "relays.visi.com")
148 "List of blackhole servers."
149 :type '(repeat (string :tag "Server"))
152 (defcustom spam-ham-marks (list 'gnus-del-mark 'gnus-read-mark
153 'gnus-killed-mark 'gnus-kill-file-mark
154 'gnus-low-score-mark)
155 "Marks considered as being ham (positively not spam).
156 Such articles will be processed as ham (non-spam) on group exit."
158 (variable-item gnus-del-mark)
159 (variable-item gnus-read-mark)
160 (variable-item gnus-killed-mark)
161 (variable-item gnus-kill-file-mark)
162 (variable-item gnus-low-score-mark))
165 (defcustom spam-spam-marks (list 'gnus-spam-mark)
166 "Marks considered as being spam (positively spam).
167 Such articles will be transmitted to `bogofilter -s' on group exit."
169 (variable-item gnus-spam-mark)
170 (variable-item gnus-killed-mark)
171 (variable-item gnus-kill-file-mark)
172 (variable-item gnus-low-score-mark))
175 (defcustom spam-face 'gnus-splash-face
176 "Face for spam-marked articles"
180 (defgroup spam-ifile nil
181 "Spam ifile configuration."
184 (defcustom spam-ifile-path (executable-find "ifile")
185 "File path of the ifile executable program."
186 :type '(choice (file :tag "Location of ifile")
187 (const :tag "ifile is not installed"))
190 (defcustom spam-ifile-database-path nil
191 "File path of the ifile database."
192 :type '(choice (file :tag "Location of the ifile database")
193 (const :tag "Use the default"))
196 (defcustom spam-ifile-spam-category "spam"
197 "Name of the spam ifile category."
201 (defcustom spam-ifile-all-categories nil
202 "Whether the ifile check will return all categories, or just spam.
203 Set this to t if you want to use the spam-split invocation of ifile as
204 your main source of newsgroup names."
208 (defgroup spam-bogofilter nil
209 "Spam bogofilter configuration."
212 (defcustom spam-bogofilter-path (executable-find "bogofilter")
213 "File path of the Bogofilter executable program."
214 :type '(choice (file :tag "Location of bogofilter")
215 (const :tag "Bogofilter is not installed"))
216 :group 'spam-bogofilter)
218 (defcustom spam-bogofilter-header "X-Bogosity"
219 "The header that Bogofilter inserts in messages."
221 :group 'spam-bogofilter)
223 (defcustom spam-bogofilter-database-directory nil
224 "Directory path of the Bogofilter databases."
225 :type '(choice (directory :tag "Location of the Bogofilter database directory")
226 (const :tag "Use the default"))
229 ;;; Key bindings for spam control.
231 (gnus-define-keys gnus-summary-mode-map
232 "St" spam-bogofilter-score
233 "Sx" gnus-summary-mark-as-spam
234 "Mst" spam-bogofilter-score
235 "Msx" gnus-summary-mark-as-spam
236 "\M-d" gnus-summary-mark-as-spam)
238 ;;; How to highlight a spam summary line.
240 ;; TODO: How do we redo this every time spam-face is customized?
242 (push '((eq mark gnus-spam-mark) . spam-face)
243 gnus-summary-highlight)
245 ;; convenience functions
246 (defun spam-group-spam-contents-p (group)
248 (or (member group spam-junk-mailgroups)
249 (memq 'gnus-group-spam-classification-spam
250 (gnus-parameter-spam-contents group)))
253 (defun spam-group-ham-contents-p (group)
255 (memq 'gnus-group-spam-classification-ham
256 (gnus-parameter-spam-contents group))
259 (defun spam-group-processor-p (group processor)
260 (if (and (stringp group)
262 (member processor (car (gnus-parameter-spam-process group)))
265 (defun spam-group-spam-processor-bogofilter-p (group)
266 (spam-group-processor-p group 'gnus-group-spam-exit-processor-bogofilter))
268 (defun spam-group-spam-processor-blacklist-p (group)
269 (spam-group-processor-p group 'gnus-group-spam-exit-processor-blacklist))
271 (defun spam-group-spam-processor-ifile-p (group)
272 (spam-group-processor-p group 'gnus-group-spam-exit-processor-ifile))
274 (defun spam-group-ham-processor-ifile-p (group)
275 (spam-group-processor-p group 'gnus-group-ham-exit-processor-ifile))
277 (defun spam-group-ham-processor-bogofilter-p (group)
278 (spam-group-processor-p group 'gnus-group-ham-exit-processor-ifile))
280 (defun spam-group-spam-processor-stat-p (group)
281 (spam-group-processor-p group 'gnus-group-spam-exit-processor-stat))
283 (defun spam-group-ham-processor-stat-p (group)
284 (spam-group-processor-p group 'gnus-group-ham-exit-processor-stat))
286 (defun spam-group-ham-processor-whitelist-p (group)
287 (spam-group-processor-p group 'gnus-group-ham-exit-processor-whitelist))
289 (defun spam-group-ham-processor-BBDB-p (group)
290 (spam-group-processor-p group 'gnus-group-ham-exit-processor-BBDB))
292 ;;; Summary entry and exit processing.
294 (defun spam-summary-prepare ()
295 (spam-mark-junk-as-spam-routine))
297 (add-hook 'gnus-summary-prepare-hook 'spam-summary-prepare)
299 (defun spam-summary-prepare-exit ()
300 ;; The spam processors are invoked for any group, spam or ham or neither
301 (when (and spam-bogofilter-path
302 (spam-group-spam-processor-bogofilter-p gnus-newsgroup-name))
303 (spam-bogofilter-register-spam-routine))
305 (when (and spam-ifile-path
306 (spam-group-spam-processor-ifile-p gnus-newsgroup-name))
307 (spam-ifile-register-spam-routine))
309 (when (spam-group-spam-processor-stat-p gnus-newsgroup-name)
310 (spam-stat-register-spam-routine))
312 (when (spam-group-spam-processor-bogofilter-p gnus-newsgroup-name)
313 (spam-blacklist-register-routine))
315 (if spam-move-spam-nonspam-groups-only
316 (when (not (spam-group-spam-contents-p gnus-newsgroup-name))
317 (spam-mark-spam-as-expired-and-move-routine
318 (gnus-parameter-spam-process-destination gnus-newsgroup-name)))
319 (spam-mark-spam-as-expired-and-move-routine
320 (gnus-parameter-spam-process-destination gnus-newsgroup-name)))
322 ;; now we redo spam-mark-spam-as-expired-and-move-routine to only
323 ;; expire spam, in case the above did not expire them
324 (spam-mark-spam-as-expired-and-move-routine nil)
326 (when (spam-group-ham-contents-p gnus-newsgroup-name)
327 (when (spam-group-ham-processor-whitelist-p gnus-newsgroup-name)
328 (spam-whitelist-register-routine))
329 (when (spam-group-ham-processor-ifile-p gnus-newsgroup-name)
330 (spam-ifile-register-ham-routine))
331 (when (spam-group-ham-processor-bogofilter-p gnus-newsgroup-name)
332 (spam-bogofilter-register-ham-routine))
333 (when (spam-group-ham-processor-stat-p gnus-newsgroup-name)
334 (spam-stat-register-ham-routine))
335 (when (spam-group-ham-processor-BBDB-p gnus-newsgroup-name)
336 (spam-BBDB-register-routine)))
338 ;; now move all ham articles out of spam groups
339 (when (spam-group-spam-contents-p gnus-newsgroup-name)
340 (spam-ham-move-routine
341 (gnus-parameter-ham-process-destination gnus-newsgroup-name))))
343 (add-hook 'gnus-summary-prepare-exit-hook 'spam-summary-prepare-exit)
345 (defun spam-mark-junk-as-spam-routine ()
346 ;; check the global list of group names spam-junk-mailgroups and the
348 (when (spam-group-spam-contents-p gnus-newsgroup-name)
349 (let ((articles gnus-newsgroup-articles)
352 (setq article (pop articles))
353 (when (eq (gnus-summary-article-mark article) gnus-unread-mark)
354 (gnus-summary-mark-article article gnus-spam-mark))))))
356 (defun spam-mark-spam-as-expired-and-move-routine (&optional group)
357 (let ((articles gnus-newsgroup-articles)
360 (setq article (pop articles))
361 (when (eq (gnus-summary-article-mark article) gnus-spam-mark)
362 (gnus-summary-mark-article article gnus-expirable-mark)
363 (when (stringp group)
364 (let ((gnus-current-article article))
365 (gnus-summary-move-article nil group)))))))
367 (defun spam-ham-move-routine (&optional group)
368 (let ((articles gnus-newsgroup-articles)
369 article ham-mark-values mark)
370 (dolist (mark spam-ham-marks)
371 (push (symbol-value mark) ham-mark-values))
374 (setq article (pop articles))
375 (when (and (memq mark ham-mark-values)
377 (let ((gnus-current-article article))
378 (gnus-summary-move-article nil group))))))
380 (defun spam-generic-register-routine (spam-func ham-func)
381 (let ((articles gnus-newsgroup-articles)
382 article mark ham-articles spam-articles spam-mark-values
385 ;; marks are stored as symbolic values, so we have to dereference
386 ;; them for memq to work. we wouldn't have to do this if
387 ;; gnus-summary-article-mark returned a symbol.
388 (dolist (mark spam-ham-marks)
389 (push (symbol-value mark) ham-mark-values))
391 (dolist (mark spam-spam-marks)
392 (push (symbol-value mark) spam-mark-values))
395 (setq article (pop articles)
396 mark (gnus-summary-article-mark article))
397 (cond ((memq mark spam-mark-values) (push article spam-articles))
398 ((memq article gnus-newsgroup-saved))
399 ((memq mark ham-mark-values) (push article ham-articles))))
400 (when (and ham-articles ham-func)
401 (mapc ham-func ham-articles)) ; we use mapc because unlike
402 ; mapcar it discards the
404 (when (and spam-articles spam-func)
405 (mapc spam-func spam-articles)))) ; we use mapc because unlike
406 ; mapcar it discards the
410 (defalias 'spam-point-at-eol (if (fboundp 'point-at-eol)
412 'line-end-position)))
414 (defun spam-get-article-as-string (article)
415 (let ((article-string))
416 (when (numberp article)
417 (save-window-excursion
418 (gnus-summary-goto-subject article)
419 (gnus-summary-show-article t)
420 (set-buffer gnus-article-buffer)
421 (setq article-string (buffer-string))))
424 (defun spam-fetch-field-from-fast (article)
425 "Fetch the `from' field quickly, using the internal gnus-data-list function"
426 (if (and (numberp article)
427 (assoc article (gnus-data-list nil)))
428 (mail-header-from (gnus-data-header (assoc article (gnus-data-list nil))))
431 (defun spam-fetch-field-subject-fast (article)
432 "Fetch the `subject' field quickly, using the internal gnus-data-list function"
433 (if (and (numberp article)
434 (assoc article (gnus-data-list nil)))
435 (mail-header-subject (gnus-data-header (assoc article (gnus-data-list nil))))
439 ;;;; Spam determination.
441 (defvar spam-list-of-checks
442 '((spam-use-blacklist . spam-check-blacklist)
443 (spam-use-whitelist . spam-check-whitelist)
444 (spam-use-BBDB . spam-check-BBDB)
445 (spam-use-ifile . spam-check-ifile)
446 (spam-use-stat . spam-check-stat)
447 (spam-use-blackholes . spam-check-blackholes)
448 (spam-use-bogofilter-headers . spam-check-bogofilter-headers)
449 (spam-use-bogofilter . spam-check-bogofilter))
450 "The spam-list-of-checks list contains pairs associating a parameter
451 variable with a spam checking function. If the parameter variable is
452 true, then the checking function is called, and its value decides what
453 happens. Each individual check may return `nil', `t', or a mailgroup
454 name. The value `nil' means that the check does not yield a decision,
455 and so, that further checks are needed. The value `t' means that the
456 message is definitely not spam, and that further spam checks should be
457 inhibited. Otherwise, a mailgroup name is returned where the mail
458 should go, and further checks are also inhibited. The usual mailgroup
459 name is the value of `spam-split-group', meaning that the message is
463 "Split this message into the `spam' group if it is spam.
464 This function can be used as an entry in `nnmail-split-fancy', for
465 example like this: (: spam-split)
467 See the Info node `(gnus)Fancy Mail Splitting' for more details."
470 ;; load the spam-stat tables if needed
471 (when spam-use-stat (spam-stat-load))
473 (let ((list-of-checks spam-list-of-checks)
475 (while (and list-of-checks (not decision))
476 (let ((pair (pop list-of-checks)))
477 (when (symbol-value (car pair))
478 (setq decision (funcall (cdr pair))))))
485 (defun spam-check-blackholes ()
486 "Check the Received headers for blackholed relays."
487 (let ((headers (message-fetch-field "received"))
492 (goto-char (point-min))
493 (while (re-search-forward
494 "\\[\\([0-9]+.[0-9]+.[0-9]+.[0-9]+\\)\\]" nil t)
495 (message "Blackhole search found host IP %s." (match-string 1))
496 (push (mapconcat 'identity
497 (nreverse (split-string (match-string 1) "\\."))
500 (dolist (server spam-blackhole-servers)
502 (let ((query-string (concat ip "." server)))
504 (let ((query-result (query-dig query-string)))
506 (message "spam: positive blackhole check '%s'" query-result)
507 (push (list ip server query-result)
509 ;; else, if not using dig.el
510 (when (query-dns query-string)
511 (push (list ip server (query-dns query-string 'TXT))
518 ;;; original idea for spam-check-BBDB from Alexander Kotelnikov
519 ;;; <sacha@giotto.sj.ru>
521 ;; all this is done inside a condition-case to trap errors
528 (defun spam-enter-ham-BBDB (from)
529 "Enter an address into the BBDB; implies ham (non-spam) sender"
531 (let* ((parsed-address (gnus-extract-address-components from))
532 (name (or (car parsed-address) "Ham Sender"))
533 (net-address (car (cdr parsed-address))))
534 (message "Adding address %s to BBDB" from)
535 (when (and net-address
536 (not (bbdb-search-simple nil net-address)))
537 (bbdb-create-internal name nil net-address nil nil
538 "ham sender added by spam.el")))))
540 (defun spam-BBDB-register-routine ()
541 (spam-generic-register-routine
546 (spam-enter-ham-BBDB (spam-fetch-field-from-fast article)))))
548 (defun spam-check-BBDB ()
549 "Mail from people in the BBDB is never considered spam"
550 (let ((who (message-fetch-field "from")))
552 (setq who (regexp-quote (cadr
553 (gnus-extract-address-components who))))
554 (if (bbdb-search-simple nil who)
555 nil spam-split-group)))))
558 (defalias 'bbdb-search-simple 'ignore)
559 (defalias 'spam-check-BBDB 'ignore)
560 (defalias 'spam-BBDB-register-routine 'ignore)
561 (defalias 'spam-enter-ham-BBDB 'ignore)
562 (defalias 'bbdb-create-internal 'ignore)
563 (defalias 'bbdb-records 'ignore))))
568 ;;; check the ifile backend; return nil if the mail was NOT classified
571 (defun spam-get-ifile-database-parameter ()
572 "Get the command-line parameter for ifile's database from spam-ifile-database-path."
573 (if spam-ifile-database-path
574 (format "--db-file=%s" spam-ifile-database-path)
577 (defun spam-check-ifile ()
578 "Check the ifile backend for the classification of this message"
579 (let ((article-buffer-name (buffer-name))
582 (let ((temp-buffer-name (buffer-name))
583 (db-param (spam-get-ifile-database-parameter)))
585 (set-buffer article-buffer-name)
587 (call-process-region (point-min) (point-max) spam-ifile-path
588 nil temp-buffer-name nil "-q" "-c" db-param)
589 (call-process-region (point-min) (point-max) spam-ifile-path
590 nil temp-buffer-name nil "-q" "-c")))
591 (goto-char (point-min))
593 (setq category (buffer-substring (point) (spam-point-at-eol))))
594 (when (not (zerop (length category))) ; we need a category here
595 (if spam-ifile-all-categories
596 (setq return category)
597 ;; else, if spam-ifile-all-categories is not set...
598 (when (string-equal spam-ifile-spam-category category)
599 (setq return spam-split-group))))))
602 (defun spam-ifile-register-with-ifile (article-string category)
603 "Register an article, given as a string, with a category.
604 Uses `gnus-newsgroup-name' if category is nil (for ham registration)."
605 (when (stringp article-string)
606 (let ((category (or category gnus-newsgroup-name))
607 (db-param (spam-get-ifile-database-parameter)))
609 (insert-string article-string)
611 (call-process-region (point-min) (point-max) spam-ifile-path
613 "-h" "-i" category db-param)
614 (call-process-region (point-min) (point-max) spam-ifile-path
616 "-h" "-i" category))))))
618 (defun spam-ifile-register-spam-routine ()
619 (spam-generic-register-routine
621 (spam-ifile-register-with-ifile
622 (spam-get-article-as-string article) spam-ifile-spam-category))
625 (defun spam-ifile-register-ham-routine ()
626 (spam-generic-register-routine
629 (spam-ifile-register-with-ifile
630 (spam-get-article-as-string article) nil))))
637 (let ((spam-stat-install-hooks nil))
638 (require 'spam-stat))
640 (defun spam-check-stat ()
641 "Check the spam-stat backend for the classification of this message"
642 (let ((spam-stat-split-fancy-spam-group spam-split-group) ; override
643 (spam-stat-buffer (buffer-name)) ; stat the current buffer
645 (spam-stat-split-fancy)))
647 (defun spam-stat-register-spam-routine ()
648 (spam-generic-register-routine
650 (let ((article-string (spam-get-article-as-string article)))
652 (insert-string article-string)
653 (spam-stat-buffer-is-spam))))
657 (defun spam-stat-register-ham-routine ()
658 (spam-generic-register-routine
661 (let ((article-string (spam-get-article-as-string article)))
663 (insert-string article-string)
664 (spam-stat-buffer-is-non-spam)))))
668 (defalias 'spam-stat-register-ham-routine 'ignore)
669 (defalias 'spam-stat-register-spam-routine 'ignore)
670 (defalias 'spam-stat-buffer-is-spam 'ignore)
671 (defalias 'spam-stat-buffer-is-non-spam 'ignore)
672 (defalias 'spam-stat-split-fancy 'ignore)
673 (defalias 'spam-stat-load 'ignore)
674 (defalias 'spam-stat-save 'ignore)
675 (defalias 'spam-check-stat 'ignore))))
679 ;;;; Blacklists and whitelists.
681 (defvar spam-whitelist-cache nil)
682 (defvar spam-blacklist-cache nil)
684 (defun spam-enter-whitelist (address)
685 "Enter ADDRESS into the whitelist."
686 (interactive "sAddress: ")
687 (spam-enter-list address spam-whitelist)
688 (setq spam-whitelist-cache nil))
690 (defun spam-enter-blacklist (address)
691 "Enter ADDRESS into the blacklist."
692 (interactive "sAddress: ")
693 (spam-enter-list address spam-blacklist)
694 (setq spam-blacklist-cache nil))
696 (defun spam-enter-list (address file)
697 "Enter ADDRESS into the given FILE, either the whitelist or the blacklist."
698 (unless (file-exists-p (file-name-directory file))
699 (make-directory (file-name-directory file) t))
702 (find-file-noselect file))
703 (goto-char (point-max))
706 (insert address "\n")
709 ;;; returns nil if the sender is in the whitelist, spam-split-group otherwise
710 (defun spam-check-whitelist ()
711 ;; FIXME! Should it detect when file timestamps change?
712 (unless spam-whitelist-cache
713 (setq spam-whitelist-cache (spam-parse-list spam-whitelist)))
714 (if (spam-from-listed-p spam-whitelist-cache) nil spam-split-group))
716 (defun spam-check-blacklist ()
717 ;; FIXME! Should it detect when file timestamps change?
718 (unless spam-blacklist-cache
719 (setq spam-blacklist-cache (spam-parse-list spam-blacklist)))
720 (and (spam-from-listed-p spam-blacklist-cache) spam-split-group))
722 (defun spam-parse-list (file)
723 (when (file-readable-p file)
724 (let (contents address)
726 (insert-file-contents file)
728 (setq address (buffer-substring (point) (spam-point-at-eol)))
730 (unless (zerop (length address))
731 (setq address (regexp-quote address))
732 (while (string-match "\\\\\\*" address)
733 (setq address (replace-match ".*" t t address)))
734 (push address contents))))
735 (nreverse contents))))
737 (defun spam-from-listed-p (cache)
738 (let ((from (message-fetch-field "from"))
741 (when (string-match (pop cache) from)
746 (defun spam-blacklist-register-routine ()
747 (spam-generic-register-routine
750 (let ((from (spam-fetch-field-from-fast article)))
752 (spam-enter-blacklist from))))
756 (defun spam-whitelist-register-routine ()
757 (spam-generic-register-routine
762 (let ((from (spam-fetch-field-from-fast article)))
764 (spam-enter-whitelist from))))))
769 (defun spam-check-bogofilter-headers (&optional score)
770 (let ((header (message-fetch-field spam-bogofilter-header)))
772 (string-match "^Yes" header))
774 (when (string-match "spamicity=\\([0-9.]+\\)" header)
775 (match-string 1 header))
779 ;; return something sensible if the score can't be determined
780 (defun spam-bogofilter-score ()
781 (or (spam-check-bogofilter t)
784 (defun spam-check-bogofilter (&optional score)
785 "Check the Bogofilter backend for the classification of this message"
786 (let ((article-buffer-name (buffer-name))
789 (let ((temp-buffer-name (buffer-name)))
791 (set-buffer article-buffer-name)
792 (if spam-bogofilter-database-directory
793 (call-process-region (point-min) (point-max)
795 nil temp-buffer-name nil "-v"
796 "-d" spam-bogofilter-database-directory)
797 (call-process-region (point-min) (point-max) spam-bogofilter-path
798 nil temp-buffer-name nil "-v")))
799 (setq return (spam-check-bogofilter-headers score))))
802 (defun spam-bogofilter-register-with-bogofilter (article-string spam)
803 "Register an article, given as a string, as spam or non-spam."
804 (when (stringp article-string)
805 (let ((switch (if spam "-s" "-n")))
807 (insert-string article-string)
808 (if spam-bogofilter-database-directory
809 (call-process-region (point-min) (point-max)
811 nil nil nil "-v" switch
812 "-d" spam-bogofilter-database-directory)
813 (call-process-region (point-min) (point-max) spam-bogofilter-path
814 nil nil nil "-v" switch))))))
816 (defun spam-bogofilter-register-spam-routine ()
817 (spam-generic-register-routine
819 (spam-bogofilter-register-with-bogofilter
820 (spam-get-article-as-string article) t))
823 (defun spam-bogofilter-register-ham-routine ()
824 (spam-generic-register-routine
827 (spam-bogofilter-register-with-bogofilter
828 (spam-get-article-as-string article) nil))))
832 ;;; spam.el ends here.