annotate lisp/vm/vm-mime.el @ 24:4103f0995bd7 r19-15b95

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