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.63 $
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.63 1996/05/22 02:25:54 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" "Approved" "Path" "Replied" "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 start (point-max) encoding)
1087 (mime-flag-region (point-min) (1- (point-max)) ?\^M)
1088 (goto-char (point-max)))
1090 ;; Define encoding even if it is 7bit.
1091 (if (stringp encoding)
1093 (goto-char tagend) ;Make sure which line the tag is on.
1094 (mime-editor/define-encoding encoding)))
1098 ;; Commands work on a current message flagment.
1100 (defun mime-editor/goto-tag ()
1101 "Search for the beginning of the tagged MIME message."
1102 (let ((current (point)) multipart)
1103 (if (looking-at mime-editor/tag-regexp)
1105 ;; At first, go to the end.
1106 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1107 (goto-char (match-beginning 0)) ;For multiline tag
1112 (goto-char (point-max))
1114 ;; Then search for the beginning.
1115 (re-search-backward mime-editor/end-tag-regexp nil t)
1117 (or (looking-at mime-editor/beginning-tag-regexp)
1118 ;; Restore previous point.
1125 (defun mime-editor/content-beginning ()
1126 "Return the point of the beginning of content."
1128 (let ((beg (save-excursion
1129 (beginning-of-line) (point))))
1130 (if (mime-editor/goto-tag)
1131 (let ((top (point)))
1132 (goto-char (match-end 0))
1133 (if (and (= beg top)
1134 (= (following-char) ?\^M))
1138 ;; Default text/plain tag.
1139 (goto-char (point-min))
1141 (concat "\n" (regexp-quote mail-header-separator)
1142 (if mime-ignore-preceding-spaces
1143 "[ \t\n]*\n" "\n")) nil 'move)
1147 (defun mime-editor/content-end ()
1148 "Return the point of the end of content."
1150 (let ((beg (save-excursion
1151 (beginning-of-line) (point))))
1152 (if (mime-editor/goto-tag)
1153 (let ((top (point)))
1154 (goto-char (match-end 0))
1155 (if (and (= beg top) ;Must be on the same line.
1156 (= (following-char) ?\^M))
1160 ;; Move to the end of this text.
1161 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1162 ;; Don't forget a multiline tag.
1163 (goto-char (match-beginning 0)))
1166 ;; Assume the message begins with text/plain.
1167 (goto-char (mime-editor/content-beginning))
1168 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1169 ;; Don't forget a multiline tag.
1170 (goto-char (match-beginning 0)))
1174 (defun mime-editor/define-charset (charset)
1175 "Set charset of current tag to CHARSET."
1177 (if (mime-editor/goto-tag)
1178 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1179 (delete-region (match-beginning 0) (match-end 0))
1181 (mime-create-tag (mime-set-parameter
1182 (mime-editor/get-contype tag) "charset" charset)
1183 (mime-editor/get-encoding tag))))
1186 (defun mime-editor/define-encoding (encoding)
1187 "Set encoding of current tag to ENCODING."
1189 (if (mime-editor/goto-tag)
1190 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1191 (delete-region (match-beginning 0) (match-end 0))
1192 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1195 (defun mime-editor/choose-charset ()
1196 "Choose charset of a text following current point."
1197 (mime/find-charset-region (point) (mime-editor/content-end))
1200 (defun mime-make-text-tag (&optional subtype)
1201 "Make a tag for a text after current point.
1202 Subtype of text type can be specified by an optional argument SUBTYPE.
1203 Otherwise, it is obtained from mime-content-types."
1204 (let* ((pritype "text")
1205 (subtype (or subtype
1206 (car (car (cdr (assoc pritype mime-content-types)))))))
1207 ;; Charset should be defined later.
1208 (mime-make-tag pritype subtype)))
1211 ;; Tag handling functions
1213 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1214 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1215 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1219 (defun mime-create-tag (contype &optional encoding)
1220 "Make a tag with CONTENT-TYPE and optional ENCODING."
1221 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1224 (defun mime-editor/get-contype (tag)
1225 "Return Content-Type (including parameters) of TAG."
1227 (or (string-match mime-editor/single-part-tag-regexp tag)
1228 (string-match mime-editor/multipart-beginning-regexp tag)
1229 (string-match mime-editor/multipart-end-regexp tag)
1231 (substring tag (match-beginning 1) (match-end 1))
1234 (defun mime-editor/get-encoding (tag)
1235 "Return encoding of TAG."
1237 (string-match mime-editor/single-part-tag-regexp tag)
1239 (not (= (match-beginning 3) (match-end 3)))
1240 (substring tag (match-beginning 3) (match-end 3))))
1242 (defun mime-get-parameter (contype parameter)
1243 "For given CONTYPE return value for PARAMETER.
1244 Nil if no such parameter."
1248 (regexp-quote parameter)
1249 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1251 (substring contype (match-beginning 1) (match-end 1))
1252 nil ;No such parameter
1255 (defun mime-set-parameter (contype parameter value)
1256 "For given CONTYPE set PARAMETER to VALUE."
1260 (regexp-quote parameter)
1261 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1264 (concat (substring contype 0 (match-beginning 1))
1266 (substring contype (match-end 1)))
1267 (concat contype "; " parameter "=" value)))
1269 (defun mime-strip-parameters (contype)
1270 "Return primary content-type and subtype without parameters for CONTYPE."
1271 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1272 (substring contype (match-beginning 1) (match-end 1)) nil))
1274 (defun mime-test-content-type (contype type &optional subtype)
1275 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1276 (and (stringp contype)
1279 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1280 (downcase contype))))
1285 (defun mime-find-file-type (file)
1286 "Guess Content-Type, subtype, and parameters from FILE."
1288 (guesses mime-file-types))
1289 (while (and (not guess) guesses)
1290 (if (string-match (car (car guesses)) file)
1291 (setq guess (cdr (car guesses))))
1292 (setq guesses (cdr guesses)))
1296 (defun mime-prompt-for-type ()
1297 "Ask for Content-type."
1299 ;; Repeat until primary content type is specified.
1300 (while (string-equal type "")
1302 (completing-read "What content type: "
1305 'require-match ;Type must be specified.
1308 (if (string-equal type "")
1310 (message "Content type is required.")
1318 (defun mime-prompt-for-subtype (pritype)
1319 "Ask for Content-type subtype of Content-Type PRITYPE."
1320 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1325 "What content subtype: (default " default ") ")
1326 "What content subtype: ")
1327 (cdr (assoc pritype mime-content-types))
1329 'require-match ;Subtype must be specified.
1332 (if (string-equal answer "") default answer)))
1334 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1335 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1336 Optional DELIMITER specifies parameter delimiter (';' by default)."
1337 (let* ((delimiter (or delimiter "; "))
1342 (mime-prompt-for-parameters-1
1344 (cdr (assoc pritype mime-content-types))))))
1347 (if (and (stringp parameters)
1348 (not (string-equal parameters "")))
1349 (concat delimiter parameters)
1350 "" ;"" if no parameters
1353 (defun mime-prompt-for-parameters-1 (optlist)
1354 (apply (function append)
1355 (mapcar (function mime-prompt-for-parameter) optlist)))
1357 (defun mime-prompt-for-parameter (parameter)
1359 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1360 (let* ((prompt (car parameter))
1361 (choices (mapcar (function
1363 (if (consp e) e (list e))))
1365 (default (car (car choices)))
1371 (concat "What " prompt
1373 (if (string-equal default "") "\"\"" default)
1375 choices nil nil ""))
1376 ;; If nothing is selected, use default.
1377 (if (string-equal answer "")
1378 (setq answer default)))
1380 (read-string (concat "What " prompt ": "))))
1381 (cons (if (and answer
1382 (not (string-equal answer "")))
1384 ;; Note: control characters ignored!
1385 (if (string-match mime-tspecials-regexp answer)
1386 (concat "\"" answer "\"") answer)))
1387 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1390 (defun mime-flag-region (from to flag)
1391 "Hides or shows lines from FROM to TO, according to FLAG.
1392 If FLAG is `\\n' (newline character) then text is shown,
1393 while if FLAG is `\\^M' (control-M) the text is hidden."
1394 (let ((buffer-read-only nil) ;Okay even if write protected.
1395 (modp (buffer-modified-p)))
1397 (subst-char-in-region from to
1398 (if (= flag ?\n) ?\^M ?\n)
1400 (set-buffer-modified-p modp))))
1403 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1406 (defvar mime-editor/translate-buffer-hook
1407 '(mime-editor/pgp-enclose-buffer
1408 mime/encode-message-header
1409 mime-editor/translate-body))
1411 (defun mime-editor/translate-buffer ()
1412 "Encode the tagged MIME message in current buffer in MIME compliant message."
1414 (if (catch 'mime-editor/error
1416 (run-hooks 'mime-editor/translate-buffer-hook)
1420 (error "Translation error!")
1423 (defun mime-editor/find-inmost ()
1424 (goto-char (point-min))
1425 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1426 (let ((bb (match-beginning 0))
1428 (type (buffer-substring (match-beginning 1)(match-end 1)))
1430 (setq end-exp (format "^--}-<<%s>>\n" type))
1432 (if (re-search-forward end-exp nil t)
1434 (setq eb (match-beginning 0))
1435 (setq ee (match-end 0))
1437 (setq eb (point-max))
1438 (setq ee (point-max))
1440 (narrow-to-region be eb)
1442 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1444 (narrow-to-region (match-beginning 0)(point-max))
1445 (mime-editor/find-inmost)
1448 ;;(delete-region eb ee)
1449 (list type bb be eb)
1452 (defun mime-editor/process-multipart-1 (boundary)
1453 (let ((ret (mime-editor/find-inmost)))
1455 (let ((type (car ret))
1456 (bb (nth 1 ret))(be (nth 2 ret))
1459 (narrow-to-region bb eb)
1460 (delete-region bb be)
1461 (setq bb (point-min))
1462 (setq eb (point-max))
1465 (if (looking-at mime-editor/multipart-end-regexp)
1466 (let ((beg (match-beginning 0))
1469 (delete-region beg end)
1470 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
1472 (insert (concat (mime-make-text-tag) "\n"))
1474 (cond ((string= type "signed")
1475 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1476 (mime-editor/sign-pgp-elkins bb eb boundary)
1478 ((eq mime-editor/signing-type 'pgp-kazu)
1479 (mime-editor/sign-pgp-kazu bb eb boundary)
1482 ((string= type "encrypted")
1483 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1484 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1486 ((eq mime-editor/encrypting-type 'pgp-kazu)
1487 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1491 (nth 2 (mime-editor/translate-region bb eb
1495 (format "--[[multipart/%s;
1496 boundary=\"%s\"][7bit]]\n"
1502 (autoload 'mc-pgp-lookup-key "mc-pgp")
1503 (autoload 'mc-pgp-sign-region "mc-pgp")
1504 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1506 (defun tm:mc-pgp-generic-parser (result)
1507 (let ((ret (mc-pgp-generic-parser result)))
1509 (vector (car ret)(cdr ret))
1512 (defun tm:mc-process-region
1513 (beg end passwd program args parser &optional buffer boundary)
1514 (let ((obuf (current-buffer))
1515 (process-connection-type nil)
1516 mybuf result rgn proc)
1519 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1523 (buffer-disable-undo mybuf)
1525 (apply 'start-process "*PGP*" mybuf program args))
1528 (process-send-string proc (concat passwd "\n"))
1529 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1530 (process-send-region proc beg end)
1531 (process-send-eof proc)
1532 (while (eq 'run (process-status proc))
1533 (accept-process-output proc 5))
1534 (setq result (process-exit-status proc))
1535 ;; Hack to force a status_notify() in Emacs 19.29
1536 (delete-process proc)
1538 (goto-char (point-max))
1539 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1540 (delete-region (match-beginning 0) (match-end 0)))
1541 (goto-char (point-min))
1543 (while (search-forward "\r\n" nil t)
1544 (replace-match "\n"))
1545 ;; Hurm. FIXME; must get better result codes.
1546 (if (stringp result)
1547 (error "%s exited abnormally: '%s'" program result)
1548 (setq rgn (funcall parser result))
1549 ;; If the parser found something, migrate it
1555 (narrow-to-region beg end)
1557 (insert (format "--%s\n" boundary))
1558 (goto-char (point-max))
1559 (insert (format "\n--%s
1560 Content-Type: application/pgp-signature
1561 Content-Transfer-Encoding: 7bit
1564 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1565 (goto-char (point-max))
1566 (insert (format "\n--%s--\n" boundary))
1568 (delete-region beg end)
1570 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1573 (delete-region (car rgn) (cdr rgn)))))
1574 ;; Return nil on failure and exit code on success
1576 ;; Cleanup even on nonlocal exit
1577 (if (and proc (eq 'run (process-status proc)))
1578 (interrupt-process proc))
1580 (or buffer (null mybuf) (kill-buffer mybuf)))))
1582 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1583 (if (not (boundp 'mc-pgp-user-id))
1586 (let ((process-environment process-environment)
1587 (buffer (get-buffer-create mc-buffer-name))
1589 (parser (function mc-pgp-generic-parser))
1590 (pgp-path mc-pgp-path)
1592 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1596 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1597 (setenv "PGPPASSFD" "0")
1603 (list "+verbose=1" "+language=en"
1604 (format "+clearsig=%s" (if unclear "off" "on"))
1605 "+batchmode" "-u" (cdr key))))
1607 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1609 (message "Signing as %s ..." (car key))
1610 (if (tm:mc-process-region
1611 start end passwd pgp-path args parser buffer boundary)
1615 (goto-char (point-min))
1618 --[[multipart/signed; protocol=\"application/pgp-signature\";
1619 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1621 (message "Signing as %s ... Done." (car key))
1625 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1628 (narrow-to-region beg end)
1630 (mime-editor/translate-region beg end boundary))
1632 (encoding (nth 1 ret))
1634 (pgp-boundary (concat "pgp-sign-" boundary))
1637 (insert (format "Content-Type: %s\n" ctype))
1639 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1642 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1643 nil nil pgp-boundary)
1644 (throw 'mime-editor/error 'pgp-error)
1648 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1651 (let ((from (rfc822/get-field-body "From"))
1652 (to (rfc822/get-field-body "To"))
1653 (cc (rfc822/get-field-body "cc"))
1655 (narrow-to-region beg end)
1657 (mime-editor/translate-region beg end boundary))
1659 (encoding (nth 1 ret))
1661 (pgp-boundary (concat "pgp-" boundary))
1664 (if (and (stringp from)
1665 (not (string-equal from "")))
1666 (insert (format "From: %s\n" from))
1668 (if (and (stringp to)
1669 (not (string-equal to "")))
1671 (insert (format "To: %s\n" to))
1672 (setq recipients to)
1674 (if (and (stringp cc)
1675 (not (string-equal cc "")))
1677 (insert (format "cc: %s\n" cc))
1679 (setq recipients (concat recipients "," cc))
1680 (setq recipients cc)
1682 (insert (format "Content-Type: %s\n" ctype))
1684 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1688 (let ((mc-pgp-always-sign 'never))
1689 (mc-pgp-encrypt-region
1690 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1691 (point-min) (point-max) from nil)
1693 (throw 'mime-editor/error 'pgp-error)
1696 (insert (format "--[[multipart/encrypted;
1698 protocol=\"application/pgp-encrypted\"][7bit]]
1700 Content-Type: application/pgp-encrypted
1703 Content-Type: application/octet-stream
1704 Content-Transfer-Encoding: 7bit
1706 " pgp-boundary pgp-boundary pgp-boundary))
1707 (goto-char (point-max))
1708 (insert (format "\n--%s--\n" pgp-boundary))
1711 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1714 (narrow-to-region beg end)
1716 (mime-editor/translate-region beg end boundary))
1718 (encoding (nth 1 ret))
1722 (insert (format "Content-Type: %s\n" ctype))
1724 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1727 (or (let ((program-coding-system-alist
1728 (cons (cons (cons nil ".*pgp.*")
1729 (cons *noconv* *noconv*))
1730 program-coding-system-alist))
1732 (mc-pgp-sign-region beg (point-max))
1734 (throw 'mime-editor/error 'pgp-error)
1738 "--[[application/pgp; format=mime][7bit]]\n")
1742 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1744 (let ((from (rfc822/get-field-body "From"))
1745 (to (rfc822/get-field-body "To"))
1746 (cc (rfc822/get-field-body "cc"))
1749 (narrow-to-region beg end)
1751 (mime-editor/translate-region beg end boundary))
1753 (encoding (nth 1 ret))
1757 (if (and (stringp from)
1758 (not (string-equal from "")))
1759 (insert (format "From: %s\n" from))
1761 (if (and (stringp to)
1762 (not (string-equal to "")))
1764 (insert (format "To: %s\n" to))
1765 (setq recipients to)
1767 (if (and (stringp cc)
1768 (not (string-equal cc "")))
1770 (insert (format "cc: %s\n" cc))
1772 (setq recipients (concat recipients "," cc))
1773 (setq recipients cc)
1775 (insert (format "Content-Type: %s\n" ctype))
1777 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1780 (or (let ((program-coding-system-alist
1781 (cons (cons (cons nil ".*pgp.*")
1782 (cons *noconv* *noconv*))
1783 program-coding-system-alist))
1785 (mc-pgp-encrypt-region
1786 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1789 (throw 'mime-editor/error 'pgp-error)
1793 "--[[application/pgp; format=mime][7bit]]\n")
1797 (defun mime-editor/translate-body ()
1798 "Encode the tagged MIME body in current buffer in MIME compliant message."
1802 (concat mime-multipart-boundary "_"
1803 (replace-space-with-underline (current-time-string))
1807 (while (mime-editor/process-multipart-1
1808 (format "%s-%d" boundary i))
1812 ;; We are interested in message body.
1815 (goto-char (point-min))
1817 (concat "\n" (regexp-quote mail-header-separator)
1818 (if mime-ignore-preceding-spaces
1819 "[ \t\n]*\n" "\n")) nil 'move)
1823 (goto-char (point-max))
1824 (and mime-ignore-trailing-spaces
1825 (re-search-backward "[^ \t\n]\n" beg t)
1828 (setq ret (mime-editor/translate-region
1830 (format "%s-%d" boundary i)))
1832 (let ((contype (car ret)) ;Content-Type
1833 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1835 ;; Make primary MIME headers.
1836 (or (mail-position-on-field "Mime-Version")
1837 (insert mime-editor/mime-version-value))
1838 ;; Remove old Content-Type and other fields.
1840 (goto-char (point-min))
1841 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1842 (narrow-to-region (point-min) (point))
1843 (goto-char (point-min))
1844 (mime-delete-field "Content-Type")
1845 (mime-delete-field "Content-Transfer-Encoding"))
1846 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1847 (mail-position-on-field "Content-Type")
1851 (mail-position-on-field "Content-Transfer-Encoding")
1855 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1858 (concat mime-multipart-boundary "_"
1859 (replace-space-with-underline (current-time-string))))
1863 (narrow-to-region beg end)
1864 (let ((tag nil) ;MIME tag
1865 (contype nil) ;Content-Type
1866 (encoding nil) ;Content-Transfer-Encoding
1867 (nparts 0)) ;Number of body parts
1868 ;; Normalize the body part by inserting appropriate message
1869 ;; tags for every message contents.
1870 (mime-editor/normalize-body)
1871 ;; Counting the number of Content-Type.
1872 (goto-char (point-min))
1873 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1874 (setq nparts (1+ nparts)))
1875 ;; Begin translation.
1876 (cond ((and (<= nparts 1)(not multipart))
1877 ;; It's a singular message.
1878 (goto-char (point-min))
1879 (while (re-search-forward
1880 mime-editor/single-part-tag-regexp nil t)
1882 (buffer-substring (match-beginning 0) (match-end 0)))
1883 (delete-region (match-beginning 0) (1+ (match-end 0)))
1884 (setq contype (mime-editor/get-contype tag))
1885 (setq encoding (mime-editor/get-encoding tag))
1888 ;; It's a multipart message.
1889 (goto-char (point-min))
1890 (while (re-search-forward
1891 mime-editor/single-part-tag-regexp nil t)
1893 (buffer-substring (match-beginning 0) (match-end 0)))
1894 (delete-region (match-beginning 0) (match-end 0))
1895 (setq contype (mime-editor/get-contype tag))
1896 (setq encoding (mime-editor/get-encoding tag))
1897 (insert "--" boundary "\n")
1898 (insert "Content-Type: " contype "\n")
1900 (insert "Content-Transfer-Encoding: " encoding "\n"))
1902 ;; Define Content-Type as "multipart/mixed".
1904 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1905 ;; Content-Transfer-Encoding must be "7bit".
1906 ;; The following encoding can be `nil', but is
1907 ;; specified as is since there is no way that a user
1909 (setq encoding "7bit")
1910 ;; Insert the trailer.
1911 (goto-char (point-max))
1913 (insert "--" boundary "--\n")
1914 (insert "\n--" boundary "--\n")
1916 (list contype encoding boundary nparts)
1919 (defun mime-editor/normalize-body ()
1920 "Normalize the body part by inserting appropriate message tags."
1921 ;; Insert the first MIME tags if necessary.
1922 (goto-char (point-min))
1923 (if (not (looking-at mime-editor/single-part-tag-regexp))
1924 (insert (mime-make-text-tag) "\n"))
1925 ;; Check each tag, and add new tag or correct it if necessary.
1926 (goto-char (point-min))
1927 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1928 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1929 (contype (mime-editor/get-contype tag))
1930 (charset (mime-get-parameter contype "charset"))
1931 (encoding (mime-editor/get-encoding tag)))
1932 ;; Remove extra whitespaces after the tag.
1933 (if (looking-at "[ \t]+$")
1934 (delete-region (match-beginning 0) (match-end 0)))
1936 ((= (following-char) ?\^M)
1937 ;; It must be image, audio or video.
1939 (end (mime-editor/content-end)))
1940 ;; Insert explicit MIME tags after hidden messages.
1942 (if (and (not (eobp))
1943 (not (looking-at mime-editor/single-part-tag-regexp)))
1945 (insert (mime-make-text-tag) "\n")
1946 (forward-line -1) ;Process it again as text.
1948 ;; Show a hidden message. The point is not altered
1949 ;; after the conversion.
1950 (mime-flag-region beg end ?\n)
1952 ((mime-test-content-type contype "message")
1953 ;; Content-type "message" should be sent as is.
1956 ((mime-test-content-type contype "text")
1957 ;; Define charset for text if necessary.
1958 (setq charset (or charset (mime-editor/choose-charset)))
1959 (mime-editor/define-charset charset)
1960 (cond ((string-equal contype "text/x-rot13-47")
1964 (goto-char (mime-editor/content-end))
1967 ((string-equal contype "text/enriched")
1972 (end (mime-editor/content-end))
1974 (enriched-encode beg end)
1976 (if (search-forward "\n\n")
1977 (delete-region beg (match-end 0))
1980 ;; Point is now on current tag.
1981 ;; Define encoding and encode text if necessary.
1982 (or encoding ;Encoding is not specified.
1986 mime-editor/charset-default-encoding-alist)
1988 (beg (mime-editor/content-beginning))
1990 (mime-charset-encode-region beg (mime-editor/content-end)
1992 (mime-encode-region beg (mime-editor/content-end) encoding)
1993 (mime-editor/define-encoding encoding)
1997 ((null encoding) ;Encoding is not specified.
1998 ;; Application, image, audio, video, and any other
1999 ;; unknown content-type without encoding should be
2001 (let* ((encoding "base64") ;Encode in BASE64 by default.
2002 (beg (mime-editor/content-beginning))
2003 (end (mime-editor/content-end))
2004 (body (buffer-substring beg end))
2006 (mime-encode-region beg end encoding)
2007 (mime-editor/define-encoding encoding))
2013 (defun mime-delete-field (field)
2014 "Delete header FIELD."
2015 (let ((regexp (format "^%s:[ \t]*" field)))
2016 (goto-char (point-min))
2017 (while (re-search-forward regexp nil t)
2018 (delete-region (match-beginning 0)
2019 (progn (forward-line 1) (point)))
2024 ;;; Platform dependent functions
2027 ;; Sun implementations
2029 (defun mime-voice-recorder-for-sun ()
2030 "Record voice in a buffer using Sun audio device, and return the buffer.
2031 If the environment variable AUDIOHOST is defined, its value is used as
2032 a recording host instead of local host."
2033 (let ((buffer (get-buffer-create " *MIME audio*"))
2034 (host (getenv "AUDIOHOST")))
2035 (message "Start the recording on %s. Type C-g to finish the recording..."
2036 (or host (system-name)))
2040 (condition-case errorcode
2041 (let ((selective-display nil) ;Disable ^M to nl translation.
2043 (kanji-flag nil)) ;NEmacs
2044 ;; If AUDIOHOST is defined, use the value as recording host.
2045 (cond ((not (null host))
2046 ;; Disable automatic conversion of coding system if Mule.
2047 (if (featurep 'mule)
2048 (define-program-coding-system nil "rsh" *noconv*))
2058 ;; Disable automatic conversion of coding system if Mule.
2059 (if (featurep 'mule)
2060 (define-program-coding-system nil "cat" *noconv*))
2066 (quit (message "Type C-g to finish recording... done.")
2067 buffer ;Return the buffer
2071 ;;; @ Other useful commands.
2074 ;; Message forwarding commands as content-type "message/rfc822".
2076 (defun mime-editor/insert-message (&optional message)
2078 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2079 (if (and inserter (fboundp inserter))
2081 (mime-editor/insert-tag "message" "rfc822")
2082 (funcall inserter message)
2084 (message "Sorry, I don't have message inserter for your MUA.")
2087 (defun mime-editor/insert-mail (&optional message)
2089 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2090 (if (and inserter (fboundp inserter))
2092 (mime-editor/insert-tag "message" "rfc822")
2093 (funcall inserter message)
2095 (message "Sorry, I don't have mail inserter for your MUA.")
2098 (defun mime-editor/inserted-message-filter ()
2101 (let ((header-start (point))
2102 (case-fold-search t)
2105 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2106 (if (re-search-forward "^$" (mark t))
2107 (narrow-to-region header-start (match-beginning 0))
2109 (goto-char header-start)
2110 (while (and (re-search-forward
2111 mime-editor/yank-ignored-field-regexp nil t)
2112 (setq beg (match-beginning 0))
2113 (setq end (1+ (rfc822/field-end)))
2115 (delete-region beg end)
2120 ;;; @ multipart enclosure
2123 (defun mime-editor/enclose-region (type beg end)
2126 (let ((current (point))
2129 (if (mime-editor/goto-tag)
2130 (or (eq current (match-beginning 0))
2131 (setq exist-prev-tag t)
2134 (narrow-to-region beg end)
2139 (insert (format "--<<%s>>-{\n" type))
2140 (goto-char (point-max))
2141 (insert (format "\n--}-<<%s>>\n" type))
2142 (goto-char (point-max))
2144 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
2146 (insert (mime-make-text-tag) "\n")
2150 (defun mime-editor/enclose-mixed-region (beg end)
2152 (mime-editor/enclose-region "mixed" beg end)
2155 (defun mime-editor/enclose-parallel-region (beg end)
2157 (mime-editor/enclose-region "parallel" beg end)
2160 (defun mime-editor/enclose-digest-region (beg end)
2162 (mime-editor/enclose-region "digest" beg end)
2165 (defun mime-editor/enclose-alternative-region (beg end)
2167 (mime-editor/enclose-region "alternative" beg end)
2170 (defun mime-editor/enclose-signed-region (beg end)
2172 (if mime-editor/signing-type
2173 (mime-editor/enclose-region "signed" beg end)
2174 (message "Please specify signing type.")
2177 (defun mime-editor/enclose-encrypted-region (beg end)
2179 (if mime-editor/signing-type
2180 (mime-editor/enclose-region "encrypted" beg end)
2181 (message "Please specify encrypting type.")
2184 (defun mime-editor/insert-key (&optional arg)
2185 "Insert a pgp public key."
2187 (mime-editor/insert-tag "application" "pgp-keys")
2188 (mime-editor/define-encoding "7bit")
2189 (mc-insert-public-key)
2196 (defun mime-editor/set-split (arg)
2199 (y-or-n-p "Do you want to enable split?")
2201 (setq mime-editor/split-message arg)
2203 (message "This message is enabled to split.")
2204 (message "This message is not enabled to split.")
2207 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2208 "Toggle transfer-level is 7bit or 8bit through.
2210 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2212 (if (numberp transfer-level)
2213 (setq mime-editor/transfer-level transfer-level)
2214 (if (< mime-editor/transfer-level 8)
2215 (setq mime-editor/transfer-level 8)
2216 (setq mime-editor/transfer-level 7)
2218 (setq mime-editor/charset-default-encoding-alist
2219 (mime/make-charset-default-encoding-alist
2220 mime-editor/transfer-level))
2221 (message (format "Current transfer-level is %d bit"
2222 mime-editor/transfer-level))
2223 (setq mime-editor/transfer-level-string
2224 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2225 (force-mode-line-update)
2232 (defun mime-editor/set-sign (arg)
2235 (y-or-n-p "Do you want to sign?")
2238 (if mime-editor/signing-type
2240 (setq mime-editor/pgp-processing 'sign)
2241 (message "This message will be signed.")
2243 (message "Please specify signing type.")
2245 (if (eq mime-editor/pgp-processing 'sign)
2246 (setq mime-editor/pgp-processing nil)
2248 (message "This message will not be signed.")
2251 (defun mime-editor/set-encrypt (arg)
2254 (y-or-n-p "Do you want to encrypt?")
2257 (if mime-editor/encrypting-type
2259 (setq mime-editor/pgp-processing 'encrypt)
2260 (message "This message will be encrypt.")
2262 (message "Please specify encrypting type.")
2264 (if (eq mime-editor/pgp-processing 'encrypt)
2265 (setq mime-editor/pgp-processing nil)
2267 (message "This message will not be encrypt.")
2270 (defvar mime-editor/pgp-processing nil)
2271 (make-variable-buffer-local 'mime-editor/pgp-processing)
2273 (defun mime-editor/pgp-enclose-buffer ()
2274 (let ((beg (save-excursion
2275 (goto-char (point-min))
2276 (if (search-forward (concat "\n" mail-header-separator "\n"))
2282 (cond ((eq mime-editor/pgp-processing 'sign)
2283 (mime-editor/enclose-signed-region beg end)
2285 ((eq mime-editor/pgp-processing 'encrypt)
2286 (mime-editor/enclose-encrypted-region beg end)
2294 (defun mime-editor/insert-partial-header
2295 (fields subject id number total separator)
2297 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2298 (insert (format "Mime-Version: 1.0 (split by tm-edit %s)\n"
2299 mime-editor/version))
2301 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2302 id number total separator))
2305 (defun mime-editor/split-and-send
2306 (&optional cmd lines mime-editor/message-max-length)
2310 (count-lines (point-min) (point-max)))
2312 (or mime-editor/message-max-length
2313 (setq mime-editor/message-max-length
2314 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2315 mime-editor/message-default-max-length))
2317 (let* ((mime-editor/draft-file-name
2318 (or (buffer-file-name)
2320 (expand-file-name "tm-draft" mime/tmp-dir))))
2321 (separator mail-header-separator)
2323 (eval (cdr (assq major-mode mime-editor/window-config-alist))))
2325 (replace-space-with-underline (current-time-string))
2326 "@" (system-name) "\"")))
2327 (run-hooks 'mime-editor/before-split-hook)
2328 (let* ((header (rfc822/get-header-string-except
2329 mime-editor/split-ignored-field-regexp separator))
2330 (subject (mail-fetch-field "subject"))
2331 (total (+ (/ lines mime-editor/message-max-length)
2332 (if (> (mod lines mime-editor/message-max-length) 0)
2334 (the-buf (current-buffer))
2335 (buf (get-buffer "*tmp-send*"))
2340 mime-editor/split-message-sender-alist))
2343 mime-editor/message-default-sender-alist))
2346 (goto-char (point-min))
2347 (if (re-search-forward (concat "^" (regexp-quote separator) "$")
2353 (switch-to-buffer buf)
2355 (switch-to-buffer the-buf)
2357 (setq buf (get-buffer-create "*tmp-send*"))
2359 (switch-to-buffer buf)
2360 (make-local-variable 'mail-header-separator)
2361 (setq mail-header-separator separator)
2362 (switch-to-buffer the-buf)
2363 (goto-char (point-min))
2364 (re-search-forward "^$" nil t)
2365 (let ((mime-editor/partial-number 1))
2366 (setq data (buffer-substring
2369 (goto-line mime-editor/message-max-length)
2372 (delete-region (point-min)(point))
2373 (switch-to-buffer buf)
2374 (mime-editor/insert-partial-header
2375 header subject id mime-editor/partial-number total separator)
2379 (goto-char (point-min))
2380 (search-forward (concat "\n" mail-header-separator "\n"))
2383 (if (re-search-forward "^$" nil t)
2387 (goto-char (point-min))
2388 (while (re-search-forward
2389 mime-editor/split-blind-field-regexp nil t)
2390 (delete-region (match-beginning 0)
2391 (let ((e (rfc822/field-end)))
2392 (if (< e (point-max))
2398 (message (format "Sending %d/%d..."
2399 mime-editor/partial-number total))
2400 (call-interactively command)
2401 (message (format "Sending %d/%d... done"
2402 mime-editor/partial-number total))
2405 (switch-to-buffer the-buf)
2406 (setq mime-editor/partial-number 2)
2407 (while (< mime-editor/partial-number total)
2408 (setq data (buffer-substring
2411 (goto-line mime-editor/message-max-length)
2414 (delete-region (point-min)(point))
2415 (switch-to-buffer buf)
2416 (mime-editor/insert-partial-header
2417 header subject id mime-editor/partial-number total separator)
2420 (message (format "Sending %d/%d..."
2421 mime-editor/partial-number total))
2422 (call-interactively command)
2423 (message (format "Sending %d/%d... done"
2424 mime-editor/partial-number total))
2427 (switch-to-buffer the-buf)
2428 (setq mime-editor/partial-number
2429 (1+ mime-editor/partial-number))
2431 (goto-char (point-min))
2432 (mime-editor/insert-partial-header
2433 header subject id mime-editor/partial-number total separator)
2434 (message (format "Sending %d/%d..."
2435 mime-editor/partial-number total))
2438 (defun mime-editor/maybe-split-and-send (&optional cmd)
2440 (run-hooks 'mime-editor/before-send-hook)
2441 (let ((mime-editor/message-max-length
2442 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2443 mime-editor/message-default-max-length))
2444 (lines (count-lines (point-min) (point-max)))
2446 (if (and (> lines mime-editor/message-max-length)
2447 mime-editor/split-message)
2448 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2452 ;;; @ preview message
2455 (defun mime-editor/preview-message ()
2456 "preview editing MIME message. [tm-edit.el]"
2458 (let* ((str (buffer-string))
2459 (separator mail-header-separator)
2460 (the-buf (current-buffer))
2461 (buf-name (buffer-name))
2462 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2463 (buf (get-buffer temp-buf-name))
2467 (switch-to-buffer buf)
2470 (setq buf (get-buffer-create temp-buf-name))
2471 (switch-to-buffer buf)
2474 (setq major-mode 'mime/temporary-message-mode)
2475 (make-local-variable 'mail-header-separator)
2476 (setq mail-header-separator separator)
2477 (make-local-variable 'mime/editing-buffer)
2478 (setq mime/editing-buffer the-buf)
2480 (run-hooks 'mime-editor/translate-hook)
2481 (mime-editor/translate-buffer)
2482 (goto-char (point-min))
2483 (if (re-search-forward
2484 (concat "^" (regexp-quote separator) "$"))
2490 (defun mime-editor/quitting-method ()
2491 (let ((temp mime::preview/article-buffer)
2493 (mime-viewer/kill-buffer)
2495 (setq buf mime/editing-buffer)
2497 (switch-to-buffer buf)
2500 (set-alist 'mime-viewer/quitting-method-alist
2501 'mime/temporary-message-mode
2502 (function mime-editor/quitting-method)
2508 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2509 ;; Mon, 10 Apr 1995 20:03:07 +0900
2511 (defvar mime-editor/draft-header-separator-alist
2512 '((news-reply-mode . mail-header-separator)
2513 (mh-letter-mode . mail-header-separator)
2516 (defvar mime::article/draft-header-separator nil)
2518 (defun mime-editor/draft-preview ()
2520 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2521 (or (stringp sep) (setq sep (eval sep)))
2522 (make-variable-buffer-local 'mime::article/draft-header-separator)
2523 (goto-char (point-min))
2525 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2526 (setq mime::article/draft-header-separator
2527 (buffer-substring (match-beginning 0) (match-end 0)))
2529 (mime/viewer-mode (current-buffer))
2530 (pop-to-buffer (current-buffer))
2533 (defun mime-viewer::quitting-method/draft-preview ()
2534 (let ((mother mime::preview/mother-buffer))
2536 (switch-to-buffer mother)
2537 (goto-char (point-min))
2541 (regexp-quote mime::article/draft-header-separator)
2545 (insert mime::article/draft-header-separator)
2546 (set-buffer-modified-p (buffer-modified-p))
2548 (mime-viewer/kill-buffer)
2549 (pop-to-buffer mother)
2552 (set-alist 'mime-viewer/quitting-method-alist
2554 (function mime-viewer::quitting-method/draft-preview)
2557 (set-alist 'mime-viewer/quitting-method-alist
2559 (function mime-viewer::quitting-method/draft-preview)
2566 (defun mime-editor::edit-again (code-conversion)
2568 (goto-char (point-min))
2569 (let ((ctl (mime/Content-Type)))
2571 (let ((ctype (car ctl))
2574 (if (string-match "/" ctype)
2576 (setq type (substring ctype 0 (match-beginning 0)))
2577 (setq stype (substring ctype (match-end 0)))
2582 ((string-equal type "multipart")
2583 (let ((boundary (assoc-value "boundary" params)))
2584 (re-search-forward (concat "\n--" boundary) nil t)
2585 (let ((bb (match-beginning 0)) eb tag)
2586 (setq tag (format "\n--<<%s>>-{" stype))
2589 (setq bb (+ bb (length tag)))
2590 (re-search-forward (concat "\n--" boundary "--") nil t)
2591 (setq eb (match-beginning 0))
2592 (replace-match (format "\n--}-<<%s>>" stype))
2594 (narrow-to-region bb eb)
2595 (goto-char (point-min))
2596 (while (re-search-forward
2597 (concat "\n--" boundary "\n") nil t)
2598 (let ((beg (match-beginning 0))
2600 (delete-region beg (match-end 0))
2602 (if (re-search-forward
2603 (concat "\n--" boundary) nil t)
2604 (setq end (match-beginning 0))
2605 (setq end (point-max))
2608 (narrow-to-region beg end)
2609 (mime-editor::edit-again code-conversion)
2610 (goto-char (point-max))
2613 (goto-char (point-min))
2614 (or (= (point-min) 1)
2615 (delete-region (point-min)
2616 (if (re-search-forward "^$" nil t)
2624 (mapconcat (function
2626 (if (string-equal (car attr)
2629 (setq charset (cdr attr))
2631 (concat ";" (car attr)
2639 (if (re-search-forward
2640 "Content-Transfer-Encoding:" nil t)
2641 (let ((beg (match-beginning 0))
2642 (hbeg (match-end 0))
2643 (end (rfc822/field-end)))
2645 (eliminate-top-spaces
2646 (rfc822/unfolding-string
2647 (buffer-substring hbeg end))))
2648 (if (or charset (string-equal type "text"))
2650 (delete-region beg (1+ end))
2651 (goto-char (point-min))
2652 (if (search-forward "\n\n" nil t)
2655 (match-end 0)(point-max) encoding)
2659 (if (or code-conversion encoded)
2661 (mime-charset-decode-region (point-min)(point-max)
2663 (character-decode-region (point-min)(point-max)
2664 mime/default-coding-system)
2667 (if (re-search-forward "^$" nil t)
2671 (if (= (point-min) 1)
2678 (concat type "/" stype pstr) encoding)
2681 (delete-region (point-min) he)
2685 (concat type "/" stype pstr) encoding)
2690 (character-decode-region (point-min) (point-max)
2691 mime/default-coding-system)
2695 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2697 (mime-editor::edit-again code-conversion)
2698 (goto-char (point-min))
2700 (narrow-to-region (point-min)
2701 (if (re-search-forward "^$" nil t)
2705 (goto-char (point-min))
2706 (while (re-search-forward
2707 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2708 (delete-region (match-beginning 0) (1+ (rfc822/field-end)))
2711 (and (re-search-forward "^$")
2712 (replace-match mail-header-separator)
2724 (run-hooks 'tm-edit-load-hook)
2726 ;;; tm-edit.el ends here