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