1 ;;; tm-edit.el --- Simple MIME Composer for GNU Emacs
3 ;; Copyright (C) 1993,1994,1995,1996,1997 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 ;; Keywords: mail, news, MIME, multimedia, multilingual
11 ;; This file is part of tm (Tools for MIME).
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
30 ;; This is an Emacs minor mode for editing Internet multimedia
31 ;; messages formatted in MIME (RFC 2045, 2046, 2047, 2048 and 2049).
32 ;; All messages in this mode are composed in the tagged MIME format,
33 ;; that are described in the following examples. The messages
34 ;; composed in the tagged MIME format are automatically translated
35 ;; into a MIME compliant message when exiting the mode.
37 ;; Mule (a multilingual extension to Emacs 18 and 19) has a capability
38 ;; of handling multilingual text in limited ISO-2022 manner that is
39 ;; based on early experiences in Japanese Internet community and
40 ;; resulted in RFC 1468 (ISO-2022-JP charset for MIME). In order to
41 ;; enable multilingual capability in single text message in MIME,
42 ;; charset of multilingual text written in Mule is declared as either
43 ;; `ISO-2022-JP-2' [RFC 1554]. Mule is required for reading the such
46 ;; This MIME composer can work with Mail mode, mh-e letter Mode, and
47 ;; News mode. First of all, you need the following autoload
48 ;; definition to load mime/editor-mode automatically:
50 ;; (autoload 'mime/editor-mode "tm-edit"
51 ;; "Minor mode for editing MIME message." t)
53 ;; In case of Mail mode (includes VM mode), you need the following
56 ;; (add-hook 'mail-mode-hook 'mime/editor-mode)
57 ;; (add-hook 'mail-send-hook 'mime-editor/maybe-translate)
59 ;; In case of MH-E, you need the following hook definition:
61 ;; (add-hook 'mh-letter-mode-hook
65 ;; (make-local-variable 'mail-header-separator)
66 ;; (setq mail-header-separator "--------")
68 ;; (add-hook 'mh-before-send-letter-hook 'mime-editor/maybe-translate)
70 ;; In case of News mode, you need the following hook definition:
72 ;; (add-hook 'news-reply-mode-hook 'mime/editor-mode)
73 ;; (add-hook 'news-inews-hook 'mime-editor/maybe-translate)
75 ;; In case of Emacs 19, it is possible to emphasize the message tags
76 ;; using font-lock mode as follows:
78 ;; (add-hook 'mime/editor-mode-hook
82 ;; (setq font-lock-keywords (list mime-editor/tag-regexp))
85 ;; The message tag looks like:
87 ;; --[[TYPE/SUBTYPE;PARAMETERS][ENCODING]]
89 ;; The tagged MIME message examples:
91 ;; This is a conventional plain text. It should be translated into
95 ;; This is also a plain text. But, it is explicitly specified as is.
96 ;;--[[text/plain; charset=ISO-8859-1]]
97 ;; This is also a plain text. But charset is specified as iso-8859-1.
99 ;; ¡Hola! Buenos días. ¿Cómo está usted?
100 ;;--[[text/enriched]]
101 ;; <center>This is a richtext.</center>
103 ;;--[[image/gif][base64]]^M...image encoded in base64 comes here...
105 ;;--[[audio/basic][base64]]^M...audio encoded in base64 comes here...
110 (require 'mail-utils)
114 (require 'eword-encode)
121 (defconst mime-editor/version "8.2 (Bang The Gong)")
123 (defconst mime-editor/version-name
124 (concat "tm-edit " mime-editor/version))
130 (defvar mime-prefix "\C-c\C-x"
131 "*Keymap prefix for MIME commands.")
133 (defvar mime-ignore-preceding-spaces nil
134 "*Ignore preceding white spaces if non-nil.")
136 (defvar mime-ignore-trailing-spaces nil
137 "*Ignore trailing white spaces if non-nil.")
139 (defvar mime-ignore-same-text-tag t
140 "*Ignore preceding text content-type tag that is same with new one.
141 If non-nil, the text tag is not inserted unless something different.")
143 (defvar mime-auto-hide-body t
144 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
146 (defvar mime-editor/voice-recorder
147 (function mime-editor/voice-recorder-for-sun)
148 "*Function to record a voice message and encode it. [tm-edit.el]")
150 (defvar mime/editor-mode-hook nil
151 "*Hook called when enter MIME mode.")
153 (defvar mime-editor/translate-hook nil
154 "*Hook called before translating into a MIME compliant message.
155 To insert a signature file automatically, call the function
156 `mime-editor/insert-signature' from this hook.")
158 (defvar mime-editor/exit-hook nil
159 "*Hook called when exit MIME mode.")
161 (defvar mime-content-types
163 ;; Charset parameter need not to be specified, since it is
164 ;; defined automatically while translation.
166 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
169 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
172 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
175 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
178 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
186 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
187 ("directory" "/pub/GNU/elisp/mime")
189 ("mode" "image" "ascii" "local8"))
194 ("mode" "image" "ascii" "local8"))
195 ("tftp" ("site") ("name"))
196 ("afs" ("site") ("name"))
197 ("local-file" ("site") ("name"))
198 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
203 ("octet-stream" ("type" "" "tar" "shar"))
205 ("x-kiss" ("x-cnf")))
219 "*Alist of content-type, subtype, parameters and its values.")
221 (defvar mime-file-types
223 "text" "richtext" nil
226 ("\\.\\(html\\|htm\\)$"
231 "application" "postscript" nil
233 "attachment" (("filename" . file))
235 ("\\.\\(jpeg\\|jpg\\)$"
238 "inline" (("filename" . file))
243 "inline" (("filename" . file))
248 "inline" (("filename" . file))
250 ("\\.\\(tiff\\|tif\\)$"
253 "inline" (("filename" . file))
258 "inline" (("filename" . file))
263 "inline" (("filename" . file))
268 "inline" (("filename" . file))
273 "inline" (("filename" . file))
278 "attachment" (("filename" . file))
283 "attachment" (("filename" . file))
288 "attachment" (("filename" . file))
291 "application" "octet-stream" (("type" . "emacs-lisp"))
293 "attachment" (("filename" . file))
296 "application" "octet-stream" (("type" . "common-lisp"))
298 "attachment" (("filename" . file))
301 "application" "octet-stream" (("type" . "tar+gzip"))
303 "attachment" (("filename" . file))
306 "application" "octet-stream" (("type" . "tar+gzip"))
308 "attachment" (("filename" . file))
311 "application" "octet-stream" (("type" . "tar+compress"))
313 "attachment" (("filename" . file))
316 "application" "octet-stream" (("type" . "tar+compress"))
318 "attachment" (("filename" . file))
321 "application" "octet-stream" (("type" . "gzip"))
323 "attachment" (("filename" . file))
326 "application" "octet-stream" (("type" . "compress"))
328 "attachment" (("filename" . file))
331 "application" "octet-stream" (("type" . "lha"))
333 "attachment" (("filename" . file))
336 "application" "zip" nil
338 "attachment" (("filename" . file))
341 "application" "octet-stream" (("type" . "patch"))
343 "attachment" (("filename" . file))
346 "application" "octet-stream" (("type" . "patch"))
348 "attachment" (("filename" . file))
351 "text" "plain" nil nil)
353 "application" "octet-stream" nil
355 "attachment" (("filename" . file))
358 "*Alist of file name, types, parameters, and default encoding.
359 If encoding is nil, it is determined from its contents.")
361 ;;; @@ about charset, encoding and transfer-level
364 (defvar mime-editor/transfer-level 7
365 "*A number of network transfer level. It should be bigger than 7.")
366 (make-variable-buffer-local 'mime-editor/transfer-level)
368 (defvar mime-editor/transfer-level-string
369 (mime/encoding-name mime-editor/transfer-level 'not-omit)
370 "*A string formatted version of mime/defaul-transfer-level")
371 (make-variable-buffer-local 'mime-editor/transfer-level-string)
373 (defun mime-editor/make-charset-default-encoding-alist (transfer-level)
375 (lambda (charset-type)
376 (let ((charset (car charset-type))
377 (type (nth 1 charset-type))
378 (encoding (nth 2 charset-type))
380 (if (<= type transfer-level)
381 (cons charset (mime/encoding-name type))
382 (cons charset encoding)
384 mime-charset-type-list))
386 (defvar mime-editor/charset-default-encoding-alist
387 (mime-editor/make-charset-default-encoding-alist mime-editor/transfer-level))
388 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
390 ;;; @@ about message inserting
393 (defvar mime-editor/yank-ignored-field-list
394 '("Received" "Approved" "Path" "Replied" "Status"
395 "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
396 "Delete these fields from original message when it is inserted
397 as message/rfc822 part.
398 Each elements are regexp of field-name. [tm-edit.el]")
400 (defvar mime-editor/yank-ignored-field-regexp
402 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
405 (defvar mime-editor/message-inserter-alist nil)
406 (defvar mime-editor/mail-inserter-alist nil)
408 ;;; @@ about message splitting
411 (defvar mime-editor/split-message t
412 "*Split large message if it is non-nil. [tm-edit.el]")
414 (defvar mime-editor/message-default-max-lines 1000
415 "*Default maximum lines of a message. [tm-edit.el]")
417 (defvar mime-editor/message-max-lines-alist
418 '((news-reply-mode . 500))
419 "Alist of major-mode vs maximum lines of a message.
420 If it is not specified for a major-mode,
421 `mime-editor/message-default-max-lines' is used. [tm-edit.el]")
423 (defconst mime-editor/split-ignored-field-regexp
424 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
426 (defvar mime-editor/split-blind-field-regexp
427 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
429 (defvar mime-editor/split-message-sender-alist nil)
431 (defvar mime-editor/news-reply-mode-server-running nil)
437 (defvar mime-editor/signing-type 'pgp-elkins
438 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
440 (defvar mime-editor/encrypting-type 'pgp-elkins
441 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
447 (defconst mime-editor/single-part-tag-regexp
448 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
449 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
451 (defconst mime-editor/quoted-single-part-tag-regexp
452 (concat "- " (substring mime-editor/single-part-tag-regexp 1)))
454 (defconst mime-editor/multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
456 (defconst mime-editor/multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
458 (defconst mime-editor/beginning-tag-regexp
459 (regexp-or mime-editor/single-part-tag-regexp
460 mime-editor/multipart-beginning-regexp))
462 (defconst mime-editor/end-tag-regexp
463 (regexp-or mime-editor/single-part-tag-regexp
464 mime-editor/multipart-end-regexp))
466 (defconst mime-editor/tag-regexp
467 (regexp-or mime-editor/single-part-tag-regexp
468 mime-editor/multipart-beginning-regexp
469 mime-editor/multipart-end-regexp))
471 (defvar mime-tag-format "--[[%s]]"
472 "*Control-string making a MIME tag.")
474 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
475 "*Control-string making a MIME tag with encoding.")
477 ;;; @@ multipart boundary
480 (defvar mime-multipart-boundary "Multipart"
481 "*Boundary of a multipart message.")
484 ;;; @@ buffer local variables
487 (defvar mime/editor-mode-old-local-map nil)
488 (defvar mime/editing-buffer nil)
494 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
495 "*Specify MIME tspecials.
496 Tspecials means any character that matches with it in header must be quoted.")
498 (defconst mime-editor/mime-version-value
499 (concat "1.0 (generated by " mime-editor/version-name ")")
500 "MIME version number.")
502 (defconst mime-editor/mime-map (make-sparse-keymap)
503 "Keymap for MIME commands.")
505 ;;; @ keymap and menu
508 (defvar mime/editor-mode-flag nil)
509 (make-variable-buffer-local 'mime/editor-mode-flag)
511 (defun mime-editor/define-keymap (keymap)
512 "Add mime-editor commands to KEYMAP."
513 (if (not (keymapp keymap))
515 (define-key keymap "\C-t" 'mime-editor/insert-text)
516 (define-key keymap "\C-i" 'mime-editor/insert-file)
517 (define-key keymap "\C-e" 'mime-editor/insert-external)
518 (define-key keymap "\C-v" 'mime-editor/insert-voice)
519 (define-key keymap "\C-y" 'mime-editor/insert-message)
520 (define-key keymap "\C-m" 'mime-editor/insert-mail)
521 (define-key keymap "\C-w" 'mime-editor/insert-signature)
522 (define-key keymap "\C-s" 'mime-editor/insert-signature)
523 (define-key keymap "\C-k" 'mime-editor/insert-key)
524 (define-key keymap "t" 'mime-editor/insert-tag)
525 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
526 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
527 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
528 (define-key keymap "d" 'mime-editor/enclose-digest-region)
529 (define-key keymap "s" 'mime-editor/enclose-signed-region)
530 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
531 (define-key keymap "q" 'mime-editor/enclose-quote-region)
532 (define-key keymap "7" 'mime-editor/set-transfer-level-7bit)
533 (define-key keymap "8" 'mime-editor/set-transfer-level-8bit)
534 (define-key keymap "/" 'mime-editor/set-split)
535 (define-key keymap "v" 'mime-editor/set-sign)
536 (define-key keymap "h" 'mime-editor/set-encrypt)
537 (define-key keymap "\C-p" 'mime-editor/preview-message)
538 (define-key keymap "\C-z" 'mime-editor/exit)
539 (define-key keymap "?" 'mime-editor/help)
542 (mime-editor/define-keymap mime-editor/mime-map)
544 (defun mime-editor/toggle-mode ()
546 (if mime/editor-mode-flag
547 (mime-editor/exit 'nomime)
551 (cond (running-xemacs
552 (defconst mime-editor/minor-mime-map nil "Keymap for MIME commands.")
553 (or mime-editor/minor-mime-map
555 (setq mime-editor/minor-mime-map
556 (make-sparse-keymap 'mime-editor/minor-mime-map))
558 mime-editor/minor-mime-map mime-prefix mime-editor/mime-map)
560 (add-minor-mode 'mime/editor-mode-flag
561 '((" MIME-Edit " mime-editor/transfer-level-string))
562 mime-editor/minor-mime-map
564 'mime-editor/toggle-mode)
567 (set-alist 'minor-mode-alist
568 'mime/editor-mode-flag
569 '((" MIME-Edit " mime-editor/transfer-level-string))))
572 (defconst mime-editor/menu-title "MIME-Edit")
574 (defconst mime-editor/menu-list
575 '((mime-help "Describe MIME editor mode" mime-editor/help)
576 (file "Insert File" mime-editor/insert-file)
577 (file "Insert File (verbose)" mime-editor/insert-file-verbose)
578 (external "Insert External" mime-editor/insert-external)
579 (voice "Insert Voice" mime-editor/insert-voice)
580 (message "Insert Message" mime-editor/insert-message)
581 (mail "Insert Mail" mime-editor/insert-mail)
582 (signature "Insert Signature" mime-editor/insert-signature)
583 (text "Insert Text" mime-editor/insert-text)
584 (tag "Insert Tag" mime-editor/insert-tag)
585 (alternative "Enclose as alternative"
586 mime-editor/enclose-alternative-region)
587 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
588 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
589 (digest "Enclose as digest" mime-editor/enclose-digest-region)
590 (signed "Enclose as signed" mime-editor/enclose-signed-region)
591 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
592 (quote "Verbatim region" mime-editor/enclose-quote-region)
593 (key "Insert Public Key" mime-editor/insert-key)
594 (split "About split" mime-editor/set-split)
595 (sign "About sign" mime-editor/set-sign)
596 (encrypt "About encryption" mime-editor/set-encrypt)
597 (preview "Preview Message" mime-editor/preview-message)
598 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
600 "MIME-edit menubar entry.")
602 (defun mime-editor/define-menu-for-emacs19 ()
603 "Define menu for Emacs 19."
604 (define-key (current-local-map) [menu-bar mime-edit]
605 (cons mime-editor/menu-title
606 (make-sparse-keymap mime-editor/menu-title)))
609 (define-key (current-local-map)
610 (vector 'menu-bar 'mime-edit (car item))
611 (cons (nth 1 item)(nth 2 item))
614 (reverse mime-editor/menu-list)
617 ;;; modified by Pekka Marjola <pema@iki.fi>
618 ;;; 1995/9/5 (c.f. [tm-en:69])
619 (defun mime-editor/define-menu-for-xemacs ()
620 "Define menu for Emacs 19."
621 (cond ((featurep 'menubar)
622 ;; (make-local-variable 'current-menubar)
623 ;; (set-buffer-menubar current-menubar)
625 ;; (cons mime-editor/menu-title
628 ;; (vector (nth 1 item)(nth 2 item)
629 ;; mime/editor-mode-flag)
631 ;; mime-editor/menu-list)))
633 (cons mime-editor/menu-title
636 (vector (nth 1 item)(nth 2 item)
637 mime/editor-mode-flag)
639 mime-editor/menu-list)))
642 ;;; modified by Steven L. Baur <steve@miranova.com>
643 ;;; 1995/12/6 (c.f. [tm-en:209])
644 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
645 (setq mime-editor/popup-menu-for-xemacs
646 (append '("MIME Commands" "---")
647 (mapcar (function (lambda (item)
651 mime-editor/menu-list)))
660 (defun mime/editor-mode ()
661 "MIME minor mode for editing the tagged MIME message.
663 In this mode, basically, the message is composed in the tagged MIME
664 format. The message tag looks like:
666 --[[text/plain; charset=ISO-2022-JP][7bit]]
668 The tag specifies the MIME content type, subtype, optional parameters
669 and transfer encoding of the message following the tag. Messages
670 without any tag are treated as `text/plain' by default. Charset and
671 transfer encoding are automatically defined unless explicitly
672 specified. Binary messages such as audio and image are usually hidden.
673 The messages in the tagged MIME format are automatically translated
674 into a MIME compliant message when exiting this mode.
676 Available charsets depend on Emacs version being used. The following
677 lists the available charsets of each emacs.
679 EMACS 18: US-ASCII is only available.
680 NEmacs: US-ASCII and ISO-2022-JP are available.
681 EMACS 19: US-ASCII and ISO-8859-1 (or other charset) are available.
682 XEmacs 19: US-ASCII and ISO-8859-1 (or other charset) are available.
683 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
684 ISO-2022-JP, ISO-2022-JP-2, ISO-2022-KR, BIG5 and
685 ISO-2022-INT-1 are available.
687 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
688 be used to represent multilingual text in intermixed manner. Any
689 languages that has no registered charset are represented as either
690 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
692 If you want to use non-ISO-8859-1 charset in EMACS 19 or XEmacs 19,
693 please set variable `default-mime-charset'. This variable must be
694 symbol of which name is a MIME charset.
696 If you want to add more charsets in mule, please set variable
697 `charsets-mime-charset-alist'. This variable must be alist of which
698 key is list of leading-char/charset and value is symbol of MIME
699 charset. (leading-char is a term of MULE 1.* and 2.*. charset is a
700 term of XEmacs/mule, mule merged EMACS and MULE 3.*) If name of
701 coding-system is different as MIME charset, please set variable
702 `mime-charset-coding-system-alist'. This variable must be alist of
703 which key is MIME charset and value is coding-system.
705 Following commands are available in addition to major mode commands:
708 \\[mime-editor/insert-text] insert a text message.
709 \\[mime-editor/insert-file] insert a (binary) file.
710 \\[mime-editor/insert-file-verbose] insert a (binary) file, with verbose
712 \\[mime-editor/insert-external] insert a reference to external body.
713 \\[mime-editor/insert-voice] insert a voice message.
714 \\[mime-editor/insert-message] insert a mail or news message.
715 \\[mime-editor/insert-mail] insert a mail message.
716 \\[mime-editor/insert-signature] insert a signature file at end.
717 \\[mime-editor/insert-key] insert PGP public key.
718 \\[mime-editor/insert-tag] insert a new MIME tag.
720 \[make enclosure (maybe multipart)\]
721 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
722 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
723 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
724 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
725 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
726 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
727 \\[mime-editor/enclose-quote-region] enclose as verbose mode (to avoid to expand tags)
730 \\[mime-editor/set-transfer-level-7bit] set transfer-level as 7.
731 \\[mime-editor/set-transfer-level-8bit] set transfer-level as 8.
732 \\[mime-editor/set-split] set message splitting mode.
733 \\[mime-editor/set-sign] set PGP-sign mode.
734 \\[mime-editor/set-encrypt] set PGP-encryption mode.
735 \\[mime-editor/preview-message] preview editing MIME message.
736 \\[mime-editor/exit] exit and translate into a MIME compliant message.
737 \\[mime-editor/help] show this help.
738 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
740 Additional commands are available in some major modes:
741 C-c C-c exit, translate and run the original command.
742 C-c C-s exit, translate and run the original command.
744 The following is a message example written in the tagged MIME format.
745 TABs at the beginning of the line are not a part of the message:
747 This is a conventional plain text. It should be translated
750 This is also a plain text. But, it is explicitly specified as
752 --[[text/plain; charset=ISO-8859-1]]
753 This is also a plain text. But charset is specified as
756 ¡Hola! Buenos días. ¿Cómo está usted?
758 This is a <bold>enriched text</bold>.
759 --[[image/gif][base64]]...image encoded in base64 here...
760 --[[audio/basic][base64]]...audio encoded in base64 here...
762 User customizable variables (not documented all of them):
764 Specifies a key prefix for MIME minor mode commands.
766 mime-ignore-preceding-spaces
767 Preceding white spaces in a message body are ignored if non-nil.
769 mime-ignore-trailing-spaces
770 Trailing white spaces in a message body are ignored if non-nil.
773 Hide a non-textual body message encoded in base64 after insertion
776 mime-editor/transfer-level
777 A number of network transfer level. It should be bigger than 7.
778 If you are in 8bit-through environment, please set 8.
780 mime-editor/voice-recorder
781 Specifies a function to record a voice message and encode it.
782 The function `mime-editor/voice-recorder-for-sun' is for Sun
785 mime/editor-mode-hook
786 Turning on MIME mode calls the value of mime/editor-mode-hook, if
789 mime-editor/translate-hook
790 The value of mime-editor/translate-hook is called just before translating
791 the tagged MIME format into a MIME compliant message if it is
792 non-nil. If the hook call the function mime-editor/insert-signature,
793 the signature file will be inserted automatically.
795 mime-editor/exit-hook
796 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
799 (if mime/editor-mode-flag
800 (error "You are already editing a MIME message.")
801 (setq mime/editor-mode-flag t)
802 ;; Remember old key bindings.
804 (use-local-map (or (current-local-map) (make-sparse-keymap)))
805 (make-local-variable 'mime/editor-mode-old-local-map)
806 (setq mime/editor-mode-old-local-map (current-local-map))
807 ;; Add MIME commands to current local map.
808 (use-local-map (copy-keymap (or (current-local-map)
809 (make-sparse-keymap))))
811 (if (not (lookup-key (current-local-map) mime-prefix))
812 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
814 ;; Set transfer level into mode line
816 (setq mime-editor/transfer-level-string
817 (mime/encoding-name mime-editor/transfer-level 'not-omit))
818 (force-mode-line-update)
820 ;; Define menu. Menus for other emacs implementations are
822 (cond (running-xemacs
823 (mime-editor/define-menu-for-xemacs))
824 ((>= emacs-major-version 19)
825 (mime-editor/define-menu-for-emacs19)
831 ;; I don't care about saving these.
832 (setq paragraph-start
833 (regexp-or mime-editor/single-part-tag-regexp
835 (setq paragraph-separate
836 (regexp-or mime-editor/single-part-tag-regexp
838 (run-hooks 'mime/editor-mode-hook)
840 (substitute-command-keys
841 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
845 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
846 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
848 (defun mime-editor/exit (&optional nomime no-error)
849 "Translate the tagged MIME message into a MIME compliant message.
850 With no argument encode a message in the buffer into MIME, otherwise
851 just return to previous mode."
853 (if (not mime/editor-mode-flag)
855 (error "You aren't editing a MIME message.")
859 (run-hooks 'mime-editor/translate-hook)
860 (mime-editor/translate-buffer)))
861 ;; Restore previous state.
862 (setq mime/editor-mode-flag nil)
863 (cond (running-xemacs
864 (if (featurep 'menubar)
865 (delete-menu-item (list mime-editor/menu-title))))
867 (use-local-map mime/editor-mode-old-local-map)))
870 (set-buffer-modified-p (buffer-modified-p))
871 (run-hooks 'mime-editor/exit-hook)
872 (message "Exit MIME editor mode.")
875 (defun mime-editor/maybe-translate ()
877 (mime-editor/exit nil t)
878 (call-interactively 'mime-editor/maybe-split-and-send)
881 (defun mime-editor/help ()
882 "Show help message about MIME mode."
884 (with-output-to-temp-buffer "*Help*"
885 (princ "MIME editor mode:\n")
886 (princ (documentation 'mime/editor-mode))
887 (print-help-return-message)))
889 (defun mime-editor/insert-text ()
890 "Insert a text message.
891 Charset is automatically obtained from the `charsets-mime-charset-alist'."
893 (let ((ret (mime-editor/insert-tag "text" nil nil)))
896 (if (looking-at mime-editor/single-part-tag-regexp)
898 ;; Make a space between the following message.
902 (if (and (member (second ret) '("enriched" "richtext"))
903 (fboundp 'enriched-mode)
906 (if (boundp 'enriched-mode)
910 (defun mime-editor/insert-file (file &optional verbose)
911 "Insert a message from a file."
912 (interactive "fInsert file as MIME message: \nP")
913 (let* ((guess (mime-find-file-type file))
915 (subtype (nth 1 guess))
916 (parameters (nth 2 guess))
917 (encoding (nth 3 guess))
918 (disposition-type (nth 4 guess))
919 (disposition-params (nth 5 guess))
922 (setq type (mime-prompt-for-type type)
923 subtype (mime-prompt-for-subtype type subtype)
925 (if (or (interactive-p) verbose (null encoding))
926 (setq encoding (mime-prompt-for-encoding encoding))
928 (if (or (consp parameters) (stringp disposition-type))
929 (let ((rest parameters) cell attribute value)
932 (setq cell (car rest))
933 (setq attribute (car cell))
934 (setq value (cdr cell))
936 (setq value (std11-wrap-as-quoted-string
937 (file-name-nondirectory file)))
939 (setq parameters (concat parameters "; " attribute "=" value))
940 (setq rest (cdr rest))
945 (concat parameters "\n"
946 "Content-Disposition: " disposition-type))
947 (setq rest disposition-params)
949 (setq cell (car rest))
950 (setq attribute (car cell))
951 (setq value (cdr cell))
953 (setq value (std11-wrap-as-quoted-string
954 (file-name-nondirectory file)))
957 (concat parameters "; " attribute "=" value))
958 (setq rest (cdr rest))
962 (mime-editor/insert-tag type subtype parameters)
963 (mime-editor/insert-binary-file file encoding)
967 ;; mime-editor/insert-file-verbose exists so that users can access verbose
968 ;; functionality from menu picks, and not just key sequences.
970 (defun mime-editor/insert-file-verbose (file)
971 "Insert a message from a file, with verbose MIME prompting"
972 (interactive "fInsert file as MIME message: \n")
973 (mime-editor/insert-file file t)
976 (defun mime-editor/insert-external ()
977 "Insert a reference to external body."
979 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
981 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
983 (let* ((pritype (mime-prompt-for-type))
984 (subtype (mime-prompt-for-subtype pritype))
985 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
988 (insert "Content-Type: "
989 pritype "/" subtype (or parameters "") "\n")))
990 (if (and (not (eobp))
991 (not (looking-at mime-editor/single-part-tag-regexp)))
992 (insert (mime-make-text-tag) "\n")))
994 (defun mime-editor/insert-voice ()
995 "Insert a voice message."
999 "What transfer encoding: "
1000 mime-file-encoding-method-alist nil t nil)))
1001 (mime-editor/insert-tag "audio" "basic" nil)
1002 (mime-editor/define-encoding encoding)
1004 (narrow-to-region (1- (point))(point))
1006 (funcall mime-editor/voice-recorder encoding)
1009 (invisible-region (point-min)(point-max))
1010 (goto-char (point-max))
1013 (defun mime-editor/insert-signature (&optional arg)
1014 "Insert a signature file."
1016 (let ((signature-insert-hook
1019 (apply (function mime-editor/insert-tag)
1020 (mime-find-file-type signature-file-name))
1023 (insert-signature arg)
1027 ;; Insert a new tag around a point.
1029 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
1030 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
1031 If nothing is inserted, return nil."
1034 (mime-editor/goto-tag)
1035 (if (and (re-search-forward mime-editor/tag-regexp nil t)
1036 (< (match-beginning 0) p)
1039 (goto-char (match-beginning 0))
1048 (mime-prompt-for-type)))
1051 (mime-prompt-for-subtype pritype)))
1054 (mime-prompt-for-parameters pritype subtype delimiter)))
1055 ;; Make a new MIME tag.
1056 (setq newtag (mime-make-tag pritype subtype parameters))
1057 ;; Find an current MIME tag.
1060 (if (mime-editor/goto-tag)
1061 (buffer-substring (match-beginning 0) (match-end 0))
1062 ;; Assume content type is 'text/plan'.
1063 (mime-make-tag "text" "plain")
1065 ;; We are only interested in TEXT.
1067 (not (mime-test-content-type
1068 (mime-editor/get-contype oldtag) "text")))
1071 (if (or (not oldtag) ;Not text
1072 (or mime-ignore-same-text-tag
1073 (not (string-equal oldtag newtag))))
1075 ;; Mark the beginning of the tag for convenience.
1076 (push-mark (point) 'nomsg)
1077 (insert newtag "\n")
1078 (list pritype subtype parameters) ;New tag is created.
1080 ;; Restore previous point.
1082 nil ;Nothing is created.
1086 (defun mime-editor/insert-binary-file (file &optional encoding)
1087 "Insert binary FILE at point.
1088 Optional argument ENCODING specifies an encoding method such as base64."
1089 (let* ((tagend (1- (point))) ;End of the tag
1090 (hide-p (and mime-auto-hide-body
1093 (let ((en (downcase encoding)))
1094 (or (string-equal en "7bit")
1095 (string-equal en "8bit")
1096 (string-equal en "binary")
1100 (narrow-to-region tagend (point))
1101 (mime-insert-encoded-file file encoding)
1104 (invisible-region (point-min) (point-max))
1105 (goto-char (point-max))
1107 (goto-char (point-max))
1110 (looking-at mime-editor/tag-regexp)
1111 (= (point)(point-max))
1112 (mime-editor/insert-tag "text" "plain")
1114 ;; Define encoding even if it is 7bit.
1115 (if (stringp encoding)
1117 (goto-char tagend) ; Make sure which line the tag is on.
1118 (mime-editor/define-encoding encoding)
1123 ;; Commands work on a current message flagment.
1125 (defun mime-editor/goto-tag ()
1126 "Search for the beginning of the tagged MIME message."
1127 (let ((current (point)) multipart)
1128 (if (looking-at mime-editor/tag-regexp)
1130 ;; At first, go to the end.
1131 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1132 (goto-char (1- (match-beginning 0))) ;For multiline tag
1135 (goto-char (point-max))
1137 ;; Then search for the beginning.
1138 (re-search-backward mime-editor/end-tag-regexp nil t)
1139 (or (looking-at mime-editor/beginning-tag-regexp)
1140 ;; Restore previous point.
1147 (defun mime-editor/content-beginning ()
1148 "Return the point of the beginning of content."
1150 (let ((beg (save-excursion
1151 (beginning-of-line) (point))))
1152 (if (mime-editor/goto-tag)
1153 (let ((top (point)))
1154 (goto-char (match-end 0))
1155 (if (and (= beg top)
1156 (= (following-char) ?\^M))
1160 ;; Default text/plain tag.
1161 (goto-char (point-min))
1163 (concat "\n" (regexp-quote mail-header-separator)
1164 (if mime-ignore-preceding-spaces
1165 "[ \t\n]*\n" "\n")) nil 'move)
1169 (defun mime-editor/content-end ()
1170 "Return the point of the end of content."
1172 (let ((beg (point)))
1173 (if (mime-editor/goto-tag)
1174 (let ((top (point)))
1175 (goto-char (match-end 0))
1176 (if (invisible-p (point))
1177 (next-visible-point (point))
1178 ;; Move to the end of this text.
1179 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1180 ;; Don't forget a multiline tag.
1181 (goto-char (match-beginning 0))
1185 ;; Assume the message begins with text/plain.
1186 (goto-char (mime-editor/content-beginning))
1187 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1188 ;; Don't forget a multiline tag.
1189 (goto-char (match-beginning 0)))
1193 (defun mime-editor/define-charset (charset)
1194 "Set charset of current tag to CHARSET."
1196 (if (mime-editor/goto-tag)
1197 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1198 (delete-region (match-beginning 0) (match-end 0))
1201 (mime-editor/set-parameter
1202 (mime-editor/get-contype tag)
1203 "charset" (upcase (symbol-name charset)))
1204 (mime-editor/get-encoding tag)))
1207 (defun mime-editor/define-encoding (encoding)
1208 "Set encoding of current tag to ENCODING."
1210 (if (mime-editor/goto-tag)
1211 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1212 (delete-region (match-beginning 0) (match-end 0))
1213 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1216 (defun mime-editor/choose-charset ()
1217 "Choose charset of a text following current point."
1218 (detect-mime-charset-region (point) (mime-editor/content-end))
1221 (defun mime-make-text-tag (&optional subtype)
1222 "Make a tag for a text after current point.
1223 Subtype of text type can be specified by an optional argument SUBTYPE.
1224 Otherwise, it is obtained from mime-content-types."
1225 (let* ((pritype "text")
1226 (subtype (or subtype
1227 (car (car (cdr (assoc pritype mime-content-types)))))))
1228 ;; Charset should be defined later.
1229 (mime-make-tag pritype subtype)))
1232 ;; Tag handling functions
1234 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1235 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1236 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1240 (defun mime-create-tag (contype &optional encoding)
1241 "Make a tag with CONTENT-TYPE and optional ENCODING."
1242 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1245 (defun mime-editor/get-contype (tag)
1246 "Return Content-Type (including parameters) of TAG."
1248 (or (string-match mime-editor/single-part-tag-regexp tag)
1249 (string-match mime-editor/multipart-beginning-regexp tag)
1250 (string-match mime-editor/multipart-end-regexp tag)
1252 (substring tag (match-beginning 1) (match-end 1))
1255 (defun mime-editor/get-encoding (tag)
1256 "Return encoding of TAG."
1258 (string-match mime-editor/single-part-tag-regexp tag)
1260 (not (= (match-beginning 3) (match-end 3)))
1261 (substring tag (match-beginning 3) (match-end 3))))
1263 (defun mime-get-parameter (contype parameter)
1264 "For given CONTYPE return value for PARAMETER.
1265 Nil if no such parameter."
1269 (regexp-quote parameter)
1270 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1272 (substring contype (match-beginning 1) (match-end 1))
1273 nil ;No such parameter
1276 (defun mime-editor/set-parameter (contype parameter value)
1277 "For given CONTYPE set PARAMETER to VALUE."
1278 (let (ctype opt-fields)
1279 (if (string-match "\n[^ \t\n\r]+:" contype)
1280 (setq ctype (substring contype 0 (match-beginning 0))
1281 opt-fields (substring contype (match-beginning 0)))
1282 (setq ctype contype)
1287 (regexp-quote parameter)
1288 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1291 (concat (substring ctype 0 (match-beginning 1))
1293 (substring contype (match-end 1))
1295 (concat ctype "; " parameter "=" value opt-fields)
1298 (defun mime-strip-parameters (contype)
1299 "Return primary content-type and subtype without parameters for CONTYPE."
1300 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1301 (substring contype (match-beginning 1) (match-end 1)) nil))
1303 (defun mime-test-content-type (contype type &optional subtype)
1304 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1305 (and (stringp contype)
1308 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1309 (downcase contype))))
1314 (defun mime-find-file-type (file)
1315 "Guess Content-Type, subtype, and parameters from FILE."
1317 (guesses mime-file-types)
1318 (case-fold-search t))
1319 (while (and (not guess) guesses)
1320 (if (string-match (car (car guesses)) file)
1321 (setq guess (cdr (car guesses))))
1322 (setq guesses (cdr guesses)))
1326 (defun mime-prompt-for-type (&optional default)
1327 "Ask for Content-type."
1329 ;; Repeat until primary content type is specified.
1330 (while (string-equal type "")
1332 (completing-read "What content type: "
1335 'require-match ;Type must be specified.
1338 (if (string-equal type "")
1340 (message "Content type is required.")
1347 (defun mime-prompt-for-subtype (type &optional default)
1348 "Ask for subtype of media-type TYPE."
1349 (let ((subtypes (cdr (assoc type mime-content-types))))
1351 (assoc default subtypes))
1352 (setq default (car (car subtypes)))
1358 "What content subtype: (default " default ") ")
1359 "What content subtype: ")
1360 (cdr (assoc type mime-content-types))
1362 'require-match ;Subtype must be specified.
1365 (if (string-equal answer "") default answer)))
1367 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1368 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1369 Optional DELIMITER specifies parameter delimiter (';' by default)."
1370 (let* ((delimiter (or delimiter "; "))
1375 (mime-prompt-for-parameters-1
1377 (cdr (assoc pritype mime-content-types))))))
1380 (if (and (stringp parameters)
1381 (not (string-equal parameters "")))
1382 (concat delimiter parameters)
1383 "" ;"" if no parameters
1386 (defun mime-prompt-for-parameters-1 (optlist)
1387 (apply (function append)
1388 (mapcar (function mime-prompt-for-parameter) optlist)))
1390 (defun mime-prompt-for-parameter (parameter)
1392 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1393 (let* ((prompt (car parameter))
1394 (choices (mapcar (function
1396 (if (consp e) e (list e))))
1398 (default (car (car choices)))
1404 (concat "What " prompt
1406 (if (string-equal default "") "\"\"" default)
1408 choices nil nil ""))
1409 ;; If nothing is selected, use default.
1410 (if (string-equal answer "")
1411 (setq answer default)))
1413 (read-string (concat "What " prompt ": "))))
1414 (cons (if (and answer
1415 (not (string-equal answer "")))
1417 ;; Note: control characters ignored!
1418 (if (string-match mime-tspecials-regexp answer)
1419 (concat "\"" answer "\"") answer)))
1420 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1423 (defun mime-prompt-for-encoding (default)
1424 "Ask for Content-Transfer-Encoding. [tm-edit.el]"
1429 "What transfer encoding: "
1430 mime-file-encoding-method-alist nil t default)
1436 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1439 (defvar mime-editor/translate-buffer-hook
1440 '(mime-editor/pgp-enclose-buffer
1441 mime-editor/translate-header
1442 mime-editor/translate-body))
1444 (defun mime-editor/translate-header ()
1445 "Encode the message header into network representation."
1446 (eword-encode-header 'code-conversion)
1447 (run-hooks 'mime-editor/translate-header-hook)
1450 (defun mime-editor/translate-buffer ()
1451 "Encode the tagged MIME message in current buffer in MIME compliant message."
1453 (if (catch 'mime-editor/error
1455 (run-hooks 'mime-editor/translate-buffer-hook)
1459 (error "Translation error!")
1462 (defun mime-editor/find-inmost ()
1463 (goto-char (point-min))
1464 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1465 (let ((bb (match-beginning 0))
1467 (type (buffer-substring (match-beginning 1)(match-end 1)))
1469 (setq end-exp (format "--}-<<%s>>\n" type))
1471 (if (re-search-forward end-exp nil t)
1473 (setq eb (match-beginning 0))
1474 (setq ee (match-end 0))
1476 (setq eb (point-max))
1477 (setq ee (point-max))
1479 (narrow-to-region be eb)
1481 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1483 (narrow-to-region (match-beginning 0)(point-max))
1484 (mime-editor/find-inmost)
1487 (list type bb be eb)
1490 (defun mime-editor/process-multipart-1 (boundary)
1491 (let ((ret (mime-editor/find-inmost)))
1493 (let ((type (car ret))
1494 (bb (nth 1 ret))(be (nth 2 ret))
1497 (narrow-to-region bb eb)
1498 (delete-region bb be)
1499 (setq bb (point-min))
1500 (setq eb (point-max))
1503 (if (looking-at mime-editor/multipart-end-regexp)
1504 (let ((beg (match-beginning 0))
1507 (delete-region beg end)
1508 (or (looking-at mime-editor/beginning-tag-regexp)
1510 (insert (concat (mime-make-text-tag) "\n"))
1512 (cond ((string-equal type "quote")
1513 (mime-editor/enquote-region bb eb)
1515 ((string-equal type "signed")
1516 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1517 (mime-editor/sign-pgp-elkins bb eb boundary)
1519 ((eq mime-editor/signing-type 'pgp-kazu)
1520 (mime-editor/sign-pgp-kazu bb eb boundary)
1523 ((string-equal type "encrypted")
1524 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1525 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1527 ((eq mime-editor/encrypting-type 'pgp-kazu)
1528 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1532 (nth 2 (mime-editor/translate-region bb eb
1536 (format "--[[multipart/%s;
1537 boundary=\"%s\"][7bit]]\n"
1542 (defun mime-editor/enquote-region (beg end)
1545 (narrow-to-region beg end)
1547 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1548 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1549 (replace-match (concat "- " (substring tag 1)))
1552 (defun mime-editor/dequote-region (beg end)
1555 (narrow-to-region beg end)
1557 (while (re-search-forward
1558 mime-editor/quoted-single-part-tag-regexp nil t)
1559 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1560 (replace-match (concat "-" (substring tag 2)))
1563 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1566 (narrow-to-region beg end)
1568 (mime-editor/translate-region beg end boundary))
1570 (encoding (nth 1 ret))
1572 (pgp-boundary (concat "pgp-sign-" boundary))
1575 (insert (format "Content-Type: %s\n" ctype))
1577 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1580 (or (as-binary-process
1581 (funcall (pgp-function 'mime-sign)
1582 (point-min)(point-max) nil nil pgp-boundary))
1583 (throw 'mime-editor/error 'pgp-error)
1587 (defvar mime-editor/encrypt-recipient-fields-list '("To" "cc"))
1589 (defun mime-editor/make-encrypt-recipient-header ()
1590 (let* ((names mime-editor/encrypt-recipient-fields-list)
1592 (std11-field-bodies (cons "From" names)
1593 nil mail-header-separator))
1596 (setq values (cdr values))))
1597 (header (and (stringp from)
1598 (if (string-equal from "")
1600 (format "From: %s\n" from)
1603 (while (and names values)
1604 (let ((name (car names))
1605 (value (car values))
1607 (and (stringp value)
1608 (or (string-equal value "")
1610 (setq header (concat header name ": " value "\n")
1611 recipients (if recipients
1612 (concat recipients " ," value)
1615 (setq names (cdr names)
1616 values (cdr values))
1618 (vector from recipients header)
1621 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1624 (let (from recipients header)
1625 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1626 (setq from (aref ret 0)
1627 recipients (aref ret 1)
1628 header (aref ret 2))
1630 (narrow-to-region beg end)
1632 (mime-editor/translate-region beg end boundary))
1634 (encoding (nth 1 ret))
1636 (pgp-boundary (concat "pgp-" boundary))
1640 (insert (format "Content-Type: %s\n" ctype))
1642 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1645 (or (funcall (pgp-function 'encrypt)
1646 recipients (point-min) (point-max) from)
1647 (throw 'mime-editor/error 'pgp-error)
1650 (insert (format "--[[multipart/encrypted;
1652 protocol=\"application/pgp-encrypted\"][7bit]]
1654 Content-Type: application/pgp-encrypted
1657 Content-Type: application/octet-stream
1658 Content-Transfer-Encoding: 7bit
1660 " pgp-boundary pgp-boundary pgp-boundary))
1661 (goto-char (point-max))
1662 (insert (format "\n--%s--\n" pgp-boundary))
1665 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1668 (narrow-to-region beg end)
1670 (mime-editor/translate-region beg end boundary))
1672 (encoding (nth 1 ret))
1676 (insert (format "Content-Type: %s\n" ctype))
1678 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1681 (or (as-binary-process
1682 (funcall (pgp-function 'traditional-sign)
1684 (throw 'mime-editor/error 'pgp-error)
1688 "--[[application/pgp; format=mime][7bit]]\n")
1692 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1694 (let (from recipients header)
1695 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1696 (setq from (aref ret 0)
1697 recipients (aref ret 1)
1698 header (aref ret 2))
1701 (narrow-to-region beg end)
1703 (mime-editor/translate-region beg end boundary))
1705 (encoding (nth 1 ret))
1710 (insert (format "Content-Type: %s\n" ctype))
1712 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1715 (or (as-binary-process
1716 (funcall (pgp-function 'encrypt)
1717 recipients beg (point-max) nil 'maybe)
1719 (throw 'mime-editor/error 'pgp-error)
1723 "--[[application/pgp; format=mime][7bit]]\n")
1727 (defun mime-editor/translate-body ()
1728 "Encode the tagged MIME body in current buffer in MIME compliant message."
1732 (concat mime-multipart-boundary "_"
1733 (replace-space-with-underline (current-time-string))
1737 (while (mime-editor/process-multipart-1
1738 (format "%s-%d" boundary i))
1742 ;; We are interested in message body.
1745 (goto-char (point-min))
1747 (concat "\n" (regexp-quote mail-header-separator)
1748 (if mime-ignore-preceding-spaces
1749 "[ \t\n]*\n" "\n")) nil 'move)
1753 (goto-char (point-max))
1754 (and mime-ignore-trailing-spaces
1755 (re-search-backward "[^ \t\n]\n" beg t)
1758 (setq ret (mime-editor/translate-region
1760 (format "%s-%d" boundary i)))
1762 (mime-editor/dequote-region (point-min)(point-max))
1763 (let ((contype (car ret)) ;Content-Type
1764 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1766 ;; Make primary MIME headers.
1767 (or (mail-position-on-field "Mime-Version")
1768 (insert mime-editor/mime-version-value))
1769 ;; Remove old Content-Type and other fields.
1771 (goto-char (point-min))
1772 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1773 (narrow-to-region (point-min) (point))
1774 (goto-char (point-min))
1775 (mime-delete-field "Content-Type")
1776 (mime-delete-field "Content-Transfer-Encoding"))
1777 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1778 (mail-position-on-field "Content-Type")
1782 (mail-position-on-field "Content-Transfer-Encoding")
1786 (defun mime-editor/translate-single-part-tag (&optional prefix)
1787 (if (re-search-forward mime-editor/single-part-tag-regexp nil t)
1788 (let* ((beg (match-beginning 0))
1790 (tag (buffer-substring beg end))
1792 (delete-region beg end)
1793 (let ((contype (mime-editor/get-contype tag))
1794 (encoding (mime-editor/get-encoding tag))
1796 (insert (concat prefix "--" boundary "\n"))
1798 (narrow-to-region (point)(point))
1799 (insert "Content-Type: " contype "\n")
1801 (insert "Content-Transfer-Encoding: " encoding "\n"))
1802 (eword-encode-header)
1806 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1809 (concat mime-multipart-boundary "_"
1810 (replace-space-with-underline (current-time-string))))
1814 (narrow-to-region beg end)
1815 (let ((tag nil) ;MIME tag
1816 (contype nil) ;Content-Type
1817 (encoding nil) ;Content-Transfer-Encoding
1818 (nparts 0)) ;Number of body parts
1819 ;; Normalize the body part by inserting appropriate message
1820 ;; tags for every message contents.
1821 (mime-editor/normalize-body)
1822 ;; Counting the number of Content-Type.
1823 (goto-char (point-min))
1824 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1825 (setq nparts (1+ nparts)))
1826 ;; Begin translation.
1828 ((and (<= nparts 1)(not multipart))
1829 ;; It's a singular message.
1830 (goto-char (point-min))
1831 (while (re-search-forward
1832 mime-editor/single-part-tag-regexp nil t)
1834 (buffer-substring (match-beginning 0) (match-end 0)))
1835 (delete-region (match-beginning 0) (1+ (match-end 0)))
1836 (setq contype (mime-editor/get-contype tag))
1837 (setq encoding (mime-editor/get-encoding tag))
1840 ;; It's a multipart message.
1841 (goto-char (point-min))
1842 (and (mime-editor/translate-single-part-tag)
1843 (while (mime-editor/translate-single-part-tag "\n"))
1845 ;; Define Content-Type as "multipart/mixed".
1847 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1848 ;; Content-Transfer-Encoding must be "7bit".
1849 ;; The following encoding can be `nil', but is
1850 ;; specified as is since there is no way that a user
1852 (setq encoding "7bit")
1853 ;; Insert the trailer.
1854 (goto-char (point-max))
1855 (insert "\n--" boundary "--\n")
1857 (list contype encoding boundary nparts)
1860 (defun mime-editor/normalize-body ()
1861 "Normalize the body part by inserting appropriate message tags."
1862 ;; Insert the first MIME tags if necessary.
1863 (goto-char (point-min))
1864 (if (not (looking-at mime-editor/single-part-tag-regexp))
1865 (insert (mime-make-text-tag) "\n"))
1866 ;; Check each tag, and add new tag or correct it if necessary.
1867 (goto-char (point-min))
1868 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1869 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1870 (contype (mime-editor/get-contype tag))
1871 (charset (mime-get-parameter contype "charset"))
1872 (encoding (mime-editor/get-encoding tag)))
1873 ;; Remove extra whitespaces after the tag.
1874 (if (looking-at "[ \t]+$")
1875 (delete-region (match-beginning 0) (match-end 0)))
1877 (end (mime-editor/content-end))
1879 (if (= end (point-max))
1882 (or (looking-at mime-editor/beginning-tag-regexp)
1884 (insert (mime-make-text-tag) "\n")
1886 (visible-region beg end)
1890 ((mime-test-content-type contype "message")
1891 ;; Content-type "message" should be sent as is.
1894 ((mime-test-content-type contype "text")
1895 ;; Define charset for text if necessary.
1896 (setq charset (if charset
1897 (intern (downcase charset))
1898 (mime-editor/choose-charset)))
1899 (mime-editor/define-charset charset)
1900 (cond ((string-equal contype "text/x-rot13-47")
1904 (goto-char (mime-editor/content-end))
1907 ((string-equal contype "text/enriched")
1912 (end (mime-editor/content-end))
1914 ;; Patch for hard newlines
1917 ;; (while (search-forward "\n" end t)
1918 ;; (put-text-property (match-beginning 0)
1921 ;; End patch for hard newlines
1922 (enriched-encode beg end)
1924 (if (search-forward "\n\n")
1925 (delete-region beg (match-end 0))
1928 ;; Point is now on current tag.
1929 ;; Define encoding and encode text if necessary.
1930 (or encoding ;Encoding is not specified.
1934 mime-editor/charset-default-encoding-alist)
1936 (beg (mime-editor/content-beginning))
1938 (encode-mime-charset-region beg (mime-editor/content-end)
1941 (mime-encode-region beg (mime-editor/content-end) encoding))
1942 (mime-editor/define-encoding encoding)
1944 (goto-char (mime-editor/content-end))
1946 ((null encoding) ;Encoding is not specified.
1947 ;; Application, image, audio, video, and any other
1948 ;; unknown content-type without encoding should be
1950 (let* ((encoding "base64") ;Encode in BASE64 by default.
1951 (beg (mime-editor/content-beginning))
1952 (end (mime-editor/content-end))
1953 (body (buffer-substring beg end))
1955 (mime-encode-region beg end encoding)
1956 (mime-editor/define-encoding encoding))
1961 (defun mime-delete-field (field)
1962 "Delete header FIELD."
1963 (let ((regexp (format "^%s:[ \t]*" field)))
1964 (goto-char (point-min))
1965 (while (re-search-forward regexp nil t)
1966 (delete-region (match-beginning 0)
1967 (progn (forward-line 1) (point)))
1972 ;;; Platform dependent functions
1975 ;; Sun implementations
1977 (defun mime-editor/voice-recorder-for-sun (encoding)
1978 "Record voice in a buffer using Sun audio device,
1979 and insert data encoded as ENCODING. [tm-edit.el]"
1980 (message "Start the recording on %s. Type C-g to finish the recording..."
1982 (mime-insert-encoded-file "/dev/audio" encoding)
1986 ;;; @ Other useful commands.
1989 ;; Message forwarding commands as content-type "message/rfc822".
1991 (defun mime-editor/insert-message (&optional message)
1993 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
1994 (if (and inserter (fboundp inserter))
1996 (mime-editor/insert-tag "message" "rfc822")
1997 (funcall inserter message)
1999 (message "Sorry, I don't have message inserter for your MUA.")
2002 (defun mime-editor/insert-mail (&optional message)
2004 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2005 (if (and inserter (fboundp inserter))
2007 (mime-editor/insert-tag "message" "rfc822")
2008 (funcall inserter message)
2010 (message "Sorry, I don't have mail inserter for your MUA.")
2013 (defun mime-editor/inserted-message-filter ()
2016 (let ((header-start (point))
2017 (case-fold-search t)
2020 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2021 (if (re-search-forward "^$" (mark t))
2022 (narrow-to-region header-start (match-beginning 0))
2024 (goto-char header-start)
2025 (while (and (re-search-forward
2026 mime-editor/yank-ignored-field-regexp nil t)
2027 (setq beg (match-beginning 0))
2028 (setq end (1+ (std11-field-end)))
2030 (delete-region beg end)
2035 ;;; @ multipart enclosure
2038 (defun mime-editor/enclose-region (type beg end)
2041 (let ((current (point)))
2043 (narrow-to-region beg end)
2044 (insert (format "--<<%s>>-{\n" type))
2045 (goto-char (point-max))
2046 (insert (format "--}-<<%s>>\n" type))
2047 (goto-char (point-max))
2049 (or (looking-at mime-editor/beginning-tag-regexp)
2051 (insert (mime-make-text-tag) "\n")
2055 (defun mime-editor/enclose-quote-region (beg end)
2057 (mime-editor/enclose-region "quote" beg end)
2060 (defun mime-editor/enclose-mixed-region (beg end)
2062 (mime-editor/enclose-region "mixed" beg end)
2065 (defun mime-editor/enclose-parallel-region (beg end)
2067 (mime-editor/enclose-region "parallel" beg end)
2070 (defun mime-editor/enclose-digest-region (beg end)
2072 (mime-editor/enclose-region "digest" beg end)
2075 (defun mime-editor/enclose-alternative-region (beg end)
2077 (mime-editor/enclose-region "alternative" beg end)
2080 (defun mime-editor/enclose-signed-region (beg end)
2082 (if mime-editor/signing-type
2083 (mime-editor/enclose-region "signed" beg end)
2084 (message "Please specify signing type.")
2087 (defun mime-editor/enclose-encrypted-region (beg end)
2089 (if mime-editor/signing-type
2090 (mime-editor/enclose-region "encrypted" beg end)
2091 (message "Please specify encrypting type.")
2094 (defun mime-editor/insert-key (&optional arg)
2095 "Insert a pgp public key."
2097 (mime-editor/insert-tag "application" "pgp-keys")
2098 (mime-editor/define-encoding "7bit")
2099 (funcall (pgp-function 'insert-key))
2106 (defun mime-editor/set-split (arg)
2109 (y-or-n-p "Do you want to enable split?")
2111 (setq mime-editor/split-message arg)
2113 (message "This message is enabled to split.")
2114 (message "This message is not enabled to split.")
2117 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2118 "Toggle transfer-level is 7bit or 8bit through.
2120 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2122 (if (numberp transfer-level)
2123 (setq mime-editor/transfer-level transfer-level)
2124 (if (< mime-editor/transfer-level 8)
2125 (setq mime-editor/transfer-level 8)
2126 (setq mime-editor/transfer-level 7)
2128 (setq mime-editor/charset-default-encoding-alist
2129 (mime-editor/make-charset-default-encoding-alist
2130 mime-editor/transfer-level))
2131 (message (format "Current transfer-level is %d bit"
2132 mime-editor/transfer-level))
2133 (setq mime-editor/transfer-level-string
2134 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2135 (force-mode-line-update)
2138 (defun mime-editor/set-transfer-level-7bit ()
2140 (mime-editor/toggle-transfer-level 7)
2143 (defun mime-editor/set-transfer-level-8bit ()
2145 (mime-editor/toggle-transfer-level 8)
2152 (defun mime-editor/set-sign (arg)
2155 (y-or-n-p "Do you want to sign?")
2158 (if mime-editor/signing-type
2160 (setq mime-editor/pgp-processing 'sign)
2161 (message "This message will be signed.")
2163 (message "Please specify signing type.")
2165 (if (eq mime-editor/pgp-processing 'sign)
2166 (setq mime-editor/pgp-processing nil)
2168 (message "This message will not be signed.")
2171 (defun mime-editor/set-encrypt (arg)
2174 (y-or-n-p "Do you want to encrypt?")
2177 (if mime-editor/encrypting-type
2179 (setq mime-editor/pgp-processing 'encrypt)
2180 (message "This message will be encrypt.")
2182 (message "Please specify encrypting type.")
2184 (if (eq mime-editor/pgp-processing 'encrypt)
2185 (setq mime-editor/pgp-processing nil)
2187 (message "This message will not be encrypt.")
2190 (defvar mime-editor/pgp-processing nil)
2191 (make-variable-buffer-local 'mime-editor/pgp-processing)
2193 (defun mime-editor/pgp-enclose-buffer ()
2194 (let ((beg (save-excursion
2195 (goto-char (point-min))
2196 (if (search-forward (concat "\n" mail-header-separator "\n"))
2202 (cond ((eq mime-editor/pgp-processing 'sign)
2203 (mime-editor/enclose-signed-region beg end)
2205 ((eq mime-editor/pgp-processing 'encrypt)
2206 (mime-editor/enclose-encrypted-region beg end)
2214 (defun mime-editor/insert-partial-header
2215 (fields subject id number total separator)
2217 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2218 (insert (format "Mime-Version: 1.0 (split by %s)\n"
2219 mime-editor/version-name))
2221 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2222 id number total separator))
2225 (defun mime-editor/split-and-send
2226 (&optional cmd lines mime-editor/message-max-length)
2230 (count-lines (point-min) (point-max)))
2232 (or mime-editor/message-max-length
2233 (setq mime-editor/message-max-length
2234 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
2235 mime-editor/message-default-max-lines))
2237 (let* ((mime-editor/draft-file-name
2238 (or (buffer-file-name)
2240 (expand-file-name "tm-draft" mime/tmp-dir))))
2241 (separator mail-header-separator)
2243 (replace-space-with-underline (current-time-string))
2244 "@" (system-name) "\"")))
2245 (run-hooks 'mime-editor/before-split-hook)
2246 (let ((the-buf (current-buffer))
2247 (copy-buf (get-buffer-create " *Original Message*"))
2248 (header (std11-header-string-except
2249 mime-editor/split-ignored-field-regexp separator))
2250 (subject (mail-fetch-field "subject"))
2251 (total (+ (/ lines mime-editor/message-max-length)
2252 (if (> (mod lines mime-editor/message-max-length) 0)
2258 mime-editor/split-message-sender-alist))
2262 (error "Split sender is not specified for `%s'." major-mode)
2265 (mime-editor/partial-number 1)
2268 (set-buffer copy-buf)
2270 (insert-buffer the-buf)
2272 (if (re-search-forward
2273 (concat "^" (regexp-quote separator) "$") nil t)
2274 (let ((he (match-beginning 0)))
2276 (narrow-to-region (point-min) he)
2278 (goto-char (point-min))
2279 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
2280 (delete-region (match-beginning 0)
2281 (1+ (std11-field-end)))
2283 (while (< mime-editor/partial-number total)
2286 (set-buffer copy-buf)
2287 (setq data (buffer-substring
2290 (goto-line mime-editor/message-max-length)
2293 (delete-region (point-min)(point))
2295 (mime-editor/insert-partial-header
2296 header subject id mime-editor/partial-number total separator)
2299 (message (format "Sending %d/%d..."
2300 mime-editor/partial-number total))
2301 (call-interactively command)
2302 (message (format "Sending %d/%d... done"
2303 mime-editor/partial-number total))
2305 (setq mime-editor/partial-number
2306 (1+ mime-editor/partial-number))
2310 (set-buffer copy-buf)
2311 (setq data (buffer-string))
2314 (mime-editor/insert-partial-header
2315 header subject id mime-editor/partial-number total separator)
2318 (message (format "Sending %d/%d..."
2319 mime-editor/partial-number total))
2320 (message (format "Sending %d/%d... done"
2321 mime-editor/partial-number total))
2325 (defun mime-editor/maybe-split-and-send (&optional cmd)
2327 (run-hooks 'mime-editor/before-send-hook)
2328 (let ((mime-editor/message-max-length
2329 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
2330 mime-editor/message-default-max-lines))
2331 (lines (count-lines (point-min) (point-max)))
2333 (if (and (> lines mime-editor/message-max-length)
2334 mime-editor/split-message)
2335 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2339 ;;; @ preview message
2342 (defun mime-editor/preview-message ()
2343 "preview editing MIME message. [tm-edit.el]"
2345 (let* ((str (buffer-string))
2346 (separator mail-header-separator)
2347 (the-buf (current-buffer))
2348 (buf-name (buffer-name))
2349 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2350 (buf (get-buffer temp-buf-name))
2354 (switch-to-buffer buf)
2357 (setq buf (get-buffer-create temp-buf-name))
2358 (switch-to-buffer buf)
2361 (setq major-mode 'mime/temporary-message-mode)
2362 (make-local-variable 'mail-header-separator)
2363 (setq mail-header-separator separator)
2364 (make-local-variable 'mime/editing-buffer)
2365 (setq mime/editing-buffer the-buf)
2367 (run-hooks 'mime-editor/translate-hook)
2368 (mime-editor/translate-buffer)
2369 (goto-char (point-min))
2370 (if (re-search-forward
2371 (concat "^" (regexp-quote separator) "$"))
2377 (defun mime-editor/quitting-method ()
2378 (let ((temp mime::preview/article-buffer)
2380 (mime-viewer/kill-buffer)
2382 (setq buf mime/editing-buffer)
2384 (switch-to-buffer buf)
2387 (set-alist 'mime-viewer/quitting-method-alist
2388 'mime/temporary-message-mode
2389 (function mime-editor/quitting-method)
2395 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2396 ;; Mon, 10 Apr 1995 20:03:07 +0900
2398 (defvar mime-editor/draft-header-separator-alist
2399 '((news-reply-mode . mail-header-separator)
2400 (mh-letter-mode . mail-header-separator)
2403 (defvar mime::article/draft-header-separator nil)
2405 (defun mime-editor/draft-preview ()
2407 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2408 (or (stringp sep) (setq sep (eval sep)))
2409 (make-variable-buffer-local 'mime::article/draft-header-separator)
2410 (goto-char (point-min))
2412 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2413 (setq mime::article/draft-header-separator
2414 (buffer-substring (match-beginning 0) (match-end 0)))
2416 (mime/viewer-mode (current-buffer))
2417 (pop-to-buffer (current-buffer))
2420 (defun mime-viewer::quitting-method/draft-preview ()
2421 (let ((mother mime::preview/mother-buffer))
2423 (switch-to-buffer mother)
2424 (goto-char (point-min))
2428 (regexp-quote mime::article/draft-header-separator)
2432 (insert mime::article/draft-header-separator)
2433 (set-buffer-modified-p (buffer-modified-p))
2435 (mime-viewer/kill-buffer)
2436 (pop-to-buffer mother)
2439 (set-alist 'mime-viewer/quitting-method-alist
2441 (function mime-viewer::quitting-method/draft-preview)
2444 (set-alist 'mime-viewer/quitting-method-alist
2446 (function mime-viewer::quitting-method/draft-preview)
2453 (defun mime-editor::edit-again (code-conversion)
2455 (goto-char (point-min))
2456 (let ((ctl (mime/Content-Type)))
2458 (let ((ctype (car ctl))
2461 (if (string-match "/" ctype)
2463 (setq type (substring ctype 0 (match-beginning 0)))
2464 (setq stype (substring ctype (match-end 0)))
2469 ((string= ctype "application/pgp-signature")
2470 (delete-region (point-min)(point-max))
2472 ((string= type "multipart")
2473 (let* ((boundary (assoc-value "boundary" params))
2475 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2477 (re-search-forward boundary-pat nil t)
2478 (let ((bb (match-beginning 0)) eb tag)
2479 (setq tag (format "\n--<<%s>>-{\n" stype))
2482 (setq bb (+ bb (length tag)))
2484 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2486 (setq eb (match-beginning 0))
2487 (replace-match (format "--}-<<%s>>\n" stype))
2489 (narrow-to-region bb eb)
2490 (goto-char (point-min))
2491 (while (re-search-forward boundary-pat nil t)
2492 (let ((beg (match-beginning 0))
2494 (delete-region beg (match-end 0))
2496 (if (re-search-forward boundary-pat nil t)
2497 (setq end (match-beginning 0))
2498 (setq end (point-max))
2501 (narrow-to-region beg end)
2502 (mime-editor::edit-again code-conversion)
2503 (goto-char (point-max))
2506 (goto-char (point-min))
2507 (or (= (point-min) 1)
2508 (delete-region (point-min)
2509 (if (search-forward "\n\n" nil t)
2517 (let ((bytes (+ 14 (length ctype))))
2518 (mapconcat (function
2520 (if (string-equal (car attr) "charset")
2522 (setq charset (cdr attr))
2530 (setq bytes (+ bytes bs 2))
2533 (setq bytes (+ bs 1))
2541 (if (re-search-forward
2542 "Content-Transfer-Encoding:" nil t)
2543 (let ((beg (match-beginning 0))
2544 (hbeg (match-end 0))
2545 (end (std11-field-end)))
2547 (eliminate-top-spaces
2548 (std11-unfold-string
2549 (buffer-substring hbeg end))))
2550 (if (or charset (string-equal type "text"))
2552 (delete-region beg (1+ end))
2553 (goto-char (point-min))
2554 (if (search-forward "\n\n" nil t)
2557 (match-end 0)(point-max) encoding)
2561 (if (or code-conversion encoded)
2562 (decode-mime-charset-region
2563 (point-min)(point-max)
2564 (or charset default-mime-charset))
2567 (if (re-search-forward "^$" nil t)
2571 (if (= (point-min) 1)
2577 (concat type "/" stype pstr) encoding)))
2579 (delete-region (point-min) he)
2582 (concat type "/" stype pstr) encoding))
2586 (decode-mime-charset-region (point-min) (point-max)
2587 default-mime-charset)
2591 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2593 (mime-editor::edit-again code-conversion)
2594 (goto-char (point-min))
2598 (if (re-search-forward
2599 (concat "^\\(" (regexp-quote mail-header-separator) "\\)?$")
2604 (goto-char (point-min))
2605 (while (re-search-forward
2606 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2607 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2610 (and (re-search-forward "^$")
2611 (replace-match mail-header-separator)
2623 (run-hooks 'tm-edit-load-hook)
2625 ;;; tm-edit.el ends here