1 ;;; tm-edit.el --- Simple MIME Composer for GNU Emacs
3 ;; Copyright (C) 1993 .. 1996 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 ;; Version: $Revision: 7.96 $
10 ;; Keywords: mail, news, MIME, multimedia, multilingual
12 ;; This file is part of tm (Tools for MIME).
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 (a multilingual extension to Emacs 18 and 19) has a capability
39 ;; of handling multilingual text in limited ISO-2022 manner that is
40 ;; based on early experiences in Japanese Internet community and
41 ;; resulted in RFC 1468 (ISO-2022-JP charset for MIME). In order to
42 ;; enable multilingual capability in single text message in MIME,
43 ;; charset of multilingual text written in Mule is declared as either
44 ;; `ISO-2022-JP-2' [RFC 1554] or `ISO-2022-INT-1'. Mule is required
45 ;; 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/editor-mode automatically:
51 ;; (autoload 'mime/editor-mode "tm-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 'mime/editor-mode)
58 ;; (add-hook 'mail-send-hook 'mime-editor/maybe-translate)
60 ;; In case of MH-E, you need the following hook definition:
62 ;; (add-hook 'mh-letter-mode-hook
66 ;; (make-local-variable 'mail-header-separator)
67 ;; (setq mail-header-separator "--------")
69 ;; (add-hook 'mh-before-send-letter-hook 'mime-editor/maybe-translate)
71 ;; In case of News mode, you need the following hook definition:
73 ;; (add-hook 'news-reply-mode-hook 'mime/editor-mode)
74 ;; (add-hook 'news-inews-hook 'mime-editor/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/editor-mode-hook
83 ;; (setq font-lock-keywords (list mime-editor/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.
98 ;;--[[text/plain; charset=ISO-2022-JP]]
99 ;;
\e$B$3$l$O
\e(B charset
\e$B$r
\e(B ISO-2022-JP
\e$B$K;XDj$7$?F|K\8l$N
\e(B plain
\e$B%F%-%9%H$G$9
\e(B.
101 ;;--[[text/richtext]]
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...
111 (require 'mail-utils)
123 (defconst mime-editor/RCS-ID
124 "$Id: tm-edit.el,v 7.96 1996/12/10 06:28:34 morioka Exp $")
126 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
128 (defconst mime-editor/version-name
129 (concat "tm-edit " mime-editor/version))
135 (defvar mime-prefix "\C-c\C-x"
136 "*Keymap prefix for MIME commands.")
138 (defvar mime-ignore-preceding-spaces nil
139 "*Ignore preceding white spaces if non-nil.")
141 (defvar mime-ignore-trailing-spaces nil
142 "*Ignore trailing white spaces if non-nil.")
144 (defvar mime-ignore-same-text-tag t
145 "*Ignore preceding text content-type tag that is same with new one.
146 If non-nil, the text tag is not inserted unless something different.")
148 (defvar mime-auto-hide-body t
149 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
151 (defvar mime-editor/voice-recorder
152 (function mime-editor/voice-recorder-for-sun)
153 "*Function to record a voice message and encode it. [tm-edit.el]")
155 (defvar mime/editor-mode-hook nil
156 "*Hook called when enter MIME mode.")
158 (defvar mime-editor/translate-hook nil
159 "*Hook called before translating into a MIME compliant message.
160 To insert a signature file automatically, call the function
161 `mime-editor/insert-signature' from this hook.")
163 (defvar mime-editor/exit-hook nil
164 "*Hook called when exit MIME mode.")
166 (defvar mime-content-types
168 ;; Charset parameter need not to be specified, since it is
169 ;; defined automatically while translation.
171 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
174 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
177 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
180 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
183 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
191 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
192 ("directory" "/pub/GNU/elisp/mime")
194 ("mode" "image" "ascii" "local8"))
199 ("mode" "image" "ascii" "local8"))
200 ("tftp" ("site") ("name"))
201 ("afs" ("site") ("name"))
202 ("local-file" ("site") ("name"))
203 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
208 ("octet-stream" ("type" "" "tar" "shar"))
210 ("x-kiss" ("x-cnf")))
223 "*Alist of content-type, subtype, parameters and its values.")
225 (defvar mime-file-types
227 "text" "richtext" nil
235 "application" "postscript" nil
237 "attachment" (("filename" . file))
242 "inline" (("filename" . file))
247 "inline" (("filename" . file))
252 "inline" (("filename" . file))
257 "inline" (("filename" . file))
262 "inline" (("filename" . file))
267 "inline" (("filename" . file))
272 "inline" (("filename" . file))
277 "attachment" (("filename" . file))
282 "attachment" (("filename" . file))
285 "application" "octet-stream" (("type" . "emacs-lisp"))
287 "attachment" (("filename" . file))
290 "application" "octet-stream" (("type" . "common-lisp"))
292 "attachment" (("filename" . file))
295 "application" "octet-stream" (("type" . "tar+gzip"))
297 "attachment" (("filename" . file))
300 "application" "octet-stream" (("type" . "tar+gzip"))
302 "attachment" (("filename" . file))
305 "application" "octet-stream" (("type" . "tar+compress"))
307 "attachment" (("filename" . file))
310 "application" "octet-stream" (("type" . "tar+compress"))
312 "attachment" (("filename" . file))
315 "application" "octet-stream" (("type" . "gzip"))
317 "attachment" (("filename" . file))
320 "application" "octet-stream" (("type" . "compress"))
322 "attachment" (("filename" . file))
325 "application" "octet-stream" (("type" . "lha"))
327 "attachment" (("filename" . file))
330 "application" "zip" nil
332 "attachment" (("filename" . file))
335 "application" "octet-stream" (("type" . "patch"))
337 "attachment" (("filename" . file))
340 "application" "octet-stream" (("type" . "patch"))
342 "attachment" (("filename" . file))
345 "text" "plain" nil nil)
347 "application" "octet-stream" nil
349 "attachment" (("filename" . file))
352 "*Alist of file name, types, parameters, and default encoding.
353 If encoding is nil, it is determined from its contents.")
355 ;;; @@ about charset, encoding and transfer-level
358 (defvar mime-editor/transfer-level 7
359 "*A number of network transfer level. It should be bigger than 7.")
360 (make-variable-buffer-local 'mime-editor/transfer-level)
362 (defvar mime-editor/transfer-level-string
363 (mime/encoding-name mime-editor/transfer-level 'not-omit)
364 "*A string formatted version of mime/defaul-transfer-level")
365 (make-variable-buffer-local 'mime-editor/transfer-level-string)
367 (defun mime-editor/make-charset-default-encoding-alist (transfer-level)
369 (lambda (charset-type)
370 (let ((charset (car charset-type))
371 (type (nth 1 charset-type))
372 (encoding (nth 2 charset-type))
374 (if (<= type transfer-level)
375 (cons charset (mime/encoding-name type))
376 (cons charset encoding)
378 mime-charset-type-list))
380 (defvar mime-editor/charset-default-encoding-alist
381 (mime-editor/make-charset-default-encoding-alist mime-editor/transfer-level))
382 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
384 ;;; @@ about message inserting
387 (defvar mime-editor/yank-ignored-field-list
388 '("Received" "Approved" "Path" "Replied" "Status"
389 "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
390 "Delete these fields from original message when it is inserted
391 as message/rfc822 part.
392 Each elements are regexp of field-name. [tm-edit.el]")
394 (defvar mime-editor/yank-ignored-field-regexp
396 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
399 (defvar mime-editor/message-inserter-alist nil)
400 (defvar mime-editor/mail-inserter-alist nil)
402 ;;; @@ about message splitting
405 (defvar mime-editor/split-message t
406 "*Split large message if it is non-nil. [tm-edit.el]")
408 (defvar mime-editor/message-default-max-lines 1000
409 "*Default maximum lines of a message. [tm-edit.el]")
411 (defvar mime-editor/message-max-lines-alist
412 '((news-reply-mode . 500))
413 "Alist of major-mode vs maximum lines of a message.
414 If it is not specified for a major-mode,
415 `mime-editor/message-default-max-lines' is used. [tm-edit.el]")
417 (defconst mime-editor/split-ignored-field-regexp
418 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
420 (defvar mime-editor/split-blind-field-regexp
421 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
423 (defvar mime-editor/split-message-sender-alist nil)
425 (defvar mime-editor/news-reply-mode-server-running nil)
431 (defvar mime-editor/signing-type 'pgp-elkins
432 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
434 (defvar mime-editor/encrypting-type 'pgp-elkins
435 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
437 (defvar mime-editor/pgp-sign-function 'tm:mc-pgp-sign-region)
438 (defvar mime-editor/pgp-encrypt-function 'tm:mc-pgp-encrypt-region)
439 (defvar mime-editor/traditional-pgp-sign-function 'mc-pgp-sign-region)
440 (defvar mime-editor/pgp-insert-public-key-function 'mc-insert-public-key)
442 (autoload mime-editor/pgp-sign-function "tm-edit-mc")
443 (autoload mime-editor/pgp-encrypt-function "tm-edit-mc")
444 (autoload mime-editor/traditional-pgp-sign-function "mc-pgp")
445 (autoload mime-editor/pgp-insert-public-key-function "mc-toplev")
451 (defconst mime-editor/single-part-tag-regexp
452 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
453 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
455 (defconst mime-editor/quoted-single-part-tag-regexp
456 (concat "- " (substring mime-editor/single-part-tag-regexp 1)))
458 (defconst mime-editor/multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
460 (defconst mime-editor/multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
462 (defconst mime-editor/beginning-tag-regexp
463 (regexp-or mime-editor/single-part-tag-regexp
464 mime-editor/multipart-beginning-regexp))
466 (defconst mime-editor/end-tag-regexp
467 (regexp-or mime-editor/single-part-tag-regexp
468 mime-editor/multipart-end-regexp))
470 (defconst mime-editor/tag-regexp
471 (regexp-or mime-editor/single-part-tag-regexp
472 mime-editor/multipart-beginning-regexp
473 mime-editor/multipart-end-regexp))
475 (defvar mime-tag-format "--[[%s]]"
476 "*Control-string making a MIME tag.")
478 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
479 "*Control-string making a MIME tag with encoding.")
481 ;;; @@ multipart boundary
484 (defvar mime-multipart-boundary "Multipart"
485 "*Boundary of a multipart message.")
488 ;;; @@ buffer local variables
491 (defvar mime/editor-mode-old-local-map nil)
492 (defvar mime/editing-buffer nil)
498 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
499 "*Specify MIME tspecials.
500 Tspecials means any character that matches with it in header must be quoted.")
502 (defconst mime-editor/mime-version-value
503 (concat "1.0 (generated by " mime-editor/version-name ")")
504 "MIME version number.")
506 (defconst mime-editor/mime-map (make-sparse-keymap)
507 "Keymap for MIME commands.")
509 ;;; @ keymap and menu
512 (defvar mime/editor-mode-flag nil)
513 (make-variable-buffer-local 'mime/editor-mode-flag)
515 (defun mime-editor/define-keymap (keymap)
516 "Add mime-editor commands to KEYMAP."
517 (if (not (keymapp keymap))
519 (define-key keymap "\C-t" 'mime-editor/insert-text)
520 (define-key keymap "\C-i" 'mime-editor/insert-file)
521 (define-key keymap "\C-e" 'mime-editor/insert-external)
522 (define-key keymap "\C-v" 'mime-editor/insert-voice)
523 (define-key keymap "\C-y" 'mime-editor/insert-message)
524 (define-key keymap "\C-m" 'mime-editor/insert-mail)
525 (define-key keymap "\C-w" 'mime-editor/insert-signature)
526 (define-key keymap "\C-s" 'mime-editor/insert-signature)
527 (define-key keymap "\C-k" 'mime-editor/insert-key)
528 (define-key keymap "t" 'mime-editor/insert-tag)
529 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
530 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
531 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
532 (define-key keymap "d" 'mime-editor/enclose-digest-region)
533 (define-key keymap "s" 'mime-editor/enclose-signed-region)
534 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
535 (define-key keymap "q" 'mime-editor/enclose-quote-region)
536 (define-key keymap "7" 'mime-editor/set-transfer-level-7bit)
537 (define-key keymap "8" 'mime-editor/set-transfer-level-8bit)
538 (define-key keymap "/" 'mime-editor/set-split)
539 (define-key keymap "v" 'mime-editor/set-sign)
540 (define-key keymap "h" 'mime-editor/set-encrypt)
541 (define-key keymap "\C-p" 'mime-editor/preview-message)
542 (define-key keymap "\C-z" 'mime-editor/exit)
543 (define-key keymap "?" 'mime-editor/help)
546 (mime-editor/define-keymap mime-editor/mime-map)
548 (defun mime-editor/toggle-mode ()
550 (if mime/editor-mode-flag
551 (mime-editor/exit 'nomime)
555 (cond (running-xemacs
556 (defconst mime-editor/minor-mime-map nil "Keymap for MIME commands.")
557 (or mime-editor/minor-mime-map
559 (setq mime-editor/minor-mime-map
560 (make-sparse-keymap 'mime-editor/minor-mime-map))
562 mime-editor/minor-mime-map mime-prefix mime-editor/mime-map)
564 (add-minor-mode 'mime/editor-mode-flag
565 '((" MIME-Edit " mime-editor/transfer-level-string))
566 mime-editor/minor-mime-map
568 'mime-editor/toggle-mode)
571 (set-alist 'minor-mode-alist
572 'mime/editor-mode-flag
573 '((" MIME-Edit " mime-editor/transfer-level-string))))
576 (defconst mime-editor/menu-title "MIME-Edit")
578 (defconst mime-editor/menu-list
579 '((mime-help "Describe MIME editor mode" mime-editor/help)
580 (file "Insert File" mime-editor/insert-file)
581 (external "Insert External" mime-editor/insert-external)
582 (voice "Insert Voice" mime-editor/insert-voice)
583 (message "Insert Message" mime-editor/insert-message)
584 (mail "Insert Mail" mime-editor/insert-mail)
585 (signature "Insert Signature" mime-editor/insert-signature)
586 (text "Insert Text" mime-editor/insert-text)
587 (tag "Insert Tag" mime-editor/insert-tag)
588 (alternative "Enclose as alternative"
589 mime-editor/enclose-alternative-region)
590 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
591 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
592 (digest "Enclose as digest" mime-editor/enclose-digest-region)
593 (signed "Enclose as signed" mime-editor/enclose-signed-region)
594 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
595 (quote "Verbatim region" mime-editor/enclose-quote-region)
596 (key "Insert Public Key" mime-editor/insert-key)
597 (split "About split" mime-editor/set-split)
598 (sign "About sign" mime-editor/set-sign)
599 (encrypt "About encryption" mime-editor/set-encrypt)
600 (preview "Preview Message" mime-editor/preview-message)
601 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
603 "MIME-edit menubar entry.")
605 (defun mime-editor/define-menu-for-emacs19 ()
606 "Define menu for Emacs 19."
607 (define-key (current-local-map) [menu-bar mime-edit]
608 (cons mime-editor/menu-title
609 (make-sparse-keymap mime-editor/menu-title)))
612 (define-key (current-local-map)
613 (vector 'menu-bar 'mime-edit (car item))
614 (cons (nth 1 item)(nth 2 item))
617 (reverse mime-editor/menu-list)
620 ;;; modified by Pekka Marjola <pema@iki.fi>
621 ;;; 1995/9/5 (c.f. [tm-en:69])
622 (defun mime-editor/define-menu-for-xemacs ()
623 "Define menu for Emacs 19."
624 (cond ((featurep 'menubar)
625 (make-local-variable 'current-menubar)
626 (set-buffer-menubar current-menubar)
628 (cons mime-editor/menu-title
631 (vector (nth 1 item)(nth 2 item)
632 mime/editor-mode-flag)
634 mime-editor/menu-list)))
637 ;;; modified by Steven L. Baur <steve@miranova.com>
638 ;;; 1995/12/6 (c.f. [tm-en:209])
639 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
640 (setq mime-editor/popup-menu-for-xemacs
641 (append '("MIME Commands" "---")
642 (mapcar (function (lambda (item)
646 mime-editor/menu-list)))
655 (defun mime/editor-mode ()
656 "MIME minor mode for editing the tagged MIME message.
658 In this mode, basically, the message is composed in the tagged MIME
659 format. The message tag looks like:
661 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
663 The tag specifies the MIME content type, subtype, optional parameters
664 and transfer encoding of the message following the tag. Messages
665 without any tag are treated as `text/plain' by default. Charset and
666 transfer encoding are automatically defined unless explicitly
667 specified. Binary messages such as audio and image are usually hidden.
668 The messages in the tagged MIME format are automatically translated
669 into a MIME compliant message when exiting this mode.
671 Available charsets depend on Emacs version being used. The following
672 lists the available charsets of each emacs.
674 EMACS 18: US-ASCII is only available.
675 NEmacs: US-ASCII and ISO-2022-JP are available.
676 EMACS 19: US-ASCII and ISO-8859-1 (or other charset) are available.
677 XEmacs 19: US-ASCII and ISO-8859-1 (or other charset) are available.
678 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
679 ISO-2022-JP, ISO-2022-JP-2, ISO-2022-KR, BIG5 and
680 ISO-2022-INT-1 are available.
682 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
683 be used to represent multilingual text in intermixed manner. Any
684 languages that has no registered charset are represented as either
685 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
687 If you want to use non-ISO-8859-1 charset in EMACS 19 or XEmacs 19,
688 please set variable `default-mime-charset'. This variable must be
689 symbol of which name is a MIME charset.
691 If you want to add more charsets in mule, please set variable
692 `charsets-mime-charset-alist'. This variable must be alist of which
693 key is list of leading-char/charset and value is symbol of MIME
694 charset. (leading-char is a term of MULE 1.* and 2.*. charset is a
695 term of XEmacs/mule, mule merged EMACS and MULE 3.*) If name of
696 coding-system is different as MIME charset, please set variable
697 `mime-charset-coding-system-alist'. This variable must be alist of
698 which key is MIME charset and value is coding-system.
700 Following commands are available in addition to major mode commands:
701 \\[mime-editor/insert-text] insert a text message.
702 \\[mime-editor/insert-file] insert a (binary) file.
703 \\[mime-editor/insert-external] insert a reference to external body.
704 \\[mime-editor/insert-voice] insert a voice message.
705 \\[mime-editor/insert-message] insert a mail or news message.
706 \\[mime-editor/insert-mail] insert a mail message.
707 \\[mime-editor/insert-signature] insert a signature file at end.
708 \\[mime-editor/insert-tag] insert a new MIME tag.
709 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
710 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
711 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
712 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
713 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
714 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
715 \\[mime-editor/insert-key] insert PGP public key.
716 \\[mime-editor/preview-message] preview editing MIME message.
717 \\[mime-editor/exit] exit and translate into a MIME compliant message.
718 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
719 \\[mime-editor/help] show this help.
721 Additional commands are available in some major modes:
722 C-c C-c exit, translate and run the original command.
723 C-c C-s exit, translate and run the original command.
725 The following is a message example written in the tagged MIME format.
726 TABs at the beginning of the line are not a part of the message:
728 This is a conventional plain text. It should be translated
731 This is also a plain text. But, it is explicitly specified as
733 --[[text/plain; charset=ISO-2022-JP]]
734 \e$B$3$l$O
\e(B charset
\e$B$r
\e(B ISO-2022-JP
\e$B$K;XDj$7$?F|K\8l$N
\e(B plain
\e$B%F%-%9
\e(B
737 <center>This is a richtext.</center>
738 --[[image/gif][base64]]^M...image encoded in base64 here...
739 --[[audio/basic][base64]]^M...audio encoded in base64 here...
741 User customizable variables (not documented all of them):
743 Specifies a key prefix for MIME minor mode commands.
745 mime-ignore-preceding-spaces
746 Preceding white spaces in a message body are ignored if non-nil.
748 mime-ignore-trailing-spaces
749 Trailing white spaces in a message body are ignored if non-nil.
751 mime-auto-fill-header
752 Fill header fields that contain encoded-words if non-nil.
755 Hide a non-textual body message encoded in base64 after insertion
758 mime-editor/voice-recorder
759 Specifies a function to record a voice message and encode it.
760 The function `mime-editor/voice-recorder-for-sun' is for Sun
763 mime/editor-mode-hook
764 Turning on MIME mode calls the value of mime/editor-mode-hook, if
767 mime-editor/translate-hook
768 The value of mime-editor/translate-hook is called just before translating
769 the tagged MIME format into a MIME compliant message if it is
770 non-nil. If the hook call the function mime-editor/insert-signature,
771 the signature file will be inserted automatically.
773 mime-editor/exit-hook
774 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
777 (if mime/editor-mode-flag
778 (error "You are already editing a MIME message.")
779 (setq mime/editor-mode-flag t)
780 ;; Remember old key bindings.
782 (use-local-map (or (current-local-map) (make-sparse-keymap)))
783 (make-local-variable 'mime/editor-mode-old-local-map)
784 (setq mime/editor-mode-old-local-map (current-local-map))
785 ;; Add MIME commands to current local map.
786 (use-local-map (copy-keymap (or (current-local-map)
787 (make-sparse-keymap))))
789 (if (not (lookup-key (current-local-map) mime-prefix))
790 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
792 ;; Set transfer level into mode line
794 (setq mime-editor/transfer-level-string
795 (mime/encoding-name mime-editor/transfer-level 'not-omit))
796 (force-mode-line-update)
798 ;; Define menu. Menus for other emacs implementations are
800 (cond (running-xemacs
801 (mime-editor/define-menu-for-xemacs))
802 ((>= emacs-major-version 19)
803 (mime-editor/define-menu-for-emacs19)
809 ;; I don't care about saving these.
810 (setq paragraph-start
811 (regexp-or mime-editor/single-part-tag-regexp
813 (setq paragraph-separate
814 (regexp-or mime-editor/single-part-tag-regexp
816 (run-hooks 'mime/editor-mode-hook)
818 (substitute-command-keys
819 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
823 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
824 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
826 (defun mime-editor/exit (&optional nomime no-error)
827 "Translate the tagged MIME message into a MIME compliant message.
828 With no argument encode a message in the buffer into MIME, otherwise
829 just return to previous mode."
831 (if (not mime/editor-mode-flag)
833 (error "You aren't editing a MIME message.")
837 (run-hooks 'mime-editor/translate-hook)
838 (mime-editor/translate-buffer)))
839 ;; Restore previous state.
840 (setq mime/editor-mode-flag nil)
841 (cond (running-xemacs
842 (delete-menu-item (list mime-editor/menu-title)))
844 (use-local-map mime/editor-mode-old-local-map)))
847 (set-buffer-modified-p (buffer-modified-p))
848 (run-hooks 'mime-editor/exit-hook)
849 (message "Exit MIME editor mode.")
852 (defun mime-editor/maybe-translate ()
854 (mime-editor/exit nil t)
855 (call-interactively 'mime-editor/maybe-split-and-send)
858 (defun mime-editor/help ()
859 "Show help message about MIME mode."
861 (with-output-to-temp-buffer "*Help*"
862 (princ "MIME editor mode:\n")
863 (princ (documentation 'mime/editor-mode))
864 (print-help-return-message)))
866 (defun mime-editor/insert-text ()
867 "Insert a text message.
868 Charset is automatically obtained from the `mime/lc-charset-alist'."
870 (let ((ret (mime-editor/insert-tag "text" nil nil)))
873 (if (looking-at mime-editor/single-part-tag-regexp)
875 ;; Make a space between the following message.
879 (if (and (member (second ret) '("enriched" "richtext"))
880 (fboundp 'enriched-mode)
883 (if (boundp 'enriched-mode)
887 (defun mime-editor/insert-file (file)
888 "Insert a message from a file."
889 (interactive "fInsert file as MIME message: ")
890 (let* ((guess (mime-find-file-type file))
891 (pritype (nth 0 guess))
892 (subtype (nth 1 guess))
893 (parameters (nth 2 guess))
894 (default (nth 3 guess)) ;Guess encoding from its file name.
895 (disposition-type (nth 4 guess))
896 (disposition-params (nth 5 guess))
898 (if (not (interactive-p))
901 (concat "What transfer encoding"
904 (if (string-equal default "")
910 mime-file-encoding-method-alist nil t nil))))
911 (if (string-equal encoding "")
912 (setq encoding default))
913 (if (or (consp parameters) (stringp disposition-type))
914 (let ((rest parameters) cell attribute value)
917 (setq cell (car rest))
918 (setq attribute (car cell))
919 (setq value (cdr cell))
921 (setq value (std11-wrap-as-quoted-string
922 (file-name-nondirectory file)))
924 (setq parameters (concat parameters "; " attribute "=" value))
925 (setq rest (cdr rest))
930 (concat parameters "\n"
931 "Content-Disposition: " disposition-type))
932 (setq rest disposition-params)
934 (setq cell (car rest))
935 (setq attribute (car cell))
936 (setq value (cdr cell))
938 (setq value (std11-wrap-as-quoted-string
939 (file-name-nondirectory file)))
942 (concat parameters "; " attribute "=" value))
943 (setq rest (cdr rest))
947 (mime-editor/insert-tag pritype subtype parameters)
948 (mime-editor/insert-binary-file file encoding)
951 (defun mime-editor/insert-external ()
952 "Insert a reference to external body."
954 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
956 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
958 (let* ((pritype (mime-prompt-for-type))
959 (subtype (mime-prompt-for-subtype pritype))
960 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
963 (insert "Content-Type: "
964 pritype "/" subtype (or parameters "") "\n")))
965 (if (and (not (eobp))
966 (not (looking-at mime-editor/single-part-tag-regexp)))
967 (insert (mime-make-text-tag) "\n")))
969 (defun mime-editor/insert-voice ()
970 "Insert a voice message."
974 "What transfer encoding: "
975 mime-file-encoding-method-alist nil t nil)))
976 (mime-editor/insert-tag "audio" "basic" nil)
977 (mime-editor/define-encoding encoding)
979 (narrow-to-region (1- (point))(point))
981 (funcall mime-editor/voice-recorder encoding)
984 (invisible-region (point-min)(point-max))
985 (goto-char (point-max))
988 (defun mime-editor/insert-signature (&optional arg)
989 "Insert a signature file."
991 (let ((signature-insert-hook
994 (apply (function mime-editor/insert-tag)
995 (mime-find-file-type signature-file-name))
998 (insert-signature arg)
1002 ;; Insert a new tag around a point.
1004 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
1005 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
1006 If nothing is inserted, return nil."
1009 (mime-editor/goto-tag)
1010 (if (and (re-search-forward mime-editor/tag-regexp nil t)
1011 (< (match-beginning 0) p)
1014 (goto-char (match-beginning 0))
1023 (mime-prompt-for-type)))
1026 (mime-prompt-for-subtype pritype)))
1029 (mime-prompt-for-parameters pritype subtype delimiter)))
1030 ;; Make a new MIME tag.
1031 (setq newtag (mime-make-tag pritype subtype parameters))
1032 ;; Find an current MIME tag.
1035 (if (mime-editor/goto-tag)
1036 (buffer-substring (match-beginning 0) (match-end 0))
1037 ;; Assume content type is 'text/plan'.
1038 (mime-make-tag "text" "plain")
1040 ;; We are only interested in TEXT.
1042 (not (mime-test-content-type
1043 (mime-editor/get-contype oldtag) "text")))
1046 (if (or (not oldtag) ;Not text
1047 (or mime-ignore-same-text-tag
1048 (not (string-equal oldtag newtag))))
1050 ;; Mark the beginning of the tag for convenience.
1051 (push-mark (point) 'nomsg)
1052 (insert newtag "\n")
1053 (list pritype subtype parameters) ;New tag is created.
1055 ;; Restore previous point.
1057 nil ;Nothing is created.
1061 (defun mime-editor/insert-binary-file (file &optional encoding)
1062 "Insert binary FILE at point.
1063 Optional argument ENCODING specifies an encoding method such as base64."
1064 (let* ((tagend (1- (point))) ;End of the tag
1065 (hide-p (and mime-auto-hide-body
1068 (let ((en (downcase encoding)))
1069 (or (string-equal en "7bit")
1070 (string-equal en "8bit")
1071 (string-equal en "binary")
1075 (narrow-to-region tagend (point))
1076 (mime-insert-encoded-file file encoding)
1079 (invisible-region (point-min) (point-max))
1080 (goto-char (point-max))
1082 (goto-char (point-max))
1085 (looking-at mime-editor/tag-regexp)
1086 (= (point)(point-max))
1087 (mime-editor/insert-tag "text" "plain")
1089 ;; Define encoding even if it is 7bit.
1090 (if (stringp encoding)
1092 (goto-char tagend) ; Make sure which line the tag is on.
1093 (mime-editor/define-encoding encoding)
1098 ;; Commands work on a current message flagment.
1100 (defun mime-editor/goto-tag ()
1101 "Search for the beginning of the tagged MIME message."
1102 (let ((current (point)) multipart)
1103 (if (looking-at mime-editor/tag-regexp)
1105 ;; At first, go to the end.
1106 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1107 (goto-char (1- (match-beginning 0))) ;For multiline tag
1110 (goto-char (point-max))
1112 ;; Then search for the beginning.
1113 (re-search-backward mime-editor/end-tag-regexp nil t)
1114 (or (looking-at mime-editor/beginning-tag-regexp)
1115 ;; Restore previous point.
1122 (defun mime-editor/content-beginning ()
1123 "Return the point of the beginning of content."
1125 (let ((beg (save-excursion
1126 (beginning-of-line) (point))))
1127 (if (mime-editor/goto-tag)
1128 (let ((top (point)))
1129 (goto-char (match-end 0))
1130 (if (and (= beg top)
1131 (= (following-char) ?\^M))
1135 ;; Default text/plain tag.
1136 (goto-char (point-min))
1138 (concat "\n" (regexp-quote mail-header-separator)
1139 (if mime-ignore-preceding-spaces
1140 "[ \t\n]*\n" "\n")) nil 'move)
1144 (defun mime-editor/content-end ()
1145 "Return the point of the end of content."
1147 (let ((beg (point)))
1148 (if (mime-editor/goto-tag)
1149 (let ((top (point)))
1150 (goto-char (match-end 0))
1151 (if (invisible-p (point))
1152 (next-visible-point (point))
1153 ;; Move to the end of this text.
1154 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1155 ;; Don't forget a multiline tag.
1156 (goto-char (match-beginning 0))
1160 ;; Assume the message begins with text/plain.
1161 (goto-char (mime-editor/content-beginning))
1162 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1163 ;; Don't forget a multiline tag.
1164 (goto-char (match-beginning 0)))
1168 (defun mime-editor/define-charset (charset)
1169 "Set charset of current tag to CHARSET."
1171 (if (mime-editor/goto-tag)
1172 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1173 (delete-region (match-beginning 0) (match-end 0))
1176 (mime-editor/set-parameter
1177 (mime-editor/get-contype tag)
1178 "charset" (upcase (symbol-name charset)))
1179 (mime-editor/get-encoding tag)))
1182 (defun mime-editor/define-encoding (encoding)
1183 "Set encoding of current tag to ENCODING."
1185 (if (mime-editor/goto-tag)
1186 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1187 (delete-region (match-beginning 0) (match-end 0))
1188 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1191 (defun mime-editor/choose-charset ()
1192 "Choose charset of a text following current point."
1193 (detect-mime-charset-region (point) (mime-editor/content-end))
1196 (defun mime-make-text-tag (&optional subtype)
1197 "Make a tag for a text after current point.
1198 Subtype of text type can be specified by an optional argument SUBTYPE.
1199 Otherwise, it is obtained from mime-content-types."
1200 (let* ((pritype "text")
1201 (subtype (or subtype
1202 (car (car (cdr (assoc pritype mime-content-types)))))))
1203 ;; Charset should be defined later.
1204 (mime-make-tag pritype subtype)))
1207 ;; Tag handling functions
1209 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1210 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1211 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1215 (defun mime-create-tag (contype &optional encoding)
1216 "Make a tag with CONTENT-TYPE and optional ENCODING."
1217 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1220 (defun mime-editor/get-contype (tag)
1221 "Return Content-Type (including parameters) of TAG."
1223 (or (string-match mime-editor/single-part-tag-regexp tag)
1224 (string-match mime-editor/multipart-beginning-regexp tag)
1225 (string-match mime-editor/multipart-end-regexp tag)
1227 (substring tag (match-beginning 1) (match-end 1))
1230 (defun mime-editor/get-encoding (tag)
1231 "Return encoding of TAG."
1233 (string-match mime-editor/single-part-tag-regexp tag)
1235 (not (= (match-beginning 3) (match-end 3)))
1236 (substring tag (match-beginning 3) (match-end 3))))
1238 (defun mime-get-parameter (contype parameter)
1239 "For given CONTYPE return value for PARAMETER.
1240 Nil if no such parameter."
1244 (regexp-quote parameter)
1245 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1247 (substring contype (match-beginning 1) (match-end 1))
1248 nil ;No such parameter
1251 (defun mime-editor/set-parameter (contype parameter value)
1252 "For given CONTYPE set PARAMETER to VALUE."
1253 (let (ctype opt-fields)
1254 (if (string-match "\n[^ \t\n\r]+:" contype)
1255 (setq ctype (substring contype 0 (match-beginning 0))
1256 opt-fields (substring contype (match-beginning 0)))
1257 (setq ctype contype)
1262 (regexp-quote parameter)
1263 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1266 (concat (substring ctype 0 (match-beginning 1))
1268 (substring contype (match-end 1))
1270 (concat ctype "; " parameter "=" value opt-fields)
1273 (defun mime-strip-parameters (contype)
1274 "Return primary content-type and subtype without parameters for CONTYPE."
1275 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1276 (substring contype (match-beginning 1) (match-end 1)) nil))
1278 (defun mime-test-content-type (contype type &optional subtype)
1279 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1280 (and (stringp contype)
1283 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1284 (downcase contype))))
1289 (defun mime-find-file-type (file)
1290 "Guess Content-Type, subtype, and parameters from FILE."
1292 (guesses mime-file-types))
1293 (while (and (not guess) guesses)
1294 (if (string-match (car (car guesses)) file)
1295 (setq guess (cdr (car guesses))))
1296 (setq guesses (cdr guesses)))
1300 (defun mime-prompt-for-type ()
1301 "Ask for Content-type."
1303 ;; Repeat until primary content type is specified.
1304 (while (string-equal type "")
1306 (completing-read "What content type: "
1309 'require-match ;Type must be specified.
1312 (if (string-equal type "")
1314 (message "Content type is required.")
1322 (defun mime-prompt-for-subtype (pritype)
1323 "Ask for Content-type subtype of Content-Type PRITYPE."
1324 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1329 "What content subtype: (default " default ") ")
1330 "What content subtype: ")
1331 (cdr (assoc pritype mime-content-types))
1333 'require-match ;Subtype must be specified.
1336 (if (string-equal answer "") default answer)))
1338 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1339 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1340 Optional DELIMITER specifies parameter delimiter (';' by default)."
1341 (let* ((delimiter (or delimiter "; "))
1346 (mime-prompt-for-parameters-1
1348 (cdr (assoc pritype mime-content-types))))))
1351 (if (and (stringp parameters)
1352 (not (string-equal parameters "")))
1353 (concat delimiter parameters)
1354 "" ;"" if no parameters
1357 (defun mime-prompt-for-parameters-1 (optlist)
1358 (apply (function append)
1359 (mapcar (function mime-prompt-for-parameter) optlist)))
1361 (defun mime-prompt-for-parameter (parameter)
1363 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1364 (let* ((prompt (car parameter))
1365 (choices (mapcar (function
1367 (if (consp e) e (list e))))
1369 (default (car (car choices)))
1375 (concat "What " prompt
1377 (if (string-equal default "") "\"\"" default)
1379 choices nil nil ""))
1380 ;; If nothing is selected, use default.
1381 (if (string-equal answer "")
1382 (setq answer default)))
1384 (read-string (concat "What " prompt ": "))))
1385 (cons (if (and answer
1386 (not (string-equal answer "")))
1388 ;; Note: control characters ignored!
1389 (if (string-match mime-tspecials-regexp answer)
1390 (concat "\"" answer "\"") answer)))
1391 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1394 (defun mime-flag-region (from to flag)
1395 "Hides or shows lines from FROM to TO, according to FLAG.
1396 If FLAG is `\\n' (newline character) then text is shown,
1397 while if FLAG is `\\^M' (control-M) the text is hidden."
1398 (let ((buffer-read-only nil) ;Okay even if write protected.
1399 (modp (buffer-modified-p)))
1401 (subst-char-in-region from to
1402 (if (= flag ?\n) ?\^M ?\n)
1404 (set-buffer-modified-p modp))))
1407 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1410 (defvar mime-editor/translate-buffer-hook
1411 '(mime-editor/pgp-enclose-buffer
1412 mime-editor/translate-header
1413 mime-editor/translate-body))
1415 (defun mime-editor/translate-header ()
1416 "Encode the message header into network representation."
1417 (mime/encode-message-header 'code-conversion)
1418 (run-hooks 'mime-editor/translate-header-hook)
1421 (defun mime-editor/translate-buffer ()
1422 "Encode the tagged MIME message in current buffer in MIME compliant message."
1424 (if (catch 'mime-editor/error
1426 (run-hooks 'mime-editor/translate-buffer-hook)
1430 (error "Translation error!")
1433 (defun mime-editor/find-inmost ()
1434 (goto-char (point-min))
1435 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1436 (let ((bb (match-beginning 0))
1438 (type (buffer-substring (match-beginning 1)(match-end 1)))
1440 (setq end-exp (format "--}-<<%s>>\n" type))
1442 (if (re-search-forward end-exp nil t)
1444 (setq eb (match-beginning 0))
1445 (setq ee (match-end 0))
1447 (setq eb (point-max))
1448 (setq ee (point-max))
1450 (narrow-to-region be eb)
1452 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1454 (narrow-to-region (match-beginning 0)(point-max))
1455 (mime-editor/find-inmost)
1458 (list type bb be eb)
1461 (defun mime-editor/process-multipart-1 (boundary)
1462 (let ((ret (mime-editor/find-inmost)))
1464 (let ((type (car ret))
1465 (bb (nth 1 ret))(be (nth 2 ret))
1468 (narrow-to-region bb eb)
1469 (delete-region bb be)
1470 (setq bb (point-min))
1471 (setq eb (point-max))
1474 (if (looking-at mime-editor/multipart-end-regexp)
1475 (let ((beg (match-beginning 0))
1478 (delete-region beg end)
1479 (or (looking-at mime-editor/beginning-tag-regexp)
1481 (insert (concat (mime-make-text-tag) "\n"))
1483 (cond ((string-equal type "quote")
1484 (mime-editor/enquote-region bb eb)
1486 ((string-equal type "signed")
1487 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1488 (mime-editor/sign-pgp-elkins bb eb boundary)
1490 ((eq mime-editor/signing-type 'pgp-kazu)
1491 (mime-editor/sign-pgp-kazu bb eb boundary)
1494 ((string-equal type "encrypted")
1495 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1496 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1498 ((eq mime-editor/encrypting-type 'pgp-kazu)
1499 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1503 (nth 2 (mime-editor/translate-region bb eb
1507 (format "--[[multipart/%s;
1508 boundary=\"%s\"][7bit]]\n"
1513 (defun mime-editor/enquote-region (beg end)
1516 (narrow-to-region beg end)
1518 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1519 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1520 (replace-match (concat "- " (substring tag 1)))
1523 (defun mime-editor/dequote-region (beg end)
1526 (narrow-to-region beg end)
1528 (while (re-search-forward
1529 mime-editor/quoted-single-part-tag-regexp nil t)
1530 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1531 (replace-match (concat "-" (substring tag 2)))
1534 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1537 (narrow-to-region beg end)
1539 (mime-editor/translate-region beg end boundary))
1541 (encoding (nth 1 ret))
1543 (pgp-boundary (concat "pgp-sign-" boundary))
1546 (insert (format "Content-Type: %s\n" ctype))
1548 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1551 (or (funcall mime-editor/pgp-sign-function
1552 (point-min)(point-max) nil nil pgp-boundary)
1553 (throw 'mime-editor/error 'pgp-error)
1557 (defvar mime-editor/encrypt-recipient-fields-list '("To" "cc"))
1559 (defun mime-editor/make-encrypt-recipient-header ()
1560 (let* ((names mime-editor/encrypt-recipient-fields-list)
1562 (std11-field-bodies (cons "From" names)
1563 nil mail-header-separator))
1566 (setq values (cdr values))))
1567 (header (and (stringp from)
1568 (if (string-equal from "")
1570 (format "From: %s\n" from)
1573 (while (and names values)
1574 (let ((name (car names))
1575 (value (car values))
1577 (and (stringp value)
1578 (or (string-equal value "")
1580 (setq header (concat header name ": " value "\n")
1581 recipients (if recipients
1582 (concat recipients " ," value)
1585 (setq names (cdr names)
1586 values (cdr values))
1588 (vector from recipients header)
1591 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1594 (let (from recipients header)
1595 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1596 (setq from (aref ret 0)
1597 recipients (aref ret 1)
1598 header (aref ret 2))
1600 (narrow-to-region beg end)
1602 (mime-editor/translate-region beg end boundary))
1604 (encoding (nth 1 ret))
1606 (pgp-boundary (concat "pgp-" boundary))
1610 (insert (format "Content-Type: %s\n" ctype))
1612 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1615 (or (funcall mime-editor/pgp-encrypt-function
1616 recipients (point-min) (point-max) from)
1617 (throw 'mime-editor/error 'pgp-error)
1620 (insert (format "--[[multipart/encrypted;
1622 protocol=\"application/pgp-encrypted\"][7bit]]
1624 Content-Type: application/pgp-encrypted
1627 Content-Type: application/octet-stream
1628 Content-Transfer-Encoding: 7bit
1630 " pgp-boundary pgp-boundary pgp-boundary))
1631 (goto-char (point-max))
1632 (insert (format "\n--%s--\n" pgp-boundary))
1635 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1638 (narrow-to-region beg end)
1640 (mime-editor/translate-region beg end boundary))
1642 (encoding (nth 1 ret))
1646 (insert (format "Content-Type: %s\n" ctype))
1648 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1651 (or (as-binary-process
1652 (funcall mime-editor/traditional-pgp-sign-function
1654 (throw 'mime-editor/error 'pgp-error)
1658 "--[[application/pgp; format=mime][7bit]]\n")
1662 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1664 (let (from recipients header)
1665 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1666 (setq from (aref ret 0)
1667 recipients (aref ret 1)
1668 header (aref ret 2))
1671 (narrow-to-region beg end)
1673 (mime-editor/translate-region beg end boundary))
1675 (encoding (nth 1 ret))
1680 (insert (format "Content-Type: %s\n" ctype))
1682 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1685 (or (as-binary-process
1686 (funcall mime-editor/pgp-encrypt-function
1687 recipients beg (point-max) nil 'maybe)
1689 (throw 'mime-editor/error 'pgp-error)
1693 "--[[application/pgp; format=mime][7bit]]\n")
1697 (defun mime-editor/translate-body ()
1698 "Encode the tagged MIME body in current buffer in MIME compliant message."
1702 (concat mime-multipart-boundary "_"
1703 (replace-space-with-underline (current-time-string))
1707 (while (mime-editor/process-multipart-1
1708 (format "%s-%d" boundary i))
1712 ;; We are interested in message body.
1715 (goto-char (point-min))
1717 (concat "\n" (regexp-quote mail-header-separator)
1718 (if mime-ignore-preceding-spaces
1719 "[ \t\n]*\n" "\n")) nil 'move)
1723 (goto-char (point-max))
1724 (and mime-ignore-trailing-spaces
1725 (re-search-backward "[^ \t\n]\n" beg t)
1728 (setq ret (mime-editor/translate-region
1730 (format "%s-%d" boundary i)))
1732 (mime-editor/dequote-region (point-min)(point-max))
1733 (let ((contype (car ret)) ;Content-Type
1734 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1736 ;; Make primary MIME headers.
1737 (or (mail-position-on-field "Mime-Version")
1738 (insert mime-editor/mime-version-value))
1739 ;; Remove old Content-Type and other fields.
1741 (goto-char (point-min))
1742 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1743 (narrow-to-region (point-min) (point))
1744 (goto-char (point-min))
1745 (mime-delete-field "Content-Type")
1746 (mime-delete-field "Content-Transfer-Encoding"))
1747 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1748 (mail-position-on-field "Content-Type")
1752 (mail-position-on-field "Content-Transfer-Encoding")
1756 (defun mime-editor/translate-single-part-tag (&optional prefix)
1757 (if (re-search-forward mime-editor/single-part-tag-regexp nil t)
1758 (let* ((beg (match-beginning 0))
1760 (tag (buffer-substring beg end))
1762 (delete-region beg end)
1763 (setq contype (mime-editor/get-contype tag))
1764 (setq encoding (mime-editor/get-encoding tag))
1765 (insert (concat prefix "--" boundary "\n"))
1767 (narrow-to-region (point)(point))
1768 (insert "Content-Type: " contype "\n")
1770 (insert "Content-Transfer-Encoding: " encoding "\n"))
1771 (mime/encode-message-header)
1775 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1778 (concat mime-multipart-boundary "_"
1779 (replace-space-with-underline (current-time-string))))
1783 (narrow-to-region beg end)
1784 (let ((tag nil) ;MIME tag
1785 (contype nil) ;Content-Type
1786 (encoding nil) ;Content-Transfer-Encoding
1787 (nparts 0)) ;Number of body parts
1788 ;; Normalize the body part by inserting appropriate message
1789 ;; tags for every message contents.
1790 (mime-editor/normalize-body)
1791 ;; Counting the number of Content-Type.
1792 (goto-char (point-min))
1793 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1794 (setq nparts (1+ nparts)))
1795 ;; Begin translation.
1797 ((and (<= nparts 1)(not multipart))
1798 ;; It's a singular message.
1799 (goto-char (point-min))
1800 (while (re-search-forward
1801 mime-editor/single-part-tag-regexp nil t)
1803 (buffer-substring (match-beginning 0) (match-end 0)))
1804 (delete-region (match-beginning 0) (1+ (match-end 0)))
1805 (setq contype (mime-editor/get-contype tag))
1806 (setq encoding (mime-editor/get-encoding tag))
1809 ;; It's a multipart message.
1810 (goto-char (point-min))
1811 (and (mime-editor/translate-single-part-tag)
1812 (while (mime-editor/translate-single-part-tag "\n"))
1814 ;; Define Content-Type as "multipart/mixed".
1816 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1817 ;; Content-Transfer-Encoding must be "7bit".
1818 ;; The following encoding can be `nil', but is
1819 ;; specified as is since there is no way that a user
1821 (setq encoding "7bit")
1822 ;; Insert the trailer.
1823 (goto-char (point-max))
1824 (insert "\n--" boundary "--\n")
1826 (list contype encoding boundary nparts)
1829 (defun mime-editor/normalize-body ()
1830 "Normalize the body part by inserting appropriate message tags."
1831 ;; Insert the first MIME tags if necessary.
1832 (goto-char (point-min))
1833 (if (not (looking-at mime-editor/single-part-tag-regexp))
1834 (insert (mime-make-text-tag) "\n"))
1835 ;; Check each tag, and add new tag or correct it if necessary.
1836 (goto-char (point-min))
1837 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1838 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1839 (contype (mime-editor/get-contype tag))
1840 (charset (mime-get-parameter contype "charset"))
1841 (encoding (mime-editor/get-encoding tag)))
1842 ;; Remove extra whitespaces after the tag.
1843 (if (looking-at "[ \t]+$")
1844 (delete-region (match-beginning 0) (match-end 0)))
1846 (end (mime-editor/content-end))
1848 (if (= end (point-max))
1851 (or (looking-at mime-editor/beginning-tag-regexp)
1853 (insert (mime-make-text-tag) "\n")
1855 (visible-region beg end)
1859 ((mime-test-content-type contype "message")
1860 ;; Content-type "message" should be sent as is.
1863 ((mime-test-content-type contype "text")
1864 ;; Define charset for text if necessary.
1865 (setq charset (if charset
1866 (intern (downcase charset))
1867 (mime-editor/choose-charset)))
1868 (mime-editor/define-charset charset)
1869 (cond ((string-equal contype "text/x-rot13-47")
1873 (goto-char (mime-editor/content-end))
1876 ((string-equal contype "text/enriched")
1881 (end (mime-editor/content-end))
1883 ;; Patch for hard newlines
1886 ;; (while (search-forward "\n" end t)
1887 ;; (put-text-property (match-beginning 0)
1890 ;; End patch for hard newlines
1891 (enriched-encode beg end)
1893 (if (search-forward "\n\n")
1894 (delete-region beg (match-end 0))
1897 ;; Point is now on current tag.
1898 ;; Define encoding and encode text if necessary.
1899 (or encoding ;Encoding is not specified.
1903 mime-editor/charset-default-encoding-alist)
1905 (beg (mime-editor/content-beginning))
1907 (encode-mime-charset-region beg (mime-editor/content-end)
1909 (mime-encode-region beg (mime-editor/content-end) encoding)
1910 (mime-editor/define-encoding encoding)
1912 (goto-char (mime-editor/content-end))
1914 ((null encoding) ;Encoding is not specified.
1915 ;; Application, image, audio, video, and any other
1916 ;; unknown content-type without encoding should be
1918 (let* ((encoding "base64") ;Encode in BASE64 by default.
1919 (beg (mime-editor/content-beginning))
1920 (end (mime-editor/content-end))
1921 (body (buffer-substring beg end))
1923 (mime-encode-region beg end encoding)
1924 (mime-editor/define-encoding encoding))
1929 (defun mime-delete-field (field)
1930 "Delete header FIELD."
1931 (let ((regexp (format "^%s:[ \t]*" field)))
1932 (goto-char (point-min))
1933 (while (re-search-forward regexp nil t)
1934 (delete-region (match-beginning 0)
1935 (progn (forward-line 1) (point)))
1940 ;;; Platform dependent functions
1943 ;; Sun implementations
1945 (defun mime-editor/voice-recorder-for-sun (encoding)
1946 "Record voice in a buffer using Sun audio device,
1947 and insert data encoded as ENCODING. [tm-edit.el]"
1948 (message "Start the recording on %s. Type C-g to finish the recording..."
1950 (mime-insert-encoded-file "/dev/audio" encoding)
1954 ;;; @ Other useful commands.
1957 ;; Message forwarding commands as content-type "message/rfc822".
1959 (defun mime-editor/insert-message (&optional message)
1961 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
1962 (if (and inserter (fboundp inserter))
1964 (mime-editor/insert-tag "message" "rfc822")
1965 (funcall inserter message)
1967 (message "Sorry, I don't have message inserter for your MUA.")
1970 (defun mime-editor/insert-mail (&optional message)
1972 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
1973 (if (and inserter (fboundp inserter))
1975 (mime-editor/insert-tag "message" "rfc822")
1976 (funcall inserter message)
1978 (message "Sorry, I don't have mail inserter for your MUA.")
1981 (defun mime-editor/inserted-message-filter ()
1984 (let ((header-start (point))
1985 (case-fold-search t)
1988 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
1989 (if (re-search-forward "^$" (mark t))
1990 (narrow-to-region header-start (match-beginning 0))
1992 (goto-char header-start)
1993 (while (and (re-search-forward
1994 mime-editor/yank-ignored-field-regexp nil t)
1995 (setq beg (match-beginning 0))
1996 (setq end (1+ (std11-field-end)))
1998 (delete-region beg end)
2003 ;;; @ multipart enclosure
2006 (defun mime-editor/enclose-region (type beg end)
2009 (let ((current (point)))
2011 (narrow-to-region beg end)
2012 (insert (format "--<<%s>>-{\n" type))
2013 (goto-char (point-max))
2014 (insert (format "--}-<<%s>>\n" type))
2015 (goto-char (point-max))
2017 (or (looking-at mime-editor/beginning-tag-regexp)
2019 (insert (mime-make-text-tag) "\n")
2023 (defun mime-editor/enclose-quote-region (beg end)
2025 (mime-editor/enclose-region "quote" beg end)
2028 (defun mime-editor/enclose-mixed-region (beg end)
2030 (mime-editor/enclose-region "mixed" beg end)
2033 (defun mime-editor/enclose-parallel-region (beg end)
2035 (mime-editor/enclose-region "parallel" beg end)
2038 (defun mime-editor/enclose-digest-region (beg end)
2040 (mime-editor/enclose-region "digest" beg end)
2043 (defun mime-editor/enclose-alternative-region (beg end)
2045 (mime-editor/enclose-region "alternative" beg end)
2048 (defun mime-editor/enclose-signed-region (beg end)
2050 (if mime-editor/signing-type
2051 (mime-editor/enclose-region "signed" beg end)
2052 (message "Please specify signing type.")
2055 (defun mime-editor/enclose-encrypted-region (beg end)
2057 (if mime-editor/signing-type
2058 (mime-editor/enclose-region "encrypted" beg end)
2059 (message "Please specify encrypting type.")
2062 (defun mime-editor/insert-key (&optional arg)
2063 "Insert a pgp public key."
2065 (mime-editor/insert-tag "application" "pgp-keys")
2066 (mime-editor/define-encoding "7bit")
2067 (funcall mime-editor/pgp-insert-public-key-function)
2074 (defun mime-editor/set-split (arg)
2077 (y-or-n-p "Do you want to enable split?")
2079 (setq mime-editor/split-message arg)
2081 (message "This message is enabled to split.")
2082 (message "This message is not enabled to split.")
2085 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2086 "Toggle transfer-level is 7bit or 8bit through.
2088 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2090 (if (numberp transfer-level)
2091 (setq mime-editor/transfer-level transfer-level)
2092 (if (< mime-editor/transfer-level 8)
2093 (setq mime-editor/transfer-level 8)
2094 (setq mime-editor/transfer-level 7)
2096 (setq mime-editor/charset-default-encoding-alist
2097 (mime-editor/make-charset-default-encoding-alist
2098 mime-editor/transfer-level))
2099 (message (format "Current transfer-level is %d bit"
2100 mime-editor/transfer-level))
2101 (setq mime-editor/transfer-level-string
2102 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2103 (force-mode-line-update)
2106 (defun mime-editor/set-transfer-level-7bit ()
2108 (mime-editor/toggle-transfer-level 7)
2111 (defun mime-editor/set-transfer-level-8bit ()
2113 (mime-editor/toggle-transfer-level 8)
2120 (defun mime-editor/set-sign (arg)
2123 (y-or-n-p "Do you want to sign?")
2126 (if mime-editor/signing-type
2128 (setq mime-editor/pgp-processing 'sign)
2129 (message "This message will be signed.")
2131 (message "Please specify signing type.")
2133 (if (eq mime-editor/pgp-processing 'sign)
2134 (setq mime-editor/pgp-processing nil)
2136 (message "This message will not be signed.")
2139 (defun mime-editor/set-encrypt (arg)
2142 (y-or-n-p "Do you want to encrypt?")
2145 (if mime-editor/encrypting-type
2147 (setq mime-editor/pgp-processing 'encrypt)
2148 (message "This message will be encrypt.")
2150 (message "Please specify encrypting type.")
2152 (if (eq mime-editor/pgp-processing 'encrypt)
2153 (setq mime-editor/pgp-processing nil)
2155 (message "This message will not be encrypt.")
2158 (defvar mime-editor/pgp-processing nil)
2159 (make-variable-buffer-local 'mime-editor/pgp-processing)
2161 (defun mime-editor/pgp-enclose-buffer ()
2162 (let ((beg (save-excursion
2163 (goto-char (point-min))
2164 (if (search-forward (concat "\n" mail-header-separator "\n"))
2170 (cond ((eq mime-editor/pgp-processing 'sign)
2171 (mime-editor/enclose-signed-region beg end)
2173 ((eq mime-editor/pgp-processing 'encrypt)
2174 (mime-editor/enclose-encrypted-region beg end)
2182 (defun mime-editor/insert-partial-header
2183 (fields subject id number total separator)
2185 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2186 (insert (format "Mime-Version: 1.0 (split by %s)\n"
2187 mime-editor/version-name))
2189 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2190 id number total separator))
2193 (defun mime-editor/split-and-send
2194 (&optional cmd lines mime-editor/message-max-length)
2198 (count-lines (point-min) (point-max)))
2200 (or mime-editor/message-max-length
2201 (setq mime-editor/message-max-length
2202 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
2203 mime-editor/message-default-max-lines))
2205 (let* ((mime-editor/draft-file-name
2206 (or (buffer-file-name)
2208 (expand-file-name "tm-draft" mime/tmp-dir))))
2209 (separator mail-header-separator)
2211 (replace-space-with-underline (current-time-string))
2212 "@" (system-name) "\"")))
2213 (run-hooks 'mime-editor/before-split-hook)
2214 (let ((the-buf (current-buffer))
2215 (copy-buf (get-buffer-create " *Original Message*"))
2216 (header (std11-header-string-except
2217 mime-editor/split-ignored-field-regexp separator))
2218 (subject (mail-fetch-field "subject"))
2219 (total (+ (/ lines mime-editor/message-max-length)
2220 (if (> (mod lines mime-editor/message-max-length) 0)
2226 mime-editor/split-message-sender-alist))
2230 (error "Split sender is not specified for `%s'." major-mode)
2233 (mime-editor/partial-number 1)
2236 (set-buffer copy-buf)
2238 (insert-buffer the-buf)
2240 (if (re-search-forward
2241 (concat "^" (regexp-quote separator) "$") nil t)
2242 (let ((he (match-beginning 0)))
2244 (narrow-to-region (point-min) he)
2246 (goto-char (point-min))
2247 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
2248 (delete-region (match-beginning 0)
2249 (1+ (std11-field-end)))
2251 (while (< mime-editor/partial-number total)
2254 (set-buffer copy-buf)
2255 (setq data (buffer-substring
2258 (goto-line mime-editor/message-max-length)
2261 (delete-region (point-min)(point))
2263 (mime-editor/insert-partial-header
2264 header subject id mime-editor/partial-number total separator)
2267 (message (format "Sending %d/%d..."
2268 mime-editor/partial-number total))
2269 (call-interactively command)
2270 (message (format "Sending %d/%d... done"
2271 mime-editor/partial-number total))
2273 (setq mime-editor/partial-number
2274 (1+ mime-editor/partial-number))
2278 (set-buffer copy-buf)
2279 (setq data (buffer-string))
2282 (mime-editor/insert-partial-header
2283 header subject id mime-editor/partial-number total separator)
2286 (message (format "Sending %d/%d..."
2287 mime-editor/partial-number total))
2288 (message (format "Sending %d/%d... done"
2289 mime-editor/partial-number total))
2293 (defun mime-editor/maybe-split-and-send (&optional cmd)
2295 (run-hooks 'mime-editor/before-send-hook)
2296 (let ((mime-editor/message-max-length
2297 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
2298 mime-editor/message-default-max-lines))
2299 (lines (count-lines (point-min) (point-max)))
2301 (if (and (> lines mime-editor/message-max-length)
2302 mime-editor/split-message)
2303 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2307 ;;; @ preview message
2310 (defun mime-editor/preview-message ()
2311 "preview editing MIME message. [tm-edit.el]"
2313 (let* ((str (buffer-string))
2314 (separator mail-header-separator)
2315 (the-buf (current-buffer))
2316 (buf-name (buffer-name))
2317 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2318 (buf (get-buffer temp-buf-name))
2322 (switch-to-buffer buf)
2325 (setq buf (get-buffer-create temp-buf-name))
2326 (switch-to-buffer buf)
2329 (setq major-mode 'mime/temporary-message-mode)
2330 (make-local-variable 'mail-header-separator)
2331 (setq mail-header-separator separator)
2332 (make-local-variable 'mime/editing-buffer)
2333 (setq mime/editing-buffer the-buf)
2335 (run-hooks 'mime-editor/translate-hook)
2336 (mime-editor/translate-buffer)
2337 (goto-char (point-min))
2338 (if (re-search-forward
2339 (concat "^" (regexp-quote separator) "$"))
2345 (defun mime-editor/quitting-method ()
2346 (let ((temp mime::preview/article-buffer)
2348 (mime-viewer/kill-buffer)
2350 (setq buf mime/editing-buffer)
2352 (switch-to-buffer buf)
2355 (set-alist 'mime-viewer/quitting-method-alist
2356 'mime/temporary-message-mode
2357 (function mime-editor/quitting-method)
2363 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2364 ;; Mon, 10 Apr 1995 20:03:07 +0900
2366 (defvar mime-editor/draft-header-separator-alist
2367 '((news-reply-mode . mail-header-separator)
2368 (mh-letter-mode . mail-header-separator)
2371 (defvar mime::article/draft-header-separator nil)
2373 (defun mime-editor/draft-preview ()
2375 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2376 (or (stringp sep) (setq sep (eval sep)))
2377 (make-variable-buffer-local 'mime::article/draft-header-separator)
2378 (goto-char (point-min))
2380 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2381 (setq mime::article/draft-header-separator
2382 (buffer-substring (match-beginning 0) (match-end 0)))
2384 (mime/viewer-mode (current-buffer))
2385 (pop-to-buffer (current-buffer))
2388 (defun mime-viewer::quitting-method/draft-preview ()
2389 (let ((mother mime::preview/mother-buffer))
2391 (switch-to-buffer mother)
2392 (goto-char (point-min))
2396 (regexp-quote mime::article/draft-header-separator)
2400 (insert mime::article/draft-header-separator)
2401 (set-buffer-modified-p (buffer-modified-p))
2403 (mime-viewer/kill-buffer)
2404 (pop-to-buffer mother)
2407 (set-alist 'mime-viewer/quitting-method-alist
2409 (function mime-viewer::quitting-method/draft-preview)
2412 (set-alist 'mime-viewer/quitting-method-alist
2414 (function mime-viewer::quitting-method/draft-preview)
2421 (defun mime-editor::edit-again (code-conversion)
2423 (goto-char (point-min))
2424 (let ((ctl (mime/Content-Type)))
2426 (let ((ctype (car ctl))
2429 (if (string-match "/" ctype)
2431 (setq type (substring ctype 0 (match-beginning 0)))
2432 (setq stype (substring ctype (match-end 0)))
2437 ((string-equal type "multipart")
2438 (let* ((boundary (assoc-value "boundary" params))
2440 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2442 (re-search-forward boundary-pat nil t)
2443 (let ((bb (match-beginning 0)) eb tag)
2444 (setq tag (format "\n--<<%s>>-{\n" stype))
2447 (setq bb (+ bb (length tag)))
2449 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2451 (setq eb (match-beginning 0))
2452 (replace-match (format "--}-<<%s>>\n" stype))
2454 (narrow-to-region bb eb)
2455 (goto-char (point-min))
2456 (while (re-search-forward boundary-pat nil t)
2457 (let ((beg (match-beginning 0))
2459 (delete-region beg (match-end 0))
2461 (if (re-search-forward boundary-pat nil t)
2462 (setq end (match-beginning 0))
2463 (setq end (point-max))
2466 (narrow-to-region beg end)
2467 (mime-editor::edit-again code-conversion)
2468 (goto-char (point-max))
2471 (goto-char (point-min))
2472 (or (= (point-min) 1)
2473 (delete-region (point-min)
2474 (if (search-forward "\n\n" nil t)
2482 (let ((bytes (+ 14 (length ctype))))
2483 (mapconcat (function
2485 (if (string-equal (car attr) "charset")
2487 (setq charset (cdr attr))
2495 (setq bytes (+ bytes bs 2))
2498 (setq bytes (+ bs 1))
2506 (if (re-search-forward
2507 "Content-Transfer-Encoding:" nil t)
2508 (let ((beg (match-beginning 0))
2509 (hbeg (match-end 0))
2510 (end (std11-field-end)))
2512 (eliminate-top-spaces
2513 (std11-unfold-string
2514 (buffer-substring hbeg end))))
2515 (if (or charset (string-equal type "text"))
2517 (delete-region beg (1+ end))
2518 (goto-char (point-min))
2519 (if (search-forward "\n\n" nil t)
2522 (match-end 0)(point-max) encoding)
2526 (if (or code-conversion encoded)
2527 (decode-mime-charset-region
2528 (point-min)(point-max)
2529 (or charset default-mime-charset))
2532 (if (re-search-forward "^$" nil t)
2536 (if (= (point-min) 1)
2542 (concat type "/" stype pstr) encoding)))
2544 (delete-region (point-min) he)
2547 (concat type "/" stype pstr) encoding))
2551 (decode-mime-charset-region (point-min) (point-max)
2552 default-mime-charset)
2556 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2558 (mime-editor::edit-again code-conversion)
2559 (goto-char (point-min))
2563 (if (re-search-forward
2564 (concat "^\\(" (regexp-quote mail-header-separator) "\\)?$")
2569 (goto-char (point-min))
2570 (while (re-search-forward
2571 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2572 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2575 (and (re-search-forward "^$")
2576 (replace-match mail-header-separator)
2588 (run-hooks 'tm-edit-load-hook)
2590 ;;; tm-edit.el ends here