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)
122 (defconst mime-edit-version-string
123 `,(concat (car mime-user-interface-version) " "
124 (mapconcat #'number-to-string
125 (cddr mime-user-interface-version) ".")
126 " - \"" (cadr mime-user-interface-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")
198 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
199 ("directory" "/pub/GNU/elisp/mime")
201 ("mode" "image" "ascii" "local8"))
206 ("mode" "image" "ascii" "local8"))
207 ("tftp" ("site") ("name"))
208 ("afs" ("site") ("name"))
209 ("local-file" ("site") ("name"))
211 ("server" "ftpmail@nic.karrn.ad.jp")
219 ("octet-stream" ("type" "" "tar" "shar"))
221 ("x-kiss" ("x-cnf")))
235 "*Alist of content-type, subtype, parameters and its values.")
237 (defcustom mime-file-types
241 "inline" (("filename" . file))
246 "inline" (("filename" . file))
249 "text" "richtext" nil
257 "application" "postscript" nil
259 "attachment" (("filename" . file))
264 "inline" (("filename" . file))
269 "inline" (("filename" . file))
274 "inline" (("filename" . file))
279 "inline" (("filename" . file))
284 "inline" (("filename" . file))
289 "inline" (("filename" . file))
294 "inline" (("filename" . file))
299 "inline" (("filename" . file))
304 "attachment" (("filename" . file))
309 "attachment" (("filename" . file))
312 "application" "octet-stream" (("type" . "emacs-lisp"))
314 "attachment" (("filename" . file))
317 "application" "octet-stream" (("type" . "common-lisp"))
319 "attachment" (("filename" . file))
322 "application" "octet-stream" (("type" . "tar+gzip"))
324 "attachment" (("filename" . file))
327 "application" "octet-stream" (("type" . "tar+gzip"))
329 "attachment" (("filename" . file))
332 "application" "octet-stream" (("type" . "tar+compress"))
334 "attachment" (("filename" . file))
337 "application" "octet-stream" (("type" . "tar+compress"))
339 "attachment" (("filename" . file))
342 "application" "octet-stream" (("type" . "gzip"))
344 "attachment" (("filename" . file))
347 "application" "octet-stream" (("type" . "compress"))
349 "attachment" (("filename" . file))
352 "application" "octet-stream" (("type" . "lha"))
354 "attachment" (("filename" . file))
357 "application" "zip" nil
359 "attachment" (("filename" . file))
362 "application" "octet-stream" (("type" . "patch"))
364 "attachment" (("filename" . file))
367 "application" "octet-stream" (("type" . "patch"))
369 "attachment" (("filename" . file))
372 "text" "plain" nil nil nil nil)
374 "application" "octet-stream" nil
376 "attachment" (("filename" . file)))
378 "*Alist of file name, types, parameters, and default encoding.
379 If encoding is nil, it is determined from its contents."
383 (choice :tag "Primary-Type"
384 ,@(nconc (mapcar (lambda (cell)
385 (list 'item (car cell))
390 (choice :tag "Sub-Type"
393 (mapcar (lambda (cell)
394 (mapcar (lambda (cell)
395 (list 'item (car cell))
401 (repeat :tag "Parameters of Content-Type field"
402 (cons string (choice string symbol)))
403 ;; content-transfer-encoding
404 (choice :tag "Encoding"
407 (mapcar (lambda (cell)
408 (list 'item (car cell))
410 mime-file-encoding-method-alist)))
412 (choice :tag "Disposition-Type"
418 (repeat :tag "Parameters of Content-Disposition field"
419 (cons string (choice string symbol)))
424 ;;; @@ about charset, encoding and transfer-level
427 (defvar mime-charset-type-list
429 (iso-8859-1 8 "quoted-printable")
430 (iso-8859-2 8 "quoted-printable")
431 (iso-8859-3 8 "quoted-printable")
432 (iso-8859-4 8 "quoted-printable")
433 (iso-8859-5 8 "quoted-printable")
434 (koi8-r 8 "quoted-printable")
435 (iso-8859-7 8 "quoted-printable")
436 (iso-8859-8 8 "quoted-printable")
437 (iso-8859-9 8 "quoted-printable")
438 (iso-2022-jp 7 "base64")
439 (iso-2022-kr 7 "base64")
441 (cn-gb2312 8 "base64")
445 (shift_jis 8 "base64")
446 (iso-2022-jp-2 7 "base64")
447 (iso-2022-int-1 7 "base64")
450 (defvar mime-transfer-level 7
451 "*A number of network transfer level. It should be bigger than 7.")
452 (make-variable-buffer-local 'mime-transfer-level)
454 (defsubst mime-encoding-name (transfer-level &optional not-omit)
455 (cond ((> transfer-level 8) "binary")
456 ((= transfer-level 8) "8bit")
460 (defvar mime-transfer-level-string
461 (mime-encoding-name mime-transfer-level 'not-omit)
462 "A string formatted version of mime-transfer-level")
463 (make-variable-buffer-local 'mime-transfer-level-string)
466 ;;; @@ about message inserting
469 (defvar mime-edit-yank-ignored-field-list
470 '("Received" "Approved" "Path" "Replied" "Status"
471 "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
472 "Delete these fields from original message when it is inserted
473 as message/rfc822 part.
474 Each elements are regexp of field-name.")
476 (defvar mime-edit-yank-ignored-field-regexp
478 (apply (function regexp-or) mime-edit-yank-ignored-field-list)
481 (defvar mime-edit-message-inserter-alist nil)
482 (defvar mime-edit-mail-inserter-alist nil)
485 ;;; @@ about message splitting
488 (defcustom mime-edit-split-message t
489 "*Split large message if it is non-nil."
493 (defcustom mime-edit-message-default-max-lines 1000
494 "*Default maximum lines of a message."
498 (defcustom mime-edit-message-max-lines-alist
499 '((news-reply-mode . 500))
500 "Alist of major-mode vs maximum lines of a message.
501 If it is not specified for a major-mode,
502 `mime-edit-message-default-max-lines' is used."
506 (defconst mime-edit-split-ignored-field-regexp
507 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\|Message-Id:\\)")
509 (defcustom mime-edit-split-blind-field-regexp
510 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)"
511 "*Regular expression to match field-name to be ignored when split sending."
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-user-agent-field t
565 "*If non-nil, insert User-Agent header field.")
567 (defvar mime-edit-user-agent-value
568 (concat (car mime-user-interface-version)
570 (mapconcat #'number-to-string
571 (cddr mime-user-interface-version) ".")
573 (cadr mime-user-interface-version)
575 (car mime-library-version)
577 (mapconcat #'number-to-string
578 (cddr mime-library-version) ".")
580 (cadr mime-library-version)
582 (if (featurep 'xemacs)
584 (if (string-match "\\s +\\\"" emacs-version)
586 (substring emacs-version 0
588 " (" xemacs-codename ")")
589 " (" emacs-version ")")
590 (if (featurep 'mule) " MULE"))
591 (let ((ver (if (string-match "\\.[0-9]+$" emacs-version)
592 (substring emacs-version 0 (match-beginning 0))
595 (if (boundp 'enable-multibyte-characters)
597 (if enable-multibyte-characters
598 (concat " MULE/" mule-version)
599 " (with unibyte mode)")
600 (if (featurep 'meadow)
601 (let ((mver (Meadow-version)))
602 (if (string-match "^Meadow-" mver)
607 (concat "MULE/" mule-version
608 " (based on Emacs " ver ")"))
610 "Body of User-Agent field.
611 If variable `mime-edit-insert-user-agent-field' is not nil, it is
612 inserted into message header.")
618 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
619 "*Specify MIME tspecials.
620 Tspecials means any character that matches with it in header must be quoted.")
622 (defconst mime-edit-mime-version-value
623 (concat "1.0 (generated by " mime-edit-version-string ")")
624 "MIME version number.")
626 (defconst mime-edit-mime-version-field-for-message/partial
627 (concat "MIME-Version: 1.0 (split by " mime-edit-version-string ")\n")
628 "MIME version field for message/partial.")
631 ;;; @ keymap and menu
634 (defvar mime-edit-mode-flag nil)
635 (make-variable-buffer-local 'mime-edit-mode-flag)
637 (defvar mime-edit-mode-entity-prefix "\C-c\C-x"
638 "Keymap prefix for MIME-Edit mode commands to insert entity or set status.")
639 (defvar mime-edit-mode-entity-map (make-sparse-keymap)
640 "Keymap for MIME-Edit mode commands to insert entity or set status.")
642 (define-key mime-edit-mode-entity-map "\C-t" 'mime-edit-insert-text)
643 (define-key mime-edit-mode-entity-map "\C-i" 'mime-edit-insert-file)
644 (define-key mime-edit-mode-entity-map "\C-e" 'mime-edit-insert-external)
645 (define-key mime-edit-mode-entity-map "\C-v" 'mime-edit-insert-voice)
646 (define-key mime-edit-mode-entity-map "\C-y" 'mime-edit-insert-message)
647 (define-key mime-edit-mode-entity-map "\C-m" 'mime-edit-insert-mail)
648 (define-key mime-edit-mode-entity-map "\C-w" 'mime-edit-insert-signature)
649 (define-key mime-edit-mode-entity-map "\C-s" 'mime-edit-insert-signature)
650 (define-key mime-edit-mode-entity-map "\C-k" 'mime-edit-insert-key)
651 (define-key mime-edit-mode-entity-map "t" 'mime-edit-insert-tag)
653 (define-key mime-edit-mode-entity-map "7" 'mime-edit-set-transfer-level-7bit)
654 (define-key mime-edit-mode-entity-map "8" 'mime-edit-set-transfer-level-8bit)
655 (define-key mime-edit-mode-entity-map "/" 'mime-edit-set-split)
656 (define-key mime-edit-mode-entity-map "s" 'mime-edit-set-sign)
657 (define-key mime-edit-mode-entity-map "v" 'mime-edit-set-sign)
658 (define-key mime-edit-mode-entity-map "e" 'mime-edit-set-encrypt)
659 (define-key mime-edit-mode-entity-map "h" 'mime-edit-set-encrypt)
660 (define-key mime-edit-mode-entity-map "p" 'mime-edit-preview-message)
661 (define-key mime-edit-mode-entity-map "\C-z" 'mime-edit-exit)
662 (define-key mime-edit-mode-entity-map "?" 'mime-edit-help)
664 (defvar mime-edit-mode-enclosure-prefix "\C-c\C-m"
665 "Keymap prefix for MIME-Edit mode commands about enclosure.")
666 (defvar mime-edit-mode-enclosure-map (make-sparse-keymap)
667 "Keymap for MIME-Edit mode commands about enclosure.")
669 (define-key mime-edit-mode-enclosure-map
670 "\C-a" 'mime-edit-enclose-alternative-region)
671 (define-key mime-edit-mode-enclosure-map
672 "\C-p" 'mime-edit-enclose-parallel-region)
673 (define-key mime-edit-mode-enclosure-map
674 "\C-m" 'mime-edit-enclose-mixed-region)
675 (define-key mime-edit-mode-enclosure-map
676 "\C-d" 'mime-edit-enclose-digest-region)
677 (define-key mime-edit-mode-enclosure-map
678 "\C-s" 'mime-edit-enclose-pgp-signed-region)
679 (define-key mime-edit-mode-enclosure-map
680 "\C-e" 'mime-edit-enclose-pgp-encrypted-region)
681 (define-key mime-edit-mode-enclosure-map
682 "\C-q" 'mime-edit-enclose-quote-region)
684 (defvar mime-edit-mode-map (make-sparse-keymap)
685 "Keymap for MIME-Edit mode commands.")
686 (define-key mime-edit-mode-map
687 mime-edit-mode-entity-prefix mime-edit-mode-entity-map)
688 (define-key mime-edit-mode-map
689 mime-edit-mode-enclosure-prefix mime-edit-mode-enclosure-map)
691 (defconst mime-edit-menu-title "MIME-Edit")
693 (defconst mime-edit-menu-list
694 '((mime-help "Describe MIME editor mode" mime-edit-help)
695 (file "Insert File" mime-edit-insert-file)
696 (external "Insert External" mime-edit-insert-external)
697 (voice "Insert Voice" mime-edit-insert-voice)
698 (message "Insert Message" mime-edit-insert-message)
699 (mail "Insert Mail" mime-edit-insert-mail)
700 (signature "Insert Signature" mime-edit-insert-signature)
701 (text "Insert Text" mime-edit-insert-text)
702 (tag "Insert Tag" mime-edit-insert-tag)
703 (alternative "Enclose as alternative"
704 mime-edit-enclose-alternative-region)
705 (parallel "Enclose as parallel" mime-edit-enclose-parallel-region)
706 (mixed "Enclose as serial" mime-edit-enclose-mixed-region)
707 (digest "Enclose as digest" mime-edit-enclose-digest-region)
708 (signed "Enclose as signed" mime-edit-enclose-pgp-signed-region)
709 (encrypted "Enclose as encrypted" mime-edit-enclose-pgp-encrypted-region)
710 (quote "Verbatim region" mime-edit-enclose-quote-region)
711 (key "Insert Public Key" mime-edit-insert-key)
712 (split "About split" mime-edit-set-split)
713 (sign "About sign" mime-edit-set-sign)
714 (encrypt "About encryption" mime-edit-set-encrypt)
715 (preview "Preview Message" mime-edit-preview-message)
716 (level "Toggle transfer-level" mime-edit-toggle-transfer-level)
718 "MIME-edit menubar entry.")
720 (cond (running-xemacs
721 ;; modified by Pekka Marjola <pema@iki.fi>
722 ;; 1995/9/5 (c.f. [tm-en:69])
723 (defun mime-edit-define-menu-for-xemacs ()
724 "Define menu for XEmacs."
725 (cond ((featurep 'menubar)
726 (make-local-variable 'current-menubar)
727 (set-buffer-menubar current-menubar)
730 (cons mime-edit-menu-title
733 (vector (nth 1 item)(nth 2 item)
736 mime-edit-menu-list)))
739 ;; modified by Steven L. Baur <steve@miranova.com>
740 ;; 1995/12/6 (c.f. [tm-en:209])
741 (or (boundp 'mime-edit-popup-menu-for-xemacs)
742 (setq mime-edit-popup-menu-for-xemacs
743 (append '("MIME Commands" "---")
744 (mapcar (function (lambda (item)
748 mime-edit-menu-list)))
751 ((>= emacs-major-version 19)
752 (define-key mime-edit-mode-map [menu-bar mime-edit]
753 (cons mime-edit-menu-title
754 (make-sparse-keymap mime-edit-menu-title)))
757 (define-key mime-edit-mode-map
758 (vector 'menu-bar 'mime-edit (car item))
759 (cons (nth 1 item)(nth 2 item))
762 (reverse mime-edit-menu-list)
770 (defvar mime-edit-touched-flag nil)
773 (defun mime-edit-mode ()
774 "MIME minor mode for editing the tagged MIME message.
776 In this mode, basically, the message is composed in the tagged MIME
777 format. The message tag looks like:
779 --[[text/plain; charset=ISO-2022-JP][7bit]]
781 The tag specifies the MIME content type, subtype, optional parameters
782 and transfer encoding of the message following the tag. Messages
783 without any tag are treated as `text/plain' by default. Charset and
784 transfer encoding are automatically defined unless explicitly
785 specified. Binary messages such as audio and image are usually
786 hidden. The messages in the tagged MIME format are automatically
787 translated into a MIME compliant message when exiting this mode.
789 Available charsets depend on Emacs version being used. The following
790 lists the available charsets of each emacs.
792 Without mule: US-ASCII and ISO-8859-1 (or other charset) are available.
793 With mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
794 ISO-2022-JP, ISO-2022-JP-2, EUC-KR, CN-GB-2312,
795 CN-BIG5 and ISO-2022-INT-1 are available.
797 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
798 be used to represent multilingual text in intermixed manner. Any
799 languages that has no registered charset are represented as either
800 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
802 If you want to use non-ISO-8859-1 charset in Emacs 19 or XEmacs
803 without mule, please set variable `default-mime-charset'. This
804 variable must be symbol of which name is a MIME charset.
806 If you want to add more charsets in mule, please set variable
807 `charsets-mime-charset-alist'. This variable must be alist of which
808 key is list of charset and value is symbol of MIME charset. If name
809 of coding-system is different as MIME charset, please set variable
810 `mime-charset-coding-system-alist'. This variable must be alist of
811 which key is MIME charset and value is coding-system.
813 Following commands are available in addition to major mode commands:
816 \\[mime-edit-insert-text] insert a text message.
817 \\[mime-edit-insert-file] insert a (binary) file.
818 \\[mime-edit-insert-external] insert a reference to external body.
819 \\[mime-edit-insert-voice] insert a voice message.
820 \\[mime-edit-insert-message] insert a mail or news message.
821 \\[mime-edit-insert-mail] insert a mail message.
822 \\[mime-edit-insert-signature] insert a signature file at end.
823 \\[mime-edit-insert-key] insert PGP public key.
824 \\[mime-edit-insert-tag] insert a new MIME tag.
826 \[make enclosure (maybe multipart)\]
827 \\[mime-edit-enclose-alternative-region] enclose as multipart/alternative.
828 \\[mime-edit-enclose-parallel-region] enclose as multipart/parallel.
829 \\[mime-edit-enclose-mixed-region] enclose as multipart/mixed.
830 \\[mime-edit-enclose-digest-region] enclose as multipart/digest.
831 \\[mime-edit-enclose-pgp-signed-region] enclose as PGP signed.
832 \\[mime-edit-enclose-pgp-encrypted-region] enclose as PGP encrypted.
833 \\[mime-edit-enclose-quote-region] enclose as verbose mode
834 (to avoid to expand tags)
837 \\[mime-edit-set-transfer-level-7bit] set transfer-level as 7.
838 \\[mime-edit-set-transfer-level-8bit] set transfer-level as 8.
839 \\[mime-edit-set-split] set message splitting mode.
840 \\[mime-edit-set-sign] set PGP-sign mode.
841 \\[mime-edit-set-encrypt] set PGP-encryption mode.
842 \\[mime-edit-preview-message] preview editing MIME message.
843 \\[mime-edit-exit] exit and translate into a MIME
845 \\[mime-edit-help] show this help.
846 \\[mime-edit-maybe-translate] exit and translate if in MIME mode,
849 Additional commands are available in some major modes:
850 C-c C-c exit, translate and run the original command.
851 C-c C-s exit, translate and run the original command.
853 The following is a message example written in the tagged MIME format.
854 TABs at the beginning of the line are not a part of the message:
856 This is a conventional plain text. It should be translated
859 This is also a plain text. But, it is explicitly specified as
861 --[[text/plain; charset=ISO-8859-1]]
862 This is also a plain text. But charset is specified as
865 ¡Hola! Buenos días. ¿Cómo está usted?
867 This is a <bold>enriched text</bold>.
868 --[[image/gif][base64]]...image encoded in base64 here...
869 --[[audio/basic][base64]]...audio encoded in base64 here...
871 User customizable variables (not documented all of them):
873 Specifies a key prefix for MIME minor mode commands.
875 mime-ignore-preceding-spaces
876 Preceding white spaces in a message body are ignored if non-nil.
878 mime-ignore-trailing-spaces
879 Trailing white spaces in a message body are ignored if non-nil.
882 Hide a non-textual body message encoded in base64 after insertion
886 A number of network transfer level. It should be bigger than 7.
887 If you are in 8bit-through environment, please set 8.
889 mime-edit-voice-recorder
890 Specifies a function to record a voice message and encode it.
891 The function `mime-edit-voice-recorder-for-sun' is for Sun
895 Turning on MIME mode calls the value of mime-edit-mode-hook, if
898 mime-edit-translate-hook
899 The value of mime-edit-translate-hook is called just before translating
900 the tagged MIME format into a MIME compliant message if it is
901 non-nil. If the hook call the function mime-edit-insert-signature,
902 the signature file will be inserted automatically.
905 Turning off MIME mode calls the value of mime-edit-exit-hook, if it is
908 (if mime-edit-mode-flag
910 (if mime-edit-touched-flag
912 (make-local-variable 'mime-edit-touched-flag)
913 (setq mime-edit-touched-flag t)
918 (cond (running-xemacs
919 (add-minor-mode 'mime-edit-mode-flag
920 '((" MIME-Edit " mime-transfer-level-string))
926 (set-alist 'minor-mode-alist
928 '((" MIME-Edit " mime-transfer-level-string)))
929 (set-alist 'minor-mode-map-alist
936 (defun turn-on-mime-edit ()
937 "Unconditionally turn on MIME-Edit mode."
939 (if mime-edit-mode-flag
940 (error "You are already editing a MIME message.")
941 (setq mime-edit-mode-flag t)
943 ;; Set transfer level into mode line
945 (setq mime-transfer-level-string
946 (mime-encoding-name mime-transfer-level 'not-omit))
947 (force-mode-line-update)
949 ;; Define menu for XEmacs.
951 (mime-edit-define-menu-for-xemacs)
956 ;; I don't care about saving these.
957 (setq paragraph-start
958 (regexp-or mime-edit-single-part-tag-regexp
960 (setq paragraph-separate
961 (regexp-or mime-edit-single-part-tag-regexp
963 (run-hooks 'mime-edit-mode-hook)
965 (substitute-command-keys
966 "Type \\[mime-edit-exit] to exit MIME mode, and type \\[mime-edit-help] to get help."))
970 (defalias 'edit-mime 'turn-on-mime-edit) ; for convenience
973 (defun mime-edit-exit (&optional nomime no-error)
974 "Translate the tagged MIME message into a MIME compliant message.
975 With no argument encode a message in the buffer into MIME, otherwise
976 just return to previous mode."
978 (if (not mime-edit-mode-flag)
980 (error "You aren't editing a MIME message.")
984 (run-hooks 'mime-edit-translate-hook)
985 (mime-edit-translate-buffer)))
986 ;; Restore previous state.
987 (setq mime-edit-mode-flag nil)
988 (if (and running-xemacs
990 (delete-menu-item (list mime-edit-menu-title))
993 (set-buffer-modified-p (buffer-modified-p))
994 (run-hooks 'mime-edit-exit-hook)
995 (message "Exit MIME editor mode.")
998 (defun mime-edit-maybe-translate ()
1000 (mime-edit-exit nil t)
1001 (call-interactively 'mime-edit-maybe-split-and-send)
1004 (defun mime-edit-help ()
1005 "Show help message about MIME mode."
1007 (with-output-to-temp-buffer "*Help*"
1008 (princ "MIME editor mode:\n")
1009 (princ (documentation 'mime-edit-mode))
1010 (print-help-return-message)))
1012 (defun mime-edit-insert-text (&optional subtype)
1013 "Insert a text message.
1014 Charset is automatically obtained from the `charsets-mime-charset-alist'.
1015 If optional argument SUBTYPE is not nil, text/SUBTYPE tag is inserted."
1017 (let ((ret (mime-edit-insert-tag "text" subtype nil)))
1019 (if (looking-at mime-edit-single-part-tag-regexp)
1021 ;; Make a space between the following message.
1025 (if (and (member (cadr ret) '("enriched" "richtext"))
1026 (fboundp 'enriched-mode)
1029 (if (boundp 'enriched-mode)
1034 (defun mime-edit-insert-file (file &optional verbose)
1035 "Insert a message from a file."
1036 (interactive "fInsert file as MIME message: \nP")
1037 (let* ((guess (mime-find-file-type file))
1038 (type (nth 0 guess))
1039 (subtype (nth 1 guess))
1040 (parameters (nth 2 guess))
1041 (encoding (nth 3 guess))
1042 (disposition-type (nth 4 guess))
1043 (disposition-params (nth 5 guess))
1046 (setq type (mime-prompt-for-type type)
1047 subtype (mime-prompt-for-subtype type subtype)
1049 (if (or (interactive-p) verbose)
1050 (setq encoding (mime-prompt-for-encoding encoding))
1052 (if (or (consp parameters) (stringp disposition-type))
1053 (let ((rest parameters) cell attribute value)
1054 (setq parameters "")
1056 (setq cell (car rest))
1057 (setq attribute (car cell))
1058 (setq value (cdr cell))
1059 (if (eq value 'file)
1060 (setq value (std11-wrap-as-quoted-string
1061 (file-name-nondirectory file)))
1063 (setq parameters (concat parameters "; " attribute "=" value))
1064 (setq rest (cdr rest))
1066 (if disposition-type
1069 (concat parameters "\n"
1070 "Content-Disposition: " disposition-type))
1071 (setq rest disposition-params)
1073 (setq cell (car rest))
1074 (setq attribute (car cell))
1075 (setq value (cdr cell))
1076 (if (eq value 'file)
1077 (setq value (std11-wrap-as-quoted-string
1078 (file-name-nondirectory file)))
1081 (concat parameters "; " attribute "=" value))
1082 (setq rest (cdr rest))
1086 (mime-edit-insert-tag type subtype parameters)
1087 (mime-edit-insert-binary-file file encoding)
1090 (defun mime-edit-insert-external ()
1091 "Insert a reference to external body."
1093 (mime-edit-insert-tag "message" "external-body" nil ";\n\t")
1095 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
1097 (let* ((pritype (mime-prompt-for-type))
1098 (subtype (mime-prompt-for-subtype pritype))
1099 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
1102 (insert "Content-Type: "
1103 pritype "/" subtype (or parameters "") "\n")))
1104 (if (and (not (eobp))
1105 (not (looking-at mime-edit-single-part-tag-regexp)))
1106 (insert (mime-make-text-tag) "\n")))
1108 (defun mime-edit-insert-voice ()
1109 "Insert a voice message."
1113 "What transfer encoding: "
1114 mime-file-encoding-method-alist nil t nil)))
1115 (mime-edit-insert-tag "audio" "basic" nil)
1116 (mime-edit-define-encoding encoding)
1118 (narrow-to-region (1- (point))(point))
1120 (funcall mime-edit-voice-recorder encoding)
1123 (invisible-region (point-min)(point-max))
1124 (goto-char (point-max))
1127 (defun mime-edit-insert-signature (&optional arg)
1128 "Insert a signature file."
1130 (let ((signature-insert-hook
1133 (let ((items (mime-find-file-type signature-file-name)))
1134 (apply (function mime-edit-insert-tag)
1135 (car items) (cadr items) (list (caddr items))))
1138 (insert-signature arg)
1142 ;; Insert a new tag around a point.
1144 (defun mime-edit-insert-tag (&optional pritype subtype parameters delimiter)
1145 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
1146 If nothing is inserted, return nil."
1149 (mime-edit-goto-tag)
1150 (if (and (re-search-forward mime-edit-tag-regexp nil t)
1151 (< (match-beginning 0) p)
1154 (goto-char (match-beginning 0))
1163 (mime-prompt-for-type)))
1166 (mime-prompt-for-subtype pritype)))
1169 (mime-prompt-for-parameters pritype subtype delimiter)))
1170 ;; Make a new MIME tag.
1171 (setq newtag (mime-make-tag pritype subtype parameters))
1172 ;; Find an current MIME tag.
1175 (if (mime-edit-goto-tag)
1176 (buffer-substring (match-beginning 0) (match-end 0))
1177 ;; Assume content type is 'text/plan'.
1178 (mime-make-tag "text" "plain")
1180 ;; We are only interested in TEXT.
1182 (not (mime-test-content-type
1183 (mime-edit-get-contype oldtag) "text")))
1186 (if (or (not oldtag) ;Not text
1187 (or mime-ignore-same-text-tag
1188 (not (string-equal oldtag newtag))))
1190 ;; Mark the beginning of the tag for convenience.
1191 (push-mark (point) 'nomsg)
1192 (insert newtag "\n")
1193 (list pritype subtype parameters) ;New tag is created.
1195 ;; Restore previous point.
1197 nil ;Nothing is created.
1201 (defun mime-edit-insert-binary-file (file &optional encoding)
1202 "Insert binary FILE at point.
1203 Optional argument ENCODING specifies an encoding method such as base64."
1204 (let* ((tagend (1- (point))) ;End of the tag
1205 (hide-p (and mime-auto-hide-body
1208 (let ((en (downcase encoding)))
1209 (or (string-equal en "7bit")
1210 (string-equal en "8bit")
1211 (string-equal en "binary")
1215 (narrow-to-region tagend (point))
1216 (mime-insert-encoded-file file encoding)
1219 (invisible-region (point-min) (point-max))
1220 (goto-char (point-max))
1222 (goto-char (point-max))
1225 (looking-at mime-edit-tag-regexp)
1226 (= (point)(point-max))
1227 (mime-edit-insert-tag "text" "plain")
1229 ;; Define encoding even if it is 7bit.
1230 (if (stringp encoding)
1232 (goto-char tagend) ; Make sure which line the tag is on.
1233 (mime-edit-define-encoding encoding)
1238 ;; Commands work on a current message flagment.
1240 (defun mime-edit-goto-tag ()
1241 "Search for the beginning of the tagged MIME message."
1242 (let ((current (point)))
1243 (if (looking-at mime-edit-tag-regexp)
1245 ;; At first, go to the end.
1246 (cond ((re-search-forward mime-edit-beginning-tag-regexp nil t)
1247 (goto-char (1- (match-beginning 0))) ;For multiline tag
1250 (goto-char (point-max))
1252 ;; Then search for the beginning.
1253 (re-search-backward mime-edit-end-tag-regexp nil t)
1254 (or (looking-at mime-edit-beginning-tag-regexp)
1255 ;; Restore previous point.
1262 (defun mime-edit-content-beginning ()
1263 "Return the point of the beginning of content."
1265 (let ((beg (save-excursion
1266 (beginning-of-line) (point))))
1267 (if (mime-edit-goto-tag)
1268 (let ((top (point)))
1269 (goto-char (match-end 0))
1270 (if (and (= beg top)
1271 (= (following-char) ?\^M))
1275 ;; Default text/plain tag.
1276 (goto-char (point-min))
1278 (concat "\n" (regexp-quote mail-header-separator)
1279 (if mime-ignore-preceding-spaces
1280 "[ \t\n]*\n" "\n")) nil 'move)
1284 (defun mime-edit-content-end ()
1285 "Return the point of the end of content."
1287 (if (mime-edit-goto-tag)
1289 (goto-char (match-end 0))
1290 (if (invisible-p (point))
1291 (next-visible-point (point))
1292 ;; Move to the end of this text.
1293 (if (re-search-forward mime-edit-tag-regexp nil 'move)
1294 ;; Don't forget a multiline tag.
1295 (goto-char (match-beginning 0))
1299 ;; Assume the message begins with text/plain.
1300 (goto-char (mime-edit-content-beginning))
1301 (if (re-search-forward mime-edit-tag-regexp nil 'move)
1302 ;; Don't forget a multiline tag.
1303 (goto-char (match-beginning 0)))
1307 (defun mime-edit-define-charset (charset)
1308 "Set charset of current tag to CHARSET."
1310 (if (mime-edit-goto-tag)
1311 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1312 (delete-region (match-beginning 0) (match-end 0))
1315 (mime-edit-set-parameter
1316 (mime-edit-get-contype tag)
1317 "charset" (upcase (symbol-name charset)))
1318 (mime-edit-get-encoding tag)))
1321 (defun mime-edit-define-encoding (encoding)
1322 "Set encoding of current tag to ENCODING."
1324 (if (mime-edit-goto-tag)
1325 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1326 (delete-region (match-beginning 0) (match-end 0))
1327 (insert (mime-create-tag (mime-edit-get-contype tag) encoding)))
1330 (defun mime-edit-choose-charset ()
1331 "Choose charset of a text following current point."
1332 (detect-mime-charset-region (point) (mime-edit-content-end))
1335 (defun mime-make-text-tag (&optional subtype)
1336 "Make a tag for a text after current point.
1337 Subtype of text type can be specified by an optional argument SUBTYPE.
1338 Otherwise, it is obtained from mime-content-types."
1339 (let* ((pritype "text")
1340 (subtype (or subtype
1341 (car (car (cdr (assoc pritype mime-content-types)))))))
1342 ;; Charset should be defined later.
1343 (mime-make-tag pritype subtype)))
1346 ;; Tag handling functions
1348 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1349 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1350 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1354 (defun mime-create-tag (contype &optional encoding)
1355 "Make a tag with CONTENT-TYPE and optional ENCODING."
1356 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1359 (defun mime-edit-get-contype (tag)
1360 "Return Content-Type (including parameters) of TAG."
1362 (or (string-match mime-edit-single-part-tag-regexp tag)
1363 (string-match mime-edit-multipart-beginning-regexp tag)
1364 (string-match mime-edit-multipart-end-regexp tag)
1366 (substring tag (match-beginning 1) (match-end 1))
1369 (defun mime-edit-get-encoding (tag)
1370 "Return encoding of TAG."
1372 (string-match mime-edit-single-part-tag-regexp tag)
1374 (not (= (match-beginning 3) (match-end 3)))
1375 (substring tag (match-beginning 3) (match-end 3))))
1377 (defun mime-get-parameter (contype parameter)
1378 "For given CONTYPE return value for PARAMETER.
1379 Nil if no such parameter."
1383 (regexp-quote parameter)
1384 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1386 (substring contype (match-beginning 1) (match-end 1))
1387 nil ;No such parameter
1390 (defun mime-edit-set-parameter (contype parameter value)
1391 "For given CONTYPE set PARAMETER to VALUE."
1392 (let (ctype opt-fields)
1393 (if (string-match "\n[^ \t\n\r]+:" contype)
1394 (setq ctype (substring contype 0 (match-beginning 0))
1395 opt-fields (substring contype (match-beginning 0)))
1396 (setq ctype contype)
1401 (regexp-quote parameter)
1402 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1405 (concat (substring ctype 0 (match-beginning 1))
1407 (substring contype (match-end 1))
1409 (concat ctype "; " parameter "=" value opt-fields)
1412 (defun mime-strip-parameters (contype)
1413 "Return primary content-type and subtype without parameters for CONTYPE."
1414 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1415 (substring contype (match-beginning 1) (match-end 1)) nil))
1417 (defun mime-test-content-type (contype type &optional subtype)
1418 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1419 (and (stringp contype)
1422 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1423 (downcase contype))))
1428 (defun mime-find-file-type (file)
1429 "Guess Content-Type, subtype, and parameters from FILE."
1431 (guesses mime-file-types))
1432 (while (and (not guess) guesses)
1433 (if (string-match (car (car guesses)) file)
1434 (setq guess (cdr (car guesses))))
1435 (setq guesses (cdr guesses)))
1439 (defun mime-prompt-for-type (&optional default)
1440 "Ask for Content-type."
1442 ;; Repeat until primary content type is specified.
1443 (while (string-equal type "")
1445 (completing-read "What content type: "
1448 'require-match ;Type must be specified.
1451 (if (string-equal type "")
1453 (message "Content type is required.")
1460 (defun mime-prompt-for-subtype (type &optional default)
1461 "Ask for subtype of media-type TYPE."
1462 (let ((subtypes (cdr (assoc type mime-content-types))))
1464 (assoc default subtypes))
1465 (setq default (car (car subtypes)))
1471 "What content subtype: (default " default ") ")
1472 "What content subtype: ")
1473 (cdr (assoc type mime-content-types))
1475 'require-match ;Subtype must be specified.
1478 (if (string-equal answer "") default answer)))
1480 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1481 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1482 Optional DELIMITER specifies parameter delimiter (';' by default)."
1483 (let* ((delimiter (or delimiter "; "))
1488 (mime-prompt-for-parameters-1
1490 (cdr (assoc pritype mime-content-types))))))
1493 (if (and (stringp parameters)
1494 (not (string-equal parameters "")))
1495 (concat delimiter parameters)
1496 "" ;"" if no parameters
1499 (defun mime-prompt-for-parameters-1 (optlist)
1500 (apply (function append)
1501 (mapcar (function mime-prompt-for-parameter) optlist)))
1503 (defun mime-prompt-for-parameter (parameter)
1505 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1506 (let* ((prompt (car parameter))
1507 (choices (mapcar (function
1509 (if (consp e) e (list e))))
1511 (default (car (car choices)))
1517 (concat "What " prompt
1519 (if (string-equal default "") "\"\"" default)
1521 choices nil nil ""))
1522 ;; If nothing is selected, use default.
1523 (if (string-equal answer "")
1524 (setq answer default)))
1526 (read-string (concat "What " prompt ": "))))
1527 (cons (if (and answer
1528 (not (string-equal answer "")))
1530 ;; Note: control characters ignored!
1531 (if (string-match mime-tspecials-regexp answer)
1532 (concat "\"" answer "\"") answer)))
1533 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1536 (defun mime-prompt-for-encoding (default)
1537 "Ask for Content-Transfer-Encoding."
1542 "What transfer encoding: "
1543 mime-file-encoding-method-alist nil t default)
1549 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1552 (defvar mime-edit-translate-buffer-hook
1553 '(mime-edit-pgp-enclose-buffer
1554 mime-edit-translate-body
1555 mime-edit-translate-header))
1557 (defun mime-edit-translate-header ()
1558 "Encode the message header into network representation."
1559 (eword-encode-header 'code-conversion)
1560 (run-hooks 'mime-edit-translate-header-hook)
1563 (defun mime-edit-translate-buffer ()
1564 "Encode the tagged MIME message in current buffer in MIME compliant message."
1566 (if (catch 'mime-edit-error
1568 (run-hooks 'mime-edit-translate-buffer-hook)
1572 (error "Translation error!")
1575 (defun mime-edit-find-inmost ()
1576 (goto-char (point-min))
1577 (if (re-search-forward mime-edit-multipart-beginning-regexp nil t)
1578 (let ((bb (match-beginning 0))
1580 (type (buffer-substring (match-beginning 1)(match-end 1)))
1582 (setq end-exp (format "--}-<<%s>>\n" type))
1584 (if (re-search-forward end-exp nil t)
1585 (setq eb (match-beginning 0))
1586 (setq eb (point-max))
1588 (narrow-to-region be eb)
1590 (if (re-search-forward mime-edit-multipart-beginning-regexp nil t)
1592 (narrow-to-region (match-beginning 0)(point-max))
1593 (mime-edit-find-inmost)
1596 (list type bb be eb)
1599 (defun mime-edit-process-multipart-1 (boundary)
1600 (let ((ret (mime-edit-find-inmost)))
1602 (let ((type (car ret))
1603 (bb (nth 1 ret))(be (nth 2 ret))
1606 (narrow-to-region bb eb)
1607 (delete-region bb be)
1608 (setq bb (point-min))
1609 (setq eb (point-max))
1612 (if (looking-at mime-edit-multipart-end-regexp)
1613 (let ((beg (match-beginning 0))
1616 (delete-region beg end)
1617 (or (looking-at mime-edit-beginning-tag-regexp)
1619 (insert (concat (mime-make-text-tag) "\n"))
1621 (cond ((string-equal type "quote")
1622 (mime-edit-enquote-region bb eb)
1624 ((string-equal type "pgp-signed")
1625 (mime-edit-sign-pgp-mime bb eb boundary)
1627 ((string-equal type "pgp-encrypted")
1628 (mime-edit-encrypt-pgp-mime bb eb boundary)
1630 ((string-equal type "kazu-signed")
1631 (mime-edit-sign-pgp-kazu bb eb boundary)
1633 ((string-equal type "kazu-encrypted")
1634 (mime-edit-encrypt-pgp-kazu bb eb boundary)
1638 (nth 2 (mime-edit-translate-region bb eb
1642 (format "--[[multipart/%s;
1643 boundary=\"%s\"][7bit]]\n"
1648 (defun mime-edit-enquote-region (beg end)
1651 (narrow-to-region beg end)
1653 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1654 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1655 (replace-match (concat "- " (substring tag 1)))
1658 (defun mime-edit-dequote-region (beg end)
1661 (narrow-to-region beg end)
1663 (while (re-search-forward
1664 mime-edit-quoted-single-part-tag-regexp nil t)
1665 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1666 (replace-match (concat "-" (substring tag 2)))
1669 (defun mime-edit-sign-pgp-mime (beg end boundary)
1672 (narrow-to-region beg end)
1674 (mime-edit-translate-region beg end boundary))
1676 (encoding (nth 1 ret))
1677 (pgp-boundary (concat "pgp-sign-" boundary)))
1679 (insert (format "Content-Type: %s\n" ctype))
1681 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1684 (or (as-binary-process
1685 (funcall (pgp-function 'mime-sign)
1686 (point-min)(point-max) nil nil pgp-boundary))
1687 (throw 'mime-edit-error 'pgp-error)
1691 (defvar mime-edit-encrypt-recipient-fields-list '("To" "cc"))
1693 (defun mime-edit-make-encrypt-recipient-header ()
1694 (let* ((names mime-edit-encrypt-recipient-fields-list)
1696 (std11-field-bodies (cons "From" names)
1697 nil mail-header-separator))
1700 (setq values (cdr values))))
1701 (header (and (stringp from)
1702 (if (string-equal from "")
1704 (format "From: %s\n" from)
1707 (while (and names values)
1708 (let ((name (car names))
1709 (value (car values))
1711 (and (stringp value)
1712 (or (string-equal value "")
1714 (setq header (concat header name ": " value "\n")
1715 recipients (if recipients
1716 (concat recipients " ," value)
1719 (setq names (cdr names)
1720 values (cdr values))
1722 (vector from recipients header)
1725 (defun mime-edit-encrypt-pgp-mime (beg end boundary)
1728 (let (from recipients header)
1729 (let ((ret (mime-edit-make-encrypt-recipient-header)))
1730 (setq from (aref ret 0)
1731 recipients (aref ret 1)
1732 header (aref ret 2))
1734 (narrow-to-region beg end)
1736 (mime-edit-translate-region beg end boundary))
1738 (encoding (nth 1 ret))
1739 (pgp-boundary (concat "pgp-" boundary)))
1742 (insert (format "Content-Type: %s\n" ctype))
1744 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1747 (or (funcall (pgp-function 'encrypt)
1748 recipients (point-min) (point-max) from)
1749 (throw 'mime-edit-error 'pgp-error)
1752 (insert (format "--[[multipart/encrypted;
1754 protocol=\"application/pgp-encrypted\"][7bit]]
1756 Content-Type: application/pgp-encrypted
1759 Content-Type: application/octet-stream
1760 Content-Transfer-Encoding: 7bit
1762 " pgp-boundary pgp-boundary pgp-boundary))
1763 (goto-char (point-max))
1764 (insert (format "\n--%s--\n" pgp-boundary))
1767 (defun mime-edit-sign-pgp-kazu (beg end boundary)
1770 (narrow-to-region beg end)
1772 (mime-edit-translate-region beg end boundary))
1774 (encoding (nth 1 ret)))
1776 (insert (format "Content-Type: %s\n" ctype))
1778 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1781 (or (as-binary-process
1782 (funcall (pgp-function 'traditional-sign)
1784 (throw 'mime-edit-error 'pgp-error)
1788 "--[[application/pgp; format=mime][7bit]]\n")
1792 (defun mime-edit-encrypt-pgp-kazu (beg end boundary)
1794 (let (recipients header)
1795 (let ((ret (mime-edit-make-encrypt-recipient-header)))
1796 (setq recipients (aref ret 1)
1797 header (aref ret 2))
1800 (narrow-to-region beg end)
1802 (mime-edit-translate-region beg end boundary))
1804 (encoding (nth 1 ret)))
1807 (insert (format "Content-Type: %s\n" ctype))
1809 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1812 (or (as-binary-process
1813 (funcall (pgp-function 'encrypt)
1814 recipients beg (point-max) nil 'maybe)
1816 (throw 'mime-edit-error 'pgp-error)
1820 "--[[application/pgp; format=mime][7bit]]\n")
1824 (defsubst replace-space-with-underline (str)
1825 (mapconcat (function
1833 (defun mime-edit-make-boundary ()
1834 (concat mime-multipart-boundary "_"
1835 (replace-space-with-underline (current-time-string))
1838 (defun mime-edit-translate-body ()
1839 "Encode the tagged MIME body in current buffer in MIME compliant message."
1842 (let ((boundary (mime-edit-make-boundary))
1845 (while (mime-edit-process-multipart-1
1846 (format "%s-%d" boundary i))
1850 ;; We are interested in message body.
1853 (goto-char (point-min))
1855 (concat "\n" (regexp-quote mail-header-separator)
1856 (if mime-ignore-preceding-spaces
1857 "[ \t\n]*\n" "\n")) nil 'move)
1861 (goto-char (point-max))
1862 (and mime-ignore-trailing-spaces
1863 (re-search-backward "[^ \t\n]\n" beg t)
1866 (setq ret (mime-edit-translate-region
1868 (format "%s-%d" boundary i)))
1870 (mime-edit-dequote-region (point-min)(point-max))
1871 (let ((contype (car ret)) ;Content-Type
1872 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1874 ;; Insert User-Agent field
1875 (and mime-edit-insert-user-agent-field
1876 (or (mail-position-on-field "User-Agent")
1877 (insert mime-edit-user-agent-value)
1879 ;; Make primary MIME headers.
1880 (or (mail-position-on-field "MIME-Version")
1881 (insert mime-edit-mime-version-value))
1882 ;; Remove old Content-Type and other fields.
1884 (goto-char (point-min))
1885 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1886 (narrow-to-region (point-min) (point))
1887 (goto-char (point-min))
1888 (mime-delete-field "Content-Type")
1889 (mime-delete-field "Content-Transfer-Encoding"))
1890 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1891 (mail-position-on-field "Content-Type")
1895 (mail-position-on-field "Content-Transfer-Encoding")
1899 (defun mime-edit-translate-single-part-tag (boundary &optional prefix)
1900 "Translate single-part-tag to MIME header."
1901 (if (re-search-forward mime-edit-single-part-tag-regexp nil t)
1902 (let* ((beg (match-beginning 0))
1904 (tag (buffer-substring beg end)))
1905 (delete-region beg end)
1906 (let ((contype (mime-edit-get-contype tag))
1907 (encoding (mime-edit-get-encoding tag)))
1908 (insert (concat prefix "--" boundary "\n"))
1910 (narrow-to-region (point)(point))
1911 (insert "Content-Type: " contype "\n")
1913 (insert "Content-Transfer-Encoding: " encoding "\n"))
1914 (eword-encode-header)
1918 (defun mime-edit-translate-region (beg end &optional boundary multipart)
1920 (setq boundary (mime-edit-make-boundary))
1924 (narrow-to-region beg end)
1925 (let ((tag nil) ;MIME tag
1926 (contype nil) ;Content-Type
1927 (encoding nil) ;Content-Transfer-Encoding
1928 (nparts 0)) ;Number of body parts
1929 ;; Normalize the body part by inserting appropriate message
1930 ;; tags for every message contents.
1931 (mime-edit-normalize-body)
1932 ;; Counting the number of Content-Type.
1933 (goto-char (point-min))
1934 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1935 (setq nparts (1+ nparts)))
1936 ;; Begin translation.
1938 ((and (<= nparts 1)(not multipart))
1939 ;; It's a singular message.
1940 (goto-char (point-min))
1941 (while (re-search-forward
1942 mime-edit-single-part-tag-regexp nil t)
1944 (buffer-substring (match-beginning 0) (match-end 0)))
1945 (delete-region (match-beginning 0) (1+ (match-end 0)))
1946 (setq contype (mime-edit-get-contype tag))
1947 (setq encoding (mime-edit-get-encoding tag))
1950 ;; It's a multipart message.
1951 (goto-char (point-min))
1952 (and (mime-edit-translate-single-part-tag boundary)
1953 (while (mime-edit-translate-single-part-tag boundary "\n")))
1954 ;; Define Content-Type as "multipart/mixed".
1956 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1957 ;; Content-Transfer-Encoding must be "7bit".
1958 ;; The following encoding can be `nil', but is
1959 ;; specified as is since there is no way that a user
1961 (setq encoding "7bit")
1962 ;; Insert the trailer.
1963 (goto-char (point-max))
1964 (insert "\n--" boundary "--\n")
1966 (list contype encoding boundary nparts)
1969 (defun mime-edit-normalize-body ()
1970 "Normalize the body part by inserting appropriate message tags."
1971 ;; Insert the first MIME tags if necessary.
1972 (goto-char (point-min))
1973 (if (not (looking-at mime-edit-single-part-tag-regexp))
1974 (insert (mime-make-text-tag) "\n"))
1975 ;; Check each tag, and add new tag or correct it if necessary.
1976 (goto-char (point-min))
1977 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1978 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1979 (contype (mime-edit-get-contype tag))
1980 (charset (mime-get-parameter contype "charset"))
1981 (encoding (mime-edit-get-encoding tag)))
1982 ;; Remove extra whitespaces after the tag.
1983 (if (looking-at "[ \t]+$")
1984 (delete-region (match-beginning 0) (match-end 0)))
1986 (end (mime-edit-content-end))
1988 (if (= end (point-max))
1991 (or (looking-at mime-edit-beginning-tag-regexp)
1993 (insert (mime-make-text-tag) "\n")
1995 (visible-region beg end)
1999 ((mime-test-content-type contype "message")
2000 ;; Content-type "message" should be sent as is.
2003 ((mime-test-content-type contype "text")
2004 ;; Define charset for text if necessary.
2005 (setq charset (if charset
2006 (intern (downcase charset))
2007 (mime-edit-choose-charset)))
2008 (mime-edit-define-charset charset)
2009 (cond ((string-equal contype "text/x-rot13-47-48")
2012 (mule-caesar-region (point) (mime-edit-content-end))
2014 ((string-equal contype "text/enriched")
2019 (end (mime-edit-content-end))
2021 ;; Patch for hard newlines
2024 ;; (while (search-forward "\n" end t)
2025 ;; (put-text-property (match-beginning 0)
2028 ;; End patch for hard newlines
2029 (enriched-encode beg end)
2031 (if (search-forward "\n\n")
2032 (delete-region beg (match-end 0))
2035 ;; Point is now on current tag.
2036 ;; Define encoding and encode text if necessary.
2037 (or encoding ;Encoding is not specified.
2040 (let ((ret (cdr (assq charset mime-charset-type-list))))
2042 (setq bits (car ret)
2045 conv "quoted-printable")))
2046 (if (<= bits mime-transfer-level)
2047 (mime-encoding-name bits)
2049 (beg (mime-edit-content-beginning)))
2050 (encode-mime-charset-region beg (mime-edit-content-end)
2052 ;; Protect "From " in beginning of line
2054 (narrow-to-region beg (mime-edit-content-end))
2056 (let (case-fold-search)
2057 (if (re-search-forward "^From " nil t)
2059 (if (memq charset '(iso-2022-jp
2064 (replace-match "\e(BFrom ")
2065 (re-search-forward "^From " nil t)
2067 (setq encoding "quoted-printable")
2069 ;; canonicalize line break code
2070 (or (member encoding '(nil "7bit" "8bit" "quoted-printable"))
2072 (narrow-to-region beg (mime-edit-content-end))
2074 (while (re-search-forward "\\(\\=\\|[^\r]\\)\n" nil t)
2075 (replace-match "\\1\r\n"))))
2077 (mime-encode-region beg (mime-edit-content-end) encoding)
2078 (mime-edit-define-encoding encoding)
2080 (goto-char (mime-edit-content-end))
2082 ((null encoding) ;Encoding is not specified.
2083 ;; Application, image, audio, video, and any other
2084 ;; unknown content-type without encoding should be
2086 (let* ((encoding "base64") ;Encode in BASE64 by default.
2087 (beg (mime-edit-content-beginning))
2088 (end (mime-edit-content-end)))
2089 (mime-encode-region beg end encoding)
2090 (mime-edit-define-encoding encoding))
2095 (defun mime-delete-field (field)
2096 "Delete header FIELD."
2097 (let ((regexp (format "^%s:[ \t]*" field)))
2098 (goto-char (point-min))
2099 (while (re-search-forward regexp nil t)
2100 (delete-region (match-beginning 0)
2101 (progn (forward-line 1) (point)))
2106 ;;; Platform dependent functions
2109 ;; Sun implementations
2111 (defun mime-edit-voice-recorder-for-sun (encoding)
2112 "Record voice in a buffer using Sun audio device,
2113 and insert data encoded as ENCODING."
2114 (message "Start the recording on %s. Type C-g to finish the recording..."
2116 (mime-insert-encoded-file "/dev/audio" encoding)
2120 ;;; @ Other useful commands.
2123 ;; Message forwarding commands as content-type "message/rfc822".
2125 (defun mime-edit-insert-message (&optional message)
2127 (let ((inserter (cdr (assq major-mode mime-edit-message-inserter-alist))))
2128 (if (and inserter (fboundp inserter))
2130 (mime-edit-insert-tag "message" "rfc822")
2131 (funcall inserter message)
2133 (message "Sorry, I don't have message inserter for your MUA.")
2136 (defun mime-edit-insert-mail (&optional message)
2138 (let ((inserter (cdr (assq major-mode mime-edit-mail-inserter-alist))))
2139 (if (and inserter (fboundp inserter))
2141 (mime-edit-insert-tag "message" "rfc822")
2142 (funcall inserter message)
2144 (message "Sorry, I don't have mail inserter for your MUA.")
2147 (defun mime-edit-inserted-message-filter ()
2150 (let ((header-start (point))
2151 (case-fold-search t)
2154 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2155 (if (re-search-forward "^$" (mark t))
2156 (narrow-to-region header-start (match-beginning 0))
2158 (goto-char header-start)
2159 (while (and (re-search-forward
2160 mime-edit-yank-ignored-field-regexp nil t)
2161 (setq beg (match-beginning 0))
2162 (setq end (1+ (std11-field-end)))
2164 (delete-region beg end)
2169 ;;; @ multipart enclosure
2172 (defun mime-edit-enclose-region-internal (type beg end)
2176 (narrow-to-region beg end)
2177 (insert (format "--<<%s>>-{\n" type))
2178 (goto-char (point-max))
2179 (insert (format "--}-<<%s>>\n" type))
2180 (goto-char (point-max))
2182 (or (looking-at mime-edit-beginning-tag-regexp)
2184 (insert (mime-make-text-tag) "\n")
2188 (defun mime-edit-enclose-quote-region (beg end)
2190 (mime-edit-enclose-region-internal 'quote beg end)
2193 (defun mime-edit-enclose-mixed-region (beg end)
2195 (mime-edit-enclose-region-internal 'mixed beg end)
2198 (defun mime-edit-enclose-parallel-region (beg end)
2200 (mime-edit-enclose-region-internal 'parallel beg end)
2203 (defun mime-edit-enclose-digest-region (beg end)
2205 (mime-edit-enclose-region-internal 'digest beg end)
2208 (defun mime-edit-enclose-alternative-region (beg end)
2210 (mime-edit-enclose-region-internal 'alternative beg end)
2213 (defun mime-edit-enclose-pgp-signed-region (beg end)
2215 (mime-edit-enclose-region-internal 'pgp-signed beg end)
2218 (defun mime-edit-enclose-pgp-encrypted-region (beg end)
2220 (mime-edit-enclose-region-internal 'pgp-encrypted beg end)
2223 (defun mime-edit-enclose-kazu-signed-region (beg end)
2225 (mime-edit-enclose-region-internal 'kazu-signed beg end)
2228 (defun mime-edit-enclose-kazu-encrypted-region (beg end)
2230 (mime-edit-enclose-region-internal 'kazu-encrypted beg end)
2233 (defun mime-edit-insert-key (&optional arg)
2234 "Insert a pgp public key."
2236 (mime-edit-insert-tag "application" "pgp-keys")
2237 (mime-edit-define-encoding "7bit")
2238 (funcall (pgp-function 'insert-key))
2245 (defun mime-edit-set-split (arg)
2248 (y-or-n-p "Do you want to enable split? ")
2250 (setq mime-edit-split-message arg)
2252 (message "This message is enabled to split.")
2253 (message "This message is not enabled to split.")
2256 (defun mime-edit-toggle-transfer-level (&optional transfer-level)
2257 "Toggle transfer-level is 7bit or 8bit through.
2259 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2261 (if (numberp transfer-level)
2262 (setq mime-transfer-level transfer-level)
2263 (if (< mime-transfer-level 8)
2264 (setq mime-transfer-level 8)
2265 (setq mime-transfer-level 7)
2267 (message (format "Current transfer-level is %d bit"
2268 mime-transfer-level))
2269 (setq mime-transfer-level-string
2270 (mime-encoding-name mime-transfer-level 'not-omit))
2271 (force-mode-line-update)
2274 (defun mime-edit-set-transfer-level-7bit ()
2276 (mime-edit-toggle-transfer-level 7)
2279 (defun mime-edit-set-transfer-level-8bit ()
2281 (mime-edit-toggle-transfer-level 8)
2288 (defvar mime-edit-pgp-processing nil)
2289 (make-variable-buffer-local 'mime-edit-pgp-processing)
2291 (defun mime-edit-set-sign (arg)
2294 (y-or-n-p "Do you want to sign? ")
2298 (setq mime-edit-pgp-processing 'sign)
2299 (message "This message will be signed.")
2301 (if (eq mime-edit-pgp-processing 'sign)
2302 (setq mime-edit-pgp-processing nil)
2304 (message "This message will not be signed.")
2307 (defun mime-edit-set-encrypt (arg)
2310 (y-or-n-p "Do you want to encrypt? ")
2314 (setq mime-edit-pgp-processing 'encrypt)
2315 (message "This message will be encrypt.")
2317 (if (eq mime-edit-pgp-processing 'encrypt)
2318 (setq mime-edit-pgp-processing nil)
2320 (message "This message will not be encrypt.")
2323 (defun mime-edit-pgp-enclose-buffer ()
2324 (let ((beg (save-excursion
2325 (goto-char (point-min))
2326 (if (search-forward (concat "\n" mail-header-separator "\n"))
2332 (cond ((eq mime-edit-pgp-processing 'sign)
2333 (mime-edit-enclose-pgp-signed-region beg end)
2335 ((eq mime-edit-pgp-processing 'encrypt)
2336 (mime-edit-enclose-pgp-encrypted-region beg end)
2344 (defun mime-edit-insert-partial-header (fields subject
2345 id number total separator)
2347 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2348 (insert mime-edit-mime-version-field-for-message/partial)
2350 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2351 id number total separator))
2354 (defun mime-edit-split-and-send
2355 (&optional cmd lines mime-edit-message-max-length)
2359 (count-lines (point-min) (point-max)))
2361 (or mime-edit-message-max-length
2362 (setq mime-edit-message-max-length
2363 (or (cdr (assq major-mode mime-edit-message-max-lines-alist))
2364 mime-edit-message-default-max-lines))
2366 (let* ((mime-edit-draft-file-name
2367 (or (buffer-file-name)
2369 (expand-file-name "mime-draft" mime-temp-directory))))
2370 (separator mail-header-separator)
2372 (replace-space-with-underline (current-time-string))
2373 "@" (system-name) "\"")))
2374 (run-hooks 'mime-edit-before-split-hook)
2375 (let ((the-buf (current-buffer))
2376 (copy-buf (get-buffer-create " *Original Message*"))
2377 (header (std11-header-string-except
2378 mime-edit-split-ignored-field-regexp separator))
2379 (subject (mail-fetch-field "subject"))
2380 (total (+ (/ lines mime-edit-message-max-length)
2381 (if (> (mod lines mime-edit-message-max-length) 0)
2387 mime-edit-split-message-sender-alist))
2391 (error "Split sender is not specified for `%s'." major-mode)
2394 (mime-edit-partial-number 1)
2397 (set-buffer copy-buf)
2399 (insert-buffer the-buf)
2401 (if (re-search-forward
2402 (concat "^" (regexp-quote separator) "$") nil t)
2403 (let ((he (match-beginning 0)))
2405 (narrow-to-region (point-min) he)
2407 (goto-char (point-min))
2408 (while (re-search-forward mime-edit-split-blind-field-regexp nil t)
2409 (delete-region (match-beginning 0)
2410 (1+ (std11-field-end)))
2412 (while (< mime-edit-partial-number total)
2415 (set-buffer copy-buf)
2416 (setq data (buffer-substring
2419 (goto-line mime-edit-message-max-length)
2422 (delete-region (point-min)(point))
2424 (mime-edit-insert-partial-header
2425 header subject id mime-edit-partial-number total separator)
2428 (message (format "Sending %d/%d..."
2429 mime-edit-partial-number total))
2430 (call-interactively command)
2431 (message (format "Sending %d/%d... done"
2432 mime-edit-partial-number total))
2434 (setq mime-edit-partial-number
2435 (1+ mime-edit-partial-number))
2439 (set-buffer copy-buf)
2440 (setq data (buffer-string))
2443 (mime-edit-insert-partial-header
2444 header subject id mime-edit-partial-number total separator)
2447 (message (format "Sending %d/%d..."
2448 mime-edit-partial-number total))
2449 (message (format "Sending %d/%d... done"
2450 mime-edit-partial-number total))
2454 (defun mime-edit-maybe-split-and-send (&optional cmd)
2456 (run-hooks 'mime-edit-before-send-hook)
2457 (let ((mime-edit-message-max-length
2458 (or (cdr (assq major-mode mime-edit-message-max-lines-alist))
2459 mime-edit-message-default-max-lines))
2460 (lines (count-lines (point-min) (point-max)))
2462 (if (and (> lines mime-edit-message-max-length)
2463 mime-edit-split-message)
2464 (mime-edit-split-and-send cmd lines mime-edit-message-max-length)
2468 ;;; @ preview message
2471 (defvar mime-edit-buffer nil) ; buffer local variable
2473 (defun mime-edit-preview-message ()
2474 "preview editing MIME message."
2476 (let* ((str (buffer-string))
2477 (separator mail-header-separator)
2478 (the-buf (current-buffer))
2479 (buf-name (buffer-name))
2480 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2481 (buf (get-buffer temp-buf-name))
2485 (switch-to-buffer buf)
2488 (setq buf (get-buffer-create temp-buf-name))
2489 (switch-to-buffer buf)
2492 (setq major-mode 'mime-temp-message-mode)
2493 (make-local-variable 'mail-header-separator)
2494 (setq mail-header-separator separator)
2495 (make-local-variable 'mime-edit-buffer)
2496 (setq mime-edit-buffer the-buf)
2498 (run-hooks 'mime-edit-translate-hook)
2499 (mime-edit-translate-buffer)
2500 (goto-char (point-min))
2501 (if (re-search-forward
2502 (concat "^" (regexp-quote separator) "$"))
2508 (defun mime-edit-quitting-method ()
2509 "Quitting method for mime-view."
2510 (let ((temp mime-raw-buffer)
2512 (mime-preview-kill-buffer)
2514 (setq buf mime-edit-buffer)
2516 (switch-to-buffer buf)
2519 (set-alist 'mime-preview-quitting-method-alist
2520 'mime-temp-message-mode
2521 #'mime-edit-quitting-method)
2527 (defvar mime-edit-again-ignored-field-regexp
2528 (concat "^\\(" "Content-.*\\|Mime-Version"
2529 (if mime-edit-insert-user-agent-field "\\|User-Agent")
2531 "Regexp for deleted header fields when `mime-edit-again' is called.")
2533 (defun mime-edit-decode-buffer (not-decode-text)
2535 (goto-char (point-min))
2536 (let ((ctl (mime-read-Content-Type)))
2538 (let ((type (mime-content-type-primary-type ctl))
2539 (stype (mime-content-type-subtype ctl))
2540 (params (mime-content-type-parameters ctl)))
2542 ((and (eq type 'application)(eq stype 'pgp-signature))
2543 (delete-region (point-min)(point-max))
2545 ((eq type 'multipart)
2546 (let* ((boundary (cdr (assoc "boundary" params)))
2548 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2550 (re-search-forward boundary-pat nil t)
2551 (let ((bb (match-beginning 0)) eb tag)
2552 (setq tag (format "\n--<<%s>>-{\n" stype))
2555 (setq bb (+ bb (length tag)))
2557 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2559 (setq eb (match-beginning 0))
2560 (replace-match (format "--}-<<%s>>\n" stype))
2562 (narrow-to-region bb eb)
2563 (goto-char (point-min))
2564 (while (re-search-forward boundary-pat nil t)
2565 (let ((beg (match-beginning 0))
2567 (delete-region beg (match-end 0))
2569 (if (re-search-forward boundary-pat nil t)
2570 (setq end (match-beginning 0))
2571 (setq end (point-max))
2574 (narrow-to-region beg end)
2575 (mime-edit-decode-buffer not-decode-text)
2576 (goto-char (point-max))
2579 (goto-char (point-min))
2580 (or (= (point-min) 1)
2581 (delete-region (point-min)
2582 (if (search-forward "\n\n" nil t)
2588 (let* ((ctype (format "%s/%s" type stype))
2591 (let ((bytes (+ 14 (length ctype))))
2592 (mapconcat (function
2594 (if (string= (car attr) "charset")
2596 (setq charset (cdr attr))
2604 (setq bytes (+ bytes bs 2))
2607 (setq bytes (+ bs 1))
2615 (if (re-search-forward
2616 "Content-Transfer-Encoding:" nil t)
2617 (let ((beg (match-beginning 0))
2618 (hbeg (match-end 0))
2619 (end (std11-field-end)))
2621 (eliminate-top-spaces
2622 (std11-unfold-string
2623 (buffer-substring hbeg end))))
2624 (if (or charset (eq type 'text))
2626 (delete-region beg (1+ end))
2627 (goto-char (point-min))
2628 (if (search-forward "\n\n" nil t)
2631 (match-end 0)(point-max) encoding)
2635 (if (or encoded (not not-decode-text))
2636 (decode-mime-charset-region
2637 (point-min)(point-max)
2638 (or charset default-mime-charset))
2641 (if (re-search-forward "^$" nil t)
2645 (if (= (point-min) 1)
2651 (format "%s/%s%s" type stype pstr)
2654 (delete-region (point-min) he)
2657 (format "%s/%s%s" type stype pstr)
2662 (decode-mime-charset-region (point-min) (point-max)
2663 default-mime-charset)
2667 (defun mime-edit-again (&optional not-decode-text no-separator not-turn-on)
2668 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode.
2669 Content-Type and Content-Transfer-Encoding header fields will be
2670 converted to MIME-Edit tags."
2672 (goto-char (point-min))
2674 (concat "\n" (regexp-quote mail-header-separator) "\n")
2676 (replace-match "\n\n")
2678 (mime-edit-decode-buffer not-decode-text)
2679 (goto-char (point-min))
2681 (std11-narrow-to-header)
2682 (goto-char (point-min))
2683 (while (re-search-forward mime-edit-again-ignored-field-regexp nil t)
2684 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2687 (and (re-search-forward "^$")
2688 (replace-match mail-header-separator)
2698 (provide 'mime-edit)
2700 (run-hooks 'mime-edit-load-hook)
2702 ;;; mime-edit.el ends here