File name fix, for AUTHORS.
[emacs.git] / lisp / gnus / spam-wash.el
blobbbcbf67c0bb034987de9ef4c550bd4c6645f0cfe
1 ;;; spam-wash.el --- wash spam before analysis
3 ;; Copyright (C) 2004, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Andrew Cohen <cohen@andy.bu.edu>
6 ;; Keywords: mail
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; This library decodes MIME encodings such as base64 and
26 ;; quoted-printable to allow for better spam analysis.
28 ;; `spam-wash' should be called in a buffer containing the message.
30 ;;; Code:
32 (require 'gnus-art)
34 (defun spam-wash ()
35 "Treat the current buffer prior to spam analysis."
36 (interactive)
37 (run-hooks 'gnus-article-decode-hook)
38 (save-excursion
39 (save-restriction
40 (let* ((buffer-read-only nil)
41 (gnus-inhibit-treatment t)
42 (gnus-article-buffer (current-buffer))
43 (handles (or (mm-dissect-buffer nil gnus-article-loose-mime)
44 (and gnus-article-emulate-mime
45 (mm-uu-dissect))))
46 handle)
47 (when gnus-article-mime-handles
48 (mm-destroy-parts gnus-article-mime-handles)
49 (setq gnus-article-mime-handle-alist nil))
50 (setq gnus-article-mime-handles handles)
51 (when (and handles
52 (or (not (stringp (car handles)))
53 (cdr handles)))
54 (article-goto-body)
55 (delete-region (point) (point-max))
56 (spam-treat-parts handles))))))
58 (defun spam-treat-parts (handle)
59 (if (stringp (car handle))
60 (mapcar 'spam-treat-parts (cdr handle))
61 (if (bufferp (car handle))
62 (save-restriction
63 (narrow-to-region (point) (point))
64 (when (let ((case-fold-search t))
65 (string-match "text" (car (mm-handle-type handle))))
66 (mm-insert-part handle))
67 (goto-char (point-max)))
68 (mapcar 'spam-treat-parts handle))))
70 (provide 'spam-wash)
72 ;; arch-tag: 3c7f94a7-c96d-4c77-bb59-950df12bc85f
73 ;;; spam-wash.el ends here