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