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