;;; mm-encode.el --- Functions for encoding MIME things
;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
(eval-when-compile (require 'cl))
(require 'mail-parse)
(require 'mailcap)
-(eval-and-compile
- (autoload 'mm-body-7-or-8 "mm-bodies")
- (autoload 'mm-long-lines-p "mm-bodies"))
+(autoload 'mm-body-7-or-8 "mm-bodies")
+(autoload 'mm-long-lines-p "mm-bodies")
(defcustom mm-content-transfer-encoding-defaults
'(("text/x-patch" 8bit)
"application/octet-stream"
(mailcap-extension-to-mime (match-string 0 file))))
-(defun mm-safer-encoding (encoding)
+(defun mm-safer-encoding (encoding &optional type)
"Return an encoding similar to ENCODING but safer than it."
(cond
((eq encoding '7bit) '7bit) ;; 7bit is considered safe.
- ((memq encoding '(8bit quoted-printable)) 'quoted-printable)
+ ((memq encoding '(8bit quoted-printable))
+ ;; According to RFC2046, 5.2.1, RFC822 Subtype, "quoted-printable" is not
+ ;; a valid encoding for message/rfc822:
+ ;; No encoding other than "7bit", "8bit", or "binary" is permitted for the
+ ;; body of a "message/rfc822" entity.
+ (if (string= type "message/rfc822") '8bit 'quoted-printable))
;; The remaining encodings are binary and base64 (and perhaps some
;; non-standard ones), which are both turned into base64.
- (t 'base64)))
+ (t (if (string= type "message/rfc822") 'binary 'base64))))
(defun mm-encode-content-transfer-encoding (encoding &optional type)
"Encode the current buffer with ENCODING for MIME type TYPE.
(mm-qp-or-base64)
(cadr (car rules)))))
(if mm-use-ultra-safe-encoding
- (mm-safer-encoding encoding)
+ (mm-safer-encoding encoding type)
encoding))))
(pop rules)))))