2 ;;; tm-edit.el --- Simple MIME Composer for GNU Emacs
4 ;;; Copyright (C) 1993 UMEDA Masanobu
5 ;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
7 ;;; Author: UMEDA Masanobu <umerin@mse.kyutech.ac.jp>
8 ;;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
10 ;;; Created: 1994/08/21 renamed from mime.el
11 ;;; Version: $Revision: 7.73 $
12 ;;; Keywords: mail, news, MIME, multimedia, multilingual
14 ;;; This file is part of tm (Tools for MIME).
16 ;;; This program is free software; you can redistribute it and/or
17 ;;; modify it under the terms of the GNU General Public License as
18 ;;; published by the Free Software Foundation; either version 2, or
19 ;;; (at your option) any later version.
21 ;;; This program is distributed in the hope that it will be useful,
22 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 ;;; General Public License for more details.
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with This program. If not, write to the Free Software
28 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
32 ;; This is an Emacs minor mode for editing Internet multimedia
33 ;; messages formatted in MIME (RFC 1521 and RFC 1522). All messages in
34 ;; this mode are composed in the tagged MIME format, that are
35 ;; described in the following examples. The messages composed in the
36 ;; tagged MIME format are automatically translated into a MIME
37 ;; compliant message when exiting the mode.
39 ;; Mule (a multilingual extension to Emacs 18 and 19) has a capability
40 ;; of handling multilingual text in limited ISO-2022 manner that is
41 ;; based on early experiences in Japanese Internet community and
42 ;; resulted in RFC 1468 (ISO-2022-JP charset for MIME). In order to
43 ;; enable multilingual capability in single text message in MIME,
44 ;; charset of multilingual text written in Mule is declared as either
45 ;; `ISO-2022-JP-2' [RFC 1554] or `ISO-2022-INT-1'. Mule is required
46 ;; for reading the such messages.
48 ;; This MIME composer can work with Mail mode, mh-e letter Mode, and
49 ;; News mode. First of all, you need the following autoload
50 ;; definition to load mime/editor-mode automatically:
52 ;; (autoload 'mime/editor-mode "tm-edit"
53 ;; "Minor mode for editing MIME message." t)
55 ;; In case of Mail mode (includes VM mode), you need the following
58 ;; (add-hook 'mail-mode-hook 'mime/editor-mode)
59 ;; (add-hook 'mail-send-hook 'mime-editor/maybe-translate)
61 ;; In case of MH-E, you need the following hook definition:
63 ;; (add-hook 'mh-letter-mode-hook
67 ;; (make-local-variable 'mail-header-separator)
68 ;; (setq mail-header-separator "--------")
70 ;; (add-hook 'mh-before-send-letter-hook 'mime-editor/maybe-translate)
72 ;; In case of News mode, you need the following hook definition:
74 ;; (add-hook 'news-reply-mode-hook 'mime/editor-mode)
75 ;; (add-hook 'news-inews-hook 'mime-editor/maybe-translate)
77 ;; In case of Emacs 19, it is possible to emphasize the message tags
78 ;; using font-lock mode as follows:
80 ;; (add-hook 'mime/editor-mode-hook
84 ;; (setq font-lock-keywords (list mime-editor/tag-regexp))
87 ;; The message tag looks like:
89 ;; --[[TYPE/SUBTYPE;PARAMETERS][ENCODING]]
91 ;; The tagged MIME message examples:
93 ;; This is a conventional plain text. It should be translated into
97 ;; This is also a plain text. But, it is explicitly specified as is.
99 ;;--[[text/plain; charset=ISO-2022-JP]]
100 ;;
\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.
102 ;;--[[text/richtext]]
103 ;; <center>This is a richtext.</center>
105 ;;--[[image/gif][base64]]^M...image encoded in base64 comes here...
107 ;;--[[audio/basic][base64]]^M...audio encoded in base64 comes here...
112 (require 'mail-utils)
124 (defconst mime-editor/RCS-ID
125 "$Id: tm-edit.el,v 7.73 1996/07/22 19:29:42 morioka Exp $")
127 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
129 (defconst mime-editor/version-name
130 (concat "tm-edit " mime-editor/version))
136 (defvar mime-prefix "\C-c\C-x"
137 "*Keymap prefix for MIME commands.")
139 (defvar mime-ignore-preceding-spaces nil
140 "*Ignore preceding white spaces if non-nil.")
142 (defvar mime-ignore-trailing-spaces nil
143 "*Ignore trailing white spaces if non-nil.")
145 (defvar mime-ignore-same-text-tag t
146 "*Ignore preceding text content-type tag that is same with new one.
147 If non-nil, the text tag is not inserted unless something different.")
149 (defvar mime-auto-hide-body t
150 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
152 (defvar mime-voice-recorder
153 (function mime-voice-recorder-for-sun)
154 "*Function to record a voice message and return a buffer that contains it.")
156 (defvar mime/editor-mode-hook nil
157 "*Hook called when enter MIME mode.")
159 (defvar mime-editor/translate-hook nil
160 "*Hook called before translating into a MIME compliant message.
161 To insert a signature file automatically, call the function
162 `mime-editor/insert-signature' from this hook.")
164 (defvar mime-editor/exit-hook nil
165 "*Hook called when exit MIME mode.")
167 (defvar mime-content-types
169 ;; Charset parameter need not to be specified, since it is
170 ;; defined automatically while translation.
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")
181 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
184 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
192 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
193 ("directory" "/pub/GNU/elisp/mime")
195 ("mode" "image" "ascii" "local8"))
200 ("mode" "image" "ascii" "local8"))
201 ("tftp" ("site") ("name"))
202 ("afs" ("site") ("name"))
203 ("local-file" ("site") ("name"))
204 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
209 ("octet-stream" ("type" "" "tar" "shar"))
211 ("x-kiss" ("x-cnf")))
224 "*Alist of content-type, subtype, parameters and its values.")
226 (defvar mime-file-types
228 "text" "richtext" nil
236 "application" "postscript" nil
238 "attachment" (("filename" . file))
243 "inline" (("filename" . file))
248 "inline" (("filename" . file))
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))
286 "application" "octet-stream" (("type" . "emacs-lisp"))
288 "attachment" (("filename" . file))
291 "application" "octet-stream" (("type" . "common-lisp"))
293 "attachment" (("filename" . file))
296 "application" "octet-stream" (("type" . "tar+gzip"))
298 "attachment" (("filename" . file))
301 "application" "octet-stream" (("type" . "tar+gzip"))
303 "attachment" (("filename" . file))
306 "application" "octet-stream" (("type" . "tar+compress"))
308 "attachment" (("filename" . file))
311 "application" "octet-stream" (("type" . "tar+compress"))
313 "attachment" (("filename" . file))
316 "application" "octet-stream" (("type" . "gzip"))
318 "attachment" (("filename" . file))
321 "application" "octet-stream" (("type" . "compress"))
323 "attachment" (("filename" . file))
326 "application" "octet-stream" (("type" . "lha"))
328 "attachment" (("filename" . file))
331 "application" "zip" nil
333 "attachment" (("filename" . file))
336 "application" "octet-stream" (("type" . "patch"))
338 "attachment" (("filename" . file))
341 "application" "octet-stream" (("type" . "patch"))
343 "attachment" (("filename" . file))
346 "text" "plain" nil nil)
348 "application" "octet-stream" nil
350 "attachment" (("filename" . file))
353 "*Alist of file name, types, parameters, and default encoding.
354 If encoding is nil, it is determined from its contents.")
356 ;;; @@ about charset, encoding and transfer-level
359 (defvar mime-editor/transfer-level 7
360 "*A number of network transfer level. It should be bigger than 7.")
361 (make-variable-buffer-local 'mime-editor/transfer-level)
363 (defvar mime-editor/transfer-level-string
364 (mime/encoding-name mime-editor/transfer-level 'not-omit)
365 "*A string formatted version of mime/defaul-transfer-level")
366 (make-variable-buffer-local 'mime-editor/transfer-level-string)
368 (defun mime-editor/make-charset-default-encoding-alist (transfer-level)
370 (lambda (charset-type)
371 (let ((charset (car charset-type))
372 (type (nth 1 charset-type))
373 (encoding (nth 2 charset-type))
375 (if (<= type transfer-level)
376 (cons charset (mime/encoding-name type))
377 (cons charset encoding)
379 mime-charset-type-list))
381 (defvar mime-editor/charset-default-encoding-alist
382 (mime-editor/make-charset-default-encoding-alist mime-editor/transfer-level))
383 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
385 ;;; @@ about message inserting
388 (defvar mime-editor/yank-ignored-field-list
389 '("Received" "Approved" "Path" "Replied" "Status" "X-VM-.*" "X-UIDL")
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-length 1000
409 "*Default maximum size of a message. [tm-edit.el]")
411 (defvar mime-editor/message-max-length-alist
412 '((news-reply-mode . 500)))
414 (defconst mime-editor/split-ignored-field-regexp
415 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
417 (defvar mime-editor/split-blind-field-regexp
418 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
420 (defvar mime-editor/split-message-sender-alist
422 . (lambda (&optional arg)
424 (write-region (point-min) (point-max)
425 mime-editor/draft-file-name nil 'no-message)
427 (pop-to-buffer "MH mail delivery")
429 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
431 mh-send-args mime-editor/draft-file-name)
432 (goto-char (point-max)) ; show the interesting part
436 (apply 'mh-exec-cmd-quiet t mh-send-prog
438 (list "-nopush" "-nodraftfolder"
439 "-noverbose" "-nowatch"
440 mh-send-args mime-editor/draft-file-name)))))
444 (defvar mime-editor/news-reply-mode-server-running nil)
450 (defvar mime-editor/signing-type nil
451 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
453 (defvar mime-editor/encrypting-type nil
454 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
456 (if (or mime-editor/signing-type mime-editor/encrypting-type)
464 (defconst mime-editor/single-part-tag-regexp
465 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
466 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
468 (defconst mime-editor/quoted-single-part-tag-regexp
469 (concat "- " (substring mime-editor/single-part-tag-regexp 1)))
471 (defconst mime-editor/multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
473 (defconst mime-editor/multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
475 (defconst mime-editor/beginning-tag-regexp
476 (regexp-or mime-editor/single-part-tag-regexp
477 mime-editor/multipart-beginning-regexp))
479 (defconst mime-editor/end-tag-regexp
480 (regexp-or mime-editor/single-part-tag-regexp
481 mime-editor/multipart-end-regexp))
483 (defconst mime-editor/tag-regexp
484 (regexp-or mime-editor/single-part-tag-regexp
485 mime-editor/multipart-beginning-regexp
486 mime-editor/multipart-end-regexp))
488 (defvar mime-tag-format "--[[%s]]"
489 "*Control-string making a MIME tag.")
491 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
492 "*Control-string making a MIME tag with encoding.")
494 ;;; @@ multipart boundary
497 (defvar mime-multipart-boundary "Multipart"
498 "*Boundary of a multipart message.")
501 ;;; @@ buffer local variables
504 (defvar mime/editor-mode-old-local-map nil)
505 (defvar mime/editing-buffer nil)
511 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
512 "*Specify MIME tspecials.
513 Tspecials means any character that matches with it in header must be quoted.")
515 (defconst mime-editor/mime-version-value
516 (concat "1.0 (generated by " mime-editor/version-name ")")
517 "MIME version number.")
519 (defconst mime-editor/mime-map (make-sparse-keymap)
520 "Keymap for MIME commands.")
522 ;;; @ keymap and menu
525 (defvar mime/editor-mode-flag nil)
526 (make-variable-buffer-local 'mime/editor-mode-flag)
528 (defun mime-editor/define-keymap (keymap)
529 "Add mime-editor commands to KEYMAP."
530 (if (not (keymapp keymap))
532 (define-key keymap "\C-t" 'mime-editor/insert-text)
533 (define-key keymap "\C-i" 'mime-editor/insert-file)
534 (define-key keymap "\C-e" 'mime-editor/insert-external)
535 (define-key keymap "\C-v" 'mime-editor/insert-voice)
536 (define-key keymap "\C-y" 'mime-editor/insert-message)
537 (define-key keymap "\C-m" 'mime-editor/insert-mail)
538 (define-key keymap "\C-w" 'mime-editor/insert-signature)
539 (define-key keymap "\C-s" 'mime-editor/insert-signature)
540 (define-key keymap "\C-k" 'mime-editor/insert-key)
541 (define-key keymap "t" 'mime-editor/insert-tag)
542 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
543 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
544 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
545 (define-key keymap "d" 'mime-editor/enclose-digest-region)
546 (define-key keymap "s" 'mime-editor/enclose-signed-region)
547 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
548 (define-key keymap "q" 'mime-editor/enclose-quote-region)
549 (define-key keymap "\C-p" 'mime-editor/preview-message)
550 (define-key keymap "\C-z" 'mime-editor/exit)
551 (define-key keymap "?" 'mime-editor/help)
554 (mime-editor/define-keymap mime-editor/mime-map)
556 (defun mime-editor/toggle-mode ()
558 (if mime/editor-mode-flag
559 (mime-editor/exit 'nomime)
563 (cond (running-xemacs
564 (defconst mime-editor/minor-mime-map nil "Keymap for MIME commands.")
565 (or mime-editor/minor-mime-map
567 (setq mime-editor/minor-mime-map
568 (make-sparse-keymap 'mime-editor/minor-mime-map))
570 mime-editor/minor-mime-map mime-prefix mime-editor/mime-map)
572 (add-minor-mode 'mime/editor-mode-flag
573 '((" MIME-Edit " mime-editor/transfer-level-string))
574 mime-editor/minor-mime-map
576 'mime-editor/toggle-mode)
579 (set-alist 'minor-mode-alist
580 'mime/editor-mode-flag
581 '((" MIME-Edit " mime-editor/transfer-level-string))))
584 (defconst mime-editor/menu-title "MIME-Edit")
586 (defconst mime-editor/menu-list
587 '((mime-help "Describe MIME editor mode" mime-editor/help)
588 (file "Insert File" mime-editor/insert-file)
589 (external "Insert External" mime-editor/insert-external)
590 (voice "Insert Voice" mime-editor/insert-voice)
591 (message "Insert Message" mime-editor/insert-message)
592 (mail "Insert Mail" mime-editor/insert-mail)
593 (signature "Insert Signature" mime-editor/insert-signature)
594 (text "Insert Text" mime-editor/insert-text)
595 (tag "Insert Tag" mime-editor/insert-tag)
596 (alternative "Enclose as alternative"
597 mime-editor/enclose-alternative-region)
598 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
599 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
600 (digest "Enclose as digest" mime-editor/enclose-digest-region)
601 (signed "Enclose as signed" mime-editor/enclose-signed-region)
602 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
603 (quote "Verbatim region" mime-editor/enclose-quote-region)
604 (key "Insert Public Key" mime-editor/insert-key)
605 (split "About split" mime-editor/set-split)
606 (sign "About sign" mime-editor/set-sign)
607 (encrypt "About encryption" mime-editor/set-encrypt)
608 (preview "Preview Message" mime-editor/preview-message)
609 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
611 "MIME-edit menubar entry.")
613 (defun mime-editor/define-menu-for-emacs19 ()
614 "Define menu for Emacs 19."
615 (define-key (current-local-map) [menu-bar mime-edit]
616 (cons mime-editor/menu-title
617 (make-sparse-keymap mime-editor/menu-title)))
620 (define-key (current-local-map)
621 (vector 'menu-bar 'mime-edit (car item))
622 (cons (nth 1 item)(nth 2 item))
625 (reverse mime-editor/menu-list)
628 ;;; modified by Pekka Marjola <pema@iki.fi>
629 ;;; 1995/9/5 (c.f. [tm-en:69])
630 (defun mime-editor/define-menu-for-xemacs ()
631 "Define menu for Emacs 19."
632 (cond ((featurep 'menubar)
633 (make-local-variable 'current-menubar)
634 (set-buffer-menubar current-menubar)
636 (cons mime-editor/menu-title
639 (vector (nth 1 item)(nth 2 item)
640 mime/editor-mode-flag)
642 mime-editor/menu-list)))
645 ;;; modified by Steven L. Baur <steve@miranova.com>
646 ;;; 1995/12/6 (c.f. [tm-en:209])
647 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
648 (setq mime-editor/popup-menu-for-xemacs
649 (append '("MIME Commands" "---")
650 (mapcar (function (lambda (item)
654 mime-editor/menu-list)))
663 (defun mime/editor-mode ()
664 "MIME minor mode for editing the tagged MIME message.
666 In this mode, basically, the message is composed in the tagged MIME
667 format. The message tag looks like:
669 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
671 The tag specifies the MIME content type, subtype, optional parameters
672 and transfer encoding of the message following the tag. Messages
673 without any tag are treated as `text/plain' by default. Charset and
674 transfer encoding are automatically defined unless explicitly
675 specified. Binary messages such as audio and image are usually hidden.
676 The messages in the tagged MIME format are automatically translated
677 into a MIME compliant message when exiting this mode.
679 Available charsets depend on Emacs version being used. The following
680 lists the available charsets of each emacs.
682 EMACS 18: US-ASCII is only available.
683 NEmacs: US-ASCII and ISO-2022-JP are available.
684 EMACS 19: US-ASCII and ISO-8859-1 (or other charset) are available.
685 XEmacs 19: US-ASCII and ISO-8859-1 (or other charset) are available.
686 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
687 ISO-2022-JP, ISO-2022-JP-2, ISO-2022-KR, BIG5 and
688 ISO-2022-INT-1 are available.
690 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
691 be used to represent multilingual text in intermixed manner. Any
692 languages that has no registered charset are represented as either
693 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
695 If you want to use non-ISO-8859-1 charset in EMACS 19 or XEmacs 19,
696 please set variable `default-mime-charset'. This variable must be
697 symbol of which name is a MIME charset.
699 If you want to add more charsets in mule, please set variable
700 `charsets-mime-charset-alist'. This variable must be alist of which
701 key is list of leading-char/charset and value is symbol of MIME
702 charset. (leading-char is a term of MULE 1.* and 2.*. charset is a
703 term of XEmacs/mule, mule merged EMACS and MULE 3.*) If name of
704 coding-system is different as MIME charset, please set variable
705 `mime-charset-coding-system-alist'. This variable must be alist of
706 which key is MIME charset and value is coding-system.
708 Following commands are available in addition to major mode commands:
709 \\[mime-editor/insert-text] insert a text message.
710 \\[mime-editor/insert-file] insert a (binary) file.
711 \\[mime-editor/insert-external] insert a reference to external body.
712 \\[mime-editor/insert-voice] insert a voice message.
713 \\[mime-editor/insert-message] insert a mail or news message.
714 \\[mime-editor/insert-mail] insert a mail message.
715 \\[mime-editor/insert-signature] insert a signature file at end.
716 \\[mime-editor/insert-tag] insert a new MIME tag.
717 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
718 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
719 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
720 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
721 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
722 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
723 \\[mime-editor/insert-key] insert PGP public key.
724 \\[mime-editor/preview-message] preview editing MIME message.
725 \\[mime-editor/exit] exit and translate into a MIME compliant message.
726 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
727 \\[mime-editor/help] show this help.
729 Additional commands are available in some major modes:
730 C-c C-c exit, translate and run the original command.
731 C-c C-s exit, translate and run the original command.
733 The following is a message example written in the tagged MIME format.
734 TABs at the beginning of the line are not a part of the message:
736 This is a conventional plain text. It should be translated
739 This is also a plain text. But, it is explicitly specified as
741 --[[text/plain; charset=ISO-2022-JP]]
742 \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
745 <center>This is a richtext.</center>
746 --[[image/gif][base64]]^M...image encoded in base64 here...
747 --[[audio/basic][base64]]^M...audio encoded in base64 here...
749 User customizable variables (not documented all of them):
751 Specifies a key prefix for MIME minor mode commands.
753 mime-ignore-preceding-spaces
754 Preceding white spaces in a message body are ignored if non-nil.
756 mime-ignore-trailing-spaces
757 Trailing white spaces in a message body are ignored if non-nil.
759 mime-auto-fill-header
760 Fill header fields that contain encoded-words if non-nil.
763 Hide a non-textual body message encoded in base64 after insertion
767 Specifies a function to record a voice message and return a buffer
768 that contains it. The function mime-voice-recorder-for-sun is for
771 mime/editor-mode-hook
772 Turning on MIME mode calls the value of mime/editor-mode-hook, if
775 mime-editor/translate-hook
776 The value of mime-editor/translate-hook is called just before translating
777 the tagged MIME format into a MIME compliant message if it is
778 non-nil. If the hook call the function mime-editor/insert-signature,
779 the signature file will be inserted automatically.
781 mime-editor/exit-hook
782 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
785 (if mime/editor-mode-flag
786 (error "You are already editing a MIME message.")
787 (setq mime/editor-mode-flag t)
788 ;; Remember old key bindings.
791 (make-local-variable 'mime/editor-mode-old-local-map)
792 (setq mime/editor-mode-old-local-map (current-local-map))
793 ;; Add MIME commands to current local map.
794 (use-local-map (copy-keymap (current-local-map)))
796 (if (not (lookup-key (current-local-map) mime-prefix))
797 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
799 ;; Set transfer level into mode line
801 (setq mime-editor/transfer-level-string
802 (mime/encoding-name mime-editor/transfer-level 'not-omit))
803 (force-mode-line-update)
805 ;; Define menu. Menus for other emacs implementations are
807 (cond (running-xemacs
808 (mime-editor/define-menu-for-xemacs))
809 ((>= emacs-major-version 19)
810 (mime-editor/define-menu-for-emacs19)
816 ;; I don't care about saving these.
817 (setq paragraph-start
818 (regexp-or mime-editor/single-part-tag-regexp
820 (setq paragraph-separate
821 (regexp-or mime-editor/single-part-tag-regexp
823 (run-hooks 'mime/editor-mode-hook)
825 (substitute-command-keys
826 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
830 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
831 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
833 (defun mime-editor/exit (&optional nomime no-error)
834 "Translate the tagged MIME message into a MIME compliant message.
835 With no argument encode a message in the buffer into MIME, otherwise
836 just return to previous mode."
838 (if (not mime/editor-mode-flag)
840 (error "You aren't editing a MIME message.")
844 (run-hooks 'mime-editor/translate-hook)
845 (mime-editor/translate-buffer)))
846 ;; Restore previous state.
847 (setq mime/editor-mode-flag nil)
848 (cond (running-xemacs
849 (delete-menu-item (list mime-editor/menu-title)))
851 (use-local-map mime/editor-mode-old-local-map)))
854 (set-buffer-modified-p (buffer-modified-p))
855 (run-hooks 'mime-editor/exit-hook)
856 (message "Exit MIME editor mode.")
859 (defun mime-editor/maybe-translate ()
861 (mime-editor/exit nil t)
862 (call-interactively 'mime-editor/maybe-split-and-send)
865 (defun mime-editor/help ()
866 "Show help message about MIME mode."
868 (with-output-to-temp-buffer "*Help*"
869 (princ "MIME editor mode:\n")
870 (princ (documentation 'mime/editor-mode))
871 (print-help-return-message)))
873 (defun mime-editor/insert-text ()
874 "Insert a text message.
875 Charset is automatically obtained from the `mime/lc-charset-alist'."
877 (if (and (mime-editor/insert-tag "text" nil nil)
878 (looking-at mime-editor/single-part-tag-regexp))
880 ;; Make a space between the following message.
885 (defun mime-editor/insert-file (file)
886 "Insert a message from a file."
887 (interactive "fInsert file as MIME message: ")
888 (let* ((guess (mime-find-file-type file))
889 (pritype (nth 0 guess))
890 (subtype (nth 1 guess))
891 (parameters (nth 2 guess))
892 (default (nth 3 guess)) ;Guess encoding from its file name.
893 (disposition-type (nth 4 guess))
894 (disposition-params (nth 5 guess))
896 (if (not (interactive-p))
899 (concat "What transfer encoding"
902 (if (string-equal default "")
908 mime-encoding-method-alist nil t nil))))
909 (if (string-equal encoding "")
910 (setq encoding default))
911 (if (or (consp parameters) (stringp disposition-type))
912 (let ((rest parameters) cell attribute value)
915 (setq cell (car rest))
916 (setq attribute (car cell))
917 (setq value (cdr cell))
919 (setq value (rfc822/wrap-as-quoted-string
920 (file-name-nondirectory file)))
922 (setq parameters (concat parameters "; " attribute "=" value))
923 (setq rest (cdr rest))
928 (concat parameters "\n"
929 "Content-Disposition: " disposition-type))
930 (setq rest disposition-params)
932 (setq cell (car rest))
933 (setq attribute (car cell))
934 (setq value (cdr cell))
936 (setq value (rfc822/wrap-as-quoted-string
937 (file-name-nondirectory file)))
940 (concat parameters "; " attribute "=" value))
941 (setq rest (cdr rest))
945 (mime-editor/insert-tag pritype subtype parameters)
946 (mime-editor/insert-binary-file file encoding)
949 (defun mime-editor/insert-external ()
950 "Insert a reference to external body."
952 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
954 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
956 (let* ((pritype (mime-prompt-for-type))
957 (subtype (mime-prompt-for-subtype pritype))
958 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
961 (insert "Content-Type: "
962 pritype "/" subtype (or parameters "") "\n")))
963 (if (and (not (eobp))
964 (not (looking-at mime-editor/single-part-tag-regexp)))
965 (insert (mime-make-text-tag) "\n")))
967 (defun mime-editor/insert-voice ()
968 "Insert a voice message."
970 (mime-editor/insert-tag "audio" "basic" nil)
971 (let ((buffer (funcall mime-voice-recorder)))
973 (mime-editor/insert-binary-buffer buffer "base64")
977 (defun mime-editor/insert-signature (&optional arg)
978 "Insert a signature file."
980 (let ((signature-insert-hook
983 (apply (function mime-editor/insert-tag)
984 (mime-find-file-type signature-file-name))
987 (insert-signature arg)
991 ;; Insert a new tag around a point.
993 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
994 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
995 If nothing is inserted, return nil."
1003 (mime-prompt-for-type)))
1006 (mime-prompt-for-subtype pritype)))
1009 (mime-prompt-for-parameters pritype subtype delimiter)))
1010 ;; Make a new MIME tag.
1011 (setq newtag (mime-make-tag pritype subtype parameters))
1012 ;; Find an current MIME tag.
1015 (if (mime-editor/goto-tag)
1016 (buffer-substring (match-beginning 0) (match-end 0))
1017 ;; Assume content type is 'text/plan'.
1018 (mime-make-tag "text" "plain")
1020 ;; We are only interested in TEXT.
1022 (not (mime-test-content-type
1023 (mime-editor/get-contype oldtag) "text")))
1026 (if (or (not oldtag) ;Not text
1027 (or mime-ignore-same-text-tag
1028 (not (string-equal oldtag newtag))))
1030 ;; Mark the beginning of the tag for convenience.
1031 (push-mark (point) 'nomsg)
1032 (insert newtag "\n")
1033 (list pritype subtype parameters) ;New tag is created.
1035 ;; Restore previous point.
1037 nil ;Nothing is created.
1041 ;; Insert the binary content after MIME tag.
1042 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1044 (defun mime-editor/insert-binary-file (file &optional encoding)
1045 "Insert binary FILE at point.
1046 Optional argument ENCODING specifies an encoding method such as base64."
1047 (let ((tmpbuf (get-buffer-create " *MIME insert*")))
1051 (let ((mc-flag nil) ;Mule
1052 (file-coding-system-for-read
1053 (if (featurep 'mule) *noconv*))
1054 (kanji-flag nil) ;NEmacs
1055 (emx-binary-mode t) ;Stop CRLF to LF conversion in OS/2
1057 (let (jka-compr-compression-info-list
1058 jam-zcat-filename-list)
1059 (insert-file-contents file))))
1061 (if (and (stringp encoding)
1062 (string-equal (downcase encoding) "x-uue"))
1065 (let ((uuencode-external-encoder
1066 (cons (car uuencode-external-encoder)
1067 (list (file-name-nondirectory file))
1069 (mime-editor/insert-binary-buffer tmpbuf encoding)
1071 (mime-editor/insert-binary-buffer tmpbuf encoding))
1072 (kill-buffer tmpbuf))))
1074 ;; Insert the binary content after MIME tag.
1075 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1077 (defun mime-editor/insert-binary-buffer (buffer &optional encoding)
1078 "Insert binary BUFFER at point.
1079 Optional argument ENCODING specifies an encoding method such as base64."
1080 (let* ((tagend (1- (point))) ;End of the tag
1081 (hide-p (and mime-auto-hide-body
1083 (let ((en (downcase encoding)))
1084 (or (string-equal en "base64")
1085 (string-equal en "x-uue")
1089 (narrow-to-region (1- (point)) (point))
1090 (let ((start (point))
1091 (emx-binary-mode t)) ;Stop LF to CRLF conversion in OS/2
1092 (insert-buffer-substring buffer)
1093 ;; Encode binary message if necessary.
1095 (mime-encode-region start (point-max) encoding)
1099 (invisible-region (point-min) (point-max))
1100 (goto-char (point-max))
1103 ;; Define encoding even if it is 7bit.
1104 (if (stringp encoding)
1106 (goto-char tagend) ;Make sure which line the tag is on.
1107 (mime-editor/define-encoding encoding)))
1111 ;; Commands work on a current message flagment.
1113 (defun mime-editor/goto-tag ()
1114 "Search for the beginning of the tagged MIME message."
1115 (let ((current (point)) multipart)
1116 (if (looking-at mime-editor/tag-regexp)
1118 ;; At first, go to the end.
1119 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1120 (goto-char (1- (match-beginning 0))) ;For multiline tag
1123 (goto-char (point-max))
1125 ;; Then search for the beginning.
1126 (re-search-backward mime-editor/end-tag-regexp nil t)
1127 (or (looking-at mime-editor/beginning-tag-regexp)
1128 ;; Restore previous point.
1135 (defun mime-editor/content-beginning ()
1136 "Return the point of the beginning of content."
1138 (let ((beg (save-excursion
1139 (beginning-of-line) (point))))
1140 (if (mime-editor/goto-tag)
1141 (let ((top (point)))
1142 (goto-char (match-end 0))
1143 (if (and (= beg top)
1144 (= (following-char) ?\^M))
1148 ;; Default text/plain tag.
1149 (goto-char (point-min))
1151 (concat "\n" (regexp-quote mail-header-separator)
1152 (if mime-ignore-preceding-spaces
1153 "[ \t\n]*\n" "\n")) nil 'move)
1157 (defun mime-editor/content-end ()
1158 "Return the point of the end of content."
1160 (let ((beg (point)))
1161 (if (mime-editor/goto-tag)
1162 (let ((top (point)))
1163 (goto-char (match-end 0))
1164 (if (invisible-p (point))
1165 (next-visible-point (point))
1166 ;; Move to the end of this text.
1167 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1168 ;; Don't forget a multiline tag.
1169 (goto-char (match-beginning 0))
1173 ;; Assume the message begins with text/plain.
1174 (goto-char (mime-editor/content-beginning))
1175 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1176 ;; Don't forget a multiline tag.
1177 (goto-char (match-beginning 0)))
1181 (defun mime-editor/define-charset (charset)
1182 "Set charset of current tag to CHARSET."
1184 (if (mime-editor/goto-tag)
1185 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1186 (delete-region (match-beginning 0) (match-end 0))
1189 (mime-editor/set-parameter
1190 (mime-editor/get-contype tag)
1191 "charset" (upcase (symbol-name charset)))
1192 (mime-editor/get-encoding tag)))
1195 (defun mime-editor/define-encoding (encoding)
1196 "Set encoding of current tag to ENCODING."
1198 (if (mime-editor/goto-tag)
1199 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1200 (delete-region (match-beginning 0) (match-end 0))
1201 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1204 (defun mime-editor/choose-charset ()
1205 "Choose charset of a text following current point."
1206 (detect-mime-charset-region (point) (mime-editor/content-end))
1209 (defun mime-make-text-tag (&optional subtype)
1210 "Make a tag for a text after current point.
1211 Subtype of text type can be specified by an optional argument SUBTYPE.
1212 Otherwise, it is obtained from mime-content-types."
1213 (let* ((pritype "text")
1214 (subtype (or subtype
1215 (car (car (cdr (assoc pritype mime-content-types)))))))
1216 ;; Charset should be defined later.
1217 (mime-make-tag pritype subtype)))
1220 ;; Tag handling functions
1222 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1223 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1224 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1228 (defun mime-create-tag (contype &optional encoding)
1229 "Make a tag with CONTENT-TYPE and optional ENCODING."
1230 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1233 (defun mime-editor/get-contype (tag)
1234 "Return Content-Type (including parameters) of TAG."
1236 (or (string-match mime-editor/single-part-tag-regexp tag)
1237 (string-match mime-editor/multipart-beginning-regexp tag)
1238 (string-match mime-editor/multipart-end-regexp tag)
1240 (substring tag (match-beginning 1) (match-end 1))
1243 (defun mime-editor/get-encoding (tag)
1244 "Return encoding of TAG."
1246 (string-match mime-editor/single-part-tag-regexp tag)
1248 (not (= (match-beginning 3) (match-end 3)))
1249 (substring tag (match-beginning 3) (match-end 3))))
1251 (defun mime-get-parameter (contype parameter)
1252 "For given CONTYPE return value for PARAMETER.
1253 Nil if no such parameter."
1257 (regexp-quote parameter)
1258 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1260 (substring contype (match-beginning 1) (match-end 1))
1261 nil ;No such parameter
1264 (defun mime-editor/set-parameter (contype parameter value)
1265 "For given CONTYPE set PARAMETER to VALUE."
1266 (let (ctype opt-fields)
1267 (if (string-match "\n[^ \t\n\r]+:" contype)
1268 (setq ctype (substring contype 0 (match-beginning 0))
1269 opt-fields (substring contype (match-beginning 0)))
1270 (setq ctype contype)
1275 (regexp-quote parameter)
1276 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1279 (concat (substring ctype 0 (match-beginning 1))
1281 (substring contype (match-end 1))
1283 (concat ctype "; " parameter "=" value opt-fields)
1286 (defun mime-strip-parameters (contype)
1287 "Return primary content-type and subtype without parameters for CONTYPE."
1288 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1289 (substring contype (match-beginning 1) (match-end 1)) nil))
1291 (defun mime-test-content-type (contype type &optional subtype)
1292 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1293 (and (stringp contype)
1296 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1297 (downcase contype))))
1302 (defun mime-find-file-type (file)
1303 "Guess Content-Type, subtype, and parameters from FILE."
1305 (guesses mime-file-types))
1306 (while (and (not guess) guesses)
1307 (if (string-match (car (car guesses)) file)
1308 (setq guess (cdr (car guesses))))
1309 (setq guesses (cdr guesses)))
1313 (defun mime-prompt-for-type ()
1314 "Ask for Content-type."
1316 ;; Repeat until primary content type is specified.
1317 (while (string-equal type "")
1319 (completing-read "What content type: "
1322 'require-match ;Type must be specified.
1325 (if (string-equal type "")
1327 (message "Content type is required.")
1335 (defun mime-prompt-for-subtype (pritype)
1336 "Ask for Content-type subtype of Content-Type PRITYPE."
1337 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1342 "What content subtype: (default " default ") ")
1343 "What content subtype: ")
1344 (cdr (assoc pritype mime-content-types))
1346 'require-match ;Subtype must be specified.
1349 (if (string-equal answer "") default answer)))
1351 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1352 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1353 Optional DELIMITER specifies parameter delimiter (';' by default)."
1354 (let* ((delimiter (or delimiter "; "))
1359 (mime-prompt-for-parameters-1
1361 (cdr (assoc pritype mime-content-types))))))
1364 (if (and (stringp parameters)
1365 (not (string-equal parameters "")))
1366 (concat delimiter parameters)
1367 "" ;"" if no parameters
1370 (defun mime-prompt-for-parameters-1 (optlist)
1371 (apply (function append)
1372 (mapcar (function mime-prompt-for-parameter) optlist)))
1374 (defun mime-prompt-for-parameter (parameter)
1376 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1377 (let* ((prompt (car parameter))
1378 (choices (mapcar (function
1380 (if (consp e) e (list e))))
1382 (default (car (car choices)))
1388 (concat "What " prompt
1390 (if (string-equal default "") "\"\"" default)
1392 choices nil nil ""))
1393 ;; If nothing is selected, use default.
1394 (if (string-equal answer "")
1395 (setq answer default)))
1397 (read-string (concat "What " prompt ": "))))
1398 (cons (if (and answer
1399 (not (string-equal answer "")))
1401 ;; Note: control characters ignored!
1402 (if (string-match mime-tspecials-regexp answer)
1403 (concat "\"" answer "\"") answer)))
1404 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1407 (defun mime-flag-region (from to flag)
1408 "Hides or shows lines from FROM to TO, according to FLAG.
1409 If FLAG is `\\n' (newline character) then text is shown,
1410 while if FLAG is `\\^M' (control-M) the text is hidden."
1411 (let ((buffer-read-only nil) ;Okay even if write protected.
1412 (modp (buffer-modified-p)))
1414 (subst-char-in-region from to
1415 (if (= flag ?\n) ?\^M ?\n)
1417 (set-buffer-modified-p modp))))
1420 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1423 (defvar mime-editor/translate-buffer-hook
1424 '(mime-editor/pgp-enclose-buffer
1425 mime/encode-message-header
1426 mime-editor/translate-body))
1428 (defun mime-editor/translate-buffer ()
1429 "Encode the tagged MIME message in current buffer in MIME compliant message."
1431 (if (catch 'mime-editor/error
1433 (run-hooks 'mime-editor/translate-buffer-hook)
1437 (error "Translation error!")
1440 (defun mime-editor/find-inmost ()
1441 (goto-char (point-min))
1442 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1443 (let ((bb (match-beginning 0))
1445 (type (buffer-substring (match-beginning 1)(match-end 1)))
1447 (setq end-exp (format "--}-<<%s>>\n" type))
1449 (if (re-search-forward end-exp nil t)
1451 (setq eb (match-beginning 0))
1452 (setq ee (match-end 0))
1454 (setq eb (point-max))
1455 (setq ee (point-max))
1457 (narrow-to-region be eb)
1459 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1461 (narrow-to-region (match-beginning 0)(point-max))
1462 (mime-editor/find-inmost)
1465 (list type bb be eb)
1468 (defun mime-editor/process-multipart-1 (boundary)
1469 (let ((ret (mime-editor/find-inmost)))
1471 (let ((type (car ret))
1472 (bb (nth 1 ret))(be (nth 2 ret))
1475 (narrow-to-region bb eb)
1476 (delete-region bb be)
1477 (setq bb (point-min))
1478 (setq eb (point-max))
1481 (if (looking-at mime-editor/multipart-end-regexp)
1482 (let ((beg (match-beginning 0))
1485 (delete-region beg end)
1486 (or (looking-at mime-editor/beginning-tag-regexp)
1488 (insert (concat (mime-make-text-tag) "\n"))
1490 (cond ((string-equal type "quote")
1491 (mime-editor/enquote-region bb eb)
1493 ((string-equal type "signed")
1494 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1495 (mime-editor/sign-pgp-elkins bb eb boundary)
1497 ((eq mime-editor/signing-type 'pgp-kazu)
1498 (mime-editor/sign-pgp-kazu bb eb boundary)
1501 ((string-equal type "encrypted")
1502 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1503 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1505 ((eq mime-editor/encrypting-type 'pgp-kazu)
1506 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1510 (nth 2 (mime-editor/translate-region bb eb
1514 (format "--[[multipart/%s;
1515 boundary=\"%s\"][7bit]]\n"
1520 (defun mime-editor/enquote-region (beg end)
1523 (narrow-to-region beg end)
1525 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1526 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1527 (replace-match (concat "- " (substring tag 1)))
1530 (defun mime-editor/dequote-region (beg end)
1533 (narrow-to-region beg end)
1535 (while (re-search-forward
1536 mime-editor/quoted-single-part-tag-regexp nil t)
1537 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1538 (replace-match (concat "-" (substring tag 2)))
1541 (autoload 'mc-pgp-lookup-key "mc-pgp")
1542 (autoload 'mc-pgp-sign-region "mc-pgp")
1543 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1545 (defun tm:mc-pgp-generic-parser (result)
1546 (let ((ret (mc-pgp-generic-parser result)))
1548 (vector (car ret)(cdr ret))
1551 (defun tm:mc-process-region
1552 (beg end passwd program args parser &optional buffer boundary)
1553 (let ((obuf (current-buffer))
1554 (process-connection-type nil)
1555 mybuf result rgn proc)
1558 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1562 (buffer-disable-undo mybuf)
1564 (apply 'start-process "*PGP*" mybuf program args))
1567 (process-send-string proc (concat passwd "\n"))
1568 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1569 (process-send-region proc beg end)
1570 (process-send-eof proc)
1571 (while (eq 'run (process-status proc))
1572 (accept-process-output proc 5))
1573 (setq result (process-exit-status proc))
1574 ;; Hack to force a status_notify() in Emacs 19.29
1575 (delete-process proc)
1577 (goto-char (point-max))
1578 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1579 (delete-region (match-beginning 0) (match-end 0)))
1580 (goto-char (point-min))
1582 (while (search-forward "\r\n" nil t)
1583 (replace-match "\n"))
1584 ;; Hurm. FIXME; must get better result codes.
1585 (if (stringp result)
1586 (error "%s exited abnormally: '%s'" program result)
1587 (setq rgn (funcall parser result))
1588 ;; If the parser found something, migrate it
1594 (narrow-to-region beg end)
1596 (insert (format "--%s\n" boundary))
1597 (goto-char (point-max))
1598 (insert (format "\n--%s
1599 Content-Type: application/pgp-signature
1600 Content-Transfer-Encoding: 7bit
1603 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1604 (goto-char (point-max))
1605 (insert (format "\n--%s--\n" boundary))
1607 (delete-region beg end)
1609 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1612 (delete-region (car rgn) (cdr rgn)))))
1613 ;; Return nil on failure and exit code on success
1615 ;; Cleanup even on nonlocal exit
1616 (if (and proc (eq 'run (process-status proc)))
1617 (interrupt-process proc))
1619 (or buffer (null mybuf) (kill-buffer mybuf)))))
1621 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1622 (if (not (boundp 'mc-pgp-user-id))
1625 (let ((process-environment process-environment)
1626 (buffer (get-buffer-create mc-buffer-name))
1628 (parser (function mc-pgp-generic-parser))
1629 (pgp-path mc-pgp-path)
1631 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1635 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1636 (setenv "PGPPASSFD" "0")
1642 (list "+verbose=1" "+language=en"
1643 (format "+clearsig=%s" (if unclear "off" "on"))
1644 "+batchmode" "-u" (cdr key))))
1646 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1648 (message "Signing as %s ..." (car key))
1649 (if (tm:mc-process-region
1650 start end passwd pgp-path args parser buffer boundary)
1654 (goto-char (point-min))
1657 --[[multipart/signed; protocol=\"application/pgp-signature\";
1658 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1660 (message "Signing as %s ... Done." (car key))
1664 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1667 (narrow-to-region beg end)
1669 (mime-editor/translate-region beg end boundary))
1671 (encoding (nth 1 ret))
1673 (pgp-boundary (concat "pgp-sign-" boundary))
1676 (insert (format "Content-Type: %s\n" ctype))
1678 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1681 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1682 nil nil pgp-boundary)
1683 (throw 'mime-editor/error 'pgp-error)
1687 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1690 (let ((from (rfc822/get-field-body "From"))
1691 (to (rfc822/get-field-body "To"))
1692 (cc (rfc822/get-field-body "cc"))
1694 (narrow-to-region beg end)
1696 (mime-editor/translate-region beg end boundary))
1698 (encoding (nth 1 ret))
1700 (pgp-boundary (concat "pgp-" boundary))
1703 (if (and (stringp from)
1704 (not (string-equal from "")))
1705 (insert (format "From: %s\n" from))
1707 (if (and (stringp to)
1708 (not (string-equal to "")))
1710 (insert (format "To: %s\n" to))
1711 (setq recipients to)
1713 (if (and (stringp cc)
1714 (not (string-equal cc "")))
1716 (insert (format "cc: %s\n" cc))
1718 (setq recipients (concat recipients "," cc))
1719 (setq recipients cc)
1721 (insert (format "Content-Type: %s\n" ctype))
1723 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1727 (let ((mc-pgp-always-sign 'never))
1728 (mc-pgp-encrypt-region
1729 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1730 (point-min) (point-max) from nil)
1732 (throw 'mime-editor/error 'pgp-error)
1735 (insert (format "--[[multipart/encrypted;
1737 protocol=\"application/pgp-encrypted\"][7bit]]
1739 Content-Type: application/pgp-encrypted
1742 Content-Type: application/octet-stream
1743 Content-Transfer-Encoding: 7bit
1745 " pgp-boundary pgp-boundary pgp-boundary))
1746 (goto-char (point-max))
1747 (insert (format "\n--%s--\n" pgp-boundary))
1750 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1753 (narrow-to-region beg end)
1755 (mime-editor/translate-region beg end boundary))
1757 (encoding (nth 1 ret))
1761 (insert (format "Content-Type: %s\n" ctype))
1763 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1766 (or (as-binary-process (mc-pgp-sign-region beg (point-max)))
1767 (throw 'mime-editor/error 'pgp-error)
1771 "--[[application/pgp; format=mime][7bit]]\n")
1775 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1777 (let ((from (rfc822/get-field-body "From"))
1778 (to (rfc822/get-field-body "To"))
1779 (cc (rfc822/get-field-body "cc"))
1782 (narrow-to-region beg end)
1784 (mime-editor/translate-region beg end boundary))
1786 (encoding (nth 1 ret))
1790 (if (and (stringp from)
1791 (not (string-equal from "")))
1792 (insert (format "From: %s\n" from))
1794 (if (and (stringp to)
1795 (not (string-equal to "")))
1797 (insert (format "To: %s\n" to))
1798 (setq recipients to)
1800 (if (and (stringp cc)
1801 (not (string-equal cc "")))
1803 (insert (format "cc: %s\n" cc))
1805 (setq recipients (concat recipients "," cc))
1806 (setq recipients cc)
1808 (insert (format "Content-Type: %s\n" ctype))
1810 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1813 (or (as-binary-process
1814 (mc-pgp-encrypt-region
1815 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1818 (throw 'mime-editor/error 'pgp-error)
1822 "--[[application/pgp; format=mime][7bit]]\n")
1826 (defun mime-editor/translate-body ()
1827 "Encode the tagged MIME body in current buffer in MIME compliant message."
1831 (concat mime-multipart-boundary "_"
1832 (replace-space-with-underline (current-time-string))
1836 (while (mime-editor/process-multipart-1
1837 (format "%s-%d" boundary i))
1841 ;; We are interested in message body.
1844 (goto-char (point-min))
1846 (concat "\n" (regexp-quote mail-header-separator)
1847 (if mime-ignore-preceding-spaces
1848 "[ \t\n]*\n" "\n")) nil 'move)
1852 (goto-char (point-max))
1853 (and mime-ignore-trailing-spaces
1854 (re-search-backward "[^ \t\n]\n" beg t)
1857 (setq ret (mime-editor/translate-region
1859 (format "%s-%d" boundary i)))
1861 (mime-editor/dequote-region (point-min)(point-max))
1862 (let ((contype (car ret)) ;Content-Type
1863 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1865 ;; Make primary MIME headers.
1866 (or (mail-position-on-field "Mime-Version")
1867 (insert mime-editor/mime-version-value))
1868 ;; Remove old Content-Type and other fields.
1870 (goto-char (point-min))
1871 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1872 (narrow-to-region (point-min) (point))
1873 (goto-char (point-min))
1874 (mime-delete-field "Content-Type")
1875 (mime-delete-field "Content-Transfer-Encoding"))
1876 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1877 (mail-position-on-field "Content-Type")
1881 (mail-position-on-field "Content-Transfer-Encoding")
1885 (defun mime-editor/translate-single-part-tag (&optional prefix)
1886 (if (re-search-forward mime-editor/single-part-tag-regexp nil t)
1887 (let* ((beg (match-beginning 0))
1889 (tag (buffer-substring beg end))
1891 (delete-region beg end)
1892 (setq contype (mime-editor/get-contype tag))
1893 (setq encoding (mime-editor/get-encoding tag))
1894 (insert (concat prefix "--" boundary "\n"))
1896 (narrow-to-region (point)(point))
1897 (insert "Content-Type: " contype "\n")
1899 (insert "Content-Transfer-Encoding: " encoding "\n"))
1900 (mime/encode-message-header)
1904 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1907 (concat mime-multipart-boundary "_"
1908 (replace-space-with-underline (current-time-string))))
1912 (narrow-to-region beg end)
1913 (let ((tag nil) ;MIME tag
1914 (contype nil) ;Content-Type
1915 (encoding nil) ;Content-Transfer-Encoding
1916 (nparts 0)) ;Number of body parts
1917 ;; Normalize the body part by inserting appropriate message
1918 ;; tags for every message contents.
1919 (mime-editor/normalize-body)
1920 ;; Counting the number of Content-Type.
1921 (goto-char (point-min))
1922 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1923 (setq nparts (1+ nparts)))
1924 ;; Begin translation.
1926 ((and (<= nparts 1)(not multipart))
1927 ;; It's a singular message.
1928 (goto-char (point-min))
1929 (while (re-search-forward
1930 mime-editor/single-part-tag-regexp nil t)
1932 (buffer-substring (match-beginning 0) (match-end 0)))
1933 (delete-region (match-beginning 0) (1+ (match-end 0)))
1934 (setq contype (mime-editor/get-contype tag))
1935 (setq encoding (mime-editor/get-encoding tag))
1938 ;; It's a multipart message.
1939 (goto-char (point-min))
1940 (and (mime-editor/translate-single-part-tag)
1941 (while (mime-editor/translate-single-part-tag "\n"))
1943 ;; Define Content-Type as "multipart/mixed".
1945 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1946 ;; Content-Transfer-Encoding must be "7bit".
1947 ;; The following encoding can be `nil', but is
1948 ;; specified as is since there is no way that a user
1950 (setq encoding "7bit")
1951 ;; Insert the trailer.
1952 (goto-char (point-max))
1953 (insert "\n--" boundary "--\n")
1955 (list contype encoding boundary nparts)
1958 (defun mime-editor/normalize-body ()
1959 "Normalize the body part by inserting appropriate message tags."
1960 ;; Insert the first MIME tags if necessary.
1961 (goto-char (point-min))
1962 (if (not (looking-at mime-editor/single-part-tag-regexp))
1963 (insert (mime-make-text-tag) "\n"))
1964 ;; Check each tag, and add new tag or correct it if necessary.
1965 (goto-char (point-min))
1966 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1967 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1968 (contype (mime-editor/get-contype tag))
1969 (charset (mime-get-parameter contype "charset"))
1970 (encoding (mime-editor/get-encoding tag)))
1971 ;; Remove extra whitespaces after the tag.
1972 (if (looking-at "[ \t]+$")
1973 (delete-region (match-beginning 0) (match-end 0)))
1975 (end (mime-editor/content-end))
1978 (or (looking-at mime-editor/beginning-tag-regexp)
1980 (insert (mime-make-text-tag) "\n")
1982 (visible-region beg end)
1986 ((mime-test-content-type contype "message")
1987 ;; Content-type "message" should be sent as is.
1990 ((mime-test-content-type contype "text")
1991 ;; Define charset for text if necessary.
1992 (setq charset (if charset
1993 (intern (downcase charset))
1994 (mime-editor/choose-charset)))
1995 (mime-editor/define-charset charset)
1996 (cond ((string-equal contype "text/x-rot13-47")
2000 (goto-char (mime-editor/content-end))
2003 ((string-equal contype "text/enriched")
2008 (end (mime-editor/content-end))
2010 (enriched-encode beg end)
2012 (if (search-forward "\n\n")
2013 (delete-region beg (match-end 0))
2016 ;; Point is now on current tag.
2017 ;; Define encoding and encode text if necessary.
2018 (or encoding ;Encoding is not specified.
2022 mime-editor/charset-default-encoding-alist)
2024 (beg (mime-editor/content-beginning))
2026 (encode-mime-charset-region beg (mime-editor/content-end)
2028 (mime-encode-region beg (mime-editor/content-end) encoding)
2029 (mime-editor/define-encoding encoding)
2031 (goto-char (mime-editor/content-end))
2033 ((null encoding) ;Encoding is not specified.
2034 ;; Application, image, audio, video, and any other
2035 ;; unknown content-type without encoding should be
2037 (let* ((encoding "base64") ;Encode in BASE64 by default.
2038 (beg (mime-editor/content-beginning))
2039 (end (mime-editor/content-end))
2040 (body (buffer-substring beg end))
2042 (mime-encode-region beg end encoding)
2043 (mime-editor/define-encoding encoding))
2048 (defun mime-delete-field (field)
2049 "Delete header FIELD."
2050 (let ((regexp (format "^%s:[ \t]*" field)))
2051 (goto-char (point-min))
2052 (while (re-search-forward regexp nil t)
2053 (delete-region (match-beginning 0)
2054 (progn (forward-line 1) (point)))
2059 ;;; Platform dependent functions
2062 ;; Sun implementations
2064 (defun mime-voice-recorder-for-sun ()
2065 "Record voice in a buffer using Sun audio device, and return the buffer.
2066 If the environment variable AUDIOHOST is defined, its value is used as
2067 a recording host instead of local host."
2068 (let ((buffer (get-buffer-create " *MIME audio*"))
2069 (host (getenv "AUDIOHOST")))
2070 (message "Start the recording on %s. Type C-g to finish the recording..."
2071 (or host (system-name)))
2075 (condition-case errorcode
2076 (let ((selective-display nil) ;Disable ^M to nl translation.
2078 (kanji-flag nil)) ;NEmacs
2079 ;; If AUDIOHOST is defined, use the value as recording host.
2080 (cond ((not (null host))
2081 ;; Disable automatic conversion of coding system if Mule.
2082 (if (featurep 'mule)
2083 (define-program-coding-system nil "rsh" *noconv*))
2093 ;; Disable automatic conversion of coding system if Mule.
2094 (if (featurep 'mule)
2095 (define-program-coding-system nil "cat" *noconv*))
2101 (quit (message "Type C-g to finish recording... done.")
2102 buffer ;Return the buffer
2106 ;;; @ Other useful commands.
2109 ;; Message forwarding commands as content-type "message/rfc822".
2111 (defun mime-editor/insert-message (&optional message)
2113 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2114 (if (and inserter (fboundp inserter))
2116 (mime-editor/insert-tag "message" "rfc822")
2117 (funcall inserter message)
2119 (message "Sorry, I don't have message inserter for your MUA.")
2122 (defun mime-editor/insert-mail (&optional message)
2124 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2125 (if (and inserter (fboundp inserter))
2127 (mime-editor/insert-tag "message" "rfc822")
2128 (funcall inserter message)
2130 (message "Sorry, I don't have mail inserter for your MUA.")
2133 (defun mime-editor/inserted-message-filter ()
2136 (let ((header-start (point))
2137 (case-fold-search t)
2140 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2141 (if (re-search-forward "^$" (mark t))
2142 (narrow-to-region header-start (match-beginning 0))
2144 (goto-char header-start)
2145 (while (and (re-search-forward
2146 mime-editor/yank-ignored-field-regexp nil t)
2147 (setq beg (match-beginning 0))
2148 (setq end (1+ (rfc822/field-end)))
2150 (delete-region beg end)
2155 ;;; @ multipart enclosure
2158 (defun mime-editor/enclose-region (type beg end)
2161 (let ((current (point)))
2163 (narrow-to-region beg end)
2164 (insert (format "--<<%s>>-{\n" type))
2165 (goto-char (point-max))
2166 (insert (format "--}-<<%s>>\n" type))
2167 (goto-char (point-max))
2169 (or (looking-at mime-editor/beginning-tag-regexp)
2171 (insert (mime-make-text-tag) "\n")
2175 (defun mime-editor/enclose-quote-region (beg end)
2177 (mime-editor/enclose-region "quote" beg end)
2180 (defun mime-editor/enclose-mixed-region (beg end)
2182 (mime-editor/enclose-region "mixed" beg end)
2185 (defun mime-editor/enclose-parallel-region (beg end)
2187 (mime-editor/enclose-region "parallel" beg end)
2190 (defun mime-editor/enclose-digest-region (beg end)
2192 (mime-editor/enclose-region "digest" beg end)
2195 (defun mime-editor/enclose-alternative-region (beg end)
2197 (mime-editor/enclose-region "alternative" beg end)
2200 (defun mime-editor/enclose-signed-region (beg end)
2202 (if mime-editor/signing-type
2203 (mime-editor/enclose-region "signed" beg end)
2204 (message "Please specify signing type.")
2207 (defun mime-editor/enclose-encrypted-region (beg end)
2209 (if mime-editor/signing-type
2210 (mime-editor/enclose-region "encrypted" beg end)
2211 (message "Please specify encrypting type.")
2214 (defun mime-editor/insert-key (&optional arg)
2215 "Insert a pgp public key."
2217 (mime-editor/insert-tag "application" "pgp-keys")
2218 (mime-editor/define-encoding "7bit")
2219 (mc-insert-public-key)
2226 (defun mime-editor/set-split (arg)
2229 (y-or-n-p "Do you want to enable split?")
2231 (setq mime-editor/split-message arg)
2233 (message "This message is enabled to split.")
2234 (message "This message is not enabled to split.")
2237 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2238 "Toggle transfer-level is 7bit or 8bit through.
2240 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2242 (if (numberp transfer-level)
2243 (setq mime-editor/transfer-level transfer-level)
2244 (if (< mime-editor/transfer-level 8)
2245 (setq mime-editor/transfer-level 8)
2246 (setq mime-editor/transfer-level 7)
2248 (setq mime-editor/charset-default-encoding-alist
2249 (mime-editor/make-charset-default-encoding-alist
2250 mime-editor/transfer-level))
2251 (message (format "Current transfer-level is %d bit"
2252 mime-editor/transfer-level))
2253 (setq mime-editor/transfer-level-string
2254 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2255 (force-mode-line-update)
2262 (defun mime-editor/set-sign (arg)
2265 (y-or-n-p "Do you want to sign?")
2268 (if mime-editor/signing-type
2270 (setq mime-editor/pgp-processing 'sign)
2271 (message "This message will be signed.")
2273 (message "Please specify signing type.")
2275 (if (eq mime-editor/pgp-processing 'sign)
2276 (setq mime-editor/pgp-processing nil)
2278 (message "This message will not be signed.")
2281 (defun mime-editor/set-encrypt (arg)
2284 (y-or-n-p "Do you want to encrypt?")
2287 (if mime-editor/encrypting-type
2289 (setq mime-editor/pgp-processing 'encrypt)
2290 (message "This message will be encrypt.")
2292 (message "Please specify encrypting type.")
2294 (if (eq mime-editor/pgp-processing 'encrypt)
2295 (setq mime-editor/pgp-processing nil)
2297 (message "This message will not be encrypt.")
2300 (defvar mime-editor/pgp-processing nil)
2301 (make-variable-buffer-local 'mime-editor/pgp-processing)
2303 (defun mime-editor/pgp-enclose-buffer ()
2304 (let ((beg (save-excursion
2305 (goto-char (point-min))
2306 (if (search-forward (concat "\n" mail-header-separator "\n"))
2312 (cond ((eq mime-editor/pgp-processing 'sign)
2313 (mime-editor/enclose-signed-region beg end)
2315 ((eq mime-editor/pgp-processing 'encrypt)
2316 (mime-editor/enclose-encrypted-region beg end)
2324 (defun mime-editor/insert-partial-header
2325 (fields subject id number total separator)
2327 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2328 (insert (format "Mime-Version: 1.0 (split by %s)\n"
2329 mime-editor/version-name))
2331 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2332 id number total separator))
2335 (defun mime-editor/split-and-send
2336 (&optional cmd lines mime-editor/message-max-length)
2340 (count-lines (point-min) (point-max)))
2342 (or mime-editor/message-max-length
2343 (setq mime-editor/message-max-length
2344 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2345 mime-editor/message-default-max-length))
2347 (let* ((mime-editor/draft-file-name
2348 (or (buffer-file-name)
2350 (expand-file-name "tm-draft" mime/tmp-dir))))
2351 (separator mail-header-separator)
2353 (replace-space-with-underline (current-time-string))
2354 "@" (system-name) "\"")))
2355 (run-hooks 'mime-editor/before-split-hook)
2356 (let ((the-buf (current-buffer))
2357 (copy-buf (get-buffer-create " *Original Message*"))
2358 (header (rfc822/get-header-string-except
2359 mime-editor/split-ignored-field-regexp separator))
2360 (subject (mail-fetch-field "subject"))
2361 (total (+ (/ lines mime-editor/message-max-length)
2362 (if (> (mod lines mime-editor/message-max-length) 0)
2368 mime-editor/split-message-sender-alist))
2370 (mime-editor/partial-number 1)
2373 (set-buffer copy-buf)
2375 (insert-buffer the-buf)
2377 (if (re-search-forward
2378 (concat "^" (regexp-quote separator) "$") nil t)
2379 (let ((he (match-beginning 0)))
2381 (narrow-to-region (point-min) he)
2383 (goto-char (point-min))
2384 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
2385 (delete-region (match-beginning 0)
2386 (1+ (rfc822/field-end)))
2388 (while (< mime-editor/partial-number total)
2391 (set-buffer copy-buf)
2392 (setq data (buffer-substring
2395 (goto-line mime-editor/message-max-length)
2398 (delete-region (point-min)(point))
2400 (mime-editor/insert-partial-header
2401 header subject id mime-editor/partial-number total separator)
2404 (message (format "Sending %d/%d..."
2405 mime-editor/partial-number total))
2406 (call-interactively command)
2407 (message (format "Sending %d/%d... done"
2408 mime-editor/partial-number total))
2410 (setq mime-editor/partial-number
2411 (1+ mime-editor/partial-number))
2415 (set-buffer copy-buf)
2416 (setq data (buffer-string))
2419 (mime-editor/insert-partial-header
2420 header subject id mime-editor/partial-number total separator)
2423 (message (format "Sending %d/%d..."
2424 mime-editor/partial-number total))
2425 (message (format "Sending %d/%d... done"
2426 mime-editor/partial-number total))
2430 (defun mime-editor/maybe-split-and-send (&optional cmd)
2432 (run-hooks 'mime-editor/before-send-hook)
2433 (let ((mime-editor/message-max-length
2434 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2435 mime-editor/message-default-max-length))
2436 (lines (count-lines (point-min) (point-max)))
2438 (if (and (> lines mime-editor/message-max-length)
2439 mime-editor/split-message)
2440 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2444 ;;; @ preview message
2447 (defun mime-editor/preview-message ()
2448 "preview editing MIME message. [tm-edit.el]"
2450 (let* ((str (buffer-string))
2451 (separator mail-header-separator)
2452 (the-buf (current-buffer))
2453 (buf-name (buffer-name))
2454 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2455 (buf (get-buffer temp-buf-name))
2459 (switch-to-buffer buf)
2462 (setq buf (get-buffer-create temp-buf-name))
2463 (switch-to-buffer buf)
2466 (setq major-mode 'mime/temporary-message-mode)
2467 (make-local-variable 'mail-header-separator)
2468 (setq mail-header-separator separator)
2469 (make-local-variable 'mime/editing-buffer)
2470 (setq mime/editing-buffer the-buf)
2472 (run-hooks 'mime-editor/translate-hook)
2473 (mime-editor/translate-buffer)
2474 (goto-char (point-min))
2475 (if (re-search-forward
2476 (concat "^" (regexp-quote separator) "$"))
2482 (defun mime-editor/quitting-method ()
2483 (let ((temp mime::preview/article-buffer)
2485 (mime-viewer/kill-buffer)
2487 (setq buf mime/editing-buffer)
2489 (switch-to-buffer buf)
2492 (set-alist 'mime-viewer/quitting-method-alist
2493 'mime/temporary-message-mode
2494 (function mime-editor/quitting-method)
2500 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2501 ;; Mon, 10 Apr 1995 20:03:07 +0900
2503 (defvar mime-editor/draft-header-separator-alist
2504 '((news-reply-mode . mail-header-separator)
2505 (mh-letter-mode . mail-header-separator)
2508 (defvar mime::article/draft-header-separator nil)
2510 (defun mime-editor/draft-preview ()
2512 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2513 (or (stringp sep) (setq sep (eval sep)))
2514 (make-variable-buffer-local 'mime::article/draft-header-separator)
2515 (goto-char (point-min))
2517 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2518 (setq mime::article/draft-header-separator
2519 (buffer-substring (match-beginning 0) (match-end 0)))
2521 (mime/viewer-mode (current-buffer))
2522 (pop-to-buffer (current-buffer))
2525 (defun mime-viewer::quitting-method/draft-preview ()
2526 (let ((mother mime::preview/mother-buffer))
2528 (switch-to-buffer mother)
2529 (goto-char (point-min))
2533 (regexp-quote mime::article/draft-header-separator)
2537 (insert mime::article/draft-header-separator)
2538 (set-buffer-modified-p (buffer-modified-p))
2540 (mime-viewer/kill-buffer)
2541 (pop-to-buffer mother)
2544 (set-alist 'mime-viewer/quitting-method-alist
2546 (function mime-viewer::quitting-method/draft-preview)
2549 (set-alist 'mime-viewer/quitting-method-alist
2551 (function mime-viewer::quitting-method/draft-preview)
2558 (defun mime-editor::edit-again (code-conversion)
2560 (goto-char (point-min))
2561 (let ((ctl (mime/Content-Type)))
2563 (let ((ctype (car ctl))
2566 (if (string-match "/" ctype)
2568 (setq type (substring ctype 0 (match-beginning 0)))
2569 (setq stype (substring ctype (match-end 0)))
2574 ((string-equal type "multipart")
2575 (let* ((boundary (assoc-value "boundary" params))
2577 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2579 (re-search-forward boundary-pat nil t)
2580 (let ((bb (match-beginning 0)) eb tag)
2581 (setq tag (format "\n--<<%s>>-{\n" stype))
2584 (setq bb (+ bb (length tag)))
2586 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2588 (setq eb (match-beginning 0))
2589 (replace-match (format "--}-<<%s>>\n" stype))
2591 (narrow-to-region bb eb)
2592 (goto-char (point-min))
2593 (while (re-search-forward boundary-pat nil t)
2594 (let ((beg (match-beginning 0))
2596 (delete-region beg (match-end 0))
2598 (if (re-search-forward boundary-pat nil t)
2599 (setq end (match-beginning 0))
2600 (setq end (point-max))
2603 (narrow-to-region beg end)
2604 (mime-editor::edit-again code-conversion)
2605 (goto-char (point-max))
2608 (goto-char (point-min))
2609 (or (= (point-min) 1)
2610 (delete-region (point-min)
2611 (if (search-forward "\n\n" nil t)
2619 (mapconcat (function
2621 (if (string-equal (car attr)
2624 (setq charset (cdr attr))
2626 (concat ";" (car attr)
2634 (if (re-search-forward
2635 "Content-Transfer-Encoding:" nil t)
2636 (let ((beg (match-beginning 0))
2637 (hbeg (match-end 0))
2638 (end (rfc822/field-end)))
2640 (eliminate-top-spaces
2641 (rfc822/unfolding-string
2642 (buffer-substring hbeg end))))
2643 (if (or charset (string-equal type "text"))
2645 (delete-region beg (1+ end))
2646 (goto-char (point-min))
2647 (if (search-forward "\n\n" nil t)
2650 (match-end 0)(point-max) encoding)
2654 (if (or code-conversion encoded)
2655 (decode-mime-charset-region
2656 (point-min)(point-max)
2657 (or charset default-mime-charset))
2660 (if (re-search-forward "^$" nil t)
2664 (if (= (point-min) 1)
2670 (concat type "/" stype pstr) encoding)))
2672 (delete-region (point-min) he)
2675 (concat type "/" stype pstr) encoding))
2679 (decode-mime-charset-region (point-min) (point-max)
2680 default-mime-charset)
2684 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2686 (mime-editor::edit-again code-conversion)
2687 (goto-char (point-min))
2691 (if (re-search-forward
2692 (concat "^\\(" (regexp-quote mail-header-separator) "\\)?$")
2697 (goto-char (point-min))
2698 (while (re-search-forward
2699 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2700 (delete-region (match-beginning 0) (1+ (rfc822/field-end)))
2703 (and (re-search-forward "^$")
2704 (replace-match mail-header-separator)
2716 (run-hooks 'tm-edit-load-hook)
2718 ;;; tm-edit.el ends here