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")
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"))
218 ("server" "ftpmail@nic.karrn.ad.jp")
226 ("octet-stream" ("type" "" "tar" "shar"))
228 ("x-kiss" ("x-cnf")))
242 "*Alist of content-type, subtype, parameters and its values.")
244 (defcustom mime-file-types
248 "inline" (("filename" . file))
253 "inline" (("filename" . file))
256 "text" "richtext" nil
264 "application" "postscript" nil
266 "attachment" (("filename" . file))
271 "inline" (("filename" . file))
276 "inline" (("filename" . file))
281 "inline" (("filename" . file))
286 "inline" (("filename" . file))
291 "inline" (("filename" . file))
296 "inline" (("filename" . file))
301 "inline" (("filename" . file))
306 "inline" (("filename" . file))
311 "attachment" (("filename" . file))
316 "attachment" (("filename" . file))
319 "application" "octet-stream" (("type" . "emacs-lisp"))
321 "attachment" (("filename" . file))
324 "application" "octet-stream" (("type" . "common-lisp"))
326 "attachment" (("filename" . file))
329 "application" "octet-stream" (("type" . "tar+gzip"))
331 "attachment" (("filename" . file))
334 "application" "octet-stream" (("type" . "tar+gzip"))
336 "attachment" (("filename" . file))
339 "application" "octet-stream" (("type" . "tar+compress"))
341 "attachment" (("filename" . file))
344 "application" "octet-stream" (("type" . "tar+compress"))
346 "attachment" (("filename" . file))
349 "application" "octet-stream" (("type" . "gzip"))
351 "attachment" (("filename" . file))
354 "application" "octet-stream" (("type" . "compress"))
356 "attachment" (("filename" . file))
359 "application" "octet-stream" (("type" . "lha"))
361 "attachment" (("filename" . file))
364 "application" "zip" nil
366 "attachment" (("filename" . file))
369 "application" "octet-stream" (("type" . "patch"))
371 "attachment" (("filename" . file))
374 "application" "octet-stream" (("type" . "patch"))
376 "attachment" (("filename" . file))
379 "text" "plain" nil nil nil nil)
381 "application" "octet-stream" nil
383 "attachment" (("filename" . file)))
385 "*Alist of file name, types, parameters, and default encoding.
386 If encoding is nil, it is determined from its contents."
390 (choice :tag "Primary-Type"
391 ,@(nconc (mapcar (lambda (cell)
392 (list 'item (car cell))
397 (choice :tag "Sub-Type"
400 (mapcar (lambda (cell)
401 (mapcar (lambda (cell)
402 (list 'item (car cell))
408 (repeat :tag "Parameters of Content-Type field"
409 (cons string (choice string symbol)))
410 ;; content-transfer-encoding
411 (choice :tag "Encoding"
414 (mapcar (lambda (cell)
415 (list 'item (car cell))
417 mime-file-encoding-method-alist)))
419 (choice :tag "Disposition-Type"
425 (repeat :tag "Parameters of Content-Disposition field"
426 (cons string (choice string symbol)))
431 ;;; @@ about charset, encoding and transfer-level
434 (defvar mime-charset-type-list
436 (iso-8859-1 8 "quoted-printable")
437 (iso-8859-2 8 "quoted-printable")
438 (iso-8859-3 8 "quoted-printable")
439 (iso-8859-4 8 "quoted-printable")
440 (iso-8859-5 8 "quoted-printable")
441 (koi8-r 8 "quoted-printable")
442 (iso-8859-7 8 "quoted-printable")
443 (iso-8859-8 8 "quoted-printable")
444 (iso-8859-9 8 "quoted-printable")
445 (iso-2022-jp 7 "base64")
446 (iso-2022-kr 7 "base64")
448 (cn-gb2312 8 "base64")
452 (shift_jis 8 "base64")
453 (iso-2022-jp-2 7 "base64")
454 (iso-2022-int-1 7 "base64")
457 (defvar mime-transfer-level 7
458 "*A number of network transfer level. It should be bigger than 7.")
459 (make-variable-buffer-local 'mime-transfer-level)
461 (defsubst mime-encoding-name (transfer-level &optional not-omit)
462 (cond ((> transfer-level 8) "binary")
463 ((= transfer-level 8) "8bit")
467 (defvar mime-transfer-level-string
468 (mime-encoding-name mime-transfer-level 'not-omit)
469 "A string formatted version of mime-transfer-level")
470 (make-variable-buffer-local 'mime-transfer-level-string)
473 ;;; @@ about message inserting
476 (defvar mime-edit-yank-ignored-field-list
477 '("Received" "Approved" "Path" "Replied" "Status"
478 "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
479 "Delete these fields from original message when it is inserted
480 as message/rfc822 part.
481 Each elements are regexp of field-name.")
483 (defvar mime-edit-yank-ignored-field-regexp
485 (apply (function regexp-or) mime-edit-yank-ignored-field-list)
488 (defvar mime-edit-message-inserter-alist nil)
489 (defvar mime-edit-mail-inserter-alist nil)
492 ;;; @@ about message splitting
495 (defcustom mime-edit-split-message t
496 "*Split large message if it is non-nil."
500 (defcustom mime-edit-message-default-max-lines 1000
501 "*Default maximum lines of a message."
505 (defcustom mime-edit-message-max-lines-alist
506 '((news-reply-mode . 500))
507 "Alist of major-mode vs maximum lines of a message.
508 If it is not specified for a major-mode,
509 `mime-edit-message-default-max-lines' is used."
513 (defconst mime-edit-split-ignored-field-regexp
514 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\|Message-Id:\\)")
516 (defcustom mime-edit-split-blind-field-regexp
517 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)"
518 "*Regular expression to match field-name to be ignored when split sending."
522 (defvar mime-edit-split-message-sender-alist nil)
524 (defvar mime-edit-news-reply-mode-server-running nil)
530 (defconst mime-edit-single-part-tag-regexp
531 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
532 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
534 (defconst mime-edit-quoted-single-part-tag-regexp
535 (concat "- " (substring mime-edit-single-part-tag-regexp 1)))
537 (defconst mime-edit-multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
539 (defconst mime-edit-multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
541 (defconst mime-edit-beginning-tag-regexp
542 (regexp-or mime-edit-single-part-tag-regexp
543 mime-edit-multipart-beginning-regexp))
545 (defconst mime-edit-end-tag-regexp
546 (regexp-or mime-edit-single-part-tag-regexp
547 mime-edit-multipart-end-regexp))
549 (defconst mime-edit-tag-regexp
550 (regexp-or mime-edit-single-part-tag-regexp
551 mime-edit-multipart-beginning-regexp
552 mime-edit-multipart-end-regexp))
554 (defvar mime-tag-format "--[[%s]]"
555 "*Control-string making a MIME tag.")
557 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
558 "*Control-string making a MIME tag with encoding.")
561 ;;; @@ multipart boundary
564 (defvar mime-multipart-boundary "Multipart"
565 "*Boundary of a multipart message.")
568 ;;; @@ optional header fields
571 (defvar mime-edit-insert-x-emacs-field t
572 "*If non-nil, insert X-Emacs header field.")
574 (defvar mime-edit-x-emacs-value
575 (if (featurep 'xemacs)
576 (concat emacs-version (if (featurep 'mule)
579 (let ((ver (if (string-match "\\.[0-9]+$" emacs-version)
580 (substring emacs-version 0 (match-beginning 0))
583 (if (boundp 'enable-multibyte-characters)
585 (if enable-multibyte-characters
586 (concat ", MULE " mule-version)
587 " (with raw setting)")
588 (if (featurep 'meadow)
589 (concat ", " (Meadow-version))
591 (concat "MULE " mule-version " based on Emacs " ver))
593 "Body of X-Emacs field.
594 If variable `mime-edit-insert-x-emacs-field' is not nil, it is
595 inserted into message header.")
601 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
602 "*Specify MIME tspecials.
603 Tspecials means any character that matches with it in header must be quoted.")
605 (defconst mime-edit-mime-version-value
606 (concat "1.0 (generated by " mime-edit-version-string ")")
607 "MIME version number.")
609 (defconst mime-edit-mime-version-field-for-message/partial
610 (concat "MIME-Version: 1.0 (split by " mime-edit-version-string ")\n")
611 "MIME version field for message/partial.")
614 ;;; @ keymap and menu
617 (defvar mime-edit-mode-flag nil)
618 (make-variable-buffer-local 'mime-edit-mode-flag)
620 (defvar mime-edit-mode-entity-prefix "\C-c\C-x"
621 "Keymap prefix for MIME-Edit mode commands to insert entity or set status.")
622 (defvar mime-edit-mode-entity-map (make-sparse-keymap)
623 "Keymap for MIME-Edit mode commands to insert entity or set status.")
625 (define-key mime-edit-mode-entity-map "\C-t" 'mime-edit-insert-text)
626 (define-key mime-edit-mode-entity-map "\C-i" 'mime-edit-insert-file)
627 (define-key mime-edit-mode-entity-map "\C-e" 'mime-edit-insert-external)
628 (define-key mime-edit-mode-entity-map "\C-v" 'mime-edit-insert-voice)
629 (define-key mime-edit-mode-entity-map "\C-y" 'mime-edit-insert-message)
630 (define-key mime-edit-mode-entity-map "\C-m" 'mime-edit-insert-mail)
631 (define-key mime-edit-mode-entity-map "\C-w" 'mime-edit-insert-signature)
632 (define-key mime-edit-mode-entity-map "\C-s" 'mime-edit-insert-signature)
633 (define-key mime-edit-mode-entity-map "\C-k" 'mime-edit-insert-key)
634 (define-key mime-edit-mode-entity-map "t" 'mime-edit-insert-tag)
636 (define-key mime-edit-mode-entity-map "7" 'mime-edit-set-transfer-level-7bit)
637 (define-key mime-edit-mode-entity-map "8" 'mime-edit-set-transfer-level-8bit)
638 (define-key mime-edit-mode-entity-map "/" 'mime-edit-set-split)
639 (define-key mime-edit-mode-entity-map "s" 'mime-edit-set-sign)
640 (define-key mime-edit-mode-entity-map "v" 'mime-edit-set-sign)
641 (define-key mime-edit-mode-entity-map "e" 'mime-edit-set-encrypt)
642 (define-key mime-edit-mode-entity-map "h" 'mime-edit-set-encrypt)
643 (define-key mime-edit-mode-entity-map "p" 'mime-edit-preview-message)
644 (define-key mime-edit-mode-entity-map "\C-z" 'mime-edit-exit)
645 (define-key mime-edit-mode-entity-map "?" 'mime-edit-help)
647 (defvar mime-edit-mode-enclosure-prefix "\C-c\C-m"
648 "Keymap prefix for MIME-Edit mode commands about enclosure.")
649 (defvar mime-edit-mode-enclosure-map (make-sparse-keymap)
650 "Keymap for MIME-Edit mode commands about enclosure.")
652 (define-key mime-edit-mode-enclosure-map
653 "\C-a" 'mime-edit-enclose-alternative-region)
654 (define-key mime-edit-mode-enclosure-map
655 "\C-p" 'mime-edit-enclose-parallel-region)
656 (define-key mime-edit-mode-enclosure-map
657 "\C-m" 'mime-edit-enclose-mixed-region)
658 (define-key mime-edit-mode-enclosure-map
659 "\C-d" 'mime-edit-enclose-digest-region)
660 (define-key mime-edit-mode-enclosure-map
661 "\C-s" 'mime-edit-enclose-pgp-signed-region)
662 (define-key mime-edit-mode-enclosure-map
663 "\C-e" 'mime-edit-enclose-pgp-encrypted-region)
664 (define-key mime-edit-mode-enclosure-map
665 "\C-q" 'mime-edit-enclose-quote-region)
667 (defvar mime-edit-mode-map (make-sparse-keymap)
668 "Keymap for MIME-Edit mode commands.")
669 (define-key mime-edit-mode-map
670 mime-edit-mode-entity-prefix mime-edit-mode-entity-map)
671 (define-key mime-edit-mode-map
672 mime-edit-mode-enclosure-prefix mime-edit-mode-enclosure-map)
674 (defconst mime-edit-menu-title "MIME-Edit")
676 (defconst mime-edit-menu-list
677 '((mime-help "Describe MIME editor mode" mime-edit-help)
678 (file "Insert File" mime-edit-insert-file)
679 (external "Insert External" mime-edit-insert-external)
680 (voice "Insert Voice" mime-edit-insert-voice)
681 (message "Insert Message" mime-edit-insert-message)
682 (mail "Insert Mail" mime-edit-insert-mail)
683 (signature "Insert Signature" mime-edit-insert-signature)
684 (text "Insert Text" mime-edit-insert-text)
685 (tag "Insert Tag" mime-edit-insert-tag)
686 (alternative "Enclose as alternative"
687 mime-edit-enclose-alternative-region)
688 (parallel "Enclose as parallel" mime-edit-enclose-parallel-region)
689 (mixed "Enclose as serial" mime-edit-enclose-mixed-region)
690 (digest "Enclose as digest" mime-edit-enclose-digest-region)
691 (signed "Enclose as signed" mime-edit-enclose-pgp-signed-region)
692 (encrypted "Enclose as encrypted" mime-edit-enclose-pgp-encrypted-region)
693 (quote "Verbatim region" mime-edit-enclose-quote-region)
694 (key "Insert Public Key" mime-edit-insert-key)
695 (split "About split" mime-edit-set-split)
696 (sign "About sign" mime-edit-set-sign)
697 (encrypt "About encryption" mime-edit-set-encrypt)
698 (preview "Preview Message" mime-edit-preview-message)
699 (level "Toggle transfer-level" mime-edit-toggle-transfer-level)
701 "MIME-edit menubar entry.")
703 (cond (running-xemacs
704 ;; modified by Pekka Marjola <pema@iki.fi>
705 ;; 1995/9/5 (c.f. [tm-en:69])
706 (defun mime-edit-define-menu-for-xemacs ()
707 "Define menu for XEmacs."
708 (cond ((featurep 'menubar)
709 (make-local-variable 'current-menubar)
710 (set-buffer-menubar current-menubar)
713 (cons mime-edit-menu-title
716 (vector (nth 1 item)(nth 2 item)
719 mime-edit-menu-list)))
722 ;; modified by Steven L. Baur <steve@miranova.com>
723 ;; 1995/12/6 (c.f. [tm-en:209])
724 (or (boundp 'mime-edit-popup-menu-for-xemacs)
725 (setq mime-edit-popup-menu-for-xemacs
726 (append '("MIME Commands" "---")
727 (mapcar (function (lambda (item)
731 mime-edit-menu-list)))
734 ((>= emacs-major-version 19)
735 (define-key mime-edit-mode-map [menu-bar mime-edit]
736 (cons mime-edit-menu-title
737 (make-sparse-keymap mime-edit-menu-title)))
740 (define-key mime-edit-mode-map
741 (vector 'menu-bar 'mime-edit (car item))
742 (cons (nth 1 item)(nth 2 item))
745 (reverse mime-edit-menu-list)
753 (defvar mime-edit-touched-flag nil)
756 (defun mime-edit-mode ()
757 "MIME minor mode for editing the tagged MIME message.
759 In this mode, basically, the message is composed in the tagged MIME
760 format. The message tag looks like:
762 --[[text/plain; charset=ISO-2022-JP][7bit]]
764 The tag specifies the MIME content type, subtype, optional parameters
765 and transfer encoding of the message following the tag. Messages
766 without any tag are treated as `text/plain' by default. Charset and
767 transfer encoding are automatically defined unless explicitly
768 specified. Binary messages such as audio and image are usually
769 hidden. The messages in the tagged MIME format are automatically
770 translated into a MIME compliant message when exiting this mode.
772 Available charsets depend on Emacs version being used. The following
773 lists the available charsets of each emacs.
775 Without mule: US-ASCII and ISO-8859-1 (or other charset) are available.
776 With mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
777 ISO-2022-JP, ISO-2022-JP-2, EUC-KR, CN-GB-2312,
778 CN-BIG5 and ISO-2022-INT-1 are available.
780 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
781 be used to represent multilingual text in intermixed manner. Any
782 languages that has no registered charset are represented as either
783 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
785 If you want to use non-ISO-8859-1 charset in Emacs 19 or XEmacs
786 without mule, please set variable `default-mime-charset'. This
787 variable must be symbol of which name is a MIME charset.
789 If you want to add more charsets in mule, please set variable
790 `charsets-mime-charset-alist'. This variable must be alist of which
791 key is list of charset and value is symbol of MIME charset. If name
792 of coding-system is different as MIME charset, please set variable
793 `mime-charset-coding-system-alist'. This variable must be alist of
794 which key is MIME charset and value is coding-system.
796 Following commands are available in addition to major mode commands:
799 \\[mime-edit-insert-text] insert a text message.
800 \\[mime-edit-insert-file] insert a (binary) file.
801 \\[mime-edit-insert-external] insert a reference to external body.
802 \\[mime-edit-insert-voice] insert a voice message.
803 \\[mime-edit-insert-message] insert a mail or news message.
804 \\[mime-edit-insert-mail] insert a mail message.
805 \\[mime-edit-insert-signature] insert a signature file at end.
806 \\[mime-edit-insert-key] insert PGP public key.
807 \\[mime-edit-insert-tag] insert a new MIME tag.
809 \[make enclosure (maybe multipart)\]
810 \\[mime-edit-enclose-alternative-region] enclose as multipart/alternative.
811 \\[mime-edit-enclose-parallel-region] enclose as multipart/parallel.
812 \\[mime-edit-enclose-mixed-region] enclose as multipart/mixed.
813 \\[mime-edit-enclose-digest-region] enclose as multipart/digest.
814 \\[mime-edit-enclose-pgp-signed-region] enclose as PGP signed.
815 \\[mime-edit-enclose-pgp-encrypted-region] enclose as PGP encrypted.
816 \\[mime-edit-enclose-quote-region] enclose as verbose mode
817 (to avoid to expand tags)
820 \\[mime-edit-set-transfer-level-7bit] set transfer-level as 7.
821 \\[mime-edit-set-transfer-level-8bit] set transfer-level as 8.
822 \\[mime-edit-set-split] set message splitting mode.
823 \\[mime-edit-set-sign] set PGP-sign mode.
824 \\[mime-edit-set-encrypt] set PGP-encryption mode.
825 \\[mime-edit-preview-message] preview editing MIME message.
826 \\[mime-edit-exit] exit and translate into a MIME
828 \\[mime-edit-help] show this help.
829 \\[mime-edit-maybe-translate] exit and translate if in MIME mode,
832 Additional commands are available in some major modes:
833 C-c C-c exit, translate and run the original command.
834 C-c C-s exit, translate and run the original command.
836 The following is a message example written in the tagged MIME format.
837 TABs at the beginning of the line are not a part of the message:
839 This is a conventional plain text. It should be translated
842 This is also a plain text. But, it is explicitly specified as
844 --[[text/plain; charset=ISO-8859-1]]
845 This is also a plain text. But charset is specified as
848 ¡Hola! Buenos días. ¿Cómo está usted?
850 This is a <bold>enriched text</bold>.
851 --[[image/gif][base64]]...image encoded in base64 here...
852 --[[audio/basic][base64]]...audio encoded in base64 here...
854 User customizable variables (not documented all of them):
856 Specifies a key prefix for MIME minor mode commands.
858 mime-ignore-preceding-spaces
859 Preceding white spaces in a message body are ignored if non-nil.
861 mime-ignore-trailing-spaces
862 Trailing white spaces in a message body are ignored if non-nil.
865 Hide a non-textual body message encoded in base64 after insertion
869 A number of network transfer level. It should be bigger than 7.
870 If you are in 8bit-through environment, please set 8.
872 mime-edit-voice-recorder
873 Specifies a function to record a voice message and encode it.
874 The function `mime-edit-voice-recorder-for-sun' is for Sun
878 Turning on MIME mode calls the value of mime-edit-mode-hook, if
881 mime-edit-translate-hook
882 The value of mime-edit-translate-hook is called just before translating
883 the tagged MIME format into a MIME compliant message if it is
884 non-nil. If the hook call the function mime-edit-insert-signature,
885 the signature file will be inserted automatically.
888 Turning off MIME mode calls the value of mime-edit-exit-hook, if it is
891 (if mime-edit-mode-flag
893 (if mime-edit-touched-flag
895 (make-local-variable 'mime-edit-touched-flag)
896 (setq mime-edit-touched-flag t)
901 (cond (running-xemacs
902 (add-minor-mode 'mime-edit-mode-flag
903 '((" MIME-Edit " mime-transfer-level-string))
909 (set-alist 'minor-mode-alist
911 '((" MIME-Edit " mime-transfer-level-string)))
912 (set-alist 'minor-mode-map-alist
919 (defun turn-on-mime-edit ()
920 "Unconditionally turn on MIME-Edit mode."
922 (if mime-edit-mode-flag
923 (error "You are already editing a MIME message.")
924 (setq mime-edit-mode-flag t)
926 ;; Set transfer level into mode line
928 (setq mime-transfer-level-string
929 (mime-encoding-name mime-transfer-level 'not-omit))
930 (force-mode-line-update)
932 ;; Define menu for XEmacs.
934 (mime-edit-define-menu-for-xemacs)
939 ;; I don't care about saving these.
940 (setq paragraph-start
941 (regexp-or mime-edit-single-part-tag-regexp
943 (setq paragraph-separate
944 (regexp-or mime-edit-single-part-tag-regexp
946 (run-hooks 'mime-edit-mode-hook)
948 (substitute-command-keys
949 "Type \\[mime-edit-exit] to exit MIME mode, and type \\[mime-edit-help] to get help."))
953 (defalias 'edit-mime 'turn-on-mime-edit) ; for convenience
956 (defun mime-edit-exit (&optional nomime no-error)
957 "Translate the tagged MIME message into a MIME compliant message.
958 With no argument encode a message in the buffer into MIME, otherwise
959 just return to previous mode."
961 (if (not mime-edit-mode-flag)
963 (error "You aren't editing a MIME message.")
967 (run-hooks 'mime-edit-translate-hook)
968 (mime-edit-translate-buffer)))
969 ;; Restore previous state.
970 (setq mime-edit-mode-flag nil)
971 (if (and running-xemacs
973 (delete-menu-item (list mime-edit-menu-title))
976 (set-buffer-modified-p (buffer-modified-p))
977 (run-hooks 'mime-edit-exit-hook)
978 (message "Exit MIME editor mode.")
981 (defun mime-edit-maybe-translate ()
983 (mime-edit-exit nil t)
984 (call-interactively 'mime-edit-maybe-split-and-send)
987 (defun mime-edit-help ()
988 "Show help message about MIME mode."
990 (with-output-to-temp-buffer "*Help*"
991 (princ "MIME editor mode:\n")
992 (princ (documentation 'mime-edit-mode))
993 (print-help-return-message)))
995 (defun mime-edit-insert-text (&optional subtype)
996 "Insert a text message.
997 Charset is automatically obtained from the `charsets-mime-charset-alist'.
998 If optional argument SUBTYPE is not nil, text/SUBTYPE tag is inserted."
1000 (let ((ret (mime-edit-insert-tag "text" subtype nil)))
1002 (if (looking-at mime-edit-single-part-tag-regexp)
1004 ;; Make a space between the following message.
1008 (if (and (member (cadr ret) '("enriched" "richtext"))
1009 (fboundp 'enriched-mode)
1012 (if (boundp 'enriched-mode)
1017 (defun mime-edit-insert-file (file &optional verbose)
1018 "Insert a message from a file."
1019 (interactive "fInsert file as MIME message: \nP")
1020 (let* ((guess (mime-find-file-type file))
1021 (type (nth 0 guess))
1022 (subtype (nth 1 guess))
1023 (parameters (nth 2 guess))
1024 (encoding (nth 3 guess))
1025 (disposition-type (nth 4 guess))
1026 (disposition-params (nth 5 guess))
1029 (setq type (mime-prompt-for-type type)
1030 subtype (mime-prompt-for-subtype type subtype)
1032 (if (or (interactive-p) verbose)
1033 (setq encoding (mime-prompt-for-encoding encoding))
1035 (if (or (consp parameters) (stringp disposition-type))
1036 (let ((rest parameters) cell attribute value)
1037 (setq parameters "")
1039 (setq cell (car rest))
1040 (setq attribute (car cell))
1041 (setq value (cdr cell))
1042 (if (eq value 'file)
1043 (setq value (std11-wrap-as-quoted-string
1044 (file-name-nondirectory file)))
1046 (setq parameters (concat parameters "; " attribute "=" value))
1047 (setq rest (cdr rest))
1049 (if disposition-type
1052 (concat parameters "\n"
1053 "Content-Disposition: " disposition-type))
1054 (setq rest disposition-params)
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)))
1064 (concat parameters "; " attribute "=" value))
1065 (setq rest (cdr rest))
1069 (mime-edit-insert-tag type subtype parameters)
1070 (mime-edit-insert-binary-file file encoding)
1073 (defun mime-edit-insert-external ()
1074 "Insert a reference to external body."
1076 (mime-edit-insert-tag "message" "external-body" nil ";\n\t")
1078 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
1080 (let* ((pritype (mime-prompt-for-type))
1081 (subtype (mime-prompt-for-subtype pritype))
1082 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
1085 (insert "Content-Type: "
1086 pritype "/" subtype (or parameters "") "\n")))
1087 (if (and (not (eobp))
1088 (not (looking-at mime-edit-single-part-tag-regexp)))
1089 (insert (mime-make-text-tag) "\n")))
1091 (defun mime-edit-insert-voice ()
1092 "Insert a voice message."
1096 "What transfer encoding: "
1097 mime-file-encoding-method-alist nil t nil)))
1098 (mime-edit-insert-tag "audio" "basic" nil)
1099 (mime-edit-define-encoding encoding)
1101 (narrow-to-region (1- (point))(point))
1103 (funcall mime-edit-voice-recorder encoding)
1106 (invisible-region (point-min)(point-max))
1107 (goto-char (point-max))
1110 (defun mime-edit-insert-signature (&optional arg)
1111 "Insert a signature file."
1113 (let ((signature-insert-hook
1116 (let ((items (mime-find-file-type signature-file-name)))
1117 (apply (function mime-edit-insert-tag)
1118 (car items) (cadr items) (list (caddr items))))
1121 (insert-signature arg)
1125 ;; Insert a new tag around a point.
1127 (defun mime-edit-insert-tag (&optional pritype subtype parameters delimiter)
1128 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
1129 If nothing is inserted, return nil."
1132 (mime-edit-goto-tag)
1133 (if (and (re-search-forward mime-edit-tag-regexp nil t)
1134 (< (match-beginning 0) p)
1137 (goto-char (match-beginning 0))
1146 (mime-prompt-for-type)))
1149 (mime-prompt-for-subtype pritype)))
1152 (mime-prompt-for-parameters pritype subtype delimiter)))
1153 ;; Make a new MIME tag.
1154 (setq newtag (mime-make-tag pritype subtype parameters))
1155 ;; Find an current MIME tag.
1158 (if (mime-edit-goto-tag)
1159 (buffer-substring (match-beginning 0) (match-end 0))
1160 ;; Assume content type is 'text/plan'.
1161 (mime-make-tag "text" "plain")
1163 ;; We are only interested in TEXT.
1165 (not (mime-test-content-type
1166 (mime-edit-get-contype oldtag) "text")))
1169 (if (or (not oldtag) ;Not text
1170 (or mime-ignore-same-text-tag
1171 (not (string-equal oldtag newtag))))
1173 ;; Mark the beginning of the tag for convenience.
1174 (push-mark (point) 'nomsg)
1175 (insert newtag "\n")
1176 (list pritype subtype parameters) ;New tag is created.
1178 ;; Restore previous point.
1180 nil ;Nothing is created.
1184 (defun mime-edit-insert-binary-file (file &optional encoding)
1185 "Insert binary FILE at point.
1186 Optional argument ENCODING specifies an encoding method such as base64."
1187 (let* ((tagend (1- (point))) ;End of the tag
1188 (hide-p (and mime-auto-hide-body
1191 (let ((en (downcase encoding)))
1192 (or (string-equal en "7bit")
1193 (string-equal en "8bit")
1194 (string-equal en "binary")
1198 (narrow-to-region tagend (point))
1199 (mime-insert-encoded-file file encoding)
1202 (invisible-region (point-min) (point-max))
1203 (goto-char (point-max))
1205 (goto-char (point-max))
1208 (looking-at mime-edit-tag-regexp)
1209 (= (point)(point-max))
1210 (mime-edit-insert-tag "text" "plain")
1212 ;; Define encoding even if it is 7bit.
1213 (if (stringp encoding)
1215 (goto-char tagend) ; Make sure which line the tag is on.
1216 (mime-edit-define-encoding encoding)
1221 ;; Commands work on a current message flagment.
1223 (defun mime-edit-goto-tag ()
1224 "Search for the beginning of the tagged MIME message."
1225 (let ((current (point)))
1226 (if (looking-at mime-edit-tag-regexp)
1228 ;; At first, go to the end.
1229 (cond ((re-search-forward mime-edit-beginning-tag-regexp nil t)
1230 (goto-char (1- (match-beginning 0))) ;For multiline tag
1233 (goto-char (point-max))
1235 ;; Then search for the beginning.
1236 (re-search-backward mime-edit-end-tag-regexp nil t)
1237 (or (looking-at mime-edit-beginning-tag-regexp)
1238 ;; Restore previous point.
1245 (defun mime-edit-content-beginning ()
1246 "Return the point of the beginning of content."
1248 (let ((beg (save-excursion
1249 (beginning-of-line) (point))))
1250 (if (mime-edit-goto-tag)
1251 (let ((top (point)))
1252 (goto-char (match-end 0))
1253 (if (and (= beg top)
1254 (= (following-char) ?\^M))
1258 ;; Default text/plain tag.
1259 (goto-char (point-min))
1261 (concat "\n" (regexp-quote mail-header-separator)
1262 (if mime-ignore-preceding-spaces
1263 "[ \t\n]*\n" "\n")) nil 'move)
1267 (defun mime-edit-content-end ()
1268 "Return the point of the end of content."
1270 (if (mime-edit-goto-tag)
1272 (goto-char (match-end 0))
1273 (if (invisible-p (point))
1274 (next-visible-point (point))
1275 ;; Move to the end of this text.
1276 (if (re-search-forward mime-edit-tag-regexp nil 'move)
1277 ;; Don't forget a multiline tag.
1278 (goto-char (match-beginning 0))
1282 ;; Assume the message begins with text/plain.
1283 (goto-char (mime-edit-content-beginning))
1284 (if (re-search-forward mime-edit-tag-regexp nil 'move)
1285 ;; Don't forget a multiline tag.
1286 (goto-char (match-beginning 0)))
1290 (defun mime-edit-define-charset (charset)
1291 "Set charset of current tag to CHARSET."
1293 (if (mime-edit-goto-tag)
1294 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1295 (delete-region (match-beginning 0) (match-end 0))
1298 (mime-edit-set-parameter
1299 (mime-edit-get-contype tag)
1300 "charset" (upcase (symbol-name charset)))
1301 (mime-edit-get-encoding tag)))
1304 (defun mime-edit-define-encoding (encoding)
1305 "Set encoding of current tag to ENCODING."
1307 (if (mime-edit-goto-tag)
1308 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1309 (delete-region (match-beginning 0) (match-end 0))
1310 (insert (mime-create-tag (mime-edit-get-contype tag) encoding)))
1313 (defun mime-edit-choose-charset ()
1314 "Choose charset of a text following current point."
1315 (detect-mime-charset-region (point) (mime-edit-content-end))
1318 (defun mime-make-text-tag (&optional subtype)
1319 "Make a tag for a text after current point.
1320 Subtype of text type can be specified by an optional argument SUBTYPE.
1321 Otherwise, it is obtained from mime-content-types."
1322 (let* ((pritype "text")
1323 (subtype (or subtype
1324 (car (car (cdr (assoc pritype mime-content-types)))))))
1325 ;; Charset should be defined later.
1326 (mime-make-tag pritype subtype)))
1329 ;; Tag handling functions
1331 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1332 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1333 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1337 (defun mime-create-tag (contype &optional encoding)
1338 "Make a tag with CONTENT-TYPE and optional ENCODING."
1339 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1342 (defun mime-edit-get-contype (tag)
1343 "Return Content-Type (including parameters) of TAG."
1345 (or (string-match mime-edit-single-part-tag-regexp tag)
1346 (string-match mime-edit-multipart-beginning-regexp tag)
1347 (string-match mime-edit-multipart-end-regexp tag)
1349 (substring tag (match-beginning 1) (match-end 1))
1352 (defun mime-edit-get-encoding (tag)
1353 "Return encoding of TAG."
1355 (string-match mime-edit-single-part-tag-regexp tag)
1357 (not (= (match-beginning 3) (match-end 3)))
1358 (substring tag (match-beginning 3) (match-end 3))))
1360 (defun mime-get-parameter (contype parameter)
1361 "For given CONTYPE return value for PARAMETER.
1362 Nil if no such parameter."
1366 (regexp-quote parameter)
1367 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1369 (substring contype (match-beginning 1) (match-end 1))
1370 nil ;No such parameter
1373 (defun mime-edit-set-parameter (contype parameter value)
1374 "For given CONTYPE set PARAMETER to VALUE."
1375 (let (ctype opt-fields)
1376 (if (string-match "\n[^ \t\n\r]+:" contype)
1377 (setq ctype (substring contype 0 (match-beginning 0))
1378 opt-fields (substring contype (match-beginning 0)))
1379 (setq ctype contype)
1384 (regexp-quote parameter)
1385 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1388 (concat (substring ctype 0 (match-beginning 1))
1390 (substring contype (match-end 1))
1392 (concat ctype "; " parameter "=" value opt-fields)
1395 (defun mime-strip-parameters (contype)
1396 "Return primary content-type and subtype without parameters for CONTYPE."
1397 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1398 (substring contype (match-beginning 1) (match-end 1)) nil))
1400 (defun mime-test-content-type (contype type &optional subtype)
1401 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1402 (and (stringp contype)
1405 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1406 (downcase contype))))
1411 (defun mime-find-file-type (file)
1412 "Guess Content-Type, subtype, and parameters from FILE."
1414 (guesses mime-file-types))
1415 (while (and (not guess) guesses)
1416 (if (string-match (car (car guesses)) file)
1417 (setq guess (cdr (car guesses))))
1418 (setq guesses (cdr guesses)))
1422 (defun mime-prompt-for-type (&optional default)
1423 "Ask for Content-type."
1425 ;; Repeat until primary content type is specified.
1426 (while (string-equal type "")
1428 (completing-read "What content type: "
1431 'require-match ;Type must be specified.
1434 (if (string-equal type "")
1436 (message "Content type is required.")
1443 (defun mime-prompt-for-subtype (type &optional default)
1444 "Ask for subtype of media-type TYPE."
1445 (let ((subtypes (cdr (assoc type mime-content-types))))
1447 (assoc default subtypes))
1448 (setq default (car (car subtypes)))
1454 "What content subtype: (default " default ") ")
1455 "What content subtype: ")
1456 (cdr (assoc type mime-content-types))
1458 'require-match ;Subtype must be specified.
1461 (if (string-equal answer "") default answer)))
1463 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1464 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1465 Optional DELIMITER specifies parameter delimiter (';' by default)."
1466 (let* ((delimiter (or delimiter "; "))
1471 (mime-prompt-for-parameters-1
1473 (cdr (assoc pritype mime-content-types))))))
1476 (if (and (stringp parameters)
1477 (not (string-equal parameters "")))
1478 (concat delimiter parameters)
1479 "" ;"" if no parameters
1482 (defun mime-prompt-for-parameters-1 (optlist)
1483 (apply (function append)
1484 (mapcar (function mime-prompt-for-parameter) optlist)))
1486 (defun mime-prompt-for-parameter (parameter)
1488 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1489 (let* ((prompt (car parameter))
1490 (choices (mapcar (function
1492 (if (consp e) e (list e))))
1494 (default (car (car choices)))
1500 (concat "What " prompt
1502 (if (string-equal default "") "\"\"" default)
1504 choices nil nil ""))
1505 ;; If nothing is selected, use default.
1506 (if (string-equal answer "")
1507 (setq answer default)))
1509 (read-string (concat "What " prompt ": "))))
1510 (cons (if (and answer
1511 (not (string-equal answer "")))
1513 ;; Note: control characters ignored!
1514 (if (string-match mime-tspecials-regexp answer)
1515 (concat "\"" answer "\"") answer)))
1516 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1519 (defun mime-prompt-for-encoding (default)
1520 "Ask for Content-Transfer-Encoding."
1525 "What transfer encoding: "
1526 mime-file-encoding-method-alist nil t default)
1532 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1535 (defvar mime-edit-translate-buffer-hook
1536 '(mime-edit-pgp-enclose-buffer
1537 mime-edit-translate-body
1538 mime-edit-translate-header))
1540 (defun mime-edit-translate-header ()
1541 "Encode the message header into network representation."
1542 (eword-encode-header 'code-conversion)
1543 (run-hooks 'mime-edit-translate-header-hook)
1546 (defun mime-edit-translate-buffer ()
1547 "Encode the tagged MIME message in current buffer in MIME compliant message."
1549 (if (catch 'mime-edit-error
1551 (run-hooks 'mime-edit-translate-buffer-hook)
1555 (error "Translation error!")
1558 (defun mime-edit-find-inmost ()
1559 (goto-char (point-min))
1560 (if (re-search-forward mime-edit-multipart-beginning-regexp nil t)
1561 (let ((bb (match-beginning 0))
1563 (type (buffer-substring (match-beginning 1)(match-end 1)))
1565 (setq end-exp (format "--}-<<%s>>\n" type))
1567 (if (re-search-forward end-exp nil t)
1568 (setq eb (match-beginning 0))
1569 (setq eb (point-max))
1571 (narrow-to-region be eb)
1573 (if (re-search-forward mime-edit-multipart-beginning-regexp nil t)
1575 (narrow-to-region (match-beginning 0)(point-max))
1576 (mime-edit-find-inmost)
1579 (list type bb be eb)
1582 (defun mime-edit-process-multipart-1 (boundary)
1583 (let ((ret (mime-edit-find-inmost)))
1585 (let ((type (car ret))
1586 (bb (nth 1 ret))(be (nth 2 ret))
1589 (narrow-to-region bb eb)
1590 (delete-region bb be)
1591 (setq bb (point-min))
1592 (setq eb (point-max))
1595 (if (looking-at mime-edit-multipart-end-regexp)
1596 (let ((beg (match-beginning 0))
1599 (delete-region beg end)
1600 (or (looking-at mime-edit-beginning-tag-regexp)
1602 (insert (concat (mime-make-text-tag) "\n"))
1604 (cond ((string-equal type "quote")
1605 (mime-edit-enquote-region bb eb)
1607 ((string-equal type "pgp-signed")
1608 (mime-edit-sign-pgp-mime bb eb boundary)
1610 ((string-equal type "pgp-encrypted")
1611 (mime-edit-encrypt-pgp-mime bb eb boundary)
1613 ((string-equal type "kazu-signed")
1614 (mime-edit-sign-pgp-kazu bb eb boundary)
1616 ((string-equal type "kazu-encrypted")
1617 (mime-edit-encrypt-pgp-kazu bb eb boundary)
1621 (nth 2 (mime-edit-translate-region bb eb
1625 (format "--[[multipart/%s;
1626 boundary=\"%s\"][7bit]]\n"
1631 (defun mime-edit-enquote-region (beg end)
1634 (narrow-to-region beg end)
1636 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1637 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1638 (replace-match (concat "- " (substring tag 1)))
1641 (defun mime-edit-dequote-region (beg end)
1644 (narrow-to-region beg end)
1646 (while (re-search-forward
1647 mime-edit-quoted-single-part-tag-regexp nil t)
1648 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1649 (replace-match (concat "-" (substring tag 2)))
1652 (defun mime-edit-sign-pgp-mime (beg end boundary)
1655 (narrow-to-region beg end)
1657 (mime-edit-translate-region beg end boundary))
1659 (encoding (nth 1 ret))
1660 (pgp-boundary (concat "pgp-sign-" boundary)))
1662 (insert (format "Content-Type: %s\n" ctype))
1664 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1667 (or (as-binary-process
1668 (funcall (pgp-function 'mime-sign)
1669 (point-min)(point-max) nil nil pgp-boundary))
1670 (throw 'mime-edit-error 'pgp-error)
1674 (defvar mime-edit-encrypt-recipient-fields-list '("To" "cc"))
1676 (defun mime-edit-make-encrypt-recipient-header ()
1677 (let* ((names mime-edit-encrypt-recipient-fields-list)
1679 (std11-field-bodies (cons "From" names)
1680 nil mail-header-separator))
1683 (setq values (cdr values))))
1684 (header (and (stringp from)
1685 (if (string-equal from "")
1687 (format "From: %s\n" from)
1690 (while (and names values)
1691 (let ((name (car names))
1692 (value (car values))
1694 (and (stringp value)
1695 (or (string-equal value "")
1697 (setq header (concat header name ": " value "\n")
1698 recipients (if recipients
1699 (concat recipients " ," value)
1702 (setq names (cdr names)
1703 values (cdr values))
1705 (vector from recipients header)
1708 (defun mime-edit-encrypt-pgp-mime (beg end boundary)
1711 (let (from recipients header)
1712 (let ((ret (mime-edit-make-encrypt-recipient-header)))
1713 (setq from (aref ret 0)
1714 recipients (aref ret 1)
1715 header (aref ret 2))
1717 (narrow-to-region beg end)
1719 (mime-edit-translate-region beg end boundary))
1721 (encoding (nth 1 ret))
1722 (pgp-boundary (concat "pgp-" boundary)))
1725 (insert (format "Content-Type: %s\n" ctype))
1727 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1730 (or (funcall (pgp-function 'encrypt)
1731 recipients (point-min) (point-max) from)
1732 (throw 'mime-edit-error 'pgp-error)
1735 (insert (format "--[[multipart/encrypted;
1737 protocol=\"application/pgp-encrypted\"][7bit]]
1739 Content-Type: application/pgp-encrypted
1742 Content-Type: application/octet-stream
1743 Content-Transfer-Encoding: 7bit
1745 " pgp-boundary pgp-boundary pgp-boundary))
1746 (goto-char (point-max))
1747 (insert (format "\n--%s--\n" pgp-boundary))
1750 (defun mime-edit-sign-pgp-kazu (beg end boundary)
1753 (narrow-to-region beg end)
1755 (mime-edit-translate-region beg end boundary))
1757 (encoding (nth 1 ret)))
1759 (insert (format "Content-Type: %s\n" ctype))
1761 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1764 (or (as-binary-process
1765 (funcall (pgp-function 'traditional-sign)
1767 (throw 'mime-edit-error 'pgp-error)
1771 "--[[application/pgp; format=mime][7bit]]\n")
1775 (defun mime-edit-encrypt-pgp-kazu (beg end boundary)
1777 (let (recipients header)
1778 (let ((ret (mime-edit-make-encrypt-recipient-header)))
1779 (setq recipients (aref ret 1)
1780 header (aref ret 2))
1783 (narrow-to-region beg end)
1785 (mime-edit-translate-region beg end boundary))
1787 (encoding (nth 1 ret)))
1790 (insert (format "Content-Type: %s\n" ctype))
1792 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1795 (or (as-binary-process
1796 (funcall (pgp-function 'encrypt)
1797 recipients beg (point-max) nil 'maybe)
1799 (throw 'mime-edit-error 'pgp-error)
1803 "--[[application/pgp; format=mime][7bit]]\n")
1807 (defsubst replace-space-with-underline (str)
1808 (mapconcat (function
1816 (defun mime-edit-make-boundary ()
1817 (concat mime-multipart-boundary "_"
1818 (replace-space-with-underline (current-time-string))
1821 (defun mime-edit-translate-body ()
1822 "Encode the tagged MIME body in current buffer in MIME compliant message."
1825 (let ((boundary (mime-edit-make-boundary))
1828 (while (mime-edit-process-multipart-1
1829 (format "%s-%d" boundary i))
1833 ;; We are interested in message body.
1836 (goto-char (point-min))
1838 (concat "\n" (regexp-quote mail-header-separator)
1839 (if mime-ignore-preceding-spaces
1840 "[ \t\n]*\n" "\n")) nil 'move)
1844 (goto-char (point-max))
1845 (and mime-ignore-trailing-spaces
1846 (re-search-backward "[^ \t\n]\n" beg t)
1849 (setq ret (mime-edit-translate-region
1851 (format "%s-%d" boundary i)))
1853 (mime-edit-dequote-region (point-min)(point-max))
1854 (let ((contype (car ret)) ;Content-Type
1855 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1857 ;; Insert X-Emacs field
1858 (and mime-edit-insert-x-emacs-field
1859 (or (mail-position-on-field "X-Emacs")
1860 (insert mime-edit-x-emacs-value)
1862 ;; Make primary MIME headers.
1863 (or (mail-position-on-field "MIME-Version")
1864 (insert mime-edit-mime-version-value))
1865 ;; Remove old Content-Type and other fields.
1867 (goto-char (point-min))
1868 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1869 (narrow-to-region (point-min) (point))
1870 (goto-char (point-min))
1871 (mime-delete-field "Content-Type")
1872 (mime-delete-field "Content-Transfer-Encoding"))
1873 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1874 (mail-position-on-field "Content-Type")
1878 (mail-position-on-field "Content-Transfer-Encoding")
1882 (defun mime-edit-translate-single-part-tag (boundary &optional prefix)
1883 "Translate single-part-tag to MIME header."
1884 (if (re-search-forward mime-edit-single-part-tag-regexp nil t)
1885 (let* ((beg (match-beginning 0))
1887 (tag (buffer-substring beg end)))
1888 (delete-region beg end)
1889 (let ((contype (mime-edit-get-contype tag))
1890 (encoding (mime-edit-get-encoding tag)))
1891 (insert (concat prefix "--" boundary "\n"))
1893 (narrow-to-region (point)(point))
1894 (insert "Content-Type: " contype "\n")
1896 (insert "Content-Transfer-Encoding: " encoding "\n"))
1897 (eword-encode-header)
1901 (defun mime-edit-translate-region (beg end &optional boundary multipart)
1903 (setq boundary (mime-edit-make-boundary))
1907 (narrow-to-region beg end)
1908 (let ((tag nil) ;MIME tag
1909 (contype nil) ;Content-Type
1910 (encoding nil) ;Content-Transfer-Encoding
1911 (nparts 0)) ;Number of body parts
1912 ;; Normalize the body part by inserting appropriate message
1913 ;; tags for every message contents.
1914 (mime-edit-normalize-body)
1915 ;; Counting the number of Content-Type.
1916 (goto-char (point-min))
1917 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1918 (setq nparts (1+ nparts)))
1919 ;; Begin translation.
1921 ((and (<= nparts 1)(not multipart))
1922 ;; It's a singular message.
1923 (goto-char (point-min))
1924 (while (re-search-forward
1925 mime-edit-single-part-tag-regexp nil t)
1927 (buffer-substring (match-beginning 0) (match-end 0)))
1928 (delete-region (match-beginning 0) (1+ (match-end 0)))
1929 (setq contype (mime-edit-get-contype tag))
1930 (setq encoding (mime-edit-get-encoding tag))
1933 ;; It's a multipart message.
1934 (goto-char (point-min))
1935 (and (mime-edit-translate-single-part-tag boundary)
1936 (while (mime-edit-translate-single-part-tag boundary "\n")))
1937 ;; Define Content-Type as "multipart/mixed".
1939 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1940 ;; Content-Transfer-Encoding must be "7bit".
1941 ;; The following encoding can be `nil', but is
1942 ;; specified as is since there is no way that a user
1944 (setq encoding "7bit")
1945 ;; Insert the trailer.
1946 (goto-char (point-max))
1947 (insert "\n--" boundary "--\n")
1949 (list contype encoding boundary nparts)
1952 (defun mime-edit-normalize-body ()
1953 "Normalize the body part by inserting appropriate message tags."
1954 ;; Insert the first MIME tags if necessary.
1955 (goto-char (point-min))
1956 (if (not (looking-at mime-edit-single-part-tag-regexp))
1957 (insert (mime-make-text-tag) "\n"))
1958 ;; Check each tag, and add new tag or correct it if necessary.
1959 (goto-char (point-min))
1960 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1961 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1962 (contype (mime-edit-get-contype tag))
1963 (charset (mime-get-parameter contype "charset"))
1964 (encoding (mime-edit-get-encoding tag)))
1965 ;; Remove extra whitespaces after the tag.
1966 (if (looking-at "[ \t]+$")
1967 (delete-region (match-beginning 0) (match-end 0)))
1969 (end (mime-edit-content-end))
1971 (if (= end (point-max))
1974 (or (looking-at mime-edit-beginning-tag-regexp)
1976 (insert (mime-make-text-tag) "\n")
1978 (visible-region beg end)
1982 ((mime-test-content-type contype "message")
1983 ;; Content-type "message" should be sent as is.
1986 ((mime-test-content-type contype "text")
1987 ;; Define charset for text if necessary.
1988 (setq charset (if charset
1989 (intern (downcase charset))
1990 (mime-edit-choose-charset)))
1991 (mime-edit-define-charset charset)
1992 (cond ((string-equal contype "text/x-rot13-47-48")
1995 (mule-caesar-region (point) (mime-edit-content-end))
1997 ((string-equal contype "text/enriched")
2002 (end (mime-edit-content-end))
2004 ;; Patch for hard newlines
2007 ;; (while (search-forward "\n" end t)
2008 ;; (put-text-property (match-beginning 0)
2011 ;; End patch for hard newlines
2012 (enriched-encode beg end)
2014 (if (search-forward "\n\n")
2015 (delete-region beg (match-end 0))
2018 ;; Point is now on current tag.
2019 ;; Define encoding and encode text if necessary.
2020 (or encoding ;Encoding is not specified.
2023 (let ((ret (cdr (assq charset mime-charset-type-list))))
2025 (setq bits (car ret)
2028 conv "quoted-printable")))
2029 (if (<= bits mime-transfer-level)
2030 (mime-encoding-name bits)
2032 (beg (mime-edit-content-beginning)))
2033 (encode-mime-charset-region beg (mime-edit-content-end)
2035 ;; Protect "From " in beginning of line
2037 (narrow-to-region beg (mime-edit-content-end))
2039 (let (case-fold-search)
2040 (if (re-search-forward "^From " nil t)
2042 (if (memq charset '(iso-2022-jp
2047 (replace-match "\e(BFrom ")
2048 (re-search-forward "^From " nil t)
2050 (setq encoding "quoted-printable")
2052 ;; canonicalize line break code
2053 (or (member encoding '(nil "7bit" "8bit" "quoted-printable"))
2055 (narrow-to-region beg (mime-edit-content-end))
2057 (while (re-search-forward "\\([^\r]\\)\n" nil t)
2059 (concat (buffer-substring (match-beginning 0)
2060 (match-end 1)) "\r\n"))
2063 (mime-encode-region beg (mime-edit-content-end) encoding)
2064 (mime-edit-define-encoding encoding)
2066 (goto-char (mime-edit-content-end))
2068 ((null encoding) ;Encoding is not specified.
2069 ;; Application, image, audio, video, and any other
2070 ;; unknown content-type without encoding should be
2072 (let* ((encoding "base64") ;Encode in BASE64 by default.
2073 (beg (mime-edit-content-beginning))
2074 (end (mime-edit-content-end)))
2075 (mime-encode-region beg end encoding)
2076 (mime-edit-define-encoding encoding))
2081 (defun mime-delete-field (field)
2082 "Delete header FIELD."
2083 (let ((regexp (format "^%s:[ \t]*" field)))
2084 (goto-char (point-min))
2085 (while (re-search-forward regexp nil t)
2086 (delete-region (match-beginning 0)
2087 (progn (forward-line 1) (point)))
2092 ;;; Platform dependent functions
2095 ;; Sun implementations
2097 (defun mime-edit-voice-recorder-for-sun (encoding)
2098 "Record voice in a buffer using Sun audio device,
2099 and insert data encoded as ENCODING."
2100 (message "Start the recording on %s. Type C-g to finish the recording..."
2102 (mime-insert-encoded-file "/dev/audio" encoding)
2106 ;;; @ Other useful commands.
2109 ;; Message forwarding commands as content-type "message/rfc822".
2111 (defun mime-edit-insert-message (&optional message)
2113 (let ((inserter (cdr (assq major-mode mime-edit-message-inserter-alist))))
2114 (if (and inserter (fboundp inserter))
2116 (mime-edit-insert-tag "message" "rfc822")
2117 (funcall inserter message)
2119 (message "Sorry, I don't have message inserter for your MUA.")
2122 (defun mime-edit-insert-mail (&optional message)
2124 (let ((inserter (cdr (assq major-mode mime-edit-mail-inserter-alist))))
2125 (if (and inserter (fboundp inserter))
2127 (mime-edit-insert-tag "message" "rfc822")
2128 (funcall inserter message)
2130 (message "Sorry, I don't have mail inserter for your MUA.")
2133 (defun mime-edit-inserted-message-filter ()
2136 (let ((header-start (point))
2137 (case-fold-search t)
2140 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2141 (if (re-search-forward "^$" (mark t))
2142 (narrow-to-region header-start (match-beginning 0))
2144 (goto-char header-start)
2145 (while (and (re-search-forward
2146 mime-edit-yank-ignored-field-regexp nil t)
2147 (setq beg (match-beginning 0))
2148 (setq end (1+ (std11-field-end)))
2150 (delete-region beg end)
2155 ;;; @ multipart enclosure
2158 (defun mime-edit-enclose-region-internal (type beg end)
2162 (narrow-to-region beg end)
2163 (insert (format "--<<%s>>-{\n" type))
2164 (goto-char (point-max))
2165 (insert (format "--}-<<%s>>\n" type))
2166 (goto-char (point-max))
2168 (or (looking-at mime-edit-beginning-tag-regexp)
2170 (insert (mime-make-text-tag) "\n")
2174 (defun mime-edit-enclose-quote-region (beg end)
2176 (mime-edit-enclose-region-internal 'quote beg end)
2179 (defun mime-edit-enclose-mixed-region (beg end)
2181 (mime-edit-enclose-region-internal 'mixed beg end)
2184 (defun mime-edit-enclose-parallel-region (beg end)
2186 (mime-edit-enclose-region-internal 'parallel beg end)
2189 (defun mime-edit-enclose-digest-region (beg end)
2191 (mime-edit-enclose-region-internal 'digest beg end)
2194 (defun mime-edit-enclose-alternative-region (beg end)
2196 (mime-edit-enclose-region-internal 'alternative beg end)
2199 (defun mime-edit-enclose-pgp-signed-region (beg end)
2201 (mime-edit-enclose-region-internal 'pgp-signed beg end)
2204 (defun mime-edit-enclose-pgp-encrypted-region (beg end)
2206 (mime-edit-enclose-region-internal 'pgp-encrypted beg end)
2209 (defun mime-edit-enclose-kazu-signed-region (beg end)
2211 (mime-edit-enclose-region-internal 'kazu-signed beg end)
2214 (defun mime-edit-enclose-kazu-encrypted-region (beg end)
2216 (mime-edit-enclose-region-internal 'kazu-encrypted beg end)
2219 (defun mime-edit-insert-key (&optional arg)
2220 "Insert a pgp public key."
2222 (mime-edit-insert-tag "application" "pgp-keys")
2223 (mime-edit-define-encoding "7bit")
2224 (funcall (pgp-function 'insert-key))
2231 (defun mime-edit-set-split (arg)
2234 (y-or-n-p "Do you want to enable split? ")
2236 (setq mime-edit-split-message arg)
2238 (message "This message is enabled to split.")
2239 (message "This message is not enabled to split.")
2242 (defun mime-edit-toggle-transfer-level (&optional transfer-level)
2243 "Toggle transfer-level is 7bit or 8bit through.
2245 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2247 (if (numberp transfer-level)
2248 (setq mime-transfer-level transfer-level)
2249 (if (< mime-transfer-level 8)
2250 (setq mime-transfer-level 8)
2251 (setq mime-transfer-level 7)
2253 (message (format "Current transfer-level is %d bit"
2254 mime-transfer-level))
2255 (setq mime-transfer-level-string
2256 (mime-encoding-name mime-transfer-level 'not-omit))
2257 (force-mode-line-update)
2260 (defun mime-edit-set-transfer-level-7bit ()
2262 (mime-edit-toggle-transfer-level 7)
2265 (defun mime-edit-set-transfer-level-8bit ()
2267 (mime-edit-toggle-transfer-level 8)
2274 (defvar mime-edit-pgp-processing nil)
2275 (make-variable-buffer-local 'mime-edit-pgp-processing)
2277 (defun mime-edit-set-sign (arg)
2280 (y-or-n-p "Do you want to sign? ")
2284 (setq mime-edit-pgp-processing 'sign)
2285 (message "This message will be signed.")
2287 (if (eq mime-edit-pgp-processing 'sign)
2288 (setq mime-edit-pgp-processing nil)
2290 (message "This message will not be signed.")
2293 (defun mime-edit-set-encrypt (arg)
2296 (y-or-n-p "Do you want to encrypt? ")
2300 (setq mime-edit-pgp-processing 'encrypt)
2301 (message "This message will be encrypt.")
2303 (if (eq mime-edit-pgp-processing 'encrypt)
2304 (setq mime-edit-pgp-processing nil)
2306 (message "This message will not be encrypt.")
2309 (defun mime-edit-pgp-enclose-buffer ()
2310 (let ((beg (save-excursion
2311 (goto-char (point-min))
2312 (if (search-forward (concat "\n" mail-header-separator "\n"))
2318 (cond ((eq mime-edit-pgp-processing 'sign)
2319 (mime-edit-enclose-pgp-signed-region beg end)
2321 ((eq mime-edit-pgp-processing 'encrypt)
2322 (mime-edit-enclose-pgp-encrypted-region beg end)
2330 (defun mime-edit-insert-partial-header (fields subject
2331 id number total separator)
2333 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2334 (insert mime-edit-mime-version-field-for-message/partial)
2336 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2337 id number total separator))
2340 (defun mime-edit-split-and-send
2341 (&optional cmd lines mime-edit-message-max-length)
2345 (count-lines (point-min) (point-max)))
2347 (or mime-edit-message-max-length
2348 (setq mime-edit-message-max-length
2349 (or (cdr (assq major-mode mime-edit-message-max-lines-alist))
2350 mime-edit-message-default-max-lines))
2352 (let* ((mime-edit-draft-file-name
2353 (or (buffer-file-name)
2355 (expand-file-name "mime-draft" mime-temp-directory))))
2356 (separator mail-header-separator)
2358 (replace-space-with-underline (current-time-string))
2359 "@" (system-name) "\"")))
2360 (run-hooks 'mime-edit-before-split-hook)
2361 (let ((the-buf (current-buffer))
2362 (copy-buf (get-buffer-create " *Original Message*"))
2363 (header (std11-header-string-except
2364 mime-edit-split-ignored-field-regexp separator))
2365 (subject (mail-fetch-field "subject"))
2366 (total (+ (/ lines mime-edit-message-max-length)
2367 (if (> (mod lines mime-edit-message-max-length) 0)
2373 mime-edit-split-message-sender-alist))
2377 (error "Split sender is not specified for `%s'." major-mode)
2380 (mime-edit-partial-number 1)
2383 (set-buffer copy-buf)
2385 (insert-buffer the-buf)
2387 (if (re-search-forward
2388 (concat "^" (regexp-quote separator) "$") nil t)
2389 (let ((he (match-beginning 0)))
2391 (narrow-to-region (point-min) he)
2393 (goto-char (point-min))
2394 (while (re-search-forward mime-edit-split-blind-field-regexp nil t)
2395 (delete-region (match-beginning 0)
2396 (1+ (std11-field-end)))
2398 (while (< mime-edit-partial-number total)
2401 (set-buffer copy-buf)
2402 (setq data (buffer-substring
2405 (goto-line mime-edit-message-max-length)
2408 (delete-region (point-min)(point))
2410 (mime-edit-insert-partial-header
2411 header subject id mime-edit-partial-number total separator)
2414 (message (format "Sending %d/%d..."
2415 mime-edit-partial-number total))
2416 (call-interactively command)
2417 (message (format "Sending %d/%d... done"
2418 mime-edit-partial-number total))
2420 (setq mime-edit-partial-number
2421 (1+ mime-edit-partial-number))
2425 (set-buffer copy-buf)
2426 (setq data (buffer-string))
2429 (mime-edit-insert-partial-header
2430 header subject id mime-edit-partial-number total separator)
2433 (message (format "Sending %d/%d..."
2434 mime-edit-partial-number total))
2435 (message (format "Sending %d/%d... done"
2436 mime-edit-partial-number total))
2440 (defun mime-edit-maybe-split-and-send (&optional cmd)
2442 (run-hooks 'mime-edit-before-send-hook)
2443 (let ((mime-edit-message-max-length
2444 (or (cdr (assq major-mode mime-edit-message-max-lines-alist))
2445 mime-edit-message-default-max-lines))
2446 (lines (count-lines (point-min) (point-max)))
2448 (if (and (> lines mime-edit-message-max-length)
2449 mime-edit-split-message)
2450 (mime-edit-split-and-send cmd lines mime-edit-message-max-length)
2454 ;;; @ preview message
2457 (defvar mime-edit-buffer nil) ; buffer local variable
2459 (defun mime-edit-preview-message ()
2460 "preview editing MIME message."
2462 (let* ((str (buffer-string))
2463 (separator mail-header-separator)
2464 (the-buf (current-buffer))
2465 (buf-name (buffer-name))
2466 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2467 (buf (get-buffer temp-buf-name))
2471 (switch-to-buffer buf)
2474 (setq buf (get-buffer-create temp-buf-name))
2475 (switch-to-buffer buf)
2478 (setq major-mode 'mime-temp-message-mode)
2479 (make-local-variable 'mail-header-separator)
2480 (setq mail-header-separator separator)
2481 (make-local-variable 'mime-edit-buffer)
2482 (setq mime-edit-buffer the-buf)
2484 (run-hooks 'mime-edit-translate-hook)
2485 (mime-edit-translate-buffer)
2486 (goto-char (point-min))
2487 (if (re-search-forward
2488 (concat "^" (regexp-quote separator) "$"))
2494 (defun mime-edit-quitting-method ()
2495 "Quitting method for mime-view."
2496 (let ((temp mime-raw-buffer)
2498 (mime-preview-kill-buffer)
2500 (setq buf mime-edit-buffer)
2502 (switch-to-buffer buf)
2505 (set-alist 'mime-preview-quitting-method-alist
2506 'mime-temp-message-mode
2507 #'mime-edit-quitting-method)
2513 (defvar mime-edit-again-ignored-field-regexp
2514 (concat "^\\(" "Content-.*\\|Mime-Version"
2515 (if mime-edit-insert-x-emacs-field "\\|X-Emacs")
2517 "Regexp for deleted header fields when `mime-edit-again' is called.")
2519 (defun mime-edit-decode-buffer (not-decode-text)
2521 (goto-char (point-min))
2522 (let ((ctl (mime-read-Content-Type)))
2524 (let ((type (mime-content-type-primary-type ctl))
2525 (stype (mime-content-type-subtype ctl))
2526 (params (mime-content-type-parameters ctl)))
2528 ((and (eq type 'application)(eq stype 'pgp-signature))
2529 (delete-region (point-min)(point-max))
2531 ((eq type 'multipart)
2532 (let* ((boundary (cdr (assoc "boundary" params)))
2534 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2536 (re-search-forward boundary-pat nil t)
2537 (let ((bb (match-beginning 0)) eb tag)
2538 (setq tag (format "\n--<<%s>>-{\n" stype))
2541 (setq bb (+ bb (length tag)))
2543 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2545 (setq eb (match-beginning 0))
2546 (replace-match (format "--}-<<%s>>\n" stype))
2548 (narrow-to-region bb eb)
2549 (goto-char (point-min))
2550 (while (re-search-forward boundary-pat nil t)
2551 (let ((beg (match-beginning 0))
2553 (delete-region beg (match-end 0))
2555 (if (re-search-forward boundary-pat nil t)
2556 (setq end (match-beginning 0))
2557 (setq end (point-max))
2560 (narrow-to-region beg end)
2561 (mime-edit-decode-buffer not-decode-text)
2562 (goto-char (point-max))
2565 (goto-char (point-min))
2566 (or (= (point-min) 1)
2567 (delete-region (point-min)
2568 (if (search-forward "\n\n" nil t)
2574 (let* ((ctype (format "%s/%s" type stype))
2577 (let ((bytes (+ 14 (length ctype))))
2578 (mapconcat (function
2580 (if (string= (car attr) "charset")
2582 (setq charset (cdr attr))
2590 (setq bytes (+ bytes bs 2))
2593 (setq bytes (+ bs 1))
2601 (if (re-search-forward
2602 "Content-Transfer-Encoding:" nil t)
2603 (let ((beg (match-beginning 0))
2604 (hbeg (match-end 0))
2605 (end (std11-field-end)))
2607 (eliminate-top-spaces
2608 (std11-unfold-string
2609 (buffer-substring hbeg end))))
2610 (if (or charset (eq type 'text))
2612 (delete-region beg (1+ end))
2613 (goto-char (point-min))
2614 (if (search-forward "\n\n" nil t)
2617 (match-end 0)(point-max) encoding)
2621 (if (or encoded (not not-decode-text))
2622 (decode-mime-charset-region
2623 (point-min)(point-max)
2624 (or charset default-mime-charset))
2627 (if (re-search-forward "^$" nil t)
2631 (if (= (point-min) 1)
2637 (format "%s/%s%s" type stype pstr)
2640 (delete-region (point-min) he)
2643 (format "%s/%s%s" type stype pstr)
2648 (decode-mime-charset-region (point-min) (point-max)
2649 default-mime-charset)
2653 (defun mime-edit-again (&optional not-decode-text no-separator not-turn-on)
2654 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode.
2655 Content-Type and Content-Transfer-Encoding header fields will be
2656 converted to MIME-Edit tags."
2658 (goto-char (point-min))
2660 (concat "\n" (regexp-quote mail-header-separator) "\n")
2662 (replace-match "\n\n")
2664 (mime-edit-decode-buffer not-decode-text)
2665 (goto-char (point-min))
2667 (std11-narrow-to-header)
2668 (goto-char (point-min))
2669 (while (re-search-forward mime-edit-again-ignored-field-regexp nil t)
2670 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2673 (and (re-search-forward "^$")
2674 (replace-match mail-header-separator)
2684 (provide 'mime-edit)
2686 (run-hooks 'mime-edit-load-hook)
2688 ;;; mime-edit.el ends here