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