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.69 $
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.69 1996/06/27 14:22:59 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-ignore-preceding-spaces nil
137 "*Ignore preceding white spaces if non-nil.")
139 (defvar mime-ignore-trailing-spaces nil
140 "*Ignore trailing white spaces if non-nil.")
142 (defvar mime-ignore-same-text-tag t
143 "*Ignore preceding text content-type tag that is same with new one.
144 If non-nil, the text tag is not inserted unless something different.")
146 (defvar mime-auto-hide-body t
147 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
149 (defvar mime-voice-recorder
150 (function mime-voice-recorder-for-sun)
151 "*Function to record a voice message and return a buffer that contains it.")
153 (defvar mime/editor-mode-hook nil
154 "*Hook called when enter MIME mode.")
156 (defvar mime-editor/translate-hook nil
157 "*Hook called before translating into a MIME compliant message.
158 To insert a signature file automatically, call the function
159 `mime-editor/insert-signature' from this hook.")
161 (defvar mime-editor/exit-hook nil
162 "*Hook called when exit MIME mode.")
164 (defvar mime-content-types
166 ;; Charset parameter need not to be specified, since it is
167 ;; defined automatically while translation.
169 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
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")
189 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
190 ("directory" "/pub/GNU/elisp/mime")
192 ("mode" "image" "ascii" "local8"))
197 ("mode" "image" "ascii" "local8"))
198 ("tftp" ("site") ("name"))
199 ("afs" ("site") ("name"))
200 ("local-file" ("site") ("name"))
201 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
206 ("octet-stream" ("type" "" "tar" "shar"))
208 ("x-kiss" ("x-cnf")))
221 "*Alist of content-type, subtype, parameters and its values.")
223 (defvar mime-file-types
225 "text" "richtext" nil
233 "application" "postscript" nil
235 "attachment" (("filename" . file))
240 "inline" (("filename" . file))
245 "inline" (("filename" . file))
250 "inline" (("filename" . file))
255 "inline" (("filename" . file))
260 "inline" (("filename" . file))
265 "inline" (("filename" . file))
270 "inline" (("filename" . file))
275 "attachment" (("filename" . file))
280 "attachment" (("filename" . file))
283 "application" "octet-stream" (("type" . "emacs-lisp"))
285 "attachment" (("filename" . file))
288 "application" "octet-stream" (("type" . "common-lisp"))
290 "attachment" (("filename" . file))
293 "application" "octet-stream" (("type" . "tar+gzip"))
295 "attachment" (("filename" . file))
298 "application" "octet-stream" (("type" . "tar+gzip"))
300 "attachment" (("filename" . file))
303 "application" "octet-stream" (("type" . "tar+compress"))
305 "attachment" (("filename" . file))
308 "application" "octet-stream" (("type" . "tar+compress"))
310 "attachment" (("filename" . file))
313 "application" "octet-stream" (("type" . "gzip"))
315 "attachment" (("filename" . file))
318 "application" "octet-stream" (("type" . "compress"))
320 "attachment" (("filename" . file))
323 "application" "octet-stream" (("type" . "lha"))
325 "attachment" (("filename" . file))
328 "application" "zip" nil
330 "attachment" (("filename" . file))
333 "application" "octet-stream" (("type" . "patch"))
335 "attachment" (("filename" . file))
338 "application" "octet-stream" (("type" . "patch"))
340 "attachment" (("filename" . file))
343 "text" "plain" nil nil)
345 "application" "octet-stream" nil
347 "attachment" (("filename" . file))
350 "*Alist of file name, types, parameters, and default encoding.
351 If encoding is nil, it is determined from its contents.")
353 ;;; @@ about charset, encoding and transfer-level
356 (defvar mime-editor/transfer-level 7
357 "*A number of network transfer level. It should be bigger than 7.")
358 (make-variable-buffer-local 'mime-editor/transfer-level)
360 (defvar mime-editor/transfer-level-string
361 (mime/encoding-name mime-editor/transfer-level 'not-omit)
362 "*A string formatted version of mime/defaul-transfer-level")
363 (make-variable-buffer-local 'mime-editor/transfer-level-string)
365 (defvar mime-editor/charset-default-encoding-alist
366 (mime/make-charset-default-encoding-alist mime-editor/transfer-level))
367 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
369 ;;; @@ about message inserting
372 (defvar mime-editor/yank-ignored-field-list
373 '("Received" "Approved" "Path" "Replied" "Status" "X-VM-.*" "X-UIDL")
374 "Delete these fields from original message when it is inserted
375 as message/rfc822 part.
376 Each elements are regexp of field-name. [tm-edit.el]")
378 (defvar mime-editor/yank-ignored-field-regexp
380 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
383 (defvar mime-editor/message-inserter-alist nil)
384 (defvar mime-editor/mail-inserter-alist nil)
386 ;;; @@ about message splitting
389 (defvar mime-editor/split-message t
390 "*Split large message if it is non-nil. [tm-edit.el]")
392 (defvar mime-editor/message-default-max-length 1000
393 "*Default maximum size of a message. [tm-edit.el]")
395 (defvar mime-editor/message-max-length-alist
396 '((news-reply-mode . 500)))
398 (defconst mime-editor/split-ignored-field-regexp
399 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
401 (defvar mime-editor/split-blind-field-regexp
402 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
404 (defvar mime-editor/split-message-sender-alist
406 . (lambda (&optional arg)
408 (write-region (point-min) (point-max)
409 mime-editor/draft-file-name nil 'no-message)
411 (pop-to-buffer "MH mail delivery")
413 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
415 mh-send-args mime-editor/draft-file-name)
416 (goto-char (point-max)) ; show the interesting part
420 (apply 'mh-exec-cmd-quiet t mh-send-prog
422 (list "-nopush" "-nodraftfolder"
423 "-noverbose" "-nowatch"
424 mh-send-args mime-editor/draft-file-name)))))
428 (defvar mime-editor/news-reply-mode-server-running nil)
434 (defvar mime-editor/signing-type nil
435 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
437 (defvar mime-editor/encrypting-type nil
438 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
440 (if (or mime-editor/signing-type mime-editor/encrypting-type)
448 (defconst mime-editor/single-part-tag-regexp
449 "^--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
450 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
452 (defconst mime-editor/multipart-beginning-regexp "^--<<\\([^<>]+\\)>>-{\n")
454 (defconst mime-editor/multipart-end-regexp "^--}-<<\\([^<>]+\\)>>\n")
456 (defconst mime-editor/beginning-tag-regexp
457 (regexp-or mime-editor/single-part-tag-regexp
458 mime-editor/multipart-beginning-regexp))
460 (defconst mime-editor/end-tag-regexp
461 (regexp-or mime-editor/single-part-tag-regexp
462 mime-editor/multipart-end-regexp))
464 (defconst mime-editor/tag-regexp
465 (regexp-or mime-editor/single-part-tag-regexp
466 mime-editor/multipart-beginning-regexp
467 mime-editor/multipart-end-regexp))
469 (defvar mime-tag-format "--[[%s]]"
470 "*Control-string making a MIME tag.")
472 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
473 "*Control-string making a MIME tag with encoding.")
475 ;;; @@ multipart boundary
478 (defvar mime-multipart-boundary "Multipart"
479 "*Boundary of a multipart message.")
482 ;;; @@ buffer local variables
485 (defvar mime/editor-mode-old-local-map nil)
486 (defvar mime/editor-mode-old-selective-display nil)
487 (defvar mime/editing-buffer nil)
493 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
494 "*Specify MIME tspecials.
495 Tspecials means any character that matches with it in header must be quoted.")
497 (defconst mime-editor/mime-version-value
498 (format "1.0 (generated by tm-edit %s)" mime-editor/version)
499 "MIME version number.")
501 (defconst mime-editor/mime-map (make-sparse-keymap)
502 "Keymap for MIME commands.")
505 ;;; @ keymap and menu
508 (defvar mime/editor-mode-flag nil)
509 (make-variable-buffer-local 'mime/editor-mode-flag)
511 (set-alist 'minor-mode-alist
512 'mime/editor-mode-flag
513 '((" MIME-Edit " mime-editor/transfer-level-string)))
515 (defun mime-editor/define-keymap (keymap)
516 "Add mime-editor commands to KEYMAP."
517 (if (not (keymapp keymap))
519 (define-key keymap "\C-t" 'mime-editor/insert-text)
520 (define-key keymap "\C-i" 'mime-editor/insert-file)
521 (define-key keymap "\C-e" 'mime-editor/insert-external)
522 (define-key keymap "\C-v" 'mime-editor/insert-voice)
523 (define-key keymap "\C-y" 'mime-editor/insert-message)
524 (define-key keymap "\C-m" 'mime-editor/insert-mail)
525 (define-key keymap "\C-w" 'mime-editor/insert-signature)
526 (define-key keymap "\C-s" 'mime-editor/insert-signature)
527 (define-key keymap "\C-k" 'mime-editor/insert-key)
528 (define-key keymap "t" 'mime-editor/insert-tag)
529 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
530 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
531 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
532 (define-key keymap "d" 'mime-editor/enclose-digest-region)
533 (define-key keymap "s" 'mime-editor/enclose-signed-region)
534 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
535 (define-key keymap "\C-p" 'mime-editor/preview-message)
536 (define-key keymap "\C-z" 'mime-editor/exit)
537 (define-key keymap "?" 'mime-editor/help)
540 (mime-editor/define-keymap mime-editor/mime-map)
542 (defconst mime-editor/menu-title "MIME-Edit")
544 (defconst mime-editor/menu-list
545 '((mime-help "Describe MIME editor mode" mime-editor/help)
546 (file "Insert File" mime-editor/insert-file)
547 (external "Insert External" mime-editor/insert-external)
548 (voice "Insert Voice" mime-editor/insert-voice)
549 (message "Insert Message" mime-editor/insert-message)
550 (mail "Insert Mail" mime-editor/insert-mail)
551 (signature "Insert Signature" mime-editor/insert-signature)
552 (text "Insert Text" mime-editor/insert-text)
553 (tag "Insert Tag" mime-editor/insert-tag)
554 (alternative "Enclose as alternative"
555 mime-editor/enclose-alternative-region)
556 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
557 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
558 (digest "Enclose as digest" mime-editor/enclose-digest-region)
559 (signed "Enclose as signed" mime-editor/enclose-signed-region)
560 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
561 (key "Insert Public Key" mime-editor/insert-key)
562 (split "About split" mime-editor/set-split)
563 (sign "About sign" mime-editor/set-sign)
564 (encrypt "About encryption" mime-editor/set-encrypt)
565 (preview "Preview Message" mime-editor/preview-message)
566 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
568 "MIME-edit menubar entry.")
570 (defun mime-editor/define-menu-for-emacs19 ()
571 "Define menu for Emacs 19."
572 (define-key (current-local-map) [menu-bar mime-edit]
573 (cons mime-editor/menu-title
574 (make-sparse-keymap mime-editor/menu-title)))
577 (define-key (current-local-map)
578 (vector 'menu-bar 'mime-edit (car item))
579 (cons (nth 1 item)(nth 2 item))
582 (reverse mime-editor/menu-list)
585 ;;; modified by Pekka Marjola <pema@iki.fi>
586 ;;; 1995/9/5 (c.f. [tm-en:69])
587 (defun mime-editor/define-menu-for-xemacs ()
588 "Define menu for Emacs 19."
589 (cond ((featurep 'menubar)
590 (make-local-variable 'current-menubar)
591 (set-buffer-menubar current-menubar)
593 (cons mime-editor/menu-title
596 (vector (nth 1 item)(nth 2 item)
597 mime/editor-mode-flag)
599 mime-editor/menu-list)))
602 ;;; modified by Steven L. Baur <steve@miranova.com>
603 ;;; 1995/12/6 (c.f. [tm-en:209])
604 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
605 (setq mime-editor/popup-menu-for-xemacs
606 (append '("MIME Commands" "---")
607 (mapcar (function (lambda (item)
611 mime-editor/menu-list)))
620 (defun mime/editor-mode ()
621 "MIME minor mode for editing the tagged MIME message.
623 In this mode, basically, the message is composed in the tagged MIME
624 format. The message tag looks like:
626 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
628 The tag specifies the MIME content type, subtype, optional parameters
629 and transfer encoding of the message following the tag. Messages
630 without any tag are treated as `text/plain' by default. Charset and
631 transfer encoding are automatically defined unless explicitly
632 specified. Binary messages such as audio and image are usually hidden
633 using selective-display facility. The messages in the tagged MIME
634 format are automatically translated into a MIME compliant message when
637 Available charsets depend on Emacs version being used. The following
638 lists the available charsets of each emacs.
640 Emacs18: US-ASCII is only available.
641 NEmacs: US-ASCII and ISO-2022-JP are available.
642 Emacs19: US-ASCII and ISO-8859-1 are available.
643 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-6),
644 ISO-2022-JP, ISO-2022-JP-2 and ISO-2022-INT-1 are available.
646 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in Mule is expected to
647 be used to represent multilingual text in intermixed manner. Any
648 languages that has no registered charset are represented as either
649 ISO-2022-JP-2 or ISO-2022-INT-1 in Mule.
651 Following commands are available in addition to major mode commands:
652 \\[mime-editor/insert-text] insert a text message.
653 \\[mime-editor/insert-file] insert a (binary) file.
654 \\[mime-editor/insert-external] insert a reference to external body.
655 \\[mime-editor/insert-voice] insert a voice message.
656 \\[mime-editor/insert-message] insert a mail or news message.
657 \\[mime-editor/insert-mail] insert a mail message.
658 \\[mime-editor/insert-signature] insert a signature file at end.
659 \\[mime-editor/insert-tag] insert a new MIME tag.
660 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
661 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
662 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
663 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
664 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
665 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
666 \\[mime-editor/insert-key] insert PGP public key.
667 \\[mime-editor/preview-message] preview editing MIME message.
668 \\[mime-editor/exit] exit and translate into a MIME compliant message.
669 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
670 \\[mime-editor/help] show this help.
672 Additional commands are available in some major modes:
673 C-c C-c exit, translate and run the original command.
674 C-c C-s exit, translate and run the original command.
676 The following is a message example written in the tagged MIME format.
677 TABs at the beginning of the line are not a part of the message:
679 This is a conventional plain text. It should be translated
682 This is also a plain text. But, it is explicitly specified as
684 --[[text/plain; charset=ISO-2022-JP]]
685 \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
688 <center>This is a richtext.</center>
689 --[[image/gif][base64]]^M...image encoded in base64 here...
690 --[[audio/basic][base64]]^M...audio encoded in base64 here...
692 User customizable variables (not documented all of them):
694 Specifies a key prefix for MIME minor mode commands.
696 mime-ignore-preceding-spaces
697 Preceding white spaces in a message body are ignored if non-nil.
699 mime-ignore-trailing-spaces
700 Trailing white spaces in a message body are ignored if non-nil.
702 mime-auto-fill-header
703 Fill header fields that contain encoded-words if non-nil.
706 Hide a non-textual body message encoded in base64 after insertion
710 Specifies a function to record a voice message and return a buffer
711 that contains it. The function mime-voice-recorder-for-sun is for
714 mime/editor-mode-hook
715 Turning on MIME mode calls the value of mime/editor-mode-hook, if
718 mime-editor/translate-hook
719 The value of mime-editor/translate-hook is called just before translating
720 the tagged MIME format into a MIME compliant message if it is
721 non-nil. If the hook call the function mime-editor/insert-signature,
722 the signature file will be inserted automatically.
724 mime-editor/exit-hook
725 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
728 (if mime/editor-mode-flag
729 (error "You are already editing a MIME message.")
730 (setq mime/editor-mode-flag t)
731 ;; Remember old key bindings.
734 (make-local-variable 'mime/editor-mode-old-local-map)
735 (setq mime/editor-mode-old-local-map (current-local-map))
736 ;; Add MIME commands to current local map.
737 (use-local-map (copy-keymap (current-local-map)))
739 (if (not (lookup-key (current-local-map) mime-prefix))
740 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
742 ;; Set transfer level into mode line
744 (setq mime-editor/transfer-level-string
745 (mime/encoding-name mime-editor/transfer-level 'not-omit))
746 (force-mode-line-update)
748 ;; Define menu. Menus for other emacs implementations are
750 (cond (running-xemacs
751 (mime-editor/define-menu-for-xemacs))
752 ((>= emacs-major-version 19)
753 (mime-editor/define-menu-for-emacs19)
757 ;; Remember old selective-display.
758 (make-local-variable 'mime/editor-mode-old-selective-display)
759 (setq mime/editor-mode-old-selective-display selective-display)
760 (setq selective-display t)
761 ;; I don't care about saving these.
762 (setq paragraph-start
763 (regexp-or mime-editor/single-part-tag-regexp
765 (setq paragraph-separate
766 (regexp-or mime-editor/single-part-tag-regexp
768 (run-hooks 'mime/editor-mode-hook)
770 (substitute-command-keys
771 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
775 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
776 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
778 (defun mime-editor/exit (&optional nomime no-error)
779 "Translate the tagged MIME message into a MIME compliant message.
780 With no argument encode a message in the buffer into MIME, otherwise
781 just return to previous mode."
783 (if (not mime/editor-mode-flag)
785 (error "You aren't editing a MIME message.")
789 (run-hooks 'mime-editor/translate-hook)
790 (mime-editor/translate-buffer)))
791 ;; Restore previous state.
792 (setq mime/editor-mode-flag nil)
793 (cond (running-xemacs
794 ;; mime-prefix only defined if binding was nil
795 (if (eq (lookup-key (current-local-map) mime-prefix)
796 mime-editor/mime-map)
797 (define-key (current-local-map) mime-prefix nil))
798 (delete-menu-item (list mime-editor/menu-title)))
800 (use-local-map mime/editor-mode-old-local-map)))
802 (setq selective-display mime/editor-mode-old-selective-display)
803 (set-buffer-modified-p (buffer-modified-p))
804 (run-hooks 'mime-editor/exit-hook)
805 (message "Exit MIME editor mode.")
808 (defun mime-editor/maybe-translate ()
810 (mime-editor/exit nil t)
811 (call-interactively 'mime-editor/maybe-split-and-send)
814 (defun mime-editor/help ()
815 "Show help message about MIME mode."
817 (with-output-to-temp-buffer "*Help*"
818 (princ "MIME editor mode:\n")
819 (princ (documentation 'mime/editor-mode))
820 (print-help-return-message)))
822 (defun mime-editor/insert-text ()
823 "Insert a text message.
824 Charset is automatically obtained from the `mime/lc-charset-alist'."
826 (if (and (mime-editor/insert-tag "text" nil nil)
827 (looking-at mime-editor/single-part-tag-regexp))
829 ;; Make a space between the following message.
834 (defun mime-editor/insert-file (file)
835 "Insert a message from a file."
836 (interactive "fInsert file as MIME message: ")
837 (let* ((guess (mime-find-file-type file))
838 (pritype (nth 0 guess))
839 (subtype (nth 1 guess))
840 (parameters (nth 2 guess))
841 (default (nth 3 guess)) ;Guess encoding from its file name.
842 (disposition-type (nth 4 guess))
843 (disposition-params (nth 5 guess))
845 (if (not (interactive-p))
848 (concat "What transfer encoding"
851 (if (string-equal default "")
857 mime-encoding-method-alist nil t nil))))
858 (if (string-equal encoding "")
859 (setq encoding default))
860 (if (or (consp parameters) (stringp disposition-type))
861 (let ((rest parameters) cell attribute value)
864 (setq cell (car rest))
865 (setq attribute (car cell))
866 (setq value (cdr cell))
868 (setq value (rfc822/wrap-as-quoted-string
869 (file-name-nondirectory file)))
871 (setq parameters (concat parameters "; " attribute "=" value))
872 (setq rest (cdr rest))
877 (concat parameters "\n"
878 "Content-Disposition: " disposition-type))
879 (setq rest disposition-params)
881 (setq cell (car rest))
882 (setq attribute (car cell))
883 (setq value (cdr cell))
885 (setq value (rfc822/wrap-as-quoted-string
886 (file-name-nondirectory file)))
889 (concat parameters "; " attribute "=" value))
890 (setq rest (cdr rest))
894 (mime-editor/insert-tag pritype subtype parameters)
895 (mime-editor/insert-binary-file file encoding)
898 (defun mime-editor/insert-external ()
899 "Insert a reference to external body."
901 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
903 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
905 (let* ((pritype (mime-prompt-for-type))
906 (subtype (mime-prompt-for-subtype pritype))
907 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
910 (insert "Content-Type: "
911 pritype "/" subtype (or parameters "") "\n")))
912 (if (and (not (eobp))
913 (not (looking-at mime-editor/single-part-tag-regexp)))
914 (insert (mime-make-text-tag) "\n")))
916 (defun mime-editor/insert-voice ()
917 "Insert a voice message."
919 (mime-editor/insert-tag "audio" "basic" nil)
920 (let ((buffer (funcall mime-voice-recorder)))
922 (mime-editor/insert-binary-buffer buffer "base64")
926 (defun mime-editor/insert-signature (&optional arg)
927 "Insert a signature file."
929 (let ((signature-insert-hook
932 (apply (function mime-editor/insert-tag)
933 (mime-find-file-type signature-file-name))
936 (insert-signature arg)
940 ;; Insert a new tag around a point.
942 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
943 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
944 If nothing is inserted, return nil."
949 exist-prev-tag exist-next-tag)
952 (mime-prompt-for-type)))
955 (mime-prompt-for-subtype pritype)))
958 (mime-prompt-for-parameters pritype subtype delimiter)))
959 ;; Make a new MIME tag.
960 (setq newtag (mime-make-tag pritype subtype parameters))
961 ;; Find an current MIME tag.
964 (if (mime-editor/goto-tag)
966 (if (eq current (match-beginning 0))
967 (setq exist-next-tag t)
968 (setq exist-prev-tag t)
970 (buffer-substring (match-beginning 0) (match-end 0))
972 ;; Assume content type is 'text/plan'.
973 (mime-make-tag "text" "plain")
975 ;; We are only interested in TEXT.
977 (not (mime-test-content-type
978 (mime-editor/get-contype oldtag) "text")))
980 (cond (exist-prev-tag (insert "\n"))
981 (exist-next-tag (save-excursion
990 (if (or (not oldtag) ;Not text
991 (or mime-ignore-same-text-tag
992 (not (string-equal oldtag newtag))))
994 ;; Mark the beginning of the tag for convenience.
995 (push-mark (point) 'nomsg)
997 (list pritype subtype parameters) ;New tag is created.
999 ;; Restore previous point.
1001 nil ;Nothing is created.
1005 ;; Insert the binary content after MIME tag.
1006 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1008 (defun mime-editor/insert-binary-file (file &optional encoding)
1009 "Insert binary FILE at point.
1010 Optional argument ENCODING specifies an encoding method such as base64."
1011 (let ((tmpbuf (get-buffer-create " *MIME insert*")))
1015 (let ((mc-flag nil) ;Mule
1016 (file-coding-system-for-read
1017 (if (featurep 'mule) *noconv*))
1018 (kanji-flag nil) ;NEmacs
1019 (emx-binary-mode t) ;Stop CRLF to LF conversion in OS/2
1021 (let (jka-compr-compression-info-list
1022 jam-zcat-filename-list)
1023 (insert-file-contents file))))
1025 (if (and (stringp encoding)
1026 (string-equal (downcase encoding) "x-uue"))
1029 (let ((uuencode-external-encoder
1030 (cons (car uuencode-external-encoder)
1031 (list (file-name-nondirectory file))
1033 (mime-editor/insert-binary-buffer tmpbuf encoding)
1035 (mime-editor/insert-binary-buffer tmpbuf encoding))
1036 (kill-buffer tmpbuf))))
1038 ;; Insert the binary content after MIME tag.
1039 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1041 (defun mime-editor/insert-binary-buffer (buffer &optional encoding)
1042 "Insert binary BUFFER at point.
1043 Optional argument ENCODING specifies an encoding method such as base64."
1044 (let* ((tagend (1- (point))) ;End of the tag
1045 (hide-p (and mime-auto-hide-body
1047 (let ((en (downcase encoding)))
1048 (or (string-equal en "base64")
1049 (string-equal en "x-uue")
1053 (narrow-to-region (1- (point)) (point))
1054 (let ((start (point))
1055 (emx-binary-mode t)) ;Stop LF to CRLF conversion in OS/2
1056 (insert-buffer-substring buffer)
1057 ;; Encode binary message if necessary.
1059 (mime-encode-region start (point-max) encoding)
1063 (mime-flag-region (point-min) (1- (point-max)) ?\^M)
1064 (goto-char (point-max)))
1066 ;; Define encoding even if it is 7bit.
1067 (if (stringp encoding)
1069 (goto-char tagend) ;Make sure which line the tag is on.
1070 (mime-editor/define-encoding encoding)))
1074 ;; Commands work on a current message flagment.
1076 (defun mime-editor/goto-tag ()
1077 "Search for the beginning of the tagged MIME message."
1078 (let ((current (point)) multipart)
1079 (if (looking-at mime-editor/tag-regexp)
1081 ;; At first, go to the end.
1082 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1083 (goto-char (match-beginning 0)) ;For multiline tag
1088 (goto-char (point-max))
1090 ;; Then search for the beginning.
1091 (re-search-backward mime-editor/end-tag-regexp nil t)
1093 (or (looking-at mime-editor/beginning-tag-regexp)
1094 ;; Restore previous point.
1101 (defun mime-editor/content-beginning ()
1102 "Return the point of the beginning of content."
1104 (let ((beg (save-excursion
1105 (beginning-of-line) (point))))
1106 (if (mime-editor/goto-tag)
1107 (let ((top (point)))
1108 (goto-char (match-end 0))
1109 (if (and (= beg top)
1110 (= (following-char) ?\^M))
1114 ;; Default text/plain tag.
1115 (goto-char (point-min))
1117 (concat "\n" (regexp-quote mail-header-separator)
1118 (if mime-ignore-preceding-spaces
1119 "[ \t\n]*\n" "\n")) nil 'move)
1123 (defun mime-editor/content-end ()
1124 "Return the point of the end of content."
1126 (let ((beg (save-excursion
1127 (beginning-of-line) (point))))
1128 (if (mime-editor/goto-tag)
1129 (let ((top (point)))
1130 (goto-char (match-end 0))
1131 (if (and (= beg top) ;Must be on the same line.
1132 (= (following-char) ?\^M))
1136 ;; Move to the end of this text.
1137 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1138 ;; Don't forget a multiline tag.
1139 (goto-char (match-beginning 0)))
1142 ;; Assume the message begins with text/plain.
1143 (goto-char (mime-editor/content-beginning))
1144 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1145 ;; Don't forget a multiline tag.
1146 (goto-char (match-beginning 0)))
1150 (defun mime-editor/define-charset (charset)
1151 "Set charset of current tag to CHARSET."
1153 (if (mime-editor/goto-tag)
1154 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1155 (delete-region (match-beginning 0) (match-end 0))
1157 (mime-create-tag (mime-set-parameter
1158 (mime-editor/get-contype tag) "charset" charset)
1159 (mime-editor/get-encoding tag))))
1162 (defun mime-editor/define-encoding (encoding)
1163 "Set encoding of current tag to ENCODING."
1165 (if (mime-editor/goto-tag)
1166 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1167 (delete-region (match-beginning 0) (match-end 0))
1168 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1171 (defun mime-editor/choose-charset ()
1172 "Choose charset of a text following current point."
1173 (mime/find-charset-region (point) (mime-editor/content-end))
1176 (defun mime-make-text-tag (&optional subtype)
1177 "Make a tag for a text after current point.
1178 Subtype of text type can be specified by an optional argument SUBTYPE.
1179 Otherwise, it is obtained from mime-content-types."
1180 (let* ((pritype "text")
1181 (subtype (or subtype
1182 (car (car (cdr (assoc pritype mime-content-types)))))))
1183 ;; Charset should be defined later.
1184 (mime-make-tag pritype subtype)))
1187 ;; Tag handling functions
1189 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1190 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1191 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1195 (defun mime-create-tag (contype &optional encoding)
1196 "Make a tag with CONTENT-TYPE and optional ENCODING."
1197 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1200 (defun mime-editor/get-contype (tag)
1201 "Return Content-Type (including parameters) of TAG."
1203 (or (string-match mime-editor/single-part-tag-regexp tag)
1204 (string-match mime-editor/multipart-beginning-regexp tag)
1205 (string-match mime-editor/multipart-end-regexp tag)
1207 (substring tag (match-beginning 1) (match-end 1))
1210 (defun mime-editor/get-encoding (tag)
1211 "Return encoding of TAG."
1213 (string-match mime-editor/single-part-tag-regexp tag)
1215 (not (= (match-beginning 3) (match-end 3)))
1216 (substring tag (match-beginning 3) (match-end 3))))
1218 (defun mime-get-parameter (contype parameter)
1219 "For given CONTYPE return value for PARAMETER.
1220 Nil if no such parameter."
1224 (regexp-quote parameter)
1225 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1227 (substring contype (match-beginning 1) (match-end 1))
1228 nil ;No such parameter
1231 (defun mime-set-parameter (contype parameter value)
1232 "For given CONTYPE set PARAMETER to VALUE."
1236 (regexp-quote parameter)
1237 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1240 (concat (substring contype 0 (match-beginning 1))
1242 (substring contype (match-end 1)))
1243 (concat contype "; " parameter "=" value)))
1245 (defun mime-strip-parameters (contype)
1246 "Return primary content-type and subtype without parameters for CONTYPE."
1247 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1248 (substring contype (match-beginning 1) (match-end 1)) nil))
1250 (defun mime-test-content-type (contype type &optional subtype)
1251 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1252 (and (stringp contype)
1255 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1256 (downcase contype))))
1261 (defun mime-find-file-type (file)
1262 "Guess Content-Type, subtype, and parameters from FILE."
1264 (guesses mime-file-types))
1265 (while (and (not guess) guesses)
1266 (if (string-match (car (car guesses)) file)
1267 (setq guess (cdr (car guesses))))
1268 (setq guesses (cdr guesses)))
1272 (defun mime-prompt-for-type ()
1273 "Ask for Content-type."
1275 ;; Repeat until primary content type is specified.
1276 (while (string-equal type "")
1278 (completing-read "What content type: "
1281 'require-match ;Type must be specified.
1284 (if (string-equal type "")
1286 (message "Content type is required.")
1294 (defun mime-prompt-for-subtype (pritype)
1295 "Ask for Content-type subtype of Content-Type PRITYPE."
1296 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1301 "What content subtype: (default " default ") ")
1302 "What content subtype: ")
1303 (cdr (assoc pritype mime-content-types))
1305 'require-match ;Subtype must be specified.
1308 (if (string-equal answer "") default answer)))
1310 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1311 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1312 Optional DELIMITER specifies parameter delimiter (';' by default)."
1313 (let* ((delimiter (or delimiter "; "))
1318 (mime-prompt-for-parameters-1
1320 (cdr (assoc pritype mime-content-types))))))
1323 (if (and (stringp parameters)
1324 (not (string-equal parameters "")))
1325 (concat delimiter parameters)
1326 "" ;"" if no parameters
1329 (defun mime-prompt-for-parameters-1 (optlist)
1330 (apply (function append)
1331 (mapcar (function mime-prompt-for-parameter) optlist)))
1333 (defun mime-prompt-for-parameter (parameter)
1335 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1336 (let* ((prompt (car parameter))
1337 (choices (mapcar (function
1339 (if (consp e) e (list e))))
1341 (default (car (car choices)))
1347 (concat "What " prompt
1349 (if (string-equal default "") "\"\"" default)
1351 choices nil nil ""))
1352 ;; If nothing is selected, use default.
1353 (if (string-equal answer "")
1354 (setq answer default)))
1356 (read-string (concat "What " prompt ": "))))
1357 (cons (if (and answer
1358 (not (string-equal answer "")))
1360 ;; Note: control characters ignored!
1361 (if (string-match mime-tspecials-regexp answer)
1362 (concat "\"" answer "\"") answer)))
1363 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1366 (defun mime-flag-region (from to flag)
1367 "Hides or shows lines from FROM to TO, according to FLAG.
1368 If FLAG is `\\n' (newline character) then text is shown,
1369 while if FLAG is `\\^M' (control-M) the text is hidden."
1370 (let ((buffer-read-only nil) ;Okay even if write protected.
1371 (modp (buffer-modified-p)))
1373 (subst-char-in-region from to
1374 (if (= flag ?\n) ?\^M ?\n)
1376 (set-buffer-modified-p modp))))
1379 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1382 (defvar mime-editor/translate-buffer-hook
1383 '(mime-editor/pgp-enclose-buffer
1384 mime/encode-message-header
1385 mime-editor/translate-body))
1387 (defun mime-editor/translate-buffer ()
1388 "Encode the tagged MIME message in current buffer in MIME compliant message."
1390 (if (catch 'mime-editor/error
1392 (run-hooks 'mime-editor/translate-buffer-hook)
1396 (error "Translation error!")
1399 (defun mime-editor/find-inmost ()
1400 (goto-char (point-min))
1401 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1402 (let ((bb (match-beginning 0))
1404 (type (buffer-substring (match-beginning 1)(match-end 1)))
1406 (setq end-exp (format "^--}-<<%s>>\n" type))
1408 (if (re-search-forward end-exp nil t)
1410 (setq eb (match-beginning 0))
1411 (setq ee (match-end 0))
1413 (setq eb (point-max))
1414 (setq ee (point-max))
1416 (narrow-to-region be eb)
1418 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1420 (narrow-to-region (match-beginning 0)(point-max))
1421 (mime-editor/find-inmost)
1424 ;;(delete-region eb ee)
1425 (list type bb be eb)
1428 (defun mime-editor/process-multipart-1 (boundary)
1429 (let ((ret (mime-editor/find-inmost)))
1431 (let ((type (car ret))
1432 (bb (nth 1 ret))(be (nth 2 ret))
1435 (narrow-to-region bb eb)
1436 (delete-region bb be)
1437 (setq bb (point-min))
1438 (setq eb (point-max))
1441 (if (looking-at mime-editor/multipart-end-regexp)
1442 (let ((beg (match-beginning 0))
1445 (delete-region beg end)
1446 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
1448 (insert (concat (mime-make-text-tag) "\n"))
1450 (cond ((string= type "signed")
1451 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1452 (mime-editor/sign-pgp-elkins bb eb boundary)
1454 ((eq mime-editor/signing-type 'pgp-kazu)
1455 (mime-editor/sign-pgp-kazu bb eb boundary)
1458 ((string= type "encrypted")
1459 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1460 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1462 ((eq mime-editor/encrypting-type 'pgp-kazu)
1463 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1467 (nth 2 (mime-editor/translate-region bb eb
1471 (format "--[[multipart/%s;
1472 boundary=\"%s\"][7bit]]\n"
1478 (autoload 'mc-pgp-lookup-key "mc-pgp")
1479 (autoload 'mc-pgp-sign-region "mc-pgp")
1480 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1482 (defun tm:mc-pgp-generic-parser (result)
1483 (let ((ret (mc-pgp-generic-parser result)))
1485 (vector (car ret)(cdr ret))
1488 (defun tm:mc-process-region
1489 (beg end passwd program args parser &optional buffer boundary)
1490 (let ((obuf (current-buffer))
1491 (process-connection-type nil)
1492 mybuf result rgn proc)
1495 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1499 (buffer-disable-undo mybuf)
1501 (apply 'start-process "*PGP*" mybuf program args))
1504 (process-send-string proc (concat passwd "\n"))
1505 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1506 (process-send-region proc beg end)
1507 (process-send-eof proc)
1508 (while (eq 'run (process-status proc))
1509 (accept-process-output proc 5))
1510 (setq result (process-exit-status proc))
1511 ;; Hack to force a status_notify() in Emacs 19.29
1512 (delete-process proc)
1514 (goto-char (point-max))
1515 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1516 (delete-region (match-beginning 0) (match-end 0)))
1517 (goto-char (point-min))
1519 (while (search-forward "\r\n" nil t)
1520 (replace-match "\n"))
1521 ;; Hurm. FIXME; must get better result codes.
1522 (if (stringp result)
1523 (error "%s exited abnormally: '%s'" program result)
1524 (setq rgn (funcall parser result))
1525 ;; If the parser found something, migrate it
1531 (narrow-to-region beg end)
1533 (insert (format "--%s\n" boundary))
1534 (goto-char (point-max))
1535 (insert (format "\n--%s
1536 Content-Type: application/pgp-signature
1537 Content-Transfer-Encoding: 7bit
1540 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1541 (goto-char (point-max))
1542 (insert (format "\n--%s--\n" boundary))
1544 (delete-region beg end)
1546 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1549 (delete-region (car rgn) (cdr rgn)))))
1550 ;; Return nil on failure and exit code on success
1552 ;; Cleanup even on nonlocal exit
1553 (if (and proc (eq 'run (process-status proc)))
1554 (interrupt-process proc))
1556 (or buffer (null mybuf) (kill-buffer mybuf)))))
1558 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1559 (if (not (boundp 'mc-pgp-user-id))
1562 (let ((process-environment process-environment)
1563 (buffer (get-buffer-create mc-buffer-name))
1565 (parser (function mc-pgp-generic-parser))
1566 (pgp-path mc-pgp-path)
1568 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1572 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1573 (setenv "PGPPASSFD" "0")
1579 (list "+verbose=1" "+language=en"
1580 (format "+clearsig=%s" (if unclear "off" "on"))
1581 "+batchmode" "-u" (cdr key))))
1583 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1585 (message "Signing as %s ..." (car key))
1586 (if (tm:mc-process-region
1587 start end passwd pgp-path args parser buffer boundary)
1591 (goto-char (point-min))
1594 --[[multipart/signed; protocol=\"application/pgp-signature\";
1595 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1597 (message "Signing as %s ... Done." (car key))
1601 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1604 (narrow-to-region beg end)
1606 (mime-editor/translate-region beg end boundary))
1608 (encoding (nth 1 ret))
1610 (pgp-boundary (concat "pgp-sign-" boundary))
1613 (insert (format "Content-Type: %s\n" ctype))
1615 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1618 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1619 nil nil pgp-boundary)
1620 (throw 'mime-editor/error 'pgp-error)
1624 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1627 (let ((from (rfc822/get-field-body "From"))
1628 (to (rfc822/get-field-body "To"))
1629 (cc (rfc822/get-field-body "cc"))
1631 (narrow-to-region beg end)
1633 (mime-editor/translate-region beg end boundary))
1635 (encoding (nth 1 ret))
1637 (pgp-boundary (concat "pgp-" boundary))
1640 (if (and (stringp from)
1641 (not (string-equal from "")))
1642 (insert (format "From: %s\n" from))
1644 (if (and (stringp to)
1645 (not (string-equal to "")))
1647 (insert (format "To: %s\n" to))
1648 (setq recipients to)
1650 (if (and (stringp cc)
1651 (not (string-equal cc "")))
1653 (insert (format "cc: %s\n" cc))
1655 (setq recipients (concat recipients "," cc))
1656 (setq recipients cc)
1658 (insert (format "Content-Type: %s\n" ctype))
1660 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1664 (let ((mc-pgp-always-sign 'never))
1665 (mc-pgp-encrypt-region
1666 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1667 (point-min) (point-max) from nil)
1669 (throw 'mime-editor/error 'pgp-error)
1672 (insert (format "--[[multipart/encrypted;
1674 protocol=\"application/pgp-encrypted\"][7bit]]
1676 Content-Type: application/pgp-encrypted
1679 Content-Type: application/octet-stream
1680 Content-Transfer-Encoding: 7bit
1682 " pgp-boundary pgp-boundary pgp-boundary))
1683 (goto-char (point-max))
1684 (insert (format "\n--%s--\n" pgp-boundary))
1687 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1690 (narrow-to-region beg end)
1692 (mime-editor/translate-region beg end boundary))
1694 (encoding (nth 1 ret))
1698 (insert (format "Content-Type: %s\n" ctype))
1700 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1703 (or (as-binary-process (mc-pgp-sign-region beg (point-max)))
1704 (throw 'mime-editor/error 'pgp-error)
1708 "--[[application/pgp; format=mime][7bit]]\n")
1712 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1714 (let ((from (rfc822/get-field-body "From"))
1715 (to (rfc822/get-field-body "To"))
1716 (cc (rfc822/get-field-body "cc"))
1719 (narrow-to-region beg end)
1721 (mime-editor/translate-region beg end boundary))
1723 (encoding (nth 1 ret))
1727 (if (and (stringp from)
1728 (not (string-equal from "")))
1729 (insert (format "From: %s\n" from))
1731 (if (and (stringp to)
1732 (not (string-equal to "")))
1734 (insert (format "To: %s\n" to))
1735 (setq recipients to)
1737 (if (and (stringp cc)
1738 (not (string-equal cc "")))
1740 (insert (format "cc: %s\n" cc))
1742 (setq recipients (concat recipients "," cc))
1743 (setq recipients cc)
1745 (insert (format "Content-Type: %s\n" ctype))
1747 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1750 (or (as-binary-process
1751 (mc-pgp-encrypt-region
1752 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1755 (throw 'mime-editor/error 'pgp-error)
1759 "--[[application/pgp; format=mime][7bit]]\n")
1763 (defun mime-editor/translate-body ()
1764 "Encode the tagged MIME body in current buffer in MIME compliant message."
1768 (concat mime-multipart-boundary "_"
1769 (replace-space-with-underline (current-time-string))
1773 (while (mime-editor/process-multipart-1
1774 (format "%s-%d" boundary i))
1778 ;; We are interested in message body.
1781 (goto-char (point-min))
1783 (concat "\n" (regexp-quote mail-header-separator)
1784 (if mime-ignore-preceding-spaces
1785 "[ \t\n]*\n" "\n")) nil 'move)
1789 (goto-char (point-max))
1790 (and mime-ignore-trailing-spaces
1791 (re-search-backward "[^ \t\n]\n" beg t)
1794 (setq ret (mime-editor/translate-region
1796 (format "%s-%d" boundary i)))
1798 (let ((contype (car ret)) ;Content-Type
1799 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1801 ;; Make primary MIME headers.
1802 (or (mail-position-on-field "Mime-Version")
1803 (insert mime-editor/mime-version-value))
1804 ;; Remove old Content-Type and other fields.
1806 (goto-char (point-min))
1807 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1808 (narrow-to-region (point-min) (point))
1809 (goto-char (point-min))
1810 (mime-delete-field "Content-Type")
1811 (mime-delete-field "Content-Transfer-Encoding"))
1812 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1813 (mail-position-on-field "Content-Type")
1817 (mail-position-on-field "Content-Transfer-Encoding")
1821 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1824 (concat mime-multipart-boundary "_"
1825 (replace-space-with-underline (current-time-string))))
1829 (narrow-to-region beg end)
1830 (let ((tag nil) ;MIME tag
1831 (contype nil) ;Content-Type
1832 (encoding nil) ;Content-Transfer-Encoding
1833 (nparts 0)) ;Number of body parts
1834 ;; Normalize the body part by inserting appropriate message
1835 ;; tags for every message contents.
1836 (mime-editor/normalize-body)
1837 ;; Counting the number of Content-Type.
1838 (goto-char (point-min))
1839 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1840 (setq nparts (1+ nparts)))
1841 ;; Begin translation.
1842 (cond ((and (<= nparts 1)(not multipart))
1843 ;; It's a singular message.
1844 (goto-char (point-min))
1845 (while (re-search-forward
1846 mime-editor/single-part-tag-regexp nil t)
1848 (buffer-substring (match-beginning 0) (match-end 0)))
1849 (delete-region (match-beginning 0) (1+ (match-end 0)))
1850 (setq contype (mime-editor/get-contype tag))
1851 (setq encoding (mime-editor/get-encoding tag))
1854 ;; It's a multipart message.
1855 (goto-char (point-min))
1856 (while (re-search-forward
1857 mime-editor/single-part-tag-regexp nil t)
1859 (buffer-substring (match-beginning 0) (match-end 0)))
1860 (delete-region (match-beginning 0) (match-end 0))
1861 (setq contype (mime-editor/get-contype tag))
1862 (setq encoding (mime-editor/get-encoding tag))
1863 (insert "--" boundary "\n")
1864 (insert "Content-Type: " contype "\n")
1866 (insert "Content-Transfer-Encoding: " encoding "\n"))
1868 ;; Define Content-Type as "multipart/mixed".
1870 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1871 ;; Content-Transfer-Encoding must be "7bit".
1872 ;; The following encoding can be `nil', but is
1873 ;; specified as is since there is no way that a user
1875 (setq encoding "7bit")
1876 ;; Insert the trailer.
1877 (goto-char (point-max))
1879 (insert "--" boundary "--\n")
1880 (insert "\n--" boundary "--\n")
1882 (list contype encoding boundary nparts)
1885 (defun mime-editor/normalize-body ()
1886 "Normalize the body part by inserting appropriate message tags."
1887 ;; Insert the first MIME tags if necessary.
1888 (goto-char (point-min))
1889 (if (not (looking-at mime-editor/single-part-tag-regexp))
1890 (insert (mime-make-text-tag) "\n"))
1891 ;; Check each tag, and add new tag or correct it if necessary.
1892 (goto-char (point-min))
1893 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1894 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1895 (contype (mime-editor/get-contype tag))
1896 (charset (mime-get-parameter contype "charset"))
1897 (encoding (mime-editor/get-encoding tag)))
1898 ;; Remove extra whitespaces after the tag.
1899 (if (looking-at "[ \t]+$")
1900 (delete-region (match-beginning 0) (match-end 0)))
1902 ((= (following-char) ?\^M)
1903 ;; It must be image, audio or video.
1905 (end (mime-editor/content-end)))
1906 ;; Insert explicit MIME tags after hidden messages.
1908 (if (and (not (eobp))
1909 (not (looking-at mime-editor/single-part-tag-regexp)))
1911 (insert (mime-make-text-tag) "\n")
1912 (forward-line -1) ;Process it again as text.
1914 ;; Show a hidden message. The point is not altered
1915 ;; after the conversion.
1916 (mime-flag-region beg end ?\n)
1918 ((mime-test-content-type contype "message")
1919 ;; Content-type "message" should be sent as is.
1922 ((mime-test-content-type contype "text")
1923 ;; Define charset for text if necessary.
1924 (setq charset (or charset (mime-editor/choose-charset)))
1925 (mime-editor/define-charset charset)
1926 (cond ((string-equal contype "text/x-rot13-47")
1930 (goto-char (mime-editor/content-end))
1933 ((string-equal contype "text/enriched")
1938 (end (mime-editor/content-end))
1940 (enriched-encode beg end)
1942 (if (search-forward "\n\n")
1943 (delete-region beg (match-end 0))
1946 ;; Point is now on current tag.
1947 ;; Define encoding and encode text if necessary.
1948 (or encoding ;Encoding is not specified.
1952 mime-editor/charset-default-encoding-alist)
1954 (beg (mime-editor/content-beginning))
1956 (mime-charset-encode-region beg (mime-editor/content-end)
1958 (mime-encode-region beg (mime-editor/content-end) encoding)
1959 (mime-editor/define-encoding encoding)
1963 ((null encoding) ;Encoding is not specified.
1964 ;; Application, image, audio, video, and any other
1965 ;; unknown content-type without encoding should be
1967 (let* ((encoding "base64") ;Encode in BASE64 by default.
1968 (beg (mime-editor/content-beginning))
1969 (end (mime-editor/content-end))
1970 (body (buffer-substring beg end))
1972 (mime-encode-region beg end encoding)
1973 (mime-editor/define-encoding encoding))
1979 (defun mime-delete-field (field)
1980 "Delete header FIELD."
1981 (let ((regexp (format "^%s:[ \t]*" field)))
1982 (goto-char (point-min))
1983 (while (re-search-forward regexp nil t)
1984 (delete-region (match-beginning 0)
1985 (progn (forward-line 1) (point)))
1990 ;;; Platform dependent functions
1993 ;; Sun implementations
1995 (defun mime-voice-recorder-for-sun ()
1996 "Record voice in a buffer using Sun audio device, and return the buffer.
1997 If the environment variable AUDIOHOST is defined, its value is used as
1998 a recording host instead of local host."
1999 (let ((buffer (get-buffer-create " *MIME audio*"))
2000 (host (getenv "AUDIOHOST")))
2001 (message "Start the recording on %s. Type C-g to finish the recording..."
2002 (or host (system-name)))
2006 (condition-case errorcode
2007 (let ((selective-display nil) ;Disable ^M to nl translation.
2009 (kanji-flag nil)) ;NEmacs
2010 ;; If AUDIOHOST is defined, use the value as recording host.
2011 (cond ((not (null host))
2012 ;; Disable automatic conversion of coding system if Mule.
2013 (if (featurep 'mule)
2014 (define-program-coding-system nil "rsh" *noconv*))
2024 ;; Disable automatic conversion of coding system if Mule.
2025 (if (featurep 'mule)
2026 (define-program-coding-system nil "cat" *noconv*))
2032 (quit (message "Type C-g to finish recording... done.")
2033 buffer ;Return the buffer
2037 ;;; @ Other useful commands.
2040 ;; Message forwarding commands as content-type "message/rfc822".
2042 (defun mime-editor/insert-message (&optional message)
2044 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2045 (if (and inserter (fboundp inserter))
2047 (mime-editor/insert-tag "message" "rfc822")
2048 (funcall inserter message)
2050 (message "Sorry, I don't have message inserter for your MUA.")
2053 (defun mime-editor/insert-mail (&optional message)
2055 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2056 (if (and inserter (fboundp inserter))
2058 (mime-editor/insert-tag "message" "rfc822")
2059 (funcall inserter message)
2061 (message "Sorry, I don't have mail inserter for your MUA.")
2064 (defun mime-editor/inserted-message-filter ()
2067 (let ((header-start (point))
2068 (case-fold-search t)
2071 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2072 (if (re-search-forward "^$" (mark t))
2073 (narrow-to-region header-start (match-beginning 0))
2075 (goto-char header-start)
2076 (while (and (re-search-forward
2077 mime-editor/yank-ignored-field-regexp nil t)
2078 (setq beg (match-beginning 0))
2079 (setq end (1+ (rfc822/field-end)))
2081 (delete-region beg end)
2086 ;;; @ multipart enclosure
2089 (defun mime-editor/enclose-region (type beg end)
2092 (let ((current (point))
2095 (if (mime-editor/goto-tag)
2096 (or (eq current (match-beginning 0))
2097 (setq exist-prev-tag t)
2100 (narrow-to-region beg end)
2105 (insert (format "--<<%s>>-{\n" type))
2106 (goto-char (point-max))
2107 (insert (format "\n--}-<<%s>>\n" type))
2108 (goto-char (point-max))
2110 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
2112 (insert (mime-make-text-tag) "\n")
2116 (defun mime-editor/enclose-mixed-region (beg end)
2118 (mime-editor/enclose-region "mixed" beg end)
2121 (defun mime-editor/enclose-parallel-region (beg end)
2123 (mime-editor/enclose-region "parallel" beg end)
2126 (defun mime-editor/enclose-digest-region (beg end)
2128 (mime-editor/enclose-region "digest" beg end)
2131 (defun mime-editor/enclose-alternative-region (beg end)
2133 (mime-editor/enclose-region "alternative" beg end)
2136 (defun mime-editor/enclose-signed-region (beg end)
2138 (if mime-editor/signing-type
2139 (mime-editor/enclose-region "signed" beg end)
2140 (message "Please specify signing type.")
2143 (defun mime-editor/enclose-encrypted-region (beg end)
2145 (if mime-editor/signing-type
2146 (mime-editor/enclose-region "encrypted" beg end)
2147 (message "Please specify encrypting type.")
2150 (defun mime-editor/insert-key (&optional arg)
2151 "Insert a pgp public key."
2153 (mime-editor/insert-tag "application" "pgp-keys")
2154 (mime-editor/define-encoding "7bit")
2155 (mc-insert-public-key)
2162 (defun mime-editor/set-split (arg)
2165 (y-or-n-p "Do you want to enable split?")
2167 (setq mime-editor/split-message arg)
2169 (message "This message is enabled to split.")
2170 (message "This message is not enabled to split.")
2173 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2174 "Toggle transfer-level is 7bit or 8bit through.
2176 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2178 (if (numberp transfer-level)
2179 (setq mime-editor/transfer-level transfer-level)
2180 (if (< mime-editor/transfer-level 8)
2181 (setq mime-editor/transfer-level 8)
2182 (setq mime-editor/transfer-level 7)
2184 (setq mime-editor/charset-default-encoding-alist
2185 (mime/make-charset-default-encoding-alist
2186 mime-editor/transfer-level))
2187 (message (format "Current transfer-level is %d bit"
2188 mime-editor/transfer-level))
2189 (setq mime-editor/transfer-level-string
2190 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2191 (force-mode-line-update)
2198 (defun mime-editor/set-sign (arg)
2201 (y-or-n-p "Do you want to sign?")
2204 (if mime-editor/signing-type
2206 (setq mime-editor/pgp-processing 'sign)
2207 (message "This message will be signed.")
2209 (message "Please specify signing type.")
2211 (if (eq mime-editor/pgp-processing 'sign)
2212 (setq mime-editor/pgp-processing nil)
2214 (message "This message will not be signed.")
2217 (defun mime-editor/set-encrypt (arg)
2220 (y-or-n-p "Do you want to encrypt?")
2223 (if mime-editor/encrypting-type
2225 (setq mime-editor/pgp-processing 'encrypt)
2226 (message "This message will be encrypt.")
2228 (message "Please specify encrypting type.")
2230 (if (eq mime-editor/pgp-processing 'encrypt)
2231 (setq mime-editor/pgp-processing nil)
2233 (message "This message will not be encrypt.")
2236 (defvar mime-editor/pgp-processing nil)
2237 (make-variable-buffer-local 'mime-editor/pgp-processing)
2239 (defun mime-editor/pgp-enclose-buffer ()
2240 (let ((beg (save-excursion
2241 (goto-char (point-min))
2242 (if (search-forward (concat "\n" mail-header-separator "\n"))
2248 (cond ((eq mime-editor/pgp-processing 'sign)
2249 (mime-editor/enclose-signed-region beg end)
2251 ((eq mime-editor/pgp-processing 'encrypt)
2252 (mime-editor/enclose-encrypted-region beg end)
2260 (defun mime-editor/insert-partial-header
2261 (fields subject id number total separator)
2263 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2264 (insert (format "Mime-Version: 1.0 (split by tm-edit %s)\n"
2265 mime-editor/version))
2267 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2268 id number total separator))
2271 (defun mime-editor/split-and-send
2272 (&optional cmd lines mime-editor/message-max-length)
2276 (count-lines (point-min) (point-max)))
2278 (or mime-editor/message-max-length
2279 (setq mime-editor/message-max-length
2280 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2281 mime-editor/message-default-max-length))
2283 (let* ((mime-editor/draft-file-name
2284 (or (buffer-file-name)
2286 (expand-file-name "tm-draft" mime/tmp-dir))))
2287 (separator mail-header-separator)
2289 (replace-space-with-underline (current-time-string))
2290 "@" (system-name) "\"")))
2291 (run-hooks 'mime-editor/before-split-hook)
2292 (let ((the-buf (current-buffer))
2293 (copy-buf (get-buffer-create " *Original Message*"))
2294 (header (rfc822/get-header-string-except
2295 mime-editor/split-ignored-field-regexp separator))
2296 (subject (mail-fetch-field "subject"))
2297 (total (+ (/ lines mime-editor/message-max-length)
2298 (if (> (mod lines mime-editor/message-max-length) 0)
2304 mime-editor/split-message-sender-alist))
2306 (mime-editor/partial-number 1)
2309 (set-buffer copy-buf)
2311 (insert-buffer the-buf)
2313 (if (re-search-forward
2314 (concat "^" (regexp-quote separator) "$") nil t)
2315 (let ((he (match-beginning 0)))
2317 (narrow-to-region (point-min) he)
2319 (goto-char (point-min))
2320 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
2321 (delete-region (match-beginning 0)
2322 (1+ (rfc822/field-end)))
2324 (while (< mime-editor/partial-number total)
2327 (set-buffer copy-buf)
2328 (setq data (buffer-substring
2331 (goto-line mime-editor/message-max-length)
2334 (delete-region (point-min)(point))
2336 (mime-editor/insert-partial-header
2337 header subject id mime-editor/partial-number total separator)
2340 (message (format "Sending %d/%d..."
2341 mime-editor/partial-number total))
2342 (call-interactively command)
2343 (message (format "Sending %d/%d... done"
2344 mime-editor/partial-number total))
2346 (setq mime-editor/partial-number
2347 (1+ mime-editor/partial-number))
2351 (set-buffer copy-buf)
2352 (setq data (buffer-string))
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 (message (format "Sending %d/%d... done"
2362 mime-editor/partial-number total))
2366 (defun mime-editor/maybe-split-and-send (&optional cmd)
2368 (run-hooks 'mime-editor/before-send-hook)
2369 (let ((mime-editor/message-max-length
2370 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2371 mime-editor/message-default-max-length))
2372 (lines (count-lines (point-min) (point-max)))
2374 (if (and (> lines mime-editor/message-max-length)
2375 mime-editor/split-message)
2376 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2380 ;;; @ preview message
2383 (defun mime-editor/preview-message ()
2384 "preview editing MIME message. [tm-edit.el]"
2386 (let* ((str (buffer-string))
2387 (separator mail-header-separator)
2388 (the-buf (current-buffer))
2389 (buf-name (buffer-name))
2390 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2391 (buf (get-buffer temp-buf-name))
2395 (switch-to-buffer buf)
2398 (setq buf (get-buffer-create temp-buf-name))
2399 (switch-to-buffer buf)
2402 (setq major-mode 'mime/temporary-message-mode)
2403 (make-local-variable 'mail-header-separator)
2404 (setq mail-header-separator separator)
2405 (make-local-variable 'mime/editing-buffer)
2406 (setq mime/editing-buffer the-buf)
2408 (run-hooks 'mime-editor/translate-hook)
2409 (mime-editor/translate-buffer)
2410 (goto-char (point-min))
2411 (if (re-search-forward
2412 (concat "^" (regexp-quote separator) "$"))
2418 (defun mime-editor/quitting-method ()
2419 (let ((temp mime::preview/article-buffer)
2421 (mime-viewer/kill-buffer)
2423 (setq buf mime/editing-buffer)
2425 (switch-to-buffer buf)
2428 (set-alist 'mime-viewer/quitting-method-alist
2429 'mime/temporary-message-mode
2430 (function mime-editor/quitting-method)
2436 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2437 ;; Mon, 10 Apr 1995 20:03:07 +0900
2439 (defvar mime-editor/draft-header-separator-alist
2440 '((news-reply-mode . mail-header-separator)
2441 (mh-letter-mode . mail-header-separator)
2444 (defvar mime::article/draft-header-separator nil)
2446 (defun mime-editor/draft-preview ()
2448 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2449 (or (stringp sep) (setq sep (eval sep)))
2450 (make-variable-buffer-local 'mime::article/draft-header-separator)
2451 (goto-char (point-min))
2453 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2454 (setq mime::article/draft-header-separator
2455 (buffer-substring (match-beginning 0) (match-end 0)))
2457 (mime/viewer-mode (current-buffer))
2458 (pop-to-buffer (current-buffer))
2461 (defun mime-viewer::quitting-method/draft-preview ()
2462 (let ((mother mime::preview/mother-buffer))
2464 (switch-to-buffer mother)
2465 (goto-char (point-min))
2469 (regexp-quote mime::article/draft-header-separator)
2473 (insert mime::article/draft-header-separator)
2474 (set-buffer-modified-p (buffer-modified-p))
2476 (mime-viewer/kill-buffer)
2477 (pop-to-buffer mother)
2480 (set-alist 'mime-viewer/quitting-method-alist
2482 (function mime-viewer::quitting-method/draft-preview)
2485 (set-alist 'mime-viewer/quitting-method-alist
2487 (function mime-viewer::quitting-method/draft-preview)
2494 (defun mime-editor::edit-again (code-conversion)
2496 (goto-char (point-min))
2497 (let ((ctl (mime/Content-Type)))
2499 (let ((ctype (car ctl))
2502 (if (string-match "/" ctype)
2504 (setq type (substring ctype 0 (match-beginning 0)))
2505 (setq stype (substring ctype (match-end 0)))
2510 ((string-equal type "multipart")
2511 (let ((boundary (assoc-value "boundary" params)))
2512 (re-search-forward (concat "\n--" boundary) nil t)
2513 (let ((bb (match-beginning 0)) eb tag)
2514 (setq tag (format "\n--<<%s>>-{" stype))
2517 (setq bb (+ bb (length tag)))
2518 (re-search-forward (concat "\n--" boundary "--") nil t)
2519 (setq eb (match-beginning 0))
2520 (replace-match (format "\n--}-<<%s>>" stype))
2522 (narrow-to-region bb eb)
2523 (goto-char (point-min))
2524 (while (re-search-forward
2525 (concat "\n--" boundary "\n") nil t)
2526 (let ((beg (match-beginning 0))
2528 (delete-region beg (match-end 0))
2530 (if (re-search-forward
2531 (concat "\n--" boundary) nil t)
2532 (setq end (match-beginning 0))
2533 (setq end (point-max))
2536 (narrow-to-region beg end)
2537 (mime-editor::edit-again code-conversion)
2538 (goto-char (point-max))
2541 (goto-char (point-min))
2542 (or (= (point-min) 1)
2543 (delete-region (point-min)
2544 (if (re-search-forward "^$" nil t)
2552 (mapconcat (function
2554 (if (string-equal (car attr)
2557 (setq charset (cdr attr))
2559 (concat ";" (car attr)
2567 (if (re-search-forward
2568 "Content-Transfer-Encoding:" nil t)
2569 (let ((beg (match-beginning 0))
2570 (hbeg (match-end 0))
2571 (end (rfc822/field-end)))
2573 (eliminate-top-spaces
2574 (rfc822/unfolding-string
2575 (buffer-substring hbeg end))))
2576 (if (or charset (string-equal type "text"))
2578 (delete-region beg (1+ end))
2579 (goto-char (point-min))
2580 (if (search-forward "\n\n" nil t)
2583 (match-end 0)(point-max) encoding)
2587 (if (or code-conversion encoded)
2589 (mime-charset-decode-region (point-min)(point-max)
2591 (character-decode-region (point-min)(point-max)
2592 mime/default-coding-system)
2595 (if (re-search-forward "^$" nil t)
2599 (if (= (point-min) 1)
2606 (concat type "/" stype pstr) encoding)
2609 (delete-region (point-min) he)
2613 (concat type "/" stype pstr) encoding)
2618 (character-decode-region (point-min) (point-max)
2619 mime/default-coding-system)
2623 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2625 (mime-editor::edit-again code-conversion)
2626 (goto-char (point-min))
2628 (narrow-to-region (point-min)
2629 (if (re-search-forward "^$" nil t)
2633 (goto-char (point-min))
2634 (while (re-search-forward
2635 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2636 (delete-region (match-beginning 0) (1+ (rfc822/field-end)))
2639 (and (re-search-forward "^$")
2640 (replace-match mail-header-separator)
2652 (run-hooks 'tm-edit-load-hook)
2654 ;;; tm-edit.el ends here