annotate lisp/gnus/mm-encode.el @ 111096:d7e691f6ffc0

Merge changes made in Gnus trunk. gnus.texi (Subscription Commands): Mention that you can also subscribe to new groups via the Server buffer, which is probably more convenient when subscribing to many groups. gnus-group.el (gnus-group-mark-group): Use gnus-group-position-point instead of the summary one. shr.el (shr-tag-img): Don't bug out on images that don't have a SRC.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Sat, 23 Oct 2010 00:01:49 +0000
parents 42815c76b976
children 417b1e4d63cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
1 ;;; mm-encode.el --- Functions for encoding MIME things
64754
fafd692d1e40 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
2
fafd692d1e40 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106562
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94369
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94369
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94369
diff changeset
13 ;; (at your option) any later version.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94369
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94369
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;;; Code:
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
32223
1d234b7994c8 Require CL. At least, for `incf'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31717
diff changeset
27 (eval-when-compile (require 'cl))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 (require 'mail-parse)
107427
ecbe0edc4f69 Stop message.el from loading about 40 libraries it doesn't always need.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
29 (autoload 'mailcap-extension-to-mime "mailcap")
95820
645fb33380d6 Remove unnecessary eval-and-compile of autoloads.
Glenn Morris <rgm@gnu.org>
parents: 94662
diff changeset
30 (autoload 'mm-body-7-or-8 "mm-bodies")
645fb33380d6 Remove unnecessary eval-and-compile of autoloads.
Glenn Morris <rgm@gnu.org>
parents: 94662
diff changeset
31 (autoload 'mm-long-lines-p "mm-bodies")
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
33 (defcustom mm-content-transfer-encoding-defaults
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 '(("text/x-patch" 8bit)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ("text/.*" qp-or-base64)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ("message/rfc822" 8bit)
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
37 ("application/emacs-lisp" qp-or-base64)
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
38 ("application/x-emacs-lisp" qp-or-base64)
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
39 ("application/x-patch" qp-or-base64)
43420
33c54ecf6602 * mm-encode.el (mm-content-transfer-encoding-defaults): Set
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 38413
diff changeset
40 (".*" base64))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 "Alist of regexps that match MIME types and their encodings.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 If the encoding is `qp-or-base64', then either quoted-printable
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
43 or base64 will be used, depending on what is more efficient.
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
44
110689
42815c76b976 Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110102
diff changeset
45 This list is only consulted when encoding MIME parts in the
42815c76b976 Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110102
diff changeset
46 bodies -- not for the regular non-MIME-ish messages."
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
47 :type '(repeat (list (regexp :tag "MIME type")
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
48 (choice :tag "encoding"
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
49 (const 7bit)
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
50 (const 8bit)
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
51 (const qp-or-base64)
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
52 (const quoted-printable)
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
53 (const base64))))
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
54 :group 'mime)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55
105253
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
56 (defcustom mm-sign-option nil
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
57 "Option how to create signed parts.
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
58 nil, use the default keys without asking;
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
59 `guided', let you select signing keys from the menu."
106562
0d89cb5de442 (mm-sign-option, mm-encrypt-option): Add :version tag.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 105253
diff changeset
60 :version "23.2" ;; No Gnus 0.12
105253
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
61 :type '(choice (item guided)
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
62 (item :tag "default" nil))
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
63 :group 'mime-security)
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
64
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
65 (defcustom mm-encrypt-option nil
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
66 "Option how to create encrypted parts.
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
67 nil, use the default keys without asking;
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
68 `guided', let you select recipients' keys from the menu."
106562
0d89cb5de442 (mm-sign-option, mm-encrypt-option): Add :version tag.
Reiner Steib <Reiner.Steib@gmx.de>
parents: 105253
diff changeset
69 :version "23.2" ;; No Gnus 0.12
105253
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
70 :type '(choice (item guided)
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
71 (item :tag "default" nil))
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
72 :group 'mime-security)
baa4e6ac9e46 Synch with Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 104889
diff changeset
73
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 (defvar mm-use-ultra-safe-encoding nil
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 "If non-nil, use encodings aimed at Procrustean bed survival.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 This means that textual parts are encoded as quoted-printable if they
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 contain lines longer than 76 characters or starting with \"From \" in
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 the body. Non-7bit encodings (8bit, binary) are generally disallowed.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 This is to reduce the probability that a broken MTA or MDA changes the
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 message.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 This variable should never be set directly, but bound before a call to
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 `mml-generate-mime' or similar functions.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 (defun mm-insert-rfc822-headers (charset encoding)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 "Insert text/plain headers with CHARSET and ENCODING."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 (insert "MIME-Version: 1.0\n")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 (insert "Content-Type: text/plain; charset="
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 (mail-quote-string (downcase (symbol-name charset))) "\n")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 (insert "Content-Transfer-Encoding: "
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 (downcase (symbol-name encoding)) "\n"))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 (defun mm-insert-multipart-headers ()
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 "Insert multipart/mixed headers."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 (let ((boundary "=-=-="))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 (insert "MIME-Version: 1.0\n")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 (insert "Content-Type: multipart/mixed; boundary=\"" boundary "\"\n")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 boundary))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (defun mm-default-file-encoding (file)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 "Return a default encoding for FILE."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 (if (not (string-match "\\.[^.]+$" file))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 "application/octet-stream"
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 (mailcap-extension-to-mime (match-string 0 file))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93975
diff changeset
107 (defun mm-safer-encoding (encoding &optional type)
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
108 "Return an encoding similar to ENCODING but safer than it."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 (cond
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
110 ((eq encoding '7bit) '7bit) ;; 7bit is considered safe.
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93975
diff changeset
111 ((memq encoding '(8bit quoted-printable))
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93975
diff changeset
112 ;; According to RFC2046, 5.2.1, RFC822 Subtype, "quoted-printable" is not
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93975
diff changeset
113 ;; a valid encoding for message/rfc822:
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93975
diff changeset
114 ;; No encoding other than "7bit", "8bit", or "binary" is permitted for the
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93975
diff changeset
115 ;; body of a "message/rfc822" entity.
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93975
diff changeset
116 (if (string= type "message/rfc822") '8bit 'quoted-printable))
48588
ShengHuo ZHU <zsh@cs.rochester.edu>
parents: 43420
diff changeset
117 ;; The remaining encodings are binary and base64 (and perhaps some
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 ;; non-standard ones), which are both turned into base64.
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93975
diff changeset
119 (t (if (string= type "message/rfc822") 'binary 'base64))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 (defun mm-encode-content-transfer-encoding (encoding &optional type)
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
122 "Encode the current buffer with ENCODING for MIME type TYPE.
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
123 ENCODING can be: nil (do nothing); one of `quoted-printable', `base64';
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
124 `7bit', `8bit' or `binary' (all do nothing); a function to do the encoding."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 (cond
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 ((eq encoding 'quoted-printable)
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
127 ;; This used to try to make a multibyte buffer unibyte. That's
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
128 ;; completely wrong, since you'd get QP-encoded emacs-mule. If
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
129 ;; this gets run on multibyte text it's an error that needs
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
130 ;; fixing, and the encoding function will signal an error.
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
131 ;; Likewise base64 below.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 (quoted-printable-encode-region (point-min) (point-max) t))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 ((eq encoding 'base64)
65342
c71b1b2d2d04 Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-530
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
134 (when (string-match "\\`text/" type)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (goto-char (point-min))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (while (search-forward "\n" nil t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 (replace-match "\r\n" t t)))
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
138 (base64-encode-region (point-min) (point-max)))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 ((memq encoding '(7bit 8bit binary))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 ;; Do nothing.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 )
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 ((null encoding)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 ;; Do nothing.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 )
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
145 ;; Fixme: Ignoring errors here looks bogus.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 ((functionp encoding)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (ignore-errors (funcall encoding (point-min) (point-max))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (t
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
149 (error "Unknown encoding %s" encoding))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150
104889
18c2aea5083c 2009-09-09 Katsumi Yamaoka <yamaoka@jpl.org>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 100908
diff changeset
151 (defun mm-encode-buffer (type &optional encoding)
18c2aea5083c 2009-09-09 Katsumi Yamaoka <yamaoka@jpl.org>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 100908
diff changeset
152 "Encode the buffer which contains data of MIME type TYPE by ENCODING.
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
153 TYPE is a string or a list of the components.
104889
18c2aea5083c 2009-09-09 Katsumi Yamaoka <yamaoka@jpl.org>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 100908
diff changeset
154 The optional ENCODING overrides the encoding determined according to
18c2aea5083c 2009-09-09 Katsumi Yamaoka <yamaoka@jpl.org>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 100908
diff changeset
155 TYPE and `mm-content-transfer-encoding-defaults'.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 The encoding used is returned."
104889
18c2aea5083c 2009-09-09 Katsumi Yamaoka <yamaoka@jpl.org>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 100908
diff changeset
157 (let ((mime-type (if (stringp type) type (car type))))
18c2aea5083c 2009-09-09 Katsumi Yamaoka <yamaoka@jpl.org>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 100908
diff changeset
158 (mm-encode-content-transfer-encoding
18c2aea5083c 2009-09-09 Katsumi Yamaoka <yamaoka@jpl.org>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 100908
diff changeset
159 (or encoding
18c2aea5083c 2009-09-09 Katsumi Yamaoka <yamaoka@jpl.org>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 100908
diff changeset
160 (setq encoding (or (and (listp type)
18c2aea5083c 2009-09-09 Katsumi Yamaoka <yamaoka@jpl.org>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 100908
diff changeset
161 (cadr (assq 'encoding type)))
18c2aea5083c 2009-09-09 Katsumi Yamaoka <yamaoka@jpl.org>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 100908
diff changeset
162 (mm-content-transfer-encoding mime-type))))
18c2aea5083c 2009-09-09 Katsumi Yamaoka <yamaoka@jpl.org>
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 100908
diff changeset
163 mime-type)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 encoding))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (defun mm-insert-headers (type encoding &optional file)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 "Insert headers for TYPE."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 (insert "Content-Type: " type)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (when file
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (insert ";\n\tname=\"" (file-name-nondirectory file) "\""))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (insert "\n")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (insert "Content-Disposition: inline")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (when file
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (insert ";\n\tfilename=\"" (file-name-nondirectory file) "\""))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 (insert "\n")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (insert "\n"))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 (defun mm-content-transfer-encoding (type)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 "Return a CTE suitable for TYPE to encode the current buffer."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 (let ((rules mm-content-transfer-encoding-defaults))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (catch 'found
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (while rules
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 (when (string-match (caar rules) type)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 (throw 'found
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48588
diff changeset
186 (let ((encoding
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 (if (eq (cadr (car rules)) 'qp-or-base64)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 (mm-qp-or-base64)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (cadr (car rules)))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 (if mm-use-ultra-safe-encoding
94369
86c0a3e7c039 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 93975
diff changeset
191 (mm-safer-encoding encoding type)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 encoding))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (pop rules)))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 (defun mm-qp-or-base64 ()
56927
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
196 "Return the type with which to encode the buffer.
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
197 This is either `base64' or `quoted-printable'."
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
198 (if (equal mm-use-ultra-safe-encoding '(sign . "pgp"))
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
199 ;; perhaps not always accurate?
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
200 'quoted-printable
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
201 (save-excursion
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
202 (let ((limit (min (point-max) (+ 2000 (point-min))))
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
203 (n8bit 0))
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
204 (goto-char (point-min))
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
205 (skip-chars-forward "\x20-\x7f\r\n\t" limit)
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
206 (while (< (point) limit)
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
207 (incf n8bit)
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
208 (forward-char 1)
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
209 (skip-chars-forward "\x20-\x7f\r\n\t" limit))
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
210 (if (or (< (* 6 n8bit) (- limit (point-min)))
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
211 ;; Don't base64, say, a short line with a single
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
212 ;; non-ASCII char when splitting parts by charset.
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
213 (= n8bit 1))
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
214 'quoted-printable
55fd4f77387a Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents: 52401
diff changeset
215 'base64)))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (provide 'mm-encode)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 ;;; mm-encode.el ends here