4
|
1 ;;; tm-edit.el --- Simple MIME Composer for GNU Emacs
|
|
2
|
70
|
3 ;; Copyright (C) 1993 .. 1996 Free Software Foundation, Inc.
|
4
|
4
|
|
5 ;; Author: UMEDA Masanobu <umerin@mse.kyutech.ac.jp>
|
|
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
|
7 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
|
8 ;; Created: 1994/08/21 renamed from mime.el
|
76
|
9 ;; Version: $Revision: 1.2 $
|
4
|
10 ;; Keywords: mail, news, MIME, multimedia, multilingual
|
|
11
|
|
12 ;; This file is part of tm (Tools for MIME).
|
|
13
|
|
14 ;; This program is free software; you can redistribute it and/or
|
|
15 ;; modify it under the terms of the GNU General Public License as
|
|
16 ;; published by the Free Software Foundation; either version 2, or (at
|
|
17 ;; your option) any later version.
|
|
18
|
|
19 ;; This program is distributed in the hope that it will be useful, but
|
|
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
22 ;; General Public License for more details.
|
|
23
|
|
24 ;; You should have received a copy of the GNU General Public License
|
|
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
27 ;; Boston, MA 02111-1307, USA.
|
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
31 ;; This is an Emacs minor mode for editing Internet multimedia
|
74
|
32 ;; messages formatted in MIME (RFC 2045, 2046, 2047, 2048 and 2049).
|
|
33 ;; All messages in this mode are composed in the tagged MIME format,
|
|
34 ;; that are described in the following examples. The messages
|
|
35 ;; composed in the tagged MIME format are automatically translated
|
|
36 ;; into a MIME compliant message when exiting the mode.
|
4
|
37
|
|
38 ;; Mule (a multilingual extension to Emacs 18 and 19) has a capability
|
|
39 ;; of handling multilingual text in limited ISO-2022 manner that is
|
|
40 ;; based on early experiences in Japanese Internet community and
|
74
|
41 ;; resulted in RFC 1468 (ISO-2022-JP charset for MIME). In order to
|
4
|
42 ;; enable multilingual capability in single text message in MIME,
|
|
43 ;; charset of multilingual text written in Mule is declared as either
|
74
|
44 ;; `ISO-2022-JP-2' [RFC 1554] or `ISO-2022-INT-1'. Mule is required
|
70
|
45 ;; for reading the such messages.
|
4
|
46
|
|
47 ;; This MIME composer can work with Mail mode, mh-e letter Mode, and
|
|
48 ;; News mode. First of all, you need the following autoload
|
|
49 ;; definition to load mime/editor-mode automatically:
|
|
50 ;;
|
|
51 ;; (autoload 'mime/editor-mode "tm-edit"
|
|
52 ;; "Minor mode for editing MIME message." t)
|
|
53 ;;
|
|
54 ;; In case of Mail mode (includes VM mode), you need the following
|
|
55 ;; hook definition:
|
|
56 ;;
|
|
57 ;; (add-hook 'mail-mode-hook 'mime/editor-mode)
|
|
58 ;; (add-hook 'mail-send-hook 'mime-editor/maybe-translate)
|
|
59 ;;
|
|
60 ;; In case of MH-E, you need the following hook definition:
|
|
61 ;;
|
|
62 ;; (add-hook 'mh-letter-mode-hook
|
|
63 ;; (function
|
|
64 ;; (lambda ()
|
|
65 ;; (mime/editor-mode)
|
|
66 ;; (make-local-variable 'mail-header-separator)
|
|
67 ;; (setq mail-header-separator "--------")
|
|
68 ;; ))))
|
|
69 ;; (add-hook 'mh-before-send-letter-hook 'mime-editor/maybe-translate)
|
|
70 ;;
|
|
71 ;; In case of News mode, you need the following hook definition:
|
|
72 ;;
|
|
73 ;; (add-hook 'news-reply-mode-hook 'mime/editor-mode)
|
|
74 ;; (add-hook 'news-inews-hook 'mime-editor/maybe-translate)
|
|
75 ;;
|
|
76 ;; In case of Emacs 19, it is possible to emphasize the message tags
|
|
77 ;; using font-lock mode as follows:
|
|
78 ;;
|
|
79 ;; (add-hook 'mime/editor-mode-hook
|
|
80 ;; (function
|
|
81 ;; (lambda ()
|
|
82 ;; (font-lock-mode 1)
|
|
83 ;; (setq font-lock-keywords (list mime-editor/tag-regexp))
|
|
84 ;; ))))
|
|
85
|
|
86 ;; The message tag looks like:
|
|
87 ;;
|
|
88 ;; --[[TYPE/SUBTYPE;PARAMETERS][ENCODING]]
|
|
89 ;;
|
|
90 ;; The tagged MIME message examples:
|
|
91 ;;
|
|
92 ;; This is a conventional plain text. It should be translated into
|
|
93 ;; text/plain.
|
|
94 ;;
|
|
95 ;;--[[text/plain]]
|
|
96 ;; This is also a plain text. But, it is explicitly specified as is.
|
|
97 ;;
|
70
|
98 ;;--[[text/plain; charset=ISO-2022-JP]]
|
74
|
99 ;; これは charset を ISO-2022-JP に指定した日本語の plain テキストです.
|
70
|
100 ;;
|
|
101 ;;--[[text/richtext]]
|
4
|
102 ;; <center>This is a richtext.</center>
|
|
103 ;;
|
|
104 ;;--[[image/gif][base64]]^M...image encoded in base64 comes here...
|
|
105 ;;
|
|
106 ;;--[[audio/basic][base64]]^M...audio encoded in base64 comes here...
|
|
107
|
|
108 ;;; Code:
|
|
109
|
|
110 (require 'sendmail)
|
|
111 (require 'mail-utils)
|
|
112 (require 'mel)
|
|
113 (require 'tl-list)
|
|
114 (require 'tm-view)
|
|
115 (require 'tm-ew-e)
|
|
116 (require 'signature)
|
|
117
|
|
118
|
|
119 ;;; @ version
|
|
120 ;;;
|
|
121
|
|
122 (defconst mime-editor/RCS-ID
|
76
|
123 "$Id: tm-edit.el,v 1.2 1996/12/28 21:03:13 steve Exp $")
|
4
|
124
|
|
125 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
|
|
126
|
|
127 (defconst mime-editor/version-name
|
|
128 (concat "tm-edit " mime-editor/version))
|
|
129
|
|
130
|
|
131 ;;; @ variables
|
|
132 ;;;
|
|
133
|
|
134 (defvar mime-prefix "\C-c\C-x"
|
|
135 "*Keymap prefix for MIME commands.")
|
|
136
|
|
137 (defvar mime-ignore-preceding-spaces nil
|
|
138 "*Ignore preceding white spaces if non-nil.")
|
|
139
|
|
140 (defvar mime-ignore-trailing-spaces nil
|
|
141 "*Ignore trailing white spaces if non-nil.")
|
|
142
|
|
143 (defvar mime-ignore-same-text-tag t
|
|
144 "*Ignore preceding text content-type tag that is same with new one.
|
|
145 If non-nil, the text tag is not inserted unless something different.")
|
|
146
|
|
147 (defvar mime-auto-hide-body t
|
|
148 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
|
|
149
|
|
150 (defvar mime-editor/voice-recorder
|
|
151 (function mime-editor/voice-recorder-for-sun)
|
|
152 "*Function to record a voice message and encode it. [tm-edit.el]")
|
|
153
|
|
154 (defvar mime/editor-mode-hook nil
|
|
155 "*Hook called when enter MIME mode.")
|
|
156
|
|
157 (defvar mime-editor/translate-hook nil
|
|
158 "*Hook called before translating into a MIME compliant message.
|
|
159 To insert a signature file automatically, call the function
|
|
160 `mime-editor/insert-signature' from this hook.")
|
|
161
|
|
162 (defvar mime-editor/exit-hook nil
|
|
163 "*Hook called when exit MIME mode.")
|
|
164
|
|
165 (defvar mime-content-types
|
|
166 '(("text"
|
|
167 ;; Charset parameter need not to be specified, since it is
|
|
168 ;; defined automatically while translation.
|
|
169 ("plain"
|
|
170 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
|
|
171 )
|
|
172 ("richtext"
|
|
173 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
|
|
174 )
|
|
175 ("enriched"
|
|
176 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
|
|
177 )
|
|
178 ("x-latex"
|
|
179 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
|
|
180 )
|
|
181 ("html"
|
|
182 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
|
|
183 )
|
|
184 ("x-rot13-47")
|
|
185 )
|
|
186 ("message"
|
|
187 ("external-body"
|
|
188 ("access-type"
|
|
189 ("anon-ftp"
|
|
190 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
|
|
191 ("directory" "/pub/GNU/elisp/mime")
|
|
192 ("name")
|
|
193 ("mode" "image" "ascii" "local8"))
|
|
194 ("ftp"
|
|
195 ("site")
|
|
196 ("directory")
|
|
197 ("name")
|
|
198 ("mode" "image" "ascii" "local8"))
|
|
199 ("tftp" ("site") ("name"))
|
|
200 ("afs" ("site") ("name"))
|
|
201 ("local-file" ("site") ("name"))
|
|
202 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
|
|
203 ))
|
|
204 ("rfc822")
|
|
205 )
|
|
206 ("application"
|
|
207 ("octet-stream" ("type" "" "tar" "shar"))
|
|
208 ("postscript")
|
|
209 ("x-kiss" ("x-cnf")))
|
|
210 ("image"
|
|
211 ("gif")
|
|
212 ("jpeg")
|
|
213 ("tiff")
|
|
214 ("x-pic")
|
|
215 ("x-mag")
|
|
216 ("x-xwd")
|
|
217 ("x-xbm")
|
|
218 )
|
|
219 ("audio" ("basic"))
|
|
220 ("video" ("mpeg"))
|
|
221 )
|
|
222 "*Alist of content-type, subtype, parameters and its values.")
|
|
223
|
|
224 (defvar mime-file-types
|
|
225 '(("\\.rtf$"
|
|
226 "text" "richtext" nil
|
|
227 nil
|
|
228 nil nil)
|
|
229 ("\\.html$"
|
|
230 "text" "html" nil
|
|
231 nil
|
|
232 nil nil)
|
|
233 ("\\.ps$"
|
|
234 "application" "postscript" nil
|
|
235 "quoted-printable"
|
|
236 "attachment" (("filename" . file))
|
|
237 )
|
|
238 ("\\.jpg$"
|
|
239 "image" "jpeg" nil
|
|
240 "base64"
|
|
241 "inline" (("filename" . file))
|
|
242 )
|
|
243 ("\\.gif$"
|
|
244 "image" "gif" nil
|
|
245 "base64"
|
|
246 "inline" (("filename" . file))
|
|
247 )
|
|
248 ("\\.tiff$"
|
|
249 "image" "tiff" nil
|
|
250 "base64"
|
|
251 "inline" (("filename" . file))
|
|
252 )
|
|
253 ("\\.pic$"
|
|
254 "image" "x-pic" nil
|
|
255 "base64"
|
|
256 "inline" (("filename" . file))
|
|
257 )
|
|
258 ("\\.mag$"
|
|
259 "image" "x-mag" nil
|
|
260 "base64"
|
|
261 "inline" (("filename" . file))
|
|
262 )
|
|
263 ("\\.xbm$"
|
|
264 "image" "x-xbm" nil
|
|
265 "base64"
|
|
266 "inline" (("filename" . file))
|
|
267 )
|
|
268 ("\\.xwd$"
|
|
269 "image" "x-xwd" nil
|
|
270 "base64"
|
|
271 "inline" (("filename" . file))
|
|
272 )
|
|
273 ("\\.au$"
|
|
274 "audio" "basic" nil
|
|
275 "base64"
|
|
276 "attachment" (("filename" . file))
|
|
277 )
|
|
278 ("\\.mpg$"
|
|
279 "video" "mpeg" nil
|
|
280 "base64"
|
|
281 "attachment" (("filename" . file))
|
|
282 )
|
|
283 ("\\.el$"
|
|
284 "application" "octet-stream" (("type" . "emacs-lisp"))
|
|
285 "7bit"
|
|
286 "attachment" (("filename" . file))
|
|
287 )
|
|
288 ("\\.lsp$"
|
|
289 "application" "octet-stream" (("type" . "common-lisp"))
|
|
290 "7bit"
|
|
291 "attachment" (("filename" . file))
|
|
292 )
|
|
293 ("\\.tar\\.gz$"
|
|
294 "application" "octet-stream" (("type" . "tar+gzip"))
|
76
|
295 "base64"
|
4
|
296 "attachment" (("filename" . file))
|
|
297 )
|
|
298 ("\\.tgz$"
|
|
299 "application" "octet-stream" (("type" . "tar+gzip"))
|
76
|
300 "base64"
|
4
|
301 "attachment" (("filename" . file))
|
|
302 )
|
|
303 ("\\.tar\\.Z$"
|
|
304 "application" "octet-stream" (("type" . "tar+compress"))
|
76
|
305 "base64"
|
4
|
306 "attachment" (("filename" . file))
|
|
307 )
|
|
308 ("\\.taz$"
|
|
309 "application" "octet-stream" (("type" . "tar+compress"))
|
76
|
310 "base64"
|
4
|
311 "attachment" (("filename" . file))
|
|
312 )
|
|
313 ("\\.gz$"
|
|
314 "application" "octet-stream" (("type" . "gzip"))
|
76
|
315 "base64"
|
4
|
316 "attachment" (("filename" . file))
|
|
317 )
|
|
318 ("\\.Z$"
|
|
319 "application" "octet-stream" (("type" . "compress"))
|
76
|
320 "base64"
|
4
|
321 "attachment" (("filename" . file))
|
|
322 )
|
|
323 ("\\.lzh$"
|
|
324 "application" "octet-stream" (("type" . "lha"))
|
76
|
325 "base64"
|
4
|
326 "attachment" (("filename" . file))
|
|
327 )
|
|
328 ("\\.zip$"
|
|
329 "application" "zip" nil
|
76
|
330 "base64"
|
4
|
331 "attachment" (("filename" . file))
|
|
332 )
|
|
333 ("\\.diff$"
|
|
334 "application" "octet-stream" (("type" . "patch"))
|
|
335 nil
|
|
336 "attachment" (("filename" . file))
|
|
337 )
|
|
338 ("\\.patch$"
|
|
339 "application" "octet-stream" (("type" . "patch"))
|
|
340 nil
|
|
341 "attachment" (("filename" . file))
|
|
342 )
|
|
343 ("\\.signature"
|
|
344 "text" "plain" nil nil)
|
|
345 (".*"
|
|
346 "application" "octet-stream" nil
|
|
347 nil
|
|
348 "attachment" (("filename" . file))
|
|
349 )
|
|
350 )
|
|
351 "*Alist of file name, types, parameters, and default encoding.
|
|
352 If encoding is nil, it is determined from its contents.")
|
|
353
|
|
354 ;;; @@ about charset, encoding and transfer-level
|
|
355 ;;;
|
|
356
|
|
357 (defvar mime-editor/transfer-level 7
|
76
|
358 "*A number of network transfer level. It should be bigger than 7.")
|
4
|
359 (make-variable-buffer-local 'mime-editor/transfer-level)
|
|
360
|
|
361 (defvar mime-editor/transfer-level-string
|
|
362 (mime/encoding-name mime-editor/transfer-level 'not-omit)
|
|
363 "*A string formatted version of mime/defaul-transfer-level")
|
|
364 (make-variable-buffer-local 'mime-editor/transfer-level-string)
|
|
365
|
|
366 (defun mime-editor/make-charset-default-encoding-alist (transfer-level)
|
|
367 (mapcar (function
|
|
368 (lambda (charset-type)
|
|
369 (let ((charset (car charset-type))
|
|
370 (type (nth 1 charset-type))
|
|
371 (encoding (nth 2 charset-type))
|
|
372 )
|
|
373 (if (<= type transfer-level)
|
|
374 (cons charset (mime/encoding-name type))
|
|
375 (cons charset encoding)
|
|
376 ))))
|
|
377 mime-charset-type-list))
|
|
378
|
|
379 (defvar mime-editor/charset-default-encoding-alist
|
|
380 (mime-editor/make-charset-default-encoding-alist mime-editor/transfer-level))
|
|
381 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
|
|
382
|
|
383 ;;; @@ about message inserting
|
|
384 ;;;
|
|
385
|
|
386 (defvar mime-editor/yank-ignored-field-list
|
|
387 '("Received" "Approved" "Path" "Replied" "Status"
|
|
388 "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
|
|
389 "Delete these fields from original message when it is inserted
|
|
390 as message/rfc822 part.
|
|
391 Each elements are regexp of field-name. [tm-edit.el]")
|
|
392
|
|
393 (defvar mime-editor/yank-ignored-field-regexp
|
|
394 (concat "^"
|
|
395 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
|
|
396 ":"))
|
|
397
|
|
398 (defvar mime-editor/message-inserter-alist nil)
|
|
399 (defvar mime-editor/mail-inserter-alist nil)
|
|
400
|
|
401 ;;; @@ about message splitting
|
|
402 ;;;
|
|
403
|
|
404 (defvar mime-editor/split-message t
|
|
405 "*Split large message if it is non-nil. [tm-edit.el]")
|
|
406
|
|
407 (defvar mime-editor/message-default-max-lines 1000
|
|
408 "*Default maximum lines of a message. [tm-edit.el]")
|
|
409
|
|
410 (defvar mime-editor/message-max-lines-alist
|
|
411 '((news-reply-mode . 500))
|
|
412 "Alist of major-mode vs maximum lines of a message.
|
|
413 If it is not specified for a major-mode,
|
|
414 `mime-editor/message-default-max-lines' is used. [tm-edit.el]")
|
|
415
|
|
416 (defconst mime-editor/split-ignored-field-regexp
|
|
417 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
|
|
418
|
|
419 (defvar mime-editor/split-blind-field-regexp
|
|
420 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
|
|
421
|
|
422 (defvar mime-editor/split-message-sender-alist nil)
|
|
423
|
|
424 (defvar mime-editor/news-reply-mode-server-running nil)
|
|
425
|
|
426
|
|
427 ;;; @@ about PGP
|
|
428 ;;;
|
|
429
|
|
430 (defvar mime-editor/signing-type 'pgp-elkins
|
|
431 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
|
|
432
|
|
433 (defvar mime-editor/encrypting-type 'pgp-elkins
|
|
434 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
|
|
435
|
70
|
436 (defvar mime-editor/pgp-sign-function 'tm:mc-pgp-sign-region)
|
|
437 (defvar mime-editor/pgp-encrypt-function 'tm:mc-pgp-encrypt-region)
|
|
438 (defvar mime-editor/traditional-pgp-sign-function 'mc-pgp-sign-region)
|
|
439 (defvar mime-editor/pgp-insert-public-key-function 'mc-insert-public-key)
|
|
440
|
|
441 (autoload mime-editor/pgp-sign-function "tm-edit-mc")
|
|
442 (autoload mime-editor/pgp-encrypt-function "tm-edit-mc")
|
|
443 (autoload mime-editor/traditional-pgp-sign-function "mc-pgp")
|
|
444 (autoload mime-editor/pgp-insert-public-key-function "mc-toplev")
|
|
445
|
4
|
446
|
|
447 ;;; @@ about tag
|
|
448 ;;;
|
|
449
|
|
450 (defconst mime-editor/single-part-tag-regexp
|
|
451 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
|
|
452 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
|
|
453
|
|
454 (defconst mime-editor/quoted-single-part-tag-regexp
|
|
455 (concat "- " (substring mime-editor/single-part-tag-regexp 1)))
|
|
456
|
|
457 (defconst mime-editor/multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
|
|
458
|
|
459 (defconst mime-editor/multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
|
|
460
|
|
461 (defconst mime-editor/beginning-tag-regexp
|
|
462 (regexp-or mime-editor/single-part-tag-regexp
|
|
463 mime-editor/multipart-beginning-regexp))
|
|
464
|
|
465 (defconst mime-editor/end-tag-regexp
|
|
466 (regexp-or mime-editor/single-part-tag-regexp
|
|
467 mime-editor/multipart-end-regexp))
|
|
468
|
|
469 (defconst mime-editor/tag-regexp
|
|
470 (regexp-or mime-editor/single-part-tag-regexp
|
|
471 mime-editor/multipart-beginning-regexp
|
|
472 mime-editor/multipart-end-regexp))
|
|
473
|
|
474 (defvar mime-tag-format "--[[%s]]"
|
|
475 "*Control-string making a MIME tag.")
|
|
476
|
|
477 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
|
|
478 "*Control-string making a MIME tag with encoding.")
|
|
479
|
|
480 ;;; @@ multipart boundary
|
|
481 ;;;
|
|
482
|
|
483 (defvar mime-multipart-boundary "Multipart"
|
|
484 "*Boundary of a multipart message.")
|
|
485
|
|
486
|
|
487 ;;; @@ buffer local variables
|
|
488 ;;;
|
|
489
|
|
490 (defvar mime/editor-mode-old-local-map nil)
|
|
491 (defvar mime/editing-buffer nil)
|
|
492
|
|
493
|
|
494 ;;; @ constants
|
|
495 ;;;
|
|
496
|
|
497 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
|
|
498 "*Specify MIME tspecials.
|
|
499 Tspecials means any character that matches with it in header must be quoted.")
|
|
500
|
|
501 (defconst mime-editor/mime-version-value
|
|
502 (concat "1.0 (generated by " mime-editor/version-name ")")
|
|
503 "MIME version number.")
|
|
504
|
|
505 (defconst mime-editor/mime-map (make-sparse-keymap)
|
|
506 "Keymap for MIME commands.")
|
|
507
|
|
508 ;;; @ keymap and menu
|
|
509 ;;;
|
|
510
|
|
511 (defvar mime/editor-mode-flag nil)
|
|
512 (make-variable-buffer-local 'mime/editor-mode-flag)
|
|
513
|
|
514 (defun mime-editor/define-keymap (keymap)
|
|
515 "Add mime-editor commands to KEYMAP."
|
|
516 (if (not (keymapp keymap))
|
|
517 nil
|
|
518 (define-key keymap "\C-t" 'mime-editor/insert-text)
|
|
519 (define-key keymap "\C-i" 'mime-editor/insert-file)
|
|
520 (define-key keymap "\C-e" 'mime-editor/insert-external)
|
|
521 (define-key keymap "\C-v" 'mime-editor/insert-voice)
|
|
522 (define-key keymap "\C-y" 'mime-editor/insert-message)
|
|
523 (define-key keymap "\C-m" 'mime-editor/insert-mail)
|
|
524 (define-key keymap "\C-w" 'mime-editor/insert-signature)
|
|
525 (define-key keymap "\C-s" 'mime-editor/insert-signature)
|
|
526 (define-key keymap "\C-k" 'mime-editor/insert-key)
|
|
527 (define-key keymap "t" 'mime-editor/insert-tag)
|
|
528 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
|
|
529 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
|
|
530 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
|
|
531 (define-key keymap "d" 'mime-editor/enclose-digest-region)
|
|
532 (define-key keymap "s" 'mime-editor/enclose-signed-region)
|
|
533 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
|
|
534 (define-key keymap "q" 'mime-editor/enclose-quote-region)
|
|
535 (define-key keymap "7" 'mime-editor/set-transfer-level-7bit)
|
|
536 (define-key keymap "8" 'mime-editor/set-transfer-level-8bit)
|
|
537 (define-key keymap "/" 'mime-editor/set-split)
|
|
538 (define-key keymap "v" 'mime-editor/set-sign)
|
|
539 (define-key keymap "h" 'mime-editor/set-encrypt)
|
|
540 (define-key keymap "\C-p" 'mime-editor/preview-message)
|
|
541 (define-key keymap "\C-z" 'mime-editor/exit)
|
|
542 (define-key keymap "?" 'mime-editor/help)
|
|
543 ))
|
|
544
|
|
545 (mime-editor/define-keymap mime-editor/mime-map)
|
|
546
|
|
547 (defun mime-editor/toggle-mode ()
|
|
548 (interactive)
|
|
549 (if mime/editor-mode-flag
|
|
550 (mime-editor/exit 'nomime)
|
|
551 (mime/editor-mode)
|
|
552 ))
|
|
553
|
|
554 (cond (running-xemacs
|
|
555 (defconst mime-editor/minor-mime-map nil "Keymap for MIME commands.")
|
|
556 (or mime-editor/minor-mime-map
|
|
557 (progn
|
|
558 (setq mime-editor/minor-mime-map
|
|
559 (make-sparse-keymap 'mime-editor/minor-mime-map))
|
|
560 (define-key
|
|
561 mime-editor/minor-mime-map mime-prefix mime-editor/mime-map)
|
|
562 ))
|
|
563 (add-minor-mode 'mime/editor-mode-flag
|
|
564 '((" MIME-Edit " mime-editor/transfer-level-string))
|
|
565 mime-editor/minor-mime-map
|
|
566 nil
|
|
567 'mime-editor/toggle-mode)
|
|
568 )
|
|
569 (t
|
|
570 (set-alist 'minor-mode-alist
|
|
571 'mime/editor-mode-flag
|
|
572 '((" MIME-Edit " mime-editor/transfer-level-string))))
|
|
573 )
|
|
574
|
|
575 (defconst mime-editor/menu-title "MIME-Edit")
|
|
576
|
|
577 (defconst mime-editor/menu-list
|
|
578 '((mime-help "Describe MIME editor mode" mime-editor/help)
|
|
579 (file "Insert File" mime-editor/insert-file)
|
|
580 (external "Insert External" mime-editor/insert-external)
|
|
581 (voice "Insert Voice" mime-editor/insert-voice)
|
|
582 (message "Insert Message" mime-editor/insert-message)
|
|
583 (mail "Insert Mail" mime-editor/insert-mail)
|
|
584 (signature "Insert Signature" mime-editor/insert-signature)
|
|
585 (text "Insert Text" mime-editor/insert-text)
|
|
586 (tag "Insert Tag" mime-editor/insert-tag)
|
|
587 (alternative "Enclose as alternative"
|
|
588 mime-editor/enclose-alternative-region)
|
|
589 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
|
|
590 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
|
|
591 (digest "Enclose as digest" mime-editor/enclose-digest-region)
|
|
592 (signed "Enclose as signed" mime-editor/enclose-signed-region)
|
|
593 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
|
|
594 (quote "Verbatim region" mime-editor/enclose-quote-region)
|
|
595 (key "Insert Public Key" mime-editor/insert-key)
|
|
596 (split "About split" mime-editor/set-split)
|
|
597 (sign "About sign" mime-editor/set-sign)
|
|
598 (encrypt "About encryption" mime-editor/set-encrypt)
|
|
599 (preview "Preview Message" mime-editor/preview-message)
|
|
600 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
|
|
601 )
|
|
602 "MIME-edit menubar entry.")
|
|
603
|
|
604 (defun mime-editor/define-menu-for-emacs19 ()
|
|
605 "Define menu for Emacs 19."
|
|
606 (define-key (current-local-map) [menu-bar mime-edit]
|
|
607 (cons mime-editor/menu-title
|
|
608 (make-sparse-keymap mime-editor/menu-title)))
|
|
609 (mapcar (function
|
|
610 (lambda (item)
|
|
611 (define-key (current-local-map)
|
|
612 (vector 'menu-bar 'mime-edit (car item))
|
|
613 (cons (nth 1 item)(nth 2 item))
|
|
614 )
|
|
615 ))
|
|
616 (reverse mime-editor/menu-list)
|
|
617 ))
|
|
618
|
|
619 ;;; modified by Pekka Marjola <pema@iki.fi>
|
|
620 ;;; 1995/9/5 (c.f. [tm-en:69])
|
|
621 (defun mime-editor/define-menu-for-xemacs ()
|
|
622 "Define menu for Emacs 19."
|
|
623 (cond ((featurep 'menubar)
|
|
624 (make-local-variable 'current-menubar)
|
|
625 (set-buffer-menubar current-menubar)
|
|
626 (add-submenu nil
|
|
627 (cons mime-editor/menu-title
|
|
628 (mapcar (function
|
|
629 (lambda (item)
|
|
630 (vector (nth 1 item)(nth 2 item)
|
|
631 mime/editor-mode-flag)
|
|
632 ))
|
|
633 mime-editor/menu-list)))
|
|
634 )))
|
|
635
|
|
636 ;;; modified by Steven L. Baur <steve@miranova.com>
|
|
637 ;;; 1995/12/6 (c.f. [tm-en:209])
|
|
638 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
|
|
639 (setq mime-editor/popup-menu-for-xemacs
|
|
640 (append '("MIME Commands" "---")
|
|
641 (mapcar (function (lambda (item)
|
|
642 (vector (nth 1 item)
|
|
643 (nth 2 item)
|
|
644 t)))
|
|
645 mime-editor/menu-list)))
|
|
646 )
|
|
647 ;;; end
|
|
648
|
|
649
|
|
650 ;;; @ functions
|
|
651 ;;;
|
|
652
|
76
|
653 ;; The following text was removed from the docstring of the subsequent
|
|
654 ;; functions due to problems with the resulting autoload file. -sb
|
|
655
|
|
656 ;; --[[text/plain; charset=ISO-2022-JP]]
|
|
657 ;; これは charset を ISO-2022-JP に指定した日本語の plain テキス
|
|
658 ;; トです.
|
|
659
|
|
660
|
4
|
661 ;;;###autoload
|
|
662 (defun mime/editor-mode ()
|
|
663 "MIME minor mode for editing the tagged MIME message.
|
|
664
|
|
665 In this mode, basically, the message is composed in the tagged MIME
|
|
666 format. The message tag looks like:
|
|
667
|
76
|
668 --[[text/plain; charset=ISO-2022-JP][7bit]]
|
4
|
669
|
|
670 The tag specifies the MIME content type, subtype, optional parameters
|
|
671 and transfer encoding of the message following the tag. Messages
|
|
672 without any tag are treated as `text/plain' by default. Charset and
|
|
673 transfer encoding are automatically defined unless explicitly
|
|
674 specified. Binary messages such as audio and image are usually hidden.
|
|
675 The messages in the tagged MIME format are automatically translated
|
|
676 into a MIME compliant message when exiting this mode.
|
|
677
|
|
678 Available charsets depend on Emacs version being used. The following
|
|
679 lists the available charsets of each emacs.
|
|
680
|
|
681 EMACS 18: US-ASCII is only available.
|
|
682 NEmacs: US-ASCII and ISO-2022-JP are available.
|
|
683 EMACS 19: US-ASCII and ISO-8859-1 (or other charset) are available.
|
|
684 XEmacs 19: US-ASCII and ISO-8859-1 (or other charset) are available.
|
|
685 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
|
|
686 ISO-2022-JP, ISO-2022-JP-2, ISO-2022-KR, BIG5 and
|
|
687 ISO-2022-INT-1 are available.
|
|
688
|
|
689 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
|
|
690 be used to represent multilingual text in intermixed manner. Any
|
|
691 languages that has no registered charset are represented as either
|
|
692 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
|
|
693
|
|
694 If you want to use non-ISO-8859-1 charset in EMACS 19 or XEmacs 19,
|
|
695 please set variable `default-mime-charset'. This variable must be
|
|
696 symbol of which name is a MIME charset.
|
|
697
|
|
698 If you want to add more charsets in mule, please set variable
|
|
699 `charsets-mime-charset-alist'. This variable must be alist of which
|
|
700 key is list of leading-char/charset and value is symbol of MIME
|
|
701 charset. (leading-char is a term of MULE 1.* and 2.*. charset is a
|
|
702 term of XEmacs/mule, mule merged EMACS and MULE 3.*) If name of
|
|
703 coding-system is different as MIME charset, please set variable
|
|
704 `mime-charset-coding-system-alist'. This variable must be alist of
|
|
705 which key is MIME charset and value is coding-system.
|
|
706
|
|
707 Following commands are available in addition to major mode commands:
|
76
|
708
|
|
709 \[make single part\]
|
4
|
710 \\[mime-editor/insert-text] insert a text message.
|
|
711 \\[mime-editor/insert-file] insert a (binary) file.
|
|
712 \\[mime-editor/insert-external] insert a reference to external body.
|
|
713 \\[mime-editor/insert-voice] insert a voice message.
|
|
714 \\[mime-editor/insert-message] insert a mail or news message.
|
|
715 \\[mime-editor/insert-mail] insert a mail message.
|
|
716 \\[mime-editor/insert-signature] insert a signature file at end.
|
76
|
717 \\[mime-editor/insert-key] insert PGP public key.
|
4
|
718 \\[mime-editor/insert-tag] insert a new MIME tag.
|
76
|
719
|
|
720 \[make enclosure (maybe multipart)\]
|
4
|
721 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
|
|
722 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
|
|
723 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
|
|
724 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
|
|
725 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
|
|
726 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
|
76
|
727 \\[mime-editor/enclose-quote-region] enclose as verbose mode (to avoid to expand tags)
|
|
728
|
|
729 \[other commands\]
|
|
730 \\[mime-editor/set-transfer-level-7bit] set transfer-level as 7.
|
|
731 \\[mime-editor/set-transfer-level-8bit] set transfer-level as 8.
|
|
732 \\[mime-editor/set-split] set message splitting mode.
|
|
733 \\[mime-editor/set-sign] set PGP-sign mode.
|
|
734 \\[mime-editor/set-encrypt] set PGP-encryption mode.
|
4
|
735 \\[mime-editor/preview-message] preview editing MIME message.
|
|
736 \\[mime-editor/exit] exit and translate into a MIME compliant message.
|
76
|
737 \\[mime-editor/help] show this help.
|
70
|
738 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
|
4
|
739
|
|
740 Additional commands are available in some major modes:
|
|
741 C-c C-c exit, translate and run the original command.
|
|
742 C-c C-s exit, translate and run the original command.
|
|
743
|
|
744 The following is a message example written in the tagged MIME format.
|
|
745 TABs at the beginning of the line are not a part of the message:
|
|
746
|
|
747 This is a conventional plain text. It should be translated
|
|
748 into text/plain.
|
|
749 --[[text/plain]]
|
|
750 This is also a plain text. But, it is explicitly specified as
|
|
751 is.
|
70
|
752 --[[text/richtext]]
|
|
753 <center>This is a richtext.</center>
|
|
754 --[[image/gif][base64]]^M...image encoded in base64 here...
|
|
755 --[[audio/basic][base64]]^M...audio encoded in base64 here...
|
4
|
756
|
|
757 User customizable variables (not documented all of them):
|
|
758 mime-prefix
|
|
759 Specifies a key prefix for MIME minor mode commands.
|
|
760
|
|
761 mime-ignore-preceding-spaces
|
|
762 Preceding white spaces in a message body are ignored if non-nil.
|
|
763
|
|
764 mime-ignore-trailing-spaces
|
|
765 Trailing white spaces in a message body are ignored if non-nil.
|
|
766
|
|
767 mime-auto-hide-body
|
|
768 Hide a non-textual body message encoded in base64 after insertion
|
|
769 if non-nil.
|
|
770
|
76
|
771 mime-editor/transfer-level
|
|
772 A number of network transfer level. It should be bigger than 7.
|
|
773 If you are in 8bit-through environment, please set 8.
|
|
774
|
4
|
775 mime-editor/voice-recorder
|
|
776 Specifies a function to record a voice message and encode it.
|
|
777 The function `mime-editor/voice-recorder-for-sun' is for Sun
|
|
778 SparcStations.
|
|
779
|
|
780 mime/editor-mode-hook
|
|
781 Turning on MIME mode calls the value of mime/editor-mode-hook, if
|
|
782 it is non-nil.
|
|
783
|
|
784 mime-editor/translate-hook
|
|
785 The value of mime-editor/translate-hook is called just before translating
|
|
786 the tagged MIME format into a MIME compliant message if it is
|
|
787 non-nil. If the hook call the function mime-editor/insert-signature,
|
|
788 the signature file will be inserted automatically.
|
|
789
|
|
790 mime-editor/exit-hook
|
|
791 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
|
|
792 non-nil."
|
|
793 (interactive)
|
|
794 (if mime/editor-mode-flag
|
|
795 (error "You are already editing a MIME message.")
|
|
796 (setq mime/editor-mode-flag t)
|
|
797 ;; Remember old key bindings.
|
|
798 (if running-xemacs
|
|
799 (use-local-map (or (current-local-map) (make-sparse-keymap)))
|
|
800 (make-local-variable 'mime/editor-mode-old-local-map)
|
|
801 (setq mime/editor-mode-old-local-map (current-local-map))
|
|
802 ;; Add MIME commands to current local map.
|
|
803 (use-local-map (copy-keymap (or (current-local-map)
|
|
804 (make-sparse-keymap))))
|
|
805 )
|
|
806 (if (not (lookup-key (current-local-map) mime-prefix))
|
|
807 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
|
|
808
|
|
809 ;; Set transfer level into mode line
|
|
810 ;;
|
|
811 (setq mime-editor/transfer-level-string
|
|
812 (mime/encoding-name mime-editor/transfer-level 'not-omit))
|
|
813 (force-mode-line-update)
|
|
814
|
|
815 ;; Define menu. Menus for other emacs implementations are
|
|
816 ;; welcome.
|
|
817 (cond (running-xemacs
|
|
818 (mime-editor/define-menu-for-xemacs))
|
|
819 ((>= emacs-major-version 19)
|
|
820 (mime-editor/define-menu-for-emacs19)
|
|
821 ))
|
|
822 ;; end
|
|
823
|
|
824 (enable-invisible)
|
|
825
|
|
826 ;; I don't care about saving these.
|
|
827 (setq paragraph-start
|
|
828 (regexp-or mime-editor/single-part-tag-regexp
|
|
829 paragraph-start))
|
|
830 (setq paragraph-separate
|
|
831 (regexp-or mime-editor/single-part-tag-regexp
|
|
832 paragraph-separate))
|
|
833 (run-hooks 'mime/editor-mode-hook)
|
|
834 (message
|
|
835 (substitute-command-keys
|
|
836 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
|
|
837 ))
|
|
838
|
|
839 ;;;###autoload
|
|
840 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
|
|
841 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
|
|
842
|
|
843 (defun mime-editor/exit (&optional nomime no-error)
|
|
844 "Translate the tagged MIME message into a MIME compliant message.
|
|
845 With no argument encode a message in the buffer into MIME, otherwise
|
|
846 just return to previous mode."
|
|
847 (interactive "P")
|
|
848 (if (not mime/editor-mode-flag)
|
|
849 (if (null no-error)
|
|
850 (error "You aren't editing a MIME message.")
|
|
851 )
|
|
852 (if (not nomime)
|
|
853 (progn
|
|
854 (run-hooks 'mime-editor/translate-hook)
|
|
855 (mime-editor/translate-buffer)))
|
|
856 ;; Restore previous state.
|
|
857 (setq mime/editor-mode-flag nil)
|
|
858 (cond (running-xemacs
|
70
|
859 (delete-menu-item (list mime-editor/menu-title)))
|
4
|
860 (t
|
|
861 (use-local-map mime/editor-mode-old-local-map)))
|
|
862
|
|
863 (end-of-invisible)
|
|
864 (set-buffer-modified-p (buffer-modified-p))
|
|
865 (run-hooks 'mime-editor/exit-hook)
|
|
866 (message "Exit MIME editor mode.")
|
|
867 ))
|
|
868
|
|
869 (defun mime-editor/maybe-translate ()
|
|
870 (interactive)
|
|
871 (mime-editor/exit nil t)
|
|
872 (call-interactively 'mime-editor/maybe-split-and-send)
|
|
873 )
|
|
874
|
|
875 (defun mime-editor/help ()
|
|
876 "Show help message about MIME mode."
|
|
877 (interactive)
|
|
878 (with-output-to-temp-buffer "*Help*"
|
|
879 (princ "MIME editor mode:\n")
|
|
880 (princ (documentation 'mime/editor-mode))
|
|
881 (print-help-return-message)))
|
|
882
|
|
883 (defun mime-editor/insert-text ()
|
|
884 "Insert a text message.
|
70
|
885 Charset is automatically obtained from the `mime/lc-charset-alist'."
|
4
|
886 (interactive)
|
|
887 (let ((ret (mime-editor/insert-tag "text" nil nil)))
|
|
888 (if ret
|
|
889 (progn
|
|
890 (if (looking-at mime-editor/single-part-tag-regexp)
|
|
891 (progn
|
|
892 ;; Make a space between the following message.
|
|
893 (insert "\n")
|
|
894 (forward-char -1)
|
|
895 ))
|
|
896 (if (and (member (second ret) '("enriched" "richtext"))
|
|
897 (fboundp 'enriched-mode)
|
|
898 )
|
|
899 (enriched-mode t)
|
|
900 (if (boundp 'enriched-mode)
|
|
901 (enriched-mode nil)
|
|
902 ))))))
|
|
903
|
76
|
904 (defun mime-editor/insert-file (file &optional verbose)
|
4
|
905 "Insert a message from a file."
|
76
|
906 (interactive "fInsert file as MIME message: \nP")
|
4
|
907 (let* ((guess (mime-find-file-type file))
|
76
|
908 (type (nth 0 guess))
|
4
|
909 (subtype (nth 1 guess))
|
|
910 (parameters (nth 2 guess))
|
76
|
911 (encoding (nth 3 guess))
|
4
|
912 (disposition-type (nth 4 guess))
|
|
913 (disposition-params (nth 5 guess))
|
76
|
914 )
|
|
915 (if verbose
|
|
916 (setq type (mime-prompt-for-type type)
|
|
917 subtype (mime-prompt-for-subtype type subtype)
|
|
918 ))
|
|
919 (if (or (interactive-p) verbose)
|
|
920 (setq encoding (mime-prompt-for-encoding encoding))
|
|
921 )
|
4
|
922 (if (or (consp parameters) (stringp disposition-type))
|
|
923 (let ((rest parameters) cell attribute value)
|
|
924 (setq parameters "")
|
|
925 (while rest
|
|
926 (setq cell (car rest))
|
|
927 (setq attribute (car cell))
|
|
928 (setq value (cdr cell))
|
|
929 (if (eq value 'file)
|
|
930 (setq value (std11-wrap-as-quoted-string
|
|
931 (file-name-nondirectory file)))
|
|
932 )
|
|
933 (setq parameters (concat parameters "; " attribute "=" value))
|
|
934 (setq rest (cdr rest))
|
|
935 )
|
|
936 (if disposition-type
|
|
937 (progn
|
|
938 (setq parameters
|
|
939 (concat parameters "\n"
|
|
940 "Content-Disposition: " disposition-type))
|
|
941 (setq rest disposition-params)
|
|
942 (while rest
|
|
943 (setq cell (car rest))
|
|
944 (setq attribute (car cell))
|
|
945 (setq value (cdr cell))
|
|
946 (if (eq value 'file)
|
|
947 (setq value (std11-wrap-as-quoted-string
|
|
948 (file-name-nondirectory file)))
|
|
949 )
|
|
950 (setq parameters
|
|
951 (concat parameters "; " attribute "=" value))
|
|
952 (setq rest (cdr rest))
|
|
953 )
|
|
954 ))
|
|
955 ))
|
76
|
956 (mime-editor/insert-tag type subtype parameters)
|
4
|
957 (mime-editor/insert-binary-file file encoding)
|
|
958 ))
|
|
959
|
|
960 (defun mime-editor/insert-external ()
|
|
961 "Insert a reference to external body."
|
|
962 (interactive)
|
|
963 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
|
|
964 ;;(forward-char -1)
|
|
965 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
|
|
966 ;;(forward-line 1)
|
|
967 (let* ((pritype (mime-prompt-for-type))
|
|
968 (subtype (mime-prompt-for-subtype pritype))
|
|
969 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
|
|
970 (and pritype
|
|
971 subtype
|
|
972 (insert "Content-Type: "
|
|
973 pritype "/" subtype (or parameters "") "\n")))
|
|
974 (if (and (not (eobp))
|
|
975 (not (looking-at mime-editor/single-part-tag-regexp)))
|
|
976 (insert (mime-make-text-tag) "\n")))
|
|
977
|
|
978 (defun mime-editor/insert-voice ()
|
|
979 "Insert a voice message."
|
|
980 (interactive)
|
|
981 (let ((encoding
|
|
982 (completing-read
|
|
983 "What transfer encoding: "
|
|
984 mime-file-encoding-method-alist nil t nil)))
|
|
985 (mime-editor/insert-tag "audio" "basic" nil)
|
|
986 (mime-editor/define-encoding encoding)
|
|
987 (save-restriction
|
|
988 (narrow-to-region (1- (point))(point))
|
|
989 (unwind-protect
|
|
990 (funcall mime-editor/voice-recorder encoding)
|
|
991 (progn
|
|
992 (insert "\n")
|
|
993 (invisible-region (point-min)(point-max))
|
|
994 (goto-char (point-max))
|
|
995 )))))
|
|
996
|
|
997 (defun mime-editor/insert-signature (&optional arg)
|
|
998 "Insert a signature file."
|
|
999 (interactive "P")
|
|
1000 (let ((signature-insert-hook
|
|
1001 (function
|
|
1002 (lambda ()
|
|
1003 (apply (function mime-editor/insert-tag)
|
|
1004 (mime-find-file-type signature-file-name))
|
|
1005 )))
|
|
1006 )
|
|
1007 (insert-signature arg)
|
|
1008 ))
|
|
1009
|
|
1010
|
|
1011 ;; Insert a new tag around a point.
|
|
1012
|
|
1013 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
|
|
1014 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
|
|
1015 If nothing is inserted, return nil."
|
|
1016 (interactive)
|
|
1017 (let ((p (point)))
|
|
1018 (mime-editor/goto-tag)
|
|
1019 (if (and (re-search-forward mime-editor/tag-regexp nil t)
|
|
1020 (< (match-beginning 0) p)
|
|
1021 (< p (match-end 0))
|
|
1022 )
|
|
1023 (goto-char (match-beginning 0))
|
|
1024 (goto-char p)
|
|
1025 ))
|
|
1026 (let ((oldtag nil)
|
|
1027 (newtag nil)
|
|
1028 (current (point))
|
|
1029 )
|
|
1030 (setq pritype
|
|
1031 (or pritype
|
|
1032 (mime-prompt-for-type)))
|
|
1033 (setq subtype
|
|
1034 (or subtype
|
|
1035 (mime-prompt-for-subtype pritype)))
|
|
1036 (setq parameters
|
|
1037 (or parameters
|
|
1038 (mime-prompt-for-parameters pritype subtype delimiter)))
|
|
1039 ;; Make a new MIME tag.
|
|
1040 (setq newtag (mime-make-tag pritype subtype parameters))
|
|
1041 ;; Find an current MIME tag.
|
|
1042 (setq oldtag
|
|
1043 (save-excursion
|
|
1044 (if (mime-editor/goto-tag)
|
|
1045 (buffer-substring (match-beginning 0) (match-end 0))
|
|
1046 ;; Assume content type is 'text/plan'.
|
|
1047 (mime-make-tag "text" "plain")
|
|
1048 )))
|
|
1049 ;; We are only interested in TEXT.
|
|
1050 (if (and oldtag
|
|
1051 (not (mime-test-content-type
|
|
1052 (mime-editor/get-contype oldtag) "text")))
|
|
1053 (setq oldtag nil))
|
|
1054 ;; Make a new tag.
|
|
1055 (if (or (not oldtag) ;Not text
|
|
1056 (or mime-ignore-same-text-tag
|
|
1057 (not (string-equal oldtag newtag))))
|
|
1058 (progn
|
|
1059 ;; Mark the beginning of the tag for convenience.
|
|
1060 (push-mark (point) 'nomsg)
|
|
1061 (insert newtag "\n")
|
|
1062 (list pritype subtype parameters) ;New tag is created.
|
|
1063 )
|
|
1064 ;; Restore previous point.
|
|
1065 (goto-char current)
|
|
1066 nil ;Nothing is created.
|
|
1067 )
|
|
1068 ))
|
|
1069
|
|
1070 (defun mime-editor/insert-binary-file (file &optional encoding)
|
|
1071 "Insert binary FILE at point.
|
|
1072 Optional argument ENCODING specifies an encoding method such as base64."
|
|
1073 (let* ((tagend (1- (point))) ;End of the tag
|
|
1074 (hide-p (and mime-auto-hide-body
|
|
1075 (stringp encoding)
|
|
1076 (not
|
|
1077 (let ((en (downcase encoding)))
|
|
1078 (or (string-equal en "7bit")
|
|
1079 (string-equal en "8bit")
|
|
1080 (string-equal en "binary")
|
|
1081 )))))
|
|
1082 )
|
|
1083 (save-restriction
|
|
1084 (narrow-to-region tagend (point))
|
|
1085 (mime-insert-encoded-file file encoding)
|
|
1086 (if hide-p
|
|
1087 (progn
|
|
1088 (invisible-region (point-min) (point-max))
|
|
1089 (goto-char (point-max))
|
|
1090 )
|
|
1091 (goto-char (point-max))
|
|
1092 ))
|
|
1093 (or hide-p
|
|
1094 (looking-at mime-editor/tag-regexp)
|
|
1095 (= (point)(point-max))
|
|
1096 (mime-editor/insert-tag "text" "plain")
|
|
1097 )
|
|
1098 ;; Define encoding even if it is 7bit.
|
|
1099 (if (stringp encoding)
|
|
1100 (save-excursion
|
|
1101 (goto-char tagend) ; Make sure which line the tag is on.
|
|
1102 (mime-editor/define-encoding encoding)
|
|
1103 ))
|
|
1104 ))
|
|
1105
|
|
1106
|
|
1107 ;; Commands work on a current message flagment.
|
|
1108
|
|
1109 (defun mime-editor/goto-tag ()
|
|
1110 "Search for the beginning of the tagged MIME message."
|
|
1111 (let ((current (point)) multipart)
|
|
1112 (if (looking-at mime-editor/tag-regexp)
|
|
1113 t
|
|
1114 ;; At first, go to the end.
|
|
1115 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
|
|
1116 (goto-char (1- (match-beginning 0))) ;For multiline tag
|
|
1117 )
|
|
1118 (t
|
|
1119 (goto-char (point-max))
|
|
1120 ))
|
|
1121 ;; Then search for the beginning.
|
|
1122 (re-search-backward mime-editor/end-tag-regexp nil t)
|
|
1123 (or (looking-at mime-editor/beginning-tag-regexp)
|
|
1124 ;; Restore previous point.
|
|
1125 (progn
|
|
1126 (goto-char current)
|
|
1127 nil
|
|
1128 ))
|
|
1129 )))
|
|
1130
|
|
1131 (defun mime-editor/content-beginning ()
|
|
1132 "Return the point of the beginning of content."
|
|
1133 (save-excursion
|
|
1134 (let ((beg (save-excursion
|
|
1135 (beginning-of-line) (point))))
|
|
1136 (if (mime-editor/goto-tag)
|
|
1137 (let ((top (point)))
|
|
1138 (goto-char (match-end 0))
|
|
1139 (if (and (= beg top)
|
|
1140 (= (following-char) ?\^M))
|
|
1141 (point)
|
|
1142 (forward-line 1)
|
|
1143 (point)))
|
|
1144 ;; Default text/plain tag.
|
|
1145 (goto-char (point-min))
|
|
1146 (re-search-forward
|
|
1147 (concat "\n" (regexp-quote mail-header-separator)
|
|
1148 (if mime-ignore-preceding-spaces
|
|
1149 "[ \t\n]*\n" "\n")) nil 'move)
|
|
1150 (point))
|
|
1151 )))
|
|
1152
|
|
1153 (defun mime-editor/content-end ()
|
|
1154 "Return the point of the end of content."
|
|
1155 (save-excursion
|
|
1156 (let ((beg (point)))
|
|
1157 (if (mime-editor/goto-tag)
|
|
1158 (let ((top (point)))
|
|
1159 (goto-char (match-end 0))
|
|
1160 (if (invisible-p (point))
|
|
1161 (next-visible-point (point))
|
|
1162 ;; Move to the end of this text.
|
|
1163 (if (re-search-forward mime-editor/tag-regexp nil 'move)
|
|
1164 ;; Don't forget a multiline tag.
|
|
1165 (goto-char (match-beginning 0))
|
|
1166 )
|
|
1167 (point)
|
|
1168 ))
|
|
1169 ;; Assume the message begins with text/plain.
|
|
1170 (goto-char (mime-editor/content-beginning))
|
|
1171 (if (re-search-forward mime-editor/tag-regexp nil 'move)
|
|
1172 ;; Don't forget a multiline tag.
|
|
1173 (goto-char (match-beginning 0)))
|
|
1174 (point))
|
|
1175 )))
|
|
1176
|
|
1177 (defun mime-editor/define-charset (charset)
|
|
1178 "Set charset of current tag to CHARSET."
|
|
1179 (save-excursion
|
|
1180 (if (mime-editor/goto-tag)
|
|
1181 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
|
|
1182 (delete-region (match-beginning 0) (match-end 0))
|
|
1183 (insert
|
|
1184 (mime-create-tag
|
|
1185 (mime-editor/set-parameter
|
|
1186 (mime-editor/get-contype tag)
|
|
1187 "charset" (upcase (symbol-name charset)))
|
|
1188 (mime-editor/get-encoding tag)))
|
|
1189 ))))
|
|
1190
|
|
1191 (defun mime-editor/define-encoding (encoding)
|
|
1192 "Set encoding of current tag to ENCODING."
|
|
1193 (save-excursion
|
|
1194 (if (mime-editor/goto-tag)
|
|
1195 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
|
|
1196 (delete-region (match-beginning 0) (match-end 0))
|
|
1197 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
|
|
1198 )))
|
|
1199
|
|
1200 (defun mime-editor/choose-charset ()
|
|
1201 "Choose charset of a text following current point."
|
|
1202 (detect-mime-charset-region (point) (mime-editor/content-end))
|
|
1203 )
|
|
1204
|
|
1205 (defun mime-make-text-tag (&optional subtype)
|
|
1206 "Make a tag for a text after current point.
|
|
1207 Subtype of text type can be specified by an optional argument SUBTYPE.
|
|
1208 Otherwise, it is obtained from mime-content-types."
|
|
1209 (let* ((pritype "text")
|
|
1210 (subtype (or subtype
|
|
1211 (car (car (cdr (assoc pritype mime-content-types)))))))
|
|
1212 ;; Charset should be defined later.
|
|
1213 (mime-make-tag pritype subtype)))
|
|
1214
|
|
1215
|
|
1216 ;; Tag handling functions
|
|
1217
|
|
1218 (defun mime-make-tag (pritype subtype &optional parameters encoding)
|
|
1219 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
|
|
1220 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
|
|
1221 (or parameters ""))
|
|
1222 encoding))
|
|
1223
|
|
1224 (defun mime-create-tag (contype &optional encoding)
|
|
1225 "Make a tag with CONTENT-TYPE and optional ENCODING."
|
|
1226 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
|
|
1227 contype encoding))
|
|
1228
|
|
1229 (defun mime-editor/get-contype (tag)
|
|
1230 "Return Content-Type (including parameters) of TAG."
|
|
1231 (and (stringp tag)
|
|
1232 (or (string-match mime-editor/single-part-tag-regexp tag)
|
|
1233 (string-match mime-editor/multipart-beginning-regexp tag)
|
|
1234 (string-match mime-editor/multipart-end-regexp tag)
|
|
1235 )
|
|
1236 (substring tag (match-beginning 1) (match-end 1))
|
|
1237 ))
|
|
1238
|
|
1239 (defun mime-editor/get-encoding (tag)
|
|
1240 "Return encoding of TAG."
|
|
1241 (and (stringp tag)
|
|
1242 (string-match mime-editor/single-part-tag-regexp tag)
|
|
1243 (match-beginning 3)
|
|
1244 (not (= (match-beginning 3) (match-end 3)))
|
|
1245 (substring tag (match-beginning 3) (match-end 3))))
|
|
1246
|
|
1247 (defun mime-get-parameter (contype parameter)
|
|
1248 "For given CONTYPE return value for PARAMETER.
|
|
1249 Nil if no such parameter."
|
|
1250 (if (string-match
|
|
1251 (concat
|
|
1252 ";[ \t\n]*"
|
|
1253 (regexp-quote parameter)
|
|
1254 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
|
|
1255 contype)
|
|
1256 (substring contype (match-beginning 1) (match-end 1))
|
|
1257 nil ;No such parameter
|
|
1258 ))
|
|
1259
|
|
1260 (defun mime-editor/set-parameter (contype parameter value)
|
|
1261 "For given CONTYPE set PARAMETER to VALUE."
|
|
1262 (let (ctype opt-fields)
|
|
1263 (if (string-match "\n[^ \t\n\r]+:" contype)
|
|
1264 (setq ctype (substring contype 0 (match-beginning 0))
|
|
1265 opt-fields (substring contype (match-beginning 0)))
|
|
1266 (setq ctype contype)
|
|
1267 )
|
|
1268 (if (string-match
|
|
1269 (concat
|
|
1270 ";[ \t\n]*\\("
|
|
1271 (regexp-quote parameter)
|
|
1272 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
|
|
1273 ctype)
|
|
1274 ;; Change value
|
|
1275 (concat (substring ctype 0 (match-beginning 1))
|
|
1276 parameter "=" value
|
|
1277 (substring contype (match-end 1))
|
|
1278 opt-fields)
|
|
1279 (concat ctype "; " parameter "=" value opt-fields)
|
|
1280 )))
|
|
1281
|
|
1282 (defun mime-strip-parameters (contype)
|
|
1283 "Return primary content-type and subtype without parameters for CONTYPE."
|
|
1284 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
|
|
1285 (substring contype (match-beginning 1) (match-end 1)) nil))
|
|
1286
|
|
1287 (defun mime-test-content-type (contype type &optional subtype)
|
|
1288 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
|
|
1289 (and (stringp contype)
|
|
1290 (stringp type)
|
|
1291 (string-match
|
|
1292 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
|
|
1293 (downcase contype))))
|
|
1294
|
|
1295
|
|
1296 ;; Basic functions
|
|
1297
|
|
1298 (defun mime-find-file-type (file)
|
|
1299 "Guess Content-Type, subtype, and parameters from FILE."
|
|
1300 (let ((guess nil)
|
|
1301 (guesses mime-file-types))
|
|
1302 (while (and (not guess) guesses)
|
|
1303 (if (string-match (car (car guesses)) file)
|
|
1304 (setq guess (cdr (car guesses))))
|
|
1305 (setq guesses (cdr guesses)))
|
|
1306 guess
|
|
1307 ))
|
|
1308
|
76
|
1309 (defun mime-prompt-for-type (&optional default)
|
4
|
1310 "Ask for Content-type."
|
|
1311 (let ((type ""))
|
|
1312 ;; Repeat until primary content type is specified.
|
|
1313 (while (string-equal type "")
|
|
1314 (setq type
|
|
1315 (completing-read "What content type: "
|
|
1316 mime-content-types
|
|
1317 nil
|
|
1318 'require-match ;Type must be specified.
|
76
|
1319 default
|
4
|
1320 ))
|
|
1321 (if (string-equal type "")
|
|
1322 (progn
|
|
1323 (message "Content type is required.")
|
|
1324 (beep)
|
|
1325 (sit-for 1)
|
|
1326 ))
|
|
1327 )
|
76
|
1328 type))
|
4
|
1329
|
76
|
1330 (defun mime-prompt-for-subtype (type &optional default)
|
|
1331 "Ask for subtype of media-type TYPE."
|
|
1332 (let ((subtypes (cdr (assoc type mime-content-types))))
|
|
1333 (or (and default
|
|
1334 (assoc default subtypes))
|
|
1335 (setq default (car (car subtypes)))
|
|
1336 ))
|
|
1337 (let* ((answer
|
4
|
1338 (completing-read
|
|
1339 (if default
|
|
1340 (concat
|
|
1341 "What content subtype: (default " default ") ")
|
|
1342 "What content subtype: ")
|
76
|
1343 (cdr (assoc type mime-content-types))
|
4
|
1344 nil
|
|
1345 'require-match ;Subtype must be specified.
|
|
1346 nil
|
|
1347 )))
|
|
1348 (if (string-equal answer "") default answer)))
|
|
1349
|
|
1350 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
|
|
1351 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
|
|
1352 Optional DELIMITER specifies parameter delimiter (';' by default)."
|
|
1353 (let* ((delimiter (or delimiter "; "))
|
|
1354 (parameters
|
|
1355 (mapconcat
|
|
1356 (function identity)
|
|
1357 (delq nil
|
|
1358 (mime-prompt-for-parameters-1
|
|
1359 (cdr (assoc subtype
|
|
1360 (cdr (assoc pritype mime-content-types))))))
|
|
1361 delimiter
|
|
1362 )))
|
|
1363 (if (and (stringp parameters)
|
|
1364 (not (string-equal parameters "")))
|
|
1365 (concat delimiter parameters)
|
|
1366 "" ;"" if no parameters
|
|
1367 )))
|
|
1368
|
|
1369 (defun mime-prompt-for-parameters-1 (optlist)
|
|
1370 (apply (function append)
|
|
1371 (mapcar (function mime-prompt-for-parameter) optlist)))
|
|
1372
|
|
1373 (defun mime-prompt-for-parameter (parameter)
|
|
1374 "Ask for PARAMETER.
|
|
1375 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
|
|
1376 (let* ((prompt (car parameter))
|
|
1377 (choices (mapcar (function
|
|
1378 (lambda (e)
|
|
1379 (if (consp e) e (list e))))
|
|
1380 (cdr parameter)))
|
|
1381 (default (car (car choices)))
|
|
1382 (answer nil))
|
|
1383 (if choices
|
|
1384 (progn
|
|
1385 (setq answer
|
|
1386 (completing-read
|
|
1387 (concat "What " prompt
|
|
1388 ": (default "
|
|
1389 (if (string-equal default "") "\"\"" default)
|
|
1390 ") ")
|
|
1391 choices nil nil ""))
|
|
1392 ;; If nothing is selected, use default.
|
|
1393 (if (string-equal answer "")
|
|
1394 (setq answer default)))
|
|
1395 (setq answer
|
|
1396 (read-string (concat "What " prompt ": "))))
|
|
1397 (cons (if (and answer
|
|
1398 (not (string-equal answer "")))
|
|
1399 (concat prompt "="
|
|
1400 ;; Note: control characters ignored!
|
|
1401 (if (string-match mime-tspecials-regexp answer)
|
|
1402 (concat "\"" answer "\"") answer)))
|
|
1403 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
|
|
1404 ))
|
|
1405
|
76
|
1406 (defun mime-prompt-for-encoding (default)
|
|
1407 "Ask for Content-Transfer-Encoding. [tm-edit.el]"
|
|
1408 (let (encoding)
|
|
1409 (while (string=
|
|
1410 (setq encoding
|
|
1411 (completing-read
|
|
1412 "What transfer encoding: "
|
|
1413 mime-file-encoding-method-alist nil t default)
|
|
1414 )
|
|
1415 ""))
|
|
1416 encoding))
|
4
|
1417
|
|
1418
|
|
1419 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
|
|
1420 ;;;
|
|
1421
|
|
1422 (defvar mime-editor/translate-buffer-hook
|
|
1423 '(mime-editor/pgp-enclose-buffer
|
|
1424 mime-editor/translate-header
|
|
1425 mime-editor/translate-body))
|
|
1426
|
|
1427 (defun mime-editor/translate-header ()
|
|
1428 "Encode the message header into network representation."
|
|
1429 (mime/encode-message-header 'code-conversion)
|
|
1430 (run-hooks 'mime-editor/translate-header-hook)
|
|
1431 )
|
|
1432
|
|
1433 (defun mime-editor/translate-buffer ()
|
|
1434 "Encode the tagged MIME message in current buffer in MIME compliant message."
|
|
1435 (interactive)
|
|
1436 (if (catch 'mime-editor/error
|
|
1437 (save-excursion
|
|
1438 (run-hooks 'mime-editor/translate-buffer-hook)
|
|
1439 ))
|
|
1440 (progn
|
|
1441 (undo)
|
|
1442 (error "Translation error!")
|
|
1443 )))
|
|
1444
|
|
1445 (defun mime-editor/find-inmost ()
|
|
1446 (goto-char (point-min))
|
|
1447 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
|
|
1448 (let ((bb (match-beginning 0))
|
|
1449 (be (match-end 0))
|
|
1450 (type (buffer-substring (match-beginning 1)(match-end 1)))
|
|
1451 end-exp eb ee)
|
|
1452 (setq end-exp (format "--}-<<%s>>\n" type))
|
|
1453 (widen)
|
|
1454 (if (re-search-forward end-exp nil t)
|
|
1455 (progn
|
|
1456 (setq eb (match-beginning 0))
|
|
1457 (setq ee (match-end 0))
|
|
1458 )
|
|
1459 (setq eb (point-max))
|
|
1460 (setq ee (point-max))
|
|
1461 )
|
|
1462 (narrow-to-region be eb)
|
|
1463 (goto-char be)
|
|
1464 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
|
|
1465 (let (ret)
|
|
1466 (narrow-to-region (match-beginning 0)(point-max))
|
|
1467 (mime-editor/find-inmost)
|
|
1468 )
|
|
1469 (widen)
|
|
1470 (list type bb be eb)
|
|
1471 ))))
|
|
1472
|
|
1473 (defun mime-editor/process-multipart-1 (boundary)
|
|
1474 (let ((ret (mime-editor/find-inmost)))
|
|
1475 (if ret
|
|
1476 (let ((type (car ret))
|
|
1477 (bb (nth 1 ret))(be (nth 2 ret))
|
|
1478 (eb (nth 3 ret))
|
|
1479 )
|
|
1480 (narrow-to-region bb eb)
|
|
1481 (delete-region bb be)
|
|
1482 (setq bb (point-min))
|
|
1483 (setq eb (point-max))
|
|
1484 (widen)
|
|
1485 (goto-char eb)
|
|
1486 (if (looking-at mime-editor/multipart-end-regexp)
|
|
1487 (let ((beg (match-beginning 0))
|
|
1488 (end (match-end 0))
|
|
1489 )
|
|
1490 (delete-region beg end)
|
|
1491 (or (looking-at mime-editor/beginning-tag-regexp)
|
|
1492 (eobp)
|
|
1493 (insert (concat (mime-make-text-tag) "\n"))
|
|
1494 )))
|
|
1495 (cond ((string-equal type "quote")
|
|
1496 (mime-editor/enquote-region bb eb)
|
|
1497 )
|
|
1498 ((string-equal type "signed")
|
|
1499 (cond ((eq mime-editor/signing-type 'pgp-elkins)
|
|
1500 (mime-editor/sign-pgp-elkins bb eb boundary)
|
|
1501 )
|
|
1502 ((eq mime-editor/signing-type 'pgp-kazu)
|
|
1503 (mime-editor/sign-pgp-kazu bb eb boundary)
|
|
1504 ))
|
|
1505 )
|
|
1506 ((string-equal type "encrypted")
|
|
1507 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
|
|
1508 (mime-editor/encrypt-pgp-elkins bb eb boundary)
|
|
1509 )
|
|
1510 ((eq mime-editor/encrypting-type 'pgp-kazu)
|
|
1511 (mime-editor/encrypt-pgp-kazu bb eb boundary)
|
|
1512 )))
|
|
1513 (t
|
|
1514 (setq boundary
|
|
1515 (nth 2 (mime-editor/translate-region bb eb
|
|
1516 boundary t)))
|
|
1517 (goto-char bb)
|
|
1518 (insert
|
|
1519 (format "--[[multipart/%s;
|
|
1520 boundary=\"%s\"][7bit]]\n"
|
|
1521 type boundary))
|
|
1522 ))
|
|
1523 boundary))))
|
|
1524
|
|
1525 (defun mime-editor/enquote-region (beg end)
|
|
1526 (save-excursion
|
|
1527 (save-restriction
|
|
1528 (narrow-to-region beg end)
|
|
1529 (goto-char beg)
|
|
1530 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
|
|
1531 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
|
|
1532 (replace-match (concat "- " (substring tag 1)))
|
|
1533 )))))
|
|
1534
|
|
1535 (defun mime-editor/dequote-region (beg end)
|
|
1536 (save-excursion
|
|
1537 (save-restriction
|
|
1538 (narrow-to-region beg end)
|
|
1539 (goto-char beg)
|
|
1540 (while (re-search-forward
|
|
1541 mime-editor/quoted-single-part-tag-regexp nil t)
|
|
1542 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
|
|
1543 (replace-match (concat "-" (substring tag 2)))
|
|
1544 )))))
|
|
1545
|
|
1546 (defun mime-editor/sign-pgp-elkins (beg end boundary)
|
|
1547 (save-excursion
|
|
1548 (save-restriction
|
|
1549 (narrow-to-region beg end)
|
|
1550 (let* ((ret
|
|
1551 (mime-editor/translate-region beg end boundary))
|
|
1552 (ctype (car ret))
|
|
1553 (encoding (nth 1 ret))
|
|
1554 (parts (nth 3 ret))
|
|
1555 (pgp-boundary (concat "pgp-sign-" boundary))
|
|
1556 )
|
|
1557 (goto-char beg)
|
|
1558 (insert (format "Content-Type: %s\n" ctype))
|
|
1559 (if encoding
|
|
1560 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
|
|
1561 )
|
|
1562 (insert "\n")
|
70
|
1563 (or (funcall mime-editor/pgp-sign-function
|
4
|
1564 (point-min)(point-max) nil nil pgp-boundary)
|
|
1565 (throw 'mime-editor/error 'pgp-error)
|
|
1566 )
|
|
1567 ))))
|
|
1568
|
|
1569 (defvar mime-editor/encrypt-recipient-fields-list '("To" "cc"))
|
|
1570
|
|
1571 (defun mime-editor/make-encrypt-recipient-header ()
|
|
1572 (let* ((names mime-editor/encrypt-recipient-fields-list)
|
|
1573 (values
|
|
1574 (std11-field-bodies (cons "From" names)
|
|
1575 nil mail-header-separator))
|
|
1576 (from (prog1
|
|
1577 (car values)
|
|
1578 (setq values (cdr values))))
|
|
1579 (header (and (stringp from)
|
|
1580 (if (string-equal from "")
|
|
1581 ""
|
|
1582 (format "From: %s\n" from)
|
|
1583 )))
|
|
1584 recipients)
|
|
1585 (while (and names values)
|
|
1586 (let ((name (car names))
|
|
1587 (value (car values))
|
|
1588 )
|
|
1589 (and (stringp value)
|
|
1590 (or (string-equal value "")
|
|
1591 (progn
|
|
1592 (setq header (concat header name ": " value "\n")
|
|
1593 recipients (if recipients
|
|
1594 (concat recipients " ," value)
|
|
1595 value))
|
|
1596 ))))
|
|
1597 (setq names (cdr names)
|
|
1598 values (cdr values))
|
|
1599 )
|
|
1600 (vector from recipients header)
|
|
1601 ))
|
|
1602
|
|
1603 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
|
|
1604 (save-excursion
|
|
1605 (save-restriction
|
|
1606 (let (from recipients header)
|
|
1607 (let ((ret (mime-editor/make-encrypt-recipient-header)))
|
|
1608 (setq from (aref ret 0)
|
|
1609 recipients (aref ret 1)
|
|
1610 header (aref ret 2))
|
|
1611 )
|
|
1612 (narrow-to-region beg end)
|
|
1613 (let* ((ret
|
|
1614 (mime-editor/translate-region beg end boundary))
|
|
1615 (ctype (car ret))
|
|
1616 (encoding (nth 1 ret))
|
|
1617 (parts (nth 3 ret))
|
|
1618 (pgp-boundary (concat "pgp-" boundary))
|
|
1619 )
|
|
1620 (goto-char beg)
|
|
1621 (insert header)
|
|
1622 (insert (format "Content-Type: %s\n" ctype))
|
|
1623 (if encoding
|
|
1624 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
|
|
1625 )
|
|
1626 (insert "\n")
|
70
|
1627 (or (funcall mime-editor/pgp-encrypt-function
|
4
|
1628 recipients (point-min) (point-max) from)
|
|
1629 (throw 'mime-editor/error 'pgp-error)
|
|
1630 )
|
|
1631 (goto-char beg)
|
|
1632 (insert (format "--[[multipart/encrypted;
|
|
1633 boundary=\"%s\";
|
|
1634 protocol=\"application/pgp-encrypted\"][7bit]]
|
|
1635 --%s
|
|
1636 Content-Type: application/pgp-encrypted
|
|
1637
|
|
1638 --%s
|
|
1639 Content-Type: application/octet-stream
|
|
1640 Content-Transfer-Encoding: 7bit
|
|
1641
|
|
1642 " pgp-boundary pgp-boundary pgp-boundary))
|
|
1643 (goto-char (point-max))
|
|
1644 (insert (format "\n--%s--\n" pgp-boundary))
|
|
1645 )))))
|
|
1646
|
|
1647 (defun mime-editor/sign-pgp-kazu (beg end boundary)
|
|
1648 (save-excursion
|
|
1649 (save-restriction
|
|
1650 (narrow-to-region beg end)
|
|
1651 (let* ((ret
|
|
1652 (mime-editor/translate-region beg end boundary))
|
|
1653 (ctype (car ret))
|
|
1654 (encoding (nth 1 ret))
|
|
1655 (parts (nth 3 ret))
|
|
1656 )
|
|
1657 (goto-char beg)
|
|
1658 (insert (format "Content-Type: %s\n" ctype))
|
|
1659 (if encoding
|
|
1660 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
|
|
1661 )
|
|
1662 (insert "\n")
|
|
1663 (or (as-binary-process
|
70
|
1664 (funcall mime-editor/traditional-pgp-sign-function
|
4
|
1665 beg (point-max)))
|
|
1666 (throw 'mime-editor/error 'pgp-error)
|
|
1667 )
|
|
1668 (goto-char beg)
|
|
1669 (insert
|
|
1670 "--[[application/pgp; format=mime][7bit]]\n")
|
|
1671 ))
|
|
1672 ))
|
|
1673
|
|
1674 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
|
|
1675 (save-excursion
|
|
1676 (let (from recipients header)
|
|
1677 (let ((ret (mime-editor/make-encrypt-recipient-header)))
|
|
1678 (setq from (aref ret 0)
|
|
1679 recipients (aref ret 1)
|
|
1680 header (aref ret 2))
|
|
1681 )
|
|
1682 (save-restriction
|
|
1683 (narrow-to-region beg end)
|
|
1684 (let* ((ret
|
|
1685 (mime-editor/translate-region beg end boundary))
|
|
1686 (ctype (car ret))
|
|
1687 (encoding (nth 1 ret))
|
|
1688 (parts (nth 3 ret))
|
|
1689 )
|
|
1690 (goto-char beg)
|
|
1691 (insert header)
|
|
1692 (insert (format "Content-Type: %s\n" ctype))
|
|
1693 (if encoding
|
|
1694 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
|
|
1695 )
|
|
1696 (insert "\n")
|
|
1697 (or (as-binary-process
|
70
|
1698 (funcall mime-editor/pgp-encrypt-function
|
4
|
1699 recipients beg (point-max) nil 'maybe)
|
|
1700 )
|
|
1701 (throw 'mime-editor/error 'pgp-error)
|
|
1702 )
|
|
1703 (goto-char beg)
|
|
1704 (insert
|
|
1705 "--[[application/pgp; format=mime][7bit]]\n")
|
|
1706 ))
|
|
1707 )))
|
|
1708
|
|
1709 (defun mime-editor/translate-body ()
|
|
1710 "Encode the tagged MIME body in current buffer in MIME compliant message."
|
|
1711 (interactive)
|
|
1712 (save-excursion
|
|
1713 (let ((boundary
|
|
1714 (concat mime-multipart-boundary "_"
|
|
1715 (replace-space-with-underline (current-time-string))
|
|
1716 ))
|
|
1717 (i 1)
|
|
1718 ret)
|
|
1719 (while (mime-editor/process-multipart-1
|
|
1720 (format "%s-%d" boundary i))
|
|
1721 (setq i (1+ i))
|
|
1722 )
|
|
1723 (save-restriction
|
|
1724 ;; We are interested in message body.
|
|
1725 (let* ((beg
|
|
1726 (progn
|
|
1727 (goto-char (point-min))
|
|
1728 (re-search-forward
|
|
1729 (concat "\n" (regexp-quote mail-header-separator)
|
|
1730 (if mime-ignore-preceding-spaces
|
|
1731 "[ \t\n]*\n" "\n")) nil 'move)
|
|
1732 (point)))
|
|
1733 (end
|
|
1734 (progn
|
|
1735 (goto-char (point-max))
|
|
1736 (and mime-ignore-trailing-spaces
|
|
1737 (re-search-backward "[^ \t\n]\n" beg t)
|
|
1738 (forward-char 1))
|
|
1739 (point))))
|
|
1740 (setq ret (mime-editor/translate-region
|
|
1741 beg end
|
|
1742 (format "%s-%d" boundary i)))
|
|
1743 ))
|
|
1744 (mime-editor/dequote-region (point-min)(point-max))
|
|
1745 (let ((contype (car ret)) ;Content-Type
|
|
1746 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
|
|
1747 )
|
|
1748 ;; Make primary MIME headers.
|
|
1749 (or (mail-position-on-field "Mime-Version")
|
|
1750 (insert mime-editor/mime-version-value))
|
|
1751 ;; Remove old Content-Type and other fields.
|
|
1752 (save-restriction
|
|
1753 (goto-char (point-min))
|
|
1754 (search-forward (concat "\n" mail-header-separator "\n") nil t)
|
|
1755 (narrow-to-region (point-min) (point))
|
|
1756 (goto-char (point-min))
|
|
1757 (mime-delete-field "Content-Type")
|
|
1758 (mime-delete-field "Content-Transfer-Encoding"))
|
|
1759 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
|
|
1760 (mail-position-on-field "Content-Type")
|
|
1761 (insert contype)
|
|
1762 (if encoding
|
|
1763 (progn
|
|
1764 (mail-position-on-field "Content-Transfer-Encoding")
|
|
1765 (insert encoding)))
|
|
1766 ))))
|
|
1767
|
|
1768 (defun mime-editor/translate-single-part-tag (&optional prefix)
|
|
1769 (if (re-search-forward mime-editor/single-part-tag-regexp nil t)
|
|
1770 (let* ((beg (match-beginning 0))
|
|
1771 (end (match-end 0))
|
|
1772 (tag (buffer-substring beg end))
|
|
1773 )
|
|
1774 (delete-region beg end)
|
70
|
1775 (setq contype (mime-editor/get-contype tag))
|
|
1776 (setq encoding (mime-editor/get-encoding tag))
|
|
1777 (insert (concat prefix "--" boundary "\n"))
|
|
1778 (save-restriction
|
|
1779 (narrow-to-region (point)(point))
|
|
1780 (insert "Content-Type: " contype "\n")
|
|
1781 (if encoding
|
|
1782 (insert "Content-Transfer-Encoding: " encoding "\n"))
|
|
1783 (mime/encode-message-header)
|
|
1784 )
|
4
|
1785 t)))
|
|
1786
|
|
1787 (defun mime-editor/translate-region (beg end &optional boundary multipart)
|
|
1788 (if (null boundary)
|
|
1789 (setq boundary
|
|
1790 (concat mime-multipart-boundary "_"
|
|
1791 (replace-space-with-underline (current-time-string))))
|
|
1792 )
|
|
1793 (save-excursion
|
|
1794 (save-restriction
|
|
1795 (narrow-to-region beg end)
|
|
1796 (let ((tag nil) ;MIME tag
|
|
1797 (contype nil) ;Content-Type
|
|
1798 (encoding nil) ;Content-Transfer-Encoding
|
|
1799 (nparts 0)) ;Number of body parts
|
|
1800 ;; Normalize the body part by inserting appropriate message
|
|
1801 ;; tags for every message contents.
|
|
1802 (mime-editor/normalize-body)
|
|
1803 ;; Counting the number of Content-Type.
|
|
1804 (goto-char (point-min))
|
|
1805 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
|
|
1806 (setq nparts (1+ nparts)))
|
|
1807 ;; Begin translation.
|
|
1808 (cond
|
|
1809 ((and (<= nparts 1)(not multipart))
|
|
1810 ;; It's a singular message.
|
|
1811 (goto-char (point-min))
|
|
1812 (while (re-search-forward
|
|
1813 mime-editor/single-part-tag-regexp nil t)
|
|
1814 (setq tag
|
|
1815 (buffer-substring (match-beginning 0) (match-end 0)))
|
|
1816 (delete-region (match-beginning 0) (1+ (match-end 0)))
|
|
1817 (setq contype (mime-editor/get-contype tag))
|
|
1818 (setq encoding (mime-editor/get-encoding tag))
|
|
1819 ))
|
|
1820 (t
|
|
1821 ;; It's a multipart message.
|
|
1822 (goto-char (point-min))
|
|
1823 (and (mime-editor/translate-single-part-tag)
|
|
1824 (while (mime-editor/translate-single-part-tag "\n"))
|
|
1825 )
|
|
1826 ;; Define Content-Type as "multipart/mixed".
|
|
1827 (setq contype
|
|
1828 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
|
|
1829 ;; Content-Transfer-Encoding must be "7bit".
|
|
1830 ;; The following encoding can be `nil', but is
|
|
1831 ;; specified as is since there is no way that a user
|
|
1832 ;; specifies it.
|
|
1833 (setq encoding "7bit")
|
|
1834 ;; Insert the trailer.
|
|
1835 (goto-char (point-max))
|
|
1836 (insert "\n--" boundary "--\n")
|
|
1837 ))
|
|
1838 (list contype encoding boundary nparts)
|
|
1839 ))))
|
|
1840
|
|
1841 (defun mime-editor/normalize-body ()
|
|
1842 "Normalize the body part by inserting appropriate message tags."
|
|
1843 ;; Insert the first MIME tags if necessary.
|
|
1844 (goto-char (point-min))
|
|
1845 (if (not (looking-at mime-editor/single-part-tag-regexp))
|
|
1846 (insert (mime-make-text-tag) "\n"))
|
|
1847 ;; Check each tag, and add new tag or correct it if necessary.
|
|
1848 (goto-char (point-min))
|
|
1849 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
|
|
1850 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
|
|
1851 (contype (mime-editor/get-contype tag))
|
|
1852 (charset (mime-get-parameter contype "charset"))
|
|
1853 (encoding (mime-editor/get-encoding tag)))
|
|
1854 ;; Remove extra whitespaces after the tag.
|
|
1855 (if (looking-at "[ \t]+$")
|
|
1856 (delete-region (match-beginning 0) (match-end 0)))
|
|
1857 (let ((beg (point))
|
|
1858 (end (mime-editor/content-end))
|
|
1859 )
|
|
1860 (if (= end (point-max))
|
|
1861 nil
|
|
1862 (goto-char end)
|
|
1863 (or (looking-at mime-editor/beginning-tag-regexp)
|
|
1864 (eobp)
|
|
1865 (insert (mime-make-text-tag) "\n")
|
|
1866 ))
|
|
1867 (visible-region beg end)
|
|
1868 (goto-char beg)
|
|
1869 )
|
|
1870 (cond
|
|
1871 ((mime-test-content-type contype "message")
|
|
1872 ;; Content-type "message" should be sent as is.
|
|
1873 (forward-line 1)
|
|
1874 )
|
|
1875 ((mime-test-content-type contype "text")
|
|
1876 ;; Define charset for text if necessary.
|
|
1877 (setq charset (if charset
|
|
1878 (intern (downcase charset))
|
|
1879 (mime-editor/choose-charset)))
|
|
1880 (mime-editor/define-charset charset)
|
|
1881 (cond ((string-equal contype "text/x-rot13-47")
|
|
1882 (save-excursion
|
|
1883 (forward-line)
|
|
1884 (set-mark (point))
|
|
1885 (goto-char (mime-editor/content-end))
|
|
1886 (tm:caesar-region)
|
|
1887 ))
|
|
1888 ((string-equal contype "text/enriched")
|
|
1889 (save-excursion
|
|
1890 (let ((beg (progn
|
|
1891 (forward-line)
|
|
1892 (point)))
|
|
1893 (end (mime-editor/content-end))
|
|
1894 )
|
|
1895 ;; Patch for hard newlines
|
|
1896 ;; (save-excursion
|
|
1897 ;; (goto-char beg)
|
|
1898 ;; (while (search-forward "\n" end t)
|
|
1899 ;; (put-text-property (match-beginning 0)
|
|
1900 ;; (point)
|
|
1901 ;; 'hard t)))
|
|
1902 ;; End patch for hard newlines
|
|
1903 (enriched-encode beg end)
|
|
1904 (goto-char beg)
|
|
1905 (if (search-forward "\n\n")
|
|
1906 (delete-region beg (match-end 0))
|
|
1907 )
|
|
1908 ))))
|
|
1909 ;; Point is now on current tag.
|
|
1910 ;; Define encoding and encode text if necessary.
|
|
1911 (or encoding ;Encoding is not specified.
|
|
1912 (let* ((encoding
|
|
1913 (cdr
|
|
1914 (assq charset
|
|
1915 mime-editor/charset-default-encoding-alist)
|
|
1916 ))
|
|
1917 (beg (mime-editor/content-beginning))
|
|
1918 )
|
|
1919 (encode-mime-charset-region beg (mime-editor/content-end)
|
|
1920 charset)
|
|
1921 (mime-encode-region beg (mime-editor/content-end) encoding)
|
|
1922 (mime-editor/define-encoding encoding)
|
|
1923 ))
|
|
1924 (goto-char (mime-editor/content-end))
|
|
1925 )
|
|
1926 ((null encoding) ;Encoding is not specified.
|
|
1927 ;; Application, image, audio, video, and any other
|
|
1928 ;; unknown content-type without encoding should be
|
|
1929 ;; encoded.
|
|
1930 (let* ((encoding "base64") ;Encode in BASE64 by default.
|
|
1931 (beg (mime-editor/content-beginning))
|
|
1932 (end (mime-editor/content-end))
|
|
1933 (body (buffer-substring beg end))
|
|
1934 )
|
|
1935 (mime-encode-region beg end encoding)
|
|
1936 (mime-editor/define-encoding encoding))
|
|
1937 (forward-line 1)
|
|
1938 ))
|
|
1939 )))
|
|
1940
|
|
1941 (defun mime-delete-field (field)
|
|
1942 "Delete header FIELD."
|
|
1943 (let ((regexp (format "^%s:[ \t]*" field)))
|
|
1944 (goto-char (point-min))
|
|
1945 (while (re-search-forward regexp nil t)
|
|
1946 (delete-region (match-beginning 0)
|
|
1947 (progn (forward-line 1) (point)))
|
|
1948 )))
|
|
1949
|
|
1950
|
|
1951 ;;;
|
|
1952 ;;; Platform dependent functions
|
|
1953 ;;;
|
|
1954
|
|
1955 ;; Sun implementations
|
|
1956
|
|
1957 (defun mime-editor/voice-recorder-for-sun (encoding)
|
|
1958 "Record voice in a buffer using Sun audio device,
|
|
1959 and insert data encoded as ENCODING. [tm-edit.el]"
|
|
1960 (message "Start the recording on %s. Type C-g to finish the recording..."
|
|
1961 (system-name))
|
|
1962 (mime-insert-encoded-file "/dev/audio" encoding)
|
|
1963 )
|
|
1964
|
|
1965
|
|
1966 ;;; @ Other useful commands.
|
|
1967 ;;;
|
|
1968
|
|
1969 ;; Message forwarding commands as content-type "message/rfc822".
|
|
1970
|
|
1971 (defun mime-editor/insert-message (&optional message)
|
|
1972 (interactive)
|
|
1973 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
|
|
1974 (if (and inserter (fboundp inserter))
|
|
1975 (progn
|
|
1976 (mime-editor/insert-tag "message" "rfc822")
|
|
1977 (funcall inserter message)
|
|
1978 )
|
|
1979 (message "Sorry, I don't have message inserter for your MUA.")
|
|
1980 )))
|
|
1981
|
|
1982 (defun mime-editor/insert-mail (&optional message)
|
|
1983 (interactive)
|
|
1984 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
|
|
1985 (if (and inserter (fboundp inserter))
|
|
1986 (progn
|
|
1987 (mime-editor/insert-tag "message" "rfc822")
|
|
1988 (funcall inserter message)
|
|
1989 )
|
|
1990 (message "Sorry, I don't have mail inserter for your MUA.")
|
|
1991 )))
|
|
1992
|
|
1993 (defun mime-editor/inserted-message-filter ()
|
|
1994 (save-excursion
|
|
1995 (save-restriction
|
|
1996 (let ((header-start (point))
|
|
1997 (case-fold-search t)
|
|
1998 beg end)
|
|
1999 ;; for Emacs 18
|
|
2000 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
|
|
2001 (if (re-search-forward "^$" (mark t))
|
|
2002 (narrow-to-region header-start (match-beginning 0))
|
|
2003 )
|
|
2004 (goto-char header-start)
|
|
2005 (while (and (re-search-forward
|
|
2006 mime-editor/yank-ignored-field-regexp nil t)
|
|
2007 (setq beg (match-beginning 0))
|
|
2008 (setq end (1+ (std11-field-end)))
|
|
2009 )
|
|
2010 (delete-region beg end)
|
|
2011 )
|
|
2012 ))))
|
|
2013
|
|
2014
|
|
2015 ;;; @ multipart enclosure
|
|
2016 ;;;
|
|
2017
|
|
2018 (defun mime-editor/enclose-region (type beg end)
|
|
2019 (save-excursion
|
|
2020 (goto-char beg)
|
|
2021 (let ((current (point)))
|
|
2022 (save-restriction
|
|
2023 (narrow-to-region beg end)
|
|
2024 (insert (format "--<<%s>>-{\n" type))
|
|
2025 (goto-char (point-max))
|
|
2026 (insert (format "--}-<<%s>>\n" type))
|
|
2027 (goto-char (point-max))
|
|
2028 )
|
|
2029 (or (looking-at mime-editor/beginning-tag-regexp)
|
|
2030 (eobp)
|
|
2031 (insert (mime-make-text-tag) "\n")
|
|
2032 )
|
|
2033 )))
|
|
2034
|
|
2035 (defun mime-editor/enclose-quote-region (beg end)
|
|
2036 (interactive "*r")
|
|
2037 (mime-editor/enclose-region "quote" beg end)
|
|
2038 )
|
|
2039
|
|
2040 (defun mime-editor/enclose-mixed-region (beg end)
|
|
2041 (interactive "*r")
|
|
2042 (mime-editor/enclose-region "mixed" beg end)
|
|
2043 )
|
|
2044
|
|
2045 (defun mime-editor/enclose-parallel-region (beg end)
|
|
2046 (interactive "*r")
|
|
2047 (mime-editor/enclose-region "parallel" beg end)
|
|
2048 )
|
|
2049
|
|
2050 (defun mime-editor/enclose-digest-region (beg end)
|
|
2051 (interactive "*r")
|
|
2052 (mime-editor/enclose-region "digest" beg end)
|
|
2053 )
|
|
2054
|
|
2055 (defun mime-editor/enclose-alternative-region (beg end)
|
|
2056 (interactive "*r")
|
|
2057 (mime-editor/enclose-region "alternative" beg end)
|
|
2058 )
|
|
2059
|
|
2060 (defun mime-editor/enclose-signed-region (beg end)
|
|
2061 (interactive "*r")
|
|
2062 (if mime-editor/signing-type
|
|
2063 (mime-editor/enclose-region "signed" beg end)
|
|
2064 (message "Please specify signing type.")
|
|
2065 ))
|
|
2066
|
|
2067 (defun mime-editor/enclose-encrypted-region (beg end)
|
|
2068 (interactive "*r")
|
|
2069 (if mime-editor/signing-type
|
|
2070 (mime-editor/enclose-region "encrypted" beg end)
|
|
2071 (message "Please specify encrypting type.")
|
|
2072 ))
|
|
2073
|
|
2074 (defun mime-editor/insert-key (&optional arg)
|
|
2075 "Insert a pgp public key."
|
|
2076 (interactive "P")
|
|
2077 (mime-editor/insert-tag "application" "pgp-keys")
|
|
2078 (mime-editor/define-encoding "7bit")
|
70
|
2079 (funcall mime-editor/pgp-insert-public-key-function)
|
4
|
2080 )
|
|
2081
|
|
2082
|
|
2083 ;;; @ flag setting
|
|
2084 ;;;
|
|
2085
|
|
2086 (defun mime-editor/set-split (arg)
|
|
2087 (interactive
|
|
2088 (list
|
|
2089 (y-or-n-p "Do you want to enable split?")
|
|
2090 ))
|
|
2091 (setq mime-editor/split-message arg)
|
|
2092 (if arg
|
|
2093 (message "This message is enabled to split.")
|
|
2094 (message "This message is not enabled to split.")
|
|
2095 ))
|
|
2096
|
|
2097 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
|
|
2098 "Toggle transfer-level is 7bit or 8bit through.
|
|
2099
|
|
2100 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
|
|
2101 (interactive)
|
|
2102 (if (numberp transfer-level)
|
|
2103 (setq mime-editor/transfer-level transfer-level)
|
|
2104 (if (< mime-editor/transfer-level 8)
|
|
2105 (setq mime-editor/transfer-level 8)
|
|
2106 (setq mime-editor/transfer-level 7)
|
|
2107 ))
|
|
2108 (setq mime-editor/charset-default-encoding-alist
|
|
2109 (mime-editor/make-charset-default-encoding-alist
|
|
2110 mime-editor/transfer-level))
|
|
2111 (message (format "Current transfer-level is %d bit"
|
|
2112 mime-editor/transfer-level))
|
|
2113 (setq mime-editor/transfer-level-string
|
|
2114 (mime/encoding-name mime-editor/transfer-level 'not-omit))
|
|
2115 (force-mode-line-update)
|
|
2116 )
|
|
2117
|
|
2118 (defun mime-editor/set-transfer-level-7bit ()
|
|
2119 (interactive)
|
|
2120 (mime-editor/toggle-transfer-level 7)
|
|
2121 )
|
|
2122
|
|
2123 (defun mime-editor/set-transfer-level-8bit ()
|
|
2124 (interactive)
|
|
2125 (mime-editor/toggle-transfer-level 8)
|
|
2126 )
|
|
2127
|
|
2128
|
|
2129 ;;; @ pgp
|
|
2130 ;;;
|
|
2131
|
|
2132 (defun mime-editor/set-sign (arg)
|
|
2133 (interactive
|
|
2134 (list
|
|
2135 (y-or-n-p "Do you want to sign?")
|
|
2136 ))
|
|
2137 (if arg
|
|
2138 (if mime-editor/signing-type
|
|
2139 (progn
|
|
2140 (setq mime-editor/pgp-processing 'sign)
|
|
2141 (message "This message will be signed.")
|
|
2142 )
|
|
2143 (message "Please specify signing type.")
|
|
2144 )
|
|
2145 (if (eq mime-editor/pgp-processing 'sign)
|
|
2146 (setq mime-editor/pgp-processing nil)
|
|
2147 )
|
|
2148 (message "This message will not be signed.")
|
|
2149 ))
|
|
2150
|
|
2151 (defun mime-editor/set-encrypt (arg)
|
|
2152 (interactive
|
|
2153 (list
|
|
2154 (y-or-n-p "Do you want to encrypt?")
|
|
2155 ))
|
|
2156 (if arg
|
|
2157 (if mime-editor/encrypting-type
|
|
2158 (progn
|
|
2159 (setq mime-editor/pgp-processing 'encrypt)
|
|
2160 (message "This message will be encrypt.")
|
|
2161 )
|
|
2162 (message "Please specify encrypting type.")
|
|
2163 )
|
|
2164 (if (eq mime-editor/pgp-processing 'encrypt)
|
|
2165 (setq mime-editor/pgp-processing nil)
|
|
2166 )
|
|
2167 (message "This message will not be encrypt.")
|
|
2168 ))
|
|
2169
|
|
2170 (defvar mime-editor/pgp-processing nil)
|
|
2171 (make-variable-buffer-local 'mime-editor/pgp-processing)
|
|
2172
|
|
2173 (defun mime-editor/pgp-enclose-buffer ()
|
|
2174 (let ((beg (save-excursion
|
|
2175 (goto-char (point-min))
|
|
2176 (if (search-forward (concat "\n" mail-header-separator "\n"))
|
|
2177 (match-end 0)
|
|
2178 )))
|
|
2179 (end (point-max))
|
|
2180 )
|
|
2181 (if beg
|
|
2182 (cond ((eq mime-editor/pgp-processing 'sign)
|
|
2183 (mime-editor/enclose-signed-region beg end)
|
|
2184 )
|
|
2185 ((eq mime-editor/pgp-processing 'encrypt)
|
|
2186 (mime-editor/enclose-encrypted-region beg end)
|
|
2187 ))
|
|
2188 )))
|
|
2189
|
|
2190
|
|
2191 ;;; @ split
|
|
2192 ;;;
|
|
2193
|
|
2194 (defun mime-editor/insert-partial-header
|
|
2195 (fields subject id number total separator)
|
|
2196 (insert fields)
|
|
2197 (insert (format "Subject: %s (%d/%d)\n" subject number total))
|
|
2198 (insert (format "Mime-Version: 1.0 (split by %s)\n"
|
|
2199 mime-editor/version-name))
|
|
2200 (insert (format "\
|
|
2201 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
|
|
2202 id number total separator))
|
|
2203 )
|
|
2204
|
|
2205 (defun mime-editor/split-and-send
|
|
2206 (&optional cmd lines mime-editor/message-max-length)
|
|
2207 (interactive)
|
|
2208 (or lines
|
|
2209 (setq lines
|
|
2210 (count-lines (point-min) (point-max)))
|
|
2211 )
|
|
2212 (or mime-editor/message-max-length
|
|
2213 (setq mime-editor/message-max-length
|
|
2214 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
|
|
2215 mime-editor/message-default-max-lines))
|
|
2216 )
|
|
2217 (let* ((mime-editor/draft-file-name
|
|
2218 (or (buffer-file-name)
|
|
2219 (make-temp-name
|
|
2220 (expand-file-name "tm-draft" mime/tmp-dir))))
|
|
2221 (separator mail-header-separator)
|
|
2222 (id (concat "\""
|
|
2223 (replace-space-with-underline (current-time-string))
|
|
2224 "@" (system-name) "\"")))
|
|
2225 (run-hooks 'mime-editor/before-split-hook)
|
|
2226 (let ((the-buf (current-buffer))
|
|
2227 (copy-buf (get-buffer-create " *Original Message*"))
|
|
2228 (header (std11-header-string-except
|
|
2229 mime-editor/split-ignored-field-regexp separator))
|
|
2230 (subject (mail-fetch-field "subject"))
|
|
2231 (total (+ (/ lines mime-editor/message-max-length)
|
|
2232 (if (> (mod lines mime-editor/message-max-length) 0)
|
|
2233 1)))
|
|
2234 (command
|
|
2235 (or cmd
|
|
2236 (cdr
|
|
2237 (assq major-mode
|
|
2238 mime-editor/split-message-sender-alist))
|
|
2239 (function
|
|
2240 (lambda ()
|
|
2241 (interactive)
|
|
2242 (error "Split sender is not specified for `%s'." major-mode)
|
|
2243 ))
|
|
2244 ))
|
|
2245 (mime-editor/partial-number 1)
|
|
2246 data)
|
|
2247 (save-excursion
|
|
2248 (set-buffer copy-buf)
|
|
2249 (erase-buffer)
|
|
2250 (insert-buffer the-buf)
|
|
2251 (save-restriction
|
|
2252 (if (re-search-forward
|
|
2253 (concat "^" (regexp-quote separator) "$") nil t)
|
|
2254 (let ((he (match-beginning 0)))
|
|
2255 (replace-match "")
|
|
2256 (narrow-to-region (point-min) he)
|
|
2257 ))
|
|
2258 (goto-char (point-min))
|
|
2259 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
|
|
2260 (delete-region (match-beginning 0)
|
|
2261 (1+ (std11-field-end)))
|
|
2262 )))
|
|
2263 (while (< mime-editor/partial-number total)
|
|
2264 (erase-buffer)
|
|
2265 (save-excursion
|
|
2266 (set-buffer copy-buf)
|
|
2267 (setq data (buffer-substring
|
|
2268 (point-min)
|
|
2269 (progn
|
|
2270 (goto-line mime-editor/message-max-length)
|
|
2271 (point))
|
|
2272 ))
|
|
2273 (delete-region (point-min)(point))
|
|
2274 )
|
|
2275 (mime-editor/insert-partial-header
|
|
2276 header subject id mime-editor/partial-number total separator)
|
|
2277 (insert data)
|
|
2278 (save-excursion
|
|
2279 (message (format "Sending %d/%d..."
|
|
2280 mime-editor/partial-number total))
|
|
2281 (call-interactively command)
|
|
2282 (message (format "Sending %d/%d... done"
|
|
2283 mime-editor/partial-number total))
|
|
2284 )
|
|
2285 (setq mime-editor/partial-number
|
|
2286 (1+ mime-editor/partial-number))
|
|
2287 )
|
|
2288 (erase-buffer)
|
|
2289 (save-excursion
|
|
2290 (set-buffer copy-buf)
|
|
2291 (setq data (buffer-string))
|
|
2292 (erase-buffer)
|
|
2293 )
|
|
2294 (mime-editor/insert-partial-header
|
|
2295 header subject id mime-editor/partial-number total separator)
|
|
2296 (insert data)
|
|
2297 (save-excursion
|
|
2298 (message (format "Sending %d/%d..."
|
|
2299 mime-editor/partial-number total))
|
|
2300 (message (format "Sending %d/%d... done"
|
|
2301 mime-editor/partial-number total))
|
|
2302 )
|
|
2303 )))
|
|
2304
|
|
2305 (defun mime-editor/maybe-split-and-send (&optional cmd)
|
|
2306 (interactive)
|
|
2307 (run-hooks 'mime-editor/before-send-hook)
|
|
2308 (let ((mime-editor/message-max-length
|
|
2309 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
|
|
2310 mime-editor/message-default-max-lines))
|
|
2311 (lines (count-lines (point-min) (point-max)))
|
|
2312 )
|
|
2313 (if (and (> lines mime-editor/message-max-length)
|
|
2314 mime-editor/split-message)
|
|
2315 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
|
|
2316 )))
|
|
2317
|
|
2318
|
|
2319 ;;; @ preview message
|
|
2320 ;;;
|
|
2321
|
|
2322 (defun mime-editor/preview-message ()
|
|
2323 "preview editing MIME message. [tm-edit.el]"
|
|
2324 (interactive)
|
|
2325 (let* ((str (buffer-string))
|
|
2326 (separator mail-header-separator)
|
|
2327 (the-buf (current-buffer))
|
|
2328 (buf-name (buffer-name))
|
|
2329 (temp-buf-name (concat "*temp-article:" buf-name "*"))
|
|
2330 (buf (get-buffer temp-buf-name))
|
|
2331 )
|
|
2332 (if buf
|
|
2333 (progn
|
|
2334 (switch-to-buffer buf)
|
|
2335 (erase-buffer)
|
|
2336 )
|
|
2337 (setq buf (get-buffer-create temp-buf-name))
|
|
2338 (switch-to-buffer buf)
|
|
2339 )
|
|
2340 (insert str)
|
|
2341 (setq major-mode 'mime/temporary-message-mode)
|
|
2342 (make-local-variable 'mail-header-separator)
|
|
2343 (setq mail-header-separator separator)
|
|
2344 (make-local-variable 'mime/editing-buffer)
|
|
2345 (setq mime/editing-buffer the-buf)
|
|
2346
|
|
2347 (run-hooks 'mime-editor/translate-hook)
|
|
2348 (mime-editor/translate-buffer)
|
|
2349 (goto-char (point-min))
|
|
2350 (if (re-search-forward
|
|
2351 (concat "^" (regexp-quote separator) "$"))
|
|
2352 (replace-match "")
|
|
2353 )
|
|
2354 (mime/viewer-mode)
|
|
2355 ))
|
|
2356
|
|
2357 (defun mime-editor/quitting-method ()
|
|
2358 (let ((temp mime::preview/article-buffer)
|
|
2359 buf)
|
|
2360 (mime-viewer/kill-buffer)
|
|
2361 (set-buffer temp)
|
|
2362 (setq buf mime/editing-buffer)
|
|
2363 (kill-buffer temp)
|
|
2364 (switch-to-buffer buf)
|
|
2365 ))
|
|
2366
|
|
2367 (set-alist 'mime-viewer/quitting-method-alist
|
|
2368 'mime/temporary-message-mode
|
|
2369 (function mime-editor/quitting-method)
|
|
2370 )
|
|
2371
|
|
2372
|
|
2373 ;;; @ draft preview
|
|
2374 ;;;
|
|
2375 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
|
|
2376 ;; Mon, 10 Apr 1995 20:03:07 +0900
|
|
2377
|
|
2378 (defvar mime-editor/draft-header-separator-alist
|
|
2379 '((news-reply-mode . mail-header-separator)
|
|
2380 (mh-letter-mode . mail-header-separator)
|
|
2381 ))
|
|
2382
|
|
2383 (defvar mime::article/draft-header-separator nil)
|
|
2384
|
|
2385 (defun mime-editor/draft-preview ()
|
|
2386 (interactive)
|
|
2387 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
|
|
2388 (or (stringp sep) (setq sep (eval sep)))
|
|
2389 (make-variable-buffer-local 'mime::article/draft-header-separator)
|
|
2390 (goto-char (point-min))
|
|
2391 (re-search-forward
|
|
2392 (concat "^\\(" (regexp-quote sep) "\\)?$"))
|
|
2393 (setq mime::article/draft-header-separator
|
|
2394 (buffer-substring (match-beginning 0) (match-end 0)))
|
|
2395 (replace-match "")
|
|
2396 (mime/viewer-mode (current-buffer))
|
|
2397 (pop-to-buffer (current-buffer))
|
|
2398 ))
|
|
2399
|
|
2400 (defun mime-viewer::quitting-method/draft-preview ()
|
|
2401 (let ((mother mime::preview/mother-buffer))
|
|
2402 (save-excursion
|
|
2403 (switch-to-buffer mother)
|
|
2404 (goto-char (point-min))
|
|
2405 (if (and
|
|
2406 (re-search-forward
|
|
2407 (concat "^\\("
|
|
2408 (regexp-quote mime::article/draft-header-separator)
|
|
2409 "\\)?$") nil t)
|
|
2410 (bolp))
|
|
2411 (progn
|
|
2412 (insert mime::article/draft-header-separator)
|
|
2413 (set-buffer-modified-p (buffer-modified-p))
|
|
2414 )))
|
|
2415 (mime-viewer/kill-buffer)
|
|
2416 (pop-to-buffer mother)
|
|
2417 ))
|
|
2418
|
|
2419 (set-alist 'mime-viewer/quitting-method-alist
|
|
2420 'mh-letter-mode
|
|
2421 (function mime-viewer::quitting-method/draft-preview)
|
|
2422 )
|
|
2423
|
|
2424 (set-alist 'mime-viewer/quitting-method-alist
|
|
2425 'news-reply-mode
|
|
2426 (function mime-viewer::quitting-method/draft-preview)
|
|
2427 )
|
|
2428
|
|
2429
|
|
2430 ;;; @ edit again
|
|
2431 ;;;
|
|
2432
|
|
2433 (defun mime-editor::edit-again (code-conversion)
|
|
2434 (save-excursion
|
|
2435 (goto-char (point-min))
|
|
2436 (let ((ctl (mime/Content-Type)))
|
|
2437 (if ctl
|
|
2438 (let ((ctype (car ctl))
|
|
2439 (params (cdr ctl))
|
|
2440 type stype)
|
|
2441 (if (string-match "/" ctype)
|
|
2442 (progn
|
|
2443 (setq type (substring ctype 0 (match-beginning 0)))
|
|
2444 (setq stype (substring ctype (match-end 0)))
|
|
2445 )
|
|
2446 (setq type ctype)
|
|
2447 )
|
|
2448 (cond
|
70
|
2449 ((string-equal type "multipart")
|
4
|
2450 (let* ((boundary (assoc-value "boundary" params))
|
|
2451 (boundary-pat
|
|
2452 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
|
|
2453 )
|
|
2454 (re-search-forward boundary-pat nil t)
|
|
2455 (let ((bb (match-beginning 0)) eb tag)
|
|
2456 (setq tag (format "\n--<<%s>>-{\n" stype))
|
|
2457 (goto-char bb)
|
|
2458 (insert tag)
|
|
2459 (setq bb (+ bb (length tag)))
|
|
2460 (re-search-forward
|
|
2461 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
|
|
2462 nil t)
|
|
2463 (setq eb (match-beginning 0))
|
|
2464 (replace-match (format "--}-<<%s>>\n" stype))
|
|
2465 (save-restriction
|
|
2466 (narrow-to-region bb eb)
|
|
2467 (goto-char (point-min))
|
|
2468 (while (re-search-forward boundary-pat nil t)
|
|
2469 (let ((beg (match-beginning 0))
|
|
2470 end)
|
|
2471 (delete-region beg (match-end 0))
|
|
2472 (save-excursion
|
|
2473 (if (re-search-forward boundary-pat nil t)
|
|
2474 (setq end (match-beginning 0))
|
|
2475 (setq end (point-max))
|
|
2476 )
|
|
2477 (save-restriction
|
|
2478 (narrow-to-region beg end)
|
|
2479 (mime-editor::edit-again code-conversion)
|
|
2480 (goto-char (point-max))
|
|
2481 ))))
|
|
2482 ))
|
|
2483 (goto-char (point-min))
|
|
2484 (or (= (point-min) 1)
|
|
2485 (delete-region (point-min)
|
|
2486 (if (search-forward "\n\n" nil t)
|
|
2487 (match-end 0)
|
|
2488 (point-min)
|
|
2489 )))
|
|
2490 ))
|
|
2491 (t
|
|
2492 (let* (charset
|
|
2493 (pstr
|
74
|
2494 (let ((bytes (+ 14 (length ctype))))
|
|
2495 (mapconcat (function
|
|
2496 (lambda (attr)
|
|
2497 (if (string-equal (car attr) "charset")
|
|
2498 (progn
|
|
2499 (setq charset (cdr attr))
|
|
2500 "")
|
|
2501 (let* ((str
|
|
2502 (concat (car attr)
|
|
2503 "=" (cdr attr))
|
|
2504 )
|
|
2505 (bs (length str))
|
|
2506 )
|
|
2507 (setq bytes (+ bytes bs 2))
|
|
2508 (if (< bytes 76)
|
|
2509 (concat "; " str)
|
|
2510 (setq bytes (+ bs 1))
|
|
2511 (concat ";\n " str)
|
|
2512 )
|
|
2513 ))))
|
|
2514 params "")))
|
4
|
2515 encoding
|
|
2516 encoded)
|
|
2517 (save-excursion
|
|
2518 (if (re-search-forward
|
|
2519 "Content-Transfer-Encoding:" nil t)
|
|
2520 (let ((beg (match-beginning 0))
|
|
2521 (hbeg (match-end 0))
|
|
2522 (end (std11-field-end)))
|
|
2523 (setq encoding
|
|
2524 (eliminate-top-spaces
|
|
2525 (std11-unfold-string
|
|
2526 (buffer-substring hbeg end))))
|
|
2527 (if (or charset (string-equal type "text"))
|
|
2528 (progn
|
|
2529 (delete-region beg (1+ end))
|
|
2530 (goto-char (point-min))
|
|
2531 (if (search-forward "\n\n" nil t)
|
|
2532 (progn
|
|
2533 (mime-decode-region
|
|
2534 (match-end 0)(point-max) encoding)
|
|
2535 (setq encoded t
|
|
2536 encoding nil)
|
|
2537 )))))))
|
|
2538 (if (or code-conversion encoded)
|
|
2539 (decode-mime-charset-region
|
|
2540 (point-min)(point-max)
|
|
2541 (or charset default-mime-charset))
|
|
2542 )
|
|
2543 (let ((he
|
|
2544 (if (re-search-forward "^$" nil t)
|
|
2545 (match-end 0)
|
|
2546 (point-min)
|
|
2547 )))
|
|
2548 (if (= (point-min) 1)
|
|
2549 (progn
|
|
2550 (goto-char he)
|
|
2551 (insert
|
|
2552 (concat "\n"
|
|
2553 (mime-create-tag
|
|
2554 (concat type "/" stype pstr) encoding)))
|
|
2555 )
|
|
2556 (delete-region (point-min) he)
|
|
2557 (insert
|
|
2558 (mime-create-tag
|
|
2559 (concat type "/" stype pstr) encoding))
|
|
2560 ))
|
|
2561 ))))
|
|
2562 (if code-conversion
|
|
2563 (decode-mime-charset-region (point-min) (point-max)
|
|
2564 default-mime-charset)
|
|
2565 )
|
|
2566 ))))
|
|
2567
|
|
2568 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
|
|
2569 (interactive)
|
|
2570 (mime-editor::edit-again code-conversion)
|
|
2571 (goto-char (point-min))
|
|
2572 (save-restriction
|
|
2573 (narrow-to-region
|
|
2574 (point-min)
|
|
2575 (if (re-search-forward
|
|
2576 (concat "^\\(" (regexp-quote mail-header-separator) "\\)?$")
|
|
2577 nil t)
|
|
2578 (match-end 0)
|
|
2579 (point-max)
|
|
2580 ))
|
|
2581 (goto-char (point-min))
|
|
2582 (while (re-search-forward
|
|
2583 "^\\(Content-.*\\|Mime-Version\\):" nil t)
|
|
2584 (delete-region (match-beginning 0) (1+ (std11-field-end)))
|
|
2585 ))
|
|
2586 (or no-separator
|
|
2587 (and (re-search-forward "^$")
|
|
2588 (replace-match mail-header-separator)
|
|
2589 ))
|
|
2590 (or no-mode
|
|
2591 (mime/editor-mode)
|
|
2592 ))
|
|
2593
|
|
2594
|
|
2595 ;;; @ end
|
|
2596 ;;;
|
|
2597
|
|
2598 (provide 'tm-edit)
|
|
2599
|
|
2600 (run-hooks 'tm-edit-load-hook)
|
|
2601
|
|
2602 ;;; tm-edit.el ends here
|