1 ;;; mm-bodies.el --- Functions for decoding MIME things
2 ;; Copyright (C) 1998 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
28 (if (not (fboundp 'base64-encode-string))
33 (defun mm-encode-body ()
35 Should be called narrowed to the body that is to be encoded.
36 If there is more than one non-ASCII MULE charset, then list of found
37 MULE charsets are returned.
38 If successful, the MIME charset is returned.
39 If no encoding was done, nil is returned."
41 (goto-char (point-min))
43 (delq 'ascii (find-charset-region (point-min) (point-max))))
50 ((> (length charsets) 1)
54 (let ((mime-charset (mm-mule-charset-to-mime-charset (car charsets)))
58 (not (mm-coding-system-equal
59 mime-charset buffer-file-coding-system)))
61 (if (eq (char-charset (following-char)) 'ascii)
63 (mm-encode-coding-region start (point) mime-charset)
66 (setq start (point))))
69 (mm-encode-coding-region start (point) mime-charset)
73 (defun mm-body-encoding ()
74 "Return the encoding of the current buffer."
76 (null (delq 'ascii (find-charset-region (point-min) (point-max))))
77 ;;;!!!The following is necessary because the function
78 ;;;!!!above seems to return the wrong result under Emacs 20.3.
81 (goto-char (point-min))
82 (skip-chars-forward "\0-\177")
88 ;;; Functions for decoding
91 (defun mm-decode-body (charset encoding)
92 "Decode the current article that has been encoded with ENCODING.
93 The characters in CHARSET should then be decoded."
94 (setq charset (or charset rfc2047-default-charset))
98 ((eq encoding 'quoted-printable)
99 (quoted-printable-decode-region (point-min) (point-max)))
100 ((eq encoding 'base64)
102 (base64-decode-region (point-min) (point-max))
104 ((memq encoding '(7bit 8bit binary))
109 (error "Can't decode encoding %s" encoding))))
110 (when (featurep 'mule)
113 (setq mule-charset (mm-charset-to-coding-system charset))
114 buffer-file-coding-system
115 ;;(not (mm-coding-system-equal
116 ;; buffer-file-coding-system mule-charset))
118 (mm-decode-coding-region (point-min) (point-max) mule-charset))))))
122 ;; mm-bodies.el ends here