annotate lisp/gnus/mm-bodies.el @ 51399:c2c7a2898903

Use HAVE_SYS_RESOURCE_H, HAVE_SYS_VLIMIT_H.
author Dave Love <fx@gnu.org>
date Mon, 02 Jun 2003 18:39:39 +0000
parents bce2c13027f2
children 695cf19ef79e d7ddb3e565de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38413
a26d9b55abb6 Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents: 33343
diff changeset
1 ;;; mm-bodies.el --- functions for decoding MIME things
47948
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
2 ;; Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; This file is part of GNU Emacs.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; any later version.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is distributed in the hope that it will be useful,
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; GNU General Public License for more details.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; Boston, MA 02111-1307, USA.
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 (eval-and-compile
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 (or (fboundp 'base64-decode-region)
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
29 (require 'base64)))
32409
9373d6d073ed Don't require `mm-uu' at compile-time; it leads
Gerd Moellmann <gerd@gnu.org>
parents: 32209
diff changeset
30
32628
0b11e5c822d5 (mm-uu-decode-function)
Dave Love <fx@gnu.org>
parents: 32409
diff changeset
31 (eval-when-compile
0b11e5c822d5 (mm-uu-decode-function)
Dave Love <fx@gnu.org>
parents: 32409
diff changeset
32 (defvar mm-uu-decode-function)
0b11e5c822d5 (mm-uu-decode-function)
Dave Love <fx@gnu.org>
parents: 32409
diff changeset
33 (defvar mm-uu-binhex-decode-function))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 (require 'mm-util)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 (require 'rfc2047)
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
37 (require 'mm-encode)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; 8bit treatment gets any char except: 0x32 - 0x7f, CR, LF, TAB, BEL,
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; BS, vertical TAB, form feed, and ^_
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 (defvar mm-7bit-chars "\x20-\x7f\r\n\t\x7\x8\xb\xc\x1f")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 (defcustom mm-body-charset-encoding-alist
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 '((iso-2022-jp . 7bit)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 (iso-2022-jp-2 . 7bit))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 "Alist of MIME charsets to encodings.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 Valid encodings are `7bit', `8bit', `quoted-printable' and `base64'."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 :type '(repeat (cons (symbol :tag "charset")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 (choice :tag "encoding"
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 (const 7bit)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 (const 8bit)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 (const quoted-printable)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 (const base64))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 :group 'mime)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 (defun mm-encode-body ()
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 "Encode a body.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 Should be called narrowed to the body that is to be encoded.
47948
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
59 If there is more than one non-ASCII Mule charset, then the list of found
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
60 Mule charsets is returned.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 If successful, the MIME charset is returned.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 If no encoding was done, nil is returned."
33343
074ad4abf8e0 (mm-encode-body): Use mm-multibyte-p, don't just
Dave Love <fx@gnu.org>
parents: 32628
diff changeset
63 (if (not (mm-multibyte-p))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;; In the non-Mule case, we search for non-ASCII chars and
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;; return the value of `mail-parse-charset' if any are found.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 (save-excursion
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 (goto-char (point-min))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 (if (re-search-forward "[^\x0-\x7f]" nil t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 (or mail-parse-charset
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 (mm-read-charset "Charset used in the article: "))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;; The logic in `mml-generate-mime-1' confirms that it's OK
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 ;; to return nil here.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 nil))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 (save-excursion
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 (goto-char (point-min))
47948
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
76 (let ((charsets (mm-find-mime-charset-region (point-min) (point-max))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 (cond
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;; No encoding.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ((null charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 ;; Too many charsets.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 ((> (length charsets) 1)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ;; We encode.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 (t
47948
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
86 (mm-encode-coding-region (point-min) (point-max)
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
87 (mm-charset-to-coding-system
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
88 (car charsets)))
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
89 (car charsets)))))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
91 (eval-when-compile (defvar message-posting-charset))
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
92
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 (defun mm-body-encoding (charset &optional encoding)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 "Do Content-Transfer-Encoding and return the encoding of the current buffer."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 (let ((bits (mm-body-7-or-8)))
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
96 (require 'message)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 (cond
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 ((and (not mm-use-ultra-safe-encoding) (eq bits '7bit))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 bits)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 ((and (not mm-use-ultra-safe-encoding)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (or (eq t (cdr message-posting-charset))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 (memq charset (cdr message-posting-charset))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 (eq charset mail-parse-charset)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 bits)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 (t
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 (let ((encoding (or encoding
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 (cdr (assq charset mm-body-charset-encoding-alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 (mm-qp-or-base64))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 (when mm-use-ultra-safe-encoding
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 (setq encoding (mm-safer-encoding encoding)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 (mm-encode-content-transfer-encoding encoding "text/plain")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 encoding)))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 (defun mm-body-7-or-8 ()
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 "Say whether the body is 7bit or 8bit."
47948
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
116 (if (save-excursion
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
117 (goto-char (point-min))
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
118 (skip-chars-forward mm-7bit-chars)
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
119 (eobp))
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
120 '7bit
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
121 '8bit))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 ;;;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 ;;; Functions for decoding
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 ;;;
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (defun mm-decode-content-transfer-encoding (encoding &optional type)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 (prog1
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (condition-case error
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (cond
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 ((eq encoding 'quoted-printable)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 (quoted-printable-decode-region (point-min) (point-max)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 ((eq encoding 'base64)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (base64-decode-region
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (point-min)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 ;; Some mailers insert whitespace
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 ;; junk at the end which
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 ;; base64-decode-region dislikes.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 ;; Also remove possible junk which could
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 ;; have been added by mailing list software.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (save-excursion
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 (goto-char (point-min))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (while (re-search-forward "^[\t ]*\r?\n" nil t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (delete-region (match-beginning 0) (match-end 0)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (goto-char (point-max))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (when (re-search-backward "^[A-Za-z0-9+/]+=*[\t ]*$" nil t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (forward-line)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (delete-region (point) (point-max)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 (point-max))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 ((memq encoding '(7bit 8bit binary))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 ;; Do nothing.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 )
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 ((null encoding)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 ;; Do nothing.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 )
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 ((memq encoding '(x-uuencode x-uue))
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
157 (require 'mm-uu)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 (funcall mm-uu-decode-function (point-min) (point-max)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 ((eq encoding 'x-binhex)
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
160 (require 'mm-uu)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 (funcall mm-uu-binhex-decode-function (point-min) (point-max)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 ((functionp encoding)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 (funcall encoding (point-min) (point-max)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 (t
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 (message "Unknown encoding %s; defaulting to 8bit" encoding)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (error
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 (message "Error while decoding: %s" error)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 nil))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (when (and
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (memq encoding '(base64 x-uuencode x-uue x-binhex))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (equal type "text/plain"))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (goto-char (point-min))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (while (search-forward "\r\n" nil t)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (replace-match "\n" t t)))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 (defun mm-decode-body (charset &optional encoding type)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 "Decode the current article that has been encoded with ENCODING.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 The characters in CHARSET should then be decoded."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 (if (stringp charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 (setq charset (intern (downcase charset))))
47948
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
181 (if (or (not charset)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (eq 'gnus-all mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (memq 'gnus-all mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 (memq charset mail-parse-ignored-charsets))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 (setq charset mail-parse-charset))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 (save-excursion
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 (when encoding
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 (mm-decode-content-transfer-encoding encoding type))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (when (featurep 'mule)
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
190 (let ((coding-system (mm-charset-to-coding-system charset)))
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
191 (if (and (not coding-system)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (listp mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (memq 'gnus-unknown mail-parse-ignored-charsets))
47948
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
194 (setq coding-system
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 (mm-charset-to-coding-system mail-parse-charset)))
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
196 (when (and charset coding-system
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 ;; buffer-file-coding-system
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 ;;Article buffer is nil coding system
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 ;;in XEmacs
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 (mm-multibyte-p)
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
201 (or (not (eq coding-system 'ascii))
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
202 (setq coding-system mail-parse-charset))
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
203 (not (eq coding-system 'gnus-decoded)))
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
204 (mm-decode-coding-region (point-min) (point-max) coding-system))))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 (defun mm-decode-string (string charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 "Decode STRING with CHARSET."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (when (stringp charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 (setq charset (intern (downcase charset))))
47948
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
210 (when (or (not charset)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (eq 'gnus-all mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 (memq 'gnus-all mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 (memq charset mail-parse-ignored-charsets))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 (setq charset mail-parse-charset))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 (or
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 (when (featurep 'mule)
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
217 (let ((coding-system (mm-charset-to-coding-system charset)))
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
218 (if (and (not coding-system)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (listp mail-parse-ignored-charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (memq 'gnus-unknown mail-parse-ignored-charsets))
47948
bce2c13027f2 (mm-body-7-or-8): Don't special-case Mule.
Dave Love <fx@gnu.org>
parents: 38413
diff changeset
221 (setq coding-system
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (mm-charset-to-coding-system mail-parse-charset)))
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
223 (when (and charset coding-system
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (mm-multibyte-p)
32209
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
225 (or (not (eq coding-system 'ascii))
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
226 (setq coding-system mail-parse-charset)))
cbbde5b20af5 Require mm-uu, Don't require qp, uudecode.
Dave Love <fx@gnu.org>
parents: 31717
diff changeset
227 (mm-decode-coding-string string coding-system))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 string))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (provide 'mm-bodies)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231
38413
a26d9b55abb6 Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents: 33343
diff changeset
232 ;;; mm-bodies.el ends here