Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / gnus / spam-wash.el
CommitLineData
01c52d31
MB
1;;; spam-wash.el --- wash spam before analysis
2
73b0cd50 3;; Copyright (C) 2004, 2007-2011 Free Software Foundation, Inc.
01c52d31
MB
4
5;; Author: Andrew Cohen <cohen@andy.bu.edu>
6;; Keywords: mail
7
8;; This file is part of GNU Emacs.
9
5e809f55 10;; GNU Emacs is free software: you can redistribute it and/or modify
62961127 11;; it under the terms of the GNU General Public License as published by
5e809f55
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
01c52d31 14
62961127
GM
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.
01c52d31
MB
19
20;; You should have received a copy of the GNU General Public License
5e809f55 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
01c52d31
MB
22
23;;; Commentary:
24
25;; This library decodes MIME encodings such as base64 and
26;; quoted-printable to allow for better spam analysis.
27;;
28;; `spam-wash' should be called in a buffer containing the message.
29
30;;; Code:
31
32(require 'gnus-art)
33
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))))))
57
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))))
69
70(provide 'spam-wash)
71
01c52d31 72;;; spam-wash.el ends here