1 ;;; spam-wash.el --- wash spam before analysis
3 ;; Copyright (C) 2004 Free Software Foundation, Inc.
5 ;; Author: Andrew Cohen <cohen@andy.bu.edu>
8 ;; This file is part of GNU Emacs.
10 ;; This is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This is distributed in the hope that it will be useful, but WITHOUT
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18 ;; License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This library decodes MIME encodings such as base64 and
28 ;; quoted-printable to allow for better spam analysis.
30 ;; `spam-wash' should be called in a buffer containing the message.
37 "Treat the current buffer prior to spam analysis."
39 (run-hooks 'gnus-article-decode-hook)
42 (let* ((buffer-read-only nil)
43 (gnus-inhibit-treatment t)
44 (gnus-article-buffer (current-buffer))
45 (handles (or (mm-dissect-buffer nil gnus-article-loose-mime)
46 (and gnus-article-emulate-mime
49 (when gnus-article-mime-handles
50 (mm-destroy-parts gnus-article-mime-handles)
51 (setq gnus-article-mime-handle-alist nil))
52 (setq gnus-article-mime-handles handles)
54 (or (not (stringp (car handles)))
57 (delete-region (point) (point-max))
58 (spam-treat-parts handles))))))
60 (defun spam-treat-parts (handle)
61 (if (stringp (car handle))
62 (mapcar 'spam-treat-parts (cdr handle))
63 (if (bufferp (car handle))
65 (narrow-to-region (point) (point))
66 (when (let ((case-fold-search t))
67 (string-match "text" (car (mm-handle-type handle))))
68 (mm-insert-part handle))
69 (goto-char (point-max)))
70 (mapcar 'spam-treat-parts handle))))
74 ;;; spam-wash.el ends here