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