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.62 $
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.62 1996/05/19 16:16:42 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-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 "text" "plain" nil nil)
343 "application" "octet-stream" nil
345 "attachment" (("filename" . file))
348 "*Alist of file name, types, parameters, and default encoding.
349 If encoding is nil, it is determined from its contents.")
351 ;;; @@ about charset, encoding and transfer-level
354 (defvar mime-editor/transfer-level 7
355 "*A number of network transfer level. It should be bigger than 7.")
356 (make-variable-buffer-local 'mime-editor/transfer-level)
358 (defvar mime-editor/transfer-level-string
359 (mime/encoding-name mime-editor/transfer-level 'not-omit)
360 "*A string formatted version of mime/defaul-transfer-level")
361 (make-variable-buffer-local 'mime-editor/transfer-level-string)
363 (defvar mime-editor/charset-default-encoding-alist
364 (mime/make-charset-default-encoding-alist mime-editor/transfer-level))
365 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
367 ;;; @@ about message inserting
370 (defvar mime-editor/yank-ignored-field-list
371 '("Received" "Sender" "Approved" "Path" "Status" "X-VM-.*" "X-UIDL")
372 "Delete these fields from original message when it is inserted
373 as message/rfc822 part.
374 Each elements are regexp of field-name. [tm-edit.el]")
376 (defvar mime-editor/yank-ignored-field-regexp
378 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
381 (defvar mime-editor/message-inserter-alist nil)
382 (defvar mime-editor/mail-inserter-alist nil)
384 ;;; @@ about message splitting
387 (defvar mime-editor/split-message t
388 "*Split large message if it is non-nil. [tm-edit.el]")
390 (defvar mime-editor/message-default-max-length 1000
391 "*Default maximum size of a message. [tm-edit.el]")
393 (defvar mime-editor/message-max-length-alist
394 '((news-reply-mode . 500)))
396 (defconst mime-editor/split-ignored-field-regexp
397 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
399 (defvar mime-editor/split-blind-field-regexp
400 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
402 (defvar mime-editor/message-default-sender-alist
403 '((mail-mode . mail-send-and-exit)
404 (mh-letter-mode . mh-send-letter)
405 (news-reply-mode . gnus-inews-news)
408 (defvar mime-editor/split-message-sender-alist
415 . (lambda (&optional arg)
417 (write-region (point-min) (point-max)
418 mime-editor/draft-file-name nil 'no-message)
420 (pop-to-buffer "MH mail delivery")
422 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
424 mh-send-args mime-editor/draft-file-name)
425 (goto-char (point-max)) ; show the interesting part
429 (apply 'mh-exec-cmd-quiet t mh-send-prog
431 (list "-nopush" "-nodraftfolder"
432 "-noverbose" "-nowatch"
433 mh-send-args mime-editor/draft-file-name)))))
437 (defvar mime-editor/window-config-alist
439 (mh-letter-mode . mh-previous-window-config)
440 (news-reply-mode . (cond ((boundp 'gnus-winconf-post-news)
442 gnus-winconf-post-news
443 (setq gnus-winconf-post-news nil)
445 ((boundp 'gnus-prev-winconf)
448 (setq gnus-prev-winconf nil)
453 (defvar mime-editor/news-reply-mode-server-running nil)
459 (defvar mime-editor/signing-type nil
460 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
462 (defvar mime-editor/encrypting-type nil
463 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
465 (if (or mime-editor/signing-type mime-editor/encrypting-type)
473 (defconst mime-editor/single-part-tag-regexp
474 "^--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
475 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
477 (defconst mime-editor/multipart-beginning-regexp "^--<<\\([^<>]+\\)>>-{\n")
479 (defconst mime-editor/multipart-end-regexp "^--}-<<\\([^<>]+\\)>>\n")
481 (defconst mime-editor/beginning-tag-regexp
482 (regexp-or mime-editor/single-part-tag-regexp
483 mime-editor/multipart-beginning-regexp))
485 (defconst mime-editor/end-tag-regexp
486 (regexp-or mime-editor/single-part-tag-regexp
487 mime-editor/multipart-end-regexp))
489 (defconst mime-editor/tag-regexp
490 (regexp-or mime-editor/single-part-tag-regexp
491 mime-editor/multipart-beginning-regexp
492 mime-editor/multipart-end-regexp))
494 (defvar mime-tag-format "--[[%s]]"
495 "*Control-string making a MIME tag.")
497 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
498 "*Control-string making a MIME tag with encoding.")
500 ;;; @@ multipart boundary
503 (defvar mime-multipart-boundary "Multipart"
504 "*Boundary of a multipart message.")
507 ;;; @@ buffer local variables
510 (defvar mime/editor-mode-old-local-map nil)
511 (defvar mime/editor-mode-old-selective-display nil)
512 (defvar mime/editing-buffer nil)
518 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
519 "*Specify MIME tspecials.
520 Tspecials means any character that matches with it in header must be quoted.")
522 (defconst mime-editor/mime-version-value
523 (format "1.0 (generated by tm-edit %s)" mime-editor/version)
524 "MIME version number.")
526 (defconst mime-editor/mime-map (make-sparse-keymap)
527 "Keymap for MIME commands.")
529 ;;; @ keymap and menu
532 (defvar mime/editor-mode-flag nil)
533 (make-variable-buffer-local 'mime/editor-mode-flag)
535 (set-alist 'minor-mode-alist
536 'mime/editor-mode-flag
537 '((" MIME-Edit " mime-editor/transfer-level-string)))
539 (defun mime-editor/define-keymap (keymap)
540 "Add mime-editor commands to KEYMAP."
541 (if (not (keymapp keymap))
543 (define-key keymap "\C-t" 'mime-editor/insert-text)
544 (define-key keymap "\C-i" 'mime-editor/insert-file)
545 (define-key keymap "\C-e" 'mime-editor/insert-external)
546 (define-key keymap "\C-v" 'mime-editor/insert-voice)
547 (define-key keymap "\C-y" 'mime-editor/insert-message)
548 (define-key keymap "\C-m" 'mime-editor/insert-mail)
549 (define-key keymap "\C-w" 'mime-editor/insert-signature)
550 (define-key keymap "\C-s" 'mime-editor/insert-signature)
551 (define-key keymap "\C-k" 'mime-editor/insert-key)
552 (define-key keymap "t" 'mime-editor/insert-tag)
553 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
554 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
555 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
556 (define-key keymap "d" 'mime-editor/enclose-digest-region)
557 (define-key keymap "s" 'mime-editor/enclose-signed-region)
558 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
559 (define-key keymap "\C-p" 'mime-editor/preview-message)
560 (define-key keymap "\C-z" 'mime-editor/exit)
561 (define-key keymap "?" 'mime-editor/help)
564 (mime-editor/define-keymap mime-editor/mime-map)
566 (defconst mime-editor/menu-title "MIME-Edit")
568 (defconst mime-editor/menu-list
569 '((mime-help "Describe MIME editor mode" mime-editor/help)
570 (file "Insert File" mime-editor/insert-file)
571 (external "Insert External" mime-editor/insert-external)
572 (voice "Insert Voice" mime-editor/insert-voice)
573 (message "Insert Message" mime-editor/insert-message)
574 (mail "Insert Mail" mime-editor/insert-mail)
575 (signature "Insert Signature" mime-editor/insert-signature)
576 (text "Insert Text" mime-editor/insert-text)
577 (tag "Insert Tag" mime-editor/insert-tag)
578 (alternative "Enclose as alternative"
579 mime-editor/enclose-alternative-region)
580 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
581 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
582 (digest "Enclose as digest" mime-editor/enclose-digest-region)
583 (signed "Enclose as signed" mime-editor/enclose-signed-region)
584 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
585 (key "Insert Public Key" mime-editor/insert-key)
586 (split "About split" mime-editor/set-split)
587 (sign "About sign" mime-editor/set-sign)
588 (encrypt "About encryption" mime-editor/set-encrypt)
589 (preview "Preview Message" mime-editor/preview-message)
590 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
592 "MIME-edit menubar entry.")
594 (defun mime-editor/define-menu-for-emacs19 ()
595 "Define menu for Emacs 19."
596 (define-key (current-local-map) [menu-bar mime-edit]
597 (cons mime-editor/menu-title
598 (make-sparse-keymap mime-editor/menu-title)))
601 (define-key (current-local-map)
602 (vector 'menu-bar 'mime-edit (car item))
603 (cons (nth 1 item)(nth 2 item))
606 (reverse mime-editor/menu-list)
609 ;;; modified by Pekka Marjola <pema@iki.fi>
610 ;;; 1995/9/5 (c.f. [tm-en:69])
611 (defun mime-editor/define-menu-for-xemacs ()
612 "Define menu for Emacs 19."
613 (cond ((featurep 'menubar)
614 (make-local-variable 'current-menubar)
615 (set-buffer-menubar current-menubar)
617 (cons mime-editor/menu-title
620 (vector (nth 1 item)(nth 2 item)
621 mime/editor-mode-flag)
623 mime-editor/menu-list)))
626 ;;; modified by Steven L. Baur <steve@miranova.com>
627 ;;; 1995/12/6 (c.f. [tm-en:209])
628 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
629 (setq mime-editor/popup-menu-for-xemacs
630 (append '("MIME Commands" "---")
631 (mapcar (function (lambda (item)
635 mime-editor/menu-list)))
644 (defun mime/editor-mode ()
645 "MIME minor mode for editing the tagged MIME message.
647 In this mode, basically, the message is composed in the tagged MIME
648 format. The message tag looks like:
650 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
652 The tag specifies the MIME content type, subtype, optional parameters
653 and transfer encoding of the message following the tag. Messages
654 without any tag are treated as `text/plain' by default. Charset and
655 transfer encoding are automatically defined unless explicitly
656 specified. Binary messages such as audio and image are usually hidden
657 using selective-display facility. The messages in the tagged MIME
658 format are automatically translated into a MIME compliant message when
661 Available charsets depend on Emacs version being used. The following
662 lists the available charsets of each emacs.
664 Emacs18: US-ASCII is only available.
665 NEmacs: US-ASCII and ISO-2022-JP are available.
666 Emacs19: US-ASCII and ISO-8859-1 are available.
667 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-6),
668 ISO-2022-JP, ISO-2022-JP-2 and ISO-2022-INT-1 are available.
670 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in Mule is expected to
671 be used to represent multilingual text in intermixed manner. Any
672 languages that has no registered charset are represented as either
673 ISO-2022-JP-2 or ISO-2022-INT-1 in Mule.
675 Following commands are available in addition to major mode commands:
676 \\[mime-editor/insert-text] insert a text message.
677 \\[mime-editor/insert-file] insert a (binary) file.
678 \\[mime-editor/insert-external] insert a reference to external body.
679 \\[mime-editor/insert-voice] insert a voice message.
680 \\[mime-editor/insert-message] insert a mail or news message.
681 \\[mime-editor/insert-mail] insert a mail message.
682 \\[mime-editor/insert-signature] insert a signature file at end.
683 \\[mime-editor/insert-tag] insert a new MIME tag.
684 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
685 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
686 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
687 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
688 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
689 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
690 \\[mime-editor/insert-key] insert PGP public key.
691 \\[mime-editor/preview-message] preview editing MIME message.
692 \\[mime-editor/exit] exit and translate into a MIME compliant message.
693 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
694 \\[mime-editor/help] show this help.
696 Additional commands are available in some major modes:
697 C-c C-c exit, translate and run the original command.
698 C-c C-s exit, translate and run the original command.
700 The following is a message example written in the tagged MIME format.
701 TABs at the beginning of the line are not a part of the message:
703 This is a conventional plain text. It should be translated
706 This is also a plain text. But, it is explicitly specified as
708 --[[text/plain; charset=ISO-2022-JP]]
709 \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
712 <center>This is a richtext.</center>
713 --[[image/gif][base64]]^M...image encoded in base64 here...
714 --[[audio/basic][base64]]^M...audio encoded in base64 here...
716 User customizable variables (not documented all of them):
718 Specifies a key prefix for MIME minor mode commands.
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 record a voice message and return a buffer
735 that contains it. The function mime-voice-recorder-for-sun is for
738 mime/editor-mode-hook
739 Turning on MIME mode calls the value of mime/editor-mode-hook, if
742 mime-editor/translate-hook
743 The value of mime-editor/translate-hook is called just before translating
744 the tagged MIME format into a MIME compliant message if it is
745 non-nil. If the hook call the function mime-editor/insert-signature,
746 the signature file will be inserted automatically.
748 mime-editor/exit-hook
749 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
752 (if mime/editor-mode-flag
753 (error "You are already editing a MIME message.")
754 (setq mime/editor-mode-flag t)
755 ;; Remember old key bindings.
758 (make-local-variable 'mime/editor-mode-old-local-map)
759 (setq mime/editor-mode-old-local-map (current-local-map))
760 ;; Add MIME commands to current local map.
761 (use-local-map (copy-keymap (current-local-map)))
763 (if (not (lookup-key (current-local-map) mime-prefix))
764 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
766 ;; Set transfer level into mode line
768 (setq mime-editor/transfer-level-string
769 (mime/encoding-name mime-editor/transfer-level 'not-omit))
770 (force-mode-line-update)
772 ;; Define menu. Menus for other emacs implementations are
774 (cond (running-xemacs
775 (mime-editor/define-menu-for-xemacs))
776 ((>= emacs-major-version 19)
777 (mime-editor/define-menu-for-emacs19)
781 ;; Remember old selective-display.
782 (make-local-variable 'mime/editor-mode-old-selective-display)
783 (setq mime/editor-mode-old-selective-display selective-display)
784 (setq selective-display t)
785 ;; I don't care about saving these.
786 (setq paragraph-start
787 (regexp-or mime-editor/single-part-tag-regexp
789 (setq paragraph-separate
790 (regexp-or mime-editor/single-part-tag-regexp
792 (run-hooks 'mime/editor-mode-hook)
794 (substitute-command-keys
795 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
799 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
800 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
802 (defun mime-editor/exit (&optional nomime no-error)
803 "Translate the tagged MIME message into a MIME compliant message.
804 With no argument encode a message in the buffer into MIME, otherwise
805 just return to previous mode."
807 (if (not mime/editor-mode-flag)
809 (error "You aren't editing a MIME message.")
813 (run-hooks 'mime-editor/translate-hook)
814 (mime-editor/translate-buffer)))
815 ;; Restore previous state.
816 (setq mime/editor-mode-flag nil)
817 (cond (running-xemacs
818 ;; mime-prefix only defined if binding was nil
819 (if (eq (lookup-key (current-local-map) mime-prefix)
820 mime-editor/mime-map)
821 (define-key (current-local-map) mime-prefix nil))
822 (delete-menu-item (list mime-editor/menu-title)))
824 (use-local-map mime/editor-mode-old-local-map)))
826 (setq selective-display mime/editor-mode-old-selective-display)
827 (set-buffer-modified-p (buffer-modified-p))
828 (run-hooks 'mime-editor/exit-hook)
829 (message "Exit MIME editor mode.")
832 (defun mime-editor/maybe-translate ()
834 (mime-editor/exit nil t)
835 (call-interactively 'mime-editor/maybe-split-and-send)
838 (defun mime-editor/help ()
839 "Show help message about MIME mode."
841 (with-output-to-temp-buffer "*Help*"
842 (princ "MIME editor mode:\n")
843 (princ (documentation 'mime/editor-mode))
844 (print-help-return-message)))
846 (defun mime-editor/insert-text ()
847 "Insert a text message.
848 Charset is automatically obtained from the `mime/lc-charset-alist'."
850 (if (and (mime-editor/insert-tag "text" nil nil)
851 (looking-at mime-editor/single-part-tag-regexp))
853 ;; Make a space between the following message.
858 (defun mime-editor/insert-file (file)
859 "Insert a message from a file."
860 (interactive "fInsert file as MIME message: ")
861 (let* ((guess (mime-find-file-type file))
862 (pritype (nth 0 guess))
863 (subtype (nth 1 guess))
864 (parameters (nth 2 guess))
865 (default (nth 3 guess)) ;Guess encoding from its file name.
866 (disposition-type (nth 4 guess))
867 (disposition-params (nth 5 guess))
869 (if (not (interactive-p))
872 (concat "What transfer encoding"
875 (if (string-equal default "")
881 mime-encoding-method-alist nil t nil))))
882 (if (string-equal encoding "")
883 (setq encoding default))
884 (if (or (consp parameters) (stringp disposition-type))
885 (let ((rest parameters) cell attribute value)
888 (setq cell (car rest))
889 (setq attribute (car cell))
890 (setq value (cdr cell))
892 (setq value (rfc822/wrap-as-quoted-string
893 (file-name-nondirectory file)))
895 (setq parameters (concat parameters "; " attribute "=" value))
896 (setq rest (cdr rest))
901 (concat parameters "\n"
902 "Content-Disposition: " disposition-type))
903 (setq rest disposition-params)
905 (setq cell (car rest))
906 (setq attribute (car cell))
907 (setq value (cdr cell))
909 (setq value (rfc822/wrap-as-quoted-string
910 (file-name-nondirectory file)))
913 (concat parameters "; " attribute "=" value))
914 (setq rest (cdr rest))
918 (mime-editor/insert-tag pritype subtype parameters)
919 (mime-editor/insert-binary-file file encoding)
922 (defun mime-editor/insert-external ()
923 "Insert a reference to external body."
925 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
927 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
929 (let* ((pritype (mime-prompt-for-type))
930 (subtype (mime-prompt-for-subtype pritype))
931 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
934 (insert "Content-Type: "
935 pritype "/" subtype (or parameters "") "\n")))
936 (if (and (not (eobp))
937 (not (looking-at mime-editor/single-part-tag-regexp)))
938 (insert (mime-make-text-tag) "\n")))
940 (defun mime-editor/insert-voice ()
941 "Insert a voice message."
943 (mime-editor/insert-tag "audio" "basic" nil)
944 (let ((buffer (funcall mime-voice-recorder)))
946 (mime-editor/insert-binary-buffer buffer "base64")
950 (defun mime-editor/insert-signature (&optional arg)
951 "Insert a signature file."
953 (let ((signature-insert-hook
956 (apply (function mime-editor/insert-tag)
957 (mime-find-file-type signature))
960 (insert-signature arg)
964 ;; Insert a new tag around a point.
966 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
967 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
968 If nothing is inserted, return nil."
973 exist-prev-tag exist-next-tag)
976 (mime-prompt-for-type)))
979 (mime-prompt-for-subtype pritype)))
982 (mime-prompt-for-parameters pritype subtype delimiter)))
983 ;; Make a new MIME tag.
984 (setq newtag (mime-make-tag pritype subtype parameters))
985 ;; Find an current MIME tag.
988 (if (mime-editor/goto-tag)
990 (if (eq current (match-beginning 0))
991 (setq exist-next-tag t)
992 (setq exist-prev-tag t)
994 (buffer-substring (match-beginning 0) (match-end 0))
996 ;; Assume content type is 'text/plan'.
997 (mime-make-tag "text" "plain")
999 ;; We are only interested in TEXT.
1001 (not (mime-test-content-type
1002 (mime-editor/get-contype oldtag) "text")))
1004 (cond (exist-prev-tag (insert "\n"))
1005 (exist-next-tag (save-excursion
1014 (if (or (not oldtag) ;Not text
1015 (or mime-ignore-same-text-tag
1016 (not (string-equal oldtag newtag))))
1018 ;; Mark the beginning of the tag for convenience.
1019 (push-mark (point) 'nomsg)
1020 (insert newtag "\n")
1021 (list pritype subtype parameters) ;New tag is created.
1023 ;; Restore previous point.
1025 nil ;Nothing is created.
1029 ;; Insert the binary content after MIME tag.
1030 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1032 (defun mime-editor/insert-binary-file (file &optional encoding)
1033 "Insert binary FILE at point.
1034 Optional argument ENCODING specifies an encoding method such as base64."
1035 (let ((tmpbuf (get-buffer-create " *MIME insert*")))
1039 (let ((mc-flag nil) ;Mule
1040 (file-coding-system-for-read
1041 (if (featurep 'mule) *noconv*))
1042 (kanji-flag nil) ;NEmacs
1043 (emx-binary-mode t) ;Stop CRLF to LF conversion in OS/2
1045 (let (jka-compr-compression-info-list
1046 jam-zcat-filename-list)
1047 (insert-file-contents file))))
1049 (if (and (stringp encoding)
1050 (string-equal (downcase encoding) "x-uue"))
1053 (let ((uuencode-external-encoder
1054 (cons (car uuencode-external-encoder)
1055 (list (file-name-nondirectory file))
1057 (mime-editor/insert-binary-buffer tmpbuf encoding)
1059 (mime-editor/insert-binary-buffer tmpbuf encoding))
1060 (kill-buffer tmpbuf))))
1062 ;; Insert the binary content after MIME tag.
1063 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1065 (defun mime-editor/insert-binary-buffer (buffer &optional encoding)
1066 "Insert binary BUFFER at point.
1067 Optional argument ENCODING specifies an encoding method such as base64."
1068 (let* ((tagend (1- (point))) ;End of the tag
1069 (hide-p (and mime-auto-hide-body
1071 (let ((en (downcase encoding)))
1072 (or (string-equal en "base64")
1073 (string-equal en "x-uue")
1077 (narrow-to-region (1- (point)) (point))
1078 (let ((start (point))
1079 (emx-binary-mode t)) ;Stop LF to CRLF conversion in OS/2
1080 (insert-buffer-substring buffer)
1081 ;; Encode binary message if necessary.
1083 (mime-encode-region encoding start (point-max))))
1086 (mime-flag-region (point-min) (1- (point-max)) ?\^M)
1087 (goto-char (point-max)))
1089 ;; Define encoding even if it is 7bit.
1090 (if (stringp encoding)
1092 (goto-char tagend) ;Make sure which line the tag is on.
1093 (mime-editor/define-encoding encoding)))
1097 ;; Commands work on a current message flagment.
1099 (defun mime-editor/goto-tag ()
1100 "Search for the beginning of the tagged MIME message."
1101 (let ((current (point)) multipart)
1102 (if (looking-at mime-editor/tag-regexp)
1104 ;; At first, go to the end.
1105 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1106 (goto-char (match-beginning 0)) ;For multiline tag
1111 (goto-char (point-max))
1113 ;; Then search for the beginning.
1114 (re-search-backward mime-editor/end-tag-regexp nil t)
1116 (or (looking-at mime-editor/beginning-tag-regexp)
1117 ;; Restore previous point.
1124 (defun mime-editor/content-beginning ()
1125 "Return the point of the beginning of content."
1127 (let ((beg (save-excursion
1128 (beginning-of-line) (point))))
1129 (if (mime-editor/goto-tag)
1130 (let ((top (point)))
1131 (goto-char (match-end 0))
1132 (if (and (= beg top)
1133 (= (following-char) ?\^M))
1137 ;; Default text/plain tag.
1138 (goto-char (point-min))
1140 (concat "\n" (regexp-quote mail-header-separator)
1141 (if mime-ignore-preceding-spaces
1142 "[ \t\n]*\n" "\n")) nil 'move)
1146 (defun mime-editor/content-end ()
1147 "Return the point of the end of content."
1149 (let ((beg (save-excursion
1150 (beginning-of-line) (point))))
1151 (if (mime-editor/goto-tag)
1152 (let ((top (point)))
1153 (goto-char (match-end 0))
1154 (if (and (= beg top) ;Must be on the same line.
1155 (= (following-char) ?\^M))
1159 ;; Move to the end of this text.
1160 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1161 ;; Don't forget a multiline tag.
1162 (goto-char (match-beginning 0)))
1165 ;; Assume the message begins with text/plain.
1166 (goto-char (mime-editor/content-beginning))
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 (defun mime-editor/define-charset (charset)
1174 "Set charset of current tag to CHARSET."
1176 (if (mime-editor/goto-tag)
1177 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1178 (delete-region (match-beginning 0) (match-end 0))
1180 (mime-create-tag (mime-set-parameter
1181 (mime-editor/get-contype tag) "charset" charset)
1182 (mime-editor/get-encoding tag))))
1185 (defun mime-editor/define-encoding (encoding)
1186 "Set encoding of current tag to ENCODING."
1188 (if (mime-editor/goto-tag)
1189 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1190 (delete-region (match-beginning 0) (match-end 0))
1191 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1194 (defun mime-editor/choose-charset ()
1195 "Choose charset of a text following current point."
1196 (mime/find-charset-region (point) (mime-editor/content-end))
1199 (defun mime-make-text-tag (&optional subtype)
1200 "Make a tag for a text after current point.
1201 Subtype of text type can be specified by an optional argument SUBTYPE.
1202 Otherwise, it is obtained from mime-content-types."
1203 (let* ((pritype "text")
1204 (subtype (or subtype
1205 (car (car (cdr (assoc pritype mime-content-types)))))))
1206 ;; Charset should be defined later.
1207 (mime-make-tag pritype subtype)))
1210 ;; Tag handling functions
1212 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1213 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1214 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1218 (defun mime-create-tag (contype &optional encoding)
1219 "Make a tag with CONTENT-TYPE and optional ENCODING."
1220 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1223 (defun mime-editor/get-contype (tag)
1224 "Return Content-Type (including parameters) of TAG."
1226 (or (string-match mime-editor/single-part-tag-regexp tag)
1227 (string-match mime-editor/multipart-beginning-regexp tag)
1228 (string-match mime-editor/multipart-end-regexp tag)
1230 (substring tag (match-beginning 1) (match-end 1))
1233 (defun mime-editor/get-encoding (tag)
1234 "Return encoding of TAG."
1236 (string-match mime-editor/single-part-tag-regexp tag)
1238 (not (= (match-beginning 3) (match-end 3)))
1239 (substring tag (match-beginning 3) (match-end 3))))
1241 (defun mime-get-parameter (contype parameter)
1242 "For given CONTYPE return value for PARAMETER.
1243 Nil if no such parameter."
1247 (regexp-quote parameter)
1248 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1250 (substring contype (match-beginning 1) (match-end 1))
1251 nil ;No such parameter
1254 (defun mime-set-parameter (contype parameter value)
1255 "For given CONTYPE set PARAMETER to VALUE."
1259 (regexp-quote parameter)
1260 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1263 (concat (substring contype 0 (match-beginning 1))
1265 (substring contype (match-end 1)))
1266 (concat contype "; " parameter "=" value)))
1268 (defun mime-strip-parameters (contype)
1269 "Return primary content-type and subtype without parameters for CONTYPE."
1270 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1271 (substring contype (match-beginning 1) (match-end 1)) nil))
1273 (defun mime-test-content-type (contype type &optional subtype)
1274 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1275 (and (stringp contype)
1278 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1279 (downcase contype))))
1284 (defun mime-find-file-type (file)
1285 "Guess Content-Type, subtype, and parameters from FILE."
1287 (guesses mime-file-types))
1288 (while (and (not guess) guesses)
1289 (if (string-match (car (car guesses)) file)
1290 (setq guess (cdr (car guesses))))
1291 (setq guesses (cdr guesses)))
1295 (defun mime-prompt-for-type ()
1296 "Ask for Content-type."
1298 ;; Repeat until primary content type is specified.
1299 (while (string-equal type "")
1301 (completing-read "What content type: "
1304 'require-match ;Type must be specified.
1307 (if (string-equal type "")
1309 (message "Content type is required.")
1317 (defun mime-prompt-for-subtype (pritype)
1318 "Ask for Content-type subtype of Content-Type PRITYPE."
1319 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1324 "What content subtype: (default " default ") ")
1325 "What content subtype: ")
1326 (cdr (assoc pritype mime-content-types))
1328 'require-match ;Subtype must be specified.
1331 (if (string-equal answer "") default answer)))
1333 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1334 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1335 Optional DELIMITER specifies parameter delimiter (';' by default)."
1336 (let* ((delimiter (or delimiter "; "))
1341 (mime-prompt-for-parameters-1
1343 (cdr (assoc pritype mime-content-types))))))
1346 (if (and (stringp parameters)
1347 (not (string-equal parameters "")))
1348 (concat delimiter parameters)
1349 "" ;"" if no parameters
1352 (defun mime-prompt-for-parameters-1 (optlist)
1353 (apply (function append)
1354 (mapcar (function mime-prompt-for-parameter) optlist)))
1356 (defun mime-prompt-for-parameter (parameter)
1358 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1359 (let* ((prompt (car parameter))
1360 (choices (mapcar (function
1362 (if (consp e) e (list e))))
1364 (default (car (car choices)))
1370 (concat "What " prompt
1372 (if (string-equal default "") "\"\"" default)
1374 choices nil nil ""))
1375 ;; If nothing is selected, use default.
1376 (if (string-equal answer "")
1377 (setq answer default)))
1379 (read-string (concat "What " prompt ": "))))
1380 (cons (if (and answer
1381 (not (string-equal answer "")))
1383 ;; Note: control characters ignored!
1384 (if (string-match mime-tspecials-regexp answer)
1385 (concat "\"" answer "\"") answer)))
1386 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1389 (defun mime-flag-region (from to flag)
1390 "Hides or shows lines from FROM to TO, according to FLAG.
1391 If FLAG is `\\n' (newline character) then text is shown,
1392 while if FLAG is `\\^M' (control-M) the text is hidden."
1393 (let ((buffer-read-only nil) ;Okay even if write protected.
1394 (modp (buffer-modified-p)))
1396 (subst-char-in-region from to
1397 (if (= flag ?\n) ?\^M ?\n)
1399 (set-buffer-modified-p modp))))
1402 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1405 (defvar mime-editor/translate-buffer-hook
1406 '(mime-editor/pgp-enclose-buffer
1407 mime/encode-message-header
1408 mime-editor/translate-body))
1410 (defun mime-editor/translate-buffer ()
1411 "Encode the tagged MIME message in current buffer in MIME compliant message."
1413 (if (catch 'mime-editor/error
1415 (run-hooks 'mime-editor/translate-buffer-hook)
1419 (error "Translation error!")
1422 (defun mime-editor/find-inmost ()
1423 (goto-char (point-min))
1424 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1425 (let ((bb (match-beginning 0))
1427 (type (buffer-substring (match-beginning 1)(match-end 1)))
1429 (setq end-exp (format "^--}-<<%s>>\n" type))
1431 (if (re-search-forward end-exp nil t)
1433 (setq eb (match-beginning 0))
1434 (setq ee (match-end 0))
1436 (setq eb (point-max))
1437 (setq ee (point-max))
1439 (narrow-to-region be eb)
1441 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1443 (narrow-to-region (match-beginning 0)(point-max))
1444 (mime-editor/find-inmost)
1447 ;;(delete-region eb ee)
1448 (list type bb be eb)
1451 (defun mime-editor/process-multipart-1 (boundary)
1452 (let ((ret (mime-editor/find-inmost)))
1454 (let ((type (car ret))
1455 (bb (nth 1 ret))(be (nth 2 ret))
1458 (narrow-to-region bb eb)
1459 (delete-region bb be)
1460 (setq bb (point-min))
1461 (setq eb (point-max))
1464 (if (looking-at mime-editor/multipart-end-regexp)
1465 (let ((beg (match-beginning 0))
1468 (delete-region beg end)
1469 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
1471 (insert (concat (mime-make-text-tag) "\n"))
1473 (cond ((string= type "signed")
1474 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1475 (mime-editor/sign-pgp-elkins bb eb boundary)
1477 ((eq mime-editor/signing-type 'pgp-kazu)
1478 (mime-editor/sign-pgp-kazu bb eb boundary)
1481 ((string= type "encrypted")
1482 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1483 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1485 ((eq mime-editor/encrypting-type 'pgp-kazu)
1486 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1490 (nth 2 (mime-editor/translate-region bb eb
1494 (format "--[[multipart/%s;
1495 boundary=\"%s\"][7bit]]\n"
1501 (autoload 'mc-pgp-lookup-key "mc-pgp")
1502 (autoload 'mc-pgp-sign-region "mc-pgp")
1503 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1505 (defun tm:mc-pgp-generic-parser (result)
1506 (let ((ret (mc-pgp-generic-parser result)))
1508 (vector (car ret)(cdr ret))
1511 (defun tm:mc-process-region
1512 (beg end passwd program args parser &optional buffer boundary)
1513 (let ((obuf (current-buffer))
1514 (process-connection-type nil)
1515 mybuf result rgn proc)
1518 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1522 (buffer-disable-undo mybuf)
1524 (apply 'start-process "*PGP*" mybuf program args))
1527 (process-send-string proc (concat passwd "\n"))
1528 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1529 (process-send-region proc beg end)
1530 (process-send-eof proc)
1531 (while (eq 'run (process-status proc))
1532 (accept-process-output proc 5))
1533 (setq result (process-exit-status proc))
1534 ;; Hack to force a status_notify() in Emacs 19.29
1535 (delete-process proc)
1537 (goto-char (point-max))
1538 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1539 (delete-region (match-beginning 0) (match-end 0)))
1540 (goto-char (point-min))
1542 (while (search-forward "\r\n" nil t)
1543 (replace-match "\n"))
1544 ;; Hurm. FIXME; must get better result codes.
1545 (if (stringp result)
1546 (error "%s exited abnormally: '%s'" program result)
1547 (setq rgn (funcall parser result))
1548 ;; If the parser found something, migrate it
1554 (narrow-to-region beg end)
1556 (insert (format "--%s\n" boundary))
1557 (goto-char (point-max))
1558 (insert (format "\n--%s
1559 Content-Type: application/pgp-signature
1560 Content-Transfer-Encoding: 7bit
1563 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1564 (goto-char (point-max))
1565 (insert (format "\n--%s--\n" boundary))
1567 (delete-region beg end)
1569 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1572 (delete-region (car rgn) (cdr rgn)))))
1573 ;; Return nil on failure and exit code on success
1575 ;; Cleanup even on nonlocal exit
1576 (if (and proc (eq 'run (process-status proc)))
1577 (interrupt-process proc))
1579 (or buffer (null mybuf) (kill-buffer mybuf)))))
1581 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1582 (if (not (boundp 'mc-pgp-user-id))
1585 (let ((process-environment process-environment)
1586 (buffer (get-buffer-create mc-buffer-name))
1588 (parser (function mc-pgp-generic-parser))
1589 (pgp-path mc-pgp-path)
1591 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1595 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1596 (setenv "PGPPASSFD" "0")
1602 (list "+verbose=1" "+language=en"
1603 (format "+clearsig=%s" (if unclear "off" "on"))
1604 "+batchmode" "-u" (cdr key))))
1606 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1608 (message "Signing as %s ..." (car key))
1609 (if (tm:mc-process-region
1610 start end passwd pgp-path args parser buffer boundary)
1614 (goto-char (point-min))
1617 --[[multipart/signed; protocol=\"application/pgp-signature\";
1618 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1620 (message "Signing as %s ... Done." (car key))
1624 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1627 (narrow-to-region beg end)
1629 (mime-editor/translate-region beg end boundary))
1631 (encoding (nth 1 ret))
1633 (pgp-boundary (concat "pgp-sign-" boundary))
1636 (insert (format "Content-Type: %s\n" ctype))
1638 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1641 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1642 nil nil pgp-boundary)
1643 (throw 'mime-editor/error 'pgp-error)
1647 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1650 (let ((from (rfc822/get-field-body "From"))
1651 (to (rfc822/get-field-body "To"))
1652 (cc (rfc822/get-field-body "cc"))
1654 (narrow-to-region beg end)
1656 (mime-editor/translate-region beg end boundary))
1658 (encoding (nth 1 ret))
1660 (pgp-boundary (concat "pgp-" boundary))
1663 (if (and (stringp from)
1664 (not (string-equal from "")))
1665 (insert (format "From: %s\n" from))
1667 (if (and (stringp to)
1668 (not (string-equal to "")))
1670 (insert (format "To: %s\n" to))
1671 (setq recipients to)
1673 (if (and (stringp cc)
1674 (not (string-equal cc "")))
1676 (insert (format "cc: %s\n" cc))
1678 (setq recipients (concat recipients "," cc))
1679 (setq recipients cc)
1681 (insert (format "Content-Type: %s\n" ctype))
1683 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1687 (let ((mc-pgp-always-sign 'never))
1688 (mc-pgp-encrypt-region
1689 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1690 (point-min) (point-max) from nil)
1692 (throw 'mime-editor/error 'pgp-error)
1695 (insert (format "--[[multipart/encrypted;
1697 protocol=\"application/pgp-encrypted\"][7bit]]
1699 Content-Type: application/pgp-encrypted
1702 Content-Type: application/octet-stream
1703 Content-Transfer-Encoding: 7bit
1705 " pgp-boundary pgp-boundary pgp-boundary))
1706 (goto-char (point-max))
1707 (insert (format "\n--%s--\n" pgp-boundary))
1710 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1713 (narrow-to-region beg end)
1715 (mime-editor/translate-region beg end boundary))
1717 (encoding (nth 1 ret))
1721 (insert (format "Content-Type: %s\n" ctype))
1723 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1726 (or (let ((program-coding-system-alist
1727 (cons (cons (cons nil ".*pgp.*")
1728 (cons *noconv* *noconv*))
1729 program-coding-system-alist))
1731 (mc-pgp-sign-region beg (point-max))
1733 (throw 'mime-editor/error 'pgp-error)
1737 "--[[application/pgp; format=mime][7bit]]\n")
1741 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1743 (let ((from (rfc822/get-field-body "From"))
1744 (to (rfc822/get-field-body "To"))
1745 (cc (rfc822/get-field-body "cc"))
1748 (narrow-to-region beg end)
1750 (mime-editor/translate-region beg end boundary))
1752 (encoding (nth 1 ret))
1756 (if (and (stringp from)
1757 (not (string-equal from "")))
1758 (insert (format "From: %s\n" from))
1760 (if (and (stringp to)
1761 (not (string-equal to "")))
1763 (insert (format "To: %s\n" to))
1764 (setq recipients to)
1766 (if (and (stringp cc)
1767 (not (string-equal cc "")))
1769 (insert (format "cc: %s\n" cc))
1771 (setq recipients (concat recipients "," cc))
1772 (setq recipients cc)
1774 (insert (format "Content-Type: %s\n" ctype))
1776 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1779 (or (let ((program-coding-system-alist
1780 (cons (cons (cons nil ".*pgp.*")
1781 (cons *noconv* *noconv*))
1782 program-coding-system-alist))
1784 (mc-pgp-encrypt-region
1785 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1788 (throw 'mime-editor/error 'pgp-error)
1792 "--[[application/pgp; format=mime][7bit]]\n")
1796 (defun mime-editor/translate-body ()
1797 "Encode the tagged MIME body in current buffer in MIME compliant message."
1801 (concat mime-multipart-boundary "_"
1802 (replace-space-with-underline (current-time-string))
1806 (while (mime-editor/process-multipart-1
1807 (format "%s-%d" boundary i))
1811 ;; We are interested in message body.
1814 (goto-char (point-min))
1816 (concat "\n" (regexp-quote mail-header-separator)
1817 (if mime-ignore-preceding-spaces
1818 "[ \t\n]*\n" "\n")) nil 'move)
1822 (goto-char (point-max))
1823 (and mime-ignore-trailing-spaces
1824 (re-search-backward "[^ \t\n]\n" beg t)
1827 (setq ret (mime-editor/translate-region
1829 (format "%s-%d" boundary i)))
1831 (let ((contype (car ret)) ;Content-Type
1832 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1834 ;; Make primary MIME headers.
1835 (or (mail-position-on-field "Mime-Version")
1836 (insert mime-editor/mime-version-value))
1837 ;; Remove old Content-Type and other fields.
1839 (goto-char (point-min))
1840 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1841 (narrow-to-region (point-min) (point))
1842 (goto-char (point-min))
1843 (mime-delete-field "Content-Type")
1844 (mime-delete-field "Content-Transfer-Encoding"))
1845 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1846 (mail-position-on-field "Content-Type")
1850 (mail-position-on-field "Content-Transfer-Encoding")
1854 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1857 (concat mime-multipart-boundary "_"
1858 (replace-space-with-underline (current-time-string))))
1862 (narrow-to-region beg end)
1863 (let ((tag nil) ;MIME tag
1864 (contype nil) ;Content-Type
1865 (encoding nil) ;Content-Transfer-Encoding
1866 (nparts 0)) ;Number of body parts
1867 ;; Normalize the body part by inserting appropriate message
1868 ;; tags for every message contents.
1869 (mime-editor/normalize-body)
1870 ;; Counting the number of Content-Type.
1871 (goto-char (point-min))
1872 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1873 (setq nparts (1+ nparts)))
1874 ;; Begin translation.
1875 (cond ((and (<= nparts 1)(not multipart))
1876 ;; It's a singular message.
1877 (goto-char (point-min))
1878 (while (re-search-forward
1879 mime-editor/single-part-tag-regexp nil t)
1881 (buffer-substring (match-beginning 0) (match-end 0)))
1882 (delete-region (match-beginning 0) (1+ (match-end 0)))
1883 (setq contype (mime-editor/get-contype tag))
1884 (setq encoding (mime-editor/get-encoding tag))
1887 ;; It's a multipart message.
1888 (goto-char (point-min))
1889 (while (re-search-forward
1890 mime-editor/single-part-tag-regexp nil t)
1892 (buffer-substring (match-beginning 0) (match-end 0)))
1893 (delete-region (match-beginning 0) (match-end 0))
1894 (setq contype (mime-editor/get-contype tag))
1895 (setq encoding (mime-editor/get-encoding tag))
1896 (insert "--" boundary "\n")
1897 (insert "Content-Type: " contype "\n")
1899 (insert "Content-Transfer-Encoding: " encoding "\n"))
1901 ;; Define Content-Type as "multipart/mixed".
1903 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1904 ;; Content-Transfer-Encoding must be "7bit".
1905 ;; The following encoding can be `nil', but is
1906 ;; specified as is since there is no way that a user
1908 (setq encoding "7bit")
1909 ;; Insert the trailer.
1910 (goto-char (point-max))
1912 (insert "--" boundary "--\n")
1913 (insert "\n--" boundary "--\n")
1915 (list contype encoding boundary nparts)
1918 (defun mime-editor/normalize-body ()
1919 "Normalize the body part by inserting appropriate message tags."
1920 ;; Insert the first MIME tags if necessary.
1921 (goto-char (point-min))
1922 (if (not (looking-at mime-editor/single-part-tag-regexp))
1923 (insert (mime-make-text-tag) "\n"))
1924 ;; Check each tag, and add new tag or correct it if necessary.
1925 (goto-char (point-min))
1926 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1927 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1928 (contype (mime-editor/get-contype tag))
1929 (charset (mime-get-parameter contype "charset"))
1930 (encoding (mime-editor/get-encoding tag)))
1931 ;; Remove extra whitespaces after the tag.
1932 (if (looking-at "[ \t]+$")
1933 (delete-region (match-beginning 0) (match-end 0)))
1935 ((= (following-char) ?\^M)
1936 ;; It must be image, audio or video.
1938 (end (mime-editor/content-end)))
1939 ;; Insert explicit MIME tags after hidden messages.
1941 (if (and (not (eobp))
1942 (not (looking-at mime-editor/single-part-tag-regexp)))
1944 (insert (mime-make-text-tag) "\n")
1945 (forward-line -1) ;Process it again as text.
1947 ;; Show a hidden message. The point is not altered
1948 ;; after the conversion.
1949 (mime-flag-region beg end ?\n)
1951 ((mime-test-content-type contype "message")
1952 ;; Content-type "message" should be sent as is.
1955 ((mime-test-content-type contype "text")
1956 ;; Define charset for text if necessary.
1957 (setq charset (or charset (mime-editor/choose-charset)))
1958 (mime-editor/define-charset charset)
1959 (cond ((string-equal contype "text/x-rot13-47")
1963 (goto-char (mime-editor/content-end))
1966 ((string-equal contype "text/enriched")
1971 (end (mime-editor/content-end))
1973 (enriched-encode beg end)
1975 (if (search-forward "\n\n")
1976 (delete-region beg (match-end 0))
1979 ;; Point is now on current tag.
1980 ;; Define encoding and encode text if necessary.
1981 (or encoding ;Encoding is not specified.
1985 mime-editor/charset-default-encoding-alist)
1987 (beg (mime-editor/content-beginning))
1989 (mime-charset-encode-region beg (mime-editor/content-end)
1991 (mime-encode-region encoding beg (mime-editor/content-end))
1992 (mime-editor/define-encoding encoding)
1996 ((null encoding) ;Encoding is not specified.
1997 ;; Application, image, audio, video, and any other
1998 ;; unknown content-type without encoding should be
2000 (let* ((encoding "base64") ;Encode in BASE64 by default.
2001 (beg (mime-editor/content-beginning))
2002 (end (mime-editor/content-end))
2003 (body (buffer-substring beg end))
2005 (mime-encode-region encoding beg end)
2006 (mime-editor/define-encoding encoding))
2012 (defun mime-delete-field (field)
2013 "Delete header FIELD."
2014 (let ((regexp (format "^%s:[ \t]*" field)))
2015 (goto-char (point-min))
2016 (while (re-search-forward regexp nil t)
2017 (delete-region (match-beginning 0)
2018 (progn (forward-line 1) (point)))
2023 ;;; Platform dependent functions
2026 ;; Sun implementations
2028 (defun mime-voice-recorder-for-sun ()
2029 "Record voice in a buffer using Sun audio device, and return the buffer.
2030 If the environment variable AUDIOHOST is defined, its value is used as
2031 a recording host instead of local host."
2032 (let ((buffer (get-buffer-create " *MIME audio*"))
2033 (host (getenv "AUDIOHOST")))
2034 (message "Start the recording on %s. Type C-g to finish the recording..."
2035 (or host (system-name)))
2039 (condition-case errorcode
2040 (let ((selective-display nil) ;Disable ^M to nl translation.
2042 (kanji-flag nil)) ;NEmacs
2043 ;; If AUDIOHOST is defined, use the value as recording host.
2044 (cond ((not (null host))
2045 ;; Disable automatic conversion of coding system if Mule.
2046 (if (featurep 'mule)
2047 (define-program-coding-system nil "rsh" *noconv*))
2057 ;; Disable automatic conversion of coding system if Mule.
2058 (if (featurep 'mule)
2059 (define-program-coding-system nil "cat" *noconv*))
2065 (quit (message "Type C-g to finish recording... done.")
2066 buffer ;Return the buffer
2070 ;;; @ Other useful commands.
2073 ;; Message forwarding commands as content-type "message/rfc822".
2075 (defun mime-editor/insert-message (&optional message)
2077 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2078 (if (and inserter (fboundp inserter))
2080 (mime-editor/insert-tag "message" "rfc822")
2081 (funcall inserter message)
2083 (message "Sorry, I don't have message inserter for your MUA.")
2086 (defun mime-editor/insert-mail (&optional message)
2088 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2089 (if (and inserter (fboundp inserter))
2091 (mime-editor/insert-tag "message" "rfc822")
2092 (funcall inserter message)
2094 (message "Sorry, I don't have mail inserter for your MUA.")
2097 (defun mime-editor/inserted-message-filter ()
2100 (let ((header-start (point))
2101 (case-fold-search t)
2104 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2105 (if (re-search-forward "^$" (mark t))
2106 (narrow-to-region header-start (match-beginning 0))
2108 (goto-char header-start)
2109 (while (and (re-search-forward
2110 mime-editor/yank-ignored-field-regexp nil t)
2111 (setq beg (match-beginning 0))
2112 (setq end (1+ (rfc822/field-end)))
2114 (delete-region beg end)
2119 ;;; @ multipart enclosure
2122 (defun mime-editor/enclose-region (type beg end)
2125 (let ((current (point))
2128 (if (mime-editor/goto-tag)
2129 (or (eq current (match-beginning 0))
2130 (setq exist-prev-tag t)
2133 (narrow-to-region beg end)
2138 (insert (format "--<<%s>>-{\n" type))
2139 (goto-char (point-max))
2140 (insert (format "\n--}-<<%s>>\n" type))
2141 (goto-char (point-max))
2143 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
2145 (insert (mime-make-text-tag) "\n")
2149 (defun mime-editor/enclose-mixed-region (beg end)
2151 (mime-editor/enclose-region "mixed" beg end)
2154 (defun mime-editor/enclose-parallel-region (beg end)
2156 (mime-editor/enclose-region "parallel" beg end)
2159 (defun mime-editor/enclose-digest-region (beg end)
2161 (mime-editor/enclose-region "digest" beg end)
2164 (defun mime-editor/enclose-alternative-region (beg end)
2166 (mime-editor/enclose-region "alternative" beg end)
2169 (defun mime-editor/enclose-signed-region (beg end)
2171 (if mime-editor/signing-type
2172 (mime-editor/enclose-region "signed" beg end)
2173 (message "Please specify signing type.")
2176 (defun mime-editor/enclose-encrypted-region (beg end)
2178 (if mime-editor/signing-type
2179 (mime-editor/enclose-region "encrypted" beg end)
2180 (message "Please specify encrypting type.")
2183 (defun mime-editor/insert-key (&optional arg)
2184 "Insert a pgp public key."
2186 (mime-editor/insert-tag "application" "pgp-keys")
2187 (mime-editor/define-encoding "7bit")
2188 (mc-insert-public-key)
2195 (defun mime-editor/set-split (arg)
2198 (y-or-n-p "Do you want to enable split?")
2200 (setq mime-editor/split-message arg)
2202 (message "This message is enabled to split.")
2203 (message "This message is not enabled to split.")
2206 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2207 "Toggle transfer-level is 7bit or 8bit through.
2209 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2211 (if (numberp transfer-level)
2212 (setq mime-editor/transfer-level transfer-level)
2213 (if (< mime-editor/transfer-level 8)
2214 (setq mime-editor/transfer-level 8)
2215 (setq mime-editor/transfer-level 7)
2217 (setq mime-editor/charset-default-encoding-alist
2218 (mime/make-charset-default-encoding-alist
2219 mime-editor/transfer-level))
2220 (message (format "Current transfer-level is %d bit"
2221 mime-editor/transfer-level))
2222 (setq mime-editor/transfer-level-string
2223 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2224 (force-mode-line-update)
2231 (defun mime-editor/set-sign (arg)
2234 (y-or-n-p "Do you want to sign?")
2237 (if mime-editor/signing-type
2239 (setq mime-editor/pgp-processing 'sign)
2240 (message "This message will be signed.")
2242 (message "Please specify signing type.")
2244 (if (eq mime-editor/pgp-processing 'sign)
2245 (setq mime-editor/pgp-processing nil)
2247 (message "This message will not be signed.")
2250 (defun mime-editor/set-encrypt (arg)
2253 (y-or-n-p "Do you want to encrypt?")
2256 (if mime-editor/encrypting-type
2258 (setq mime-editor/pgp-processing 'encrypt)
2259 (message "This message will be encrypt.")
2261 (message "Please specify encrypting type.")
2263 (if (eq mime-editor/pgp-processing 'encrypt)
2264 (setq mime-editor/pgp-processing nil)
2266 (message "This message will not be encrypt.")
2269 (defvar mime-editor/pgp-processing nil)
2270 (make-variable-buffer-local 'mime-editor/pgp-processing)
2272 (defun mime-editor/pgp-enclose-buffer ()
2273 (let ((beg (save-excursion
2274 (goto-char (point-min))
2275 (if (search-forward (concat "\n" mail-header-separator "\n"))
2281 (cond ((eq mime-editor/pgp-processing 'sign)
2282 (mime-editor/enclose-signed-region beg end)
2284 ((eq mime-editor/pgp-processing 'encrypt)
2285 (mime-editor/enclose-encrypted-region beg end)
2293 (defun mime-editor/insert-partial-header
2294 (fields subject id number total separator)
2296 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2297 (insert (format "Mime-Version: 1.0 (split by tm-edit %s)\n"
2298 mime-editor/version))
2300 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2301 id number total separator))
2304 (defun mime-editor/split-and-send
2305 (&optional cmd lines mime-editor/message-max-length)
2309 (count-lines (point-min) (point-max)))
2311 (or mime-editor/message-max-length
2312 (setq mime-editor/message-max-length
2313 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2314 mime-editor/message-default-max-length))
2316 (let* ((mime-editor/draft-file-name
2317 (or (buffer-file-name)
2319 (expand-file-name "tm-draft" mime/tmp-dir))))
2320 (separator mail-header-separator)
2322 (eval (cdr (assq major-mode mime-editor/window-config-alist))))
2324 (replace-space-with-underline (current-time-string))
2325 "@" (system-name) "\"")))
2326 (run-hooks 'mime-editor/before-split-hook)
2327 (let* ((header (rfc822/get-header-string-except
2328 mime-editor/split-ignored-field-regexp separator))
2329 (subject (mail-fetch-field "subject"))
2330 (total (+ (/ lines mime-editor/message-max-length)
2331 (if (> (mod lines mime-editor/message-max-length) 0)
2333 (the-buf (current-buffer))
2334 (buf (get-buffer "*tmp-send*"))
2339 mime-editor/split-message-sender-alist))
2342 mime-editor/message-default-sender-alist))
2345 (goto-char (point-min))
2346 (if (re-search-forward (concat "^" (regexp-quote separator) "$")
2352 (switch-to-buffer buf)
2354 (switch-to-buffer the-buf)
2356 (setq buf (get-buffer-create "*tmp-send*"))
2358 (switch-to-buffer buf)
2359 (make-local-variable 'mail-header-separator)
2360 (setq mail-header-separator separator)
2361 (switch-to-buffer the-buf)
2362 (goto-char (point-min))
2363 (re-search-forward "^$" nil t)
2364 (let ((mime-editor/partial-number 1))
2365 (setq data (buffer-substring
2368 (goto-line mime-editor/message-max-length)
2371 (delete-region (point-min)(point))
2372 (switch-to-buffer buf)
2373 (mime-editor/insert-partial-header
2374 header subject id mime-editor/partial-number total separator)
2378 (goto-char (point-min))
2379 (search-forward (concat "\n" mail-header-separator "\n"))
2382 (if (re-search-forward "^$" nil t)
2386 (goto-char (point-min))
2387 (while (re-search-forward
2388 mime-editor/split-blind-field-regexp nil t)
2389 (delete-region (match-beginning 0)
2390 (let ((e (rfc822/field-end)))
2391 (if (< e (point-max))
2397 (message (format "Sending %d/%d..."
2398 mime-editor/partial-number total))
2399 (call-interactively command)
2400 (message (format "Sending %d/%d... done"
2401 mime-editor/partial-number total))
2404 (switch-to-buffer the-buf)
2405 (setq mime-editor/partial-number 2)
2406 (while (< mime-editor/partial-number total)
2407 (setq data (buffer-substring
2410 (goto-line mime-editor/message-max-length)
2413 (delete-region (point-min)(point))
2414 (switch-to-buffer buf)
2415 (mime-editor/insert-partial-header
2416 header subject id mime-editor/partial-number total separator)
2419 (message (format "Sending %d/%d..."
2420 mime-editor/partial-number total))
2421 (call-interactively command)
2422 (message (format "Sending %d/%d... done"
2423 mime-editor/partial-number total))
2426 (switch-to-buffer the-buf)
2427 (setq mime-editor/partial-number
2428 (1+ mime-editor/partial-number))
2430 (goto-char (point-min))
2431 (mime-editor/insert-partial-header
2432 header subject id mime-editor/partial-number total separator)
2433 (message (format "Sending %d/%d..."
2434 mime-editor/partial-number total))
2437 (defun mime-editor/maybe-split-and-send (&optional cmd)
2439 (run-hooks 'mime-editor/before-send-hook)
2440 (let ((mime-editor/message-max-length
2441 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2442 mime-editor/message-default-max-length))
2443 (lines (count-lines (point-min) (point-max)))
2445 (if (and (> lines mime-editor/message-max-length)
2446 mime-editor/split-message)
2447 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2451 ;;; @ preview message
2454 (defun mime-editor/preview-message ()
2455 "preview editing MIME message. [tm-edit.el]"
2457 (let* ((str (buffer-string))
2458 (separator mail-header-separator)
2459 (the-buf (current-buffer))
2460 (buf-name (buffer-name))
2461 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2462 (buf (get-buffer temp-buf-name))
2466 (switch-to-buffer buf)
2469 (setq buf (get-buffer-create temp-buf-name))
2470 (switch-to-buffer buf)
2473 (setq major-mode 'mime/temporary-message-mode)
2474 (make-local-variable 'mail-header-separator)
2475 (setq mail-header-separator separator)
2476 (make-local-variable 'mime/editing-buffer)
2477 (setq mime/editing-buffer the-buf)
2479 (run-hooks 'mime-editor/translate-hook)
2480 (mime-editor/translate-buffer)
2481 (goto-char (point-min))
2482 (if (re-search-forward
2483 (concat "^" (regexp-quote separator) "$"))
2489 (defun mime-editor/quitting-method ()
2490 (let ((temp mime::preview/article-buffer)
2492 (mime-viewer/kill-buffer)
2494 (setq buf mime/editing-buffer)
2496 (switch-to-buffer buf)
2499 (set-alist 'mime-viewer/quitting-method-alist
2500 'mime/temporary-message-mode
2501 (function mime-editor/quitting-method)
2507 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2508 ;; Mon, 10 Apr 1995 20:03:07 +0900
2510 (defvar mime-editor/draft-header-separator-alist
2511 '((news-reply-mode . mail-header-separator)
2512 (mh-letter-mode . mail-header-separator)
2515 (defvar mime::article/draft-header-separator nil)
2517 (defun mime-editor/draft-preview ()
2519 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2520 (or (stringp sep) (setq sep (eval sep)))
2521 (make-variable-buffer-local 'mime::article/draft-header-separator)
2522 (goto-char (point-min))
2524 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2525 (setq mime::article/draft-header-separator
2526 (buffer-substring (match-beginning 0) (match-end 0)))
2528 (mime/viewer-mode (current-buffer))
2529 (pop-to-buffer (current-buffer))
2532 (defun mime-viewer::quitting-method/draft-preview ()
2533 (let ((mother mime::preview/mother-buffer))
2535 (switch-to-buffer mother)
2536 (goto-char (point-min))
2540 (regexp-quote mime::article/draft-header-separator)
2544 (insert mime::article/draft-header-separator)
2545 (set-buffer-modified-p (buffer-modified-p))
2547 (mime-viewer/kill-buffer)
2548 (pop-to-buffer mother)
2551 (set-alist 'mime-viewer/quitting-method-alist
2553 (function mime-viewer::quitting-method/draft-preview)
2556 (set-alist 'mime-viewer/quitting-method-alist
2558 (function mime-viewer::quitting-method/draft-preview)
2565 (defun mime-editor::edit-again (code-conversion)
2567 (goto-char (point-min))
2568 (let ((ctl (mime/Content-Type)))
2570 (let ((ctype (car ctl))
2573 (if (string-match "/" ctype)
2575 (setq type (substring ctype 0 (match-beginning 0)))
2576 (setq stype (substring ctype (match-end 0)))
2581 ((string-equal type "multipart")
2582 (let ((boundary (assoc-value "boundary" params)))
2583 (re-search-forward (concat "\n--" boundary) nil t)
2584 (let ((bb (match-beginning 0)) eb tag)
2585 (setq tag (format "\n--<<%s>>-{" stype))
2588 (setq bb (+ bb (length tag)))
2589 (re-search-forward (concat "\n--" boundary "--") nil t)
2590 (setq eb (match-beginning 0))
2591 (replace-match (format "\n--}-<<%s>>" stype))
2593 (narrow-to-region bb eb)
2594 (goto-char (point-min))
2595 (while (re-search-forward
2596 (concat "\n--" boundary "\n") nil t)
2597 (let ((beg (match-beginning 0))
2599 (delete-region beg (match-end 0))
2601 (if (re-search-forward
2602 (concat "\n--" boundary) nil t)
2603 (setq end (match-beginning 0))
2604 (setq end (point-max))
2607 (narrow-to-region beg end)
2608 (mime-editor::edit-again code-conversion)
2609 (goto-char (point-max))
2612 (goto-char (point-min))
2613 (or (= (point-min) 1)
2614 (delete-region (point-min)
2615 (if (re-search-forward "^$" nil t)
2623 (mapconcat (function
2625 (if (string-equal (car attr)
2628 (setq charset (cdr attr))
2630 (concat ";" (car attr)
2638 (if (re-search-forward
2639 "Content-Transfer-Encoding:" nil t)
2640 (let ((beg (match-beginning 0))
2641 (hbeg (match-end 0))
2642 (end (rfc822/field-end)))
2644 (eliminate-top-spaces
2645 (rfc822/unfolding-string
2646 (buffer-substring hbeg end))))
2647 (if (or charset (string-equal type "text"))
2649 (delete-region beg (1+ end))
2650 (goto-char (point-min))
2651 (if (search-forward "\n\n" nil t)
2654 encoding (match-end 0)(point-max))
2658 (if (or code-conversion encoded)
2660 (mime-charset-decode-region (point-min)(point-max)
2662 (character-decode-region (point-min)(point-max)
2663 mime/default-coding-system)
2666 (if (re-search-forward "^$" nil t)
2670 (if (= (point-min) 1)
2677 (concat type "/" stype pstr) encoding)
2680 (delete-region (point-min) he)
2684 (concat type "/" stype pstr) encoding)
2689 (character-decode-region (point-min) (point-max)
2690 mime/default-coding-system)
2694 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2696 (mime-editor::edit-again code-conversion)
2697 (goto-char (point-min))
2699 (narrow-to-region (point-min)
2700 (if (re-search-forward "^$" nil t)
2704 (goto-char (point-min))
2705 (while (re-search-forward
2706 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2707 (delete-region (match-beginning 0) (1+ (rfc822/field-end)))
2710 (and (re-search-forward "^$")
2711 (replace-match mail-header-separator)
2723 (run-hooks 'tm-edit-load-hook)
2725 ;;; tm-edit.el ends here