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