2 ;;; tm-edit.el --- Simple MIME Composer for GNU Emacs
4 ;;; Copyright (C) 1993 UMEDA Masanobu
5 ;;; Copyright (C) 1994,1995 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.41 $
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.41 1996/01/18 17:49:17 morioka Exp $")
127 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
133 (defvar mime-prefix "\C-c\C-x"
134 "*Keymap prefix for MIME commands.")
136 (defvar mime-signature-file "~/.signature.rtf"
137 "*Signature file to be included as a part of a multipart message.")
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-string-encoder
153 (cond ((boundp 'NEMACS)
154 (function mime-string-encoder-for-nemacs))
156 (function mime-string-encoder-for-mule))
157 ((string-match "^19\\." emacs-version)
158 (function mime-string-encoder-for-emacs19))
160 (function mime-string-encoder-for-emacs18)))
161 "*Function to encode a string for given encoding method.
162 The method is a form of (CHARSET . ENCODING).")
164 (defvar mime-voice-recorder
165 (function mime-voice-recorder-for-sun)
166 "*Function to record a voice message and return a buffer that contains it.")
168 (defvar mime/editor-mode-hook nil
169 "*Hook called when enter MIME mode.")
171 (defvar mime-editor/translate-hook nil
172 "*Hook called before translating into a MIME compliant message.
173 To insert a signature file specified by mime-signature-file
174 (`.signature.rtf' by default) automatically, call the function
175 `mime-editor/insert-signature' from this hook.")
177 (defvar mime-editor/exit-hook nil
178 "*Hook called when exit MIME mode.")
180 (defvar mime-content-types
182 ;; Charset parameter need not to be specified, since it is
183 ;; defined automatically while translation.
185 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
188 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
191 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
194 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
197 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
205 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
206 ("directory" "/pub/GNU/elisp/mime")
208 ("mode" "image" "ascii" "local8"))
213 ("mode" "image" "ascii" "local8"))
214 ("tftp" ("site") ("name"))
215 ("afs" ("site") ("name"))
216 ("local-file" ("site") ("name"))
217 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
222 ("octet-stream" ("type" "" "tar" "shar"))
224 ("x-kiss" ("x-cnf")))
237 "*Alist of content-type, subtype, parameters and its values.")
239 (defvar mime-file-types
241 "text" "richtext" nil
249 "application" "postscript" nil
251 "attachment" (("filename" . file))
256 "inline" (("filename" . file))
261 "inline" (("filename" . file))
266 "inline" (("filename" . file))
271 "inline" (("filename" . file))
276 "inline" (("filename" . file))
281 "inline" (("filename" . file))
286 "inline" (("filename" . file))
291 "attachment" (("filename" . file))
296 "attachment" (("filename" . file))
299 "application" "octet-stream" (("type" . "emacs-lisp"))
301 "attachment" (("filename" . file))
304 "application" "octet-stream" (("type" . "common-lisp"))
306 "attachment" (("filename" . file))
309 "application" "octet-stream" (("type" . "tar+gzip"))
311 "attachment" (("filename" . file))
314 "application" "octet-stream" (("type" . "tar+gzip"))
316 "attachment" (("filename" . file))
319 "application" "octet-stream" (("type" . "tar+compress"))
321 "attachment" (("filename" . file))
324 "application" "octet-stream" (("type" . "tar+compress"))
326 "attachment" (("filename" . file))
329 "application" "octet-stream" (("type" . "gzip"))
331 "attachment" (("filename" . file))
334 "application" "octet-stream" (("type" . "compress"))
336 "attachment" (("filename" . file))
339 "application" "octet-stream" (("type" . "lha"))
341 "attachment" (("filename" . file))
344 "application" "zip" nil
346 "attachment" (("filename" . file))
349 "application" "octet-stream" (("type" . "patch"))
351 "attachment" (("filename" . file))
354 "text" "plain" nil nil)
356 "application" "octet-stream" nil
358 "attachment" (("filename" . file))
361 "*Alist of file name, types, parameters, and default encoding.
362 If encoding is nil, it is determined from its contents.")
364 ;;; @@ about message inserting
367 (defvar mime-editor/yank-ignored-field-list
368 '("Received" "Sender" "Approved" "Path" "Status" "X-VM-.*" "X-UIDL")
369 "Delete these fields from original message when it is inserted
370 as message/rfc822 part.
371 Each elements are regexp of field-name. [tm-edit.el]")
373 (defvar mime-editor/yank-ignored-field-regexp
375 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
378 (defvar mime-editor/message-inserter-alist nil)
379 (defvar mime-editor/mail-inserter-alist nil)
381 ;;; @@ about message splitting
384 (defvar mime-editor/split-message t
385 "*Split large message if it is non-nil. [tm-edit.el]")
387 (defvar mime-editor/message-default-max-length 1000
388 "*Default maximum size of a message. [tm-edit.el]")
390 (defvar mime-editor/message-max-length-alist
391 '((news-reply-mode . 500)))
393 (defconst mime-editor/split-ignored-field-regexp
394 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
396 (defvar mime-editor/split-blind-field-regexp
397 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
399 (defvar mime-editor/message-default-sender-alist
400 '((mail-mode . mail-send-and-exit)
401 (mh-letter-mode . mh-send-letter)
402 (news-reply-mode . gnus-inews-news)
405 (defvar mime-editor/split-message-sender-alist
412 . (lambda (&optional arg)
414 (write-region (point-min) (point-max)
415 mime-editor/draft-file-name nil 'no-message)
417 (pop-to-buffer "MH mail delivery")
419 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
421 mh-send-args mime-editor/draft-file-name)
422 (goto-char (point-max)) ; show the interesting part
426 (apply 'mh-exec-cmd-quiet t mh-send-prog
428 (list "-nopush" "-nodraftfolder"
429 "-noverbose" "-nowatch"
430 mh-send-args mime-editor/draft-file-name)))))
434 (defvar mime-editor/window-config-alist
436 (mh-letter-mode . mh-previous-window-config)
437 (news-reply-mode . (cond ((boundp 'gnus-winconf-post-news)
439 gnus-winconf-post-news
440 (setq gnus-winconf-post-news nil)
442 ((boundp 'gnus-prev-winconf)
445 (setq gnus-prev-winconf nil)
450 (defvar mime-editor/news-reply-mode-server-running nil)
456 (defvar mime-editor/signing-type nil
457 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
459 (defvar mime-editor/encrypting-type nil
460 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
462 (if (or mime-editor/signing-type mime-editor/encrypting-type)
470 (defconst mime-editor/single-part-tag-regexp
471 "^--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
472 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
474 (defconst mime-editor/multipart-beginning-regexp "^--<<\\([^<>]+\\)>>-{\n")
476 (defconst mime-editor/multipart-end-regexp "^--}-<<\\([^<>]+\\)>>\n")
478 (defconst mime-editor/beginning-tag-regexp
479 (regexp-or mime-editor/single-part-tag-regexp
480 mime-editor/multipart-beginning-regexp))
482 (defconst mime-editor/end-tag-regexp
483 (regexp-or mime-editor/single-part-tag-regexp
484 mime-editor/multipart-end-regexp))
486 (defconst mime-editor/tag-regexp
487 (regexp-or mime-editor/single-part-tag-regexp
488 mime-editor/multipart-beginning-regexp
489 mime-editor/multipart-end-regexp))
491 (defvar mime-tag-format "--[[%s]]"
492 "*Control-string making a MIME tag.")
494 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
495 "*Control-string making a MIME tag with encoding.")
497 ;;; @@ multipart boundary
500 (defvar mime-multipart-boundary "Multipart"
501 "*Boundary of a multipart message.")
504 ;;; @@ buffer local variables
507 (defvar mime/editor-mode-old-local-map nil)
508 (defvar mime/editor-mode-old-selective-display nil)
509 (defvar mime/editing-buffer nil)
515 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
516 "*Specify MIME tspecials.
517 Tspecials means any character that matches with it in header must be quoted.")
519 (defconst mime-editor/mime-version-value
520 (format "1.0 (generated by tm-edit %s)" mime-editor/version)
521 "MIME version number.")
524 ;;; @ keymap and menu
527 (defvar mime/editor-mode-flag nil)
528 (make-variable-buffer-local 'mime/editor-mode-flag)
530 (set-alist 'minor-mode-alist 'mime/editor-mode-flag '(" MIME-Edit"))
532 (defun mime-editor/define-keymap (keymap)
533 "Add mime-editor commands to KEYMAP."
534 (if (not (keymapp keymap))
536 (define-key keymap "\C-t" 'mime-editor/insert-text)
537 (define-key keymap "\C-i" 'mime-editor/insert-file)
538 (define-key keymap "\C-e" 'mime-editor/insert-external)
539 (define-key keymap "\C-v" 'mime-editor/insert-voice)
540 (define-key keymap "\C-y" 'mime-editor/insert-message)
541 (define-key keymap "\C-m" 'mime-editor/insert-mail)
542 (define-key keymap "\C-w" 'mime-editor/insert-signature)
543 (define-key keymap "\C-s" 'mime-editor/insert-signature)
544 (define-key keymap "\C-k" 'mime-editor/insert-key)
545 (define-key keymap "t" 'mime-editor/insert-tag)
546 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
547 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
548 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
549 (define-key keymap "d" 'mime-editor/enclose-digest-region)
550 (define-key keymap "s" 'mime-editor/enclose-signed-region)
551 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
552 (define-key keymap "\C-p" 'mime-editor/preview-message)
553 (define-key keymap "\C-z" 'mime-editor/exit)
554 (define-key keymap "?" 'mime-editor/help)
557 (defconst mime-editor/menu-title "MIME-Edit")
559 (defconst mime-editor/menu-list
561 '((mime-help "Describe MIME editor mode" mime-editor/help)
562 (file "Insert File" mime-editor/insert-file)
563 (external "Insert External" mime-editor/insert-external)
564 (voice "Insert Voice" mime-editor/insert-voice)
565 (message "Insert Message" mime-editor/insert-message)
566 (mail "Insert Mail" mime-editor/insert-mail)
567 (signature "Insert Signature" mime-editor/insert-signature)
568 (text "Insert Text" mime-editor/insert-text)
569 (tag "Insert Tag" mime-editor/insert-tag)
570 (alternative "Enclose as alternative"
571 mime-editor/enclose-alternative-region)
572 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
573 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
574 (digest "Enclose as digest" mime-editor/enclose-digest-region)
575 (signed "Enclose as signed" mime-editor/enclose-signed-region)
576 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
577 (key "Insert Public Key" mime-editor/insert-key)
578 (split "About split" mime-editor/set-split)
580 (if (and (featurep 'mailcrypt)
581 (not (or mime-editor/signing-type mime-editor/encrypting-type)))
582 '((sign "About sign" mime-editor/set-sign)
583 (encrypt "About encryption" mime-editor/set-encrypt)
585 '((preview "Preview Message" mime-editor/preview-message))
587 "MIME-edit menubar entry.")
589 (defun mime-editor/define-menu-for-emacs19 ()
590 "Define menu for Emacs 19."
591 (define-key (current-local-map) [menu-bar mime-edit]
592 (cons mime-editor/menu-title
593 (make-sparse-keymap mime-editor/menu-title)))
596 (define-key (current-local-map)
597 (vector 'menu-bar 'mime-edit (car item))
598 (cons (nth 1 item)(nth 2 item))
601 (reverse mime-editor/menu-list)
604 ;;; modified by Pekka Marjola <pema@niksula.hut.fi>
605 ;;; 1995/9/5 (c.f. [tm-en:69])
606 (defun mime-editor/define-menu-for-xemacs ()
607 "Define menu for Emacs 19."
608 (cond ((featurep 'menubar)
609 (make-local-variable 'current-menubar)
610 (set-buffer-menubar current-menubar)
612 (cons mime-editor/menu-title
615 (vector (nth 1 item)(nth 2 item)
616 mime/editor-mode-flag)
618 mime-editor/menu-list)))
621 ;;; modified by Steven L. Baur <steve@miranova.com>
622 ;;; 1995/12/6 (c.f. [tm-en:209])
623 (if (and (string-match "XEmacs\\|Lucid" emacs-version)
624 (not (boundp 'mime-editor/popup-menu-for-xemacs)))
625 (setq mime-editor/popup-menu-for-xemacs
626 (append '("MIME Commands" "---")
627 (mapcar (function (lambda (item)
631 mime-editor/menu-list)))
640 (defun mime/editor-mode ()
641 "MIME minor mode for editing the tagged MIME message.
643 In this mode, basically, the message is composed in the tagged MIME
644 format. The message tag looks like:
646 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
648 The tag specifies the MIME content type, subtype, optional parameters
649 and transfer encoding of the message following the tag. Messages
650 without any tag are treated as `text/plain' by default. Charset and
651 transfer encoding are automatically defined unless explicitly
652 specified. Binary messages such as audio and image are usually hidden
653 using selective-display facility. The messages in the tagged MIME
654 format are automatically translated into a MIME compliant message when
657 Available charsets depend on Emacs version being used. The following
658 lists the available charsets of each emacs.
660 Emacs18: US-ASCII is only available.
661 NEmacs: US-ASCII and ISO-2022-JP are available.
662 Emacs19: US-ASCII and ISO-8859-1 are available.
663 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-6),
664 ISO-2022-JP, ISO-2022-JP-2 and ISO-2022-INT-1 are available.
666 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in Mule is expected to
667 be used to represent multilingual text in intermixed manner. Any
668 languages that has no registered charset are represented as either
669 ISO-2022-JP-2 or ISO-2022-INT-1 in Mule.
671 Following commands are available in addition to major mode commands:
672 \\[mime-editor/insert-text] insert a text message.
673 \\[mime-editor/insert-file] insert a (binary) file.
674 \\[mime-editor/insert-external] insert a reference to external body.
675 \\[mime-editor/insert-voice] insert a voice message.
676 \\[mime-editor/insert-message] insert a mail or news message.
677 \\[mime-editor/insert-mail] insert a mail message.
678 \\[mime-editor/insert-signature] insert a signature file at end.
679 \\[mime-editor/insert-tag] insert a new MIME tag.
680 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
681 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
682 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
683 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
684 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
685 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
686 \\[mime-editor/insert-key] insert PGP public key.
687 \\[mime-editor/preview-message] preview editing MIME message.
688 \\[mime-editor/exit] exit and translate into a MIME compliant message.
689 \\[mime-editor/maybe-translate] exit, translate and run the original command.
690 \\[mime-editor/help] show this help.
692 Additional commands are available in some major modes:
693 C-c C-c exit, translate and run the original command.
694 C-c C-s exit, translate and run the original command.
696 The following is a message example written in the tagged MIME format.
697 TABs at the beginning of the line are not a part of the message:
699 This is a conventional plain text. It should be translated
702 This is also a plain text. But, it is explicitly specified as
704 --[[text/plain; charset=ISO-2022-JP]]
705 \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
708 <center>This is a richtext.</center>
709 --[[image/gif][base64]]^M...image encoded in base64 here...
710 --[[audio/basic][base64]]^M...audio encoded in base64 here...
712 User customizable variables (not documented all of them):
714 Specifies a key prefix for MIME minor mode commands.
717 Specifies a signature file to be included as part of a multipart
720 mime-ignore-preceding-spaces
721 Preceding white spaces in a message body are ignored if non-nil.
723 mime-ignore-trailing-spaces
724 Trailing white spaces in a message body are ignored if non-nil.
726 mime-auto-fill-header
727 Fill header fields that contain encoded-words if non-nil.
730 Hide a non-textual body message encoded in base64 after insertion
734 Specifies a function to encode a string for given encoding method.
735 The method is a form of (CHARSET . ENCODING).
738 Specifies a function to record a voice message and return a buffer
739 that contains it. The function mime-voice-recorder-for-sun is for
742 mime/editor-mode-hook
743 Turning on MIME mode calls the value of mime/editor-mode-hook, if
746 mime-editor/translate-hook
747 The value of mime-editor/translate-hook is called just before translating
748 the tagged MIME format into a MIME compliant message if it is
749 non-nil. If the hook call the function mime-editor/insert-signature,
750 the signature file will be inserted automatically.
752 mime-editor/exit-hook
753 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
756 (if mime/editor-mode-flag
757 (error "You are already editing a MIME message.")
758 (setq mime/editor-mode-flag t)
759 ;; Remember old key bindings.
760 (make-local-variable 'mime/editor-mode-old-local-map)
761 (setq mime/editor-mode-old-local-map (current-local-map))
762 ;; Add MIME commands to current local map.
763 (use-local-map (copy-keymap (current-local-map)))
764 (if (not (lookup-key (current-local-map) mime-prefix))
765 (define-key (current-local-map) mime-prefix (make-sparse-keymap)))
766 (mime-editor/define-keymap (lookup-key (current-local-map) mime-prefix))
768 ;; Define menu. Menus for other emacs implementations are
770 ;; modified by Pekka Marjola <pema@niksula.hut.fi>
771 ;; 1995/9/5 (c.f. [tm-eng:69])
772 (cond ((string-match "XEmacs\\|Lucid" emacs-version)
773 (mime-editor/define-menu-for-xemacs))
774 ((string-match "^19\\." emacs-version)
775 (mime-editor/define-menu-for-emacs19)
779 ;; Remember old selective-display.
780 (make-local-variable 'mime/editor-mode-old-selective-display)
781 (setq mime/editor-mode-old-selective-display selective-display)
782 (setq selective-display t)
783 ;; I don't care about saving these.
784 (setq paragraph-start
785 (regexp-or mime-editor/single-part-tag-regexp
787 (setq paragraph-separate
788 (regexp-or mime-editor/single-part-tag-regexp
790 (run-hooks 'mime/editor-mode-hook)
792 (substitute-command-keys
793 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
797 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
798 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
800 (defun mime-editor/exit (&optional nomime no-error)
801 "Translate the tagged MIME message into a MIME compliant message.
802 With no argument encode a message in the buffer into MIME, otherwise
803 just return to previous mode."
805 (if (not mime/editor-mode-flag)
807 (error "You aren't editing a MIME message.")
811 (run-hooks 'mime-editor/translate-hook)
812 (mime-editor/translate-buffer)))
813 ;; Restore previous state.
814 (setq mime/editor-mode-flag nil)
815 (use-local-map mime/editor-mode-old-local-map)
817 ;; modified by Pekka Marjola <pema@niksula.hut.fi>
818 ;; 1995/9/5 (c.f. [tm-eng:69])
819 (if (string-match "XEmacs\\|Lucid" emacs-version)
821 (delete-menu-item (list mime-editor/menu-title))
822 ; should rather be const
823 ;; (while mime-editor/xemacs-old-bindings
824 ;; (eval (pop mime-editor/xemacs-old-bindings)))
825 (local-unset-key mime-prefix)))
828 (setq selective-display mime/editor-mode-old-selective-display)
829 (set-buffer-modified-p (buffer-modified-p))
830 (run-hooks 'mime-editor/exit-hook)
831 (message "Exit MIME editor mode.")
834 (defun mime-editor/maybe-translate ()
836 (mime-editor/exit nil t)
837 (call-interactively 'mime-editor/maybe-split-and-send)
840 (defun mime-editor/help ()
841 "Show help message about MIME mode."
843 (with-output-to-temp-buffer "*Help*"
844 (princ "MIME editor mode:\n")
845 (princ (documentation 'mime/editor-mode))
846 (print-help-return-message)))
848 (defun mime-editor/insert-text ()
849 "Insert a text message.
850 Charset is automatically obtained from the `mime/lc-charset-alist'."
852 (if (and (mime-editor/insert-tag "text" nil nil)
853 (looking-at mime-editor/single-part-tag-regexp))
855 ;; Make a space between the following message.
860 (defun mime-editor/insert-file (file)
861 "Insert a message from a file."
862 (interactive "fInsert file as MIME message: ")
863 (let* ((guess (mime-find-file-type file))
864 (pritype (nth 0 guess))
865 (subtype (nth 1 guess))
866 (parameters (nth 2 guess))
867 (default (nth 3 guess)) ;Guess encoding from its file name.
868 (disposition-type (nth 4 guess))
869 (disposition-params (nth 5 guess))
871 (if (not (interactive-p))
874 (concat "What transfer encoding"
877 (if (string-equal default "")
883 mime-encoding-method-alist nil t nil))))
884 (if (string-equal encoding "")
885 (setq encoding default))
886 (if (or (consp parameters) (stringp disposition-type))
887 (let ((rest parameters) cell attribute value)
890 (setq cell (car rest))
891 (setq attribute (car cell))
892 (setq value (cdr cell))
894 (setq value (rfc822/wrap-as-quoted-string
895 (file-name-nondirectory file)))
897 (setq parameters (concat parameters "; " attribute "=" value))
898 (setq rest (cdr rest))
903 (concat parameters "\n"
904 "Content-Disposition: " disposition-type))
905 (setq rest disposition-params)
907 (setq cell (car rest))
908 (setq attribute (car cell))
909 (setq value (cdr cell))
911 (setq value (rfc822/wrap-as-quoted-string
912 (file-name-nondirectory file)))
915 (concat parameters "; " attribute "=" value))
916 (setq rest (cdr rest))
920 (mime-editor/insert-tag pritype subtype parameters)
921 (mime-editor/insert-binary-file file encoding)
924 (defun mime-editor/insert-external ()
925 "Insert a reference to external body."
927 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
929 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
931 (let* ((pritype (mime-prompt-for-type))
932 (subtype (mime-prompt-for-subtype pritype))
933 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
936 (insert "Content-Type: "
937 pritype "/" subtype (or parameters "") "\n")))
938 (if (and (not (eobp))
939 (not (looking-at mime-editor/single-part-tag-regexp)))
940 (insert (mime-make-text-tag) "\n")))
942 (defun mime-editor/insert-voice ()
943 "Insert a voice message."
945 (mime-editor/insert-tag "audio" "basic" nil)
946 (let ((buffer (funcall mime-voice-recorder)))
948 (mime-editor/insert-binary-buffer buffer "base64")
952 (defun mime-editor/insert-signature (&optional arg)
953 "Insert a signature file specified by mime-signature-file."
958 (read-file-name "Insert your signature: "
959 (concat signature-file-name "-")
962 (signature/get-signature-file-name))))
964 (if signature-insert-at-eof
965 (goto-char (point-max))
967 (apply (function mime-editor/insert-tag)
968 (mime-find-file-type signature))
969 (if (file-readable-p signature)
971 (goto-char (point-max))
975 (insert-file-contents signature)
976 (set-buffer-modified-p (buffer-modified-p))
977 ; force mode line update
981 ;; Insert a new tag around a point.
983 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
984 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
985 If nothing is inserted, return nil."
990 exist-prev-tag exist-next-tag)
993 (mime-prompt-for-type)))
996 (mime-prompt-for-subtype pritype)))
999 (mime-prompt-for-parameters pritype subtype delimiter)))
1000 ;; Make a new MIME tag.
1001 (setq newtag (mime-make-tag pritype subtype parameters))
1002 ;; Find an current MIME tag.
1005 (if (mime-editor/goto-tag)
1007 (if (eq current (match-beginning 0))
1008 (setq exist-next-tag t)
1009 (setq exist-prev-tag t)
1011 (buffer-substring (match-beginning 0) (match-end 0))
1013 ;; Assume content type is 'text/plan'.
1014 (mime-make-tag "text" "plain")
1016 ;; We are only interested in TEXT.
1018 (not (mime-test-content-type
1019 (mime-editor/get-contype oldtag) "text")))
1021 (cond (exist-prev-tag (insert "\n"))
1022 (exist-next-tag (save-excursion
1031 (if (or (not oldtag) ;Not text
1032 (or mime-ignore-same-text-tag
1033 (not (string-equal oldtag newtag))))
1035 ;; Mark the beginning of the tag for convenience.
1036 (push-mark (point) 'nomsg)
1037 (insert newtag "\n")
1038 (list pritype subtype parameters) ;New tag is created.
1040 ;; Restore previous point.
1042 nil ;Nothing is created.
1046 ;; Insert the binary content after MIME tag.
1047 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1049 (defun mime-editor/insert-binary-file (file &optional encoding)
1050 "Insert binary FILE at point.
1051 Optional argument ENCODING specifies an encoding method such as base64."
1052 (let ((tmpbuf (get-buffer-create " *MIME insert*")))
1056 (let ((mc-flag nil) ;Mule
1057 (file-coding-system-for-read
1058 (if (featurep 'mule) *noconv*))
1059 (kanji-flag nil) ;NEmacs
1060 (emx-binary-mode t) ;Stop CRLF to LF conversion in OS/2
1062 (let (jka-compr-compression-info-list
1063 jam-zcat-filename-list)
1064 (insert-file-contents file))))
1066 (if (and (stringp encoding)
1067 (string-equal (downcase encoding) "x-uue"))
1070 (let ((uuencode-external-encoder
1071 (cons (car uuencode-external-encoder)
1072 (list (file-name-nondirectory file))
1074 (mime-editor/insert-binary-buffer tmpbuf encoding)
1076 (mime-editor/insert-binary-buffer tmpbuf encoding))
1077 (kill-buffer tmpbuf))))
1079 ;; Insert the binary content after MIME tag.
1080 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1082 (defun mime-editor/insert-binary-buffer (buffer &optional encoding)
1083 "Insert binary BUFFER at point.
1084 Optional argument ENCODING specifies an encoding method such as base64."
1085 (let* ((tagend (1- (point))) ;End of the tag
1086 (hide-p (and mime-auto-hide-body
1088 (let ((en (downcase encoding)))
1089 (or (string-equal en "base64")
1090 (string-equal en "x-uue")
1094 (narrow-to-region (1- (point)) (point))
1095 (let ((start (point))
1096 (emx-binary-mode t)) ;Stop LF to CRLF conversion in OS/2
1097 (insert-buffer-substring buffer)
1098 ;; Encode binary message if necessary.
1100 (mime-encode-region encoding start (point-max))))
1103 (mime-flag-region (point-min) (1- (point-max)) ?\^M)
1104 (goto-char (point-max)))
1106 ;; Define encoding even if it is 7bit.
1107 (if (stringp encoding)
1109 (goto-char tagend) ;Make sure which line the tag is on.
1110 (mime-editor/define-encoding encoding)))
1114 ;; Commands work on a current message flagment.
1116 (defun mime-editor/goto-tag ()
1117 "Search for the beginning of the tagged MIME message."
1118 (let ((current (point)) multipart)
1119 (if (looking-at mime-editor/tag-regexp)
1121 ;; At first, go to the end.
1122 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1123 (goto-char (match-beginning 0)) ;For multiline tag
1128 (goto-char (point-max))
1130 ;; Then search for the beginning.
1131 (re-search-backward mime-editor/end-tag-regexp nil t)
1133 (or (looking-at mime-editor/beginning-tag-regexp)
1134 ;; Restore previous point.
1141 (defun mime-editor/content-beginning ()
1142 "Return the point of the beginning of content."
1144 (let ((beg (save-excursion
1145 (beginning-of-line) (point))))
1146 (if (mime-editor/goto-tag)
1147 (let ((top (point)))
1148 (goto-char (match-end 0))
1149 (if (and (= beg top)
1150 (= (following-char) ?\^M))
1154 ;; Default text/plain tag.
1155 (goto-char (point-min))
1157 (concat "\n" (regexp-quote mail-header-separator)
1158 (if mime-ignore-preceding-spaces
1159 "[ \t\n]*\n" "\n")) nil 'move)
1163 (defun mime-editor/content-end ()
1164 "Return the point of the end of content."
1166 (let ((beg (save-excursion
1167 (beginning-of-line) (point))))
1168 (if (mime-editor/goto-tag)
1169 (let ((top (point)))
1170 (goto-char (match-end 0))
1171 (if (and (= beg top) ;Must be on the same line.
1172 (= (following-char) ?\^M))
1176 ;; Move to the end of this text.
1177 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1178 ;; Don't forget a multiline tag.
1179 (goto-char (match-beginning 0)))
1182 ;; Assume the message begins with text/plain.
1183 (goto-char (mime-editor/content-beginning))
1184 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1185 ;; Don't forget a multiline tag.
1186 (goto-char (match-beginning 0)))
1190 (defun mime-editor/define-charset (charset)
1191 "Set charset of current tag to CHARSET."
1193 (if (mime-editor/goto-tag)
1194 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1195 (delete-region (match-beginning 0) (match-end 0))
1197 (mime-create-tag (mime-set-parameter
1198 (mime-editor/get-contype tag) "charset" charset)
1199 (mime-editor/get-encoding tag))))
1202 (defun mime-editor/define-encoding (encoding)
1203 "Set encoding of current tag to ENCODING."
1205 (if (mime-editor/goto-tag)
1206 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1207 (delete-region (match-beginning 0) (match-end 0))
1208 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1211 (defun mime-editor/choose-charset ()
1212 "Choose charset of a text following current point."
1213 (mime/find-charset-region (point) (mime-editor/content-end))
1216 (defun mime-make-text-tag (&optional subtype)
1217 "Make a tag for a text after current point.
1218 Subtype of text type can be specified by an optional argument SUBTYPE.
1219 Otherwise, it is obtained from mime-content-types."
1220 (let* ((pritype "text")
1221 (subtype (or subtype
1222 (car (car (cdr (assoc pritype mime-content-types)))))))
1223 ;; Charset should be defined later.
1224 (mime-make-tag pritype subtype)))
1227 ;; Tag handling functions
1229 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1230 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1231 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1235 (defun mime-create-tag (contype &optional encoding)
1236 "Make a tag with CONTENT-TYPE and optional ENCODING."
1237 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1240 (defun mime-editor/get-contype (tag)
1241 "Return Content-Type (including parameters) of TAG."
1243 (or (string-match mime-editor/single-part-tag-regexp tag)
1244 (string-match mime-editor/multipart-beginning-regexp tag)
1245 (string-match mime-editor/multipart-end-regexp tag)
1247 (substring tag (match-beginning 1) (match-end 1))
1250 (defun mime-editor/get-encoding (tag)
1251 "Return encoding of TAG."
1253 (string-match mime-editor/single-part-tag-regexp tag)
1255 (not (= (match-beginning 3) (match-end 3)))
1256 (substring tag (match-beginning 3) (match-end 3))))
1258 (defun mime-get-parameter (contype parameter)
1259 "For given CONTYPE return value for PARAMETER.
1260 Nil if no such parameter."
1264 (regexp-quote parameter)
1265 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1267 (substring contype (match-beginning 1) (match-end 1))
1268 nil ;No such parameter
1271 (defun mime-set-parameter (contype parameter value)
1272 "For given CONTYPE set PARAMETER to VALUE."
1276 (regexp-quote parameter)
1277 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1280 (concat (substring contype 0 (match-beginning 1))
1282 (substring contype (match-end 1)))
1283 (concat contype "; " parameter "=" value)))
1285 (defun mime-strip-parameters (contype)
1286 "Return primary content-type and subtype without parameters for CONTYPE."
1287 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1288 (substring contype (match-beginning 1) (match-end 1)) nil))
1290 (defun mime-test-content-type (contype type &optional subtype)
1291 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1292 (and (stringp contype)
1295 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1296 (downcase contype))))
1301 (defun mime-find-file-type (file)
1302 "Guess Content-Type, subtype, and parameters from FILE."
1304 (guesses mime-file-types))
1305 (while (and (not guess) guesses)
1306 (if (string-match (car (car guesses)) file)
1307 (setq guess (cdr (car guesses))))
1308 (setq guesses (cdr guesses)))
1312 (defun mime-prompt-for-type ()
1313 "Ask for Content-type."
1315 ;; Repeat until primary content type is specified.
1316 (while (string-equal type "")
1318 (completing-read "What content type: "
1321 'require-match ;Type must be specified.
1324 (if (string-equal type "")
1326 (message "Content type is required.")
1334 (defun mime-prompt-for-subtype (pritype)
1335 "Ask for Content-type subtype of Content-Type PRITYPE."
1336 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1341 "What content subtype: (default " default ") ")
1342 "What content subtype: ")
1343 (cdr (assoc pritype mime-content-types))
1345 'require-match ;Subtype must be specified.
1348 (if (string-equal answer "") default answer)))
1350 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1351 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1352 Optional DELIMITER specifies parameter delimiter (';' by default)."
1353 (let* ((delimiter (or delimiter "; "))
1358 (mime-prompt-for-parameters-1
1360 (cdr (assoc pritype mime-content-types))))))
1363 (if (and (stringp parameters)
1364 (not (string-equal parameters "")))
1365 (concat delimiter parameters)
1366 "" ;"" if no parameters
1369 (defun mime-prompt-for-parameters-1 (optlist)
1370 (apply (function append)
1371 (mapcar (function mime-prompt-for-parameter) optlist)))
1373 (defun mime-prompt-for-parameter (parameter)
1375 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1376 (let* ((prompt (car parameter))
1377 (choices (mapcar (function
1379 (if (consp e) e (list e))))
1381 (default (car (car choices)))
1387 (concat "What " prompt
1389 (if (string-equal default "") "\"\"" default)
1391 choices nil nil ""))
1392 ;; If nothing is selected, use default.
1393 (if (string-equal answer "")
1394 (setq answer default)))
1396 (read-string (concat "What " prompt ": "))))
1397 (cons (if (and answer
1398 (not (string-equal answer "")))
1400 ;; Note: control characters ignored!
1401 (if (string-match mime-tspecials-regexp answer)
1402 (concat "\"" answer "\"") answer)))
1403 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1406 (defun mime-encode-string (encoding string)
1407 "Using ENCODING encode a STRING.
1408 If the STRING is too long, the encoded string may be broken into
1411 (set-buffer (get-buffer-create " *MIME encoding*"))
1414 (mime-encode-region encoding (point-min) (point-max))
1416 (buffer-substring (point-min) (point-max))
1417 (kill-buffer (current-buffer)))))
1419 (defun mime-decode-string (encoding string)
1420 "Using ENCODING decode a STRING."
1422 (set-buffer (get-buffer-create " *MIME decoding*"))
1425 (mime-decode-region encoding (point-min) (point-max))
1427 (buffer-substring (point-min) (point-max))
1428 (kill-buffer (current-buffer)))))
1430 (defun mime-flag-region (from to flag)
1431 "Hides or shows lines from FROM to TO, according to FLAG.
1432 If FLAG is `\\n' (newline character) then text is shown,
1433 while if FLAG is `\\^M' (control-M) the text is hidden."
1434 (let ((buffer-read-only nil) ;Okay even if write protected.
1435 (modp (buffer-modified-p)))
1437 (subst-char-in-region from to
1438 (if (= flag ?\n) ?\^M ?\n)
1440 (set-buffer-modified-p modp))))
1443 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1446 (defun mime-editor/translate-buffer ()
1447 "Encode the tagged MIME message in current buffer in MIME compliant message."
1449 (if (catch 'mime-editor/error
1451 (mime/encode-message-header)
1452 (mime-editor/translate-body)
1453 (mime-editor/pgp-processing)
1457 (error "Translation error!")
1460 (defun mime-editor/find-inmost ()
1461 (goto-char (point-min))
1462 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1463 (let ((bb (match-beginning 0))
1465 (type (buffer-substring (match-beginning 1)(match-end 1)))
1467 (setq end-exp (format "^--}-<<%s>>\n" type))
1469 (if (re-search-forward end-exp nil t)
1471 (setq eb (match-beginning 0))
1472 (setq ee (match-end 0))
1474 (setq eb (point-max))
1475 (setq ee (point-max))
1477 (narrow-to-region be eb)
1479 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1481 (narrow-to-region (match-beginning 0)(point-max))
1482 (mime-editor/find-inmost)
1485 ;;(delete-region eb ee)
1486 (list type bb be eb)
1489 (defun mime-editor/process-multipart-1 (boundary)
1490 (let ((ret (mime-editor/find-inmost)))
1492 (let ((type (car ret))
1493 (bb (nth 1 ret))(be (nth 2 ret))
1496 (narrow-to-region bb eb)
1497 (delete-region bb be)
1498 (setq bb (point-min))
1499 (setq eb (point-max))
1502 (if (looking-at mime-editor/multipart-end-regexp)
1503 (let ((beg (match-beginning 0))
1506 (delete-region beg end)
1507 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
1509 (insert (concat (mime-make-text-tag) "\n"))
1511 (cond ((string= type "signed")
1512 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1513 (mime-editor/sign-pgp-elkins bb eb boundary)
1515 ((eq mime-editor/signing-type 'pgp-kazu)
1516 (mime-editor/process-pgp-kazu 'mc-sign
1520 ((string= type "encrypted")
1521 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1522 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1524 ((eq mime-editor/signing-type 'pgp-kazu)
1525 (mime-editor/process-pgp-kazu 'mc-encrypt
1530 (nth 2 (mime-editor/translate-region bb eb
1534 (format "--[[multipart/%s;
1535 boundary=\"%s\"][7bit]]\n"
1540 (defun tm:mc-pgp-generic-parser (result)
1541 (let ((ret (mc-pgp-generic-parser result)))
1543 (vector (car ret)(cdr ret))
1546 (autoload 'mc-pgp-lookup-key "mc-pgp")
1548 (defun tm:mc-process-region
1549 (beg end passwd program args parser &optional buffer boundary)
1550 (let ((obuf (current-buffer))
1551 (process-connection-type nil)
1552 mybuf result rgn proc)
1555 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1559 (buffer-disable-undo mybuf)
1561 (apply 'start-process "*PGP*" mybuf program args))
1564 (process-send-string proc (concat passwd "\n"))
1565 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1566 (process-send-region proc beg end)
1567 (process-send-eof proc)
1568 (while (eq 'run (process-status proc))
1569 (accept-process-output proc 5))
1570 (setq result (process-exit-status proc))
1571 ;; Hack to force a status_notify() in Emacs 19.29
1572 (delete-process proc)
1574 (goto-char (point-max))
1575 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1576 (delete-region (match-beginning 0) (match-end 0)))
1577 (goto-char (point-min))
1579 (while (search-forward "\r\n" nil t)
1580 (replace-match "\n"))
1581 ;; Hurm. FIXME; must get better result codes.
1582 (if (stringp result)
1583 (error "%s exited abnormally: '%s'" program result)
1584 (setq rgn (funcall parser result))
1585 ;; If the parser found something, migrate it
1591 (narrow-to-region beg end)
1593 (insert (format "--%s\n" boundary))
1594 (goto-char (point-max))
1595 (insert (format "\n--%s
1596 Content-Type: application/pgp-signature
1597 Content-Transfer-Encoding: 7bit
1600 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1601 (goto-char (point-max))
1602 (insert (format "\n--%s--\n" boundary))
1604 (delete-region beg end)
1606 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1609 (delete-region (car rgn) (cdr rgn)))))
1610 ;; Return nil on failure and exit code on success
1612 ;; Cleanup even on nonlocal exit
1613 (if (and proc (eq 'run (process-status proc)))
1614 (interrupt-process proc))
1616 (or buffer (null mybuf) (kill-buffer mybuf)))))
1618 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1619 (if (not (boundp 'mc-pgp-user-id))
1622 (let ((process-environment process-environment)
1623 (buffer (get-buffer-create mc-buffer-name))
1625 (parser (function mc-pgp-generic-parser))
1626 (pgp-path mc-pgp-path)
1628 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1632 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1633 (setenv "PGPPASSFD" "0")
1639 (list "+verbose=1" "+language=en"
1640 (format "+clearsig=%s" (if unclear "off" "on"))
1641 "+batchmode" "-u" (cdr key))))
1643 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1645 (message "Signing as %s ..." (car key))
1646 (if (tm:mc-process-region
1647 start end passwd pgp-path args parser buffer boundary)
1651 (goto-char (point-min))
1654 --[[multipart/signed; protocol=\"application/pgp-signature\";
1655 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1657 (message "Signing as %s ... Done." (car key))
1661 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1664 (narrow-to-region beg end)
1666 (mime-editor/translate-region beg end boundary))
1668 (encoding (nth 1 ret))
1670 (pgp-boundary (concat "pgp-sign-" boundary))
1673 (insert (format "Content-Type: %s\n" ctype))
1675 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1678 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1679 nil nil pgp-boundary)
1680 (throw 'mime-editor/error 'pgp-error)
1684 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1687 (narrow-to-region beg end)
1689 (mime-editor/translate-region beg end boundary))
1691 (encoding (nth 1 ret))
1693 (pgp-boundary (concat "pgp-" boundary))
1696 (insert (format "Content-Type: %s\n" ctype))
1698 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1706 (let ((mail-header-separator "="))
1707 (call-interactively 'mc-encrypt)
1710 (and (search-forward "=\n")
1713 (throw 'mime-editor/error 'pgp-error)
1716 (insert (format "--[[multipart/encrypted;
1718 protocol=\"application/pgp-encrypted\"][7bit]]
1720 Content-Type: application/pgp-encrypted
1723 Content-Type: application/octet-stream
1724 Content-Transfer-Encoding: 7bit
1726 " pgp-boundary pgp-boundary pgp-boundary))
1727 (goto-char (point-max))
1728 (insert (format "\n--%s--\n" pgp-boundary))
1732 (defun mime-editor/process-pgp-kazu (type beg end boundary)
1735 (narrow-to-region beg end)
1737 (mime-editor/translate-region beg end boundary))
1739 (encoding (nth 1 ret))
1743 (insert (format "Content-Type: %s\n" ctype))
1745 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1753 (let ((mail-header-separator "="))
1754 (call-interactively type)
1757 (and (search-forward "=\n")
1760 (throw 'mime-editor/error 'pgp-error)
1764 "--[[application/pgp; format=mime][7bit]]\n")
1768 (defun mime-editor/translate-body ()
1769 "Encode the tagged MIME body in current buffer in MIME compliant message."
1773 (concat mime-multipart-boundary "_"
1774 (replace-space-with-underline (current-time-string))
1778 (while (mime-editor/process-multipart-1
1779 (format "%s-%d" boundary i))
1783 ;; We are interested in message body.
1786 (goto-char (point-min))
1788 (concat "\n" (regexp-quote mail-header-separator)
1789 (if mime-ignore-preceding-spaces
1790 "[ \t\n]*\n" "\n")) nil 'move)
1794 (goto-char (point-max))
1795 (and mime-ignore-trailing-spaces
1796 (re-search-backward "[^ \t\n]\n" beg t)
1799 (setq ret (mime-editor/translate-region
1801 (format "%s-%d" boundary i)))
1803 (let ((contype (car ret)) ;Content-Type
1804 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1806 ;; Make primary MIME headers.
1807 (or (mail-position-on-field "Mime-Version")
1808 (insert mime-editor/mime-version-value))
1809 ;; Remove old Content-Type and other fields.
1811 (goto-char (point-min))
1812 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1813 (narrow-to-region (point-min) (point))
1814 (goto-char (point-min))
1815 (mime-delete-field "Content-Type")
1816 (mime-delete-field "Content-Transfer-Encoding"))
1817 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1818 (mail-position-on-field "Content-Type")
1822 (mail-position-on-field "Content-Transfer-Encoding")
1826 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1829 (concat mime-multipart-boundary "_"
1830 (replace-space-with-underline (current-time-string))))
1834 (narrow-to-region beg end)
1835 (let ((tag nil) ;MIME tag
1836 (contype nil) ;Content-Type
1837 (encoding nil) ;Content-Transfer-Encoding
1838 (nparts 0)) ;Number of body parts
1839 ;; Normalize the body part by inserting appropriate message
1840 ;; tags for every message contents.
1841 (mime-editor/normalize-body)
1842 ;; Counting the number of Content-Type.
1843 (goto-char (point-min))
1844 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1845 (setq nparts (1+ nparts)))
1846 ;; Begin translation.
1847 (cond ((and (<= nparts 1)(not multipart))
1848 ;; It's a singular message.
1849 (goto-char (point-min))
1850 (while (re-search-forward
1851 mime-editor/single-part-tag-regexp nil t)
1853 (buffer-substring (match-beginning 0) (match-end 0)))
1854 (delete-region (match-beginning 0) (1+ (match-end 0)))
1855 (setq contype (mime-editor/get-contype tag))
1856 (setq encoding (mime-editor/get-encoding tag))
1859 ;; It's a multipart message.
1860 (goto-char (point-min))
1861 (while (re-search-forward
1862 mime-editor/single-part-tag-regexp nil t)
1864 (buffer-substring (match-beginning 0) (match-end 0)))
1865 (delete-region (match-beginning 0) (match-end 0))
1866 (setq contype (mime-editor/get-contype tag))
1867 (setq encoding (mime-editor/get-encoding tag))
1868 (insert "--" boundary "\n")
1869 (insert "Content-Type: " contype "\n")
1871 (insert "Content-Transfer-Encoding: " encoding "\n"))
1873 ;; Define Content-Type as "multipart/mixed".
1875 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1876 ;; Content-Transfer-Encoding must be "7bit".
1877 ;; The following encoding can be `nil', but is
1878 ;; specified as is since there is no way that a user
1880 (setq encoding "7bit")
1881 ;; Insert the trailer.
1882 (goto-char (point-max))
1884 (insert "--" boundary "--\n")
1885 (insert "\n--" boundary "--\n")
1887 (list contype encoding boundary nparts)
1890 (defun mime-editor/normalize-body ()
1891 "Normalize the body part by inserting appropriate message tags."
1892 ;; Insert the first MIME tags if necessary.
1893 (goto-char (point-min))
1894 (if (not (looking-at mime-editor/single-part-tag-regexp))
1895 (insert (mime-make-text-tag) "\n"))
1896 ;; Check each tag, and add new tag or correct it if necessary.
1897 (goto-char (point-min))
1898 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1899 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1900 (contype (mime-editor/get-contype tag))
1901 (charset (mime-get-parameter contype "charset"))
1902 (encoding (mime-editor/get-encoding tag)))
1903 ;; Remove extra whitespaces after the tag.
1904 (if (looking-at "[ \t]+$")
1905 (delete-region (match-beginning 0) (match-end 0)))
1906 (cond ((= (following-char) ?\^M)
1907 ;; It must be image, audio or video.
1909 (end (mime-editor/content-end)))
1910 ;; Insert explicit MIME tags after hidden messages.
1912 (if (and (not (eobp))
1913 (not (looking-at mime-editor/single-part-tag-regexp)))
1915 (insert (mime-make-text-tag) "\n")
1916 (forward-line -1) ;Process it again as text.
1918 ;; Show a hidden message. The point is not altered
1919 ;; after the conversion.
1920 (mime-flag-region beg end ?\n)))
1921 ((mime-test-content-type contype "message")
1922 ;; Content-type "message" should be sent as is.
1924 ((mime-test-content-type contype "text")
1925 ;; Define charset for text if necessary.
1926 (setq charset (or charset (mime-editor/choose-charset)))
1927 (mime-editor/define-charset charset)
1928 (if (string-equal contype "text/x-rot13-47")
1932 (goto-char (mime-editor/content-end))
1935 ;; Point is now on current tag.
1936 ;; Define encoding and encode text if necessary.
1937 (if (null encoding) ;Encoding is not specified.
1940 (assoc charset mime/charset-default-encoding-alist)
1942 (beg (mime-editor/content-beginning))
1943 (end (mime-editor/content-end))
1944 (body (buffer-substring beg end))
1945 (encoded (funcall mime-string-encoder
1946 (cons charset encoding) body)))
1947 (if (not (string-equal body encoded))
1950 (delete-region beg end)
1953 (mime-editor/define-encoding encoding)))
1955 ((null encoding) ;Encoding is not specified.
1956 ;; Application, image, audio, video, and any other
1957 ;; unknown content-type without encoding should be
1959 (let* ((encoding "base64") ;Encode in BASE64 by default.
1960 (beg (mime-editor/content-beginning))
1961 (end (mime-editor/content-end))
1962 (body (buffer-substring beg end))
1963 (encoded (funcall mime-string-encoder
1964 (cons nil encoding) body)))
1965 (if (not (string-equal body encoded))
1968 (delete-region beg end)
1971 (mime-editor/define-encoding encoding))
1976 (defun mime-delete-field (field)
1977 "Delete header FIELD."
1978 (let ((regexp (format "^%s:[ \t]*" field)))
1979 (goto-char (point-min))
1980 (while (re-search-forward regexp nil t)
1981 (delete-region (match-beginning 0)
1982 (progn (forward-line 1) (point)))
1987 ;;; Platform dependent functions
1990 ;; Emacs 18 implementations
1992 (defun mime-string-encoder-for-emacs18 (method string)
1993 "For given METHOD that is a cons of charset and encoding, encode a STRING."
1994 (let ((charset (car method))
1995 (encoding (cdr method)))
1996 (cond ((stringp encoding)
1997 (mime-encode-string encoding string))
1998 ;; Return string without any encoding.
2003 ;; Emacs 19 implementations
2005 (defun mime-string-encoder-for-emacs19 (method string)
2006 "For given METHOD that is a cons of charset and encoding, encode a STRING."
2007 (let ((charset (car method))
2008 (encoding (cdr method)))
2009 (cond ((stringp encoding)
2010 (mime-encode-string encoding string))
2011 ;; Return string without any encoding.
2016 ;; NEmacs implementations
2018 (defun mime-string-encoder-for-nemacs (method string)
2019 "For given METHOD that is a cons of charset and encoding, encode a STRING.
2020 US-ASCII and ISO-2022-JP are supported on NEmacs."
2021 (let ((charset (car method))
2022 (encoding (cdr method)))
2023 (cond ((stringp encoding)
2024 (mime-encode-string encoding
2025 ;; Convert internal (EUC) to JIS code.
2026 (convert-string-kanji-code string 3 2)
2028 ;; NEmacs can convert into ISO-2022-JP automatically,
2029 ;; but can do it myself as follows:
2030 ;;(t (convert-string-kanji-code string 3 2))
2032 ;; Return string without any encoding.
2037 ;; Mule implementations
2038 ;; Thanks to contributions by wkenji@flab.fujitsu.co.jp (Kenji
2039 ;; WAKAMIYA) and handa@etl.go.jp (Kenichi Handa).
2041 (defun mime-string-encoder-for-mule (method string)
2042 "For given METHOD that is a cons of charset and encoding, encode a
2043 STRING. US-ASCII, ISO-8859-* (except for ISO-8859-6), ISO-2022-JP,
2044 ISO-2022-JP-2 and ISO-2022-INT-1 are supported on Mule. Either of
2045 charset ISO-2022-JP-2 or ISO-2022-INT-1 is used for multilingual
2047 (let* ((charset (car method))
2048 (encoding (cdr method))
2050 (cdr (assoc (and (stringp charset) (upcase charset))
2051 '(("ISO-8859-1" . *ctext*)
2052 ("ISO-8859-2" . *iso-8859-2*)
2053 ("ISO-8859-3" . *iso-8859-3*)
2054 ("ISO-8859-4" . *iso-8859-4*)
2055 ("ISO-8859-5" . *iso-8859-5*)
2056 ;;("ISO-8859-6" . *iso-8859-6*)
2057 ("ISO-8859-7" . *iso-8859-7*)
2058 ("ISO-8859-8" . *iso-8859-8*)
2059 ("ISO-8859-9" . *iso-8859-9*)
2060 ("ISO-2022-JP" . *junet*)
2061 ("ISO-2022-JP-2" . *iso-2022-ss2-7*)
2062 ("ISO-2022-KR" . *korean-mail*)
2063 ("ISO-2022-INT-1" . *iso-2022-int-1*)
2065 ;; In bilingual environment it may be unnecessary to convert the
2066 ;; coding system of the string unless transfer encoding is
2067 ;; required since such conversion may be performed by mule
2069 (if (not (null coding-system))
2070 (setq string (code-convert-string string *internal* coding-system)))
2071 (if (stringp encoding)
2072 (setq string (mime-encode-string encoding string)))
2077 ;; Sun implementations
2079 (defun mime-voice-recorder-for-sun ()
2080 "Record voice in a buffer using Sun audio device, and return the buffer.
2081 If the environment variable AUDIOHOST is defined, its value is used as
2082 a recording host instead of local host."
2083 (let ((buffer (get-buffer-create " *MIME audio*"))
2084 (host (getenv "AUDIOHOST")))
2085 (message "Start the recording on %s. Type C-g to finish the recording..."
2086 (or host (system-name)))
2090 (condition-case errorcode
2091 (let ((selective-display nil) ;Disable ^M to nl translation.
2093 (kanji-flag nil)) ;NEmacs
2094 ;; If AUDIOHOST is defined, use the value as recording host.
2095 (cond ((not (null host))
2096 ;; Disable automatic conversion of coding system if Mule.
2097 (if (featurep 'mule)
2098 (define-program-coding-system nil "rsh" *noconv*))
2108 ;; Disable automatic conversion of coding system if Mule.
2109 (if (featurep 'mule)
2110 (define-program-coding-system nil "cat" *noconv*))
2116 (quit (message "Type C-g to finish recording... done.")
2117 buffer ;Return the buffer
2121 ;;; @ Other useful commands.
2124 ;; Message forwarding commands as content-type "message/rfc822".
2126 (defun mime-editor/insert-message (&optional message)
2128 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2129 (if (and inserter (fboundp inserter))
2131 (mime-editor/insert-tag "message" "rfc822")
2132 (funcall inserter message)
2134 (message "Sorry, I don't have message inserter for your MUA.")
2137 (defun mime-editor/insert-mail (&optional message)
2139 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2140 (if (and inserter (fboundp inserter))
2142 (mime-editor/insert-tag "message" "rfc822")
2143 (funcall inserter message)
2145 (message "Sorry, I don't have mail inserter for your MUA.")
2148 (defun mime-editor/inserted-message-filter ()
2151 (let ((header-start (point))
2152 (case-fold-search t)
2155 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2156 (if (re-search-forward "^$" (mark t))
2157 (narrow-to-region header-start (match-beginning 0))
2159 (goto-char header-start)
2160 (while (and (re-search-forward
2161 mime-editor/yank-ignored-field-regexp nil t)
2162 (setq beg (match-beginning 0))
2163 (setq end (1+ (rfc822/field-end)))
2165 (delete-region beg end)
2170 ;;; @ multipart enclosure
2173 (defun mime-editor/enclose-region (type beg end)
2176 (let ((current (point))
2179 (if (mime-editor/goto-tag)
2180 (or (eq current (match-beginning 0))
2181 (setq exist-prev-tag t)
2184 (narrow-to-region beg end)
2189 (insert (format "--<<%s>>-{\n" type))
2190 (goto-char (point-max))
2191 (insert (format "\n--}-<<%s>>\n" type))
2192 (goto-char (point-max))
2194 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
2196 (insert (mime-make-text-tag) "\n")
2200 (defun mime-editor/enclose-mixed-region (beg end)
2202 (mime-editor/enclose-region "mixed" beg end)
2205 (defun mime-editor/enclose-parallel-region (beg end)
2207 (mime-editor/enclose-region "parallel" beg end)
2210 (defun mime-editor/enclose-digest-region (beg end)
2212 (mime-editor/enclose-region "digest" beg end)
2215 (defun mime-editor/enclose-alternative-region (beg end)
2217 (mime-editor/enclose-region "alternative" beg end)
2220 (defun mime-editor/enclose-signed-region (beg end)
2222 (if mime-editor/signing-type
2223 (mime-editor/enclose-region "signed" beg end)
2224 (message "Please specify signing type.")
2227 (defun mime-editor/enclose-encrypted-region (beg end)
2229 (if mime-editor/signing-type
2230 (mime-editor/enclose-region "encrypted" beg end)
2231 (message "Please specify encrypting type.")
2234 (defun mime-editor/insert-key (&optional arg)
2235 "Insert a pgp public key."
2237 (mime-editor/insert-tag "application" "pgp-keys")
2238 (mime-editor/define-encoding "7bit")
2239 (mc-insert-public-key)
2246 (defun mime-editor/set-split (arg)
2249 (y-or-n-p "Do you want to enable split?")
2251 (setq mime-editor/split-message arg)
2253 (message "This message is enabled to split.")
2254 (message "This message is not enabled to split.")
2261 (defun mime-editor/set-sign (arg)
2264 (y-or-n-p "Do you want to sign?")
2268 (setq mime-editor/pgp-processing 'sign)
2269 (message "This message will be signed.")
2271 (if (eq mime-editor/pgp-processing 'sign)
2272 (setq mime-editor/pgp-processing nil)
2274 (message "This message will not be signed.")
2277 (defun mime-editor/set-encrypt (arg)
2280 (y-or-n-p "Do you want to encrypt?")
2284 (setq mime-editor/pgp-processing 'encrypt)
2285 (message "This message will be encrypt.")
2287 (if (eq mime-editor/pgp-processing 'encrypt)
2288 (setq mime-editor/pgp-processing nil)
2290 (message "This message will not be encrypt.")
2293 (defvar mime-editor/pgp-processing nil)
2294 (make-variable-buffer-local 'mime-editor/pgp-processing)
2296 (defun mime-editor/call-mc (command)
2297 (let* ((header (rfc822/get-header-string-except
2298 "^Content-Type:" mail-header-separator)))
2299 (goto-char (point-min))
2300 (if (search-forward mail-header-separator)
2303 (goto-char (point-min))
2305 (insert "Content-Type: application/pgp; format=mime\n")
2306 (insert mail-header-separator)
2308 (if (null (call-interactively command))
2309 (throw 'mime-editor/error 'pgp-error)
2313 (defun mime-editor/pgp-processing ()
2315 (cdr (assq mime-editor/pgp-processing
2317 (encrypt . mc-encrypt)
2320 (mime-editor/call-mc command)
2327 (defun mime-editor/insert-partial-header
2328 (fields subject id number total separator)
2330 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2331 (insert (format "Mime-Version: 1.0 (split by tm-edit %s)\n"
2332 mime-editor/version))
2334 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2335 id number total separator))
2338 (defun mime-editor/split-and-send
2339 (&optional cmd lines mime-editor/message-max-length)
2343 (count-lines (point-min) (point-max)))
2345 (or mime-editor/message-max-length
2346 (setq mime-editor/message-max-length
2347 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2348 mime-editor/message-default-max-length))
2350 (let* ((mime-editor/draft-file-name
2351 (or (buffer-file-name)
2353 (expand-file-name "tm-draft" mime/tmp-dir))))
2354 (separator mail-header-separator)
2356 (eval (cdr (assq major-mode mime-editor/window-config-alist))))
2358 (replace-space-with-underline (current-time-string))
2359 "@" (system-name) "\"")))
2360 (run-hooks 'mime-editor/before-split-hook)
2361 (let* ((header (rfc822/get-header-string-except
2362 mime-editor/split-ignored-field-regexp separator))
2363 (subject (mail-fetch-field "subject"))
2364 (total (+ (/ lines mime-editor/message-max-length)
2365 (if (> (mod lines mime-editor/message-max-length) 0)
2367 (the-buf (current-buffer))
2368 (buf (get-buffer "*tmp-send*"))
2373 mime-editor/split-message-sender-alist))
2376 mime-editor/message-default-sender-alist))
2379 (goto-char (point-min))
2380 (if (re-search-forward (concat "^" (regexp-quote separator) "$")
2386 (switch-to-buffer buf)
2388 (switch-to-buffer the-buf)
2390 (setq buf (get-buffer-create "*tmp-send*"))
2392 (switch-to-buffer buf)
2393 (make-local-variable 'mail-header-separator)
2394 (setq mail-header-separator separator)
2395 (switch-to-buffer the-buf)
2396 (goto-char (point-min))
2397 (re-search-forward "^$" nil t)
2398 (let ((mime-editor/partial-number 1))
2399 (setq data (buffer-substring
2402 (goto-line mime-editor/message-max-length)
2405 (delete-region (point-min)(point))
2406 (switch-to-buffer buf)
2407 (mime-editor/insert-partial-header
2408 header subject id mime-editor/partial-number total separator)
2412 (goto-char (point-min))
2413 (search-forward (concat "\n" mail-header-separator "\n"))
2416 (if (re-search-forward "^$" nil t)
2420 (goto-char (point-min))
2421 (while (re-search-forward
2422 mime-editor/split-blind-field-regexp nil t)
2423 (delete-region (match-beginning 0)
2424 (let ((e (rfc822/field-end)))
2425 (if (< e (point-max))
2431 (message (format "Sending %d/%d..."
2432 mime-editor/partial-number total))
2433 (call-interactively command)
2434 (message (format "Sending %d/%d... done"
2435 mime-editor/partial-number total))
2438 (switch-to-buffer the-buf)
2439 (setq mime-editor/partial-number 2)
2440 (while (< mime-editor/partial-number total)
2441 (setq data (buffer-substring
2444 (goto-line mime-editor/message-max-length)
2447 (delete-region (point-min)(point))
2448 (switch-to-buffer buf)
2449 (mime-editor/insert-partial-header
2450 header subject id mime-editor/partial-number total separator)
2453 (message (format "Sending %d/%d..."
2454 mime-editor/partial-number total))
2455 (call-interactively command)
2456 (message (format "Sending %d/%d... done"
2457 mime-editor/partial-number total))
2460 (switch-to-buffer the-buf)
2461 (setq mime-editor/partial-number
2462 (1+ mime-editor/partial-number))
2464 (goto-char (point-min))
2465 (mime-editor/insert-partial-header
2466 header subject id mime-editor/partial-number total separator)
2467 (message (format "Sending %d/%d..."
2468 mime-editor/partial-number total))
2471 (defun mime-editor/maybe-split-and-send (&optional cmd)
2473 (run-hooks 'mime-editor/before-send-hook)
2474 (let ((mime-editor/message-max-length
2475 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2476 mime-editor/message-default-max-length))
2477 (lines (count-lines (point-min) (point-max)))
2479 (if (and (> lines mime-editor/message-max-length)
2480 mime-editor/split-message)
2481 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2485 ;;; @ preview message
2488 (defun mime-editor/preview-message ()
2489 "preview editing MIME message. [tm-edit.el]"
2491 (let* ((str (buffer-string))
2492 (separator mail-header-separator)
2493 (the-buf (current-buffer))
2494 (buf-name (buffer-name))
2495 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2496 (buf (get-buffer temp-buf-name))
2500 (switch-to-buffer buf)
2503 (setq buf (get-buffer-create temp-buf-name))
2504 (switch-to-buffer buf)
2507 (setq major-mode 'mime/temporary-message-mode)
2508 (make-local-variable 'mail-header-separator)
2509 (setq mail-header-separator separator)
2510 (make-local-variable 'mime/editing-buffer)
2511 (setq mime/editing-buffer the-buf)
2513 (run-hooks 'mime-editor/translate-hook)
2514 (mime-editor/translate-buffer)
2515 (goto-char (point-min))
2516 (if (re-search-forward
2517 (concat "^" (regexp-quote separator) "$"))
2523 (defun mime-editor/quitting-method ()
2524 (let ((temp mime::preview/article-buffer)
2526 (mime-viewer/kill-buffer)
2528 (setq buf mime/editing-buffer)
2530 (switch-to-buffer buf)
2533 (set-alist 'mime-viewer/quitting-method-alist
2534 'mime/temporary-message-mode
2535 (function mime-editor/quitting-method)
2541 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2542 ;; Mon, 10 Apr 1995 20:03:07 +0900
2544 (defvar mime-editor/draft-header-separator-alist
2545 '((news-reply-mode . mail-header-separator)
2546 (mh-letter-mode . mail-header-separator)
2549 (defvar mime::article/draft-header-separator nil)
2551 (defun mime-editor/draft-preview ()
2553 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2554 (or (stringp sep) (setq sep (eval sep)))
2555 (make-variable-buffer-local 'mime::article/draft-header-separator)
2556 (goto-char (point-min))
2558 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2559 (setq mime::article/draft-header-separator
2560 (buffer-substring (match-beginning 0) (match-end 0)))
2562 (mime/viewer-mode (current-buffer))
2563 (pop-to-buffer (current-buffer))
2566 (defun mime-viewer::quitting-method/draft-preview ()
2567 (let ((mother mime::preview/mother-buffer))
2569 (switch-to-buffer mother)
2570 (goto-char (point-min))
2574 (regexp-quote mime::article/draft-header-separator)
2578 (insert mime::article/draft-header-separator)
2579 (set-buffer-modified-p (buffer-modified-p))
2581 (mime-viewer/kill-buffer)
2582 (pop-to-buffer mother)
2585 (set-alist 'mime-viewer/quitting-method-alist
2587 (function mime-viewer::quitting-method/draft-preview)
2590 (set-alist 'mime-viewer/quitting-method-alist
2592 (function mime-viewer::quitting-method/draft-preview)
2599 (defun replace-space-with-underline (str)
2600 (mapconcat (function
2614 (run-hooks 'tm-edit-load-hook)
2616 ;;; tm-edit.el ends here