annotate lisp/vm/vm-mime.el @ 20:859a2309aef8 r19-15b93

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