1 ;;; mm-bodies.el --- Functions for decoding MIME things
3 ;; Copyright (C) 1998, 1999, 2000, 2001
4 ;; Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
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 2, or (at your option)
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; 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.
30 (or (fboundp 'base64-decode-region)
34 (defvar mm-uu-decode-function)
35 (defvar mm-uu-binhex-decode-function))
41 ;; 8bit treatment gets any char except: 0x32 - 0x7f, CR, LF, TAB, BEL,
42 ;; BS, vertical TAB, form feed, and ^_
43 (defvar mm-7bit-chars "\x20-\x7f\r\n\t\x7\x8\xb\xc\x1f")
45 (defcustom mm-body-charset-encoding-alist
46 '((iso-2022-jp . 7bit)
47 (iso-2022-jp-2 . 7bit))
48 "Alist of MIME charsets to encodings.
49 Valid encodings are `7bit', `8bit', `quoted-printable' and `base64'."
50 :type '(repeat (cons (symbol :tag "charset")
51 (choice :tag "encoding"
54 (const quoted-printable)
58 (defun mm-encode-body (&optional charset)
60 Should be called narrowed to the body that is to be encoded.
61 If there is more than one non-ASCII MULE charset, then list of found
62 MULE charsets are returned.
63 If CHARSET is non-nil, it is used.
64 If successful, the MIME charset is returned.
65 If no encoding was done, nil is returned."
66 (if (not (mm-multibyte-p))
67 ;; In the non-Mule case, we search for non-ASCII chars and
68 ;; return the value of `mail-parse-charset' if any are found.
71 (goto-char (point-min))
72 (if (re-search-forward "[^\x0-\x7f]" nil t)
73 (or mail-parse-charset
74 (message-options-get 'mm-encody-body-charset)
76 'mm-encody-body-charset
77 (mm-read-charset "Charset used in the article: ")))
78 ;; The logic in `mml-generate-mime-1' confirms that it's OK
79 ;; to return nil here.
84 (mm-encode-coding-region (point-min) (point-max) charset)
86 (goto-char (point-min))
87 (let ((charsets (mm-find-mime-charset-region (point-min) (point-max)
95 ((> (length charsets) 1)
99 (setq charset (car charsets))
101 (if (eq (mm-charset-after) 'ascii)
104 (narrow-to-region start (point))
105 (mm-encode-coding-region
106 start (point) (mm-charset-to-coding-system charset))
107 (goto-char (point-max)))
110 (setq start (point))))