Mercurial > emacs
annotate lisp/gnus/mm-uu.el @ 33133:e3d7bf8b5a51
(Info-insert-dir): Don't include blank lines at beginning of additional
dir files (one is added automatically).
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 02 Nov 2000 01:21:11 +0000 |
parents | 5d37eed2a6e2 |
children | 66b0773e0877 |
rev | line source |
---|---|
33120
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
1 ;;; mm-uu.el -- Return uu stuff as mm handles |
31717 | 2 ;; Copyright (c) 1998, 1999, 2000 Free Software Foundation, Inc. |
3 | |
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu> | |
5 ;; Keywords: postscript uudecode binhex shar forward news | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 ;; | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
23 | |
24 ;;; Commentary: | |
25 | |
26 | |
27 ;;; Code: | |
28 | |
29 (eval-when-compile (require 'cl)) | |
30 (require 'mail-parse) | |
31 (require 'nnheader) | |
32 (require 'mm-decode) | |
33 (require 'mailcap) | |
34 | |
35 (eval-and-compile | |
36 (autoload 'binhex-decode-region "binhex") | |
37 (autoload 'binhex-decode-region-external "binhex") | |
38 (autoload 'uudecode-decode-region "uudecode") | |
39 (autoload 'uudecode-decode-region-external "uudecode")) | |
40 | |
41 (defun mm-uu-copy-to-buffer (from to) | |
42 "Copy the contents of the current buffer to a fresh buffer." | |
43 (save-excursion | |
44 (let ((obuf (current-buffer))) | |
45 (set-buffer (generate-new-buffer " *mm-uu*")) | |
46 (insert-buffer-substring obuf from to) | |
47 (current-buffer)))) | |
48 | |
49 ;;; postscript | |
50 | |
51 (defconst mm-uu-postscript-begin-line "^%!PS-") | |
52 (defconst mm-uu-postscript-end-line "^%%EOF$") | |
53 | |
54 (defconst mm-uu-uu-begin-line "^begin[ \t]+[0-7][0-7][0-7][ \t]+") | |
55 (defconst mm-uu-uu-end-line "^end[ \t]*$") | |
56 | |
57 (defcustom mm-uu-decode-function 'uudecode-decode-region | |
58 "*Function to uudecode. | |
59 Internal function is done in elisp by default, therefore decoding may | |
33120
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
60 appear to be horribly slow. You can make Gnus use the external Unix |
31717 | 61 decoder, such as uudecode." |
33120
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
62 :type '(choice (const :tag "internal" uudecode-decode-region) |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
63 (const :tag "external" uudecode-decode-region-external)) |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
64 :group 'gnus-article-mime) |
31717 | 65 |
66 (defconst mm-uu-binhex-begin-line | |
67 "^:...............................................................$") | |
68 (defconst mm-uu-binhex-end-line ":$") | |
69 | |
70 (defcustom mm-uu-binhex-decode-function 'binhex-decode-region | |
71 "*Function to binhex decode. | |
72 Internal function is done in elisp by default, therefore decoding may | |
33120
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
73 appear to be horribly slow. You can make Gnus use the external Unix |
31717 | 74 decoder, such as hexbin." |
33120
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
75 :type '(choice (const :tag "internal" binhex-decode-region) |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
76 (const :tag "external" binhex-decode-region-external)) |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
77 :group 'gnus-article-mime) |
31717 | 78 |
79 (defconst mm-uu-shar-begin-line "^#! */bin/sh") | |
80 (defconst mm-uu-shar-end-line "^exit 0\\|^$") | |
81 | |
33120
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
82 ;;; Thanks to Edward J. Sabol <sabol@alderaan.gsfc.nasa.gov> and |
31717 | 83 ;;; Peter von der Ah\'e <pahe@daimi.au.dk> |
84 (defconst mm-uu-forward-begin-line "^-+ \\(Start of \\)?Forwarded message") | |
85 (defconst mm-uu-forward-end-line "^-+ End \\(of \\)?forwarded message") | |
86 | |
87 (defvar mm-uu-begin-line nil) | |
88 | |
89 (defconst mm-uu-identifier-alist | |
90 '((?% . postscript) (?b . uu) (?: . binhex) (?# . shar) | |
91 (?- . forward))) | |
92 | |
93 (defvar mm-dissect-disposition "inline" | |
94 "The default disposition of uu parts. | |
95 This can be either \"inline\" or \"attachment\".") | |
96 | |
33120
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
97 (defcustom mm-uu-configure-list nil |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
98 "A list of mm-uu configuration. |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
99 To disable dissecting shar codes, for instance, add |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
100 `(shar . disabled)' to this list." |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
101 :type '(repeat (choice (const :tag "postscript" (postscript . disabled)) |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
102 (const :tag "uu" (uu . disabled)) |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
103 (const :tag "binhax" (binhex . disabled)) |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
104 (const :tag "shar" (shar . disabled)) |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
105 (const :tag "forward" (forward . disabled)))) |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
106 :group 'gnus-article-mime |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
107 :set 'mm-uu-configure) |
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
108 |
31717 | 109 (defun mm-uu-configure-p (key val) |
110 (member (cons key val) mm-uu-configure-list)) | |
111 | |
112 (defun mm-uu-configure (&optional symbol value) | |
113 (if symbol (set-default symbol value)) | |
114 (setq mm-uu-begin-line nil) | |
115 (mapcar '(lambda (type) | |
33120
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
116 (if (mm-uu-configure-p type 'disabled) |
31717 | 117 nil |
118 (setq mm-uu-begin-line | |
119 (concat mm-uu-begin-line | |
120 (if mm-uu-begin-line "\\|") | |
121 (symbol-value | |
122 (intern (concat "mm-uu-" (symbol-name type) | |
123 "-begin-line"))))))) | |
124 '(uu postscript binhex shar forward))) | |
125 | |
126 (mm-uu-configure) | |
127 | |
128 ;;;### autoload | |
129 | |
130 (defun mm-uu-dissect () | |
131 "Dissect the current buffer and return a list of uu handles." | |
132 (let (text-start start-char end-char | |
33120
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
133 type file-name end-line result text-plain-type |
31717 | 134 start-char-1 end-char-1 |
135 (case-fold-search t)) | |
136 (save-excursion | |
137 (save-restriction | |
138 (mail-narrow-to-head) | |
139 (goto-char (point-max))) | |
140 (forward-line) | |
141 ;;; gnus-decoded is a fake charset, which means no further | |
142 ;;; decoding. | |
143 (setq text-start (point) | |
144 text-plain-type '("text/plain" (charset . gnus-decoded))) | |
145 (while (re-search-forward mm-uu-begin-line nil t) | |
146 (setq start-char (match-beginning 0)) | |
147 (setq type (cdr (assq (aref (match-string 0) 0) | |
148 mm-uu-identifier-alist))) | |
149 (setq file-name | |
150 (if (and (eq type 'uu) | |
151 (looking-at "\\(.+\\)$")) | |
152 (and (match-string 1) | |
153 (let ((nnheader-file-name-translation-alist | |
154 '((?/ . ?,) (? . ?_) (?* . ?_) (?$ . ?_)))) | |
155 (nnheader-translate-file-chars (match-string 1)))))) | |
156 (forward-line);; in case of failure | |
157 (setq start-char-1 (point)) | |
158 (setq end-line (symbol-value | |
159 (intern (concat "mm-uu-" (symbol-name type) | |
160 "-end-line")))) | |
161 (when (and (re-search-forward end-line nil t) | |
162 (not (eq (match-beginning 0) (match-end 0)))) | |
163 (setq end-char-1 (match-beginning 0)) | |
164 (forward-line) | |
165 (setq end-char (point)) | |
33120
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
166 (when (cond |
31717 | 167 ((eq type 'binhex) |
168 (setq file-name | |
169 (ignore-errors | |
170 (binhex-decode-region start-char end-char t)))) | |
171 ((eq type 'forward) | |
172 (save-excursion | |
173 (goto-char start-char-1) | |
174 (looking-at "[\r\n]*[a-zA-Z][a-zA-Z0-9-]*:"))) | |
175 (t t)) | |
176 (if (> start-char text-start) | |
177 (push | |
178 (mm-make-handle (mm-uu-copy-to-buffer text-start start-char) | |
179 text-plain-type) | |
180 result)) | |
181 (push | |
182 (cond | |
183 ((eq type 'postscript) | |
184 (mm-make-handle (mm-uu-copy-to-buffer start-char end-char) | |
185 '("application/postscript"))) | |
186 ((eq type 'forward) | |
187 (mm-make-handle (mm-uu-copy-to-buffer start-char-1 end-char-1) | |
188 '("message/rfc822" (charset . gnus-decoded)))) | |
189 ((eq type 'uu) | |
190 (mm-make-handle (mm-uu-copy-to-buffer start-char end-char) | |
191 (list (or (and file-name | |
192 (string-match "\\.[^\\.]+$" | |
193 file-name) | |
194 (mailcap-extension-to-mime | |
195 (match-string 0 file-name))) | |
196 "application/octet-stream")) | |
197 'x-uuencode nil | |
198 (if (and file-name (not (equal file-name ""))) | |
199 (list mm-dissect-disposition | |
200 (cons 'filename file-name))))) | |
201 ((eq type 'binhex) | |
202 (mm-make-handle (mm-uu-copy-to-buffer start-char end-char) | |
203 (list (or (and file-name | |
204 (string-match "\\.[^\\.]+$" file-name) | |
205 (mailcap-extension-to-mime | |
206 (match-string 0 file-name))) | |
207 "application/octet-stream")) | |
208 'x-binhex nil | |
209 (if (and file-name (not (equal file-name ""))) | |
210 (list mm-dissect-disposition | |
211 (cons 'filename file-name))))) | |
212 ((eq type 'shar) | |
213 (mm-make-handle (mm-uu-copy-to-buffer start-char end-char) | |
214 '("application/x-shar")))) | |
215 result) | |
216 (setq text-start end-char)))) | |
217 (when result | |
218 (if (> (point-max) (1+ text-start)) | |
219 (push | |
220 (mm-make-handle (mm-uu-copy-to-buffer text-start (point-max)) | |
221 text-plain-type) | |
222 result)) | |
223 (setq result (cons "multipart/mixed" (nreverse result)))) | |
224 result))) | |
225 | |
226 ;;;### autoload | |
227 (defun mm-uu-test () | |
33120
5d37eed2a6e2
(mm-uu-decode-function, mm-uu-binhex-decode-function):
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
228 "Check whether the current buffer contains uu stuff." |
31717 | 229 (save-excursion |
230 (goto-char (point-min)) | |
231 (let (type end-line result | |
232 (case-fold-search t)) | |
233 (while (and mm-uu-begin-line | |
234 (not result) (re-search-forward mm-uu-begin-line nil t)) | |
235 (forward-line) | |
236 (setq type (cdr (assq (aref (match-string 0) 0) | |
237 mm-uu-identifier-alist))) | |
238 (setq end-line (symbol-value | |
239 (intern (concat "mm-uu-" (symbol-name type) | |
240 "-end-line")))) | |
241 (if (and (re-search-forward end-line nil t) | |
242 (not (eq (match-beginning 0) (match-end 0)))) | |
243 (setq result t))) | |
244 result))) | |
245 | |
246 (provide 'mm-uu) | |
247 | |
248 ;;; mm-uu.el ends here |