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.66 $
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.66 1996/05/28 03:06:10 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/message-default-sender-alist
405 '((mail-mode . mail-send-and-exit)
406 (mh-letter-mode . mh-send-letter)
407 (news-reply-mode . gnus-inews-news)
410 (defvar mime-editor/split-message-sender-alist
417 . (lambda (&optional arg)
419 (write-region (point-min) (point-max)
420 mime-editor/draft-file-name nil 'no-message)
422 (pop-to-buffer "MH mail delivery")
424 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
426 mh-send-args mime-editor/draft-file-name)
427 (goto-char (point-max)) ; show the interesting part
431 (apply 'mh-exec-cmd-quiet t mh-send-prog
433 (list "-nopush" "-nodraftfolder"
434 "-noverbose" "-nowatch"
435 mh-send-args mime-editor/draft-file-name)))))
439 (defvar mime-editor/window-config-alist
441 (mh-letter-mode . mh-previous-window-config)
442 (news-reply-mode . (cond ((boundp 'gnus-winconf-post-news)
444 gnus-winconf-post-news
445 (setq gnus-winconf-post-news nil)
447 ((boundp 'gnus-prev-winconf)
450 (setq gnus-prev-winconf nil)
455 (defvar mime-editor/news-reply-mode-server-running nil)
461 (defvar mime-editor/signing-type nil
462 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
464 (defvar mime-editor/encrypting-type nil
465 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
467 (if (or mime-editor/signing-type mime-editor/encrypting-type)
475 (defconst mime-editor/single-part-tag-regexp
476 "^--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
477 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
479 (defconst mime-editor/multipart-beginning-regexp "^--<<\\([^<>]+\\)>>-{\n")
481 (defconst mime-editor/multipart-end-regexp "^--}-<<\\([^<>]+\\)>>\n")
483 (defconst mime-editor/beginning-tag-regexp
484 (regexp-or mime-editor/single-part-tag-regexp
485 mime-editor/multipart-beginning-regexp))
487 (defconst mime-editor/end-tag-regexp
488 (regexp-or mime-editor/single-part-tag-regexp
489 mime-editor/multipart-end-regexp))
491 (defconst mime-editor/tag-regexp
492 (regexp-or mime-editor/single-part-tag-regexp
493 mime-editor/multipart-beginning-regexp
494 mime-editor/multipart-end-regexp))
496 (defvar mime-tag-format "--[[%s]]"
497 "*Control-string making a MIME tag.")
499 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
500 "*Control-string making a MIME tag with encoding.")
502 ;;; @@ multipart boundary
505 (defvar mime-multipart-boundary "Multipart"
506 "*Boundary of a multipart message.")
509 ;;; @@ buffer local variables
512 (defvar mime/editor-mode-old-local-map nil)
513 (defvar mime/editor-mode-old-selective-display nil)
514 (defvar mime/editing-buffer nil)
520 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
521 "*Specify MIME tspecials.
522 Tspecials means any character that matches with it in header must be quoted.")
524 (defconst mime-editor/mime-version-value
525 (format "1.0 (generated by tm-edit %s)" mime-editor/version)
526 "MIME version number.")
528 (defconst mime-editor/mime-map (make-sparse-keymap)
529 "Keymap for MIME commands.")
532 ;;; @ keymap and menu
535 (defvar mime/editor-mode-flag nil)
536 (make-variable-buffer-local 'mime/editor-mode-flag)
538 (set-alist 'minor-mode-alist
539 'mime/editor-mode-flag
540 '((" MIME-Edit " mime-editor/transfer-level-string)))
542 (defun mime-editor/define-keymap (keymap)
543 "Add mime-editor commands to KEYMAP."
544 (if (not (keymapp keymap))
546 (define-key keymap "\C-t" 'mime-editor/insert-text)
547 (define-key keymap "\C-i" 'mime-editor/insert-file)
548 (define-key keymap "\C-e" 'mime-editor/insert-external)
549 (define-key keymap "\C-v" 'mime-editor/insert-voice)
550 (define-key keymap "\C-y" 'mime-editor/insert-message)
551 (define-key keymap "\C-m" 'mime-editor/insert-mail)
552 (define-key keymap "\C-w" 'mime-editor/insert-signature)
553 (define-key keymap "\C-s" 'mime-editor/insert-signature)
554 (define-key keymap "\C-k" 'mime-editor/insert-key)
555 (define-key keymap "t" 'mime-editor/insert-tag)
556 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
557 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
558 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
559 (define-key keymap "d" 'mime-editor/enclose-digest-region)
560 (define-key keymap "s" 'mime-editor/enclose-signed-region)
561 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
562 (define-key keymap "\C-p" 'mime-editor/preview-message)
563 (define-key keymap "\C-z" 'mime-editor/exit)
564 (define-key keymap "?" 'mime-editor/help)
567 (mime-editor/define-keymap mime-editor/mime-map)
569 (defconst mime-editor/menu-title "MIME-Edit")
571 (defconst mime-editor/menu-list
572 '((mime-help "Describe MIME editor mode" mime-editor/help)
573 (file "Insert File" mime-editor/insert-file)
574 (external "Insert External" mime-editor/insert-external)
575 (voice "Insert Voice" mime-editor/insert-voice)
576 (message "Insert Message" mime-editor/insert-message)
577 (mail "Insert Mail" mime-editor/insert-mail)
578 (signature "Insert Signature" mime-editor/insert-signature)
579 (text "Insert Text" mime-editor/insert-text)
580 (tag "Insert Tag" mime-editor/insert-tag)
581 (alternative "Enclose as alternative"
582 mime-editor/enclose-alternative-region)
583 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
584 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
585 (digest "Enclose as digest" mime-editor/enclose-digest-region)
586 (signed "Enclose as signed" mime-editor/enclose-signed-region)
587 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
588 (key "Insert Public Key" mime-editor/insert-key)
589 (split "About split" mime-editor/set-split)
590 (sign "About sign" mime-editor/set-sign)
591 (encrypt "About encryption" mime-editor/set-encrypt)
592 (preview "Preview Message" mime-editor/preview-message)
593 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
595 "MIME-edit menubar entry.")
597 (defun mime-editor/define-menu-for-emacs19 ()
598 "Define menu for Emacs 19."
599 (define-key (current-local-map) [menu-bar mime-edit]
600 (cons mime-editor/menu-title
601 (make-sparse-keymap mime-editor/menu-title)))
604 (define-key (current-local-map)
605 (vector 'menu-bar 'mime-edit (car item))
606 (cons (nth 1 item)(nth 2 item))
609 (reverse mime-editor/menu-list)
612 ;;; modified by Pekka Marjola <pema@iki.fi>
613 ;;; 1995/9/5 (c.f. [tm-en:69])
614 (defun mime-editor/define-menu-for-xemacs ()
615 "Define menu for Emacs 19."
616 (cond ((featurep 'menubar)
617 (make-local-variable 'current-menubar)
618 (set-buffer-menubar current-menubar)
620 (cons mime-editor/menu-title
623 (vector (nth 1 item)(nth 2 item)
624 mime/editor-mode-flag)
626 mime-editor/menu-list)))
629 ;;; modified by Steven L. Baur <steve@miranova.com>
630 ;;; 1995/12/6 (c.f. [tm-en:209])
631 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
632 (setq mime-editor/popup-menu-for-xemacs
633 (append '("MIME Commands" "---")
634 (mapcar (function (lambda (item)
638 mime-editor/menu-list)))
647 (defun mime/editor-mode ()
648 "MIME minor mode for editing the tagged MIME message.
650 In this mode, basically, the message is composed in the tagged MIME
651 format. The message tag looks like:
653 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
655 The tag specifies the MIME content type, subtype, optional parameters
656 and transfer encoding of the message following the tag. Messages
657 without any tag are treated as `text/plain' by default. Charset and
658 transfer encoding are automatically defined unless explicitly
659 specified. Binary messages such as audio and image are usually hidden
660 using selective-display facility. The messages in the tagged MIME
661 format are automatically translated into a MIME compliant message when
664 Available charsets depend on Emacs version being used. The following
665 lists the available charsets of each emacs.
667 Emacs18: US-ASCII is only available.
668 NEmacs: US-ASCII and ISO-2022-JP are available.
669 Emacs19: US-ASCII and ISO-8859-1 are available.
670 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-6),
671 ISO-2022-JP, ISO-2022-JP-2 and ISO-2022-INT-1 are available.
673 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in Mule is expected to
674 be used to represent multilingual text in intermixed manner. Any
675 languages that has no registered charset are represented as either
676 ISO-2022-JP-2 or ISO-2022-INT-1 in Mule.
678 Following commands are available in addition to major mode commands:
679 \\[mime-editor/insert-text] insert a text message.
680 \\[mime-editor/insert-file] insert a (binary) file.
681 \\[mime-editor/insert-external] insert a reference to external body.
682 \\[mime-editor/insert-voice] insert a voice message.
683 \\[mime-editor/insert-message] insert a mail or news message.
684 \\[mime-editor/insert-mail] insert a mail message.
685 \\[mime-editor/insert-signature] insert a signature file at end.
686 \\[mime-editor/insert-tag] insert a new MIME tag.
687 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
688 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
689 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
690 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
691 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
692 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
693 \\[mime-editor/insert-key] insert PGP public key.
694 \\[mime-editor/preview-message] preview editing MIME message.
695 \\[mime-editor/exit] exit and translate into a MIME compliant message.
696 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
697 \\[mime-editor/help] show this help.
699 Additional commands are available in some major modes:
700 C-c C-c exit, translate and run the original command.
701 C-c C-s exit, translate and run the original command.
703 The following is a message example written in the tagged MIME format.
704 TABs at the beginning of the line are not a part of the message:
706 This is a conventional plain text. It should be translated
709 This is also a plain text. But, it is explicitly specified as
711 --[[text/plain; charset=ISO-2022-JP]]
712 \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
715 <center>This is a richtext.</center>
716 --[[image/gif][base64]]^M...image encoded in base64 here...
717 --[[audio/basic][base64]]^M...audio encoded in base64 here...
719 User customizable variables (not documented all of them):
721 Specifies a key prefix for MIME minor mode commands.
723 mime-ignore-preceding-spaces
724 Preceding white spaces in a message body are ignored if non-nil.
726 mime-ignore-trailing-spaces
727 Trailing white spaces in a message body are ignored if non-nil.
729 mime-auto-fill-header
730 Fill header fields that contain encoded-words if non-nil.
733 Hide a non-textual body message encoded in base64 after insertion
737 Specifies a function to record a voice message and return a buffer
738 that contains it. The function mime-voice-recorder-for-sun is for
741 mime/editor-mode-hook
742 Turning on MIME mode calls the value of mime/editor-mode-hook, if
745 mime-editor/translate-hook
746 The value of mime-editor/translate-hook is called just before translating
747 the tagged MIME format into a MIME compliant message if it is
748 non-nil. If the hook call the function mime-editor/insert-signature,
749 the signature file will be inserted automatically.
751 mime-editor/exit-hook
752 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
755 (if mime/editor-mode-flag
756 (error "You are already editing a MIME message.")
757 (setq mime/editor-mode-flag t)
758 ;; Remember old key bindings.
761 (make-local-variable 'mime/editor-mode-old-local-map)
762 (setq mime/editor-mode-old-local-map (current-local-map))
763 ;; Add MIME commands to current local map.
764 (use-local-map (copy-keymap (current-local-map)))
766 (if (not (lookup-key (current-local-map) mime-prefix))
767 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
769 ;; Set transfer level into mode line
771 (setq mime-editor/transfer-level-string
772 (mime/encoding-name mime-editor/transfer-level 'not-omit))
773 (force-mode-line-update)
775 ;; Define menu. Menus for other emacs implementations are
777 (cond (running-xemacs
778 (mime-editor/define-menu-for-xemacs))
779 ((>= emacs-major-version 19)
780 (mime-editor/define-menu-for-emacs19)
784 ;; Remember old selective-display.
785 (make-local-variable 'mime/editor-mode-old-selective-display)
786 (setq mime/editor-mode-old-selective-display selective-display)
787 (setq selective-display t)
788 ;; I don't care about saving these.
789 (setq paragraph-start
790 (regexp-or mime-editor/single-part-tag-regexp
792 (setq paragraph-separate
793 (regexp-or mime-editor/single-part-tag-regexp
795 (run-hooks 'mime/editor-mode-hook)
797 (substitute-command-keys
798 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
802 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
803 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
805 (defun mime-editor/exit (&optional nomime no-error)
806 "Translate the tagged MIME message into a MIME compliant message.
807 With no argument encode a message in the buffer into MIME, otherwise
808 just return to previous mode."
810 (if (not mime/editor-mode-flag)
812 (error "You aren't editing a MIME message.")
816 (run-hooks 'mime-editor/translate-hook)
817 (mime-editor/translate-buffer)))
818 ;; Restore previous state.
819 (setq mime/editor-mode-flag nil)
820 (cond (running-xemacs
821 ;; mime-prefix only defined if binding was nil
822 (if (eq (lookup-key (current-local-map) mime-prefix)
823 mime-editor/mime-map)
824 (define-key (current-local-map) mime-prefix nil))
825 (delete-menu-item (list mime-editor/menu-title)))
827 (use-local-map mime/editor-mode-old-local-map)))
829 (setq selective-display mime/editor-mode-old-selective-display)
830 (set-buffer-modified-p (buffer-modified-p))
831 (run-hooks 'mime-editor/exit-hook)
832 (message "Exit MIME editor mode.")
835 (defun mime-editor/maybe-translate ()
837 (mime-editor/exit nil t)
838 (call-interactively 'mime-editor/maybe-split-and-send)
841 (defun mime-editor/help ()
842 "Show help message about MIME mode."
844 (with-output-to-temp-buffer "*Help*"
845 (princ "MIME editor mode:\n")
846 (princ (documentation 'mime/editor-mode))
847 (print-help-return-message)))
849 (defun mime-editor/insert-text ()
850 "Insert a text message.
851 Charset is automatically obtained from the `mime/lc-charset-alist'."
853 (if (and (mime-editor/insert-tag "text" nil nil)
854 (looking-at mime-editor/single-part-tag-regexp))
856 ;; Make a space between the following message.
861 (defun mime-editor/insert-file (file)
862 "Insert a message from a file."
863 (interactive "fInsert file as MIME message: ")
864 (let* ((guess (mime-find-file-type file))
865 (pritype (nth 0 guess))
866 (subtype (nth 1 guess))
867 (parameters (nth 2 guess))
868 (default (nth 3 guess)) ;Guess encoding from its file name.
869 (disposition-type (nth 4 guess))
870 (disposition-params (nth 5 guess))
872 (if (not (interactive-p))
875 (concat "What transfer encoding"
878 (if (string-equal default "")
884 mime-encoding-method-alist nil t nil))))
885 (if (string-equal encoding "")
886 (setq encoding default))
887 (if (or (consp parameters) (stringp disposition-type))
888 (let ((rest parameters) cell attribute value)
891 (setq cell (car rest))
892 (setq attribute (car cell))
893 (setq value (cdr cell))
895 (setq value (rfc822/wrap-as-quoted-string
896 (file-name-nondirectory file)))
898 (setq parameters (concat parameters "; " attribute "=" value))
899 (setq rest (cdr rest))
904 (concat parameters "\n"
905 "Content-Disposition: " disposition-type))
906 (setq rest disposition-params)
908 (setq cell (car rest))
909 (setq attribute (car cell))
910 (setq value (cdr cell))
912 (setq value (rfc822/wrap-as-quoted-string
913 (file-name-nondirectory file)))
916 (concat parameters "; " attribute "=" value))
917 (setq rest (cdr rest))
921 (mime-editor/insert-tag pritype subtype parameters)
922 (mime-editor/insert-binary-file file encoding)
925 (defun mime-editor/insert-external ()
926 "Insert a reference to external body."
928 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
930 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
932 (let* ((pritype (mime-prompt-for-type))
933 (subtype (mime-prompt-for-subtype pritype))
934 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
937 (insert "Content-Type: "
938 pritype "/" subtype (or parameters "") "\n")))
939 (if (and (not (eobp))
940 (not (looking-at mime-editor/single-part-tag-regexp)))
941 (insert (mime-make-text-tag) "\n")))
943 (defun mime-editor/insert-voice ()
944 "Insert a voice message."
946 (mime-editor/insert-tag "audio" "basic" nil)
947 (let ((buffer (funcall mime-voice-recorder)))
949 (mime-editor/insert-binary-buffer buffer "base64")
953 (defun mime-editor/insert-signature (&optional arg)
954 "Insert a signature file."
956 (let ((signature-insert-hook
959 (apply (function mime-editor/insert-tag)
960 (mime-find-file-type signature-file-name))
963 (insert-signature arg)
967 ;; Insert a new tag around a point.
969 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
970 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
971 If nothing is inserted, return nil."
976 exist-prev-tag exist-next-tag)
979 (mime-prompt-for-type)))
982 (mime-prompt-for-subtype pritype)))
985 (mime-prompt-for-parameters pritype subtype delimiter)))
986 ;; Make a new MIME tag.
987 (setq newtag (mime-make-tag pritype subtype parameters))
988 ;; Find an current MIME tag.
991 (if (mime-editor/goto-tag)
993 (if (eq current (match-beginning 0))
994 (setq exist-next-tag t)
995 (setq exist-prev-tag t)
997 (buffer-substring (match-beginning 0) (match-end 0))
999 ;; Assume content type is 'text/plan'.
1000 (mime-make-tag "text" "plain")
1002 ;; We are only interested in TEXT.
1004 (not (mime-test-content-type
1005 (mime-editor/get-contype oldtag) "text")))
1007 (cond (exist-prev-tag (insert "\n"))
1008 (exist-next-tag (save-excursion
1017 (if (or (not oldtag) ;Not text
1018 (or mime-ignore-same-text-tag
1019 (not (string-equal oldtag newtag))))
1021 ;; Mark the beginning of the tag for convenience.
1022 (push-mark (point) 'nomsg)
1023 (insert newtag "\n")
1024 (list pritype subtype parameters) ;New tag is created.
1026 ;; Restore previous point.
1028 nil ;Nothing is created.
1032 ;; Insert the binary content after MIME tag.
1033 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1035 (defun mime-editor/insert-binary-file (file &optional encoding)
1036 "Insert binary FILE at point.
1037 Optional argument ENCODING specifies an encoding method such as base64."
1038 (let ((tmpbuf (get-buffer-create " *MIME insert*")))
1042 (let ((mc-flag nil) ;Mule
1043 (file-coding-system-for-read
1044 (if (featurep 'mule) *noconv*))
1045 (kanji-flag nil) ;NEmacs
1046 (emx-binary-mode t) ;Stop CRLF to LF conversion in OS/2
1048 (let (jka-compr-compression-info-list
1049 jam-zcat-filename-list)
1050 (insert-file-contents file))))
1052 (if (and (stringp encoding)
1053 (string-equal (downcase encoding) "x-uue"))
1056 (let ((uuencode-external-encoder
1057 (cons (car uuencode-external-encoder)
1058 (list (file-name-nondirectory file))
1060 (mime-editor/insert-binary-buffer tmpbuf encoding)
1062 (mime-editor/insert-binary-buffer tmpbuf encoding))
1063 (kill-buffer tmpbuf))))
1065 ;; Insert the binary content after MIME tag.
1066 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1068 (defun mime-editor/insert-binary-buffer (buffer &optional encoding)
1069 "Insert binary BUFFER at point.
1070 Optional argument ENCODING specifies an encoding method such as base64."
1071 (let* ((tagend (1- (point))) ;End of the tag
1072 (hide-p (and mime-auto-hide-body
1074 (let ((en (downcase encoding)))
1075 (or (string-equal en "base64")
1076 (string-equal en "x-uue")
1080 (narrow-to-region (1- (point)) (point))
1081 (let ((start (point))
1082 (emx-binary-mode t)) ;Stop LF to CRLF conversion in OS/2
1083 (insert-buffer-substring buffer)
1084 ;; Encode binary message if necessary.
1086 (mime-encode-region start (point-max) encoding)
1090 (mime-flag-region (point-min) (1- (point-max)) ?\^M)
1091 (goto-char (point-max)))
1093 ;; Define encoding even if it is 7bit.
1094 (if (stringp encoding)
1096 (goto-char tagend) ;Make sure which line the tag is on.
1097 (mime-editor/define-encoding encoding)))
1101 ;; Commands work on a current message flagment.
1103 (defun mime-editor/goto-tag ()
1104 "Search for the beginning of the tagged MIME message."
1105 (let ((current (point)) multipart)
1106 (if (looking-at mime-editor/tag-regexp)
1108 ;; At first, go to the end.
1109 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1110 (goto-char (match-beginning 0)) ;For multiline tag
1115 (goto-char (point-max))
1117 ;; Then search for the beginning.
1118 (re-search-backward mime-editor/end-tag-regexp nil t)
1120 (or (looking-at mime-editor/beginning-tag-regexp)
1121 ;; Restore previous point.
1128 (defun mime-editor/content-beginning ()
1129 "Return the point of the beginning of content."
1131 (let ((beg (save-excursion
1132 (beginning-of-line) (point))))
1133 (if (mime-editor/goto-tag)
1134 (let ((top (point)))
1135 (goto-char (match-end 0))
1136 (if (and (= beg top)
1137 (= (following-char) ?\^M))
1141 ;; Default text/plain tag.
1142 (goto-char (point-min))
1144 (concat "\n" (regexp-quote mail-header-separator)
1145 (if mime-ignore-preceding-spaces
1146 "[ \t\n]*\n" "\n")) nil 'move)
1150 (defun mime-editor/content-end ()
1151 "Return the point of the end of content."
1153 (let ((beg (save-excursion
1154 (beginning-of-line) (point))))
1155 (if (mime-editor/goto-tag)
1156 (let ((top (point)))
1157 (goto-char (match-end 0))
1158 (if (and (= beg top) ;Must be on the same line.
1159 (= (following-char) ?\^M))
1163 ;; Move to the end of this text.
1164 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1165 ;; Don't forget a multiline tag.
1166 (goto-char (match-beginning 0)))
1169 ;; Assume the message begins with text/plain.
1170 (goto-char (mime-editor/content-beginning))
1171 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1172 ;; Don't forget a multiline tag.
1173 (goto-char (match-beginning 0)))
1177 (defun mime-editor/define-charset (charset)
1178 "Set charset of current tag to CHARSET."
1180 (if (mime-editor/goto-tag)
1181 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1182 (delete-region (match-beginning 0) (match-end 0))
1184 (mime-create-tag (mime-set-parameter
1185 (mime-editor/get-contype tag) "charset" charset)
1186 (mime-editor/get-encoding tag))))
1189 (defun mime-editor/define-encoding (encoding)
1190 "Set encoding of current tag to ENCODING."
1192 (if (mime-editor/goto-tag)
1193 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1194 (delete-region (match-beginning 0) (match-end 0))
1195 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1198 (defun mime-editor/choose-charset ()
1199 "Choose charset of a text following current point."
1200 (mime/find-charset-region (point) (mime-editor/content-end))
1203 (defun mime-make-text-tag (&optional subtype)
1204 "Make a tag for a text after current point.
1205 Subtype of text type can be specified by an optional argument SUBTYPE.
1206 Otherwise, it is obtained from mime-content-types."
1207 (let* ((pritype "text")
1208 (subtype (or subtype
1209 (car (car (cdr (assoc pritype mime-content-types)))))))
1210 ;; Charset should be defined later.
1211 (mime-make-tag pritype subtype)))
1214 ;; Tag handling functions
1216 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1217 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1218 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1222 (defun mime-create-tag (contype &optional encoding)
1223 "Make a tag with CONTENT-TYPE and optional ENCODING."
1224 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1227 (defun mime-editor/get-contype (tag)
1228 "Return Content-Type (including parameters) of TAG."
1230 (or (string-match mime-editor/single-part-tag-regexp tag)
1231 (string-match mime-editor/multipart-beginning-regexp tag)
1232 (string-match mime-editor/multipart-end-regexp tag)
1234 (substring tag (match-beginning 1) (match-end 1))
1237 (defun mime-editor/get-encoding (tag)
1238 "Return encoding of TAG."
1240 (string-match mime-editor/single-part-tag-regexp tag)
1242 (not (= (match-beginning 3) (match-end 3)))
1243 (substring tag (match-beginning 3) (match-end 3))))
1245 (defun mime-get-parameter (contype parameter)
1246 "For given CONTYPE return value for PARAMETER.
1247 Nil if no such parameter."
1251 (regexp-quote parameter)
1252 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1254 (substring contype (match-beginning 1) (match-end 1))
1255 nil ;No such parameter
1258 (defun mime-set-parameter (contype parameter value)
1259 "For given CONTYPE set PARAMETER to VALUE."
1263 (regexp-quote parameter)
1264 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1267 (concat (substring contype 0 (match-beginning 1))
1269 (substring contype (match-end 1)))
1270 (concat contype "; " parameter "=" value)))
1272 (defun mime-strip-parameters (contype)
1273 "Return primary content-type and subtype without parameters for CONTYPE."
1274 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1275 (substring contype (match-beginning 1) (match-end 1)) nil))
1277 (defun mime-test-content-type (contype type &optional subtype)
1278 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1279 (and (stringp contype)
1282 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1283 (downcase contype))))
1288 (defun mime-find-file-type (file)
1289 "Guess Content-Type, subtype, and parameters from FILE."
1291 (guesses mime-file-types))
1292 (while (and (not guess) guesses)
1293 (if (string-match (car (car guesses)) file)
1294 (setq guess (cdr (car guesses))))
1295 (setq guesses (cdr guesses)))
1299 (defun mime-prompt-for-type ()
1300 "Ask for Content-type."
1302 ;; Repeat until primary content type is specified.
1303 (while (string-equal type "")
1305 (completing-read "What content type: "
1308 'require-match ;Type must be specified.
1311 (if (string-equal type "")
1313 (message "Content type is required.")
1321 (defun mime-prompt-for-subtype (pritype)
1322 "Ask for Content-type subtype of Content-Type PRITYPE."
1323 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1328 "What content subtype: (default " default ") ")
1329 "What content subtype: ")
1330 (cdr (assoc pritype mime-content-types))
1332 'require-match ;Subtype must be specified.
1335 (if (string-equal answer "") default answer)))
1337 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1338 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1339 Optional DELIMITER specifies parameter delimiter (';' by default)."
1340 (let* ((delimiter (or delimiter "; "))
1345 (mime-prompt-for-parameters-1
1347 (cdr (assoc pritype mime-content-types))))))
1350 (if (and (stringp parameters)
1351 (not (string-equal parameters "")))
1352 (concat delimiter parameters)
1353 "" ;"" if no parameters
1356 (defun mime-prompt-for-parameters-1 (optlist)
1357 (apply (function append)
1358 (mapcar (function mime-prompt-for-parameter) optlist)))
1360 (defun mime-prompt-for-parameter (parameter)
1362 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1363 (let* ((prompt (car parameter))
1364 (choices (mapcar (function
1366 (if (consp e) e (list e))))
1368 (default (car (car choices)))
1374 (concat "What " prompt
1376 (if (string-equal default "") "\"\"" default)
1378 choices nil nil ""))
1379 ;; If nothing is selected, use default.
1380 (if (string-equal answer "")
1381 (setq answer default)))
1383 (read-string (concat "What " prompt ": "))))
1384 (cons (if (and answer
1385 (not (string-equal answer "")))
1387 ;; Note: control characters ignored!
1388 (if (string-match mime-tspecials-regexp answer)
1389 (concat "\"" answer "\"") answer)))
1390 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1393 (defun mime-flag-region (from to flag)
1394 "Hides or shows lines from FROM to TO, according to FLAG.
1395 If FLAG is `\\n' (newline character) then text is shown,
1396 while if FLAG is `\\^M' (control-M) the text is hidden."
1397 (let ((buffer-read-only nil) ;Okay even if write protected.
1398 (modp (buffer-modified-p)))
1400 (subst-char-in-region from to
1401 (if (= flag ?\n) ?\^M ?\n)
1403 (set-buffer-modified-p modp))))
1406 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1409 (defvar mime-editor/translate-buffer-hook
1410 '(mime-editor/pgp-enclose-buffer
1411 mime/encode-message-header
1412 mime-editor/translate-body))
1414 (defun mime-editor/translate-buffer ()
1415 "Encode the tagged MIME message in current buffer in MIME compliant message."
1417 (if (catch 'mime-editor/error
1419 (run-hooks 'mime-editor/translate-buffer-hook)
1423 (error "Translation error!")
1426 (defun mime-editor/find-inmost ()
1427 (goto-char (point-min))
1428 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1429 (let ((bb (match-beginning 0))
1431 (type (buffer-substring (match-beginning 1)(match-end 1)))
1433 (setq end-exp (format "^--}-<<%s>>\n" type))
1435 (if (re-search-forward end-exp nil t)
1437 (setq eb (match-beginning 0))
1438 (setq ee (match-end 0))
1440 (setq eb (point-max))
1441 (setq ee (point-max))
1443 (narrow-to-region be eb)
1445 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1447 (narrow-to-region (match-beginning 0)(point-max))
1448 (mime-editor/find-inmost)
1451 ;;(delete-region eb ee)
1452 (list type bb be eb)
1455 (defun mime-editor/process-multipart-1 (boundary)
1456 (let ((ret (mime-editor/find-inmost)))
1458 (let ((type (car ret))
1459 (bb (nth 1 ret))(be (nth 2 ret))
1462 (narrow-to-region bb eb)
1463 (delete-region bb be)
1464 (setq bb (point-min))
1465 (setq eb (point-max))
1468 (if (looking-at mime-editor/multipart-end-regexp)
1469 (let ((beg (match-beginning 0))
1472 (delete-region beg end)
1473 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
1475 (insert (concat (mime-make-text-tag) "\n"))
1477 (cond ((string= type "signed")
1478 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1479 (mime-editor/sign-pgp-elkins bb eb boundary)
1481 ((eq mime-editor/signing-type 'pgp-kazu)
1482 (mime-editor/sign-pgp-kazu bb eb boundary)
1485 ((string= type "encrypted")
1486 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1487 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1489 ((eq mime-editor/encrypting-type 'pgp-kazu)
1490 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1494 (nth 2 (mime-editor/translate-region bb eb
1498 (format "--[[multipart/%s;
1499 boundary=\"%s\"][7bit]]\n"
1505 (autoload 'mc-pgp-lookup-key "mc-pgp")
1506 (autoload 'mc-pgp-sign-region "mc-pgp")
1507 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1509 (defun tm:mc-pgp-generic-parser (result)
1510 (let ((ret (mc-pgp-generic-parser result)))
1512 (vector (car ret)(cdr ret))
1515 (defun tm:mc-process-region
1516 (beg end passwd program args parser &optional buffer boundary)
1517 (let ((obuf (current-buffer))
1518 (process-connection-type nil)
1519 mybuf result rgn proc)
1522 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1526 (buffer-disable-undo mybuf)
1528 (apply 'start-process "*PGP*" mybuf program args))
1531 (process-send-string proc (concat passwd "\n"))
1532 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1533 (process-send-region proc beg end)
1534 (process-send-eof proc)
1535 (while (eq 'run (process-status proc))
1536 (accept-process-output proc 5))
1537 (setq result (process-exit-status proc))
1538 ;; Hack to force a status_notify() in Emacs 19.29
1539 (delete-process proc)
1541 (goto-char (point-max))
1542 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1543 (delete-region (match-beginning 0) (match-end 0)))
1544 (goto-char (point-min))
1546 (while (search-forward "\r\n" nil t)
1547 (replace-match "\n"))
1548 ;; Hurm. FIXME; must get better result codes.
1549 (if (stringp result)
1550 (error "%s exited abnormally: '%s'" program result)
1551 (setq rgn (funcall parser result))
1552 ;; If the parser found something, migrate it
1558 (narrow-to-region beg end)
1560 (insert (format "--%s\n" boundary))
1561 (goto-char (point-max))
1562 (insert (format "\n--%s
1563 Content-Type: application/pgp-signature
1564 Content-Transfer-Encoding: 7bit
1567 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1568 (goto-char (point-max))
1569 (insert (format "\n--%s--\n" boundary))
1571 (delete-region beg end)
1573 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1576 (delete-region (car rgn) (cdr rgn)))))
1577 ;; Return nil on failure and exit code on success
1579 ;; Cleanup even on nonlocal exit
1580 (if (and proc (eq 'run (process-status proc)))
1581 (interrupt-process proc))
1583 (or buffer (null mybuf) (kill-buffer mybuf)))))
1585 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1586 (if (not (boundp 'mc-pgp-user-id))
1589 (let ((process-environment process-environment)
1590 (buffer (get-buffer-create mc-buffer-name))
1592 (parser (function mc-pgp-generic-parser))
1593 (pgp-path mc-pgp-path)
1595 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1599 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1600 (setenv "PGPPASSFD" "0")
1606 (list "+verbose=1" "+language=en"
1607 (format "+clearsig=%s" (if unclear "off" "on"))
1608 "+batchmode" "-u" (cdr key))))
1610 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1612 (message "Signing as %s ..." (car key))
1613 (if (tm:mc-process-region
1614 start end passwd pgp-path args parser buffer boundary)
1618 (goto-char (point-min))
1621 --[[multipart/signed; protocol=\"application/pgp-signature\";
1622 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1624 (message "Signing as %s ... Done." (car key))
1628 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1631 (narrow-to-region beg end)
1633 (mime-editor/translate-region beg end boundary))
1635 (encoding (nth 1 ret))
1637 (pgp-boundary (concat "pgp-sign-" boundary))
1640 (insert (format "Content-Type: %s\n" ctype))
1642 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1645 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1646 nil nil pgp-boundary)
1647 (throw 'mime-editor/error 'pgp-error)
1651 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1654 (let ((from (rfc822/get-field-body "From"))
1655 (to (rfc822/get-field-body "To"))
1656 (cc (rfc822/get-field-body "cc"))
1658 (narrow-to-region beg end)
1660 (mime-editor/translate-region beg end boundary))
1662 (encoding (nth 1 ret))
1664 (pgp-boundary (concat "pgp-" boundary))
1667 (if (and (stringp from)
1668 (not (string-equal from "")))
1669 (insert (format "From: %s\n" from))
1671 (if (and (stringp to)
1672 (not (string-equal to "")))
1674 (insert (format "To: %s\n" to))
1675 (setq recipients to)
1677 (if (and (stringp cc)
1678 (not (string-equal cc "")))
1680 (insert (format "cc: %s\n" cc))
1682 (setq recipients (concat recipients "," cc))
1683 (setq recipients cc)
1685 (insert (format "Content-Type: %s\n" ctype))
1687 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1691 (let ((mc-pgp-always-sign 'never))
1692 (mc-pgp-encrypt-region
1693 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1694 (point-min) (point-max) from nil)
1696 (throw 'mime-editor/error 'pgp-error)
1699 (insert (format "--[[multipart/encrypted;
1701 protocol=\"application/pgp-encrypted\"][7bit]]
1703 Content-Type: application/pgp-encrypted
1706 Content-Type: application/octet-stream
1707 Content-Transfer-Encoding: 7bit
1709 " pgp-boundary pgp-boundary pgp-boundary))
1710 (goto-char (point-max))
1711 (insert (format "\n--%s--\n" pgp-boundary))
1714 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1717 (narrow-to-region beg end)
1719 (mime-editor/translate-region beg end boundary))
1721 (encoding (nth 1 ret))
1725 (insert (format "Content-Type: %s\n" ctype))
1727 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1730 (or (let ((program-coding-system-alist
1731 (cons (cons (cons nil ".*pgp.*")
1732 (cons *noconv* *noconv*))
1733 program-coding-system-alist))
1735 (mc-pgp-sign-region beg (point-max))
1737 (throw 'mime-editor/error 'pgp-error)
1741 "--[[application/pgp; format=mime][7bit]]\n")
1745 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1747 (let ((from (rfc822/get-field-body "From"))
1748 (to (rfc822/get-field-body "To"))
1749 (cc (rfc822/get-field-body "cc"))
1752 (narrow-to-region beg end)
1754 (mime-editor/translate-region beg end boundary))
1756 (encoding (nth 1 ret))
1760 (if (and (stringp from)
1761 (not (string-equal from "")))
1762 (insert (format "From: %s\n" from))
1764 (if (and (stringp to)
1765 (not (string-equal to "")))
1767 (insert (format "To: %s\n" to))
1768 (setq recipients to)
1770 (if (and (stringp cc)
1771 (not (string-equal cc "")))
1773 (insert (format "cc: %s\n" cc))
1775 (setq recipients (concat recipients "," cc))
1776 (setq recipients cc)
1778 (insert (format "Content-Type: %s\n" ctype))
1780 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1783 (or (let ((program-coding-system-alist
1784 (cons (cons (cons nil ".*pgp.*")
1785 (cons *noconv* *noconv*))
1786 program-coding-system-alist))
1788 (mc-pgp-encrypt-region
1789 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1792 (throw 'mime-editor/error 'pgp-error)
1796 "--[[application/pgp; format=mime][7bit]]\n")
1800 (defun mime-editor/translate-body ()
1801 "Encode the tagged MIME body in current buffer in MIME compliant message."
1805 (concat mime-multipart-boundary "_"
1806 (replace-space-with-underline (current-time-string))
1810 (while (mime-editor/process-multipart-1
1811 (format "%s-%d" boundary i))
1815 ;; We are interested in message body.
1818 (goto-char (point-min))
1820 (concat "\n" (regexp-quote mail-header-separator)
1821 (if mime-ignore-preceding-spaces
1822 "[ \t\n]*\n" "\n")) nil 'move)
1826 (goto-char (point-max))
1827 (and mime-ignore-trailing-spaces
1828 (re-search-backward "[^ \t\n]\n" beg t)
1831 (setq ret (mime-editor/translate-region
1833 (format "%s-%d" boundary i)))
1835 (let ((contype (car ret)) ;Content-Type
1836 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1838 ;; Make primary MIME headers.
1839 (or (mail-position-on-field "Mime-Version")
1840 (insert mime-editor/mime-version-value))
1841 ;; Remove old Content-Type and other fields.
1843 (goto-char (point-min))
1844 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1845 (narrow-to-region (point-min) (point))
1846 (goto-char (point-min))
1847 (mime-delete-field "Content-Type")
1848 (mime-delete-field "Content-Transfer-Encoding"))
1849 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1850 (mail-position-on-field "Content-Type")
1854 (mail-position-on-field "Content-Transfer-Encoding")
1858 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1861 (concat mime-multipart-boundary "_"
1862 (replace-space-with-underline (current-time-string))))
1866 (narrow-to-region beg end)
1867 (let ((tag nil) ;MIME tag
1868 (contype nil) ;Content-Type
1869 (encoding nil) ;Content-Transfer-Encoding
1870 (nparts 0)) ;Number of body parts
1871 ;; Normalize the body part by inserting appropriate message
1872 ;; tags for every message contents.
1873 (mime-editor/normalize-body)
1874 ;; Counting the number of Content-Type.
1875 (goto-char (point-min))
1876 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1877 (setq nparts (1+ nparts)))
1878 ;; Begin translation.
1879 (cond ((and (<= nparts 1)(not multipart))
1880 ;; It's a singular message.
1881 (goto-char (point-min))
1882 (while (re-search-forward
1883 mime-editor/single-part-tag-regexp nil t)
1885 (buffer-substring (match-beginning 0) (match-end 0)))
1886 (delete-region (match-beginning 0) (1+ (match-end 0)))
1887 (setq contype (mime-editor/get-contype tag))
1888 (setq encoding (mime-editor/get-encoding tag))
1891 ;; It's a multipart message.
1892 (goto-char (point-min))
1893 (while (re-search-forward
1894 mime-editor/single-part-tag-regexp nil t)
1896 (buffer-substring (match-beginning 0) (match-end 0)))
1897 (delete-region (match-beginning 0) (match-end 0))
1898 (setq contype (mime-editor/get-contype tag))
1899 (setq encoding (mime-editor/get-encoding tag))
1900 (insert "--" boundary "\n")
1901 (insert "Content-Type: " contype "\n")
1903 (insert "Content-Transfer-Encoding: " encoding "\n"))
1905 ;; Define Content-Type as "multipart/mixed".
1907 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1908 ;; Content-Transfer-Encoding must be "7bit".
1909 ;; The following encoding can be `nil', but is
1910 ;; specified as is since there is no way that a user
1912 (setq encoding "7bit")
1913 ;; Insert the trailer.
1914 (goto-char (point-max))
1916 (insert "--" boundary "--\n")
1917 (insert "\n--" boundary "--\n")
1919 (list contype encoding boundary nparts)
1922 (defun mime-editor/normalize-body ()
1923 "Normalize the body part by inserting appropriate message tags."
1924 ;; Insert the first MIME tags if necessary.
1925 (goto-char (point-min))
1926 (if (not (looking-at mime-editor/single-part-tag-regexp))
1927 (insert (mime-make-text-tag) "\n"))
1928 ;; Check each tag, and add new tag or correct it if necessary.
1929 (goto-char (point-min))
1930 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1931 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1932 (contype (mime-editor/get-contype tag))
1933 (charset (mime-get-parameter contype "charset"))
1934 (encoding (mime-editor/get-encoding tag)))
1935 ;; Remove extra whitespaces after the tag.
1936 (if (looking-at "[ \t]+$")
1937 (delete-region (match-beginning 0) (match-end 0)))
1939 ((= (following-char) ?\^M)
1940 ;; It must be image, audio or video.
1942 (end (mime-editor/content-end)))
1943 ;; Insert explicit MIME tags after hidden messages.
1945 (if (and (not (eobp))
1946 (not (looking-at mime-editor/single-part-tag-regexp)))
1948 (insert (mime-make-text-tag) "\n")
1949 (forward-line -1) ;Process it again as text.
1951 ;; Show a hidden message. The point is not altered
1952 ;; after the conversion.
1953 (mime-flag-region beg end ?\n)
1955 ((mime-test-content-type contype "message")
1956 ;; Content-type "message" should be sent as is.
1959 ((mime-test-content-type contype "text")
1960 ;; Define charset for text if necessary.
1961 (setq charset (or charset (mime-editor/choose-charset)))
1962 (mime-editor/define-charset charset)
1963 (cond ((string-equal contype "text/x-rot13-47")
1967 (goto-char (mime-editor/content-end))
1970 ((string-equal contype "text/enriched")
1975 (end (mime-editor/content-end))
1977 (enriched-encode beg end)
1979 (if (search-forward "\n\n")
1980 (delete-region beg (match-end 0))
1983 ;; Point is now on current tag.
1984 ;; Define encoding and encode text if necessary.
1985 (or encoding ;Encoding is not specified.
1989 mime-editor/charset-default-encoding-alist)
1991 (beg (mime-editor/content-beginning))
1993 (mime-charset-encode-region beg (mime-editor/content-end)
1995 (mime-encode-region beg (mime-editor/content-end) encoding)
1996 (mime-editor/define-encoding encoding)
2000 ((null encoding) ;Encoding is not specified.
2001 ;; Application, image, audio, video, and any other
2002 ;; unknown content-type without encoding should be
2004 (let* ((encoding "base64") ;Encode in BASE64 by default.
2005 (beg (mime-editor/content-beginning))
2006 (end (mime-editor/content-end))
2007 (body (buffer-substring beg end))
2009 (mime-encode-region beg end encoding)
2010 (mime-editor/define-encoding encoding))
2016 (defun mime-delete-field (field)
2017 "Delete header FIELD."
2018 (let ((regexp (format "^%s:[ \t]*" field)))
2019 (goto-char (point-min))
2020 (while (re-search-forward regexp nil t)
2021 (delete-region (match-beginning 0)
2022 (progn (forward-line 1) (point)))
2027 ;;; Platform dependent functions
2030 ;; Sun implementations
2032 (defun mime-voice-recorder-for-sun ()
2033 "Record voice in a buffer using Sun audio device, and return the buffer.
2034 If the environment variable AUDIOHOST is defined, its value is used as
2035 a recording host instead of local host."
2036 (let ((buffer (get-buffer-create " *MIME audio*"))
2037 (host (getenv "AUDIOHOST")))
2038 (message "Start the recording on %s. Type C-g to finish the recording..."
2039 (or host (system-name)))
2043 (condition-case errorcode
2044 (let ((selective-display nil) ;Disable ^M to nl translation.
2046 (kanji-flag nil)) ;NEmacs
2047 ;; If AUDIOHOST is defined, use the value as recording host.
2048 (cond ((not (null host))
2049 ;; Disable automatic conversion of coding system if Mule.
2050 (if (featurep 'mule)
2051 (define-program-coding-system nil "rsh" *noconv*))
2061 ;; Disable automatic conversion of coding system if Mule.
2062 (if (featurep 'mule)
2063 (define-program-coding-system nil "cat" *noconv*))
2069 (quit (message "Type C-g to finish recording... done.")
2070 buffer ;Return the buffer
2074 ;;; @ Other useful commands.
2077 ;; Message forwarding commands as content-type "message/rfc822".
2079 (defun mime-editor/insert-message (&optional message)
2081 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2082 (if (and inserter (fboundp inserter))
2084 (mime-editor/insert-tag "message" "rfc822")
2085 (funcall inserter message)
2087 (message "Sorry, I don't have message inserter for your MUA.")
2090 (defun mime-editor/insert-mail (&optional message)
2092 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2093 (if (and inserter (fboundp inserter))
2095 (mime-editor/insert-tag "message" "rfc822")
2096 (funcall inserter message)
2098 (message "Sorry, I don't have mail inserter for your MUA.")
2101 (defun mime-editor/inserted-message-filter ()
2104 (let ((header-start (point))
2105 (case-fold-search t)
2108 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2109 (if (re-search-forward "^$" (mark t))
2110 (narrow-to-region header-start (match-beginning 0))
2112 (goto-char header-start)
2113 (while (and (re-search-forward
2114 mime-editor/yank-ignored-field-regexp nil t)
2115 (setq beg (match-beginning 0))
2116 (setq end (1+ (rfc822/field-end)))
2118 (delete-region beg end)
2123 ;;; @ multipart enclosure
2126 (defun mime-editor/enclose-region (type beg end)
2129 (let ((current (point))
2132 (if (mime-editor/goto-tag)
2133 (or (eq current (match-beginning 0))
2134 (setq exist-prev-tag t)
2137 (narrow-to-region beg end)
2142 (insert (format "--<<%s>>-{\n" type))
2143 (goto-char (point-max))
2144 (insert (format "\n--}-<<%s>>\n" type))
2145 (goto-char (point-max))
2147 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
2149 (insert (mime-make-text-tag) "\n")
2153 (defun mime-editor/enclose-mixed-region (beg end)
2155 (mime-editor/enclose-region "mixed" beg end)
2158 (defun mime-editor/enclose-parallel-region (beg end)
2160 (mime-editor/enclose-region "parallel" beg end)
2163 (defun mime-editor/enclose-digest-region (beg end)
2165 (mime-editor/enclose-region "digest" beg end)
2168 (defun mime-editor/enclose-alternative-region (beg end)
2170 (mime-editor/enclose-region "alternative" beg end)
2173 (defun mime-editor/enclose-signed-region (beg end)
2175 (if mime-editor/signing-type
2176 (mime-editor/enclose-region "signed" beg end)
2177 (message "Please specify signing type.")
2180 (defun mime-editor/enclose-encrypted-region (beg end)
2182 (if mime-editor/signing-type
2183 (mime-editor/enclose-region "encrypted" beg end)
2184 (message "Please specify encrypting type.")
2187 (defun mime-editor/insert-key (&optional arg)
2188 "Insert a pgp public key."
2190 (mime-editor/insert-tag "application" "pgp-keys")
2191 (mime-editor/define-encoding "7bit")
2192 (mc-insert-public-key)
2199 (defun mime-editor/set-split (arg)
2202 (y-or-n-p "Do you want to enable split?")
2204 (setq mime-editor/split-message arg)
2206 (message "This message is enabled to split.")
2207 (message "This message is not enabled to split.")
2210 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2211 "Toggle transfer-level is 7bit or 8bit through.
2213 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2215 (if (numberp transfer-level)
2216 (setq mime-editor/transfer-level transfer-level)
2217 (if (< mime-editor/transfer-level 8)
2218 (setq mime-editor/transfer-level 8)
2219 (setq mime-editor/transfer-level 7)
2221 (setq mime-editor/charset-default-encoding-alist
2222 (mime/make-charset-default-encoding-alist
2223 mime-editor/transfer-level))
2224 (message (format "Current transfer-level is %d bit"
2225 mime-editor/transfer-level))
2226 (setq mime-editor/transfer-level-string
2227 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2228 (force-mode-line-update)
2235 (defun mime-editor/set-sign (arg)
2238 (y-or-n-p "Do you want to sign?")
2241 (if mime-editor/signing-type
2243 (setq mime-editor/pgp-processing 'sign)
2244 (message "This message will be signed.")
2246 (message "Please specify signing type.")
2248 (if (eq mime-editor/pgp-processing 'sign)
2249 (setq mime-editor/pgp-processing nil)
2251 (message "This message will not be signed.")
2254 (defun mime-editor/set-encrypt (arg)
2257 (y-or-n-p "Do you want to encrypt?")
2260 (if mime-editor/encrypting-type
2262 (setq mime-editor/pgp-processing 'encrypt)
2263 (message "This message will be encrypt.")
2265 (message "Please specify encrypting type.")
2267 (if (eq mime-editor/pgp-processing 'encrypt)
2268 (setq mime-editor/pgp-processing nil)
2270 (message "This message will not be encrypt.")
2273 (defvar mime-editor/pgp-processing nil)
2274 (make-variable-buffer-local 'mime-editor/pgp-processing)
2276 (defun mime-editor/pgp-enclose-buffer ()
2277 (let ((beg (save-excursion
2278 (goto-char (point-min))
2279 (if (search-forward (concat "\n" mail-header-separator "\n"))
2285 (cond ((eq mime-editor/pgp-processing 'sign)
2286 (mime-editor/enclose-signed-region beg end)
2288 ((eq mime-editor/pgp-processing 'encrypt)
2289 (mime-editor/enclose-encrypted-region beg end)
2297 (defun mime-editor/insert-partial-header
2298 (fields subject id number total separator)
2300 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2301 (insert (format "Mime-Version: 1.0 (split by tm-edit %s)\n"
2302 mime-editor/version))
2304 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2305 id number total separator))
2308 (defun mime-editor/split-and-send
2309 (&optional cmd lines mime-editor/message-max-length)
2313 (count-lines (point-min) (point-max)))
2315 (or mime-editor/message-max-length
2316 (setq mime-editor/message-max-length
2317 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2318 mime-editor/message-default-max-length))
2320 (let* ((mime-editor/draft-file-name
2321 (or (buffer-file-name)
2323 (expand-file-name "tm-draft" mime/tmp-dir))))
2324 (separator mail-header-separator)
2326 (eval (cdr (assq major-mode mime-editor/window-config-alist))))
2328 (replace-space-with-underline (current-time-string))
2329 "@" (system-name) "\"")))
2330 (run-hooks 'mime-editor/before-split-hook)
2331 (let* ((header (rfc822/get-header-string-except
2332 mime-editor/split-ignored-field-regexp separator))
2333 (subject (mail-fetch-field "subject"))
2334 (total (+ (/ lines mime-editor/message-max-length)
2335 (if (> (mod lines mime-editor/message-max-length) 0)
2337 (the-buf (current-buffer))
2338 (buf (get-buffer "*tmp-send*"))
2343 mime-editor/split-message-sender-alist))
2346 mime-editor/message-default-sender-alist))
2349 (goto-char (point-min))
2350 (if (re-search-forward (concat "^" (regexp-quote separator) "$")
2356 (switch-to-buffer buf)
2358 (switch-to-buffer the-buf)
2360 (setq buf (get-buffer-create "*tmp-send*"))
2362 (switch-to-buffer buf)
2363 (make-local-variable 'mail-header-separator)
2364 (setq mail-header-separator separator)
2365 (switch-to-buffer the-buf)
2366 (goto-char (point-min))
2367 (re-search-forward "^$" nil t)
2368 (let ((mime-editor/partial-number 1))
2369 (setq data (buffer-substring
2372 (goto-line mime-editor/message-max-length)
2375 (delete-region (point-min)(point))
2376 (switch-to-buffer buf)
2377 (mime-editor/insert-partial-header
2378 header subject id mime-editor/partial-number total separator)
2382 (goto-char (point-min))
2383 (search-forward (concat "\n" mail-header-separator "\n"))
2386 (if (re-search-forward "^$" nil t)
2390 (goto-char (point-min))
2391 (while (re-search-forward
2392 mime-editor/split-blind-field-regexp nil t)
2393 (delete-region (match-beginning 0)
2394 (let ((e (rfc822/field-end)))
2395 (if (< e (point-max))
2401 (message (format "Sending %d/%d..."
2402 mime-editor/partial-number total))
2403 (call-interactively command)
2404 (message (format "Sending %d/%d... done"
2405 mime-editor/partial-number total))
2408 (switch-to-buffer the-buf)
2409 (setq mime-editor/partial-number 2)
2410 (while (< mime-editor/partial-number total)
2411 (setq data (buffer-substring
2414 (goto-line mime-editor/message-max-length)
2417 (delete-region (point-min)(point))
2418 (switch-to-buffer buf)
2419 (mime-editor/insert-partial-header
2420 header subject id mime-editor/partial-number total separator)
2423 (message (format "Sending %d/%d..."
2424 mime-editor/partial-number total))
2425 (call-interactively command)
2426 (message (format "Sending %d/%d... done"
2427 mime-editor/partial-number total))
2430 (switch-to-buffer the-buf)
2431 (setq mime-editor/partial-number
2432 (1+ mime-editor/partial-number))
2434 (goto-char (point-min))
2435 (mime-editor/insert-partial-header
2436 header subject id mime-editor/partial-number total separator)
2437 (message (format "Sending %d/%d..."
2438 mime-editor/partial-number total))
2441 (defun mime-editor/maybe-split-and-send (&optional cmd)
2443 (run-hooks 'mime-editor/before-send-hook)
2444 (let ((mime-editor/message-max-length
2445 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2446 mime-editor/message-default-max-length))
2447 (lines (count-lines (point-min) (point-max)))
2449 (if (and (> lines mime-editor/message-max-length)
2450 mime-editor/split-message)
2451 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2455 ;;; @ preview message
2458 (defun mime-editor/preview-message ()
2459 "preview editing MIME message. [tm-edit.el]"
2461 (let* ((str (buffer-string))
2462 (separator mail-header-separator)
2463 (the-buf (current-buffer))
2464 (buf-name (buffer-name))
2465 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2466 (buf (get-buffer temp-buf-name))
2470 (switch-to-buffer buf)
2473 (setq buf (get-buffer-create temp-buf-name))
2474 (switch-to-buffer buf)
2477 (setq major-mode 'mime/temporary-message-mode)
2478 (make-local-variable 'mail-header-separator)
2479 (setq mail-header-separator separator)
2480 (make-local-variable 'mime/editing-buffer)
2481 (setq mime/editing-buffer the-buf)
2483 (run-hooks 'mime-editor/translate-hook)
2484 (mime-editor/translate-buffer)
2485 (goto-char (point-min))
2486 (if (re-search-forward
2487 (concat "^" (regexp-quote separator) "$"))
2493 (defun mime-editor/quitting-method ()
2494 (let ((temp mime::preview/article-buffer)
2496 (mime-viewer/kill-buffer)
2498 (setq buf mime/editing-buffer)
2500 (switch-to-buffer buf)
2503 (set-alist 'mime-viewer/quitting-method-alist
2504 'mime/temporary-message-mode
2505 (function mime-editor/quitting-method)
2511 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2512 ;; Mon, 10 Apr 1995 20:03:07 +0900
2514 (defvar mime-editor/draft-header-separator-alist
2515 '((news-reply-mode . mail-header-separator)
2516 (mh-letter-mode . mail-header-separator)
2519 (defvar mime::article/draft-header-separator nil)
2521 (defun mime-editor/draft-preview ()
2523 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2524 (or (stringp sep) (setq sep (eval sep)))
2525 (make-variable-buffer-local 'mime::article/draft-header-separator)
2526 (goto-char (point-min))
2528 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2529 (setq mime::article/draft-header-separator
2530 (buffer-substring (match-beginning 0) (match-end 0)))
2532 (mime/viewer-mode (current-buffer))
2533 (pop-to-buffer (current-buffer))
2536 (defun mime-viewer::quitting-method/draft-preview ()
2537 (let ((mother mime::preview/mother-buffer))
2539 (switch-to-buffer mother)
2540 (goto-char (point-min))
2544 (regexp-quote mime::article/draft-header-separator)
2548 (insert mime::article/draft-header-separator)
2549 (set-buffer-modified-p (buffer-modified-p))
2551 (mime-viewer/kill-buffer)
2552 (pop-to-buffer mother)
2555 (set-alist 'mime-viewer/quitting-method-alist
2557 (function mime-viewer::quitting-method/draft-preview)
2560 (set-alist 'mime-viewer/quitting-method-alist
2562 (function mime-viewer::quitting-method/draft-preview)
2569 (defun mime-editor::edit-again (code-conversion)
2571 (goto-char (point-min))
2572 (let ((ctl (mime/Content-Type)))
2574 (let ((ctype (car ctl))
2577 (if (string-match "/" ctype)
2579 (setq type (substring ctype 0 (match-beginning 0)))
2580 (setq stype (substring ctype (match-end 0)))
2585 ((string-equal type "multipart")
2586 (let ((boundary (assoc-value "boundary" params)))
2587 (re-search-forward (concat "\n--" boundary) nil t)
2588 (let ((bb (match-beginning 0)) eb tag)
2589 (setq tag (format "\n--<<%s>>-{" stype))
2592 (setq bb (+ bb (length tag)))
2593 (re-search-forward (concat "\n--" boundary "--") nil t)
2594 (setq eb (match-beginning 0))
2595 (replace-match (format "\n--}-<<%s>>" stype))
2597 (narrow-to-region bb eb)
2598 (goto-char (point-min))
2599 (while (re-search-forward
2600 (concat "\n--" boundary "\n") nil t)
2601 (let ((beg (match-beginning 0))
2603 (delete-region beg (match-end 0))
2605 (if (re-search-forward
2606 (concat "\n--" boundary) nil t)
2607 (setq end (match-beginning 0))
2608 (setq end (point-max))
2611 (narrow-to-region beg end)
2612 (mime-editor::edit-again code-conversion)
2613 (goto-char (point-max))
2616 (goto-char (point-min))
2617 (or (= (point-min) 1)
2618 (delete-region (point-min)
2619 (if (re-search-forward "^$" nil t)
2627 (mapconcat (function
2629 (if (string-equal (car attr)
2632 (setq charset (cdr attr))
2634 (concat ";" (car attr)
2642 (if (re-search-forward
2643 "Content-Transfer-Encoding:" nil t)
2644 (let ((beg (match-beginning 0))
2645 (hbeg (match-end 0))
2646 (end (rfc822/field-end)))
2648 (eliminate-top-spaces
2649 (rfc822/unfolding-string
2650 (buffer-substring hbeg end))))
2651 (if (or charset (string-equal type "text"))
2653 (delete-region beg (1+ end))
2654 (goto-char (point-min))
2655 (if (search-forward "\n\n" nil t)
2658 (match-end 0)(point-max) encoding)
2662 (if (or code-conversion encoded)
2664 (mime-charset-decode-region (point-min)(point-max)
2666 (character-decode-region (point-min)(point-max)
2667 mime/default-coding-system)
2670 (if (re-search-forward "^$" nil t)
2674 (if (= (point-min) 1)
2681 (concat type "/" stype pstr) encoding)
2684 (delete-region (point-min) he)
2688 (concat type "/" stype pstr) encoding)
2693 (character-decode-region (point-min) (point-max)
2694 mime/default-coding-system)
2698 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2700 (mime-editor::edit-again code-conversion)
2701 (goto-char (point-min))
2703 (narrow-to-region (point-min)
2704 (if (re-search-forward "^$" nil t)
2708 (goto-char (point-min))
2709 (while (re-search-forward
2710 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2711 (delete-region (match-beginning 0) (1+ (rfc822/field-end)))
2714 (and (re-search-forward "^$")
2715 (replace-match mail-header-separator)
2727 (run-hooks 'tm-edit-load-hook)
2729 ;;; tm-edit.el ends here