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