20
|
1 ;;; MIME support functions
|
|
2 ;;; Copyright (C) 1997 Kyle E. Jones
|
|
3 ;;;
|
|
4 ;;; This program is free software; you can redistribute it and/or modify
|
|
5 ;;; it under the terms of the GNU General Public License as published by
|
|
6 ;;; the Free Software Foundation; either version 1, or (at your option)
|
|
7 ;;; any later version.
|
|
8 ;;;
|
|
9 ;;; This program is distributed in the hope that it will be useful,
|
|
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 ;;; GNU General Public License for more details.
|
|
13 ;;;
|
|
14 ;;; You should have received a copy of the GNU General Public License
|
|
15 ;;; along with this program; if not, write to the Free Software
|
|
16 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
|
18 (provide 'vm-mime)
|
|
19
|
|
20 (defun vm-mime-error (&rest args)
|
|
21 (signal 'vm-mime-error (list (apply 'format args)))
|
|
22 (error "can't return from vm-mime-error"))
|
|
23
|
|
24 (if (fboundp 'define-error)
|
|
25 (define-error 'vm-mime-error "MIME error")
|
|
26 (put 'vm-mime-error 'error-conditions '(vm-mime-error error))
|
|
27 (put 'vm-mime-error 'error-message "MIME error"))
|
|
28
|
|
29 (defun vm-mm-layout-type (e) (aref e 0))
|
24
|
30 (defun vm-mm-layout-qtype (e) (aref e 1))
|
|
31 (defun vm-mm-layout-encoding (e) (aref e 2))
|
|
32 (defun vm-mm-layout-id (e) (aref e 3))
|
|
33 (defun vm-mm-layout-description (e) (aref e 4))
|
|
34 (defun vm-mm-layout-disposition (e) (aref e 5))
|
|
35 (defun vm-mm-layout-qdisposition (e) (aref e 6))
|
|
36 (defun vm-mm-layout-header-start (e) (aref e 7))
|
|
37 (defun vm-mm-layout-body-start (e) (aref e 8))
|
|
38 (defun vm-mm-layout-body-end (e) (aref e 9))
|
|
39 (defun vm-mm-layout-parts (e) (aref e 10))
|
|
40 (defun vm-mm-layout-cache (e) (aref e 11))
|
20
|
41
|
24
|
42 (defun vm-set-mm-layout-cache (e c) (aset e 11 c))
|
20
|
43
|
|
44 (defun vm-mm-layout (m)
|
|
45 (or (vm-mime-layout-of m)
|
|
46 (progn (vm-set-mime-layout-of
|
|
47 m
|
|
48 (condition-case data
|
|
49 (vm-mime-parse-entity m)
|
|
50 (vm-mime-error (apply 'message (cdr data)))))
|
|
51 (vm-mime-layout-of m))))
|
|
52
|
|
53 (defun vm-mm-encoded-header (m)
|
|
54 (or (vm-mime-encoded-header-flag-of m)
|
|
55 (progn (setq m (vm-real-message-of m))
|
|
56 (vm-set-mime-encoded-header-flag-of
|
|
57 m
|
|
58 (save-excursion
|
|
59 (set-buffer (vm-buffer-of m))
|
|
60 (save-excursion
|
|
61 (save-restriction
|
|
62 (widen)
|
|
63 (goto-char (vm-headers-of m))
|
|
64 (or (re-search-forward vm-mime-encoded-word-regexp
|
|
65 (vm-text-of m) t)
|
|
66 'none)))))
|
|
67 (vm-mime-encoded-header-flag-of m))))
|
|
68
|
|
69 (defun vm-mime-Q-decode-region (start end)
|
|
70 (let ((buffer-read-only nil))
|
|
71 (subst-char-in-region start end ?_ (string-to-char " ") t)
|
|
72 (vm-mime-qp-decode-region start end)))
|
|
73
|
|
74 (fset 'vm-mime-B-decode-region 'vm-mime-base64-decode-region)
|
|
75
|
|
76 (defun vm-mime-Q-encode-region (start end)
|
|
77 (let ((buffer-read-only nil))
|
|
78 (subst-char-in-region start end (string-to-char " ") ?_ t)
|
24
|
79 (vm-mime-qp-encode-region start end t)))
|
20
|
80
|
24
|
81 (defun vm-mime-B-encode-region (start end)
|
|
82 (vm-mime-base64-encode-region start end nil t))
|
20
|
83
|
|
84 (defun vm-mime-crlf-to-lf-region (start end)
|
|
85 (let ((buffer-read-only nil))
|
|
86 (save-excursion
|
|
87 (save-restriction
|
|
88 (narrow-to-region start end)
|
|
89 (goto-char start)
|
|
90 (while (search-forward "\r\n" nil t)
|
|
91 (delete-char -2)
|
|
92 (insert "\n"))))))
|
|
93
|
|
94 (defun vm-mime-lf-to-crlf-region (start end)
|
|
95 (let ((buffer-read-only nil))
|
|
96 (save-excursion
|
|
97 (save-restriction
|
|
98 (narrow-to-region start end)
|
|
99 (goto-char start)
|
|
100 (while (search-forward "\n" nil t)
|
|
101 (delete-char -1)
|
|
102 (insert "\r\n"))))))
|
|
103
|
|
104 (defun vm-mime-charset-decode-region (charset start end)
|
24
|
105 (or (markerp end) (setq end (vm-marker end)))
|
|
106 (cond ((vm-xemacs-mule-p)
|
|
107 (if (eq (device-type) 'x)
|
|
108 (let ((buffer-read-only nil)
|
|
109 (cell (cdr (vm-string-assoc
|
|
110 charset
|
|
111 vm-mime-mule-charset-to-coding-alist)))
|
|
112 (oend (marker-position end))
|
|
113 (opoint (point)))
|
|
114 (if cell
|
|
115 (progn
|
|
116 (set-marker end (+ start
|
|
117 (or (decode-coding-region
|
|
118 start end (car cell))
|
|
119 (- oend start))))
|
|
120 (put-text-property start end 'vm-string t)
|
|
121 (put-text-property start end 'vm-charset charset)
|
|
122 (put-text-property start end 'vm-coding (car cell))))
|
|
123 ;; In XEmacs 20.0 beta93 decode-coding-region moves point.
|
|
124 (goto-char opoint))))
|
|
125 ((not (vm-multiple-fonts-possible-p)) nil)
|
|
126 ((vm-string-member charset vm-mime-default-face-charsets) nil)
|
|
127 (t
|
|
128 (let ((font (cdr (vm-string-assoc
|
|
129 charset
|
|
130 vm-mime-charset-font-alist)))
|
|
131 (face (make-face (make-symbol "temp-face")))
|
|
132 (e (vm-make-extent start end)))
|
|
133 (put-text-property start end 'vm-string t)
|
|
134 (put-text-property start end 'vm-charset charset)
|
|
135 (if font
|
|
136 (condition-case data
|
|
137 (progn (set-face-font face font)
|
|
138 (vm-set-extent-property e 'face face))
|
|
139 (error nil)))))))
|
20
|
140
|
|
141 (defun vm-mime-transfer-decode-region (layout start end)
|
|
142 (let ((case-fold-search t) (crlf nil))
|
|
143 (cond ((string-match "^base64$" (vm-mm-layout-encoding layout))
|
|
144 (cond ((vm-mime-types-match "text"
|
|
145 (car (vm-mm-layout-type layout)))
|
|
146 (setq crlf t))
|
|
147 ((vm-mime-types-match "message"
|
|
148 (car (vm-mm-layout-type layout)))
|
|
149 (setq crlf t)))
|
|
150 (vm-mime-base64-decode-region start end crlf))
|
|
151 ((string-match "^quoted-printable$"
|
|
152 (vm-mm-layout-encoding layout))
|
|
153 (vm-mime-qp-decode-region start end)))))
|
|
154
|
|
155 (defun vm-mime-base64-decode-region (start end &optional crlf)
|
26
|
156 (message "Decoding base64...")
|
20
|
157 (let ((work-buffer nil)
|
|
158 (done nil)
|
|
159 (counter 0)
|
|
160 (bits 0)
|
|
161 (lim 0) inputpos
|
|
162 (non-data-chars (concat "^=" vm-mime-base64-alphabet)))
|
|
163 (unwind-protect
|
|
164 (save-excursion
|
|
165 (setq work-buffer (generate-new-buffer " *vm-work*"))
|
|
166 (buffer-disable-undo work-buffer)
|
|
167 (if vm-mime-base64-decoder-program
|
|
168 (let* ((binary-process-output t) ; any text already has CRLFs
|
|
169 (status (apply 'vm-run-command-on-region
|
|
170 start end work-buffer
|
|
171 vm-mime-base64-decoder-program
|
|
172 vm-mime-base64-decoder-switches)))
|
|
173 (if (not (eq status t))
|
|
174 (vm-mime-error "%s" (cdr status))))
|
|
175 (goto-char start)
|
|
176 (skip-chars-forward non-data-chars end)
|
|
177 (while (not done)
|
|
178 (setq inputpos (point))
|
|
179 (cond
|
|
180 ((> (skip-chars-forward vm-mime-base64-alphabet end) 0)
|
|
181 (setq lim (point))
|
|
182 (while (< inputpos lim)
|
|
183 (setq bits (+ bits
|
|
184 (aref vm-mime-base64-alphabet-decoding-vector
|
|
185 (char-after inputpos))))
|
|
186 (vm-increment counter)
|
|
187 (vm-increment inputpos)
|
|
188 (cond ((= counter 4)
|
|
189 (vm-insert-char (lsh bits -16) 1 nil work-buffer)
|
|
190 (vm-insert-char (logand (lsh bits -8) 255) 1 nil
|
|
191 work-buffer)
|
|
192 (vm-insert-char (logand bits 255) 1 nil work-buffer)
|
|
193 (setq bits 0 counter 0))
|
|
194 (t (setq bits (lsh bits 6)))))))
|
|
195 (cond
|
|
196 ((= (point) end)
|
|
197 (if (not (zerop counter))
|
|
198 (vm-mime-error "at least %d bits missing at end of base64 encoding"
|
|
199 (* (- 4 counter) 6)))
|
|
200 (setq done t))
|
|
201 ((= (char-after (point)) 61) ; 61 is ASCII equals
|
|
202 (setq done t)
|
|
203 (cond ((= counter 1)
|
|
204 (vm-mime-error "at least 2 bits missing at end of base64 encoding"))
|
|
205 ((= counter 2)
|
|
206 (vm-insert-char (lsh bits -10) 1 nil work-buffer))
|
|
207 ((= counter 3)
|
|
208 (vm-insert-char (lsh bits -16) 1 nil work-buffer)
|
|
209 (vm-insert-char (logand (lsh bits -8) 255)
|
|
210 1 nil work-buffer))
|
|
211 ((= counter 0) t)))
|
|
212 (t (skip-chars-forward non-data-chars end)))))
|
|
213 (and crlf
|
|
214 (save-excursion
|
|
215 (set-buffer work-buffer)
|
|
216 (vm-mime-crlf-to-lf-region (point-min) (point-max))))
|
|
217 (or (markerp end) (setq end (vm-marker end)))
|
|
218 (goto-char start)
|
|
219 (insert-buffer-substring work-buffer)
|
|
220 (delete-region (point) end))
|
|
221 (and work-buffer (kill-buffer work-buffer))))
|
26
|
222 (message "Decoding base64... done"))
|
20
|
223
|
24
|
224 (defun vm-mime-base64-encode-region (start end &optional crlf B-encoding)
|
|
225 (and (> (- end start) 200)
|
26
|
226 (message "Encoding base64..."))
|
20
|
227 (let ((work-buffer nil)
|
|
228 (counter 0)
|
|
229 (cols 0)
|
|
230 (bits 0)
|
|
231 (alphabet vm-mime-base64-alphabet)
|
|
232 inputpos)
|
|
233 (unwind-protect
|
|
234 (save-excursion
|
|
235 (setq work-buffer (generate-new-buffer " *vm-work*"))
|
|
236 (buffer-disable-undo work-buffer)
|
|
237 (if crlf
|
|
238 (progn
|
|
239 (or (markerp end) (setq end (vm-marker end)))
|
|
240 (vm-mime-lf-to-crlf-region start end)))
|
|
241 (if vm-mime-base64-encoder-program
|
|
242 (let ((status (apply 'vm-run-command-on-region
|
|
243 start end work-buffer
|
|
244 vm-mime-base64-encoder-program
|
|
245 vm-mime-base64-encoder-switches)))
|
|
246 (if (not (eq status t))
|
26
|
247 (vm-mime-error "%s" (cdr status)))
|
|
248 (if B-encoding
|
|
249 (progn
|
|
250 ;; if we're B encoding, strip out the line breaks
|
|
251 (goto-char (point-min))
|
|
252 (while (search-forward "\n" nil t)
|
|
253 (delete-char -1)))))
|
20
|
254 (setq inputpos start)
|
|
255 (while (< inputpos end)
|
|
256 (setq bits (+ bits (char-after inputpos)))
|
|
257 (vm-increment counter)
|
|
258 (cond ((= counter 3)
|
|
259 (vm-insert-char (aref alphabet (lsh bits -18)) 1 nil
|
|
260 work-buffer)
|
|
261 (vm-insert-char (aref alphabet (logand (lsh bits -12) 63))
|
|
262 1 nil work-buffer)
|
|
263 (vm-insert-char (aref alphabet (logand (lsh bits -6) 63))
|
|
264 1 nil work-buffer)
|
|
265 (vm-insert-char (aref alphabet (logand bits 63)) 1 nil
|
|
266 work-buffer)
|
|
267 (setq cols (+ cols 4))
|
|
268 (cond ((= cols 72)
|
24
|
269 (setq cols 0)
|
|
270 (if (not B-encoding)
|
|
271 (vm-insert-char ?\n 1 nil work-buffer))))
|
20
|
272 (setq bits 0 counter 0))
|
|
273 (t (setq bits (lsh bits 8))))
|
|
274 (vm-increment inputpos))
|
|
275 ;; write out any remaining bits with appropriate padding
|
|
276 (if (= counter 0)
|
|
277 nil
|
|
278 (setq bits (lsh bits (- 16 (* 8 counter))))
|
|
279 (vm-insert-char (aref alphabet (lsh bits -18)) 1 nil
|
|
280 work-buffer)
|
|
281 (vm-insert-char (aref alphabet (logand (lsh bits -12) 63))
|
|
282 1 nil work-buffer)
|
|
283 (if (= counter 1)
|
|
284 (vm-insert-char ?= 2 nil work-buffer)
|
|
285 (vm-insert-char (aref alphabet (logand (lsh bits -6) 63))
|
|
286 1 nil work-buffer)
|
|
287 (vm-insert-char ?= 1 nil work-buffer)))
|
|
288 (if (> cols 0)
|
|
289 (vm-insert-char ?\n 1 nil work-buffer)))
|
|
290 (or (markerp end) (setq end (vm-marker end)))
|
|
291 (goto-char start)
|
|
292 (insert-buffer-substring work-buffer)
|
24
|
293 (delete-region (point) end)
|
|
294 (and (> (- end start) 200)
|
26
|
295 (message "Encoding base64... done"))
|
24
|
296 (- end start))
|
|
297 (and work-buffer (kill-buffer work-buffer)))))
|
20
|
298
|
|
299 (defun vm-mime-qp-decode-region (start end)
|
24
|
300 (and (> (- end start) 200)
|
26
|
301 (message "Decoding quoted-printable..."))
|
20
|
302 (let ((work-buffer nil)
|
|
303 (buf (current-buffer))
|
|
304 (case-fold-search nil)
|
|
305 (hex-digit-alist '((?0 . 0) (?1 . 1) (?2 . 2) (?3 . 3)
|
|
306 (?4 . 4) (?5 . 5) (?6 . 6) (?7 . 7)
|
|
307 (?8 . 8) (?9 . 9) (?A . 10) (?B . 11)
|
|
308 (?C . 12) (?D . 13) (?E . 14) (?F . 15)))
|
|
309 inputpos stop-point copy-point)
|
|
310 (unwind-protect
|
|
311 (save-excursion
|
|
312 (setq work-buffer (generate-new-buffer " *vm-work*"))
|
|
313 (buffer-disable-undo work-buffer)
|
|
314 (goto-char start)
|
|
315 (setq inputpos start)
|
|
316 (while (< inputpos end)
|
|
317 (skip-chars-forward "^=\n" end)
|
|
318 (setq stop-point (point))
|
|
319 (cond ((looking-at "\n")
|
|
320 ;; spaces or tabs before a hard line break must be ignored
|
|
321 (skip-chars-backward " \t")
|
|
322 (setq copy-point (point))
|
|
323 (goto-char stop-point))
|
|
324 (t (setq copy-point stop-point)))
|
|
325 (save-excursion
|
|
326 (set-buffer work-buffer)
|
|
327 (insert-buffer-substring buf inputpos copy-point))
|
|
328 (cond ((= (point) end) t)
|
|
329 ((looking-at "\n")
|
|
330 (vm-insert-char ?\n 1 nil work-buffer)
|
|
331 (forward-char))
|
|
332 (t ;; looking at =
|
|
333 (forward-char)
|
|
334 (cond ((looking-at "[0-9A-F][0-9A-F]")
|
|
335 (vm-insert-char (+ (* (cdr (assq (char-after (point))
|
|
336 hex-digit-alist))
|
|
337 16)
|
|
338 (cdr (assq (char-after
|
|
339 (1+ (point)))
|
|
340 hex-digit-alist)))
|
|
341 1 nil work-buffer)
|
|
342 (forward-char 2))
|
|
343 ((looking-at "\n") ; soft line break
|
|
344 (forward-char))
|
|
345 ((looking-at "\r")
|
|
346 ;; assume the user's goatfucking
|
|
347 ;; delivery software didn't convert
|
|
348 ;; from Internet's CRLF newline
|
|
349 ;; convention to the local LF
|
|
350 ;; convention.
|
|
351 (forward-char))
|
|
352 ((looking-at "[ \t]")
|
|
353 ;; garbage added in transit
|
|
354 (skip-chars-forward " \t" end))
|
|
355 (t (vm-mime-error "something other than line break or hex digits after = in quoted-printable encoding")))))
|
|
356 (setq inputpos (point)))
|
|
357 (or (markerp end) (setq end (vm-marker end)))
|
|
358 (goto-char start)
|
|
359 (insert-buffer-substring work-buffer)
|
|
360 (delete-region (point) end))
|
|
361 (and work-buffer (kill-buffer work-buffer))))
|
24
|
362 (and (> (- end start) 200)
|
26
|
363 (message "Decoding quoted-printable... done")))
|
20
|
364
|
24
|
365 (defun vm-mime-qp-encode-region (start end &optional Q-encoding)
|
|
366 (and (> (- end start) 200)
|
26
|
367 (message "Encoding quoted-printable..."))
|
20
|
368 (let ((work-buffer nil)
|
|
369 (buf (current-buffer))
|
|
370 (cols 0)
|
|
371 (hex-digit-alist '((?0 . 0) (?1 . 1) (?2 . 2) (?3 . 3)
|
|
372 (?4 . 4) (?5 . 5) (?6 . 6) (?7 . 7)
|
|
373 (?8 . 8) (?9 . 9) (?A . 10) (?B . 11)
|
|
374 (?C . 12) (?D . 13) (?E . 14) (?F . 15)))
|
|
375 char inputpos)
|
|
376 (unwind-protect
|
|
377 (save-excursion
|
|
378 (setq work-buffer (generate-new-buffer " *vm-work*"))
|
|
379 (buffer-disable-undo work-buffer)
|
|
380 (setq inputpos start)
|
|
381 (while (< inputpos end)
|
|
382 (setq char (char-after inputpos))
|
|
383 (cond ((= char ?\n)
|
|
384 (vm-insert-char char 1 nil work-buffer)
|
|
385 (setq cols 0))
|
|
386 ((and (= char 32) (not (= ?\n (char-after (1+ inputpos)))))
|
|
387 (vm-insert-char char 1 nil work-buffer)
|
|
388 (vm-increment cols))
|
|
389 ((or (< char 33) (> char 126) (= char 61))
|
|
390 (vm-insert-char ?= 1 nil work-buffer)
|
|
391 (vm-insert-char (car (rassq (lsh char -4) hex-digit-alist))
|
|
392 1 nil work-buffer)
|
|
393 (vm-insert-char (car (rassq (logand char 15)
|
|
394 hex-digit-alist))
|
|
395 1 nil work-buffer)
|
|
396 (setq cols (+ cols 3)))
|
|
397 (t (vm-insert-char char 1 nil work-buffer)
|
|
398 (vm-increment cols)))
|
|
399 (cond ((> cols 70)
|
24
|
400 (setq cols 0)
|
|
401 (if Q-encoding
|
|
402 nil
|
|
403 (vm-insert-char ?= 1 nil work-buffer)
|
|
404 (vm-insert-char ?\n 1 nil work-buffer))))
|
20
|
405 (vm-increment inputpos))
|
|
406 (or (markerp end) (setq end (vm-marker end)))
|
|
407 (goto-char start)
|
|
408 (insert-buffer-substring work-buffer)
|
24
|
409 (delete-region (point) end)
|
|
410 (and (> (- end start) 200)
|
26
|
411 (message "Encoding quoted-printable... done"))
|
24
|
412 (- end start))
|
|
413 (and work-buffer (kill-buffer work-buffer)))))
|
20
|
414
|
|
415 (defun vm-decode-mime-message-headers (m)
|
|
416 (let ((case-fold-search t)
|
|
417 (buffer-read-only nil)
|
|
418 charset encoding match-start match-end start end)
|
|
419 (save-excursion
|
|
420 (goto-char (vm-headers-of m))
|
|
421 (while (re-search-forward vm-mime-encoded-word-regexp (vm-text-of m) t)
|
|
422 (setq match-start (match-beginning 0)
|
|
423 match-end (match-end 0)
|
|
424 charset (match-string 1)
|
|
425 encoding (match-string 2)
|
|
426 start (match-beginning 3)
|
|
427 end (vm-marker (match-end 3)))
|
|
428 ;; don't change anything if we can't display the
|
|
429 ;; character set properly.
|
|
430 (if (not (vm-mime-charset-internally-displayable-p charset))
|
|
431 nil
|
|
432 (delete-region end match-end)
|
|
433 (cond ((string-match "B" encoding)
|
|
434 (vm-mime-B-decode-region start end))
|
|
435 ((string-match "Q" encoding)
|
|
436 (vm-mime-Q-decode-region start end))
|
|
437 (t (vm-mime-error "unknown encoded word encoding, %s"
|
|
438 encoding)))
|
|
439 (vm-mime-charset-decode-region charset start end)
|
|
440 (delete-region match-start start))))))
|
|
441
|
|
442 (defun vm-decode-mime-encoded-words ()
|
|
443 (let ((case-fold-search t)
|
|
444 (buffer-read-only nil)
|
|
445 charset encoding match-start match-end start end)
|
|
446 (save-excursion
|
|
447 (goto-char (point-min))
|
|
448 (while (re-search-forward vm-mime-encoded-word-regexp nil t)
|
|
449 (setq match-start (match-beginning 0)
|
|
450 match-end (match-end 0)
|
|
451 charset (match-string 1)
|
|
452 encoding (match-string 2)
|
|
453 start (match-beginning 3)
|
|
454 end (vm-marker (match-end 3)))
|
|
455 ;; don't change anything if we can't display the
|
|
456 ;; character set properly.
|
|
457 (if (not (vm-mime-charset-internally-displayable-p charset))
|
|
458 nil
|
|
459 (delete-region end match-end)
|
|
460 (cond ((string-match "B" encoding)
|
|
461 (vm-mime-B-decode-region start end))
|
|
462 ((string-match "Q" encoding)
|
|
463 (vm-mime-Q-decode-region start end))
|
|
464 (t (vm-mime-error "unknown encoded word encoding, %s"
|
|
465 encoding)))
|
|
466 (vm-mime-charset-decode-region charset start end)
|
|
467 (delete-region match-start start))))))
|
|
468
|
24
|
469 (defun vm-decode-mime-encoded-words-in-string (string)
|
20
|
470 (if (and vm-display-using-mime
|
|
471 (string-match vm-mime-encoded-word-regexp string))
|
|
472 (vm-with-string-as-temp-buffer string 'vm-decode-mime-encoded-words)
|
|
473 string ))
|
|
474
|
24
|
475 (defun vm-reencode-mime-encoded-words ()
|
|
476 (let ((charset nil)
|
|
477 start coding pos q-encoding
|
|
478 old-size
|
|
479 (case-fold-search t)
|
|
480 (done nil))
|
|
481 (save-excursion
|
|
482 (setq start (point-min))
|
|
483 (while (not done)
|
|
484 (setq charset (get-text-property start 'vm-charset))
|
|
485 (setq pos (next-single-property-change start 'vm-charset))
|
|
486 (or pos (setq pos (point-max) done t))
|
|
487 (if charset
|
|
488 (progn
|
|
489 (if (setq coding (get-text-property start 'vm-coding))
|
|
490 (progn
|
|
491 (setq old-size (buffer-size))
|
|
492 (encode-coding-region start pos coding)
|
|
493 (setq pos (+ pos (- (buffer-size) old-size)))))
|
|
494 (setq pos
|
|
495 (+ start
|
|
496 (if (setq q-encoding
|
|
497 (string-match "^iso-8859-\\|^us-ascii"
|
|
498 charset))
|
|
499 (vm-mime-Q-encode-region start pos)
|
|
500 (vm-mime-B-encode-region start pos))))
|
|
501 (goto-char pos)
|
|
502 (insert "?=")
|
|
503 (setq pos (point))
|
|
504 (goto-char start)
|
|
505 (insert "=?" charset "?" (if q-encoding "Q" "B") "?")))
|
|
506 (setq start pos)))))
|
|
507
|
|
508 (defun vm-reencode-mime-encoded-words-in-string (string)
|
|
509 (if (and vm-display-using-mime
|
|
510 (text-property-any 0 (length string) 'vm-string t string))
|
|
511 (vm-with-string-as-temp-buffer string 'vm-reencode-mime-encoded-words)
|
|
512 string ))
|
|
513
|
|
514 (defun vm-mime-parse-content-header (string &optional sepchar keep-quotes)
|
20
|
515 (if (null string)
|
|
516 ()
|
|
517 (let ((work-buffer nil))
|
|
518 (save-excursion
|
|
519 (unwind-protect
|
|
520 (let ((list nil)
|
|
521 (nonspecials "^\"\\( \t\n\r\f")
|
|
522 start s char sp+sepchar)
|
|
523 (if sepchar
|
|
524 (setq nonspecials (concat nonspecials (list sepchar))
|
|
525 sp+sepchar (concat "\t\f\n\r " (list sepchar))))
|
|
526 (setq work-buffer (generate-new-buffer "*vm-work*"))
|
|
527 (buffer-disable-undo work-buffer)
|
|
528 (set-buffer work-buffer)
|
|
529 (insert string)
|
|
530 (goto-char (point-min))
|
|
531 (skip-chars-forward "\t\f\n\r ")
|
|
532 (setq start (point))
|
|
533 (while (not (eobp))
|
|
534 (skip-chars-forward nonspecials)
|
|
535 (setq char (following-char))
|
|
536 (cond ((looking-at "[ \t\n\r\f]")
|
|
537 (delete-char 1))
|
|
538 ((= char ?\\)
|
|
539 (forward-char 1)
|
|
540 (if (not (eobp))
|
|
541 (forward-char 1)))
|
|
542 ((and sepchar (= char sepchar))
|
|
543 (setq s (buffer-substring start (point)))
|
|
544 (if (or (null (string-match "^[\t\f\n\r ]+$" s))
|
|
545 (not (string= s "")))
|
|
546 (setq list (cons s list)))
|
|
547 (skip-chars-forward sp+sepchar)
|
|
548 (setq start (point)))
|
|
549 ((looking-at " \t\n\r\f")
|
|
550 (skip-chars-forward " \t\n\r\f"))
|
|
551 ((= char ?\")
|
24
|
552 (let ((done nil))
|
|
553 (if keep-quotes
|
|
554 (forward-char 1)
|
|
555 (delete-char 1))
|
|
556 (while (not done)
|
|
557 (if (null (re-search-forward "[\\\"]" nil t))
|
|
558 (setq done t)
|
|
559 (setq char (char-after (1- (point))))
|
|
560 (cond ((char-equal char ?\\)
|
|
561 (delete-char -1)
|
|
562 (if (eobp)
|
|
563 (setq done t)
|
|
564 (forward-char 1)))
|
|
565 (t (if (not keep-quotes)
|
|
566 (delete-char -1))
|
|
567 (setq done t)))))))
|
20
|
568 ((= char ?\()
|
24
|
569 (let ((done nil)
|
|
570 (pos (point))
|
|
571 (parens 1))
|
20
|
572 (forward-char 1)
|
24
|
573 (while (not done)
|
|
574 (if (null (re-search-forward "[\\()]" nil t))
|
|
575 (setq done t)
|
|
576 (setq char (char-after (1- (point))))
|
|
577 (cond ((char-equal char ?\\)
|
|
578 (if (eobp)
|
|
579 (setq done t)
|
|
580 (forward-char 1)))
|
|
581 ((char-equal char ?\()
|
|
582 (setq parens (1+ parens)))
|
|
583 (t
|
|
584 (setq parens (1- parens)
|
|
585 done (zerop parens))))))
|
20
|
586 (delete-region pos (point))))))
|
|
587 (setq s (buffer-substring start (point)))
|
|
588 (if (and (null (string-match "^[\t\f\n\r ]+$" s))
|
|
589 (not (string= s "")))
|
|
590 (setq list (cons s list)))
|
|
591 (nreverse list))
|
|
592 (and work-buffer (kill-buffer work-buffer)))))))
|
|
593
|
|
594 (defun vm-mime-get-header-contents (header-name-regexp)
|
|
595 (let ((contents nil)
|
|
596 regexp)
|
|
597 (setq regexp (concat "^\\(" header-name-regexp "\\)\\|\\(^$\\)"))
|
|
598 (save-excursion
|
|
599 (let ((case-fold-search t))
|
|
600 (if (and (re-search-forward regexp nil t)
|
|
601 (match-beginning 1)
|
|
602 (progn (goto-char (match-beginning 0))
|
|
603 (vm-match-header)))
|
|
604 (vm-matched-header-contents)
|
|
605 nil )))))
|
|
606
|
|
607 (defun vm-mime-parse-entity (&optional m default-type default-encoding)
|
24
|
608 (let ((case-fold-search t) version type qtype encoding id description
|
|
609 disposition qdisposition boundary boundary-regexp start
|
20
|
610 multipart-list c-t c-t-e done p returnval)
|
26
|
611 (and m (message "Parsing MIME message..."))
|
20
|
612 (prog1
|
|
613 (catch 'return-value
|
|
614 (save-excursion
|
|
615 (if m
|
|
616 (progn
|
|
617 (setq m (vm-real-message-of m))
|
|
618 (set-buffer (vm-buffer-of m))))
|
|
619 (save-excursion
|
|
620 (save-restriction
|
|
621 (if m
|
|
622 (progn
|
|
623 (setq version (vm-get-header-contents m "MIME-Version:")
|
|
624 version (car (vm-mime-parse-content-header version))
|
|
625 type (vm-get-header-contents m "Content-Type:")
|
24
|
626 qtype (vm-mime-parse-content-header type ?\; t)
|
20
|
627 type (vm-mime-parse-content-header type ?\;)
|
|
628 encoding (or (vm-get-header-contents
|
|
629 m "Content-Transfer-Encoding:")
|
|
630 "7bit")
|
|
631 encoding (car (vm-mime-parse-content-header encoding))
|
|
632 id (vm-get-header-contents m "Content-ID:")
|
|
633 id (car (vm-mime-parse-content-header id))
|
|
634 description (vm-get-header-contents
|
|
635 m "Content-Description:")
|
|
636 description (and description
|
|
637 (if (string-match "^[ \t\n]$"
|
|
638 description)
|
|
639 nil
|
|
640 description))
|
|
641 disposition (vm-get-header-contents
|
|
642 m "Content-Disposition:")
|
24
|
643 qdisposition (and disposition
|
|
644 (vm-mime-parse-content-header
|
|
645 disposition ?\; t))
|
20
|
646 disposition (and disposition
|
|
647 (vm-mime-parse-content-header
|
|
648 disposition ?\;)))
|
|
649 (widen)
|
|
650 (narrow-to-region (vm-headers-of m) (vm-text-end-of m)))
|
|
651 (goto-char (point-min))
|
|
652 (setq type (vm-mime-get-header-contents "Content-Type:")
|
24
|
653 qtype (or (vm-mime-parse-content-header type ?\; t)
|
|
654 default-type)
|
20
|
655 type (or (vm-mime-parse-content-header type ?\;)
|
|
656 default-type)
|
|
657 encoding (or (vm-mime-get-header-contents
|
|
658 "Content-Transfer-Encoding:")
|
|
659 default-encoding)
|
|
660 encoding (car (vm-mime-parse-content-header encoding))
|
|
661 id (vm-mime-get-header-contents "Content-ID:")
|
|
662 id (car (vm-mime-parse-content-header id))
|
|
663 description (vm-mime-get-header-contents
|
|
664 "Content-Description:")
|
|
665 description (and description (if (string-match "^[ \t\n]+$"
|
|
666 description)
|
|
667 nil
|
|
668 description))
|
|
669 disposition (vm-mime-get-header-contents
|
|
670 "Content-Disposition:")
|
24
|
671 qdisposition (and disposition
|
|
672 (vm-mime-parse-content-header
|
|
673 disposition ?\; t))
|
20
|
674 disposition (and disposition
|
|
675 (vm-mime-parse-content-header
|
|
676 disposition ?\;))))
|
|
677 (cond ((null m) t)
|
|
678 ((null version)
|
|
679 (throw 'return-value 'none))
|
|
680 ((string= version "1.0") t)
|
|
681 (t (vm-mime-error "Unsupported MIME version: %s" version)))
|
|
682 (cond ((and m (null type))
|
|
683 (throw 'return-value
|
|
684 (vector '("text/plain" "charset=us-ascii")
|
24
|
685 '("text/plain" "charset=us-ascii")
|
|
686 encoding id description
|
|
687 disposition qdisposition
|
20
|
688 (vm-headers-of m)
|
|
689 (vm-text-of m)
|
|
690 (vm-text-end-of m)
|
|
691 nil nil nil )))
|
|
692 ((null type)
|
|
693 (goto-char (point-min))
|
|
694 (or (re-search-forward "^\n\\|\n\\'" nil t)
|
|
695 (vm-mime-error "MIME part missing header/body separator line"))
|
24
|
696 (vector default-type default-type
|
|
697 encoding id description
|
|
698 disposition qdisposition
|
20
|
699 (vm-marker (point-min))
|
|
700 (vm-marker (point))
|
|
701 (vm-marker (point-max))
|
|
702 nil nil nil ))
|
|
703 ((null (string-match "[^/ ]+/[^/ ]+" (car type)))
|
|
704 (vm-mime-error "Malformed MIME content type: %s" (car type)))
|
|
705 ((and (string-match "^multipart/\\|^message/" (car type))
|
|
706 (null (string-match "^\\(7bit\\|8bit\\|binary\\)$"
|
|
707 encoding)))
|
|
708 (vm-mime-error "Opaque transfer encoding used with multipart or message type: %s, %s" (car type) encoding))
|
|
709 ((and (string-match "^message/partial$" (car type))
|
|
710 (null (string-match "^7bit$" encoding)))
|
|
711 (vm-mime-error "Non-7BIT transfer encoding used with message/partial message: %s" encoding))
|
|
712 ((string-match "^multipart/digest" (car type))
|
|
713 (setq c-t '("message/rfc822")
|
|
714 c-t-e "7bit"))
|
|
715 ((string-match "^multipart/" (car type))
|
|
716 (setq c-t '("text/plain" "charset=us-ascii")
|
|
717 c-t-e "7bit")) ; below
|
|
718 ((string-match "^message/rfc822" (car type))
|
|
719 (setq c-t '("text/plain" "charset=us-ascii")
|
|
720 c-t-e "7bit")
|
|
721 (goto-char (point-min))
|
|
722 (or (re-search-forward "^\n\\|\n\\'" nil t)
|
|
723 (vm-mime-error "MIME part missing header/body separator line"))
|
|
724 (throw 'return-value
|
24
|
725 (vector type qtype encoding id description
|
|
726 disposition qdisposition
|
20
|
727 (vm-marker (point-min))
|
|
728 (vm-marker (point))
|
|
729 (vm-marker (point-max))
|
|
730 (list
|
|
731 (save-restriction
|
|
732 (narrow-to-region (point) (point-max))
|
24
|
733 (vm-mime-parse-entity-safe nil c-t
|
|
734 c-t-e)))
|
20
|
735 nil )))
|
|
736 (t
|
|
737 (goto-char (point-min))
|
|
738 (or (re-search-forward "^\n\\|\n\\'" nil t)
|
|
739 (vm-mime-error "MIME part missing header/body separator line"))
|
|
740 (throw 'return-value
|
24
|
741 (vector type qtype encoding id description
|
|
742 disposition qdisposition
|
20
|
743 (vm-marker (point-min))
|
|
744 (vm-marker (point))
|
|
745 (vm-marker (point-max))
|
|
746 nil nil ))))
|
|
747 (setq p (cdr type)
|
|
748 boundary nil)
|
|
749 (while p
|
|
750 (if (string-match "^boundary=" (car p))
|
|
751 (setq boundary (car (vm-parse (car p) "=\\(.+\\)"))
|
|
752 p nil)
|
|
753 (setq p (cdr p))))
|
|
754 (or boundary
|
|
755 (vm-mime-error
|
|
756 "Boundary parameter missing in %s type specification"
|
|
757 (car type)))
|
24
|
758 ;; the \' in the regexp is to "be liberal" in the
|
|
759 ;; face of broken software that does not add a line
|
|
760 ;; break after the final boundary of a nested
|
|
761 ;; multipart entity.
|
|
762 (setq boundary-regexp
|
|
763 (concat "^--" (regexp-quote boundary)
|
|
764 "\\(--\\)?[ \t]*\\(\n\\|\\'\\)"))
|
20
|
765 (goto-char (point-min))
|
|
766 (setq start nil
|
|
767 multipart-list nil
|
|
768 done nil)
|
|
769 (while (and (not done) (re-search-forward boundary-regexp nil t))
|
|
770 (cond ((null start)
|
|
771 (setq start (match-end 0)))
|
|
772 (t
|
|
773 (and (match-beginning 1)
|
|
774 (setq done t))
|
|
775 (save-excursion
|
|
776 (save-restriction
|
|
777 (narrow-to-region start (1- (match-beginning 0)))
|
|
778 (setq start (match-end 0))
|
|
779 (setq multipart-list
|
|
780 (cons (vm-mime-parse-entity-safe nil c-t c-t-e)
|
|
781 multipart-list)))))))
|
|
782 (if (not done)
|
|
783 (vm-mime-error "final %s boundary missing" boundary))
|
|
784 (goto-char (point-min))
|
|
785 (or (re-search-forward "^\n\\|\n\\'" nil t)
|
|
786 (vm-mime-error "MIME part missing header/body separator line"))
|
24
|
787 (vector type qtype encoding id description
|
|
788 disposition qdisposition
|
20
|
789 (vm-marker (point-min))
|
|
790 (vm-marker (point))
|
|
791 (vm-marker (point-max))
|
|
792 (nreverse multipart-list)
|
|
793 nil )))))
|
26
|
794 (and m (message "Parsing MIME message... done"))
|
20
|
795 )))
|
|
796
|
|
797 (defun vm-mime-parse-entity-safe (&optional m c-t c-t-e)
|
|
798 (or c-t (setq c-t '("text/plain" "charset=us-ascii")))
|
|
799 ;; don't let subpart parse errors make the whole parse fail. use default
|
|
800 ;; type if the parse fails.
|
|
801 (condition-case error-data
|
|
802 (vm-mime-parse-entity nil c-t c-t-e)
|
|
803 (vm-mime-error
|
|
804 (let ((header (if m
|
|
805 (vm-headers-of m)
|
|
806 (vm-marker (point-min))))
|
|
807 (text (if m
|
|
808 (vm-text-of m)
|
|
809 (save-excursion
|
|
810 (re-search-forward "^\n\\|\n\\'"
|
|
811 nil 0)
|
|
812 (vm-marker (point)))))
|
|
813 (text-end (if m
|
|
814 (vm-text-end-of m)
|
|
815 (vm-marker (point-max)))))
|
24
|
816 (vector c-t c-t
|
20
|
817 (vm-determine-proper-content-transfer-encoding text text-end)
|
|
818 nil
|
|
819 ;; cram the error message into the description slot
|
24
|
820 (car (cdr error-data))
|
20
|
821 ;; mark as an attachment to improve the chance that the user
|
|
822 ;; will see the description.
|
24
|
823 '("attachment") '("attachment")
|
20
|
824 header
|
|
825 text
|
|
826 text-end)))))
|
|
827
|
|
828 (defun vm-mime-get-xxx-parameter (layout name param-list)
|
|
829 (let ((match-end (1+ (length name)))
|
|
830 (name-regexp (concat (regexp-quote name) "="))
|
|
831 (case-fold-search t)
|
|
832 (done nil))
|
|
833 (while (and param-list (not done))
|
|
834 (if (and (string-match name-regexp (car param-list))
|
|
835 (= (match-end 0) match-end))
|
|
836 (setq done t)
|
|
837 (setq param-list (cdr param-list))))
|
|
838 (and (car param-list) (car (vm-parse (car param-list) "=\\(.*\\)")))))
|
|
839
|
|
840 (defun vm-mime-get-parameter (layout name)
|
|
841 (vm-mime-get-xxx-parameter layout name (cdr (vm-mm-layout-type layout))))
|
|
842
|
|
843 (defun vm-mime-get-disposition-parameter (layout name)
|
|
844 (vm-mime-get-xxx-parameter layout name
|
|
845 (cdr (vm-mm-layout-disposition layout))))
|
|
846
|
|
847 (defun vm-mime-insert-mime-body (layout)
|
|
848 (vm-insert-region-from-buffer (marker-buffer (vm-mm-layout-body-start layout))
|
|
849 (vm-mm-layout-body-start layout)
|
|
850 (vm-mm-layout-body-end layout)))
|
|
851
|
|
852 (defun vm-mime-insert-mime-headers (layout)
|
|
853 (vm-insert-region-from-buffer (marker-buffer (vm-mm-layout-body-start layout))
|
|
854 (vm-mm-layout-header-start layout)
|
|
855 (vm-mm-layout-body-start layout))
|
|
856 (if (and (not (bobp)) (char-equal (char-after (1- (point))) ?\n))
|
|
857 (delete-char -1)))
|
|
858
|
|
859 (defun vm-make-presentation-copy (m)
|
|
860 (let ((mail-buffer (current-buffer))
|
|
861 b mm
|
|
862 (real-m (vm-real-message-of m))
|
|
863 (modified (buffer-modified-p)))
|
|
864 (cond ((or (null vm-presentation-buffer-handle)
|
|
865 (null (buffer-name vm-presentation-buffer-handle)))
|
|
866 (setq b (generate-new-buffer (concat (buffer-name)
|
|
867 " Presentation")))
|
|
868 (save-excursion
|
|
869 (set-buffer b)
|
|
870 (if (fboundp 'buffer-disable-undo)
|
|
871 (buffer-disable-undo (current-buffer))
|
|
872 ;; obfuscation to make the v19 compiler not whine
|
|
873 ;; about obsolete functions.
|
|
874 (let ((x 'buffer-flush-undo))
|
|
875 (funcall x (current-buffer))))
|
|
876 (setq mode-name "VM Presentation"
|
|
877 major-mode 'vm-presentation-mode
|
|
878 vm-message-pointer (list nil)
|
|
879 vm-mail-buffer mail-buffer
|
|
880 mode-popup-menu (and vm-use-menus vm-popup-menu-on-mouse-3
|
|
881 (vm-menu-support-possible-p)
|
|
882 (vm-menu-mode-menu))
|
24
|
883 ;; Default to binary file type for DOS/NT.
|
|
884 buffer-file-type t
|
|
885 ;; Tell XEmacs/MULE not to mess with the text on writes.
|
20
|
886 buffer-read-only t
|
|
887 mode-line-format vm-mode-line-format)
|
26
|
888 (and (vm-xemacs-mule-p)
|
24
|
889 (set-file-coding-system 'binary t))
|
20
|
890 (cond ((vm-fsfemacs-19-p)
|
|
891 ;; need to do this outside the let because
|
|
892 ;; loading disp-table initializes
|
|
893 ;; standard-display-table.
|
|
894 (require 'disp-table)
|
|
895 (let* ((standard-display-table
|
|
896 (copy-sequence standard-display-table)))
|
|
897 (standard-display-european t)
|
|
898 (setq buffer-display-table standard-display-table))))
|
|
899 (if vm-frame-per-folder
|
|
900 (vm-set-hooks-for-frame-deletion))
|
|
901 (use-local-map vm-mode-map)
|
|
902 (and (vm-toolbar-support-possible-p) vm-use-toolbar
|
|
903 (vm-toolbar-install-toolbar))
|
|
904 (and (vm-menu-support-possible-p)
|
|
905 (vm-menu-install-menus)))
|
|
906 (setq vm-presentation-buffer-handle b)))
|
|
907 (setq b vm-presentation-buffer-handle
|
|
908 vm-presentation-buffer vm-presentation-buffer-handle
|
|
909 vm-mime-decoded nil)
|
|
910 (save-excursion
|
|
911 (set-buffer (vm-buffer-of real-m))
|
|
912 (save-restriction
|
|
913 (widen)
|
|
914 ;; must reference this now so that headers will be in
|
|
915 ;; their final position before the message is copied.
|
|
916 ;; otherwise the vheader offset computed below will be
|
|
917 ;; wrong.
|
|
918 (vm-vheaders-of real-m)
|
|
919 (set-buffer b)
|
|
920 (widen)
|
|
921 (let ((buffer-read-only nil)
|
|
922 (modified (buffer-modified-p)))
|
|
923 (unwind-protect
|
|
924 (progn
|
|
925 (erase-buffer)
|
|
926 (insert-buffer-substring (vm-buffer-of real-m)
|
|
927 (vm-start-of real-m)
|
|
928 (vm-end-of real-m)))
|
|
929 (set-buffer-modified-p modified)))
|
|
930 (setq mm (copy-sequence m))
|
|
931 (vm-set-location-data-of mm (vm-copy (vm-location-data-of m)))
|
|
932 (set-marker (vm-start-of mm) (point-min))
|
|
933 (set-marker (vm-headers-of mm) (+ (vm-start-of mm)
|
|
934 (- (vm-headers-of real-m)
|
|
935 (vm-start-of real-m))))
|
|
936 (set-marker (vm-vheaders-of mm) (+ (vm-start-of mm)
|
|
937 (- (vm-vheaders-of real-m)
|
|
938 (vm-start-of real-m))))
|
|
939 (set-marker (vm-text-of mm) (+ (vm-start-of mm)
|
|
940 (- (vm-text-of real-m)
|
|
941 (vm-start-of real-m))))
|
|
942 (set-marker (vm-text-end-of mm) (+ (vm-start-of mm)
|
|
943 (- (vm-text-end-of real-m)
|
|
944 (vm-start-of real-m))))
|
|
945 (set-marker (vm-end-of mm) (+ (vm-start-of mm)
|
|
946 (- (vm-end-of real-m)
|
|
947 (vm-start-of real-m))))
|
|
948 (setcar vm-message-pointer mm)))))
|
|
949
|
|
950 (fset 'vm-presentation-mode 'vm-mode)
|
|
951 (put 'vm-presentation-mode 'mode-class 'special)
|
|
952
|
24
|
953 (defvar file-coding-system)
|
|
954
|
20
|
955 (defun vm-determine-proper-charset (beg end)
|
|
956 (save-excursion
|
|
957 (save-restriction
|
|
958 (narrow-to-region beg end)
|
|
959 (catch 'done
|
|
960 (goto-char (point-min))
|
24
|
961 (if (vm-xemacs-mule-p)
|
|
962 (let ((charsets (delq 'ascii (charsets-in-region beg end))))
|
|
963 (cond ((null charsets)
|
|
964 "us-ascii")
|
|
965 ((cdr charsets)
|
|
966 (or (car (cdr
|
|
967 (assoc (coding-system-name file-coding-system)
|
|
968 vm-mime-mule-coding-to-charset-alist)))
|
|
969 "iso-2022-jp"))
|
|
970 (t
|
|
971 (or (car (cdr
|
|
972 (vm-string-assoc
|
|
973 (car charsets)
|
|
974 vm-mime-mule-charset-to-charset-alist)))
|
|
975 "unknown"))))
|
|
976 (and (re-search-forward "[^\000-\177]" nil t)
|
|
977 (throw 'done (or vm-mime-8bit-composition-charset
|
|
978 "iso-8859-1")))
|
|
979 (throw 'done "us-ascii"))))))
|
20
|
980
|
|
981 (defun vm-determine-proper-content-transfer-encoding (beg end)
|
|
982 (save-excursion
|
|
983 (save-restriction
|
|
984 (narrow-to-region beg end)
|
|
985 (catch 'done
|
|
986 (goto-char (point-min))
|
|
987 (and (re-search-forward "[\000\015]" nil t)
|
|
988 (throw 'done "binary"))
|
|
989
|
|
990 (let ((toolong nil) bol)
|
|
991 (goto-char (point-min))
|
|
992 (setq bol (point))
|
|
993 (while (and (not (eobp)) (not toolong))
|
|
994 (forward-line)
|
|
995 (setq toolong (> (- (point) bol) 998)
|
|
996 bol (point)))
|
|
997 (and toolong (throw 'done "binary")))
|
|
998
|
|
999 (goto-char (point-min))
|
|
1000 (and (re-search-forward "[\200-\377]" nil t)
|
|
1001 (throw 'done "8bit"))
|
|
1002
|
|
1003 "7bit"))))
|
|
1004
|
|
1005 (defun vm-mime-types-match (type type/subtype)
|
|
1006 (let ((case-fold-search t))
|
|
1007 (cond ((string-match "/" type)
|
|
1008 (if (and (string-match (regexp-quote type) type/subtype)
|
|
1009 (equal 0 (match-beginning 0))
|
|
1010 (equal (length type/subtype) (match-end 0)))
|
|
1011 t
|
|
1012 nil ))
|
|
1013 ((and (string-match (regexp-quote type) type/subtype)
|
|
1014 (equal 0 (match-beginning 0))
|
|
1015 (equal (save-match-data
|
|
1016 (string-match "/" type/subtype (match-end 0)))
|
|
1017 (match-end 0)))))))
|
|
1018
|
|
1019 (defvar native-sound-only-on-console)
|
|
1020
|
|
1021 (defun vm-mime-can-display-internal (layout)
|
|
1022 (let ((type (car (vm-mm-layout-type layout))))
|
|
1023 (cond ((vm-mime-types-match "image/jpeg" type)
|
|
1024 (and (vm-xemacs-p)
|
|
1025 (featurep 'jpeg)
|
|
1026 (eq (device-type) 'x)))
|
|
1027 ((vm-mime-types-match "image/gif" type)
|
|
1028 (and (vm-xemacs-p)
|
|
1029 (featurep 'gif)
|
|
1030 (eq (device-type) 'x)))
|
|
1031 ((vm-mime-types-match "image/png" type)
|
|
1032 (and (vm-xemacs-p)
|
|
1033 (featurep 'png)
|
|
1034 (eq (device-type) 'x)))
|
|
1035 ((vm-mime-types-match "image/tiff" type)
|
|
1036 (and (vm-xemacs-p)
|
|
1037 (featurep 'tiff)
|
|
1038 (eq (device-type) 'x)))
|
|
1039 ((vm-mime-types-match "audio/basic" type)
|
|
1040 (and (vm-xemacs-p)
|
|
1041 (or (featurep 'native-sound)
|
|
1042 (featurep 'nas-sound))
|
|
1043 (or (device-sound-enabled-p)
|
|
1044 (and (featurep 'native-sound)
|
|
1045 (not native-sound-only-on-console)
|
|
1046 (eq (device-type) 'x)))))
|
|
1047 ((vm-mime-types-match "multipart" type) t)
|
|
1048 ((vm-mime-types-match "message/external-body" type) nil)
|
|
1049 ((vm-mime-types-match "message" type) t)
|
|
1050 ((or (vm-mime-types-match "text/plain" type)
|
|
1051 (vm-mime-types-match "text/enriched" type))
|
|
1052 (let ((charset (or (vm-mime-get-parameter layout "charset")
|
|
1053 "us-ascii")))
|
|
1054 (vm-mime-charset-internally-displayable-p charset)))
|
24
|
1055 ;; commented out until I decide whether W3 is safe to use in
|
|
1056 ;; light of the porposed javascript extension and the possibility
|
|
1057 ;; of executing arbitrary Emacs-Lisp code embedded in a page.
|
|
1058 ;;
|
|
1059 ;; ((vm-mime-types-match "text/html" type)
|
|
1060 ;; (condition-case ()
|
|
1061 ;; (progn (require 'w3)
|
|
1062 ;; (fboundp 'w3-region))
|
|
1063 ;; (error nil)))
|
20
|
1064 (t nil))))
|
|
1065
|
|
1066 (defun vm-mime-can-convert (type)
|
|
1067 (let ((alist vm-mime-type-converter-alist)
|
|
1068 ;; fake layout. make it the wrong length so an error will
|
|
1069 ;; be signaled if vm-mime-can-display-internal ever asks
|
|
1070 ;; for one of the other fields
|
|
1071 (fake-layout (make-vector 1 (list nil)))
|
|
1072 (done nil))
|
|
1073 (while (and alist (not done))
|
|
1074 (cond ((and (vm-mime-types-match (car (car alist)) type)
|
|
1075 (or (progn
|
|
1076 (setcar (aref fake-layout 0) (nth 1 (car alist)))
|
|
1077 (vm-mime-can-display-internal fake-layout))
|
|
1078 (vm-mime-find-external-viewer (nth 1 (car alist)))))
|
|
1079 (setq done t))
|
|
1080 (t (setq alist (cdr alist)))))
|
|
1081 (and alist (car alist))))
|
|
1082
|
|
1083 (defun vm-mime-convert-undisplayable-layout (layout)
|
|
1084 (let ((ooo (vm-mime-can-convert (car (vm-mm-layout-type layout)))))
|
26
|
1085 (message "Converting %s to %s..."
|
20
|
1086 (car (vm-mm-layout-type layout))
|
|
1087 (nth 1 ooo))
|
|
1088 (save-excursion
|
|
1089 (set-buffer (generate-new-buffer " *mime object*"))
|
|
1090 (setq vm-message-garbage-alist
|
|
1091 (cons (cons (current-buffer) 'kill-buffer)
|
|
1092 vm-message-garbage-alist))
|
|
1093 (vm-mime-insert-mime-body layout)
|
|
1094 (vm-mime-transfer-decode-region layout (point-min) (point-max))
|
|
1095 (call-process-region (point-min) (point-max) shell-file-name
|
|
1096 t t nil shell-command-switch (nth 2 ooo))
|
|
1097 (goto-char (point-min))
|
|
1098 (insert "Content-Type: " (nth 1 ooo) "\n")
|
|
1099 (insert "Content-Transfer-Encoding: binary\n\n")
|
|
1100 (set-buffer-modified-p nil)
|
26
|
1101 (message "Converting %s to %s... done"
|
20
|
1102 (car (vm-mm-layout-type layout))
|
|
1103 (nth 1 ooo))
|
|
1104 (vector (list (nth 1 ooo))
|
24
|
1105 (list (nth 1 ooo))
|
20
|
1106 "binary"
|
|
1107 (vm-mm-layout-id layout)
|
|
1108 (vm-mm-layout-description layout)
|
|
1109 (vm-mm-layout-disposition layout)
|
24
|
1110 (vm-mm-layout-qdisposition layout)
|
20
|
1111 (vm-marker (point-min))
|
|
1112 (vm-marker (point))
|
|
1113 (vm-marker (point-max))
|
|
1114 nil
|
|
1115 nil ))))
|
|
1116
|
|
1117 (defun vm-mime-should-display-button (layout dont-honor-content-disposition)
|
|
1118 (if (and vm-honor-mime-content-disposition
|
|
1119 (not dont-honor-content-disposition)
|
|
1120 (vm-mm-layout-disposition layout))
|
|
1121 (let ((case-fold-search t))
|
|
1122 (string-match "^attachment$" (car (vm-mm-layout-disposition layout))))
|
|
1123 (let ((i-list vm-auto-displayed-mime-content-types)
|
|
1124 (type (car (vm-mm-layout-type layout)))
|
|
1125 (matched nil))
|
|
1126 (if (eq i-list t)
|
|
1127 nil
|
|
1128 (while (and i-list (not matched))
|
|
1129 (if (vm-mime-types-match (car i-list) type)
|
|
1130 (setq matched t)
|
|
1131 (setq i-list (cdr i-list))))
|
|
1132 (not matched) ))))
|
|
1133
|
|
1134 (defun vm-mime-should-display-internal (layout dont-honor-content-disposition)
|
|
1135 (if (and vm-honor-mime-content-disposition
|
|
1136 (not dont-honor-content-disposition)
|
|
1137 (vm-mm-layout-disposition layout))
|
|
1138 (let ((case-fold-search t))
|
|
1139 (string-match "^inline$" (car (vm-mm-layout-disposition layout))))
|
|
1140 (let ((i-list vm-mime-internal-content-types)
|
|
1141 (type (car (vm-mm-layout-type layout)))
|
|
1142 (matched nil))
|
|
1143 (if (eq i-list t)
|
|
1144 t
|
|
1145 (while (and i-list (not matched))
|
|
1146 (if (vm-mime-types-match (car i-list) type)
|
|
1147 (setq matched t)
|
|
1148 (setq i-list (cdr i-list))))
|
|
1149 matched ))))
|
|
1150
|
|
1151 (defun vm-mime-find-external-viewer (type)
|
|
1152 (let ((e-alist vm-mime-external-content-types-alist)
|
|
1153 (matched nil))
|
|
1154 (while (and e-alist (not matched))
|
|
1155 (if (and (vm-mime-types-match (car (car e-alist)) type)
|
|
1156 (cdr (car e-alist)))
|
|
1157 (setq matched (cdr (car e-alist)))
|
|
1158 (setq e-alist (cdr e-alist))))
|
|
1159 matched ))
|
|
1160 (fset 'vm-mime-should-display-external 'vm-mime-find-external-viewer)
|
|
1161
|
|
1162 (defun vm-mime-delete-button-maybe (extent)
|
|
1163 (let ((buffer-read-only))
|
|
1164 ;; if displayed MIME object should replace the button
|
|
1165 ;; remove the button now.
|
|
1166 (cond ((vm-extent-property extent 'vm-mime-disposable)
|
|
1167 (delete-region (vm-extent-start-position extent)
|
|
1168 (vm-extent-end-position extent))
|
|
1169 (vm-detach-extent extent)))))
|
|
1170
|
|
1171 (defun vm-decode-mime-message ()
|
|
1172 "Decode the MIME objects in the current message.
|
|
1173
|
|
1174 The first time this command is run on a message, decoding is done.
|
|
1175 The second time, buttons for all the objects are displayed instead.
|
|
1176 The third time, the raw, undecoded data is displayed.
|
|
1177
|
|
1178 If decoding, the decoded objects might be displayed immediately, or
|
|
1179 buttons might be displayed that you need to activate to view the
|
|
1180 object. See the documentation for the variables
|
|
1181
|
|
1182 vm-auto-displayed-mime-content-types
|
|
1183 vm-mime-internal-content-types
|
|
1184 vm-mime-external-content-types-alist
|
|
1185
|
|
1186 to see how to control whether you see buttons or objects.
|
|
1187
|
|
1188 If the variable vm-mime-display-function is set, then its value
|
|
1189 is called as a function with no arguments, and none of the
|
|
1190 actions mentioned in the preceding paragraphs are done. At the
|
|
1191 time of the call, the current buffer will be the presentation
|
|
1192 buffer for the folder and a copy of the current message will be
|
|
1193 in the buffer. The function is expected to make the message
|
|
1194 `MIME presentable' to the user in whatever manner it sees fit."
|
|
1195 (interactive)
|
|
1196 (vm-follow-summary-cursor)
|
|
1197 (vm-select-folder-buffer)
|
|
1198 (vm-check-for-killed-summary)
|
|
1199 (vm-check-for-killed-presentation)
|
|
1200 (vm-error-if-folder-empty)
|
|
1201 (if (and (not vm-display-using-mime)
|
|
1202 (null vm-mime-display-function))
|
|
1203 (error "MIME display disabled, set vm-display-using-mime non-nil to enable."))
|
|
1204 (if vm-mime-display-function
|
|
1205 (progn
|
|
1206 (vm-make-presentation-copy (car vm-message-pointer))
|
|
1207 (set-buffer vm-presentation-buffer)
|
|
1208 (funcall vm-mime-display-function))
|
|
1209 (if vm-mime-decoded
|
|
1210 (if (eq vm-mime-decoded 'decoded)
|
|
1211 (let ((vm-preview-read-messages nil)
|
|
1212 (vm-auto-decode-mime-messages t)
|
|
1213 (vm-honor-mime-content-disposition nil)
|
|
1214 (vm-auto-displayed-mime-content-types '("multipart")))
|
|
1215 (setq vm-mime-decoded nil)
|
|
1216 (intern (buffer-name) vm-buffers-needing-display-update)
|
|
1217 (save-excursion
|
|
1218 (vm-preview-current-message))
|
|
1219 (setq vm-mime-decoded 'buttons))
|
|
1220 (let ((vm-preview-read-messages nil)
|
|
1221 (vm-auto-decode-mime-messages nil))
|
|
1222 (intern (buffer-name) vm-buffers-needing-display-update)
|
|
1223 (vm-preview-current-message)))
|
|
1224 (let ((layout (vm-mm-layout (car vm-message-pointer)))
|
|
1225 (m (car vm-message-pointer)))
|
26
|
1226 (message "Decoding MIME message...")
|
20
|
1227 (cond ((stringp layout)
|
|
1228 (error "Invalid MIME message: %s" layout)))
|
|
1229 (if (vm-mime-plain-message-p m)
|
|
1230 (error "Message needs no decoding."))
|
|
1231 (or vm-presentation-buffer
|
|
1232 ;; maybe user killed it
|
|
1233 (error "No presentation buffer."))
|
|
1234 (set-buffer vm-presentation-buffer)
|
24
|
1235 (if (and (interactive-p) (eq vm-system-state 'previewing))
|
|
1236 (let ((vm-display-using-mime nil))
|
|
1237 (vm-show-current-message)))
|
20
|
1238 (setq m (car vm-message-pointer))
|
|
1239 (vm-save-restriction
|
|
1240 (widen)
|
|
1241 (goto-char (vm-text-of m))
|
|
1242 (let ((buffer-read-only nil)
|
|
1243 (modified (buffer-modified-p)))
|
|
1244 (unwind-protect
|
|
1245 (save-excursion
|
|
1246 (and (not (eq (vm-mm-encoded-header m) 'none))
|
|
1247 (vm-decode-mime-message-headers m))
|
|
1248 (if (vectorp layout)
|
|
1249 (progn
|
|
1250 (vm-decode-mime-layout layout)
|
|
1251 (delete-region (point) (point-max)))))
|
|
1252 (set-buffer-modified-p modified))))
|
|
1253 (save-excursion (set-buffer vm-mail-buffer)
|
|
1254 (setq vm-mime-decoded 'decoded))
|
|
1255 (intern (buffer-name vm-mail-buffer) vm-buffers-needing-display-update)
|
|
1256 (vm-update-summary-and-mode-line)
|
26
|
1257 (message "Decoding MIME message... done"))))
|
20
|
1258 (vm-display nil nil '(vm-decode-mime-message)
|
|
1259 '(vm-decode-mime-message reading-message)))
|
|
1260
|
|
1261 (defun vm-decode-mime-layout (layout &optional dont-honor-c-d)
|
|
1262 (let ((modified (buffer-modified-p)) type type-no-subtype (extent nil))
|
|
1263 (unwind-protect
|
|
1264 (progn
|
|
1265 (if (not (vectorp layout))
|
|
1266 (progn
|
|
1267 (setq extent layout
|
|
1268 layout (vm-extent-property extent 'vm-mime-layout))
|
|
1269 (goto-char (vm-extent-start-position extent))))
|
|
1270 (setq type (downcase (car (vm-mm-layout-type layout)))
|
|
1271 type-no-subtype (car (vm-parse type "\\([^/]+\\)")))
|
|
1272 (cond ((and (vm-mime-should-display-button layout dont-honor-c-d)
|
|
1273 (or (condition-case nil
|
|
1274 (funcall (intern
|
|
1275 (concat "vm-mime-display-button-"
|
|
1276 type))
|
|
1277 layout)
|
|
1278 (void-function nil))
|
|
1279 (condition-case nil
|
|
1280 (funcall (intern
|
|
1281 (concat "vm-mime-display-button-"
|
|
1282 type-no-subtype))
|
|
1283 layout)
|
|
1284 (void-function nil)))))
|
|
1285 ((and (vm-mime-should-display-internal layout dont-honor-c-d)
|
|
1286 (condition-case nil
|
|
1287 (funcall (intern
|
|
1288 (concat "vm-mime-display-internal-"
|
|
1289 type))
|
|
1290 layout)
|
|
1291 (void-function nil))))
|
|
1292 ((vm-mime-types-match "multipart" type)
|
|
1293 (or (condition-case nil
|
|
1294 (funcall (intern
|
|
1295 (concat "vm-mime-display-internal-"
|
|
1296 type))
|
|
1297 layout)
|
|
1298 (void-function nil))
|
|
1299 (vm-mime-display-internal-multipart/mixed layout)))
|
|
1300 ((and (vm-mime-should-display-external type)
|
|
1301 (vm-mime-display-external-generic layout))
|
|
1302 (and extent (vm-set-extent-property
|
|
1303 extent 'vm-mime-disposable nil)))
|
|
1304 ((vm-mime-can-convert type)
|
|
1305 (vm-decode-mime-layout
|
|
1306 (vm-mime-convert-undisplayable-layout layout)))
|
|
1307 ((and (or (vm-mime-types-match "message" type)
|
|
1308 (vm-mime-types-match "text" type))
|
|
1309 ;; display unmatched message and text types as
|
|
1310 ;; text/plain.
|
|
1311 (vm-mime-display-internal-text/plain layout)))
|
|
1312 (t (vm-mime-display-internal-application/octet-stream
|
|
1313 (or extent layout))))
|
|
1314 (and extent (vm-mime-delete-button-maybe extent)))
|
|
1315 (set-buffer-modified-p modified)))
|
|
1316 t )
|
|
1317
|
|
1318 (defun vm-mime-display-button-text (layout)
|
|
1319 (vm-mime-display-button-xxxx layout t))
|
|
1320
|
24
|
1321 ;; commented out until I decide whether W3 is safe to use in
|
|
1322 ;; light of the proposed javascript extension and the possibility
|
|
1323 ;; of executing arbitrary Emacs-Lisp code embedded in a page.
|
|
1324 ;;
|
|
1325 ;;(defun vm-mime-display-internal-text/html (layout)
|
|
1326 ;; (let ((buffer-read-only nil)
|
|
1327 ;; (work-buffer nil))
|
26
|
1328 ;; (message "Inlining text/html, be patient...")
|
24
|
1329 ;; ;; w3-region is not as tame as we would like.
|
|
1330 ;; ;; make sure the yoke is firmly attached.
|
|
1331 ;; (unwind-protect
|
|
1332 ;; (progn
|
|
1333 ;; (save-excursion
|
|
1334 ;; (set-buffer (setq work-buffer
|
|
1335 ;; (generate-new-buffer " *workbuf*")))
|
|
1336 ;; (vm-mime-insert-mime-body layout)
|
|
1337 ;; (vm-mime-transfer-decode-region layout (point-min) (point-max))
|
|
1338 ;; (save-excursion
|
|
1339 ;; (save-window-excursion
|
|
1340 ;; (w3-region (point-min) (point-max)))))
|
|
1341 ;; (insert-buffer-substring work-buffer))
|
|
1342 ;; (and work-buffer (kill-buffer work-buffer)))
|
26
|
1343 ;; (message "Inlining text/html... done")
|
24
|
1344 ;; t ))
|
20
|
1345
|
|
1346 (defun vm-mime-display-internal-text/plain (layout &optional ignore-urls)
|
24
|
1347 (let ((start (point)) end old-size
|
20
|
1348 (buffer-read-only nil)
|
|
1349 (charset (or (vm-mime-get-parameter layout "charset") "us-ascii")))
|
|
1350 (if (not (vm-mime-charset-internally-displayable-p charset))
|
|
1351 nil
|
|
1352 (vm-mime-insert-mime-body layout)
|
|
1353 (setq end (point-marker))
|
|
1354 (vm-mime-transfer-decode-region layout start end)
|
24
|
1355 (setq old-size (buffer-size))
|
20
|
1356 (vm-mime-charset-decode-region charset start end)
|
24
|
1357 (set-marker end (+ end (- (buffer-size) old-size)))
|
20
|
1358 (or ignore-urls (vm-energize-urls-in-message-region start end))
|
24
|
1359 (goto-char end)
|
20
|
1360 t )))
|
|
1361
|
|
1362 (defun vm-mime-display-internal-text/enriched (layout)
|
|
1363 (require 'enriched)
|
|
1364 (let ((start (point)) end
|
|
1365 (buffer-read-only nil)
|
|
1366 (enriched-verbose t))
|
26
|
1367 (message "Decoding text/enriched, be patient...")
|
20
|
1368 (vm-mime-insert-mime-body layout)
|
|
1369 (setq end (point-marker))
|
|
1370 (vm-mime-transfer-decode-region layout start end)
|
|
1371 ;; enriched-decode expects a couple of headers at the top of
|
|
1372 ;; the region and will remove anything that looks like a
|
|
1373 ;; header. Put a header section here for it to eat so it
|
|
1374 ;; won't eat message text instead.
|
|
1375 (goto-char start)
|
|
1376 (insert "Comment: You should not see this header\n\n")
|
|
1377 (enriched-decode start end)
|
|
1378 (vm-energize-urls-in-message-region start end)
|
|
1379 (goto-char end)
|
26
|
1380 (message "Decoding text/enriched... done")
|
20
|
1381 t ))
|
|
1382
|
|
1383 (defun vm-mime-display-external-generic (layout)
|
|
1384 (let ((program-list (vm-mime-find-external-viewer
|
|
1385 (car (vm-mm-layout-type layout))))
|
|
1386 (process (nth 0 (vm-mm-layout-cache layout)))
|
|
1387 (tempfile (nth 1 (vm-mm-layout-cache layout)))
|
|
1388 (buffer-read-only nil)
|
|
1389 (start (point))
|
|
1390 end)
|
|
1391 (if (and (processp process) (eq (process-status process) 'run))
|
|
1392 nil
|
|
1393 (cond ((or (null tempfile) (null (file-exists-p tempfile)))
|
|
1394 (vm-mime-insert-mime-body layout)
|
|
1395 (setq end (point-marker))
|
|
1396 (vm-mime-transfer-decode-region layout start end)
|
|
1397 (setq tempfile (vm-make-tempfile-name))
|
24
|
1398 (let ((buffer-file-type buffer-file-type)
|
|
1399 file-coding-system)
|
|
1400 ;; Tell DOS/Windows NT whether the file is binary
|
|
1401 (setq buffer-file-type (not (vm-mime-text-type-p layout)))
|
|
1402 ;; Tell XEmacs/MULE not to mess with the bits unless
|
|
1403 ;; this is a text type.
|
26
|
1404 (if (vm-xemacs-mule-p)
|
24
|
1405 (if (vm-mime-text-type-p layout)
|
|
1406 (set-file-coding-system 'no-conversion nil)
|
|
1407 (set-file-coding-system 'binary t)))
|
|
1408 (write-region start end tempfile nil 0))
|
20
|
1409 (delete-region start end)
|
|
1410 (save-excursion
|
|
1411 (vm-select-folder-buffer)
|
|
1412 (setq vm-folder-garbage-alist
|
|
1413 (cons (cons tempfile 'delete-file)
|
|
1414 vm-folder-garbage-alist)))))
|
26
|
1415 (message "Launching %s..." (mapconcat 'identity
|
20
|
1416 program-list
|
|
1417 " "))
|
|
1418 (setq process
|
|
1419 (apply 'start-process
|
|
1420 (format "view %25s" (vm-mime-layout-description layout))
|
|
1421 nil (append program-list (list tempfile))))
|
|
1422 (process-kill-without-query process t)
|
26
|
1423 (message "Launching %s... done" (mapconcat 'identity
|
20
|
1424 program-list
|
|
1425 " "))
|
|
1426 (save-excursion
|
|
1427 (vm-select-folder-buffer)
|
|
1428 (setq vm-message-garbage-alist
|
|
1429 (cons (cons process 'delete-process)
|
|
1430 vm-message-garbage-alist)))
|
|
1431 (vm-set-mm-layout-cache layout (list process tempfile))))
|
|
1432 t )
|
|
1433
|
|
1434 (defun vm-mime-display-internal-application/octet-stream (layout)
|
|
1435 (if (vectorp layout)
|
|
1436 (let ((buffer-read-only nil)
|
|
1437 (description (vm-mm-layout-description layout)))
|
|
1438 (vm-mime-insert-button
|
24
|
1439 (format "%-35.35s [%s to save to a file]"
|
20
|
1440 (vm-mime-layout-description layout)
|
|
1441 (if (vm-mouse-support-possible-p)
|
|
1442 "Click mouse-2"
|
|
1443 "Press RETURN"))
|
|
1444 (function
|
|
1445 (lambda (layout)
|
|
1446 (save-excursion
|
|
1447 (vm-mime-display-internal-application/octet-stream layout))))
|
|
1448 layout nil))
|
|
1449 (goto-char (vm-extent-start-position layout))
|
|
1450 (setq layout (vm-extent-property layout 'vm-mime-layout))
|
|
1451 ;; support old "name" paramater for application/octet-stream
|
|
1452 ;; but don't override the "filename" parameter extracted from
|
|
1453 ;; Content-Disposition, if any.
|
|
1454 (let ((default-filename
|
|
1455 (if (vm-mime-get-disposition-parameter layout "filename")
|
|
1456 nil
|
|
1457 (vm-mime-get-parameter layout "name"))))
|
|
1458 (vm-mime-send-body-to-file layout default-filename)))
|
|
1459 t )
|
|
1460 (fset 'vm-mime-display-button-application
|
|
1461 'vm-mime-display-internal-application/octet-stream)
|
|
1462
|
|
1463 (defun vm-mime-display-button-image (layout)
|
|
1464 (vm-mime-display-button-xxxx layout t))
|
|
1465
|
|
1466 (defun vm-mime-display-button-audio (layout)
|
|
1467 (vm-mime-display-button-xxxx layout nil))
|
|
1468
|
|
1469 (defun vm-mime-display-button-video (layout)
|
|
1470 (vm-mime-display-button-xxxx layout t))
|
|
1471
|
|
1472 (defun vm-mime-display-button-message (layout)
|
|
1473 (vm-mime-display-button-xxxx layout t))
|
|
1474
|
|
1475 (defun vm-mime-display-button-multipart (layout)
|
|
1476 (vm-mime-display-button-xxxx layout t))
|
|
1477
|
|
1478 (defun vm-mime-display-internal-multipart/mixed (layout)
|
|
1479 (let ((part-list (vm-mm-layout-parts layout)))
|
|
1480 (while part-list
|
|
1481 (vm-decode-mime-layout (car part-list))
|
|
1482 (setq part-list (cdr part-list)))
|
|
1483 t ))
|
|
1484
|
|
1485 (defun vm-mime-display-internal-multipart/alternative (layout)
|
|
1486 (let (best-layout)
|
|
1487 (cond ((eq vm-mime-alternative-select-method 'best)
|
|
1488 (let ((done nil)
|
|
1489 (best nil)
|
|
1490 part-list type)
|
|
1491 (setq part-list (vm-mm-layout-parts layout)
|
|
1492 part-list (nreverse (copy-sequence part-list)))
|
|
1493 (while (and part-list (not done))
|
|
1494 (setq type (car (vm-mm-layout-type (car part-list))))
|
|
1495 (if (or (vm-mime-can-display-internal (car part-list))
|
|
1496 (vm-mime-find-external-viewer type))
|
|
1497 (setq best (car part-list)
|
|
1498 done t)
|
|
1499 (setq part-list (cdr part-list))))
|
|
1500 (setq best-layout (or best (car (vm-mm-layout-parts layout))))))
|
|
1501 ((eq vm-mime-alternative-select-method 'best-internal)
|
|
1502 (let ((done nil)
|
|
1503 (best nil)
|
|
1504 (second-best nil)
|
|
1505 part-list type)
|
|
1506 (setq part-list (vm-mm-layout-parts layout)
|
|
1507 part-list (nreverse (copy-sequence part-list)))
|
|
1508 (while (and part-list (not done))
|
|
1509 (setq type (car (vm-mm-layout-type (car part-list))))
|
|
1510 (cond ((vm-mime-can-display-internal (car part-list))
|
|
1511 (setq best (car part-list)
|
|
1512 done t))
|
|
1513 ((and (null second-best)
|
|
1514 (vm-mime-find-external-viewer type))
|
|
1515 (setq second-best (car part-list))))
|
|
1516 (setq part-list (cdr part-list)))
|
|
1517 (setq best-layout (or best second-best
|
|
1518 (car (vm-mm-layout-parts layout)))))))
|
|
1519 (vm-decode-mime-layout best-layout)))
|
|
1520
|
|
1521 (defun vm-mime-display-button-multipart/parallel (layout)
|
|
1522 (vm-mime-insert-button
|
24
|
1523 (format "%-35.35s [%s to display in parallel]"
|
20
|
1524 (vm-mime-layout-description layout)
|
|
1525 (if (vm-mouse-support-possible-p)
|
|
1526 "Click mouse-2"
|
|
1527 "Press RETURN"))
|
|
1528 (function
|
|
1529 (lambda (layout)
|
|
1530 (save-excursion
|
|
1531 (let ((vm-auto-displayed-mime-content-types t))
|
|
1532 (vm-decode-mime-layout layout t)))))
|
|
1533 layout t))
|
|
1534
|
|
1535 (fset 'vm-mime-display-internal-multipart/parallel
|
|
1536 'vm-mime-display-internal-multipart/mixed)
|
|
1537
|
|
1538 (defun vm-mime-display-internal-multipart/digest (layout)
|
|
1539 (if (vectorp layout)
|
|
1540 (let ((buffer-read-only nil))
|
|
1541 (vm-mime-insert-button
|
24
|
1542 (format "%-35.35s [%s to display]"
|
20
|
1543 (vm-mime-layout-description layout)
|
|
1544 (if (vm-mouse-support-possible-p)
|
|
1545 "Click mouse-2"
|
|
1546 "Press RETURN"))
|
|
1547 (function
|
|
1548 (lambda (layout)
|
|
1549 (save-excursion
|
|
1550 (vm-mime-display-internal-multipart/digest layout))))
|
|
1551 layout nil))
|
|
1552 (goto-char (vm-extent-start-position layout))
|
|
1553 (setq layout (vm-extent-property layout 'vm-mime-layout))
|
|
1554 (set-buffer (generate-new-buffer (format "digest from %s/%s"
|
|
1555 (buffer-name vm-mail-buffer)
|
|
1556 (vm-number-of
|
|
1557 (car vm-message-pointer)))))
|
|
1558 (setq vm-folder-type vm-default-folder-type)
|
|
1559 (vm-mime-burst-layout layout nil)
|
|
1560 (vm-save-buffer-excursion
|
|
1561 (vm-goto-new-folder-frame-maybe 'folder)
|
|
1562 (vm-mode))
|
|
1563 ;; temp buffer, don't offer to save it.
|
|
1564 (setq buffer-offer-save nil)
|
|
1565 (vm-display nil nil (list this-command) '(vm-mode startup)))
|
|
1566 t )
|
|
1567 (fset 'vm-mime-display-button-multipart/digest
|
|
1568 'vm-mime-display-internal-multipart/digest)
|
|
1569
|
|
1570 (defun vm-mime-display-internal-message/rfc822 (layout)
|
|
1571 (if (vectorp layout)
|
|
1572 (let ((buffer-read-only nil))
|
|
1573 (vm-mime-insert-button
|
24
|
1574 (format "%-35.35s [%s to display]"
|
20
|
1575 (vm-mime-layout-description layout)
|
|
1576 (if (vm-mouse-support-possible-p)
|
|
1577 "Click mouse-2"
|
|
1578 "Press RETURN"))
|
|
1579 (function
|
|
1580 (lambda (layout)
|
|
1581 (save-excursion
|
|
1582 (vm-mime-display-internal-message/rfc822 layout))))
|
|
1583 layout nil))
|
|
1584 (goto-char (vm-extent-start-position layout))
|
|
1585 (setq layout (vm-extent-property layout 'vm-mime-layout))
|
|
1586 (set-buffer (generate-new-buffer
|
|
1587 (format "message from %s/%s"
|
|
1588 (buffer-name vm-mail-buffer)
|
|
1589 (vm-number-of
|
|
1590 (car vm-message-pointer)))))
|
|
1591 (setq vm-folder-type vm-default-folder-type)
|
|
1592 (vm-mime-burst-layout layout nil)
|
|
1593 (set-buffer-modified-p nil)
|
|
1594 (vm-save-buffer-excursion
|
|
1595 (vm-goto-new-folder-frame-maybe 'folder)
|
|
1596 (vm-mode))
|
|
1597 ;; temp buffer, don't offer to save it.
|
|
1598 (setq buffer-offer-save nil)
|
|
1599 (vm-display (or vm-presentation-buffer (current-buffer)) t
|
|
1600 (list this-command) '(vm-mode startup)))
|
|
1601 t )
|
|
1602 (fset 'vm-mime-display-button-message/rfc822
|
|
1603 'vm-mime-display-internal-message/rfc822)
|
|
1604
|
|
1605 (defun vm-mime-display-internal-message/partial (layout)
|
|
1606 (if (vectorp layout)
|
|
1607 (let ((buffer-read-only nil)
|
|
1608 (number (vm-mime-get-parameter layout "number"))
|
|
1609 (total (vm-mime-get-parameter layout "total")))
|
|
1610 (vm-mime-insert-button
|
24
|
1611 (format "%-35.35s [%s to attempt assembly]"
|
20
|
1612 (concat (vm-mime-layout-description layout)
|
|
1613 (and number (concat ", part " number))
|
|
1614 (and number total (concat " of " total)))
|
|
1615 (if (vm-mouse-support-possible-p)
|
|
1616 "Click mouse-2"
|
|
1617 "Press RETURN"))
|
|
1618 (function
|
|
1619 (lambda (layout)
|
|
1620 (save-excursion
|
|
1621 (vm-mime-display-internal-message/partial layout))))
|
|
1622 layout nil))
|
26
|
1623 (message "Assembling message...")
|
20
|
1624 (let ((parts nil)
|
|
1625 (missing nil)
|
|
1626 (work-buffer nil)
|
|
1627 extent id o number total m i prev part-header-pos
|
|
1628 p-id p-number p-total p-list)
|
|
1629 (setq extent layout
|
|
1630 layout (vm-extent-property extent 'vm-mime-layout)
|
|
1631 id (vm-mime-get-parameter layout "id"))
|
|
1632 (if (null id)
|
|
1633 (vm-mime-error
|
|
1634 "message/partial message missing id parameter"))
|
|
1635 (save-excursion
|
|
1636 (set-buffer (marker-buffer (vm-mm-layout-body-start layout)))
|
|
1637 (save-excursion
|
|
1638 (save-restriction
|
|
1639 (widen)
|
|
1640 (goto-char (point-min))
|
|
1641 (while (and (search-forward id nil t)
|
|
1642 (setq m (vm-message-at-point)))
|
|
1643 (setq o (vm-mm-layout m))
|
|
1644 (if (not (vectorp o))
|
|
1645 nil
|
|
1646 (setq p-list (vm-mime-find-message/partials o id))
|
|
1647 (while p-list
|
|
1648 (setq p-id (vm-mime-get-parameter (car p-list) "id"))
|
|
1649 (setq p-total (vm-mime-get-parameter (car p-list) "total"))
|
|
1650 (if (null p-total)
|
|
1651 nil
|
|
1652 (setq p-total (string-to-int p-total))
|
|
1653 (if (< p-total 1)
|
|
1654 (vm-mime-error "message/partial specified part total < 0, %d" p-total))
|
|
1655 (if total
|
|
1656 (if (not (= total p-total))
|
|
1657 (vm-mime-error "message/partial speificed total differs between parts, (%d != %d)" p-total total))
|
|
1658 (setq total p-total)))
|
|
1659 (setq p-number (vm-mime-get-parameter (car p-list) "number"))
|
|
1660 (if (null p-number)
|
|
1661 (vm-mime-error
|
|
1662 "message/partial message missing number parameter"))
|
|
1663 (setq p-number (string-to-int p-number))
|
|
1664 (if (< p-number 1)
|
|
1665 (vm-mime-error "message/partial part number < 0, %d"
|
|
1666 p-number))
|
|
1667 (if (and total (> p-number total))
|
|
1668 (vm-mime-error "message/partial part number greater than expected number of parts, (%d > %d)" p-number total))
|
|
1669 (setq parts (cons (list p-number (car p-list)) parts)
|
|
1670 p-list (cdr p-list))))
|
|
1671 (goto-char (vm-mm-layout-body-end o))))))
|
|
1672 (if (null total)
|
|
1673 (vm-mime-error "total number of parts not specified in any message/partial part"))
|
|
1674 (setq parts (sort parts
|
|
1675 (function
|
|
1676 (lambda (p q)
|
|
1677 (< (car p)
|
|
1678 (car q))))))
|
|
1679 (setq i 0
|
|
1680 p-list parts)
|
|
1681 (while p-list
|
|
1682 (cond ((< i (car (car p-list)))
|
|
1683 (vm-increment i)
|
|
1684 (cond ((not (= i (car (car p-list))))
|
|
1685 (setq missing (cons i missing)))
|
|
1686 (t (setq prev p-list
|
|
1687 p-list (cdr p-list)))))
|
|
1688 (t
|
|
1689 ;; remove duplicate part
|
|
1690 (setcdr prev (cdr p-list))
|
|
1691 (setq p-list (cdr p-list)))))
|
|
1692 (while (< i total)
|
|
1693 (vm-increment i)
|
|
1694 (setq missing (cons i missing)))
|
|
1695 (if missing
|
|
1696 (vm-mime-error "part%s %s%s missing"
|
|
1697 (if (cdr missing) "s" "")
|
|
1698 (mapconcat
|
|
1699 (function identity)
|
|
1700 (nreverse (mapcar 'int-to-string
|
|
1701 (or (cdr missing) missing)))
|
|
1702 ", ")
|
|
1703 (if (cdr missing)
|
|
1704 (concat " and " (car missing))
|
|
1705 "")))
|
|
1706 (set-buffer (generate-new-buffer "assembled message"))
|
|
1707 (setq vm-folder-type vm-default-folder-type)
|
|
1708 (vm-mime-insert-mime-headers (car (cdr (car parts))))
|
|
1709 (goto-char (point-min))
|
|
1710 (vm-reorder-message-headers
|
|
1711 nil nil
|
|
1712 "\\(Encrypted\\|Content-\\|MIME-Version\\|Message-ID\\|Subject\\|X-VM-\\|Status\\)")
|
|
1713 (goto-char (point-max))
|
|
1714 (setq part-header-pos (point))
|
|
1715 (while parts
|
|
1716 (vm-mime-insert-mime-body (car (cdr (car parts))))
|
|
1717 (setq parts (cdr parts)))
|
|
1718 (goto-char part-header-pos)
|
|
1719 (vm-reorder-message-headers
|
|
1720 nil '("Subject" "MIME-Version" "Content-" "Message-ID" "Encrypted") nil)
|
|
1721 (vm-munge-message-separators vm-folder-type (point-min) (point-max))
|
|
1722 (goto-char (point-min))
|
|
1723 (insert (vm-leading-message-separator))
|
|
1724 (goto-char (point-max))
|
|
1725 (insert (vm-trailing-message-separator))
|
|
1726 (set-buffer-modified-p nil)
|
26
|
1727 (message "Assembling message... done")
|
20
|
1728 (vm-save-buffer-excursion
|
|
1729 (vm-goto-new-folder-frame-maybe 'folder)
|
|
1730 (vm-mode))
|
|
1731 ;; temp buffer, don't offer to save it.
|
|
1732 (setq buffer-offer-save nil)
|
|
1733 (vm-display (or vm-presentation-buffer (current-buffer)) t
|
|
1734 (list this-command) '(vm-mode startup)))
|
|
1735 t ))
|
|
1736 (fset 'vm-mime-display-button-message/partial
|
|
1737 'vm-mime-display-internal-message/partial)
|
|
1738
|
|
1739 (defun vm-mime-display-internal-image-xxxx (layout feature name)
|
|
1740 (if (and (vm-xemacs-p)
|
|
1741 (featurep feature)
|
|
1742 (eq (device-type) 'x))
|
|
1743 (let ((start (point)) end tempfile g e
|
|
1744 (buffer-read-only nil))
|
|
1745 (if (vm-mm-layout-cache layout)
|
|
1746 (setq g (vm-mm-layout-cache layout))
|
|
1747 (vm-mime-insert-mime-body layout)
|
|
1748 (setq end (point-marker))
|
|
1749 (vm-mime-transfer-decode-region layout start end)
|
|
1750 (setq tempfile (vm-make-tempfile-name))
|
24
|
1751 ;; coding system for presentation buffer is binary
|
20
|
1752 (write-region start end tempfile nil 0)
|
26
|
1753 (message "Creating %s glyph..." name)
|
20
|
1754 (setq g (make-glyph
|
|
1755 (list (vector feature ':file tempfile)
|
|
1756 (vector 'string
|
|
1757 ':data
|
|
1758 (format "[Unknown %s image encoding]\n"
|
|
1759 name)))))
|
26
|
1760 (message "")
|
20
|
1761 (vm-set-mm-layout-cache layout g)
|
|
1762 (save-excursion
|
|
1763 (vm-select-folder-buffer)
|
|
1764 (setq vm-folder-garbage-alist
|
|
1765 (cons (cons tempfile 'delete-file)
|
|
1766 vm-folder-garbage-alist)))
|
|
1767 (delete-region start end))
|
|
1768 (if (not (bolp))
|
|
1769 (insert-char ?\n 2)
|
|
1770 (insert-char ?\n 1))
|
|
1771 (setq e (vm-make-extent (1- (point)) (point)))
|
|
1772 (vm-set-extent-property e 'begin-glyph g)
|
|
1773 t )))
|
|
1774
|
|
1775 (defun vm-mime-display-internal-image/gif (layout)
|
|
1776 (vm-mime-display-internal-image-xxxx layout 'gif "GIF"))
|
|
1777
|
|
1778 (defun vm-mime-display-internal-image/jpeg (layout)
|
|
1779 (vm-mime-display-internal-image-xxxx layout 'jpeg "JPEG"))
|
|
1780
|
|
1781 (defun vm-mime-display-internal-image/png (layout)
|
|
1782 (vm-mime-display-internal-image-xxxx layout 'png "PNG"))
|
|
1783
|
|
1784 (defun vm-mime-display-internal-image/tiff (layout)
|
|
1785 (vm-mime-display-internal-image-xxxx layout 'tiff "TIFF"))
|
|
1786
|
|
1787 (defun vm-mime-display-internal-audio/basic (layout)
|
|
1788 (if (and (vm-xemacs-p)
|
|
1789 (or (featurep 'native-sound)
|
|
1790 (featurep 'nas-sound))
|
|
1791 (or (device-sound-enabled-p)
|
|
1792 (and (featurep 'native-sound)
|
|
1793 (not native-sound-only-on-console)
|
|
1794 (eq (device-type) 'x))))
|
|
1795 (let ((start (point)) end tempfile
|
|
1796 (buffer-read-only nil))
|
|
1797 (if (vm-mm-layout-cache layout)
|
|
1798 (setq tempfile (vm-mm-layout-cache layout))
|
|
1799 (vm-mime-insert-mime-body layout)
|
|
1800 (setq end (point-marker))
|
|
1801 (vm-mime-transfer-decode-region layout start end)
|
|
1802 (setq tempfile (vm-make-tempfile-name))
|
24
|
1803 ;; coding system for presentation buffer is binary
|
20
|
1804 (write-region start end tempfile nil 0)
|
|
1805 (vm-set-mm-layout-cache layout tempfile)
|
|
1806 (save-excursion
|
|
1807 (vm-select-folder-buffer)
|
|
1808 (setq vm-folder-garbage-alist
|
|
1809 (cons (cons tempfile 'delete-file)
|
|
1810 vm-folder-garbage-alist)))
|
|
1811 (delete-region start end))
|
|
1812 (start-itimer "audioplayer"
|
|
1813 (list 'lambda nil (list 'play-sound-file tempfile))
|
|
1814 1)
|
|
1815 t )
|
|
1816 nil ))
|
|
1817
|
|
1818 (defun vm-mime-display-button-xxxx (layout disposable)
|
|
1819 (let ((description (vm-mime-layout-description layout)))
|
|
1820 (vm-mime-insert-button
|
24
|
1821 (format "%-35.35s [%s to display]"
|
20
|
1822 description
|
|
1823 (if (vm-mouse-support-possible-p) "Click mouse-2" "Press RETURN"))
|
|
1824 (function
|
|
1825 (lambda (layout)
|
|
1826 (save-excursion
|
|
1827 (let ((vm-auto-displayed-mime-content-types t))
|
|
1828 (vm-decode-mime-layout layout t)))))
|
|
1829 layout disposable)
|
|
1830 t ))
|
|
1831
|
|
1832 (defun vm-mime-run-display-function-at-point (&optional function)
|
|
1833 (interactive)
|
|
1834 ;; save excursion to keep point from moving. its motion would
|
|
1835 ;; drag window point along, to a place arbitrarily far from
|
|
1836 ;; where it was when the user triggered the button.
|
|
1837 (save-excursion
|
|
1838 (cond ((vm-fsfemacs-19-p)
|
|
1839 (let (o-list o (found nil))
|
|
1840 (setq o-list (overlays-at (point)))
|
|
1841 (while (and o-list (not found))
|
|
1842 (cond ((overlay-get (car o-list) 'vm-mime-layout)
|
|
1843 (setq found t)
|
|
1844 (funcall (or function (overlay-get (car o-list)
|
|
1845 'vm-mime-function))
|
|
1846 (car o-list))))
|
|
1847 (setq o-list (cdr o-list)))))
|
|
1848 ((vm-xemacs-p)
|
|
1849 (let ((e (extent-at (point) nil 'vm-mime-layout)))
|
|
1850 (funcall (or function (extent-property e 'vm-mime-function))
|
|
1851 e))))))
|
|
1852
|
|
1853 ;; for the karking compiler
|
|
1854 (defvar vm-menu-mime-dispose-menu)
|
|
1855
|
24
|
1856 (defun vm-mime-set-extent-glyph-for-layout (e layout)
|
|
1857 (if (and (vm-xemacs-p) (fboundp 'make-glyph)
|
|
1858 (eq (device-type) 'x) (> (device-bitplanes) 15))
|
|
1859 (let ((type (car (vm-mm-layout-type layout)))
|
|
1860 (dir vm-image-directory)
|
|
1861 glyph)
|
|
1862 (setq glyph
|
|
1863 (cond ((vm-mime-types-match "text" type)
|
|
1864 (make-glyph (vector
|
|
1865 'xpm ':file
|
|
1866 (expand-file-name "document.xpm" dir))))
|
|
1867 ((vm-mime-types-match "image" type)
|
|
1868 (make-glyph (vector
|
|
1869 'gif ':file
|
|
1870 (expand-file-name "mona_stamp.gif" dir))))
|
|
1871 ((vm-mime-types-match "audio" type)
|
|
1872 (make-glyph (vector
|
|
1873 'xpm ':file
|
|
1874 (expand-file-name "audio_stamp.xpm" dir))))
|
|
1875 ((vm-mime-types-match "video" type)
|
|
1876 (make-glyph (vector
|
|
1877 'xpm ':file
|
|
1878 (expand-file-name "film.xpm" dir))))
|
|
1879 ((vm-mime-types-match "message" type)
|
|
1880 (make-glyph (vector
|
|
1881 'xpm ':file
|
|
1882 (expand-file-name "message.xpm" dir))))
|
|
1883 ((vm-mime-types-match "application" type)
|
|
1884 (make-glyph (vector
|
|
1885 'xpm ':file
|
|
1886 (expand-file-name "gear.xpm" dir))))
|
|
1887 ((vm-mime-types-match "multipart" type)
|
|
1888 (make-glyph (vector
|
|
1889 'xpm ':file
|
|
1890 (expand-file-name "stuffed_box.xpm" dir))))
|
|
1891 (t nil)))
|
|
1892 (and glyph (set-extent-begin-glyph e glyph)))))
|
|
1893
|
20
|
1894 (defun vm-mime-insert-button (caption action layout disposable)
|
|
1895 (let ((start (point)) e
|
|
1896 (keymap (make-sparse-keymap))
|
|
1897 (buffer-read-only nil))
|
|
1898 (if (fboundp 'set-keymap-parents)
|
|
1899 (set-keymap-parents keymap (list (current-local-map)))
|
|
1900 (setq keymap (nconc keymap (current-local-map))))
|
|
1901 (define-key keymap "\r" 'vm-mime-run-display-function-at-point)
|
|
1902 (if (and (vm-mouse-xemacs-mouse-p) vm-popup-menu-on-mouse-3)
|
|
1903 (define-key keymap 'button3 'vm-menu-popup-mime-dispose-menu))
|
|
1904 (if (not (bolp))
|
|
1905 (insert "\n"))
|
|
1906 (insert caption "\n")
|
|
1907 ;; we MUST have the five arg make-overlay. overlays must
|
|
1908 ;; advance when text is inserted at their start position or
|
|
1909 ;; inline text and graphics will seep into the button
|
|
1910 ;; overlay and then be removed when the button is removed.
|
|
1911 (if (fboundp 'make-overlay)
|
|
1912 (setq e (make-overlay start (point) nil t nil))
|
|
1913 (setq e (make-extent start (point)))
|
|
1914 (set-extent-property e 'start-open t)
|
|
1915 (set-extent-property e 'end-open t))
|
24
|
1916 (vm-mime-set-extent-glyph-for-layout e layout)
|
20
|
1917 ;; for emacs
|
|
1918 (vm-set-extent-property e 'mouse-face 'highlight)
|
|
1919 (vm-set-extent-property e 'local-map keymap)
|
|
1920 ;; for xemacs
|
|
1921 (vm-set-extent-property e 'highlight t)
|
|
1922 (vm-set-extent-property e 'keymap keymap)
|
|
1923 (vm-set-extent-property e 'balloon-help 'vm-mouse-3-help)
|
|
1924 ;; for all
|
|
1925 (vm-set-extent-property e 'vm-mime-disposable disposable)
|
|
1926 (vm-set-extent-property e 'face vm-mime-button-face)
|
|
1927 (vm-set-extent-property e 'vm-mime-layout layout)
|
|
1928 (vm-set-extent-property e 'vm-mime-function action)))
|
|
1929
|
|
1930 (defun vm-mime-send-body-to-file (layout &optional default-filename)
|
|
1931 (if (not (vectorp layout))
|
|
1932 (setq layout (vm-extent-property layout 'vm-mime-layout)))
|
|
1933 (or default-filename
|
|
1934 (setq default-filename
|
|
1935 (vm-mime-get-disposition-parameter layout "filename")))
|
|
1936 (and default-filename
|
|
1937 (setq default-filename (file-name-nondirectory default-filename)))
|
|
1938 (let ((work-buffer nil)
|
24
|
1939 ;; evade the XEmacs dialog box, yeccch.
|
|
1940 (use-dialog-box nil)
|
|
1941 (dir vm-mime-attachment-save-directory)
|
|
1942 (done nil)
|
20
|
1943 file)
|
24
|
1944 (while (not done)
|
|
1945 (setq file
|
|
1946 (read-file-name
|
|
1947 (if default-filename
|
|
1948 (format "Write MIME body to file (default %s): "
|
|
1949 default-filename)
|
|
1950 "Write MIME body to file: ")
|
|
1951 dir default-filename)
|
|
1952 file (expand-file-name file dir))
|
|
1953 (if (not (file-directory-p file))
|
|
1954 (setq done t)
|
|
1955 (if default-filename
|
|
1956 (message "%s is a directory" file)
|
|
1957 (error "%s is a directory" file))
|
|
1958 (sit-for 2)
|
|
1959 (setq dir file
|
|
1960 default-filename (if (string-match "/$" file)
|
|
1961 (concat file default-filename)
|
|
1962 (concat file "/" default-filename)))))
|
20
|
1963 (save-excursion
|
|
1964 (unwind-protect
|
|
1965 (progn
|
|
1966 (setq work-buffer (generate-new-buffer " *vm-work*"))
|
|
1967 (buffer-disable-undo work-buffer)
|
|
1968 (set-buffer work-buffer)
|
|
1969 ;; Tell DOS/Windows NT whether the file is binary
|
|
1970 (setq buffer-file-type (not (vm-mime-text-type-p layout)))
|
24
|
1971 ;; Tell XEmacs/MULE not to mess with the bits unless
|
|
1972 ;; this is a text type.
|
26
|
1973 (if (vm-xemacs-mule-p)
|
24
|
1974 (if (vm-mime-text-type-p layout)
|
|
1975 (set-file-coding-system 'no-conversion nil)
|
|
1976 (set-file-coding-system 'binary t)))
|
20
|
1977 (vm-mime-insert-mime-body layout)
|
|
1978 (vm-mime-transfer-decode-region layout (point-min) (point-max))
|
|
1979 (or (not (file-exists-p file))
|
|
1980 (y-or-n-p "File exists, overwrite? ")
|
|
1981 (error "Aborted"))
|
|
1982 (write-region (point-min) (point-max) file nil nil))
|
|
1983 (and work-buffer (kill-buffer work-buffer))))))
|
|
1984
|
|
1985 (defun vm-mime-pipe-body-to-command (layout &optional discard-output)
|
|
1986 (if (not (vectorp layout))
|
|
1987 (setq layout (vm-extent-property layout 'vm-mime-layout)))
|
|
1988 (let ((command-line (read-string "Pipe to command: "))
|
|
1989 (output-buffer (if discard-output
|
|
1990 0
|
|
1991 (get-buffer-create "*Shell Command Output*")))
|
|
1992 (work-buffer nil))
|
|
1993 (save-excursion
|
|
1994 (if (bufferp output-buffer)
|
|
1995 (progn
|
|
1996 (set-buffer output-buffer)
|
|
1997 (erase-buffer)))
|
|
1998 (unwind-protect
|
|
1999 (progn
|
|
2000 (setq work-buffer (generate-new-buffer " *vm-work*"))
|
|
2001 (buffer-disable-undo work-buffer)
|
|
2002 (set-buffer work-buffer)
|
|
2003 (vm-mime-insert-mime-body layout)
|
|
2004 (vm-mime-transfer-decode-region layout (point-min) (point-max))
|
|
2005 (let ((pop-up-windows (and pop-up-windows
|
|
2006 (eq vm-mutable-windows t)))
|
|
2007 ;; Tell DOS/Windows NT whether the input is binary
|
|
2008 (binary-process-input (not (vm-mime-text-type-p layout))))
|
|
2009 (call-process-region (point-min) (point-max)
|
|
2010 (or shell-file-name "sh")
|
|
2011 nil output-buffer nil
|
|
2012 shell-command-switch command-line)))
|
|
2013 (and work-buffer (kill-buffer work-buffer)))
|
|
2014 (if (bufferp output-buffer)
|
|
2015 (progn
|
|
2016 (set-buffer output-buffer)
|
|
2017 (if (not (zerop (buffer-size)))
|
|
2018 (vm-display output-buffer t (list this-command)
|
|
2019 '(vm-pipe-message-to-command))
|
|
2020 (vm-display nil nil (list this-command)
|
|
2021 '(vm-pipe-message-to-command)))))))
|
|
2022 t )
|
|
2023
|
|
2024 (defun vm-mime-pipe-body-to-command-discard-output (layout)
|
|
2025 (vm-mime-pipe-body-to-command layout t))
|
|
2026
|
|
2027 (defun vm-mime-scrub-description (string)
|
|
2028 (let ((work-buffer nil))
|
|
2029 (save-excursion
|
|
2030 (unwind-protect
|
|
2031 (progn
|
|
2032 (setq work-buffer (generate-new-buffer " *vm-work*"))
|
|
2033 (buffer-disable-undo work-buffer)
|
|
2034 (set-buffer work-buffer)
|
|
2035 (insert string)
|
|
2036 (while (re-search-forward "[ \t\n]+" nil t)
|
|
2037 (replace-match " "))
|
|
2038 (buffer-string))
|
|
2039 (and work-buffer (kill-buffer work-buffer))))))
|
|
2040
|
|
2041 (defun vm-mime-layout-description (layout)
|
26
|
2042 (let ((type (car (vm-mm-layout-type layout)))
|
|
2043 description name)
|
|
2044 (setq description
|
|
2045 (if (vm-mm-layout-description layout)
|
|
2046 (vm-mime-scrub-description (vm-mm-layout-description layout))))
|
|
2047 (concat
|
|
2048 (if description description "")
|
|
2049 (if description ", " "")
|
|
2050 (cond ((vm-mime-types-match "multipart/digest" type)
|
|
2051 (let ((n (length (vm-mm-layout-parts layout))))
|
|
2052 (format "digest (%d message%s)" n (if (= n 1) "" "s"))))
|
|
2053 ((vm-mime-types-match "multipart/alternative" type)
|
|
2054 "multipart alternative")
|
|
2055 ((vm-mime-types-match "multipart" type)
|
|
2056 (let ((n (length (vm-mm-layout-parts layout))))
|
|
2057 (format "multipart message (%d part%s)" n (if (= n 1) "" "s"))))
|
|
2058 ((vm-mime-types-match "text/plain" type)
|
|
2059 (format "plain text%s"
|
|
2060 (let ((charset (vm-mime-get-parameter layout "charset")))
|
|
2061 (if charset
|
|
2062 (concat ", " charset)
|
|
2063 ""))))
|
|
2064 ((vm-mime-types-match "text/enriched" type)
|
|
2065 "enriched text")
|
|
2066 ((vm-mime-types-match "text/html" type)
|
|
2067 "HTML")
|
|
2068 ((vm-mime-types-match "image/gif" type)
|
|
2069 "GIF image")
|
|
2070 ((vm-mime-types-match "image/jpeg" type)
|
|
2071 "JPEG image")
|
|
2072 ((and (vm-mime-types-match "application/octet-stream" type)
|
|
2073 (setq name (vm-mime-get-parameter layout "name"))
|
|
2074 (save-match-data (not (string-match "^[ \t]*$" name))))
|
|
2075 name)
|
|
2076 (t type)))))
|
20
|
2077
|
|
2078 (defun vm-mime-layout-contains-type (layout type)
|
|
2079 (if (vm-mime-types-match type (car (vm-mm-layout-type layout)))
|
|
2080 layout
|
|
2081 (let ((p (vm-mm-layout-parts layout))
|
|
2082 (result nil)
|
|
2083 (done nil))
|
|
2084 (while (and p (not done))
|
|
2085 (if (setq result (vm-mime-layout-contains-type (car p) type))
|
|
2086 (setq done t)
|
|
2087 (setq p (cdr p))))
|
|
2088 result )))
|
|
2089
|
|
2090 (defun vm-mime-plain-message-p (m)
|
|
2091 (save-match-data
|
|
2092 (let ((o (vm-mm-layout m))
|
|
2093 (case-fold-search t))
|
|
2094 (and (eq (vm-mm-encoded-header m) 'none)
|
|
2095 (or (not (vectorp o))
|
|
2096 (and (vm-mime-types-match "text/plain"
|
|
2097 (car (vm-mm-layout-type o)))
|
24
|
2098 (let* ((charset (or (vm-mime-get-parameter o "charset")
|
|
2099 "us-ascii")))
|
|
2100 (vm-string-member charset vm-mime-default-face-charsets))
|
20
|
2101 (string-match "^\\(7bit\\|8bit\\|binary\\)$"
|
|
2102 (vm-mm-layout-encoding o))))))))
|
|
2103
|
|
2104 (defun vm-mime-text-type-p (layout)
|
|
2105 (or (vm-mime-types-match "text" (car (vm-mm-layout-type layout)))
|
|
2106 (vm-mime-types-match "message" (car (vm-mm-layout-type layout)))))
|
|
2107
|
|
2108 (defun vm-mime-charset-internally-displayable-p (name)
|
|
2109 (cond ((and (vm-xemacs-mule-p) (eq (device-type) 'x))
|
24
|
2110 (vm-string-assoc name vm-mime-mule-charset-to-coding-alist))
|
|
2111 ((vm-multiple-fonts-possible-p)
|
|
2112 (or (vm-string-member name vm-mime-default-face-charsets)
|
|
2113 (vm-string-assoc name vm-mime-charset-font-alist)))
|
|
2114 (t
|
|
2115 (vm-string-member name vm-mime-default-face-charsets))))
|
20
|
2116
|
|
2117 (defun vm-mime-find-message/partials (layout id)
|
|
2118 (let ((list nil)
|
|
2119 (type (vm-mm-layout-type layout)))
|
|
2120 (cond ((vm-mime-types-match "multipart" (car type))
|
|
2121 (let ((parts (vm-mm-layout-parts layout)) o)
|
|
2122 (while parts
|
|
2123 (setq o (vm-mime-find-message/partials (car parts) id))
|
|
2124 (if o
|
|
2125 (setq list (nconc o list)))
|
|
2126 (setq parts (cdr parts)))))
|
|
2127 ((vm-mime-types-match "message/partial" (car type))
|
|
2128 (if (equal (vm-mime-get-parameter layout "id") id)
|
|
2129 (setq list (cons layout list)))))
|
|
2130 list ))
|
|
2131
|
|
2132 (defun vm-message-at-point ()
|
|
2133 (let ((mp vm-message-list)
|
|
2134 (point (point))
|
|
2135 (done nil))
|
|
2136 (while (and mp (not done))
|
|
2137 (if (and (>= point (vm-start-of (car mp)))
|
|
2138 (<= point (vm-end-of (car mp))))
|
|
2139 (setq done t)
|
|
2140 (setq mp (cdr mp))))
|
|
2141 (car mp)))
|
|
2142
|
|
2143 (defun vm-mime-make-multipart-boundary ()
|
|
2144 (let ((boundary (make-string 40 ?a))
|
|
2145 (i 0))
|
|
2146 (random t)
|
|
2147 (while (< i (length boundary))
|
|
2148 (aset boundary i (aref vm-mime-base64-alphabet
|
|
2149 (% (vm-abs (lsh (random) -8))
|
|
2150 (length vm-mime-base64-alphabet))))
|
|
2151 (vm-increment i))
|
|
2152 boundary ))
|
|
2153
|
24
|
2154 (defun vm-mime-attach-file (file type &optional charset description)
|
20
|
2155 "Attach a file to a VM composition buffer to be sent along with the message.
|
|
2156 The file is not inserted into the buffer and MIME encoded until
|
|
2157 you execute vm-mail-send or vm-mail-send-and-exit. A visible tag
|
|
2158 indicating the existence of the attachment is placed in the
|
|
2159 composition buffer. You can move the attachment around or remove
|
|
2160 it entirely with normal text editing commands. If you remove the
|
|
2161 attachment tag, the attachment will not be sent.
|
|
2162
|
|
2163 First argument, FILE, is the name of the file to attach. Second
|
|
2164 argument, TYPE, is the MIME Content-Type of the file. Optional
|
|
2165 third argument CHARSET is the character set of the attached
|
24
|
2166 document. This argument is only used for text types, and it is
|
|
2167 ignored for other types. Optional fourth argument DESCRIPTION
|
|
2168 should be a one line description of the file.
|
20
|
2169
|
|
2170 When called interactively all arguments are read from the
|
|
2171 minibuffer.
|
|
2172
|
|
2173 This command is for attaching files that do not have a MIME
|
|
2174 header section at the top. For files with MIME headers, you
|
|
2175 should use vm-mime-attach-mime-file to attach such a file. VM
|
|
2176 will extract the content type information from the headers in
|
|
2177 this case and not prompt you for it in the minibuffer."
|
|
2178 (interactive
|
|
2179 ;; protect value of last-command and this-command
|
|
2180 (let ((last-command last-command)
|
|
2181 (this-command this-command)
|
|
2182 (charset nil)
|
24
|
2183 description file default-type type)
|
20
|
2184 (if (null vm-send-using-mime)
|
|
2185 (error "MIME attachments disabled, set vm-send-using-mime non-nil to enable."))
|
|
2186 (setq file (vm-read-file-name "Attach file: " nil nil t)
|
|
2187 default-type (or (vm-mime-default-type-from-filename file)
|
|
2188 "application/octet-stream")
|
|
2189 type (completing-read
|
|
2190 (format "Content type (default %s): "
|
|
2191 default-type)
|
|
2192 vm-mime-type-completion-alist)
|
|
2193 type (if (> (length type) 0) type default-type))
|
|
2194 (if (vm-mime-types-match "text" type)
|
|
2195 (setq charset (completing-read "Character set (default US-ASCII): "
|
|
2196 vm-mime-charset-completion-alist)
|
|
2197 charset (if (> (length charset) 0) charset)))
|
24
|
2198 (setq description (read-string "One line description: "))
|
|
2199 (if (string-match "^[ \t]*$" description)
|
|
2200 (setq description nil))
|
|
2201 (list file type charset description)))
|
20
|
2202 (if (null vm-send-using-mime)
|
|
2203 (error "MIME attachments disabled, set vm-send-using-mime non-nil to enable."))
|
|
2204 (if (file-directory-p file)
|
|
2205 (error "%s is a directory, cannot attach" file))
|
|
2206 (if (not (file-exists-p file))
|
|
2207 (error "No such file: %s" file))
|
|
2208 (if (not (file-readable-p file))
|
|
2209 (error "You don't have permission to read %s" file))
|
|
2210 (and charset (setq charset (list (concat "charset=" charset))))
|
24
|
2211 (and description (setq description (vm-mime-scrub-description description)))
|
|
2212 (vm-mime-attach-object file type charset description nil))
|
20
|
2213
|
|
2214 (defun vm-mime-attach-mime-file (file)
|
|
2215 "Attach a MIME encoded file to a VM composition buffer to be sent
|
|
2216 along with the message.
|
|
2217
|
|
2218 The file is not inserted into the buffer until you execute
|
|
2219 vm-mail-send or vm-mail-send-and-exit. A visible tag indicating
|
|
2220 the existence of the attachment is placed in the composition
|
|
2221 buffer. You can move the attachment around or remove it entirely
|
|
2222 with normal text editing commands. If you remove the attachment
|
|
2223 tag, the attachment will not be sent.
|
|
2224
|
|
2225 The sole argument, FILE, is the name of the file to attach.
|
|
2226 When called interactively the FILE argument is read from the
|
|
2227 minibuffer.
|
|
2228
|
|
2229 This command is for attaching files that have a MIME
|
|
2230 header section at the top. For files without MIME headers, you
|
|
2231 should use vm-mime-attach-file to attach such a file. VM
|
|
2232 will interactively query you for the file type information."
|
|
2233 (interactive
|
|
2234 ;; protect value of last-command and this-command
|
|
2235 (let ((last-command last-command)
|
|
2236 (this-command this-command)
|
|
2237 file)
|
|
2238 (if (null vm-send-using-mime)
|
|
2239 (error "MIME attachments disabled, set vm-send-using-mime non-nil to enable."))
|
|
2240 (setq file (vm-read-file-name "Attach file: " nil nil t))
|
|
2241 (list file)))
|
|
2242 (if (null vm-send-using-mime)
|
|
2243 (error "MIME attachments disabled, set vm-send-using-mime non-nil to enable."))
|
|
2244 (if (file-directory-p file)
|
|
2245 (error "%s is a directory, cannot attach" file))
|
|
2246 (if (not (file-exists-p file))
|
|
2247 (error "No such file: %s" file))
|
|
2248 (if (not (file-readable-p file))
|
|
2249 (error "You don't have permission to read %s" file))
|
24
|
2250 (vm-mime-attach-object file nil nil nil t))
|
20
|
2251
|
24
|
2252 (defun vm-mime-attach-object (object type params description mimed)
|
20
|
2253 (if (not (eq major-mode 'mail-mode))
|
|
2254 (error "Command must be used in a VM Mail mode buffer."))
|
24
|
2255 (let (start end e tag-string disposition)
|
|
2256 (if (< (point) (save-excursion (mail-text) (point)))
|
|
2257 (mail-text))
|
|
2258 (setq start (point)
|
|
2259 tag-string (format "[ATTACHMENT %s, %s]" object
|
|
2260 (or type "MIME file")))
|
20
|
2261 (insert tag-string "\n")
|
24
|
2262 (setq end (1- (point)))
|
|
2263 ;; attach default filename for recipient if currently
|
|
2264 ;; non-MIME. if already MIME'd don't do this because it
|
|
2265 ;; would override any content-disposition header already in
|
|
2266 ;; the attachment.
|
|
2267 (if (and (stringp object) (not mimed))
|
|
2268 (progn
|
|
2269 (if (or (vm-mime-types-match "application" type)
|
|
2270 (vm-mime-types-match "model" type))
|
|
2271 (setq disposition (list "attachment"))
|
|
2272 (setq disposition (list "inline")))
|
|
2273 (setq disposition (nconc disposition
|
|
2274 (list
|
|
2275 (concat "filename=\""
|
|
2276 (file-name-nondirectory object)
|
|
2277 "\""))))))
|
|
2278 (cond ((vm-fsfemacs-19-p)
|
|
2279 (put-text-property start end 'front-sticky nil)
|
|
2280 (put-text-property start end 'rear-nonsticky t)
|
|
2281 (put-text-property start end 'intangible object)
|
|
2282 (put-text-property start end 'face vm-mime-button-face)
|
|
2283 (put-text-property start end 'vm-mime-type type)
|
|
2284 (put-text-property start end 'vm-mime-object object)
|
|
2285 (put-text-property start end 'vm-mime-parameters params)
|
|
2286 (put-text-property start end 'vm-mime-description description)
|
|
2287 (put-text-property start end 'vm-mime-disposition disposition)
|
|
2288 (put-text-property start end 'vm-mime-encoded mimed)
|
|
2289 (put-text-property start end 'vm-mime-object object))
|
20
|
2290 ((fboundp 'make-extent)
|
24
|
2291 (setq e (make-extent start end))
|
20
|
2292 (set-extent-property e 'start-open t)
|
24
|
2293 (set-extent-property e 'face vm-mime-button-face)
|
|
2294 (vm-set-extent-property e 'duplicable t)
|
|
2295 (vm-set-extent-property e 'vm-mime-type type)
|
|
2296 (vm-set-extent-property e 'vm-mime-object object)
|
|
2297 (vm-set-extent-property e 'vm-mime-parameters params)
|
|
2298 (vm-set-extent-property e 'vm-mime-description description)
|
|
2299 (vm-set-extent-property e 'vm-mime-disposition disposition)
|
|
2300 (vm-set-extent-property e 'vm-mime-encoded mimed)))))
|
|
2301
|
|
2302 (defun vm-disallow-overlay-endpoint-insertion (overlay after start end
|
|
2303 &optional old-size)
|
|
2304 (cond ((null after) nil)
|
|
2305 ((= start (overlay-start overlay))
|
|
2306 (move-overlay overlay end (overlay-end overlay)))
|
|
2307 ((= start (overlay-end overlay))
|
|
2308 (move-overlay overlay (overlay-start overlay) start))))
|
|
2309
|
|
2310 (defun vm-mime-fake-attachment-overlays (start end)
|
|
2311 (let ((o-list nil)
|
|
2312 (done nil)
|
|
2313 (pos start)
|
26
|
2314 object props o)
|
24
|
2315 (save-excursion
|
|
2316 (save-restriction
|
|
2317 (narrow-to-region start end)
|
|
2318 (while (not done)
|
|
2319 (setq object (get-text-property pos 'vm-mime-object))
|
|
2320 (setq pos (next-single-property-change pos 'vm-mime-object))
|
|
2321 (or pos (setq pos (point-max) done t))
|
|
2322 (if object
|
|
2323 (progn
|
|
2324 (setq o (make-overlay start pos))
|
|
2325 (overlay-put o 'insert-in-front-hooks
|
|
2326 '(vm-disallow-overlay-endpoint-insertion))
|
|
2327 (overlay-put o 'insert-behind-hooks
|
|
2328 '(vm-disallow-overlay-endpoint-insertion))
|
|
2329 (setq props (text-properties-at start))
|
|
2330 (while props
|
|
2331 (overlay-put o (car props) (car (cdr props)))
|
|
2332 (setq props (cdr (cdr props))))
|
|
2333 (setq o-list (cons o o-list))))
|
|
2334 (setq start pos))
|
|
2335 o-list ))))
|
20
|
2336
|
|
2337 (defun vm-mime-default-type-from-filename (file)
|
|
2338 (let ((alist vm-mime-attachment-auto-type-alist)
|
|
2339 (case-fold-search t)
|
|
2340 (done nil))
|
|
2341 (while (and alist (not done))
|
|
2342 (if (string-match (car (car alist)) file)
|
|
2343 (setq done t)
|
|
2344 (setq alist (cdr alist))))
|
|
2345 (and alist (cdr (car alist)))))
|
|
2346
|
|
2347 (defun vm-remove-mail-mode-header-separator ()
|
|
2348 (save-excursion
|
|
2349 (goto-char (point-min))
|
|
2350 (if (re-search-forward (concat "^" mail-header-separator "$") nil t)
|
|
2351 (progn
|
|
2352 (delete-region (match-beginning 0) (match-end 0))
|
|
2353 t )
|
|
2354 nil )))
|
|
2355
|
|
2356 (defun vm-add-mail-mode-header-separator ()
|
|
2357 (save-excursion
|
|
2358 (goto-char (point-min))
|
|
2359 (if (re-search-forward "^$" nil t)
|
|
2360 (replace-match mail-header-separator t t))))
|
|
2361
|
|
2362 (defun vm-mime-transfer-encode-region (encoding beg end crlf)
|
|
2363 (let ((case-fold-search t))
|
|
2364 (cond ((string-match "^binary$" encoding)
|
|
2365 (vm-mime-base64-encode-region beg end crlf)
|
|
2366 (setq encoding "base64"))
|
|
2367 ((string-match "^7bit$" encoding) t)
|
|
2368 ((string-match "^base64$" encoding) t)
|
|
2369 ((string-match "^quoted-printable$" encoding) t)
|
|
2370 ;; must be 8bit
|
|
2371 ((eq vm-mime-8bit-text-transfer-encoding 'quoted-printable)
|
|
2372 (vm-mime-qp-encode-region beg end)
|
|
2373 (setq encoding "quoted-printable"))
|
|
2374 ((eq vm-mime-8bit-text-transfer-encoding 'base64)
|
|
2375 (vm-mime-base64-encode-region beg end crlf)
|
|
2376 (setq encoding "base64"))
|
|
2377 ((eq vm-mime-8bit-text-transfer-encoding 'send) t))
|
|
2378 encoding ))
|
|
2379
|
|
2380 (defun vm-mime-transfer-encode-layout (layout)
|
|
2381 (if (vm-mime-text-type-p layout)
|
|
2382 (vm-mime-transfer-encode-region (vm-mm-layout-encoding layout)
|
|
2383 (vm-mm-layout-body-start layout)
|
|
2384 (vm-mm-layout-body-end layout)
|
|
2385 t)
|
|
2386 (vm-mime-transfer-encode-region (vm-mm-layout-encoding layout)
|
|
2387 (vm-mm-layout-body-start layout)
|
|
2388 (vm-mm-layout-body-end layout)
|
|
2389 nil)))
|
24
|
2390
|
20
|
2391 (defun vm-mime-encode-composition ()
|
|
2392 "MIME encode the current buffer.
|
|
2393 Attachment tags added to the buffer with vm-mime-attach-file are expanded
|
|
2394 and the approriate content-type and boundary markup information is added."
|
|
2395 (interactive)
|
|
2396 (save-restriction
|
|
2397 (widen)
|
|
2398 (if (not (eq major-mode 'mail-mode))
|
|
2399 (error "Command must be used in a VM Mail mode buffer."))
|
|
2400 (or (null (vm-mail-mode-get-header-contents "MIME-Version:"))
|
|
2401 (error "Message is already MIME encoded."))
|
|
2402 (let ((8bit nil)
|
|
2403 (just-one nil)
|
|
2404 (boundary-positions nil)
|
|
2405 already-mimed layout e e-list boundary
|
24
|
2406 type encoding charset params description disposition object
|
|
2407 opoint-min)
|
20
|
2408 (mail-text)
|
|
2409 (setq e-list (if (fboundp 'extent-list)
|
|
2410 (extent-list nil (point) (point-max))
|
24
|
2411 (vm-mime-fake-attachment-overlays (point) (point-max)))
|
20
|
2412 e-list (vm-delete (function
|
|
2413 (lambda (e)
|
|
2414 (vm-extent-property e 'vm-mime-object)))
|
|
2415 e-list t)
|
|
2416 e-list (sort e-list (function
|
|
2417 (lambda (e1 e2)
|
|
2418 (< (vm-extent-end-position e1)
|
|
2419 (vm-extent-end-position e2))))))
|
|
2420 ;; If there's just one attachment and no other readable
|
|
2421 ;; text in the buffer then make the message type just be
|
|
2422 ;; the attachment type rather than sending a multipart
|
|
2423 ;; message with one attachment
|
|
2424 (setq just-one (and (= (length e-list) 1)
|
|
2425 (looking-at "[ \t\n]*")
|
|
2426 (= (match-end 0)
|
|
2427 (vm-extent-start-position (car e-list)))
|
|
2428 (save-excursion
|
|
2429 (goto-char (vm-extent-end-position (car e-list)))
|
|
2430 (looking-at "[ \t\n]*\\'"))))
|
|
2431 (if (null e-list)
|
|
2432 (progn
|
|
2433 (narrow-to-region (point) (point-max))
|
|
2434 (setq charset (vm-determine-proper-charset (point-min)
|
|
2435 (point-max)))
|
26
|
2436 (if (vm-xemacs-mule-p)
|
24
|
2437 (encode-coding-region (point-min) (point-max)
|
|
2438 file-coding-system))
|
20
|
2439 (setq encoding (vm-determine-proper-content-transfer-encoding
|
|
2440 (point-min)
|
|
2441 (point-max))
|
|
2442 encoding (vm-mime-transfer-encode-region encoding
|
|
2443 (point-min)
|
|
2444 (point-max)
|
|
2445 t))
|
|
2446 (widen)
|
|
2447 (vm-remove-mail-mode-header-separator)
|
|
2448 (goto-char (point-min))
|
|
2449 (vm-reorder-message-headers
|
|
2450 nil nil "\\(Content-Type:\\|Content-Transfer-Encoding\\|MIME-Version:\\)")
|
|
2451 (insert "MIME-Version: 1.0\n")
|
|
2452 (insert "Content-Type: text/plain; charset=" charset "\n")
|
|
2453 (insert "Content-Transfer-Encoding: " encoding "\n")
|
|
2454 (vm-add-mail-mode-header-separator))
|
|
2455 (while e-list
|
|
2456 (setq e (car e-list))
|
|
2457 (if (or just-one (= (point) (vm-extent-start-position e)))
|
|
2458 nil
|
|
2459 (narrow-to-region (point) (vm-extent-start-position e))
|
|
2460 (setq charset (vm-determine-proper-charset (point-min)
|
|
2461 (point-max)))
|
|
2462 (setq encoding (vm-determine-proper-content-transfer-encoding
|
|
2463 (point-min)
|
|
2464 (point-max))
|
|
2465 encoding (vm-mime-transfer-encode-region encoding
|
|
2466 (point-min)
|
|
2467 (point-max)
|
|
2468 t))
|
|
2469 (setq boundary-positions (cons (point-marker) boundary-positions))
|
|
2470 (insert "Content-Type: text/plain; charset=" charset "\n")
|
|
2471 (insert "Content-Transfer-Encoding: " encoding "\n\n")
|
|
2472 (widen))
|
24
|
2473 (goto-char (vm-extent-start-position e))
|
20
|
2474 (narrow-to-region (point) (point))
|
|
2475 (setq object (vm-extent-property e 'vm-mime-object))
|
24
|
2476 ;; insert the object
|
20
|
2477 (cond ((bufferp object)
|
|
2478 (insert-buffer-substring object))
|
|
2479 ((stringp object)
|
24
|
2480 (let ((overridding-file-coding-system 'no-conversion))
|
|
2481 (insert-file-contents-literally object))))
|
|
2482 ;; gather information about the object from the extent.
|
20
|
2483 (if (setq already-mimed (vm-extent-property e 'vm-mime-encoded))
|
|
2484 (setq layout (vm-mime-parse-entity
|
|
2485 nil (list "text/plain" "charset=us-ascii")
|
|
2486 "7bit")
|
24
|
2487 type (or (vm-extent-property e 'vm-mime-type)
|
|
2488 (car (vm-mm-layout-type layout)))
|
|
2489 params (or (vm-extent-property e 'vm-mime-parameters)
|
|
2490 (cdr (vm-mm-layout-qtype layout)))
|
|
2491 description (vm-extent-property e 'vm-mime-description)
|
|
2492 disposition (or (vm-extent-property e 'vm-mime-disposition)
|
|
2493 (vm-mm-layout-qdisposition layout)))
|
20
|
2494 (setq type (vm-extent-property e 'vm-mime-type)
|
24
|
2495 params (vm-extent-property e 'vm-mime-parameters)
|
|
2496 description (vm-extent-property e 'vm-mime-description)
|
|
2497 disposition (vm-extent-property e 'vm-mime-disposition)))
|
20
|
2498 (cond ((vm-mime-types-match "text" type)
|
|
2499 (setq encoding
|
|
2500 (vm-determine-proper-content-transfer-encoding
|
|
2501 (if already-mimed
|
|
2502 (vm-mm-layout-body-start layout)
|
|
2503 (point-min))
|
|
2504 (point-max))
|
|
2505 encoding (vm-mime-transfer-encode-region
|
|
2506 encoding
|
|
2507 (if already-mimed
|
|
2508 (vm-mm-layout-body-start layout)
|
|
2509 (point-min))
|
|
2510 (point-max)
|
|
2511 t))
|
|
2512 (setq 8bit (or 8bit (equal encoding "8bit"))))
|
|
2513 ((or (vm-mime-types-match "message/rfc822" type)
|
|
2514 (vm-mime-types-match "multipart" type))
|
|
2515 (setq opoint-min (point-min))
|
|
2516 (if (not already-mimed)
|
|
2517 (setq layout (vm-mime-parse-entity
|
|
2518 nil (list "text/plain" "charset=us-ascii")
|
|
2519 "7bit")))
|
|
2520 ;; MIME messages of type "message" and
|
|
2521 ;; "multipart" are required to have a non-opaque
|
|
2522 ;; content transfer encoding. This means that
|
|
2523 ;; if the user only wants to send out 7bit data,
|
|
2524 ;; then any subpart that contains 8bit data must
|
|
2525 ;; have an opaque (qp or base64) 8->7bit
|
|
2526 ;; conversion performed on it so that the
|
|
2527 ;; enclosing entity can use an non-opqaue
|
|
2528 ;; encoding.
|
|
2529 ;;
|
|
2530 ;; message/partial requires a "7bit" encoding so
|
|
2531 ;; force 8->7 conversion in that case.
|
|
2532 (let ((vm-mime-8bit-text-transfer-encoding
|
|
2533 (if (vm-mime-types-match "message/partial" type)
|
|
2534 'quoted-printable
|
|
2535 vm-mime-8bit-text-transfer-encoding)))
|
|
2536 (vm-mime-map-atomic-layouts 'vm-mime-transfer-encode-layout
|
|
2537 (vm-mm-layout-parts layout)))
|
|
2538 ;; now figure out a proper content trasnfer
|
|
2539 ;; encoding value for the enclosing entity.
|
|
2540 (re-search-forward "^\n" nil t)
|
|
2541 (save-restriction
|
|
2542 (narrow-to-region (point) (point-max))
|
|
2543 (setq encoding
|
|
2544 (vm-determine-proper-content-transfer-encoding
|
|
2545 (point-min)
|
|
2546 (point-max))))
|
|
2547 (setq 8bit (or 8bit (equal encoding "8bit")))
|
|
2548 (goto-char (point-max))
|
|
2549 (widen)
|
|
2550 (narrow-to-region opoint-min (point)))
|
|
2551 (t
|
|
2552 (vm-mime-base64-encode-region
|
|
2553 (if already-mimed
|
|
2554 (vm-mm-layout-body-start layout)
|
|
2555 (point-min))
|
|
2556 (point-max))
|
|
2557 (setq encoding "base64")))
|
|
2558 (if just-one
|
|
2559 nil
|
|
2560 (goto-char (point-min))
|
|
2561 (setq boundary-positions (cons (point-marker) boundary-positions))
|
|
2562 (if (not already-mimed)
|
|
2563 nil
|
|
2564 ;; trim headers
|
|
2565 (vm-reorder-message-headers
|
24
|
2566 nil (nconc (list "Content-Disposition:" "Content-ID:")
|
|
2567 (if description
|
|
2568 (list "Content-Description:")
|
|
2569 nil))
|
|
2570 nil)
|
20
|
2571 ;; remove header/text separator
|
|
2572 (goto-char (1- (vm-mm-layout-body-start layout)))
|
|
2573 (if (looking-at "\n")
|
|
2574 (delete-char 1)))
|
|
2575 (insert "Content-Type: " type)
|
|
2576 (if params
|
|
2577 (if vm-mime-avoid-folding-content-type
|
|
2578 (insert "; " (mapconcat 'identity params "; ") "\n")
|
|
2579 (insert ";\n\t" (mapconcat 'identity params ";\n\t") "\n"))
|
|
2580 (insert "\n"))
|
24
|
2581 (and description
|
|
2582 (insert "Content-Description: " description "\n"))
|
|
2583 (if disposition
|
|
2584 (progn
|
|
2585 (insert "Content-Disposition: " (car disposition))
|
|
2586 (if (cdr disposition)
|
|
2587 (insert ";\n\t" (mapconcat 'identity
|
|
2588 (cdr disposition)
|
|
2589 ";\n\t")))
|
|
2590 (insert "\n")))
|
20
|
2591 (insert "Content-Transfer-Encoding: " encoding "\n\n"))
|
|
2592 (goto-char (point-max))
|
|
2593 (widen)
|
|
2594 (delete-region (vm-extent-start-position e)
|
|
2595 (vm-extent-end-position e))
|
|
2596 (vm-detach-extent e)
|
24
|
2597 (if (looking-at "\n")
|
|
2598 (delete-char 1))
|
20
|
2599 (setq e-list (cdr e-list)))
|
|
2600 ;; handle the remaining chunk of text after the last
|
|
2601 ;; extent, if any.
|
|
2602 (if (or just-one (= (point) (point-max)))
|
|
2603 nil
|
|
2604 (setq charset (vm-determine-proper-charset (point)
|
|
2605 (point-max)))
|
26
|
2606 (if (vm-xemacs-mule-p)
|
24
|
2607 (encode-coding-region (point-min) (point-max)
|
|
2608 file-coding-system))
|
20
|
2609 (setq encoding (vm-determine-proper-content-transfer-encoding
|
|
2610 (point)
|
|
2611 (point-max))
|
|
2612 encoding (vm-mime-transfer-encode-region encoding
|
|
2613 (point)
|
|
2614 (point-max)
|
|
2615 t))
|
|
2616 (setq 8bit (or 8bit (equal encoding "8bit")))
|
|
2617 (setq boundary-positions (cons (point-marker) boundary-positions))
|
|
2618 (insert "Content-Type: text/plain; charset=" charset "\n")
|
|
2619 (insert "Content-Transfer-Encoding: " encoding "\n\n")
|
|
2620 (goto-char (point-max)))
|
|
2621 (setq boundary (vm-mime-make-multipart-boundary))
|
|
2622 (mail-text)
|
|
2623 (while (re-search-forward (concat "^--"
|
|
2624 (regexp-quote boundary)
|
|
2625 "\\(--\\)?$")
|
|
2626 nil t)
|
|
2627 (setq boundary (vm-mime-make-multipart-boundary))
|
|
2628 (mail-text))
|
|
2629 (goto-char (point-max))
|
|
2630 (or just-one (insert "\n--" boundary "--\n"))
|
|
2631 (while boundary-positions
|
|
2632 (goto-char (car boundary-positions))
|
|
2633 (insert "\n--" boundary "\n")
|
|
2634 (setq boundary-positions (cdr boundary-positions)))
|
|
2635 (if (and just-one already-mimed)
|
|
2636 (progn
|
|
2637 (goto-char (vm-mm-layout-header-start layout))
|
|
2638 ;; trim headers
|
|
2639 (vm-reorder-message-headers
|
|
2640 nil '("Content-Description:" "Content-ID:") nil)
|
|
2641 ;; remove header/text separator
|
|
2642 (goto-char (1- (vm-mm-layout-body-start layout)))
|
|
2643 (if (looking-at "\n")
|
|
2644 (delete-char 1))
|
|
2645 ;; copy remainder to enclosing entity's header section
|
|
2646 (insert-buffer-substring (current-buffer)
|
|
2647 (vm-mm-layout-header-start layout)
|
|
2648 (vm-mm-layout-body-start layout))
|
|
2649 (delete-region (vm-mm-layout-header-start layout)
|
|
2650 (vm-mm-layout-body-start layout))))
|
|
2651 (goto-char (point-min))
|
|
2652 (vm-remove-mail-mode-header-separator)
|
|
2653 (vm-reorder-message-headers
|
|
2654 nil nil "\\(Content-Type:\\|MIME-Version:\\|Content-Transfer-Encoding\\)")
|
|
2655 (vm-add-mail-mode-header-separator)
|
|
2656 (insert "MIME-Version: 1.0\n")
|
|
2657 (if (not just-one)
|
|
2658 (insert (if vm-mime-avoid-folding-content-type
|
|
2659 "Content-Type: multipart/mixed; boundary=\""
|
|
2660 "Content-Type: multipart/mixed;\n\tboundary=\"")
|
|
2661 boundary "\"\n")
|
|
2662 (insert "Content-Type: " type)
|
|
2663 (if params
|
|
2664 (if vm-mime-avoid-folding-content-type
|
|
2665 (insert "; " (mapconcat 'identity params "; ") "\n")
|
|
2666 (insert ";\n\t" (mapconcat 'identity params ";\n\t"))))
|
|
2667 (insert "\n"))
|
|
2668 (if just-one
|
24
|
2669 (and description
|
|
2670 (insert "Content-Description: " description "\n")))
|
|
2671 (if (and just-one disposition)
|
|
2672 (progn
|
|
2673 (insert "Content-Disposition: " (car disposition))
|
|
2674 (if (cdr disposition)
|
|
2675 (insert ";\n\t" (mapconcat 'identity
|
|
2676 (cdr disposition)
|
|
2677 ";\n\t")))
|
|
2678 (insert "\n")))
|
|
2679 (if just-one
|
20
|
2680 (insert "Content-Transfer-Encoding: " encoding "\n")
|
|
2681 (if 8bit
|
|
2682 (insert "Content-Transfer-Encoding: 8bit\n")
|
|
2683 (insert "Content-Transfer-Encoding: 7bit\n")))))))
|
|
2684
|
|
2685 (defun vm-mime-fragment-composition (size)
|
|
2686 (save-restriction
|
|
2687 (widen)
|
26
|
2688 (message "Fragmenting message...")
|
20
|
2689 (let ((buffers nil)
|
|
2690 (id (vm-mime-make-multipart-boundary))
|
|
2691 (n 1)
|
|
2692 (the-end nil)
|
|
2693 b header-start header-end master-buffer start end)
|
|
2694 (vm-remove-mail-mode-header-separator)
|
|
2695 ;; message/partial must have "7bit" content transfer
|
|
2696 ;; encoding, so verify that everything has been encoded for
|
|
2697 ;; 7bit transmission.
|
|
2698 (let ((vm-mime-8bit-text-transfer-encoding
|
|
2699 (if (eq vm-mime-8bit-text-transfer-encoding 'send)
|
|
2700 'quoted-printable
|
|
2701 vm-mime-8bit-text-transfer-encoding)))
|
|
2702 (vm-mime-map-atomic-layouts
|
|
2703 'vm-mime-transfer-encode-layout
|
|
2704 (list (vm-mime-parse-entity nil (list "text/plain" "charset=us-ascii")
|
|
2705 "7bit"))))
|
|
2706 (goto-char (point-min))
|
|
2707 (setq header-start (point))
|
|
2708 (search-forward "\n\n")
|
|
2709 (setq header-end (1- (point)))
|
|
2710 (setq master-buffer (current-buffer))
|
|
2711 (goto-char (point-min))
|
|
2712 (setq start (point))
|
|
2713 (while (not (eobp))
|
|
2714 (condition-case nil
|
|
2715 (progn
|
|
2716 (forward-char (max (- size 150) 2000))
|
|
2717 (beginning-of-line))
|
|
2718 (end-of-buffer (setq the-end t)))
|
|
2719 (setq end (point))
|
|
2720 (setq b (generate-new-buffer (concat (buffer-name) " part "
|
|
2721 (int-to-string n))))
|
|
2722 (setq buffers (cons b buffers))
|
|
2723 (set-buffer b)
|
|
2724 (make-local-variable 'vm-send-using-mime)
|
|
2725 (setq vm-send-using-mime nil)
|
|
2726 (insert-buffer-substring master-buffer header-start header-end)
|
|
2727 (goto-char (point-min))
|
|
2728 (vm-reorder-message-headers nil nil
|
|
2729 "\\(Content-Type:\\|MIME-Version:\\|Content-Transfer-Encoding\\)")
|
|
2730 (insert "MIME-Version: 1.0\n")
|
|
2731 (insert (format
|
|
2732 (if vm-mime-avoid-folding-content-type
|
|
2733 "Content-Type: message/partial; id=%s; number=%d"
|
|
2734 "Content-Type: message/partial;\n\tid=%s;\n\tnumber=%d")
|
|
2735 id n))
|
|
2736 (if the-end
|
|
2737 (if vm-mime-avoid-folding-content-type
|
|
2738 (insert (format "; total=%d\n" n))
|
|
2739 (insert (format ";\n\ttotal=%d\n" n)))
|
|
2740 (insert "\n"))
|
|
2741 (insert "Content-Transfer-Encoding: 7bit\n")
|
|
2742 (goto-char (point-max))
|
|
2743 (insert mail-header-separator "\n")
|
|
2744 (insert-buffer-substring master-buffer start end)
|
|
2745 (vm-increment n)
|
|
2746 (set-buffer master-buffer)
|
|
2747 (setq start (point)))
|
26
|
2748 (message "Fragmenting message... done")
|
20
|
2749 (nreverse buffers))))
|
|
2750
|
|
2751 (defun vm-mime-preview-composition ()
|
|
2752 "Show how the current composition buffer might be displayed
|
|
2753 in a MIME-aware mail reader. VM copies and encodes the current
|
|
2754 mail composition buffer and displays it as a mail folder.
|
|
2755 Type `q' to quit this temp folder and return to composing your
|
|
2756 message."
|
|
2757 (interactive)
|
|
2758 (if (not (eq major-mode 'mail-mode))
|
|
2759 (error "Command must be used in a VM Mail mode buffer."))
|
|
2760 (let ((temp-buffer nil)
|
|
2761 (mail-buffer (current-buffer))
|
|
2762 e-list)
|
|
2763 (unwind-protect
|
|
2764 (progn
|
|
2765 (setq temp-buffer (generate-new-buffer "composition preview"))
|
|
2766 (set-buffer temp-buffer)
|
|
2767 ;; so vm-mime-encode-composition won't complain
|
|
2768 (setq major-mode 'mail-mode)
|
|
2769 (vm-insert-region-from-buffer mail-buffer)
|
|
2770 (goto-char (point-min))
|
|
2771 (or (vm-mail-mode-get-header-contents "From")
|
|
2772 (insert "From: " (or user-mail-address (user-login-name)) "\n"))
|
|
2773 (or (vm-mail-mode-get-header-contents "Message-ID")
|
24
|
2774 (insert "Message-ID: <fake@fake.fake>\n"))
|
20
|
2775 (or (vm-mail-mode-get-header-contents "Date")
|
|
2776 (insert "Date: "
|
|
2777 (format-time-string "%a, %d %b %Y %H%M%S %Z"
|
|
2778 (current-time))
|
|
2779 "\n"))
|
|
2780 (and vm-send-using-mime
|
|
2781 (null (vm-mail-mode-get-header-contents "MIME-Version:"))
|
|
2782 (vm-mime-encode-composition))
|
|
2783 (goto-char (point-min))
|
|
2784 (insert (vm-leading-message-separator 'From_))
|
|
2785 (goto-char (point-max))
|
|
2786 (insert (vm-trailing-message-separator 'From_))
|
|
2787 (set-buffer-modified-p nil)
|
|
2788 ;; point of no return, don't kill it if the user quits
|
|
2789 (setq temp-buffer nil)
|
|
2790 (let ((vm-auto-decode-mime-messages t)
|
|
2791 (vm-auto-displayed-mime-content-types t))
|
|
2792 (vm-save-buffer-excursion
|
|
2793 (vm-goto-new-folder-frame-maybe 'folder)
|
|
2794 (vm-mode)))
|
|
2795 (message
|
|
2796 (substitute-command-keys
|
|
2797 "Type \\[vm-quit] to continue composing your message"))
|
|
2798 ;; temp buffer, don't offer to save it.
|
|
2799 (setq buffer-offer-save nil)
|
|
2800 (vm-display (or vm-presentation-buffer (current-buffer)) t
|
|
2801 (list this-command) '(vm-mode startup)))
|
|
2802 (and temp-buffer (kill-buffer temp-buffer)))))
|
|
2803
|
|
2804 (defun vm-mime-composite-type-p (type)
|
|
2805 (or (vm-mime-types-match "message" type)
|
|
2806 (vm-mime-types-match "multipart" type)))
|
|
2807
|
|
2808 (defun vm-mime-map-atomic-layouts (function list)
|
|
2809 (while list
|
|
2810 (if (vm-mime-composite-type-p (car (vm-mm-layout-type (car list))))
|
|
2811 (vm-mime-map-atomic-layouts function (vm-mm-layout-parts (car list)))
|
|
2812 (funcall function (car list)))
|
|
2813 (setq list (cdr list))))
|