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.53 $
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.53 1996/04/29 01:52:53 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 specified by mime-signature-file
162 (`.signature.rtf' by default) automatically, call the function
163 `mime-editor/insert-signature' from this hook.")
165 (defvar mime-editor/exit-hook nil
166 "*Hook called when exit MIME mode.")
168 (defvar mime-content-types
170 ;; Charset parameter need not to be specified, since it is
171 ;; defined automatically while translation.
173 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
176 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
179 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
182 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
185 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
193 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
194 ("directory" "/pub/GNU/elisp/mime")
196 ("mode" "image" "ascii" "local8"))
201 ("mode" "image" "ascii" "local8"))
202 ("tftp" ("site") ("name"))
203 ("afs" ("site") ("name"))
204 ("local-file" ("site") ("name"))
205 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
210 ("octet-stream" ("type" "" "tar" "shar"))
212 ("x-kiss" ("x-cnf")))
225 "*Alist of content-type, subtype, parameters and its values.")
227 (defvar mime-file-types
229 "text" "richtext" nil
237 "application" "postscript" nil
239 "attachment" (("filename" . file))
244 "inline" (("filename" . file))
249 "inline" (("filename" . file))
254 "inline" (("filename" . file))
259 "inline" (("filename" . file))
264 "inline" (("filename" . file))
269 "inline" (("filename" . file))
274 "inline" (("filename" . file))
279 "attachment" (("filename" . file))
284 "attachment" (("filename" . file))
287 "application" "octet-stream" (("type" . "emacs-lisp"))
289 "attachment" (("filename" . file))
292 "application" "octet-stream" (("type" . "common-lisp"))
294 "attachment" (("filename" . file))
297 "application" "octet-stream" (("type" . "tar+gzip"))
299 "attachment" (("filename" . file))
302 "application" "octet-stream" (("type" . "tar+gzip"))
304 "attachment" (("filename" . file))
307 "application" "octet-stream" (("type" . "tar+compress"))
309 "attachment" (("filename" . file))
312 "application" "octet-stream" (("type" . "tar+compress"))
314 "attachment" (("filename" . file))
317 "application" "octet-stream" (("type" . "gzip"))
319 "attachment" (("filename" . file))
322 "application" "octet-stream" (("type" . "compress"))
324 "attachment" (("filename" . file))
327 "application" "octet-stream" (("type" . "lha"))
329 "attachment" (("filename" . file))
332 "application" "zip" nil
334 "attachment" (("filename" . file))
337 "application" "octet-stream" (("type" . "patch"))
339 "attachment" (("filename" . file))
342 "text" "plain" nil nil)
344 "application" "octet-stream" nil
346 "attachment" (("filename" . file))
349 "*Alist of file name, types, parameters, and default encoding.
350 If encoding is nil, it is determined from its contents.")
352 ;;; @@ about charset, encoding and transfer-level
355 (defvar mime-editor/transfer-level 7
356 "*A number of network transfer level. It should be bigger than 7.")
357 (make-variable-buffer-local 'mime-editor/transfer-level)
359 (defvar mime-editor/transfer-level-string
360 (mime/encoding-name mime-editor/transfer-level 'not-omit)
361 "*A string formatted version of mime/defaul-transfer-level")
362 (make-variable-buffer-local 'mime-editor/transfer-level-string)
364 (defvar mime-editor/charset-default-encoding-alist
365 (mime/make-charset-default-encoding-alist mime-editor/transfer-level))
366 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
368 ;;; @@ about message inserting
371 (defvar mime-editor/yank-ignored-field-list
372 '("Received" "Sender" "Approved" "Path" "Status" "X-VM-.*" "X-UIDL")
373 "Delete these fields from original message when it is inserted
374 as message/rfc822 part.
375 Each elements are regexp of field-name. [tm-edit.el]")
377 (defvar mime-editor/yank-ignored-field-regexp
379 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
382 (defvar mime-editor/message-inserter-alist nil)
383 (defvar mime-editor/mail-inserter-alist nil)
385 ;;; @@ about message splitting
388 (defvar mime-editor/split-message t
389 "*Split large message if it is non-nil. [tm-edit.el]")
391 (defvar mime-editor/message-default-max-length 1000
392 "*Default maximum size of a message. [tm-edit.el]")
394 (defvar mime-editor/message-max-length-alist
395 '((news-reply-mode . 500)))
397 (defconst mime-editor/split-ignored-field-regexp
398 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
400 (defvar mime-editor/split-blind-field-regexp
401 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
403 (defvar mime-editor/message-default-sender-alist
404 '((mail-mode . mail-send-and-exit)
405 (mh-letter-mode . mh-send-letter)
406 (news-reply-mode . gnus-inews-news)
409 (defvar mime-editor/split-message-sender-alist
416 . (lambda (&optional arg)
418 (write-region (point-min) (point-max)
419 mime-editor/draft-file-name nil 'no-message)
421 (pop-to-buffer "MH mail delivery")
423 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
425 mh-send-args mime-editor/draft-file-name)
426 (goto-char (point-max)) ; show the interesting part
430 (apply 'mh-exec-cmd-quiet t mh-send-prog
432 (list "-nopush" "-nodraftfolder"
433 "-noverbose" "-nowatch"
434 mh-send-args mime-editor/draft-file-name)))))
438 (defvar mime-editor/window-config-alist
440 (mh-letter-mode . mh-previous-window-config)
441 (news-reply-mode . (cond ((boundp 'gnus-winconf-post-news)
443 gnus-winconf-post-news
444 (setq gnus-winconf-post-news nil)
446 ((boundp 'gnus-prev-winconf)
449 (setq gnus-prev-winconf nil)
454 (defvar mime-editor/news-reply-mode-server-running nil)
460 (defvar mime-editor/signing-type nil
461 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
463 (defvar mime-editor/encrypting-type nil
464 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
466 (if (or mime-editor/signing-type mime-editor/encrypting-type)
474 (defconst mime-editor/single-part-tag-regexp
475 "^--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
476 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
478 (defconst mime-editor/multipart-beginning-regexp "^--<<\\([^<>]+\\)>>-{\n")
480 (defconst mime-editor/multipart-end-regexp "^--}-<<\\([^<>]+\\)>>\n")
482 (defconst mime-editor/beginning-tag-regexp
483 (regexp-or mime-editor/single-part-tag-regexp
484 mime-editor/multipart-beginning-regexp))
486 (defconst mime-editor/end-tag-regexp
487 (regexp-or mime-editor/single-part-tag-regexp
488 mime-editor/multipart-end-regexp))
490 (defconst mime-editor/tag-regexp
491 (regexp-or mime-editor/single-part-tag-regexp
492 mime-editor/multipart-beginning-regexp
493 mime-editor/multipart-end-regexp))
495 (defvar mime-tag-format "--[[%s]]"
496 "*Control-string making a MIME tag.")
498 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
499 "*Control-string making a MIME tag with encoding.")
501 ;;; @@ multipart boundary
504 (defvar mime-multipart-boundary "Multipart"
505 "*Boundary of a multipart message.")
508 ;;; @@ buffer local variables
511 (defvar mime/editor-mode-old-local-map nil)
512 (defvar mime/editor-mode-old-selective-display nil)
513 (defvar mime/editing-buffer nil)
519 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
520 "*Specify MIME tspecials.
521 Tspecials means any character that matches with it in header must be quoted.")
523 (defconst mime-editor/mime-version-value
524 (format "1.0 (generated by tm-edit %s)" mime-editor/version)
525 "MIME version number.")
527 (defconst mime-editor/mime-map (make-sparse-keymap)
528 "Keymap for MIME commands.")
530 ;;; @ keymap and menu
533 (defvar mime/editor-mode-flag nil)
534 (make-variable-buffer-local 'mime/editor-mode-flag)
536 (set-alist 'minor-mode-alist
537 'mime/editor-mode-flag
538 '((" MIME-Edit " mime-editor/transfer-level-string)))
540 (defun mime-editor/define-keymap (keymap)
541 "Add mime-editor commands to KEYMAP."
542 (if (not (keymapp keymap))
544 (define-key keymap "\C-t" 'mime-editor/insert-text)
545 (define-key keymap "\C-i" 'mime-editor/insert-file)
546 (define-key keymap "\C-e" 'mime-editor/insert-external)
547 (define-key keymap "\C-v" 'mime-editor/insert-voice)
548 (define-key keymap "\C-y" 'mime-editor/insert-message)
549 (define-key keymap "\C-m" 'mime-editor/insert-mail)
550 (define-key keymap "\C-w" 'mime-editor/insert-signature)
551 (define-key keymap "\C-s" 'mime-editor/insert-signature)
552 (define-key keymap "\C-k" 'mime-editor/insert-key)
553 (define-key keymap "t" 'mime-editor/insert-tag)
554 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
555 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
556 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
557 (define-key keymap "d" 'mime-editor/enclose-digest-region)
558 (define-key keymap "s" 'mime-editor/enclose-signed-region)
559 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
560 (define-key keymap "\C-p" 'mime-editor/preview-message)
561 (define-key keymap "\C-z" 'mime-editor/exit)
562 (define-key keymap "?" 'mime-editor/help)
565 (mime-editor/define-keymap mime-editor/mime-map)
567 (defconst mime-editor/menu-title "MIME-Edit")
569 (defconst mime-editor/menu-list
570 '((mime-help "Describe MIME editor mode" mime-editor/help)
571 (file "Insert File" mime-editor/insert-file)
572 (external "Insert External" mime-editor/insert-external)
573 (voice "Insert Voice" mime-editor/insert-voice)
574 (message "Insert Message" mime-editor/insert-message)
575 (mail "Insert Mail" mime-editor/insert-mail)
576 (signature "Insert Signature" mime-editor/insert-signature)
577 (text "Insert Text" mime-editor/insert-text)
578 (tag "Insert Tag" mime-editor/insert-tag)
579 (alternative "Enclose as alternative"
580 mime-editor/enclose-alternative-region)
581 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
582 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
583 (digest "Enclose as digest" mime-editor/enclose-digest-region)
584 (signed "Enclose as signed" mime-editor/enclose-signed-region)
585 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
586 (key "Insert Public Key" mime-editor/insert-key)
587 (split "About split" mime-editor/set-split)
588 (sign "About sign" mime-editor/set-sign)
589 (encrypt "About encryption" mime-editor/set-encrypt)
590 (preview "Preview Message" mime-editor/preview-message)
591 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
593 "MIME-edit menubar entry.")
595 (defun mime-editor/define-menu-for-emacs19 ()
596 "Define menu for Emacs 19."
597 (define-key (current-local-map) [menu-bar mime-edit]
598 (cons mime-editor/menu-title
599 (make-sparse-keymap mime-editor/menu-title)))
602 (define-key (current-local-map)
603 (vector 'menu-bar 'mime-edit (car item))
604 (cons (nth 1 item)(nth 2 item))
607 (reverse mime-editor/menu-list)
610 ;;; modified by Pekka Marjola <pema@niksula.hut.fi>
611 ;;; 1995/9/5 (c.f. [tm-en:69])
612 (defun mime-editor/define-menu-for-xemacs ()
613 "Define menu for Emacs 19."
614 (cond ((featurep 'menubar)
615 (make-local-variable 'current-menubar)
616 (set-buffer-menubar current-menubar)
618 (cons mime-editor/menu-title
621 (vector (nth 1 item)(nth 2 item)
622 mime/editor-mode-flag)
624 mime-editor/menu-list)))
627 ;;; modified by Steven L. Baur <steve@miranova.com>
628 ;;; 1995/12/6 (c.f. [tm-en:209])
629 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
630 (setq mime-editor/popup-menu-for-xemacs
631 (append '("MIME Commands" "---")
632 (mapcar (function (lambda (item)
636 mime-editor/menu-list)))
645 (defun mime/editor-mode ()
646 "MIME minor mode for editing the tagged MIME message.
648 In this mode, basically, the message is composed in the tagged MIME
649 format. The message tag looks like:
651 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
653 The tag specifies the MIME content type, subtype, optional parameters
654 and transfer encoding of the message following the tag. Messages
655 without any tag are treated as `text/plain' by default. Charset and
656 transfer encoding are automatically defined unless explicitly
657 specified. Binary messages such as audio and image are usually hidden
658 using selective-display facility. The messages in the tagged MIME
659 format are automatically translated into a MIME compliant message when
662 Available charsets depend on Emacs version being used. The following
663 lists the available charsets of each emacs.
665 Emacs18: US-ASCII is only available.
666 NEmacs: US-ASCII and ISO-2022-JP are available.
667 Emacs19: US-ASCII and ISO-8859-1 are available.
668 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-6),
669 ISO-2022-JP, ISO-2022-JP-2 and ISO-2022-INT-1 are available.
671 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in Mule is expected to
672 be used to represent multilingual text in intermixed manner. Any
673 languages that has no registered charset are represented as either
674 ISO-2022-JP-2 or ISO-2022-INT-1 in Mule.
676 Following commands are available in addition to major mode commands:
677 \\[mime-editor/insert-text] insert a text message.
678 \\[mime-editor/insert-file] insert a (binary) file.
679 \\[mime-editor/insert-external] insert a reference to external body.
680 \\[mime-editor/insert-voice] insert a voice message.
681 \\[mime-editor/insert-message] insert a mail or news message.
682 \\[mime-editor/insert-mail] insert a mail message.
683 \\[mime-editor/insert-signature] insert a signature file at end.
684 \\[mime-editor/insert-tag] insert a new MIME tag.
685 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
686 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
687 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
688 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
689 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
690 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
691 \\[mime-editor/insert-key] insert PGP public key.
692 \\[mime-editor/preview-message] preview editing MIME message.
693 \\[mime-editor/exit] exit and translate into a MIME compliant message.
694 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
695 \\[mime-editor/help] show this help.
697 Additional commands are available in some major modes:
698 C-c C-c exit, translate and run the original command.
699 C-c C-s exit, translate and run the original command.
701 The following is a message example written in the tagged MIME format.
702 TABs at the beginning of the line are not a part of the message:
704 This is a conventional plain text. It should be translated
707 This is also a plain text. But, it is explicitly specified as
709 --[[text/plain; charset=ISO-2022-JP]]
710 \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
713 <center>This is a richtext.</center>
714 --[[image/gif][base64]]^M...image encoded in base64 here...
715 --[[audio/basic][base64]]^M...audio encoded in base64 here...
717 User customizable variables (not documented all of them):
719 Specifies a key prefix for MIME minor mode commands.
722 Specifies a signature file to be included as part of a multipart
725 mime-ignore-preceding-spaces
726 Preceding white spaces in a message body are ignored if non-nil.
728 mime-ignore-trailing-spaces
729 Trailing white spaces in a message body are ignored if non-nil.
731 mime-auto-fill-header
732 Fill header fields that contain encoded-words if non-nil.
735 Hide a non-textual body message encoded in base64 after insertion
739 Specifies a function to record a voice message and return a buffer
740 that contains it. The function mime-voice-recorder-for-sun is for
743 mime/editor-mode-hook
744 Turning on MIME mode calls the value of mime/editor-mode-hook, if
747 mime-editor/translate-hook
748 The value of mime-editor/translate-hook is called just before translating
749 the tagged MIME format into a MIME compliant message if it is
750 non-nil. If the hook call the function mime-editor/insert-signature,
751 the signature file will be inserted automatically.
753 mime-editor/exit-hook
754 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
757 (if mime/editor-mode-flag
758 (error "You are already editing a MIME message.")
759 (setq mime/editor-mode-flag t)
760 ;; Remember old key bindings.
763 (make-local-variable 'mime/editor-mode-old-local-map)
764 (setq mime/editor-mode-old-local-map (current-local-map))
765 ;; Add MIME commands to current local map.
766 (use-local-map (copy-keymap (current-local-map)))
768 (if (not (lookup-key (current-local-map) mime-prefix))
769 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
771 ;; Set transfer level into mode line
773 (setq mime-editor/transfer-level-string
774 (mime/encoding-name mime-editor/transfer-level 'not-omit))
775 (force-mode-line-update)
777 ;; Define menu. Menus for other emacs implementations are
779 ;; modified by Pekka Marjola <pema@niksula.hut.fi>
780 ;; 1995/9/5 (c.f. [tm-eng:69])
781 (cond (running-xemacs
782 (mime-editor/define-menu-for-xemacs))
783 ((string-match "^19\\." emacs-version)
784 (mime-editor/define-menu-for-emacs19)
788 ;; Remember old selective-display.
789 (make-local-variable 'mime/editor-mode-old-selective-display)
790 (setq mime/editor-mode-old-selective-display selective-display)
791 (setq selective-display t)
792 ;; I don't care about saving these.
793 (setq paragraph-start
794 (regexp-or mime-editor/single-part-tag-regexp
796 (setq paragraph-separate
797 (regexp-or mime-editor/single-part-tag-regexp
799 (run-hooks 'mime/editor-mode-hook)
801 (substitute-command-keys
802 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
806 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
807 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
809 (defun mime-editor/exit (&optional nomime no-error)
810 "Translate the tagged MIME message into a MIME compliant message.
811 With no argument encode a message in the buffer into MIME, otherwise
812 just return to previous mode."
814 (if (not mime/editor-mode-flag)
816 (error "You aren't editing a MIME message.")
820 (run-hooks 'mime-editor/translate-hook)
821 (mime-editor/translate-buffer)))
822 ;; Restore previous state.
823 (setq mime/editor-mode-flag nil)
824 (cond (running-xemacs
825 ;; mime-prefix only defined if binding was nil
826 (if (eq (lookup-key (current-local-map) mime-prefix)
827 mime-editor/mime-map)
828 (define-key (current-local-map) mime-prefix nil))
829 (delete-menu-item (list mime-editor/menu-title)))
831 (use-local-map mime/editor-mode-old-local-map)))
833 (setq selective-display mime/editor-mode-old-selective-display)
834 (set-buffer-modified-p (buffer-modified-p))
835 (run-hooks 'mime-editor/exit-hook)
836 (message "Exit MIME editor mode.")
839 (defun mime-editor/maybe-translate ()
841 (mime-editor/exit nil t)
842 (call-interactively 'mime-editor/maybe-split-and-send)
845 (defun mime-editor/help ()
846 "Show help message about MIME mode."
848 (with-output-to-temp-buffer "*Help*"
849 (princ "MIME editor mode:\n")
850 (princ (documentation 'mime/editor-mode))
851 (print-help-return-message)))
853 (defun mime-editor/insert-text ()
854 "Insert a text message.
855 Charset is automatically obtained from the `mime/lc-charset-alist'."
857 (if (and (mime-editor/insert-tag "text" nil nil)
858 (looking-at mime-editor/single-part-tag-regexp))
860 ;; Make a space between the following message.
865 (defun mime-editor/insert-file (file)
866 "Insert a message from a file."
867 (interactive "fInsert file as MIME message: ")
868 (let* ((guess (mime-find-file-type file))
869 (pritype (nth 0 guess))
870 (subtype (nth 1 guess))
871 (parameters (nth 2 guess))
872 (default (nth 3 guess)) ;Guess encoding from its file name.
873 (disposition-type (nth 4 guess))
874 (disposition-params (nth 5 guess))
876 (if (not (interactive-p))
879 (concat "What transfer encoding"
882 (if (string-equal default "")
888 mime-encoding-method-alist nil t nil))))
889 (if (string-equal encoding "")
890 (setq encoding default))
891 (if (or (consp parameters) (stringp disposition-type))
892 (let ((rest parameters) cell attribute value)
895 (setq cell (car rest))
896 (setq attribute (car cell))
897 (setq value (cdr cell))
899 (setq value (rfc822/wrap-as-quoted-string
900 (file-name-nondirectory file)))
902 (setq parameters (concat parameters "; " attribute "=" value))
903 (setq rest (cdr rest))
908 (concat parameters "\n"
909 "Content-Disposition: " disposition-type))
910 (setq rest disposition-params)
912 (setq cell (car rest))
913 (setq attribute (car cell))
914 (setq value (cdr cell))
916 (setq value (rfc822/wrap-as-quoted-string
917 (file-name-nondirectory file)))
920 (concat parameters "; " attribute "=" value))
921 (setq rest (cdr rest))
925 (mime-editor/insert-tag pritype subtype parameters)
926 (mime-editor/insert-binary-file file encoding)
929 (defun mime-editor/insert-external ()
930 "Insert a reference to external body."
932 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
934 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
936 (let* ((pritype (mime-prompt-for-type))
937 (subtype (mime-prompt-for-subtype pritype))
938 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
941 (insert "Content-Type: "
942 pritype "/" subtype (or parameters "") "\n")))
943 (if (and (not (eobp))
944 (not (looking-at mime-editor/single-part-tag-regexp)))
945 (insert (mime-make-text-tag) "\n")))
947 (defun mime-editor/insert-voice ()
948 "Insert a voice message."
950 (mime-editor/insert-tag "audio" "basic" nil)
951 (let ((buffer (funcall mime-voice-recorder)))
953 (mime-editor/insert-binary-buffer buffer "base64")
957 (defun mime-editor/insert-signature (&optional arg)
958 "Insert a signature file specified by mime-signature-file."
960 (let ((signature-insert-hook
963 (apply (function mime-editor/insert-tag)
964 (mime-find-file-type signature))
967 (insert-signature arg)
971 ;; Insert a new tag around a point.
973 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
974 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
975 If nothing is inserted, return nil."
980 exist-prev-tag exist-next-tag)
983 (mime-prompt-for-type)))
986 (mime-prompt-for-subtype pritype)))
989 (mime-prompt-for-parameters pritype subtype delimiter)))
990 ;; Make a new MIME tag.
991 (setq newtag (mime-make-tag pritype subtype parameters))
992 ;; Find an current MIME tag.
995 (if (mime-editor/goto-tag)
997 (if (eq current (match-beginning 0))
998 (setq exist-next-tag t)
999 (setq exist-prev-tag t)
1001 (buffer-substring (match-beginning 0) (match-end 0))
1003 ;; Assume content type is 'text/plan'.
1004 (mime-make-tag "text" "plain")
1006 ;; We are only interested in TEXT.
1008 (not (mime-test-content-type
1009 (mime-editor/get-contype oldtag) "text")))
1011 (cond (exist-prev-tag (insert "\n"))
1012 (exist-next-tag (save-excursion
1021 (if (or (not oldtag) ;Not text
1022 (or mime-ignore-same-text-tag
1023 (not (string-equal oldtag newtag))))
1025 ;; Mark the beginning of the tag for convenience.
1026 (push-mark (point) 'nomsg)
1027 (insert newtag "\n")
1028 (list pritype subtype parameters) ;New tag is created.
1030 ;; Restore previous point.
1032 nil ;Nothing is created.
1036 ;; Insert the binary content after MIME tag.
1037 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1039 (defun mime-editor/insert-binary-file (file &optional encoding)
1040 "Insert binary FILE at point.
1041 Optional argument ENCODING specifies an encoding method such as base64."
1042 (let ((tmpbuf (get-buffer-create " *MIME insert*")))
1046 (let ((mc-flag nil) ;Mule
1047 (file-coding-system-for-read
1048 (if (featurep 'mule) *noconv*))
1049 (kanji-flag nil) ;NEmacs
1050 (emx-binary-mode t) ;Stop CRLF to LF conversion in OS/2
1052 (let (jka-compr-compression-info-list
1053 jam-zcat-filename-list)
1054 (insert-file-contents file))))
1056 (if (and (stringp encoding)
1057 (string-equal (downcase encoding) "x-uue"))
1060 (let ((uuencode-external-encoder
1061 (cons (car uuencode-external-encoder)
1062 (list (file-name-nondirectory file))
1064 (mime-editor/insert-binary-buffer tmpbuf encoding)
1066 (mime-editor/insert-binary-buffer tmpbuf encoding))
1067 (kill-buffer tmpbuf))))
1069 ;; Insert the binary content after MIME tag.
1070 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1072 (defun mime-editor/insert-binary-buffer (buffer &optional encoding)
1073 "Insert binary BUFFER at point.
1074 Optional argument ENCODING specifies an encoding method such as base64."
1075 (let* ((tagend (1- (point))) ;End of the tag
1076 (hide-p (and mime-auto-hide-body
1078 (let ((en (downcase encoding)))
1079 (or (string-equal en "base64")
1080 (string-equal en "x-uue")
1084 (narrow-to-region (1- (point)) (point))
1085 (let ((start (point))
1086 (emx-binary-mode t)) ;Stop LF to CRLF conversion in OS/2
1087 (insert-buffer-substring buffer)
1088 ;; Encode binary message if necessary.
1090 (mime-encode-region encoding start (point-max))))
1093 (mime-flag-region (point-min) (1- (point-max)) ?\^M)
1094 (goto-char (point-max)))
1096 ;; Define encoding even if it is 7bit.
1097 (if (stringp encoding)
1099 (goto-char tagend) ;Make sure which line the tag is on.
1100 (mime-editor/define-encoding encoding)))
1104 ;; Commands work on a current message flagment.
1106 (defun mime-editor/goto-tag ()
1107 "Search for the beginning of the tagged MIME message."
1108 (let ((current (point)) multipart)
1109 (if (looking-at mime-editor/tag-regexp)
1111 ;; At first, go to the end.
1112 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1113 (goto-char (match-beginning 0)) ;For multiline tag
1118 (goto-char (point-max))
1120 ;; Then search for the beginning.
1121 (re-search-backward mime-editor/end-tag-regexp nil t)
1123 (or (looking-at mime-editor/beginning-tag-regexp)
1124 ;; Restore previous point.
1131 (defun mime-editor/content-beginning ()
1132 "Return the point of the beginning of content."
1134 (let ((beg (save-excursion
1135 (beginning-of-line) (point))))
1136 (if (mime-editor/goto-tag)
1137 (let ((top (point)))
1138 (goto-char (match-end 0))
1139 (if (and (= beg top)
1140 (= (following-char) ?\^M))
1144 ;; Default text/plain tag.
1145 (goto-char (point-min))
1147 (concat "\n" (regexp-quote mail-header-separator)
1148 (if mime-ignore-preceding-spaces
1149 "[ \t\n]*\n" "\n")) nil 'move)
1153 (defun mime-editor/content-end ()
1154 "Return the point of the end of content."
1156 (let ((beg (save-excursion
1157 (beginning-of-line) (point))))
1158 (if (mime-editor/goto-tag)
1159 (let ((top (point)))
1160 (goto-char (match-end 0))
1161 (if (and (= beg top) ;Must be on the same line.
1162 (= (following-char) ?\^M))
1166 ;; Move to the end of this text.
1167 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1168 ;; Don't forget a multiline tag.
1169 (goto-char (match-beginning 0)))
1172 ;; Assume the message begins with text/plain.
1173 (goto-char (mime-editor/content-beginning))
1174 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1175 ;; Don't forget a multiline tag.
1176 (goto-char (match-beginning 0)))
1180 (defun mime-editor/define-charset (charset)
1181 "Set charset of current tag to CHARSET."
1183 (if (mime-editor/goto-tag)
1184 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1185 (delete-region (match-beginning 0) (match-end 0))
1187 (mime-create-tag (mime-set-parameter
1188 (mime-editor/get-contype tag) "charset" charset)
1189 (mime-editor/get-encoding tag))))
1192 (defun mime-editor/define-encoding (encoding)
1193 "Set encoding of current tag to ENCODING."
1195 (if (mime-editor/goto-tag)
1196 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1197 (delete-region (match-beginning 0) (match-end 0))
1198 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1201 (defun mime-editor/choose-charset ()
1202 "Choose charset of a text following current point."
1203 (mime/find-charset-region (point) (mime-editor/content-end))
1206 (defun mime-make-text-tag (&optional subtype)
1207 "Make a tag for a text after current point.
1208 Subtype of text type can be specified by an optional argument SUBTYPE.
1209 Otherwise, it is obtained from mime-content-types."
1210 (let* ((pritype "text")
1211 (subtype (or subtype
1212 (car (car (cdr (assoc pritype mime-content-types)))))))
1213 ;; Charset should be defined later.
1214 (mime-make-tag pritype subtype)))
1217 ;; Tag handling functions
1219 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1220 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1221 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1225 (defun mime-create-tag (contype &optional encoding)
1226 "Make a tag with CONTENT-TYPE and optional ENCODING."
1227 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1230 (defun mime-editor/get-contype (tag)
1231 "Return Content-Type (including parameters) of TAG."
1233 (or (string-match mime-editor/single-part-tag-regexp tag)
1234 (string-match mime-editor/multipart-beginning-regexp tag)
1235 (string-match mime-editor/multipart-end-regexp tag)
1237 (substring tag (match-beginning 1) (match-end 1))
1240 (defun mime-editor/get-encoding (tag)
1241 "Return encoding of TAG."
1243 (string-match mime-editor/single-part-tag-regexp tag)
1245 (not (= (match-beginning 3) (match-end 3)))
1246 (substring tag (match-beginning 3) (match-end 3))))
1248 (defun mime-get-parameter (contype parameter)
1249 "For given CONTYPE return value for PARAMETER.
1250 Nil if no such parameter."
1254 (regexp-quote parameter)
1255 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1257 (substring contype (match-beginning 1) (match-end 1))
1258 nil ;No such parameter
1261 (defun mime-set-parameter (contype parameter value)
1262 "For given CONTYPE set PARAMETER to VALUE."
1266 (regexp-quote parameter)
1267 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1270 (concat (substring contype 0 (match-beginning 1))
1272 (substring contype (match-end 1)))
1273 (concat contype "; " parameter "=" value)))
1275 (defun mime-strip-parameters (contype)
1276 "Return primary content-type and subtype without parameters for CONTYPE."
1277 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1278 (substring contype (match-beginning 1) (match-end 1)) nil))
1280 (defun mime-test-content-type (contype type &optional subtype)
1281 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1282 (and (stringp contype)
1285 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1286 (downcase contype))))
1291 (defun mime-find-file-type (file)
1292 "Guess Content-Type, subtype, and parameters from FILE."
1294 (guesses mime-file-types))
1295 (while (and (not guess) guesses)
1296 (if (string-match (car (car guesses)) file)
1297 (setq guess (cdr (car guesses))))
1298 (setq guesses (cdr guesses)))
1302 (defun mime-prompt-for-type ()
1303 "Ask for Content-type."
1305 ;; Repeat until primary content type is specified.
1306 (while (string-equal type "")
1308 (completing-read "What content type: "
1311 'require-match ;Type must be specified.
1314 (if (string-equal type "")
1316 (message "Content type is required.")
1324 (defun mime-prompt-for-subtype (pritype)
1325 "Ask for Content-type subtype of Content-Type PRITYPE."
1326 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1331 "What content subtype: (default " default ") ")
1332 "What content subtype: ")
1333 (cdr (assoc pritype mime-content-types))
1335 'require-match ;Subtype must be specified.
1338 (if (string-equal answer "") default answer)))
1340 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1341 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1342 Optional DELIMITER specifies parameter delimiter (';' by default)."
1343 (let* ((delimiter (or delimiter "; "))
1348 (mime-prompt-for-parameters-1
1350 (cdr (assoc pritype mime-content-types))))))
1353 (if (and (stringp parameters)
1354 (not (string-equal parameters "")))
1355 (concat delimiter parameters)
1356 "" ;"" if no parameters
1359 (defun mime-prompt-for-parameters-1 (optlist)
1360 (apply (function append)
1361 (mapcar (function mime-prompt-for-parameter) optlist)))
1363 (defun mime-prompt-for-parameter (parameter)
1365 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1366 (let* ((prompt (car parameter))
1367 (choices (mapcar (function
1369 (if (consp e) e (list e))))
1371 (default (car (car choices)))
1377 (concat "What " prompt
1379 (if (string-equal default "") "\"\"" default)
1381 choices nil nil ""))
1382 ;; If nothing is selected, use default.
1383 (if (string-equal answer "")
1384 (setq answer default)))
1386 (read-string (concat "What " prompt ": "))))
1387 (cons (if (and answer
1388 (not (string-equal answer "")))
1390 ;; Note: control characters ignored!
1391 (if (string-match mime-tspecials-regexp answer)
1392 (concat "\"" answer "\"") answer)))
1393 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1396 (defun mime-flag-region (from to flag)
1397 "Hides or shows lines from FROM to TO, according to FLAG.
1398 If FLAG is `\\n' (newline character) then text is shown,
1399 while if FLAG is `\\^M' (control-M) the text is hidden."
1400 (let ((buffer-read-only nil) ;Okay even if write protected.
1401 (modp (buffer-modified-p)))
1403 (subst-char-in-region from to
1404 (if (= flag ?\n) ?\^M ?\n)
1406 (set-buffer-modified-p modp))))
1409 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1412 (defvar mime-editor/translate-buffer-hook
1413 '(mime-editor/pgp-enclose-buffer
1414 mime/encode-message-header
1415 mime-editor/translate-body))
1417 (defun mime-editor/translate-buffer ()
1418 "Encode the tagged MIME message in current buffer in MIME compliant message."
1420 (if (catch 'mime-editor/error
1422 (run-hooks 'mime-editor/translate-buffer-hook)
1426 (error "Translation error!")
1429 (defun mime-editor/find-inmost ()
1430 (goto-char (point-min))
1431 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1432 (let ((bb (match-beginning 0))
1434 (type (buffer-substring (match-beginning 1)(match-end 1)))
1436 (setq end-exp (format "^--}-<<%s>>\n" type))
1438 (if (re-search-forward end-exp nil t)
1440 (setq eb (match-beginning 0))
1441 (setq ee (match-end 0))
1443 (setq eb (point-max))
1444 (setq ee (point-max))
1446 (narrow-to-region be eb)
1448 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1450 (narrow-to-region (match-beginning 0)(point-max))
1451 (mime-editor/find-inmost)
1454 ;;(delete-region eb ee)
1455 (list type bb be eb)
1458 (defun mime-editor/process-multipart-1 (boundary)
1459 (let ((ret (mime-editor/find-inmost)))
1461 (let ((type (car ret))
1462 (bb (nth 1 ret))(be (nth 2 ret))
1465 (narrow-to-region bb eb)
1466 (delete-region bb be)
1467 (setq bb (point-min))
1468 (setq eb (point-max))
1471 (if (looking-at mime-editor/multipart-end-regexp)
1472 (let ((beg (match-beginning 0))
1475 (delete-region beg end)
1476 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
1478 (insert (concat (mime-make-text-tag) "\n"))
1480 (cond ((string= type "signed")
1481 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1482 (mime-editor/sign-pgp-elkins bb eb boundary)
1484 ((eq mime-editor/signing-type 'pgp-kazu)
1485 (mime-editor/process-pgp-kazu 'mc-sign
1489 ((string= type "encrypted")
1490 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1491 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1493 ((eq mime-editor/signing-type 'pgp-kazu)
1494 (mime-editor/process-pgp-kazu 'mc-encrypt
1499 (nth 2 (mime-editor/translate-region bb eb
1503 (format "--[[multipart/%s;
1504 boundary=\"%s\"][7bit]]\n"
1509 (defun tm:mc-pgp-generic-parser (result)
1510 (let ((ret (mc-pgp-generic-parser result)))
1512 (vector (car ret)(cdr ret))
1515 (autoload 'mc-pgp-lookup-key "mc-pgp")
1517 (defun tm:mc-process-region
1518 (beg end passwd program args parser &optional buffer boundary)
1519 (let ((obuf (current-buffer))
1520 (process-connection-type nil)
1521 mybuf result rgn proc)
1524 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1528 (buffer-disable-undo mybuf)
1530 (apply 'start-process "*PGP*" mybuf program args))
1533 (process-send-string proc (concat passwd "\n"))
1534 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1535 (process-send-region proc beg end)
1536 (process-send-eof proc)
1537 (while (eq 'run (process-status proc))
1538 (accept-process-output proc 5))
1539 (setq result (process-exit-status proc))
1540 ;; Hack to force a status_notify() in Emacs 19.29
1541 (delete-process proc)
1543 (goto-char (point-max))
1544 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1545 (delete-region (match-beginning 0) (match-end 0)))
1546 (goto-char (point-min))
1548 (while (search-forward "\r\n" nil t)
1549 (replace-match "\n"))
1550 ;; Hurm. FIXME; must get better result codes.
1551 (if (stringp result)
1552 (error "%s exited abnormally: '%s'" program result)
1553 (setq rgn (funcall parser result))
1554 ;; If the parser found something, migrate it
1560 (narrow-to-region beg end)
1562 (insert (format "--%s\n" boundary))
1563 (goto-char (point-max))
1564 (insert (format "\n--%s
1565 Content-Type: application/pgp-signature
1566 Content-Transfer-Encoding: 7bit
1569 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1570 (goto-char (point-max))
1571 (insert (format "\n--%s--\n" boundary))
1573 (delete-region beg end)
1575 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1578 (delete-region (car rgn) (cdr rgn)))))
1579 ;; Return nil on failure and exit code on success
1581 ;; Cleanup even on nonlocal exit
1582 (if (and proc (eq 'run (process-status proc)))
1583 (interrupt-process proc))
1585 (or buffer (null mybuf) (kill-buffer mybuf)))))
1587 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1588 (if (not (boundp 'mc-pgp-user-id))
1591 (let ((process-environment process-environment)
1592 (buffer (get-buffer-create mc-buffer-name))
1594 (parser (function mc-pgp-generic-parser))
1595 (pgp-path mc-pgp-path)
1597 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1601 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1602 (setenv "PGPPASSFD" "0")
1608 (list "+verbose=1" "+language=en"
1609 (format "+clearsig=%s" (if unclear "off" "on"))
1610 "+batchmode" "-u" (cdr key))))
1612 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1614 (message "Signing as %s ..." (car key))
1615 (if (tm:mc-process-region
1616 start end passwd pgp-path args parser buffer boundary)
1620 (goto-char (point-min))
1623 --[[multipart/signed; protocol=\"application/pgp-signature\";
1624 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1626 (message "Signing as %s ... Done." (car key))
1630 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1633 (narrow-to-region beg end)
1635 (mime-editor/translate-region beg end boundary))
1637 (encoding (nth 1 ret))
1639 (pgp-boundary (concat "pgp-sign-" boundary))
1642 (insert (format "Content-Type: %s\n" ctype))
1644 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1647 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1648 nil nil pgp-boundary)
1649 (throw 'mime-editor/error 'pgp-error)
1653 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1655 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1658 (let ((from (rfc822/get-field-body "From"))
1659 (to (rfc822/get-field-body "To"))
1660 (cc (rfc822/get-field-body "cc"))
1662 (narrow-to-region beg end)
1664 (mime-editor/translate-region beg end boundary))
1666 (encoding (nth 1 ret))
1668 (pgp-boundary (concat "pgp-" boundary))
1671 (if (and (stringp from)
1672 (not (string-equal from "")))
1673 (insert (format "From: %s\n" from))
1675 (if (and (stringp to)
1676 (not (string-equal to "")))
1678 (insert (format "To: %s\n" to))
1679 (setq recipients to)
1681 (if (and (stringp cc)
1682 (not (string-equal cc "")))
1684 (insert (format "cc: %s\n" cc))
1686 (setq recipients (concat recipients "," cc))
1687 (setq recipients cc)
1689 (insert (format "Content-Type: %s\n" ctype))
1691 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1695 (let ((mc-pgp-always-sign 'never))
1696 (mc-pgp-encrypt-region
1697 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1698 (point-min) (point-max) from nil)
1700 (throw 'mime-editor/error 'pgp-error)
1703 (insert (format "--[[multipart/encrypted;
1705 protocol=\"application/pgp-encrypted\"][7bit]]
1707 Content-Type: application/pgp-encrypted
1710 Content-Type: application/octet-stream
1711 Content-Transfer-Encoding: 7bit
1713 " pgp-boundary pgp-boundary pgp-boundary))
1714 (goto-char (point-max))
1715 (insert (format "\n--%s--\n" pgp-boundary))
1718 (defun mime-editor/process-pgp-kazu (type beg end boundary)
1721 (narrow-to-region beg end)
1723 (mime-editor/translate-region beg end boundary))
1725 (encoding (nth 1 ret))
1729 (insert (format "Content-Type: %s\n" ctype))
1731 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1739 (let ((mail-header-separator "="))
1740 (call-interactively type)
1743 (and (search-forward "=\n")
1746 (throw 'mime-editor/error 'pgp-error)
1750 "--[[application/pgp; format=mime][7bit]]\n")
1754 (defun mime-editor/translate-body ()
1755 "Encode the tagged MIME body in current buffer in MIME compliant message."
1759 (concat mime-multipart-boundary "_"
1760 (replace-space-with-underline (current-time-string))
1764 (while (mime-editor/process-multipart-1
1765 (format "%s-%d" boundary i))
1769 ;; We are interested in message body.
1772 (goto-char (point-min))
1774 (concat "\n" (regexp-quote mail-header-separator)
1775 (if mime-ignore-preceding-spaces
1776 "[ \t\n]*\n" "\n")) nil 'move)
1780 (goto-char (point-max))
1781 (and mime-ignore-trailing-spaces
1782 (re-search-backward "[^ \t\n]\n" beg t)
1785 (setq ret (mime-editor/translate-region
1787 (format "%s-%d" boundary i)))
1789 (let ((contype (car ret)) ;Content-Type
1790 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1792 ;; Make primary MIME headers.
1793 (or (mail-position-on-field "Mime-Version")
1794 (insert mime-editor/mime-version-value))
1795 ;; Remove old Content-Type and other fields.
1797 (goto-char (point-min))
1798 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1799 (narrow-to-region (point-min) (point))
1800 (goto-char (point-min))
1801 (mime-delete-field "Content-Type")
1802 (mime-delete-field "Content-Transfer-Encoding"))
1803 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1804 (mail-position-on-field "Content-Type")
1808 (mail-position-on-field "Content-Transfer-Encoding")
1812 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1815 (concat mime-multipart-boundary "_"
1816 (replace-space-with-underline (current-time-string))))
1820 (narrow-to-region beg end)
1821 (let ((tag nil) ;MIME tag
1822 (contype nil) ;Content-Type
1823 (encoding nil) ;Content-Transfer-Encoding
1824 (nparts 0)) ;Number of body parts
1825 ;; Normalize the body part by inserting appropriate message
1826 ;; tags for every message contents.
1827 (mime-editor/normalize-body)
1828 ;; Counting the number of Content-Type.
1829 (goto-char (point-min))
1830 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1831 (setq nparts (1+ nparts)))
1832 ;; Begin translation.
1833 (cond ((and (<= nparts 1)(not multipart))
1834 ;; It's a singular message.
1835 (goto-char (point-min))
1836 (while (re-search-forward
1837 mime-editor/single-part-tag-regexp nil t)
1839 (buffer-substring (match-beginning 0) (match-end 0)))
1840 (delete-region (match-beginning 0) (1+ (match-end 0)))
1841 (setq contype (mime-editor/get-contype tag))
1842 (setq encoding (mime-editor/get-encoding tag))
1845 ;; It's a multipart message.
1846 (goto-char (point-min))
1847 (while (re-search-forward
1848 mime-editor/single-part-tag-regexp nil t)
1850 (buffer-substring (match-beginning 0) (match-end 0)))
1851 (delete-region (match-beginning 0) (match-end 0))
1852 (setq contype (mime-editor/get-contype tag))
1853 (setq encoding (mime-editor/get-encoding tag))
1854 (insert "--" boundary "\n")
1855 (insert "Content-Type: " contype "\n")
1857 (insert "Content-Transfer-Encoding: " encoding "\n"))
1859 ;; Define Content-Type as "multipart/mixed".
1861 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1862 ;; Content-Transfer-Encoding must be "7bit".
1863 ;; The following encoding can be `nil', but is
1864 ;; specified as is since there is no way that a user
1866 (setq encoding "7bit")
1867 ;; Insert the trailer.
1868 (goto-char (point-max))
1870 (insert "--" boundary "--\n")
1871 (insert "\n--" boundary "--\n")
1873 (list contype encoding boundary nparts)
1876 (defun mime-editor/normalize-body ()
1877 "Normalize the body part by inserting appropriate message tags."
1878 ;; Insert the first MIME tags if necessary.
1879 (goto-char (point-min))
1880 (if (not (looking-at mime-editor/single-part-tag-regexp))
1881 (insert (mime-make-text-tag) "\n"))
1882 ;; Check each tag, and add new tag or correct it if necessary.
1883 (goto-char (point-min))
1884 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1885 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1886 (contype (mime-editor/get-contype tag))
1887 (charset (mime-get-parameter contype "charset"))
1888 (encoding (mime-editor/get-encoding tag)))
1889 ;; Remove extra whitespaces after the tag.
1890 (if (looking-at "[ \t]+$")
1891 (delete-region (match-beginning 0) (match-end 0)))
1892 (cond ((= (following-char) ?\^M)
1893 ;; It must be image, audio or video.
1895 (end (mime-editor/content-end)))
1896 ;; Insert explicit MIME tags after hidden messages.
1898 (if (and (not (eobp))
1899 (not (looking-at mime-editor/single-part-tag-regexp)))
1901 (insert (mime-make-text-tag) "\n")
1902 (forward-line -1) ;Process it again as text.
1904 ;; Show a hidden message. The point is not altered
1905 ;; after the conversion.
1906 (mime-flag-region beg end ?\n)))
1907 ((mime-test-content-type contype "message")
1908 ;; Content-type "message" should be sent as is.
1910 ((mime-test-content-type contype "text")
1911 ;; Define charset for text if necessary.
1912 (setq charset (or charset (mime-editor/choose-charset)))
1913 (mime-editor/define-charset charset)
1914 (if (string-equal contype "text/x-rot13-47")
1918 (goto-char (mime-editor/content-end))
1921 ;; Point is now on current tag.
1922 ;; Define encoding and encode text if necessary.
1923 (if (null encoding) ;Encoding is not specified.
1927 mime-editor/charset-default-encoding-alist)
1929 (beg (mime-editor/content-beginning))
1931 (mime/code-convert-region-from-emacs
1932 beg (mime-editor/content-end) charset)
1933 (mime-encode-region encoding
1934 beg (mime-editor/content-end))
1935 (mime-editor/define-encoding encoding)))
1937 ((null encoding) ;Encoding is not specified.
1938 ;; Application, image, audio, video, and any other
1939 ;; unknown content-type without encoding should be
1941 (let* ((encoding "base64") ;Encode in BASE64 by default.
1942 (beg (mime-editor/content-beginning))
1943 (end (mime-editor/content-end))
1944 (body (buffer-substring beg end))
1946 (mime-encode-region encoding beg end)
1947 (mime-editor/define-encoding encoding))
1952 (defun mime-delete-field (field)
1953 "Delete header FIELD."
1954 (let ((regexp (format "^%s:[ \t]*" field)))
1955 (goto-char (point-min))
1956 (while (re-search-forward regexp nil t)
1957 (delete-region (match-beginning 0)
1958 (progn (forward-line 1) (point)))
1963 ;;; Platform dependent functions
1966 ;; Sun implementations
1968 (defun mime-voice-recorder-for-sun ()
1969 "Record voice in a buffer using Sun audio device, and return the buffer.
1970 If the environment variable AUDIOHOST is defined, its value is used as
1971 a recording host instead of local host."
1972 (let ((buffer (get-buffer-create " *MIME audio*"))
1973 (host (getenv "AUDIOHOST")))
1974 (message "Start the recording on %s. Type C-g to finish the recording..."
1975 (or host (system-name)))
1979 (condition-case errorcode
1980 (let ((selective-display nil) ;Disable ^M to nl translation.
1982 (kanji-flag nil)) ;NEmacs
1983 ;; If AUDIOHOST is defined, use the value as recording host.
1984 (cond ((not (null host))
1985 ;; Disable automatic conversion of coding system if Mule.
1986 (if (featurep 'mule)
1987 (define-program-coding-system nil "rsh" *noconv*))
1997 ;; Disable automatic conversion of coding system if Mule.
1998 (if (featurep 'mule)
1999 (define-program-coding-system nil "cat" *noconv*))
2005 (quit (message "Type C-g to finish recording... done.")
2006 buffer ;Return the buffer
2010 ;;; @ Other useful commands.
2013 ;; Message forwarding commands as content-type "message/rfc822".
2015 (defun mime-editor/insert-message (&optional message)
2017 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2018 (if (and inserter (fboundp inserter))
2020 (mime-editor/insert-tag "message" "rfc822")
2021 (funcall inserter message)
2023 (message "Sorry, I don't have message inserter for your MUA.")
2026 (defun mime-editor/insert-mail (&optional message)
2028 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2029 (if (and inserter (fboundp inserter))
2031 (mime-editor/insert-tag "message" "rfc822")
2032 (funcall inserter message)
2034 (message "Sorry, I don't have mail inserter for your MUA.")
2037 (defun mime-editor/inserted-message-filter ()
2040 (let ((header-start (point))
2041 (case-fold-search t)
2044 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2045 (if (re-search-forward "^$" (mark t))
2046 (narrow-to-region header-start (match-beginning 0))
2048 (goto-char header-start)
2049 (while (and (re-search-forward
2050 mime-editor/yank-ignored-field-regexp nil t)
2051 (setq beg (match-beginning 0))
2052 (setq end (1+ (rfc822/field-end)))
2054 (delete-region beg end)
2059 ;;; @ multipart enclosure
2062 (defun mime-editor/enclose-region (type beg end)
2065 (let ((current (point))
2068 (if (mime-editor/goto-tag)
2069 (or (eq current (match-beginning 0))
2070 (setq exist-prev-tag t)
2073 (narrow-to-region beg end)
2078 (insert (format "--<<%s>>-{\n" type))
2079 (goto-char (point-max))
2080 (insert (format "\n--}-<<%s>>\n" type))
2081 (goto-char (point-max))
2083 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
2085 (insert (mime-make-text-tag) "\n")
2089 (defun mime-editor/enclose-mixed-region (beg end)
2091 (mime-editor/enclose-region "mixed" beg end)
2094 (defun mime-editor/enclose-parallel-region (beg end)
2096 (mime-editor/enclose-region "parallel" beg end)
2099 (defun mime-editor/enclose-digest-region (beg end)
2101 (mime-editor/enclose-region "digest" beg end)
2104 (defun mime-editor/enclose-alternative-region (beg end)
2106 (mime-editor/enclose-region "alternative" beg end)
2109 (defun mime-editor/enclose-signed-region (beg end)
2111 (if mime-editor/signing-type
2112 (mime-editor/enclose-region "signed" beg end)
2113 (message "Please specify signing type.")
2116 (defun mime-editor/enclose-encrypted-region (beg end)
2118 (if mime-editor/signing-type
2119 (mime-editor/enclose-region "encrypted" beg end)
2120 (message "Please specify encrypting type.")
2123 (defun mime-editor/insert-key (&optional arg)
2124 "Insert a pgp public key."
2126 (mime-editor/insert-tag "application" "pgp-keys")
2127 (mime-editor/define-encoding "7bit")
2128 (mc-insert-public-key)
2135 (defun mime-editor/set-split (arg)
2138 (y-or-n-p "Do you want to enable split?")
2140 (setq mime-editor/split-message arg)
2142 (message "This message is enabled to split.")
2143 (message "This message is not enabled to split.")
2146 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2147 "Toggle transfer-level is 7bit or 8bit through.
2149 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2151 (if (numberp transfer-level)
2152 (setq mime-editor/transfer-level transfer-level)
2153 (if (< mime-editor/transfer-level 8)
2154 (setq mime-editor/transfer-level 8)
2155 (setq mime-editor/transfer-level 7)
2157 (setq mime-editor/charset-default-encoding-alist
2158 (mime/make-charset-default-encoding-alist
2159 mime-editor/transfer-level))
2160 (message (format "Current transfer-level is %d bit"
2161 mime-editor/transfer-level))
2162 (setq mime-editor/transfer-level-string
2163 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2164 (force-mode-line-update)
2171 (defun mime-editor/set-sign (arg)
2174 (y-or-n-p "Do you want to sign?")
2177 (if mime-editor/signing-type
2179 (setq mime-editor/pgp-processing 'sign)
2180 (message "This message will be signed.")
2182 (message "Please specify signing type.")
2184 (if (eq mime-editor/pgp-processing 'sign)
2185 (setq mime-editor/pgp-processing nil)
2187 (message "This message will not be signed.")
2190 (defun mime-editor/set-encrypt (arg)
2193 (y-or-n-p "Do you want to encrypt?")
2196 (if mime-editor/encrypting-type
2198 (setq mime-editor/pgp-processing 'encrypt)
2199 (message "This message will be encrypt.")
2201 (message "Please specify encrypting type.")
2203 (if (eq mime-editor/pgp-processing 'encrypt)
2204 (setq mime-editor/pgp-processing nil)
2206 (message "This message will not be encrypt.")
2209 (defvar mime-editor/pgp-processing nil)
2210 (make-variable-buffer-local 'mime-editor/pgp-processing)
2212 (defun mime-editor/pgp-enclose-buffer ()
2213 (let ((beg (save-excursion
2214 (goto-char (point-min))
2215 (if (search-forward (concat "\n" mail-header-separator "\n"))
2221 (cond ((eq mime-editor/pgp-processing 'sign)
2222 (mime-editor/enclose-signed-region beg end)
2224 ((eq mime-editor/pgp-processing 'encrypt)
2225 (mime-editor/enclose-encrypted-region beg end)
2233 (defun mime-editor/insert-partial-header
2234 (fields subject id number total separator)
2236 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2237 (insert (format "Mime-Version: 1.0 (split by tm-edit %s)\n"
2238 mime-editor/version))
2240 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2241 id number total separator))
2244 (defun mime-editor/split-and-send
2245 (&optional cmd lines mime-editor/message-max-length)
2249 (count-lines (point-min) (point-max)))
2251 (or mime-editor/message-max-length
2252 (setq mime-editor/message-max-length
2253 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2254 mime-editor/message-default-max-length))
2256 (let* ((mime-editor/draft-file-name
2257 (or (buffer-file-name)
2259 (expand-file-name "tm-draft" mime/tmp-dir))))
2260 (separator mail-header-separator)
2262 (eval (cdr (assq major-mode mime-editor/window-config-alist))))
2264 (replace-space-with-underline (current-time-string))
2265 "@" (system-name) "\"")))
2266 (run-hooks 'mime-editor/before-split-hook)
2267 (let* ((header (rfc822/get-header-string-except
2268 mime-editor/split-ignored-field-regexp separator))
2269 (subject (mail-fetch-field "subject"))
2270 (total (+ (/ lines mime-editor/message-max-length)
2271 (if (> (mod lines mime-editor/message-max-length) 0)
2273 (the-buf (current-buffer))
2274 (buf (get-buffer "*tmp-send*"))
2279 mime-editor/split-message-sender-alist))
2282 mime-editor/message-default-sender-alist))
2285 (goto-char (point-min))
2286 (if (re-search-forward (concat "^" (regexp-quote separator) "$")
2292 (switch-to-buffer buf)
2294 (switch-to-buffer the-buf)
2296 (setq buf (get-buffer-create "*tmp-send*"))
2298 (switch-to-buffer buf)
2299 (make-local-variable 'mail-header-separator)
2300 (setq mail-header-separator separator)
2301 (switch-to-buffer the-buf)
2302 (goto-char (point-min))
2303 (re-search-forward "^$" nil t)
2304 (let ((mime-editor/partial-number 1))
2305 (setq data (buffer-substring
2308 (goto-line mime-editor/message-max-length)
2311 (delete-region (point-min)(point))
2312 (switch-to-buffer buf)
2313 (mime-editor/insert-partial-header
2314 header subject id mime-editor/partial-number total separator)
2318 (goto-char (point-min))
2319 (search-forward (concat "\n" mail-header-separator "\n"))
2322 (if (re-search-forward "^$" nil t)
2326 (goto-char (point-min))
2327 (while (re-search-forward
2328 mime-editor/split-blind-field-regexp nil t)
2329 (delete-region (match-beginning 0)
2330 (let ((e (rfc822/field-end)))
2331 (if (< e (point-max))
2337 (message (format "Sending %d/%d..."
2338 mime-editor/partial-number total))
2339 (call-interactively command)
2340 (message (format "Sending %d/%d... done"
2341 mime-editor/partial-number total))
2344 (switch-to-buffer the-buf)
2345 (setq mime-editor/partial-number 2)
2346 (while (< mime-editor/partial-number total)
2347 (setq data (buffer-substring
2350 (goto-line mime-editor/message-max-length)
2353 (delete-region (point-min)(point))
2354 (switch-to-buffer buf)
2355 (mime-editor/insert-partial-header
2356 header subject id mime-editor/partial-number total separator)
2359 (message (format "Sending %d/%d..."
2360 mime-editor/partial-number total))
2361 (call-interactively command)
2362 (message (format "Sending %d/%d... done"
2363 mime-editor/partial-number total))
2366 (switch-to-buffer the-buf)
2367 (setq mime-editor/partial-number
2368 (1+ mime-editor/partial-number))
2370 (goto-char (point-min))
2371 (mime-editor/insert-partial-header
2372 header subject id mime-editor/partial-number total separator)
2373 (message (format "Sending %d/%d..."
2374 mime-editor/partial-number total))
2377 (defun mime-editor/maybe-split-and-send (&optional cmd)
2379 (run-hooks 'mime-editor/before-send-hook)
2380 (let ((mime-editor/message-max-length
2381 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2382 mime-editor/message-default-max-length))
2383 (lines (count-lines (point-min) (point-max)))
2385 (if (and (> lines mime-editor/message-max-length)
2386 mime-editor/split-message)
2387 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2391 ;;; @ preview message
2394 (defun mime-editor/preview-message ()
2395 "preview editing MIME message. [tm-edit.el]"
2397 (let* ((str (buffer-string))
2398 (separator mail-header-separator)
2399 (the-buf (current-buffer))
2400 (buf-name (buffer-name))
2401 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2402 (buf (get-buffer temp-buf-name))
2406 (switch-to-buffer buf)
2409 (setq buf (get-buffer-create temp-buf-name))
2410 (switch-to-buffer buf)
2413 (setq major-mode 'mime/temporary-message-mode)
2414 (make-local-variable 'mail-header-separator)
2415 (setq mail-header-separator separator)
2416 (make-local-variable 'mime/editing-buffer)
2417 (setq mime/editing-buffer the-buf)
2419 (run-hooks 'mime-editor/translate-hook)
2420 (mime-editor/translate-buffer)
2421 (goto-char (point-min))
2422 (if (re-search-forward
2423 (concat "^" (regexp-quote separator) "$"))
2429 (defun mime-editor/quitting-method ()
2430 (let ((temp mime::preview/article-buffer)
2432 (mime-viewer/kill-buffer)
2434 (setq buf mime/editing-buffer)
2436 (switch-to-buffer buf)
2439 (set-alist 'mime-viewer/quitting-method-alist
2440 'mime/temporary-message-mode
2441 (function mime-editor/quitting-method)
2447 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2448 ;; Mon, 10 Apr 1995 20:03:07 +0900
2450 (defvar mime-editor/draft-header-separator-alist
2451 '((news-reply-mode . mail-header-separator)
2452 (mh-letter-mode . mail-header-separator)
2455 (defvar mime::article/draft-header-separator nil)
2457 (defun mime-editor/draft-preview ()
2459 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2460 (or (stringp sep) (setq sep (eval sep)))
2461 (make-variable-buffer-local 'mime::article/draft-header-separator)
2462 (goto-char (point-min))
2464 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2465 (setq mime::article/draft-header-separator
2466 (buffer-substring (match-beginning 0) (match-end 0)))
2468 (mime/viewer-mode (current-buffer))
2469 (pop-to-buffer (current-buffer))
2472 (defun mime-viewer::quitting-method/draft-preview ()
2473 (let ((mother mime::preview/mother-buffer))
2475 (switch-to-buffer mother)
2476 (goto-char (point-min))
2480 (regexp-quote mime::article/draft-header-separator)
2484 (insert mime::article/draft-header-separator)
2485 (set-buffer-modified-p (buffer-modified-p))
2487 (mime-viewer/kill-buffer)
2488 (pop-to-buffer mother)
2491 (set-alist 'mime-viewer/quitting-method-alist
2493 (function mime-viewer::quitting-method/draft-preview)
2496 (set-alist 'mime-viewer/quitting-method-alist
2498 (function mime-viewer::quitting-method/draft-preview)
2505 (defun mime-editor::edit-again (code-conversion)
2507 (goto-char (point-min))
2508 (let ((ctl (mime/Content-Type)))
2510 (let ((ctype (car ctl))
2513 (if (string-match "/" ctype)
2515 (setq type (substring ctype 0 (match-beginning 0)))
2516 (setq stype (substring ctype (match-end 0)))
2520 (cond ((string-equal type "multipart")
2521 (let ((boundary (assoc-value "boundary" params)))
2522 (re-search-forward (concat "\n--" boundary) nil t)
2523 (let ((bb (match-beginning 0)) eb tag)
2524 (setq tag (format "\n--<<%s>>-{" stype))
2527 (setq bb (+ bb (length tag)))
2528 (re-search-forward (concat "\n--" boundary "--") nil t)
2529 (setq eb (match-beginning 0))
2530 (replace-match (format "\n--}-<<%s>>" stype))
2532 (narrow-to-region bb eb)
2533 (goto-char (point-min))
2534 (while (re-search-forward
2535 (concat "\n--" boundary "\n") nil t)
2536 (let ((beg (match-beginning 0))
2538 (delete-region beg (match-end 0))
2540 (if (re-search-forward
2541 (concat "\n--" boundary) nil t)
2542 (setq end (match-beginning 0))
2543 (setq end (point-max))
2546 (narrow-to-region beg end)
2547 (mime-editor::edit-again code-conversion)
2548 (goto-char (point-max))
2551 (goto-char (point-min))
2552 (or (= (point-min) 1)
2553 (delete-region (point-min)
2554 (if (re-search-forward "^$" nil t)
2560 (let* ((str (rfc822/get-header-string-except
2561 "^Content-Type" ""))
2564 (mapconcat (function
2566 (if (string-equal (car attr)
2569 (setq charset (cdr attr))
2571 (concat ";" (car attr)
2579 (mime/code-convert-region-to-emacs
2580 (point-min) (point-max) charset)
2581 (decode-coding-region
2582 (point-min) (point-max)
2583 mime/default-coding-system)
2586 (setq pstr (concat pstr "\n" str))
2589 (if (re-search-forward "^$" nil t)
2593 (if (= (point-min) 1)
2599 (mime-create-tag (concat type "/" stype))
2602 (delete-region (point-min) he)
2604 (concat "\n" (mime-create-tag
2605 (concat type "/" stype pstr))))
2609 (decode-coding-region (point-min) (point-max)
2610 mime/default-coding-system)
2614 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2616 (mime-editor::edit-again code-conversion)
2617 (goto-char (point-min))
2619 (narrow-to-region (point-min)
2620 (if (re-search-forward "^$" nil t)
2624 (goto-char (point-min))
2625 (while (re-search-forward
2626 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2627 (delete-region (match-beginning 0) (1+ (rfc822/field-end)))
2630 (and (re-search-forward "^$")
2631 (replace-match mail-header-separator)
2643 (run-hooks 'tm-edit-load-hook)
2645 ;;; tm-edit.el ends here