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