spam-wash.el 2.2 KB

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