1 ;;; mime-edit.el --- Simple MIME Composer for GNU Emacs
3 ;; Copyright (C) 1993,1994,1995,1996,1997,1998 Free Software Foundation, Inc.
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 ;; Keywords: MIME, multimedia, multilingual, mail, news
12 ;; This file is part of SEMI (Sophisticated Emacs MIME Interfaces).
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;; This is an Emacs minor mode for editing Internet multimedia
32 ;; messages formatted in MIME (RFC 2045, 2046, 2047, 2048 and 2049).
33 ;; All messages in this mode are composed in the tagged MIME format,
34 ;; that are described in the following examples. The messages
35 ;; composed in the tagged MIME format are automatically translated
36 ;; into a MIME compliant message when exiting the mode.
38 ;; Mule (multilingual feature of Emacs 20 and multilingual extension
39 ;; for XEmacs 20) has a capability of handling multilingual text in
40 ;; limited ISO-2022 manner that is based on early experiences in
41 ;; Japanese Internet community and resulted in RFC 1468 (ISO-2022-JP
42 ;; charset for MIME). In order to enable multilingual capability in
43 ;; single text message in MIME, charset of multilingual text written
44 ;; in Mule is declared as either `ISO-2022-JP-2' [RFC 1554]. Mule is
45 ;; required for reading the such messages.
47 ;; This MIME composer can work with Mail mode, mh-e letter Mode, and
48 ;; News mode. First of all, you need the following autoload
49 ;; definition to load mime-edit-mode automatically:
51 ;; (autoload 'turn-on-mime-edit "mime-edit"
52 ;; "Minor mode for editing MIME message." t)
54 ;; In case of Mail mode (includes VM mode), you need the following
57 ;; (add-hook 'mail-mode-hook 'turn-on-mime-edit)
58 ;; (add-hook 'mail-send-hook 'mime-edit-maybe-translate)
60 ;; In case of MH-E, you need the following hook definition:
62 ;; (add-hook 'mh-letter-mode-hook
65 ;; (turn-on-mime-edit)
66 ;; (make-local-variable 'mail-header-separator)
67 ;; (setq mail-header-separator "--------")
69 ;; (add-hook 'mh-before-send-letter-hook 'mime-edit-maybe-translate)
71 ;; In case of News mode, you need the following hook definition:
73 ;; (add-hook 'news-reply-mode-hook 'turn-on-mime-edit)
74 ;; (add-hook 'news-inews-hook 'mime-edit-maybe-translate)
76 ;; In case of Emacs 19, it is possible to emphasize the message tags
77 ;; using font-lock mode as follows:
79 ;; (add-hook 'mime-edit-mode-hook
83 ;; (setq font-lock-keywords (list mime-edit-tag-regexp))
86 ;; The message tag looks like:
88 ;; --[[TYPE/SUBTYPE;PARAMETERS][ENCODING]]
90 ;; The tagged MIME message examples:
92 ;; This is a conventional plain text. It should be translated into
96 ;; This is also a plain text. But, it is explicitly specified as is.
97 ;;--[[text/plain; charset=ISO-8859-1]]
98 ;; This is also a plain text. But charset is specified as iso-8859-1.
100 ;; ¡Hola! Buenos días. ¿Cómo está usted?
101 ;;--[[text/enriched]]
102 ;; <center>This is a richtext.</center>
104 ;;--[[image/gif][base64]]^M...image encoded in base64 comes here...
106 ;;--[[audio/basic][base64]]^M...audio encoded in base64 comes here...
112 (require 'mail-utils)
115 (require 'eword-encode)
123 (defconst mime-edit-version-string
124 `,(concat (car mime-module-version) " "
125 (mapconcat #'number-to-string (cddr mime-module-version) ".")
126 " - \"" (cadr mime-module-version) "\""))
132 (defgroup mime-edit nil
136 (defcustom mime-ignore-preceding-spaces nil
137 "*Ignore preceding white spaces if non-nil."
141 (defcustom mime-ignore-trailing-spaces nil
142 "*Ignore trailing white spaces if non-nil."
146 (defcustom mime-ignore-same-text-tag t
147 "*Ignore preceding text content-type tag that is same with new one.
148 If non-nil, the text tag is not inserted unless something different."
152 (defcustom mime-auto-hide-body t
153 "*Hide non-textual body encoded in base64 after insertion if non-nil."
157 (defcustom mime-edit-voice-recorder
158 (function mime-edit-voice-recorder-for-sun)
159 "*Function to record a voice message and encode it."
163 (defcustom mime-edit-mode-hook nil
164 "*Hook called when enter MIME mode."
168 (defcustom mime-edit-translate-hook nil
169 "*Hook called before translating into a MIME compliant message.
170 To insert a signature file automatically, call the function
171 `mime-edit-insert-signature' from this hook."
175 (defcustom mime-edit-exit-hook nil
176 "*Hook called when exit MIME mode."
180 (defvar mime-content-types
182 ;; Charset parameter need not to be specified, since it is
183 ;; defined automatically while translation.
185 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
188 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
191 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
194 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
197 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
205 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
206 ("directory" "/pub/GNU/elisp/mime")
208 ("mode" "image" "ascii" "local8"))
213 ("mode" "image" "ascii" "local8"))
214 ("tftp" ("site") ("name"))
215 ("afs" ("site") ("name"))
216 ("local-file" ("site") ("name"))
217 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
222 ("octet-stream" ("type" "" "tar" "shar"))
224 ("x-kiss" ("x-cnf")))
238 "*Alist of content-type, subtype, parameters and its values.")
240 (defcustom mime-file-types
244 "inline" (("filename" . file))
249 "inline" (("filename" . file))
252 "text" "richtext" nil
260 "application" "postscript" nil
262 "attachment" (("filename" . file))
267 "inline" (("filename" . file))
272 "inline" (("filename" . file))
277 "inline" (("filename" . file))
282 "inline" (("filename" . file))
287 "inline" (("filename" . file))
292 "inline" (("filename" . file))
297 "inline" (("filename" . file))
302 "inline" (("filename" . file))
307 "attachment" (("filename" . file))
312 "attachment" (("filename" . file))
315 "application" "octet-stream" (("type" . "emacs-lisp"))
317 "attachment" (("filename" . file))
320 "application" "octet-stream" (("type" . "common-lisp"))
322 "attachment" (("filename" . file))
325 "application" "octet-stream" (("type" . "tar+gzip"))
327 "attachment" (("filename" . file))
330 "application" "octet-stream" (("type" . "tar+gzip"))
332 "attachment" (("filename" . file))
335 "application" "octet-stream" (("type" . "tar+compress"))
337 "attachment" (("filename" . file))
340 "application" "octet-stream" (("type" . "tar+compress"))
342 "attachment" (("filename" . file))
345 "application" "octet-stream" (("type" . "gzip"))
347 "attachment" (("filename" . file))
350 "application" "octet-stream" (("type" . "compress"))
352 "attachment" (("filename" . file))
355 "application" "octet-stream" (("type" . "lha"))
357 "attachment" (("filename" . file))
360 "application" "zip" nil
362 "attachment" (("filename" . file))
365 "application" "octet-stream" (("type" . "patch"))
367 "attachment" (("filename" . file))
370 "application" "octet-stream" (("type" . "patch"))
372 "attachment" (("filename" . file))
375 "text" "plain" nil nil nil nil)
377 "application" "octet-stream" nil
379 "attachment" (("filename" . file)))
381 "*Alist of file name, types, parameters, and default encoding.
382 If encoding is nil, it is determined from its contents."
386 (choice :tag "Primary-Type"
387 ,@(nconc (mapcar (lambda (cell)
388 (list 'item (car cell))
393 (choice :tag "Sub-Type"
396 (mapcar (lambda (cell)
397 (mapcar (lambda (cell)
398 (list 'item (car cell))
404 (repeat :tag "Parameters of Content-Type field"
405 (cons string (choice string symbol)))
406 ;; content-transfer-encoding
407 (choice :tag "Encoding"
410 (mapcar (lambda (cell)
411 (list 'item (car cell))
413 mime-file-encoding-method-alist)))
415 (choice :tag "Disposition-Type"
421 (repeat :tag "Parameters of Content-Disposition field"
422 (cons string (choice string symbol)))
427 ;;; @@ about charset, encoding and transfer-level
430 (defvar mime-charset-type-list
432 (iso-8859-1 8 "quoted-printable")
433 (iso-8859-2 8 "quoted-printable")
434 (iso-8859-3 8 "quoted-printable")
435 (iso-8859-4 8 "quoted-printable")
436 (iso-8859-5 8 "quoted-printable")
437 (koi8-r 8 "quoted-printable")
438 (iso-8859-7 8 "quoted-printable")
439 (iso-8859-8 8 "quoted-printable")
440 (iso-8859-9 8 "quoted-printable")
441 (iso-2022-jp 7 "base64")
442 (iso-2022-kr 7 "base64")
444 (cn-gb2312 8 "base64")
448 (shift_jis 8 "base64")
449 (iso-2022-jp-2 7 "base64")
450 (iso-2022-int-1 7 "base64")
453 (defvar mime-transfer-level 7
454 "*A number of network transfer level. It should be bigger than 7.")
455 (make-variable-buffer-local 'mime-transfer-level)
457 (defsubst mime-encoding-name (transfer-level &optional not-omit)
458 (cond ((> transfer-level 8) "binary")
459 ((= transfer-level 8) "8bit")
463 (defvar mime-transfer-level-string
464 (mime-encoding-name mime-transfer-level 'not-omit)
465 "A string formatted version of mime-transfer-level")
466 (make-variable-buffer-local 'mime-transfer-level-string)
469 ;;; @@ about message inserting
472 (defvar mime-edit-yank-ignored-field-list
473 '("Received" "Approved" "Path" "Replied" "Status"
474 "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
475 "Delete these fields from original message when it is inserted
476 as message/rfc822 part.
477 Each elements are regexp of field-name.")
479 (defvar mime-edit-yank-ignored-field-regexp
481 (apply (function regexp-or) mime-edit-yank-ignored-field-list)
484 (defvar mime-edit-message-inserter-alist nil)
485 (defvar mime-edit-mail-inserter-alist nil)
488 ;;; @@ about message splitting
491 (defcustom mime-edit-split-message t
492 "*Split large message if it is non-nil."
496 (defcustom mime-edit-message-default-max-lines 1000
497 "*Default maximum lines of a message."
501 (defcustom mime-edit-message-max-lines-alist
502 '((news-reply-mode . 500))
503 "Alist of major-mode vs maximum lines of a message.
504 If it is not specified for a major-mode,
505 `mime-edit-message-default-max-lines' is used."
509 (defconst mime-edit-split-ignored-field-regexp
510 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\|Message-Id:\\)")
512 (defvar mime-edit-split-blind-field-regexp
513 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
515 (defvar mime-edit-split-message-sender-alist nil)
517 (defvar mime-edit-news-reply-mode-server-running nil)
523 (defconst mime-edit-single-part-tag-regexp
524 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
525 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
527 (defconst mime-edit-quoted-single-part-tag-regexp
528 (concat "- " (substring mime-edit-single-part-tag-regexp 1)))
530 (defconst mime-edit-multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
532 (defconst mime-edit-multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
534 (defconst mime-edit-beginning-tag-regexp
535 (regexp-or mime-edit-single-part-tag-regexp
536 mime-edit-multipart-beginning-regexp))
538 (defconst mime-edit-end-tag-regexp
539 (regexp-or mime-edit-single-part-tag-regexp
540 mime-edit-multipart-end-regexp))
542 (defconst mime-edit-tag-regexp
543 (regexp-or mime-edit-single-part-tag-regexp
544 mime-edit-multipart-beginning-regexp
545 mime-edit-multipart-end-regexp))
547 (defvar mime-tag-format "--[[%s]]"
548 "*Control-string making a MIME tag.")
550 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
551 "*Control-string making a MIME tag with encoding.")
554 ;;; @@ multipart boundary
557 (defvar mime-multipart-boundary "Multipart"
558 "*Boundary of a multipart message.")
561 ;;; @@ optional header fields
564 (defvar mime-edit-insert-x-emacs-field t
565 "*If non-nil, insert X-Emacs header field.")
567 (defvar mime-edit-x-emacs-value
568 (if (featurep 'xemacs)
569 (concat emacs-version (if (featurep 'mule)
572 (let ((ver (if (string-match "\\.[0-9]+$" emacs-version)
573 (substring emacs-version 0 (match-beginning 0))
576 (if (boundp 'enable-multibyte-characters)
578 (if enable-multibyte-characters
579 (concat ", MULE " mule-version)
580 " (with raw setting)")
581 (if (featurep 'meadow)
582 (concat ", " (Meadow-version))
584 (concat "MULE " mule-version " based on Emacs " ver))
586 "Body of X-Emacs field.
587 If variable `mime-edit-insert-x-emacs-field' is not nil, it is
588 inserted into message header.")
594 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
595 "*Specify MIME tspecials.
596 Tspecials means any character that matches with it in header must be quoted.")
598 (defconst mime-edit-mime-version-value
599 (concat "1.0 (generated by " mime-edit-version-string ")")
600 "MIME version number.")
602 (defconst mime-edit-mime-version-field-for-message/partial
603 (concat "MIME-Version: 1.0 (split by " mime-edit-version-string ")\n")
604 "MIME version field for message/partial.")
607 ;;; @ keymap and menu
610 (defvar mime-edit-mode-flag nil)
611 (make-variable-buffer-local 'mime-edit-mode-flag)
613 (defvar mime-edit-mode-entity-prefix "\C-c\C-x"
614 "Keymap prefix for MIME-Edit mode commands to insert entity or set status.")
615 (defvar mime-edit-mode-entity-map (make-sparse-keymap)
616 "Keymap for MIME-Edit mode commands to insert entity or set status.")
618 (define-key mime-edit-mode-entity-map "\C-t" 'mime-edit-insert-text)
619 (define-key mime-edit-mode-entity-map "\C-i" 'mime-edit-insert-file)
620 (define-key mime-edit-mode-entity-map "\C-e" 'mime-edit-insert-external)
621 (define-key mime-edit-mode-entity-map "\C-v" 'mime-edit-insert-voice)
622 (define-key mime-edit-mode-entity-map "\C-y" 'mime-edit-insert-message)
623 (define-key mime-edit-mode-entity-map "\C-m" 'mime-edit-insert-mail)
624 (define-key mime-edit-mode-entity-map "\C-w" 'mime-edit-insert-signature)
625 (define-key mime-edit-mode-entity-map "\C-s" 'mime-edit-insert-signature)
626 (define-key mime-edit-mode-entity-map "\C-k" 'mime-edit-insert-key)
627 (define-key mime-edit-mode-entity-map "t" 'mime-edit-insert-tag)
629 (define-key mime-edit-mode-entity-map "7" 'mime-edit-set-transfer-level-7bit)
630 (define-key mime-edit-mode-entity-map "8" 'mime-edit-set-transfer-level-8bit)
631 (define-key mime-edit-mode-entity-map "/" 'mime-edit-set-split)
632 (define-key mime-edit-mode-entity-map "s" 'mime-edit-set-sign)
633 (define-key mime-edit-mode-entity-map "v" 'mime-edit-set-sign)
634 (define-key mime-edit-mode-entity-map "e" 'mime-edit-set-encrypt)
635 (define-key mime-edit-mode-entity-map "h" 'mime-edit-set-encrypt)
636 (define-key mime-edit-mode-entity-map "p" 'mime-edit-preview-message)
637 (define-key mime-edit-mode-entity-map "\C-z" 'mime-edit-exit)
638 (define-key mime-edit-mode-entity-map "?" 'mime-edit-help)
640 (defvar mime-edit-mode-enclosure-prefix "\C-c\C-m"
641 "Keymap prefix for MIME-Edit mode commands about enclosure.")
642 (defvar mime-edit-mode-enclosure-map (make-sparse-keymap)
643 "Keymap for MIME-Edit mode commands about enclosure.")
645 (define-key mime-edit-mode-enclosure-map
646 "\C-a" 'mime-edit-enclose-alternative-region)
647 (define-key mime-edit-mode-enclosure-map
648 "\C-p" 'mime-edit-enclose-parallel-region)
649 (define-key mime-edit-mode-enclosure-map
650 "\C-m" 'mime-edit-enclose-mixed-region)
651 (define-key mime-edit-mode-enclosure-map
652 "\C-d" 'mime-edit-enclose-digest-region)
653 (define-key mime-edit-mode-enclosure-map
654 "\C-s" 'mime-edit-enclose-pgp-signed-region)
655 (define-key mime-edit-mode-enclosure-map
656 "\C-e" 'mime-edit-enclose-pgp-encrypted-region)
657 (define-key mime-edit-mode-enclosure-map
658 "\C-q" 'mime-edit-enclose-quote-region)
660 (defvar mime-edit-mode-map (make-sparse-keymap)
661 "Keymap for MIME-Edit mode commands.")
662 (define-key mime-edit-mode-map
663 mime-edit-mode-entity-prefix mime-edit-mode-entity-map)
664 (define-key mime-edit-mode-map
665 mime-edit-mode-enclosure-prefix mime-edit-mode-enclosure-map)
667 (defconst mime-edit-menu-title "MIME-Edit")
669 (defconst mime-edit-menu-list
670 '((mime-help "Describe MIME editor mode" mime-edit-help)
671 (file "Insert File" mime-edit-insert-file)
672 (external "Insert External" mime-edit-insert-external)
673 (voice "Insert Voice" mime-edit-insert-voice)
674 (message "Insert Message" mime-edit-insert-message)
675 (mail "Insert Mail" mime-edit-insert-mail)
676 (signature "Insert Signature" mime-edit-insert-signature)
677 (text "Insert Text" mime-edit-insert-text)
678 (tag "Insert Tag" mime-edit-insert-tag)
679 (alternative "Enclose as alternative"
680 mime-edit-enclose-alternative-region)
681 (parallel "Enclose as parallel" mime-edit-enclose-parallel-region)
682 (mixed "Enclose as serial" mime-edit-enclose-mixed-region)
683 (digest "Enclose as digest" mime-edit-enclose-digest-region)
684 (signed "Enclose as signed" mime-edit-enclose-pgp-signed-region)
685 (encrypted "Enclose as encrypted" mime-edit-enclose-pgp-encrypted-region)
686 (quote "Verbatim region" mime-edit-enclose-quote-region)
687 (key "Insert Public Key" mime-edit-insert-key)
688 (split "About split" mime-edit-set-split)
689 (sign "About sign" mime-edit-set-sign)
690 (encrypt "About encryption" mime-edit-set-encrypt)
691 (preview "Preview Message" mime-edit-preview-message)
692 (level "Toggle transfer-level" mime-edit-toggle-transfer-level)
694 "MIME-edit menubar entry.")
696 (cond (running-xemacs
697 ;; modified by Pekka Marjola <pema@iki.fi>
698 ;; 1995/9/5 (c.f. [tm-en:69])
699 (defun mime-edit-define-menu-for-xemacs ()
700 "Define menu for Emacs 19."
701 (cond ((featurep 'menubar)
702 (make-local-variable 'current-menubar)
703 (set-buffer-menubar current-menubar)
706 (cons mime-edit-menu-title
709 (vector (nth 1 item)(nth 2 item)
712 mime-edit-menu-list)))
715 ;; modified by Steven L. Baur <steve@miranova.com>
716 ;; 1995/12/6 (c.f. [tm-en:209])
717 (or (boundp 'mime-edit-popup-menu-for-xemacs)
718 (setq mime-edit-popup-menu-for-xemacs
719 (append '("MIME Commands" "---")
720 (mapcar (function (lambda (item)
724 mime-edit-menu-list)))
727 ((>= emacs-major-version 19)
728 (define-key mime-edit-mode-map [menu-bar mime-edit]
729 (cons mime-edit-menu-title
730 (make-sparse-keymap mime-edit-menu-title)))
733 (define-key mime-edit-mode-map
734 (vector 'menu-bar 'mime-edit (car item))
735 (cons (nth 1 item)(nth 2 item))
738 (reverse mime-edit-menu-list)
746 (defvar mime-edit-touched-flag nil)
749 (defun mime-edit-mode ()
750 "MIME minor mode for editing the tagged MIME message.
752 In this mode, basically, the message is composed in the tagged MIME
753 format. The message tag looks like:
755 --[[text/plain; charset=ISO-2022-JP][7bit]]
757 The tag specifies the MIME content type, subtype, optional parameters
758 and transfer encoding of the message following the tag. Messages
759 without any tag are treated as `text/plain' by default. Charset and
760 transfer encoding are automatically defined unless explicitly
761 specified. Binary messages such as audio and image are usually
762 hidden. The messages in the tagged MIME format are automatically
763 translated into a MIME compliant message when exiting this mode.
765 Available charsets depend on Emacs version being used. The following
766 lists the available charsets of each emacs.
768 Without mule: US-ASCII and ISO-8859-1 (or other charset) are available.
769 With mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
770 ISO-2022-JP, ISO-2022-JP-2, EUC-KR, CN-GB-2312,
771 CN-BIG5 and ISO-2022-INT-1 are available.
773 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
774 be used to represent multilingual text in intermixed manner. Any
775 languages that has no registered charset are represented as either
776 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
778 If you want to use non-ISO-8859-1 charset in Emacs 19 or XEmacs
779 without mule, please set variable `default-mime-charset'. This
780 variable must be symbol of which name is a MIME charset.
782 If you want to add more charsets in mule, please set variable
783 `charsets-mime-charset-alist'. This variable must be alist of which
784 key is list of charset and value is symbol of MIME charset. If name
785 of coding-system is different as MIME charset, please set variable
786 `mime-charset-coding-system-alist'. This variable must be alist of
787 which key is MIME charset and value is coding-system.
789 Following commands are available in addition to major mode commands:
792 \\[mime-edit-insert-text] insert a text message.
793 \\[mime-edit-insert-file] insert a (binary) file.
794 \\[mime-edit-insert-external] insert a reference to external body.
795 \\[mime-edit-insert-voice] insert a voice message.
796 \\[mime-edit-insert-message] insert a mail or news message.
797 \\[mime-edit-insert-mail] insert a mail message.
798 \\[mime-edit-insert-signature] insert a signature file at end.
799 \\[mime-edit-insert-key] insert PGP public key.
800 \\[mime-edit-insert-tag] insert a new MIME tag.
802 \[make enclosure (maybe multipart)\]
803 \\[mime-edit-enclose-alternative-region] enclose as multipart/alternative.
804 \\[mime-edit-enclose-parallel-region] enclose as multipart/parallel.
805 \\[mime-edit-enclose-mixed-region] enclose as multipart/mixed.
806 \\[mime-edit-enclose-digest-region] enclose as multipart/digest.
807 \\[mime-edit-enclose-pgp-signed-region] enclose as PGP signed.
808 \\[mime-edit-enclose-pgp-encrypted-region] enclose as PGP encrypted.
809 \\[mime-edit-enclose-quote-region] enclose as verbose mode
810 (to avoid to expand tags)
813 \\[mime-edit-set-transfer-level-7bit] set transfer-level as 7.
814 \\[mime-edit-set-transfer-level-8bit] set transfer-level as 8.
815 \\[mime-edit-set-split] set message splitting mode.
816 \\[mime-edit-set-sign] set PGP-sign mode.
817 \\[mime-edit-set-encrypt] set PGP-encryption mode.
818 \\[mime-edit-preview-message] preview editing MIME message.
819 \\[mime-edit-exit] exit and translate into a MIME
821 \\[mime-edit-help] show this help.
822 \\[mime-edit-maybe-translate] exit and translate if in MIME mode,
825 Additional commands are available in some major modes:
826 C-c C-c exit, translate and run the original command.
827 C-c C-s exit, translate and run the original command.
829 The following is a message example written in the tagged MIME format.
830 TABs at the beginning of the line are not a part of the message:
832 This is a conventional plain text. It should be translated
835 This is also a plain text. But, it is explicitly specified as
837 --[[text/plain; charset=ISO-8859-1]]
838 This is also a plain text. But charset is specified as
841 ¡Hola! Buenos días. ¿Cómo está usted?
843 This is a <bold>enriched text</bold>.
844 --[[image/gif][base64]]...image encoded in base64 here...
845 --[[audio/basic][base64]]...audio encoded in base64 here...
847 User customizable variables (not documented all of them):
849 Specifies a key prefix for MIME minor mode commands.
851 mime-ignore-preceding-spaces
852 Preceding white spaces in a message body are ignored if non-nil.
854 mime-ignore-trailing-spaces
855 Trailing white spaces in a message body are ignored if non-nil.
858 Hide a non-textual body message encoded in base64 after insertion
862 A number of network transfer level. It should be bigger than 7.
863 If you are in 8bit-through environment, please set 8.
865 mime-edit-voice-recorder
866 Specifies a function to record a voice message and encode it.
867 The function `mime-edit-voice-recorder-for-sun' is for Sun
871 Turning on MIME mode calls the value of mime-edit-mode-hook, if
874 mime-edit-translate-hook
875 The value of mime-edit-translate-hook is called just before translating
876 the tagged MIME format into a MIME compliant message if it is
877 non-nil. If the hook call the function mime-edit-insert-signature,
878 the signature file will be inserted automatically.
881 Turning off MIME mode calls the value of mime-edit-exit-hook, if it is
884 (if mime-edit-mode-flag
886 (if mime-edit-touched-flag
888 (make-local-variable 'mime-edit-touched-flag)
889 (setq mime-edit-touched-flag t)
894 (cond (running-xemacs
895 (add-minor-mode 'mime-edit-mode-flag
896 '((" MIME-Edit " mime-transfer-level-string))
902 (set-alist 'minor-mode-alist
904 '((" MIME-Edit " mime-transfer-level-string)))
905 (set-alist 'minor-mode-map-alist
912 (defun turn-on-mime-edit ()
913 "Unconditionally turn on MIME-Edit mode."
915 (if mime-edit-mode-flag
916 (error "You are already editing a MIME message.")
917 (setq mime-edit-mode-flag t)
919 ;; Set transfer level into mode line
921 (setq mime-transfer-level-string
922 (mime-encoding-name mime-transfer-level 'not-omit))
923 (force-mode-line-update)
925 ;; Define menu for XEmacs.
927 (mime-edit-define-menu-for-xemacs)
932 ;; I don't care about saving these.
933 (setq paragraph-start
934 (regexp-or mime-edit-single-part-tag-regexp
936 (setq paragraph-separate
937 (regexp-or mime-edit-single-part-tag-regexp
939 (run-hooks 'mime-edit-mode-hook)
941 (substitute-command-keys
942 "Type \\[mime-edit-exit] to exit MIME mode, and type \\[mime-edit-help] to get help."))
946 (defalias 'edit-mime 'turn-on-mime-edit) ; for convenience
949 (defun mime-edit-exit (&optional nomime no-error)
950 "Translate the tagged MIME message into a MIME compliant message.
951 With no argument encode a message in the buffer into MIME, otherwise
952 just return to previous mode."
954 (if (not mime-edit-mode-flag)
956 (error "You aren't editing a MIME message.")
960 (run-hooks 'mime-edit-translate-hook)
961 (mime-edit-translate-buffer)))
962 ;; Restore previous state.
963 (setq mime-edit-mode-flag nil)
964 (if (and running-xemacs
966 (delete-menu-item (list mime-edit-menu-title))
969 (set-buffer-modified-p (buffer-modified-p))
970 (run-hooks 'mime-edit-exit-hook)
971 (message "Exit MIME editor mode.")
974 (defun mime-edit-maybe-translate ()
976 (mime-edit-exit nil t)
977 (call-interactively 'mime-edit-maybe-split-and-send)
980 (defun mime-edit-help ()
981 "Show help message about MIME mode."
983 (with-output-to-temp-buffer "*Help*"
984 (princ "MIME editor mode:\n")
985 (princ (documentation 'mime-edit-mode))
986 (print-help-return-message)))
988 (defun mime-edit-insert-text (&optional subtype)
989 "Insert a text message.
990 Charset is automatically obtained from the `charsets-mime-charset-alist'.
991 If optional argument SUBTYPE is not nil, text/SUBTYPE tag is inserted."
993 (let ((ret (mime-edit-insert-tag "text" subtype nil)))
995 (if (looking-at mime-edit-single-part-tag-regexp)
997 ;; Make a space between the following message.
1001 (if (and (member (cadr ret) '("enriched" "richtext"))
1002 (fboundp 'enriched-mode)
1005 (if (boundp 'enriched-mode)
1010 (defun mime-edit-insert-file (file &optional verbose)
1011 "Insert a message from a file."
1012 (interactive "fInsert file as MIME message: \nP")
1013 (let* ((guess (mime-find-file-type file))
1014 (type (nth 0 guess))
1015 (subtype (nth 1 guess))
1016 (parameters (nth 2 guess))
1017 (encoding (nth 3 guess))
1018 (disposition-type (nth 4 guess))
1019 (disposition-params (nth 5 guess))
1022 (setq type (mime-prompt-for-type type)
1023 subtype (mime-prompt-for-subtype type subtype)
1025 (if (or (interactive-p) verbose)
1026 (setq encoding (mime-prompt-for-encoding encoding))
1028 (if (or (consp parameters) (stringp disposition-type))
1029 (let ((rest parameters) cell attribute value)
1030 (setq parameters "")
1032 (setq cell (car rest))
1033 (setq attribute (car cell))
1034 (setq value (cdr cell))
1035 (if (eq value 'file)
1036 (setq value (std11-wrap-as-quoted-string
1037 (file-name-nondirectory file)))
1039 (setq parameters (concat parameters "; " attribute "=" value))
1040 (setq rest (cdr rest))
1042 (if disposition-type
1045 (concat parameters "\n"
1046 "Content-Disposition: " disposition-type))
1047 (setq rest disposition-params)
1049 (setq cell (car rest))
1050 (setq attribute (car cell))
1051 (setq value (cdr cell))
1052 (if (eq value 'file)
1053 (setq value (std11-wrap-as-quoted-string
1054 (file-name-nondirectory file)))
1057 (concat parameters "; " attribute "=" value))
1058 (setq rest (cdr rest))
1062 (mime-edit-insert-tag type subtype parameters)
1063 (mime-edit-insert-binary-file file encoding)
1066 (defun mime-edit-insert-external ()
1067 "Insert a reference to external body."
1069 (mime-edit-insert-tag "message" "external-body" nil ";\n\t")
1071 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
1073 (let* ((pritype (mime-prompt-for-type))
1074 (subtype (mime-prompt-for-subtype pritype))
1075 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
1078 (insert "Content-Type: "
1079 pritype "/" subtype (or parameters "") "\n")))
1080 (if (and (not (eobp))
1081 (not (looking-at mime-edit-single-part-tag-regexp)))
1082 (insert (mime-make-text-tag) "\n")))
1084 (defun mime-edit-insert-voice ()
1085 "Insert a voice message."
1089 "What transfer encoding: "
1090 mime-file-encoding-method-alist nil t nil)))
1091 (mime-edit-insert-tag "audio" "basic" nil)
1092 (mime-edit-define-encoding encoding)
1094 (narrow-to-region (1- (point))(point))
1096 (funcall mime-edit-voice-recorder encoding)
1099 (invisible-region (point-min)(point-max))
1100 (goto-char (point-max))
1103 (defun mime-edit-insert-signature (&optional arg)
1104 "Insert a signature file."
1106 (let ((signature-insert-hook
1109 (let ((items (mime-find-file-type signature-file-name)))
1110 (apply (function mime-edit-insert-tag)
1111 (car items) (cadr items) (list (caddr items))))
1114 (insert-signature arg)
1118 ;; Insert a new tag around a point.
1120 (defun mime-edit-insert-tag (&optional pritype subtype parameters delimiter)
1121 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
1122 If nothing is inserted, return nil."
1125 (mime-edit-goto-tag)
1126 (if (and (re-search-forward mime-edit-tag-regexp nil t)
1127 (< (match-beginning 0) p)
1130 (goto-char (match-beginning 0))
1139 (mime-prompt-for-type)))
1142 (mime-prompt-for-subtype pritype)))
1145 (mime-prompt-for-parameters pritype subtype delimiter)))
1146 ;; Make a new MIME tag.
1147 (setq newtag (mime-make-tag pritype subtype parameters))
1148 ;; Find an current MIME tag.
1151 (if (mime-edit-goto-tag)
1152 (buffer-substring (match-beginning 0) (match-end 0))
1153 ;; Assume content type is 'text/plan'.
1154 (mime-make-tag "text" "plain")
1156 ;; We are only interested in TEXT.
1158 (not (mime-test-content-type
1159 (mime-edit-get-contype oldtag) "text")))
1162 (if (or (not oldtag) ;Not text
1163 (or mime-ignore-same-text-tag
1164 (not (string-equal oldtag newtag))))
1166 ;; Mark the beginning of the tag for convenience.
1167 (push-mark (point) 'nomsg)
1168 (insert newtag "\n")
1169 (list pritype subtype parameters) ;New tag is created.
1171 ;; Restore previous point.
1173 nil ;Nothing is created.
1177 (defun mime-edit-insert-binary-file (file &optional encoding)
1178 "Insert binary FILE at point.
1179 Optional argument ENCODING specifies an encoding method such as base64."
1180 (let* ((tagend (1- (point))) ;End of the tag
1181 (hide-p (and mime-auto-hide-body
1184 (let ((en (downcase encoding)))
1185 (or (string-equal en "7bit")
1186 (string-equal en "8bit")
1187 (string-equal en "binary")
1191 (narrow-to-region tagend (point))
1192 (mime-insert-encoded-file file encoding)
1195 (invisible-region (point-min) (point-max))
1196 (goto-char (point-max))
1198 (goto-char (point-max))
1201 (looking-at mime-edit-tag-regexp)
1202 (= (point)(point-max))
1203 (mime-edit-insert-tag "text" "plain")
1205 ;; Define encoding even if it is 7bit.
1206 (if (stringp encoding)
1208 (goto-char tagend) ; Make sure which line the tag is on.
1209 (mime-edit-define-encoding encoding)
1214 ;; Commands work on a current message flagment.
1216 (defun mime-edit-goto-tag ()
1217 "Search for the beginning of the tagged MIME message."
1218 (let ((current (point)))
1219 (if (looking-at mime-edit-tag-regexp)
1221 ;; At first, go to the end.
1222 (cond ((re-search-forward mime-edit-beginning-tag-regexp nil t)
1223 (goto-char (1- (match-beginning 0))) ;For multiline tag
1226 (goto-char (point-max))
1228 ;; Then search for the beginning.
1229 (re-search-backward mime-edit-end-tag-regexp nil t)
1230 (or (looking-at mime-edit-beginning-tag-regexp)
1231 ;; Restore previous point.
1238 (defun mime-edit-content-beginning ()
1239 "Return the point of the beginning of content."
1241 (let ((beg (save-excursion
1242 (beginning-of-line) (point))))
1243 (if (mime-edit-goto-tag)
1244 (let ((top (point)))
1245 (goto-char (match-end 0))
1246 (if (and (= beg top)
1247 (= (following-char) ?\^M))
1251 ;; Default text/plain tag.
1252 (goto-char (point-min))
1254 (concat "\n" (regexp-quote mail-header-separator)
1255 (if mime-ignore-preceding-spaces
1256 "[ \t\n]*\n" "\n")) nil 'move)
1260 (defun mime-edit-content-end ()
1261 "Return the point of the end of content."
1263 (if (mime-edit-goto-tag)
1265 (goto-char (match-end 0))
1266 (if (invisible-p (point))
1267 (next-visible-point (point))
1268 ;; Move to the end of this text.
1269 (if (re-search-forward mime-edit-tag-regexp nil 'move)
1270 ;; Don't forget a multiline tag.
1271 (goto-char (match-beginning 0))
1275 ;; Assume the message begins with text/plain.
1276 (goto-char (mime-edit-content-beginning))
1277 (if (re-search-forward mime-edit-tag-regexp nil 'move)
1278 ;; Don't forget a multiline tag.
1279 (goto-char (match-beginning 0)))
1283 (defun mime-edit-define-charset (charset)
1284 "Set charset of current tag to CHARSET."
1286 (if (mime-edit-goto-tag)
1287 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1288 (delete-region (match-beginning 0) (match-end 0))
1291 (mime-edit-set-parameter
1292 (mime-edit-get-contype tag)
1293 "charset" (upcase (symbol-name charset)))
1294 (mime-edit-get-encoding tag)))
1297 (defun mime-edit-define-encoding (encoding)
1298 "Set encoding of current tag to ENCODING."
1300 (if (mime-edit-goto-tag)
1301 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1302 (delete-region (match-beginning 0) (match-end 0))
1303 (insert (mime-create-tag (mime-edit-get-contype tag) encoding)))
1306 (defun mime-edit-choose-charset ()
1307 "Choose charset of a text following current point."
1308 (detect-mime-charset-region (point) (mime-edit-content-end))
1311 (defun mime-make-text-tag (&optional subtype)
1312 "Make a tag for a text after current point.
1313 Subtype of text type can be specified by an optional argument SUBTYPE.
1314 Otherwise, it is obtained from mime-content-types."
1315 (let* ((pritype "text")
1316 (subtype (or subtype
1317 (car (car (cdr (assoc pritype mime-content-types)))))))
1318 ;; Charset should be defined later.
1319 (mime-make-tag pritype subtype)))
1322 ;; Tag handling functions
1324 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1325 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1326 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1330 (defun mime-create-tag (contype &optional encoding)
1331 "Make a tag with CONTENT-TYPE and optional ENCODING."
1332 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1335 (defun mime-edit-get-contype (tag)
1336 "Return Content-Type (including parameters) of TAG."
1338 (or (string-match mime-edit-single-part-tag-regexp tag)
1339 (string-match mime-edit-multipart-beginning-regexp tag)
1340 (string-match mime-edit-multipart-end-regexp tag)
1342 (substring tag (match-beginning 1) (match-end 1))
1345 (defun mime-edit-get-encoding (tag)
1346 "Return encoding of TAG."
1348 (string-match mime-edit-single-part-tag-regexp tag)
1350 (not (= (match-beginning 3) (match-end 3)))
1351 (substring tag (match-beginning 3) (match-end 3))))
1353 (defun mime-get-parameter (contype parameter)
1354 "For given CONTYPE return value for PARAMETER.
1355 Nil if no such parameter."
1359 (regexp-quote parameter)
1360 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1362 (substring contype (match-beginning 1) (match-end 1))
1363 nil ;No such parameter
1366 (defun mime-edit-set-parameter (contype parameter value)
1367 "For given CONTYPE set PARAMETER to VALUE."
1368 (let (ctype opt-fields)
1369 (if (string-match "\n[^ \t\n\r]+:" contype)
1370 (setq ctype (substring contype 0 (match-beginning 0))
1371 opt-fields (substring contype (match-beginning 0)))
1372 (setq ctype contype)
1377 (regexp-quote parameter)
1378 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1381 (concat (substring ctype 0 (match-beginning 1))
1383 (substring contype (match-end 1))
1385 (concat ctype "; " parameter "=" value opt-fields)
1388 (defun mime-strip-parameters (contype)
1389 "Return primary content-type and subtype without parameters for CONTYPE."
1390 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1391 (substring contype (match-beginning 1) (match-end 1)) nil))
1393 (defun mime-test-content-type (contype type &optional subtype)
1394 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1395 (and (stringp contype)
1398 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1399 (downcase contype))))
1404 (defun mime-find-file-type (file)
1405 "Guess Content-Type, subtype, and parameters from FILE."
1407 (guesses mime-file-types))
1408 (while (and (not guess) guesses)
1409 (if (string-match (car (car guesses)) file)
1410 (setq guess (cdr (car guesses))))
1411 (setq guesses (cdr guesses)))
1415 (defun mime-prompt-for-type (&optional default)
1416 "Ask for Content-type."
1418 ;; Repeat until primary content type is specified.
1419 (while (string-equal type "")
1421 (completing-read "What content type: "
1424 'require-match ;Type must be specified.
1427 (if (string-equal type "")
1429 (message "Content type is required.")
1436 (defun mime-prompt-for-subtype (type &optional default)
1437 "Ask for subtype of media-type TYPE."
1438 (let ((subtypes (cdr (assoc type mime-content-types))))
1440 (assoc default subtypes))
1441 (setq default (car (car subtypes)))
1447 "What content subtype: (default " default ") ")
1448 "What content subtype: ")
1449 (cdr (assoc type mime-content-types))
1451 'require-match ;Subtype must be specified.
1454 (if (string-equal answer "") default answer)))
1456 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1457 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1458 Optional DELIMITER specifies parameter delimiter (';' by default)."
1459 (let* ((delimiter (or delimiter "; "))
1464 (mime-prompt-for-parameters-1
1466 (cdr (assoc pritype mime-content-types))))))
1469 (if (and (stringp parameters)
1470 (not (string-equal parameters "")))
1471 (concat delimiter parameters)
1472 "" ;"" if no parameters
1475 (defun mime-prompt-for-parameters-1 (optlist)
1476 (apply (function append)
1477 (mapcar (function mime-prompt-for-parameter) optlist)))
1479 (defun mime-prompt-for-parameter (parameter)
1481 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1482 (let* ((prompt (car parameter))
1483 (choices (mapcar (function
1485 (if (consp e) e (list e))))
1487 (default (car (car choices)))
1493 (concat "What " prompt
1495 (if (string-equal default "") "\"\"" default)
1497 choices nil nil ""))
1498 ;; If nothing is selected, use default.
1499 (if (string-equal answer "")
1500 (setq answer default)))
1502 (read-string (concat "What " prompt ": "))))
1503 (cons (if (and answer
1504 (not (string-equal answer "")))
1506 ;; Note: control characters ignored!
1507 (if (string-match mime-tspecials-regexp answer)
1508 (concat "\"" answer "\"") answer)))
1509 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1512 (defun mime-prompt-for-encoding (default)
1513 "Ask for Content-Transfer-Encoding."
1518 "What transfer encoding: "
1519 mime-file-encoding-method-alist nil t default)
1525 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1528 (defvar mime-edit-translate-buffer-hook
1529 '(mime-edit-pgp-enclose-buffer
1530 mime-edit-translate-body
1531 mime-edit-translate-header))
1533 (defun mime-edit-translate-header ()
1534 "Encode the message header into network representation."
1535 (eword-encode-header 'code-conversion)
1536 (run-hooks 'mime-edit-translate-header-hook)
1539 (defun mime-edit-translate-buffer ()
1540 "Encode the tagged MIME message in current buffer in MIME compliant message."
1542 (if (catch 'mime-edit-error
1544 (run-hooks 'mime-edit-translate-buffer-hook)
1548 (error "Translation error!")
1551 (defun mime-edit-find-inmost ()
1552 (goto-char (point-min))
1553 (if (re-search-forward mime-edit-multipart-beginning-regexp nil t)
1554 (let ((bb (match-beginning 0))
1556 (type (buffer-substring (match-beginning 1)(match-end 1)))
1558 (setq end-exp (format "--}-<<%s>>\n" type))
1560 (if (re-search-forward end-exp nil t)
1561 (setq eb (match-beginning 0))
1562 (setq eb (point-max))
1564 (narrow-to-region be eb)
1566 (if (re-search-forward mime-edit-multipart-beginning-regexp nil t)
1568 (narrow-to-region (match-beginning 0)(point-max))
1569 (mime-edit-find-inmost)
1572 (list type bb be eb)
1575 (defun mime-edit-process-multipart-1 (boundary)
1576 (let ((ret (mime-edit-find-inmost)))
1578 (let ((type (car ret))
1579 (bb (nth 1 ret))(be (nth 2 ret))
1582 (narrow-to-region bb eb)
1583 (delete-region bb be)
1584 (setq bb (point-min))
1585 (setq eb (point-max))
1588 (if (looking-at mime-edit-multipart-end-regexp)
1589 (let ((beg (match-beginning 0))
1592 (delete-region beg end)
1593 (or (looking-at mime-edit-beginning-tag-regexp)
1595 (insert (concat (mime-make-text-tag) "\n"))
1597 (cond ((string-equal type "quote")
1598 (mime-edit-enquote-region bb eb)
1600 ((string-equal type "pgp-signed")
1601 (mime-edit-sign-pgp-mime bb eb boundary)
1603 ((string-equal type "pgp-encrypted")
1604 (mime-edit-encrypt-pgp-mime bb eb boundary)
1606 ((string-equal type "kazu-signed")
1607 (mime-edit-sign-pgp-kazu bb eb boundary)
1609 ((string-equal type "kazu-encrypted")
1610 (mime-edit-encrypt-pgp-kazu bb eb boundary)
1614 (nth 2 (mime-edit-translate-region bb eb
1618 (format "--[[multipart/%s;
1619 boundary=\"%s\"][7bit]]\n"
1624 (defun mime-edit-enquote-region (beg end)
1627 (narrow-to-region beg end)
1629 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1630 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1631 (replace-match (concat "- " (substring tag 1)))
1634 (defun mime-edit-dequote-region (beg end)
1637 (narrow-to-region beg end)
1639 (while (re-search-forward
1640 mime-edit-quoted-single-part-tag-regexp nil t)
1641 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1642 (replace-match (concat "-" (substring tag 2)))
1645 (defun mime-edit-sign-pgp-mime (beg end boundary)
1648 (narrow-to-region beg end)
1650 (mime-edit-translate-region beg end boundary))
1652 (encoding (nth 1 ret))
1653 (pgp-boundary (concat "pgp-sign-" boundary)))
1655 (insert (format "Content-Type: %s\n" ctype))
1657 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1660 (or (as-binary-process
1661 (funcall (pgp-function 'mime-sign)
1662 (point-min)(point-max) nil nil pgp-boundary))
1663 (throw 'mime-edit-error 'pgp-error)
1667 (defvar mime-edit-encrypt-recipient-fields-list '("To" "cc"))
1669 (defun mime-edit-make-encrypt-recipient-header ()
1670 (let* ((names mime-edit-encrypt-recipient-fields-list)
1672 (std11-field-bodies (cons "From" names)
1673 nil mail-header-separator))
1676 (setq values (cdr values))))
1677 (header (and (stringp from)
1678 (if (string-equal from "")
1680 (format "From: %s\n" from)
1683 (while (and names values)
1684 (let ((name (car names))
1685 (value (car values))
1687 (and (stringp value)
1688 (or (string-equal value "")
1690 (setq header (concat header name ": " value "\n")
1691 recipients (if recipients
1692 (concat recipients " ," value)
1695 (setq names (cdr names)
1696 values (cdr values))
1698 (vector from recipients header)
1701 (defun mime-edit-encrypt-pgp-mime (beg end boundary)
1704 (let (from recipients header)
1705 (let ((ret (mime-edit-make-encrypt-recipient-header)))
1706 (setq from (aref ret 0)
1707 recipients (aref ret 1)
1708 header (aref ret 2))
1710 (narrow-to-region beg end)
1712 (mime-edit-translate-region beg end boundary))
1714 (encoding (nth 1 ret))
1715 (pgp-boundary (concat "pgp-" boundary)))
1718 (insert (format "Content-Type: %s\n" ctype))
1720 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1723 (or (funcall (pgp-function 'encrypt)
1724 recipients (point-min) (point-max) from)
1725 (throw 'mime-edit-error 'pgp-error)
1728 (insert (format "--[[multipart/encrypted;
1730 protocol=\"application/pgp-encrypted\"][7bit]]
1732 Content-Type: application/pgp-encrypted
1735 Content-Type: application/octet-stream
1736 Content-Transfer-Encoding: 7bit
1738 " pgp-boundary pgp-boundary pgp-boundary))
1739 (goto-char (point-max))
1740 (insert (format "\n--%s--\n" pgp-boundary))
1743 (defun mime-edit-sign-pgp-kazu (beg end boundary)
1746 (narrow-to-region beg end)
1748 (mime-edit-translate-region beg end boundary))
1750 (encoding (nth 1 ret)))
1752 (insert (format "Content-Type: %s\n" ctype))
1754 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1757 (or (as-binary-process
1758 (funcall (pgp-function 'traditional-sign)
1760 (throw 'mime-edit-error 'pgp-error)
1764 "--[[application/pgp; format=mime][7bit]]\n")
1768 (defun mime-edit-encrypt-pgp-kazu (beg end boundary)
1770 (let (recipients header)
1771 (let ((ret (mime-edit-make-encrypt-recipient-header)))
1772 (setq recipients (aref ret 1)
1773 header (aref ret 2))
1776 (narrow-to-region beg end)
1778 (mime-edit-translate-region beg end boundary))
1780 (encoding (nth 1 ret)))
1783 (insert (format "Content-Type: %s\n" ctype))
1785 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1788 (or (as-binary-process
1789 (funcall (pgp-function 'encrypt)
1790 recipients beg (point-max) nil 'maybe)
1792 (throw 'mime-edit-error 'pgp-error)
1796 "--[[application/pgp; format=mime][7bit]]\n")
1800 (defsubst replace-space-with-underline (str)
1801 (mapconcat (function
1809 (defun mime-edit-make-boundary ()
1810 (concat mime-multipart-boundary "_"
1811 (replace-space-with-underline (current-time-string))
1814 (defun mime-edit-translate-body ()
1815 "Encode the tagged MIME body in current buffer in MIME compliant message."
1818 (let ((boundary (mime-edit-make-boundary))
1821 (while (mime-edit-process-multipart-1
1822 (format "%s-%d" boundary i))
1826 ;; We are interested in message body.
1829 (goto-char (point-min))
1831 (concat "\n" (regexp-quote mail-header-separator)
1832 (if mime-ignore-preceding-spaces
1833 "[ \t\n]*\n" "\n")) nil 'move)
1837 (goto-char (point-max))
1838 (and mime-ignore-trailing-spaces
1839 (re-search-backward "[^ \t\n]\n" beg t)
1842 (setq ret (mime-edit-translate-region
1844 (format "%s-%d" boundary i)))
1846 (mime-edit-dequote-region (point-min)(point-max))
1847 (let ((contype (car ret)) ;Content-Type
1848 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1850 ;; Insert X-Emacs field
1851 (and mime-edit-insert-x-emacs-field
1852 (or (mail-position-on-field "X-Emacs")
1853 (insert mime-edit-x-emacs-value)
1855 ;; Make primary MIME headers.
1856 (or (mail-position-on-field "MIME-Version")
1857 (insert mime-edit-mime-version-value))
1858 ;; Remove old Content-Type and other fields.
1860 (goto-char (point-min))
1861 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1862 (narrow-to-region (point-min) (point))
1863 (goto-char (point-min))
1864 (mime-delete-field "Content-Type")
1865 (mime-delete-field "Content-Transfer-Encoding"))
1866 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1867 (mail-position-on-field "Content-Type")
1871 (mail-position-on-field "Content-Transfer-Encoding")
1875 (defun mime-edit-translate-single-part-tag (boundary &optional prefix)
1876 "Translate single-part-tag to MIME header."
1877 (if (re-search-forward mime-edit-single-part-tag-regexp nil t)
1878 (let* ((beg (match-beginning 0))
1880 (tag (buffer-substring beg end)))
1881 (delete-region beg end)
1882 (let ((contype (mime-edit-get-contype tag))
1883 (encoding (mime-edit-get-encoding tag)))
1884 (insert (concat prefix "--" boundary "\n"))
1886 (narrow-to-region (point)(point))
1887 (insert "Content-Type: " contype "\n")
1889 (insert "Content-Transfer-Encoding: " encoding "\n"))
1890 (eword-encode-header)
1894 (defun mime-edit-translate-region (beg end &optional boundary multipart)
1896 (setq boundary (mime-edit-make-boundary))
1900 (narrow-to-region beg end)
1901 (let ((tag nil) ;MIME tag
1902 (contype nil) ;Content-Type
1903 (encoding nil) ;Content-Transfer-Encoding
1904 (nparts 0)) ;Number of body parts
1905 ;; Normalize the body part by inserting appropriate message
1906 ;; tags for every message contents.
1907 (mime-edit-normalize-body)
1908 ;; Counting the number of Content-Type.
1909 (goto-char (point-min))
1910 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1911 (setq nparts (1+ nparts)))
1912 ;; Begin translation.
1914 ((and (<= nparts 1)(not multipart))
1915 ;; It's a singular message.
1916 (goto-char (point-min))
1917 (while (re-search-forward
1918 mime-edit-single-part-tag-regexp nil t)
1920 (buffer-substring (match-beginning 0) (match-end 0)))
1921 (delete-region (match-beginning 0) (1+ (match-end 0)))
1922 (setq contype (mime-edit-get-contype tag))
1923 (setq encoding (mime-edit-get-encoding tag))
1926 ;; It's a multipart message.
1927 (goto-char (point-min))
1928 (and (mime-edit-translate-single-part-tag boundary)
1929 (while (mime-edit-translate-single-part-tag boundary "\n")))
1930 ;; Define Content-Type as "multipart/mixed".
1932 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1933 ;; Content-Transfer-Encoding must be "7bit".
1934 ;; The following encoding can be `nil', but is
1935 ;; specified as is since there is no way that a user
1937 (setq encoding "7bit")
1938 ;; Insert the trailer.
1939 (goto-char (point-max))
1940 (insert "\n--" boundary "--\n")
1942 (list contype encoding boundary nparts)
1945 (defun mime-edit-normalize-body ()
1946 "Normalize the body part by inserting appropriate message tags."
1947 ;; Insert the first MIME tags if necessary.
1948 (goto-char (point-min))
1949 (if (not (looking-at mime-edit-single-part-tag-regexp))
1950 (insert (mime-make-text-tag) "\n"))
1951 ;; Check each tag, and add new tag or correct it if necessary.
1952 (goto-char (point-min))
1953 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1954 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1955 (contype (mime-edit-get-contype tag))
1956 (charset (mime-get-parameter contype "charset"))
1957 (encoding (mime-edit-get-encoding tag)))
1958 ;; Remove extra whitespaces after the tag.
1959 (if (looking-at "[ \t]+$")
1960 (delete-region (match-beginning 0) (match-end 0)))
1962 (end (mime-edit-content-end))
1964 (if (= end (point-max))
1967 (or (looking-at mime-edit-beginning-tag-regexp)
1969 (insert (mime-make-text-tag) "\n")
1971 (visible-region beg end)
1975 ((mime-test-content-type contype "message")
1976 ;; Content-type "message" should be sent as is.
1979 ((mime-test-content-type contype "text")
1980 ;; Define charset for text if necessary.
1981 (setq charset (if charset
1982 (intern (downcase charset))
1983 (mime-edit-choose-charset)))
1984 (mime-edit-define-charset charset)
1985 (cond ((string-equal contype "text/x-rot13-47-48")
1988 (mule-caesar-region (point) (mime-edit-content-end))
1990 ((string-equal contype "text/enriched")
1995 (end (mime-edit-content-end))
1997 ;; Patch for hard newlines
2000 ;; (while (search-forward "\n" end t)
2001 ;; (put-text-property (match-beginning 0)
2004 ;; End patch for hard newlines
2005 (enriched-encode beg end)
2007 (if (search-forward "\n\n")
2008 (delete-region beg (match-end 0))
2011 ;; Point is now on current tag.
2012 ;; Define encoding and encode text if necessary.
2013 (or encoding ;Encoding is not specified.
2016 (let ((ret (cdr (assq charset mime-charset-type-list))))
2018 (setq bits (car ret)
2021 conv "quoted-printable")))
2022 (if (<= bits mime-transfer-level)
2023 (mime-encoding-name bits)
2025 (beg (mime-edit-content-beginning)))
2026 (encode-mime-charset-region beg (mime-edit-content-end)
2028 ;; Protect "From " in beginning of line
2030 (narrow-to-region beg (mime-edit-content-end))
2032 (let (case-fold-search)
2033 (if (re-search-forward "^From " nil t)
2035 (if (memq charset '(iso-2022-jp
2040 (replace-match "\e(BFrom ")
2041 (re-search-forward "^From " nil t)
2043 (setq encoding "quoted-printable")
2045 ;; canonicalize line break code
2046 (or (member encoding '(nil "7bit" "8bit" "quoted-printable"))
2048 (narrow-to-region beg (mime-edit-content-end))
2050 (while (re-search-forward "\\([^\r]\\)\n" nil t)
2052 (concat (buffer-substring (match-beginning 0)
2053 (match-end 1)) "\r\n"))
2056 (mime-encode-region beg (mime-edit-content-end) encoding)
2057 (mime-edit-define-encoding encoding)
2059 (goto-char (mime-edit-content-end))
2061 ((null encoding) ;Encoding is not specified.
2062 ;; Application, image, audio, video, and any other
2063 ;; unknown content-type without encoding should be
2065 (let* ((encoding "base64") ;Encode in BASE64 by default.
2066 (beg (mime-edit-content-beginning))
2067 (end (mime-edit-content-end)))
2068 (mime-encode-region beg end encoding)
2069 (mime-edit-define-encoding encoding))
2074 (defun mime-delete-field (field)
2075 "Delete header FIELD."
2076 (let ((regexp (format "^%s:[ \t]*" field)))
2077 (goto-char (point-min))
2078 (while (re-search-forward regexp nil t)
2079 (delete-region (match-beginning 0)
2080 (progn (forward-line 1) (point)))
2085 ;;; Platform dependent functions
2088 ;; Sun implementations
2090 (defun mime-edit-voice-recorder-for-sun (encoding)
2091 "Record voice in a buffer using Sun audio device,
2092 and insert data encoded as ENCODING."
2093 (message "Start the recording on %s. Type C-g to finish the recording..."
2095 (mime-insert-encoded-file "/dev/audio" encoding)
2099 ;;; @ Other useful commands.
2102 ;; Message forwarding commands as content-type "message/rfc822".
2104 (defun mime-edit-insert-message (&optional message)
2106 (let ((inserter (cdr (assq major-mode mime-edit-message-inserter-alist))))
2107 (if (and inserter (fboundp inserter))
2109 (mime-edit-insert-tag "message" "rfc822")
2110 (funcall inserter message)
2112 (message "Sorry, I don't have message inserter for your MUA.")
2115 (defun mime-edit-insert-mail (&optional message)
2117 (let ((inserter (cdr (assq major-mode mime-edit-mail-inserter-alist))))
2118 (if (and inserter (fboundp inserter))
2120 (mime-edit-insert-tag "message" "rfc822")
2121 (funcall inserter message)
2123 (message "Sorry, I don't have mail inserter for your MUA.")
2126 (defun mime-edit-inserted-message-filter ()
2129 (let ((header-start (point))
2130 (case-fold-search t)
2133 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2134 (if (re-search-forward "^$" (mark t))
2135 (narrow-to-region header-start (match-beginning 0))
2137 (goto-char header-start)
2138 (while (and (re-search-forward
2139 mime-edit-yank-ignored-field-regexp nil t)
2140 (setq beg (match-beginning 0))
2141 (setq end (1+ (std11-field-end)))
2143 (delete-region beg end)
2148 ;;; @ multipart enclosure
2151 (defun mime-edit-enclose-region-internal (type beg end)
2155 (narrow-to-region beg end)
2156 (insert (format "--<<%s>>-{\n" type))
2157 (goto-char (point-max))
2158 (insert (format "--}-<<%s>>\n" type))
2159 (goto-char (point-max))
2161 (or (looking-at mime-edit-beginning-tag-regexp)
2163 (insert (mime-make-text-tag) "\n")
2167 (defun mime-edit-enclose-quote-region (beg end)
2169 (mime-edit-enclose-region-internal 'quote beg end)
2172 (defun mime-edit-enclose-mixed-region (beg end)
2174 (mime-edit-enclose-region-internal 'mixed beg end)
2177 (defun mime-edit-enclose-parallel-region (beg end)
2179 (mime-edit-enclose-region-internal 'parallel beg end)
2182 (defun mime-edit-enclose-digest-region (beg end)
2184 (mime-edit-enclose-region-internal 'digest beg end)
2187 (defun mime-edit-enclose-alternative-region (beg end)
2189 (mime-edit-enclose-region-internal 'alternative beg end)
2192 (defun mime-edit-enclose-pgp-signed-region (beg end)
2194 (mime-edit-enclose-region-internal 'pgp-signed beg end)
2197 (defun mime-edit-enclose-pgp-encrypted-region (beg end)
2199 (mime-edit-enclose-region-internal 'pgp-encrypted beg end)
2202 (defun mime-edit-enclose-kazu-signed-region (beg end)
2204 (mime-edit-enclose-region-internal 'kazu-signed beg end)
2207 (defun mime-edit-enclose-kazu-encrypted-region (beg end)
2209 (mime-edit-enclose-region-internal 'kazu-encrypted beg end)
2212 (defun mime-edit-insert-key (&optional arg)
2213 "Insert a pgp public key."
2215 (mime-edit-insert-tag "application" "pgp-keys")
2216 (mime-edit-define-encoding "7bit")
2217 (funcall (pgp-function 'insert-key))
2224 (defun mime-edit-set-split (arg)
2227 (y-or-n-p "Do you want to enable split? ")
2229 (setq mime-edit-split-message arg)
2231 (message "This message is enabled to split.")
2232 (message "This message is not enabled to split.")
2235 (defun mime-edit-toggle-transfer-level (&optional transfer-level)
2236 "Toggle transfer-level is 7bit or 8bit through.
2238 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2240 (if (numberp transfer-level)
2241 (setq mime-transfer-level transfer-level)
2242 (if (< mime-transfer-level 8)
2243 (setq mime-transfer-level 8)
2244 (setq mime-transfer-level 7)
2246 (message (format "Current transfer-level is %d bit"
2247 mime-transfer-level))
2248 (setq mime-transfer-level-string
2249 (mime-encoding-name mime-transfer-level 'not-omit))
2250 (force-mode-line-update)
2253 (defun mime-edit-set-transfer-level-7bit ()
2255 (mime-edit-toggle-transfer-level 7)
2258 (defun mime-edit-set-transfer-level-8bit ()
2260 (mime-edit-toggle-transfer-level 8)
2267 (defvar mime-edit-pgp-processing nil)
2268 (make-variable-buffer-local 'mime-edit-pgp-processing)
2270 (defun mime-edit-set-sign (arg)
2273 (y-or-n-p "Do you want to sign? ")
2277 (setq mime-edit-pgp-processing 'sign)
2278 (message "This message will be signed.")
2280 (if (eq mime-edit-pgp-processing 'sign)
2281 (setq mime-edit-pgp-processing nil)
2283 (message "This message will not be signed.")
2286 (defun mime-edit-set-encrypt (arg)
2289 (y-or-n-p "Do you want to encrypt? ")
2293 (setq mime-edit-pgp-processing 'encrypt)
2294 (message "This message will be encrypt.")
2296 (if (eq mime-edit-pgp-processing 'encrypt)
2297 (setq mime-edit-pgp-processing nil)
2299 (message "This message will not be encrypt.")
2302 (defun mime-edit-pgp-enclose-buffer ()
2303 (let ((beg (save-excursion
2304 (goto-char (point-min))
2305 (if (search-forward (concat "\n" mail-header-separator "\n"))
2311 (cond ((eq mime-edit-pgp-processing 'sign)
2312 (mime-edit-enclose-pgp-signed-region beg end)
2314 ((eq mime-edit-pgp-processing 'encrypt)
2315 (mime-edit-enclose-pgp-encrypted-region beg end)
2323 (defun mime-edit-insert-partial-header (fields subject
2324 id number total separator)
2326 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2327 (insert mime-edit-mime-version-field-for-message/partial)
2329 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2330 id number total separator))
2333 (defun mime-edit-split-and-send
2334 (&optional cmd lines mime-edit-message-max-length)
2338 (count-lines (point-min) (point-max)))
2340 (or mime-edit-message-max-length
2341 (setq mime-edit-message-max-length
2342 (or (cdr (assq major-mode mime-edit-message-max-lines-alist))
2343 mime-edit-message-default-max-lines))
2345 (let* ((mime-edit-draft-file-name
2346 (or (buffer-file-name)
2348 (expand-file-name "mime-draft" mime-temp-directory))))
2349 (separator mail-header-separator)
2351 (replace-space-with-underline (current-time-string))
2352 "@" (system-name) "\"")))
2353 (run-hooks 'mime-edit-before-split-hook)
2354 (let ((the-buf (current-buffer))
2355 (copy-buf (get-buffer-create " *Original Message*"))
2356 (header (std11-header-string-except
2357 mime-edit-split-ignored-field-regexp separator))
2358 (subject (mail-fetch-field "subject"))
2359 (total (+ (/ lines mime-edit-message-max-length)
2360 (if (> (mod lines mime-edit-message-max-length) 0)
2366 mime-edit-split-message-sender-alist))
2370 (error "Split sender is not specified for `%s'." major-mode)
2373 (mime-edit-partial-number 1)
2376 (set-buffer copy-buf)
2378 (insert-buffer the-buf)
2380 (if (re-search-forward
2381 (concat "^" (regexp-quote separator) "$") nil t)
2382 (let ((he (match-beginning 0)))
2384 (narrow-to-region (point-min) he)
2386 (goto-char (point-min))
2387 (while (re-search-forward mime-edit-split-blind-field-regexp nil t)
2388 (delete-region (match-beginning 0)
2389 (1+ (std11-field-end)))
2391 (while (< mime-edit-partial-number total)
2394 (set-buffer copy-buf)
2395 (setq data (buffer-substring
2398 (goto-line mime-edit-message-max-length)
2401 (delete-region (point-min)(point))
2403 (mime-edit-insert-partial-header
2404 header subject id mime-edit-partial-number total separator)
2407 (message (format "Sending %d/%d..."
2408 mime-edit-partial-number total))
2409 (call-interactively command)
2410 (message (format "Sending %d/%d... done"
2411 mime-edit-partial-number total))
2413 (setq mime-edit-partial-number
2414 (1+ mime-edit-partial-number))
2418 (set-buffer copy-buf)
2419 (setq data (buffer-string))
2422 (mime-edit-insert-partial-header
2423 header subject id mime-edit-partial-number total separator)
2426 (message (format "Sending %d/%d..."
2427 mime-edit-partial-number total))
2428 (message (format "Sending %d/%d... done"
2429 mime-edit-partial-number total))
2433 (defun mime-edit-maybe-split-and-send (&optional cmd)
2435 (run-hooks 'mime-edit-before-send-hook)
2436 (let ((mime-edit-message-max-length
2437 (or (cdr (assq major-mode mime-edit-message-max-lines-alist))
2438 mime-edit-message-default-max-lines))
2439 (lines (count-lines (point-min) (point-max)))
2441 (if (and (> lines mime-edit-message-max-length)
2442 mime-edit-split-message)
2443 (mime-edit-split-and-send cmd lines mime-edit-message-max-length)
2447 ;;; @ preview message
2450 (defvar mime-edit-buffer nil) ; buffer local variable
2452 (defun mime-edit-preview-message ()
2453 "preview editing MIME message."
2455 (let* ((str (buffer-string))
2456 (separator mail-header-separator)
2457 (the-buf (current-buffer))
2458 (buf-name (buffer-name))
2459 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2460 (buf (get-buffer temp-buf-name))
2464 (switch-to-buffer buf)
2467 (setq buf (get-buffer-create temp-buf-name))
2468 (switch-to-buffer buf)
2471 (setq major-mode 'mime-temp-message-mode)
2472 (make-local-variable 'mail-header-separator)
2473 (setq mail-header-separator separator)
2474 (make-local-variable 'mime-edit-buffer)
2475 (setq mime-edit-buffer the-buf)
2477 (run-hooks 'mime-edit-translate-hook)
2478 (mime-edit-translate-buffer)
2479 (goto-char (point-min))
2480 (if (re-search-forward
2481 (concat "^" (regexp-quote separator) "$"))
2487 (defun mime-edit-quitting-method ()
2488 "Quitting method for mime-view."
2489 (let ((temp mime-raw-buffer)
2491 (mime-preview-kill-buffer)
2493 (setq buf mime-edit-buffer)
2495 (switch-to-buffer buf)
2498 (set-alist 'mime-preview-quitting-method-alist
2499 'mime-temp-message-mode
2500 #'mime-edit-quitting-method)
2506 (defvar mime-edit-again-ignored-field-regexp
2507 (concat "^\\(" "Content-.*\\|Mime-Version"
2508 (if mime-edit-insert-x-emacs-field "\\|X-Emacs")
2510 "Regexp for deleted header fields when `mime-edit-again' is called.")
2512 (defun mime-edit-decode-buffer (not-decode-text)
2514 (goto-char (point-min))
2515 (let ((ctl (mime-read-Content-Type)))
2517 (let ((type (mime-content-type-primary-type ctl))
2518 (stype (mime-content-type-subtype ctl))
2519 (params (mime-content-type-parameters ctl)))
2521 ((and (eq type 'application)(eq stype 'pgp-signature))
2522 (delete-region (point-min)(point-max))
2524 ((eq type 'multipart)
2525 (let* ((boundary (cdr (assoc "boundary" params)))
2527 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2529 (re-search-forward boundary-pat nil t)
2530 (let ((bb (match-beginning 0)) eb tag)
2531 (setq tag (format "\n--<<%s>>-{\n" stype))
2534 (setq bb (+ bb (length tag)))
2536 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2538 (setq eb (match-beginning 0))
2539 (replace-match (format "--}-<<%s>>\n" stype))
2541 (narrow-to-region bb eb)
2542 (goto-char (point-min))
2543 (while (re-search-forward boundary-pat nil t)
2544 (let ((beg (match-beginning 0))
2546 (delete-region beg (match-end 0))
2548 (if (re-search-forward boundary-pat nil t)
2549 (setq end (match-beginning 0))
2550 (setq end (point-max))
2553 (narrow-to-region beg end)
2554 (mime-edit-decode-buffer not-decode-text)
2555 (goto-char (point-max))
2558 (goto-char (point-min))
2559 (or (= (point-min) 1)
2560 (delete-region (point-min)
2561 (if (search-forward "\n\n" nil t)
2567 (let* ((ctype (format "%s/%s" type stype))
2570 (let ((bytes (+ 14 (length ctype))))
2571 (mapconcat (function
2573 (if (string= (car attr) "charset")
2575 (setq charset (cdr attr))
2583 (setq bytes (+ bytes bs 2))
2586 (setq bytes (+ bs 1))
2594 (if (re-search-forward
2595 "Content-Transfer-Encoding:" nil t)
2596 (let ((beg (match-beginning 0))
2597 (hbeg (match-end 0))
2598 (end (std11-field-end)))
2600 (eliminate-top-spaces
2601 (std11-unfold-string
2602 (buffer-substring hbeg end))))
2603 (if (or charset (eq type 'text))
2605 (delete-region beg (1+ end))
2606 (goto-char (point-min))
2607 (if (search-forward "\n\n" nil t)
2610 (match-end 0)(point-max) encoding)
2614 (if (or encoded (not not-decode-text))
2615 (decode-mime-charset-region
2616 (point-min)(point-max)
2617 (or charset default-mime-charset))
2620 (if (re-search-forward "^$" nil t)
2624 (if (= (point-min) 1)
2630 (format "%s/%s%s" type stype pstr)
2633 (delete-region (point-min) he)
2636 (format "%s/%s%s" type stype pstr)
2641 (decode-mime-charset-region (point-min) (point-max)
2642 default-mime-charset)
2646 (defun mime-edit-again (&optional not-decode-text no-separator not-turn-on)
2647 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode.
2648 Content-Type and Content-Transfer-Encoding header fields will be
2649 converted to MIME-Edit tags."
2651 (goto-char (point-min))
2653 (concat "\n" (regexp-quote mail-header-separator) "\n")
2655 (replace-match "\n\n")
2657 (mime-edit-decode-buffer not-decode-text)
2658 (goto-char (point-min))
2660 (std11-narrow-to-header)
2661 (goto-char (point-min))
2662 (while (re-search-forward mime-edit-again-ignored-field-regexp nil t)
2663 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2666 (and (re-search-forward "^$")
2667 (replace-match mail-header-separator)
2677 (provide 'mime-edit)
2679 (run-hooks 'mime-edit-load-hook)
2681 ;;; mime-edit.el ends here