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.67 $
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.67 1996/06/09 07:03:58 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
411 . (lambda (&optional arg)
413 (write-region (point-min) (point-max)
414 mime-editor/draft-file-name nil 'no-message)
416 (pop-to-buffer "MH mail delivery")
418 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
420 mh-send-args mime-editor/draft-file-name)
421 (goto-char (point-max)) ; show the interesting part
425 (apply 'mh-exec-cmd-quiet t mh-send-prog
427 (list "-nopush" "-nodraftfolder"
428 "-noverbose" "-nowatch"
429 mh-send-args mime-editor/draft-file-name)))))
433 (defvar mime-editor/news-reply-mode-server-running nil)
439 (defvar mime-editor/signing-type nil
440 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
442 (defvar mime-editor/encrypting-type nil
443 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
445 (if (or mime-editor/signing-type mime-editor/encrypting-type)
453 (defconst mime-editor/single-part-tag-regexp
454 "^--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
455 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
457 (defconst mime-editor/multipart-beginning-regexp "^--<<\\([^<>]+\\)>>-{\n")
459 (defconst mime-editor/multipart-end-regexp "^--}-<<\\([^<>]+\\)>>\n")
461 (defconst mime-editor/beginning-tag-regexp
462 (regexp-or mime-editor/single-part-tag-regexp
463 mime-editor/multipart-beginning-regexp))
465 (defconst mime-editor/end-tag-regexp
466 (regexp-or mime-editor/single-part-tag-regexp
467 mime-editor/multipart-end-regexp))
469 (defconst mime-editor/tag-regexp
470 (regexp-or mime-editor/single-part-tag-regexp
471 mime-editor/multipart-beginning-regexp
472 mime-editor/multipart-end-regexp))
474 (defvar mime-tag-format "--[[%s]]"
475 "*Control-string making a MIME tag.")
477 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
478 "*Control-string making a MIME tag with encoding.")
480 ;;; @@ multipart boundary
483 (defvar mime-multipart-boundary "Multipart"
484 "*Boundary of a multipart message.")
487 ;;; @@ buffer local variables
490 (defvar mime/editor-mode-old-local-map nil)
491 (defvar mime/editor-mode-old-selective-display nil)
492 (defvar mime/editing-buffer nil)
498 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
499 "*Specify MIME tspecials.
500 Tspecials means any character that matches with it in header must be quoted.")
502 (defconst mime-editor/mime-version-value
503 (format "1.0 (generated by tm-edit %s)" mime-editor/version)
504 "MIME version number.")
506 (defconst mime-editor/mime-map (make-sparse-keymap)
507 "Keymap for MIME commands.")
510 ;;; @ keymap and menu
513 (defvar mime/editor-mode-flag nil)
514 (make-variable-buffer-local 'mime/editor-mode-flag)
516 (set-alist 'minor-mode-alist
517 'mime/editor-mode-flag
518 '((" MIME-Edit " mime-editor/transfer-level-string)))
520 (defun mime-editor/define-keymap (keymap)
521 "Add mime-editor commands to KEYMAP."
522 (if (not (keymapp keymap))
524 (define-key keymap "\C-t" 'mime-editor/insert-text)
525 (define-key keymap "\C-i" 'mime-editor/insert-file)
526 (define-key keymap "\C-e" 'mime-editor/insert-external)
527 (define-key keymap "\C-v" 'mime-editor/insert-voice)
528 (define-key keymap "\C-y" 'mime-editor/insert-message)
529 (define-key keymap "\C-m" 'mime-editor/insert-mail)
530 (define-key keymap "\C-w" 'mime-editor/insert-signature)
531 (define-key keymap "\C-s" 'mime-editor/insert-signature)
532 (define-key keymap "\C-k" 'mime-editor/insert-key)
533 (define-key keymap "t" 'mime-editor/insert-tag)
534 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
535 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
536 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
537 (define-key keymap "d" 'mime-editor/enclose-digest-region)
538 (define-key keymap "s" 'mime-editor/enclose-signed-region)
539 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
540 (define-key keymap "\C-p" 'mime-editor/preview-message)
541 (define-key keymap "\C-z" 'mime-editor/exit)
542 (define-key keymap "?" 'mime-editor/help)
545 (mime-editor/define-keymap mime-editor/mime-map)
547 (defconst mime-editor/menu-title "MIME-Edit")
549 (defconst mime-editor/menu-list
550 '((mime-help "Describe MIME editor mode" mime-editor/help)
551 (file "Insert File" mime-editor/insert-file)
552 (external "Insert External" mime-editor/insert-external)
553 (voice "Insert Voice" mime-editor/insert-voice)
554 (message "Insert Message" mime-editor/insert-message)
555 (mail "Insert Mail" mime-editor/insert-mail)
556 (signature "Insert Signature" mime-editor/insert-signature)
557 (text "Insert Text" mime-editor/insert-text)
558 (tag "Insert Tag" mime-editor/insert-tag)
559 (alternative "Enclose as alternative"
560 mime-editor/enclose-alternative-region)
561 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
562 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
563 (digest "Enclose as digest" mime-editor/enclose-digest-region)
564 (signed "Enclose as signed" mime-editor/enclose-signed-region)
565 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
566 (key "Insert Public Key" mime-editor/insert-key)
567 (split "About split" mime-editor/set-split)
568 (sign "About sign" mime-editor/set-sign)
569 (encrypt "About encryption" mime-editor/set-encrypt)
570 (preview "Preview Message" mime-editor/preview-message)
571 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
573 "MIME-edit menubar entry.")
575 (defun mime-editor/define-menu-for-emacs19 ()
576 "Define menu for Emacs 19."
577 (define-key (current-local-map) [menu-bar mime-edit]
578 (cons mime-editor/menu-title
579 (make-sparse-keymap mime-editor/menu-title)))
582 (define-key (current-local-map)
583 (vector 'menu-bar 'mime-edit (car item))
584 (cons (nth 1 item)(nth 2 item))
587 (reverse mime-editor/menu-list)
590 ;;; modified by Pekka Marjola <pema@iki.fi>
591 ;;; 1995/9/5 (c.f. [tm-en:69])
592 (defun mime-editor/define-menu-for-xemacs ()
593 "Define menu for Emacs 19."
594 (cond ((featurep 'menubar)
595 (make-local-variable 'current-menubar)
596 (set-buffer-menubar current-menubar)
598 (cons mime-editor/menu-title
601 (vector (nth 1 item)(nth 2 item)
602 mime/editor-mode-flag)
604 mime-editor/menu-list)))
607 ;;; modified by Steven L. Baur <steve@miranova.com>
608 ;;; 1995/12/6 (c.f. [tm-en:209])
609 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
610 (setq mime-editor/popup-menu-for-xemacs
611 (append '("MIME Commands" "---")
612 (mapcar (function (lambda (item)
616 mime-editor/menu-list)))
625 (defun mime/editor-mode ()
626 "MIME minor mode for editing the tagged MIME message.
628 In this mode, basically, the message is composed in the tagged MIME
629 format. The message tag looks like:
631 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
633 The tag specifies the MIME content type, subtype, optional parameters
634 and transfer encoding of the message following the tag. Messages
635 without any tag are treated as `text/plain' by default. Charset and
636 transfer encoding are automatically defined unless explicitly
637 specified. Binary messages such as audio and image are usually hidden
638 using selective-display facility. The messages in the tagged MIME
639 format are automatically translated into a MIME compliant message when
642 Available charsets depend on Emacs version being used. The following
643 lists the available charsets of each emacs.
645 Emacs18: US-ASCII is only available.
646 NEmacs: US-ASCII and ISO-2022-JP are available.
647 Emacs19: US-ASCII and ISO-8859-1 are available.
648 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-6),
649 ISO-2022-JP, ISO-2022-JP-2 and ISO-2022-INT-1 are available.
651 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in Mule is expected to
652 be used to represent multilingual text in intermixed manner. Any
653 languages that has no registered charset are represented as either
654 ISO-2022-JP-2 or ISO-2022-INT-1 in Mule.
656 Following commands are available in addition to major mode commands:
657 \\[mime-editor/insert-text] insert a text message.
658 \\[mime-editor/insert-file] insert a (binary) file.
659 \\[mime-editor/insert-external] insert a reference to external body.
660 \\[mime-editor/insert-voice] insert a voice message.
661 \\[mime-editor/insert-message] insert a mail or news message.
662 \\[mime-editor/insert-mail] insert a mail message.
663 \\[mime-editor/insert-signature] insert a signature file at end.
664 \\[mime-editor/insert-tag] insert a new MIME tag.
665 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
666 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
667 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
668 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
669 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
670 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
671 \\[mime-editor/insert-key] insert PGP public key.
672 \\[mime-editor/preview-message] preview editing MIME message.
673 \\[mime-editor/exit] exit and translate into a MIME compliant message.
674 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
675 \\[mime-editor/help] show this help.
677 Additional commands are available in some major modes:
678 C-c C-c exit, translate and run the original command.
679 C-c C-s exit, translate and run the original command.
681 The following is a message example written in the tagged MIME format.
682 TABs at the beginning of the line are not a part of the message:
684 This is a conventional plain text. It should be translated
687 This is also a plain text. But, it is explicitly specified as
689 --[[text/plain; charset=ISO-2022-JP]]
690 \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
693 <center>This is a richtext.</center>
694 --[[image/gif][base64]]^M...image encoded in base64 here...
695 --[[audio/basic][base64]]^M...audio encoded in base64 here...
697 User customizable variables (not documented all of them):
699 Specifies a key prefix for MIME minor mode commands.
701 mime-ignore-preceding-spaces
702 Preceding white spaces in a message body are ignored if non-nil.
704 mime-ignore-trailing-spaces
705 Trailing white spaces in a message body are ignored if non-nil.
707 mime-auto-fill-header
708 Fill header fields that contain encoded-words if non-nil.
711 Hide a non-textual body message encoded in base64 after insertion
715 Specifies a function to record a voice message and return a buffer
716 that contains it. The function mime-voice-recorder-for-sun is for
719 mime/editor-mode-hook
720 Turning on MIME mode calls the value of mime/editor-mode-hook, if
723 mime-editor/translate-hook
724 The value of mime-editor/translate-hook is called just before translating
725 the tagged MIME format into a MIME compliant message if it is
726 non-nil. If the hook call the function mime-editor/insert-signature,
727 the signature file will be inserted automatically.
729 mime-editor/exit-hook
730 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
733 (if mime/editor-mode-flag
734 (error "You are already editing a MIME message.")
735 (setq mime/editor-mode-flag t)
736 ;; Remember old key bindings.
739 (make-local-variable 'mime/editor-mode-old-local-map)
740 (setq mime/editor-mode-old-local-map (current-local-map))
741 ;; Add MIME commands to current local map.
742 (use-local-map (copy-keymap (current-local-map)))
744 (if (not (lookup-key (current-local-map) mime-prefix))
745 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
747 ;; Set transfer level into mode line
749 (setq mime-editor/transfer-level-string
750 (mime/encoding-name mime-editor/transfer-level 'not-omit))
751 (force-mode-line-update)
753 ;; Define menu. Menus for other emacs implementations are
755 (cond (running-xemacs
756 (mime-editor/define-menu-for-xemacs))
757 ((>= emacs-major-version 19)
758 (mime-editor/define-menu-for-emacs19)
762 ;; Remember old selective-display.
763 (make-local-variable 'mime/editor-mode-old-selective-display)
764 (setq mime/editor-mode-old-selective-display selective-display)
765 (setq selective-display t)
766 ;; I don't care about saving these.
767 (setq paragraph-start
768 (regexp-or mime-editor/single-part-tag-regexp
770 (setq paragraph-separate
771 (regexp-or mime-editor/single-part-tag-regexp
773 (run-hooks 'mime/editor-mode-hook)
775 (substitute-command-keys
776 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
780 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
781 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
783 (defun mime-editor/exit (&optional nomime no-error)
784 "Translate the tagged MIME message into a MIME compliant message.
785 With no argument encode a message in the buffer into MIME, otherwise
786 just return to previous mode."
788 (if (not mime/editor-mode-flag)
790 (error "You aren't editing a MIME message.")
794 (run-hooks 'mime-editor/translate-hook)
795 (mime-editor/translate-buffer)))
796 ;; Restore previous state.
797 (setq mime/editor-mode-flag nil)
798 (cond (running-xemacs
799 ;; mime-prefix only defined if binding was nil
800 (if (eq (lookup-key (current-local-map) mime-prefix)
801 mime-editor/mime-map)
802 (define-key (current-local-map) mime-prefix nil))
803 (delete-menu-item (list mime-editor/menu-title)))
805 (use-local-map mime/editor-mode-old-local-map)))
807 (setq selective-display mime/editor-mode-old-selective-display)
808 (set-buffer-modified-p (buffer-modified-p))
809 (run-hooks 'mime-editor/exit-hook)
810 (message "Exit MIME editor mode.")
813 (defun mime-editor/maybe-translate ()
815 (mime-editor/exit nil t)
816 (call-interactively 'mime-editor/maybe-split-and-send)
819 (defun mime-editor/help ()
820 "Show help message about MIME mode."
822 (with-output-to-temp-buffer "*Help*"
823 (princ "MIME editor mode:\n")
824 (princ (documentation 'mime/editor-mode))
825 (print-help-return-message)))
827 (defun mime-editor/insert-text ()
828 "Insert a text message.
829 Charset is automatically obtained from the `mime/lc-charset-alist'."
831 (if (and (mime-editor/insert-tag "text" nil nil)
832 (looking-at mime-editor/single-part-tag-regexp))
834 ;; Make a space between the following message.
839 (defun mime-editor/insert-file (file)
840 "Insert a message from a file."
841 (interactive "fInsert file as MIME message: ")
842 (let* ((guess (mime-find-file-type file))
843 (pritype (nth 0 guess))
844 (subtype (nth 1 guess))
845 (parameters (nth 2 guess))
846 (default (nth 3 guess)) ;Guess encoding from its file name.
847 (disposition-type (nth 4 guess))
848 (disposition-params (nth 5 guess))
850 (if (not (interactive-p))
853 (concat "What transfer encoding"
856 (if (string-equal default "")
862 mime-encoding-method-alist nil t nil))))
863 (if (string-equal encoding "")
864 (setq encoding default))
865 (if (or (consp parameters) (stringp disposition-type))
866 (let ((rest parameters) cell attribute value)
869 (setq cell (car rest))
870 (setq attribute (car cell))
871 (setq value (cdr cell))
873 (setq value (rfc822/wrap-as-quoted-string
874 (file-name-nondirectory file)))
876 (setq parameters (concat parameters "; " attribute "=" value))
877 (setq rest (cdr rest))
882 (concat parameters "\n"
883 "Content-Disposition: " disposition-type))
884 (setq rest disposition-params)
886 (setq cell (car rest))
887 (setq attribute (car cell))
888 (setq value (cdr cell))
890 (setq value (rfc822/wrap-as-quoted-string
891 (file-name-nondirectory file)))
894 (concat parameters "; " attribute "=" value))
895 (setq rest (cdr rest))
899 (mime-editor/insert-tag pritype subtype parameters)
900 (mime-editor/insert-binary-file file encoding)
903 (defun mime-editor/insert-external ()
904 "Insert a reference to external body."
906 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
908 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
910 (let* ((pritype (mime-prompt-for-type))
911 (subtype (mime-prompt-for-subtype pritype))
912 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
915 (insert "Content-Type: "
916 pritype "/" subtype (or parameters "") "\n")))
917 (if (and (not (eobp))
918 (not (looking-at mime-editor/single-part-tag-regexp)))
919 (insert (mime-make-text-tag) "\n")))
921 (defun mime-editor/insert-voice ()
922 "Insert a voice message."
924 (mime-editor/insert-tag "audio" "basic" nil)
925 (let ((buffer (funcall mime-voice-recorder)))
927 (mime-editor/insert-binary-buffer buffer "base64")
931 (defun mime-editor/insert-signature (&optional arg)
932 "Insert a signature file."
934 (let ((signature-insert-hook
937 (apply (function mime-editor/insert-tag)
938 (mime-find-file-type signature-file-name))
941 (insert-signature arg)
945 ;; Insert a new tag around a point.
947 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
948 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
949 If nothing is inserted, return nil."
954 exist-prev-tag exist-next-tag)
957 (mime-prompt-for-type)))
960 (mime-prompt-for-subtype pritype)))
963 (mime-prompt-for-parameters pritype subtype delimiter)))
964 ;; Make a new MIME tag.
965 (setq newtag (mime-make-tag pritype subtype parameters))
966 ;; Find an current MIME tag.
969 (if (mime-editor/goto-tag)
971 (if (eq current (match-beginning 0))
972 (setq exist-next-tag t)
973 (setq exist-prev-tag t)
975 (buffer-substring (match-beginning 0) (match-end 0))
977 ;; Assume content type is 'text/plan'.
978 (mime-make-tag "text" "plain")
980 ;; We are only interested in TEXT.
982 (not (mime-test-content-type
983 (mime-editor/get-contype oldtag) "text")))
985 (cond (exist-prev-tag (insert "\n"))
986 (exist-next-tag (save-excursion
995 (if (or (not oldtag) ;Not text
996 (or mime-ignore-same-text-tag
997 (not (string-equal oldtag newtag))))
999 ;; Mark the beginning of the tag for convenience.
1000 (push-mark (point) 'nomsg)
1001 (insert newtag "\n")
1002 (list pritype subtype parameters) ;New tag is created.
1004 ;; Restore previous point.
1006 nil ;Nothing is created.
1010 ;; Insert the binary content after MIME tag.
1011 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1013 (defun mime-editor/insert-binary-file (file &optional encoding)
1014 "Insert binary FILE at point.
1015 Optional argument ENCODING specifies an encoding method such as base64."
1016 (let ((tmpbuf (get-buffer-create " *MIME insert*")))
1020 (let ((mc-flag nil) ;Mule
1021 (file-coding-system-for-read
1022 (if (featurep 'mule) *noconv*))
1023 (kanji-flag nil) ;NEmacs
1024 (emx-binary-mode t) ;Stop CRLF to LF conversion in OS/2
1026 (let (jka-compr-compression-info-list
1027 jam-zcat-filename-list)
1028 (insert-file-contents file))))
1030 (if (and (stringp encoding)
1031 (string-equal (downcase encoding) "x-uue"))
1034 (let ((uuencode-external-encoder
1035 (cons (car uuencode-external-encoder)
1036 (list (file-name-nondirectory file))
1038 (mime-editor/insert-binary-buffer tmpbuf encoding)
1040 (mime-editor/insert-binary-buffer tmpbuf encoding))
1041 (kill-buffer tmpbuf))))
1043 ;; Insert the binary content after MIME tag.
1044 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1046 (defun mime-editor/insert-binary-buffer (buffer &optional encoding)
1047 "Insert binary BUFFER at point.
1048 Optional argument ENCODING specifies an encoding method such as base64."
1049 (let* ((tagend (1- (point))) ;End of the tag
1050 (hide-p (and mime-auto-hide-body
1052 (let ((en (downcase encoding)))
1053 (or (string-equal en "base64")
1054 (string-equal en "x-uue")
1058 (narrow-to-region (1- (point)) (point))
1059 (let ((start (point))
1060 (emx-binary-mode t)) ;Stop LF to CRLF conversion in OS/2
1061 (insert-buffer-substring buffer)
1062 ;; Encode binary message if necessary.
1064 (mime-encode-region start (point-max) encoding)
1068 (mime-flag-region (point-min) (1- (point-max)) ?\^M)
1069 (goto-char (point-max)))
1071 ;; Define encoding even if it is 7bit.
1072 (if (stringp encoding)
1074 (goto-char tagend) ;Make sure which line the tag is on.
1075 (mime-editor/define-encoding encoding)))
1079 ;; Commands work on a current message flagment.
1081 (defun mime-editor/goto-tag ()
1082 "Search for the beginning of the tagged MIME message."
1083 (let ((current (point)) multipart)
1084 (if (looking-at mime-editor/tag-regexp)
1086 ;; At first, go to the end.
1087 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1088 (goto-char (match-beginning 0)) ;For multiline tag
1093 (goto-char (point-max))
1095 ;; Then search for the beginning.
1096 (re-search-backward mime-editor/end-tag-regexp nil t)
1098 (or (looking-at mime-editor/beginning-tag-regexp)
1099 ;; Restore previous point.
1106 (defun mime-editor/content-beginning ()
1107 "Return the point of the beginning of content."
1109 (let ((beg (save-excursion
1110 (beginning-of-line) (point))))
1111 (if (mime-editor/goto-tag)
1112 (let ((top (point)))
1113 (goto-char (match-end 0))
1114 (if (and (= beg top)
1115 (= (following-char) ?\^M))
1119 ;; Default text/plain tag.
1120 (goto-char (point-min))
1122 (concat "\n" (regexp-quote mail-header-separator)
1123 (if mime-ignore-preceding-spaces
1124 "[ \t\n]*\n" "\n")) nil 'move)
1128 (defun mime-editor/content-end ()
1129 "Return the point of the end 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) ;Must be on the same line.
1137 (= (following-char) ?\^M))
1141 ;; Move to the end of this text.
1142 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1143 ;; Don't forget a multiline tag.
1144 (goto-char (match-beginning 0)))
1147 ;; Assume the message begins with text/plain.
1148 (goto-char (mime-editor/content-beginning))
1149 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1150 ;; Don't forget a multiline tag.
1151 (goto-char (match-beginning 0)))
1155 (defun mime-editor/define-charset (charset)
1156 "Set charset of current tag to CHARSET."
1158 (if (mime-editor/goto-tag)
1159 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1160 (delete-region (match-beginning 0) (match-end 0))
1162 (mime-create-tag (mime-set-parameter
1163 (mime-editor/get-contype tag) "charset" charset)
1164 (mime-editor/get-encoding tag))))
1167 (defun mime-editor/define-encoding (encoding)
1168 "Set encoding of current tag to ENCODING."
1170 (if (mime-editor/goto-tag)
1171 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1172 (delete-region (match-beginning 0) (match-end 0))
1173 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1176 (defun mime-editor/choose-charset ()
1177 "Choose charset of a text following current point."
1178 (mime/find-charset-region (point) (mime-editor/content-end))
1181 (defun mime-make-text-tag (&optional subtype)
1182 "Make a tag for a text after current point.
1183 Subtype of text type can be specified by an optional argument SUBTYPE.
1184 Otherwise, it is obtained from mime-content-types."
1185 (let* ((pritype "text")
1186 (subtype (or subtype
1187 (car (car (cdr (assoc pritype mime-content-types)))))))
1188 ;; Charset should be defined later.
1189 (mime-make-tag pritype subtype)))
1192 ;; Tag handling functions
1194 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1195 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1196 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1200 (defun mime-create-tag (contype &optional encoding)
1201 "Make a tag with CONTENT-TYPE and optional ENCODING."
1202 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1205 (defun mime-editor/get-contype (tag)
1206 "Return Content-Type (including parameters) of TAG."
1208 (or (string-match mime-editor/single-part-tag-regexp tag)
1209 (string-match mime-editor/multipart-beginning-regexp tag)
1210 (string-match mime-editor/multipart-end-regexp tag)
1212 (substring tag (match-beginning 1) (match-end 1))
1215 (defun mime-editor/get-encoding (tag)
1216 "Return encoding of TAG."
1218 (string-match mime-editor/single-part-tag-regexp tag)
1220 (not (= (match-beginning 3) (match-end 3)))
1221 (substring tag (match-beginning 3) (match-end 3))))
1223 (defun mime-get-parameter (contype parameter)
1224 "For given CONTYPE return value for PARAMETER.
1225 Nil if no such parameter."
1229 (regexp-quote parameter)
1230 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1232 (substring contype (match-beginning 1) (match-end 1))
1233 nil ;No such parameter
1236 (defun mime-set-parameter (contype parameter value)
1237 "For given CONTYPE set PARAMETER to VALUE."
1241 (regexp-quote parameter)
1242 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1245 (concat (substring contype 0 (match-beginning 1))
1247 (substring contype (match-end 1)))
1248 (concat contype "; " parameter "=" value)))
1250 (defun mime-strip-parameters (contype)
1251 "Return primary content-type and subtype without parameters for CONTYPE."
1252 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1253 (substring contype (match-beginning 1) (match-end 1)) nil))
1255 (defun mime-test-content-type (contype type &optional subtype)
1256 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1257 (and (stringp contype)
1260 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1261 (downcase contype))))
1266 (defun mime-find-file-type (file)
1267 "Guess Content-Type, subtype, and parameters from FILE."
1269 (guesses mime-file-types))
1270 (while (and (not guess) guesses)
1271 (if (string-match (car (car guesses)) file)
1272 (setq guess (cdr (car guesses))))
1273 (setq guesses (cdr guesses)))
1277 (defun mime-prompt-for-type ()
1278 "Ask for Content-type."
1280 ;; Repeat until primary content type is specified.
1281 (while (string-equal type "")
1283 (completing-read "What content type: "
1286 'require-match ;Type must be specified.
1289 (if (string-equal type "")
1291 (message "Content type is required.")
1299 (defun mime-prompt-for-subtype (pritype)
1300 "Ask for Content-type subtype of Content-Type PRITYPE."
1301 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1306 "What content subtype: (default " default ") ")
1307 "What content subtype: ")
1308 (cdr (assoc pritype mime-content-types))
1310 'require-match ;Subtype must be specified.
1313 (if (string-equal answer "") default answer)))
1315 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1316 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1317 Optional DELIMITER specifies parameter delimiter (';' by default)."
1318 (let* ((delimiter (or delimiter "; "))
1323 (mime-prompt-for-parameters-1
1325 (cdr (assoc pritype mime-content-types))))))
1328 (if (and (stringp parameters)
1329 (not (string-equal parameters "")))
1330 (concat delimiter parameters)
1331 "" ;"" if no parameters
1334 (defun mime-prompt-for-parameters-1 (optlist)
1335 (apply (function append)
1336 (mapcar (function mime-prompt-for-parameter) optlist)))
1338 (defun mime-prompt-for-parameter (parameter)
1340 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1341 (let* ((prompt (car parameter))
1342 (choices (mapcar (function
1344 (if (consp e) e (list e))))
1346 (default (car (car choices)))
1352 (concat "What " prompt
1354 (if (string-equal default "") "\"\"" default)
1356 choices nil nil ""))
1357 ;; If nothing is selected, use default.
1358 (if (string-equal answer "")
1359 (setq answer default)))
1361 (read-string (concat "What " prompt ": "))))
1362 (cons (if (and answer
1363 (not (string-equal answer "")))
1365 ;; Note: control characters ignored!
1366 (if (string-match mime-tspecials-regexp answer)
1367 (concat "\"" answer "\"") answer)))
1368 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1371 (defun mime-flag-region (from to flag)
1372 "Hides or shows lines from FROM to TO, according to FLAG.
1373 If FLAG is `\\n' (newline character) then text is shown,
1374 while if FLAG is `\\^M' (control-M) the text is hidden."
1375 (let ((buffer-read-only nil) ;Okay even if write protected.
1376 (modp (buffer-modified-p)))
1378 (subst-char-in-region from to
1379 (if (= flag ?\n) ?\^M ?\n)
1381 (set-buffer-modified-p modp))))
1384 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1387 (defvar mime-editor/translate-buffer-hook
1388 '(mime-editor/pgp-enclose-buffer
1389 mime/encode-message-header
1390 mime-editor/translate-body))
1392 (defun mime-editor/translate-buffer ()
1393 "Encode the tagged MIME message in current buffer in MIME compliant message."
1395 (if (catch 'mime-editor/error
1397 (run-hooks 'mime-editor/translate-buffer-hook)
1401 (error "Translation error!")
1404 (defun mime-editor/find-inmost ()
1405 (goto-char (point-min))
1406 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1407 (let ((bb (match-beginning 0))
1409 (type (buffer-substring (match-beginning 1)(match-end 1)))
1411 (setq end-exp (format "^--}-<<%s>>\n" type))
1413 (if (re-search-forward end-exp nil t)
1415 (setq eb (match-beginning 0))
1416 (setq ee (match-end 0))
1418 (setq eb (point-max))
1419 (setq ee (point-max))
1421 (narrow-to-region be eb)
1423 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1425 (narrow-to-region (match-beginning 0)(point-max))
1426 (mime-editor/find-inmost)
1429 ;;(delete-region eb ee)
1430 (list type bb be eb)
1433 (defun mime-editor/process-multipart-1 (boundary)
1434 (let ((ret (mime-editor/find-inmost)))
1436 (let ((type (car ret))
1437 (bb (nth 1 ret))(be (nth 2 ret))
1440 (narrow-to-region bb eb)
1441 (delete-region bb be)
1442 (setq bb (point-min))
1443 (setq eb (point-max))
1446 (if (looking-at mime-editor/multipart-end-regexp)
1447 (let ((beg (match-beginning 0))
1450 (delete-region beg end)
1451 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
1453 (insert (concat (mime-make-text-tag) "\n"))
1455 (cond ((string= type "signed")
1456 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1457 (mime-editor/sign-pgp-elkins bb eb boundary)
1459 ((eq mime-editor/signing-type 'pgp-kazu)
1460 (mime-editor/sign-pgp-kazu bb eb boundary)
1463 ((string= type "encrypted")
1464 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1465 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1467 ((eq mime-editor/encrypting-type 'pgp-kazu)
1468 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1472 (nth 2 (mime-editor/translate-region bb eb
1476 (format "--[[multipart/%s;
1477 boundary=\"%s\"][7bit]]\n"
1483 (autoload 'mc-pgp-lookup-key "mc-pgp")
1484 (autoload 'mc-pgp-sign-region "mc-pgp")
1485 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1487 (defun tm:mc-pgp-generic-parser (result)
1488 (let ((ret (mc-pgp-generic-parser result)))
1490 (vector (car ret)(cdr ret))
1493 (defun tm:mc-process-region
1494 (beg end passwd program args parser &optional buffer boundary)
1495 (let ((obuf (current-buffer))
1496 (process-connection-type nil)
1497 mybuf result rgn proc)
1500 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1504 (buffer-disable-undo mybuf)
1506 (apply 'start-process "*PGP*" mybuf program args))
1509 (process-send-string proc (concat passwd "\n"))
1510 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1511 (process-send-region proc beg end)
1512 (process-send-eof proc)
1513 (while (eq 'run (process-status proc))
1514 (accept-process-output proc 5))
1515 (setq result (process-exit-status proc))
1516 ;; Hack to force a status_notify() in Emacs 19.29
1517 (delete-process proc)
1519 (goto-char (point-max))
1520 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1521 (delete-region (match-beginning 0) (match-end 0)))
1522 (goto-char (point-min))
1524 (while (search-forward "\r\n" nil t)
1525 (replace-match "\n"))
1526 ;; Hurm. FIXME; must get better result codes.
1527 (if (stringp result)
1528 (error "%s exited abnormally: '%s'" program result)
1529 (setq rgn (funcall parser result))
1530 ;; If the parser found something, migrate it
1536 (narrow-to-region beg end)
1538 (insert (format "--%s\n" boundary))
1539 (goto-char (point-max))
1540 (insert (format "\n--%s
1541 Content-Type: application/pgp-signature
1542 Content-Transfer-Encoding: 7bit
1545 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1546 (goto-char (point-max))
1547 (insert (format "\n--%s--\n" boundary))
1549 (delete-region beg end)
1551 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1554 (delete-region (car rgn) (cdr rgn)))))
1555 ;; Return nil on failure and exit code on success
1557 ;; Cleanup even on nonlocal exit
1558 (if (and proc (eq 'run (process-status proc)))
1559 (interrupt-process proc))
1561 (or buffer (null mybuf) (kill-buffer mybuf)))))
1563 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1564 (if (not (boundp 'mc-pgp-user-id))
1567 (let ((process-environment process-environment)
1568 (buffer (get-buffer-create mc-buffer-name))
1570 (parser (function mc-pgp-generic-parser))
1571 (pgp-path mc-pgp-path)
1573 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1577 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1578 (setenv "PGPPASSFD" "0")
1584 (list "+verbose=1" "+language=en"
1585 (format "+clearsig=%s" (if unclear "off" "on"))
1586 "+batchmode" "-u" (cdr key))))
1588 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1590 (message "Signing as %s ..." (car key))
1591 (if (tm:mc-process-region
1592 start end passwd pgp-path args parser buffer boundary)
1596 (goto-char (point-min))
1599 --[[multipart/signed; protocol=\"application/pgp-signature\";
1600 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1602 (message "Signing as %s ... Done." (car key))
1606 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1609 (narrow-to-region beg end)
1611 (mime-editor/translate-region beg end boundary))
1613 (encoding (nth 1 ret))
1615 (pgp-boundary (concat "pgp-sign-" boundary))
1618 (insert (format "Content-Type: %s\n" ctype))
1620 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1623 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1624 nil nil pgp-boundary)
1625 (throw 'mime-editor/error 'pgp-error)
1629 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1632 (let ((from (rfc822/get-field-body "From"))
1633 (to (rfc822/get-field-body "To"))
1634 (cc (rfc822/get-field-body "cc"))
1636 (narrow-to-region beg end)
1638 (mime-editor/translate-region beg end boundary))
1640 (encoding (nth 1 ret))
1642 (pgp-boundary (concat "pgp-" boundary))
1645 (if (and (stringp from)
1646 (not (string-equal from "")))
1647 (insert (format "From: %s\n" from))
1649 (if (and (stringp to)
1650 (not (string-equal to "")))
1652 (insert (format "To: %s\n" to))
1653 (setq recipients to)
1655 (if (and (stringp cc)
1656 (not (string-equal cc "")))
1658 (insert (format "cc: %s\n" cc))
1660 (setq recipients (concat recipients "," cc))
1661 (setq recipients cc)
1663 (insert (format "Content-Type: %s\n" ctype))
1665 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1669 (let ((mc-pgp-always-sign 'never))
1670 (mc-pgp-encrypt-region
1671 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1672 (point-min) (point-max) from nil)
1674 (throw 'mime-editor/error 'pgp-error)
1677 (insert (format "--[[multipart/encrypted;
1679 protocol=\"application/pgp-encrypted\"][7bit]]
1681 Content-Type: application/pgp-encrypted
1684 Content-Type: application/octet-stream
1685 Content-Transfer-Encoding: 7bit
1687 " pgp-boundary pgp-boundary pgp-boundary))
1688 (goto-char (point-max))
1689 (insert (format "\n--%s--\n" pgp-boundary))
1692 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1695 (narrow-to-region beg end)
1697 (mime-editor/translate-region beg end boundary))
1699 (encoding (nth 1 ret))
1703 (insert (format "Content-Type: %s\n" ctype))
1705 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1708 (or (let ((program-coding-system-alist
1709 (cons (cons (cons nil ".*pgp.*")
1710 (cons *noconv* *noconv*))
1711 program-coding-system-alist))
1713 (mc-pgp-sign-region beg (point-max))
1715 (throw 'mime-editor/error 'pgp-error)
1719 "--[[application/pgp; format=mime][7bit]]\n")
1723 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1725 (let ((from (rfc822/get-field-body "From"))
1726 (to (rfc822/get-field-body "To"))
1727 (cc (rfc822/get-field-body "cc"))
1730 (narrow-to-region beg end)
1732 (mime-editor/translate-region beg end boundary))
1734 (encoding (nth 1 ret))
1738 (if (and (stringp from)
1739 (not (string-equal from "")))
1740 (insert (format "From: %s\n" from))
1742 (if (and (stringp to)
1743 (not (string-equal to "")))
1745 (insert (format "To: %s\n" to))
1746 (setq recipients to)
1748 (if (and (stringp cc)
1749 (not (string-equal cc "")))
1751 (insert (format "cc: %s\n" cc))
1753 (setq recipients (concat recipients "," cc))
1754 (setq recipients cc)
1756 (insert (format "Content-Type: %s\n" ctype))
1758 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1761 (or (let ((program-coding-system-alist
1762 (cons (cons (cons nil ".*pgp.*")
1763 (cons *noconv* *noconv*))
1764 program-coding-system-alist))
1766 (mc-pgp-encrypt-region
1767 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1770 (throw 'mime-editor/error 'pgp-error)
1774 "--[[application/pgp; format=mime][7bit]]\n")
1778 (defun mime-editor/translate-body ()
1779 "Encode the tagged MIME body in current buffer in MIME compliant message."
1783 (concat mime-multipart-boundary "_"
1784 (replace-space-with-underline (current-time-string))
1788 (while (mime-editor/process-multipart-1
1789 (format "%s-%d" boundary i))
1793 ;; We are interested in message body.
1796 (goto-char (point-min))
1798 (concat "\n" (regexp-quote mail-header-separator)
1799 (if mime-ignore-preceding-spaces
1800 "[ \t\n]*\n" "\n")) nil 'move)
1804 (goto-char (point-max))
1805 (and mime-ignore-trailing-spaces
1806 (re-search-backward "[^ \t\n]\n" beg t)
1809 (setq ret (mime-editor/translate-region
1811 (format "%s-%d" boundary i)))
1813 (let ((contype (car ret)) ;Content-Type
1814 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1816 ;; Make primary MIME headers.
1817 (or (mail-position-on-field "Mime-Version")
1818 (insert mime-editor/mime-version-value))
1819 ;; Remove old Content-Type and other fields.
1821 (goto-char (point-min))
1822 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1823 (narrow-to-region (point-min) (point))
1824 (goto-char (point-min))
1825 (mime-delete-field "Content-Type")
1826 (mime-delete-field "Content-Transfer-Encoding"))
1827 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1828 (mail-position-on-field "Content-Type")
1832 (mail-position-on-field "Content-Transfer-Encoding")
1836 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1839 (concat mime-multipart-boundary "_"
1840 (replace-space-with-underline (current-time-string))))
1844 (narrow-to-region beg end)
1845 (let ((tag nil) ;MIME tag
1846 (contype nil) ;Content-Type
1847 (encoding nil) ;Content-Transfer-Encoding
1848 (nparts 0)) ;Number of body parts
1849 ;; Normalize the body part by inserting appropriate message
1850 ;; tags for every message contents.
1851 (mime-editor/normalize-body)
1852 ;; Counting the number of Content-Type.
1853 (goto-char (point-min))
1854 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1855 (setq nparts (1+ nparts)))
1856 ;; Begin translation.
1857 (cond ((and (<= nparts 1)(not multipart))
1858 ;; It's a singular message.
1859 (goto-char (point-min))
1860 (while (re-search-forward
1861 mime-editor/single-part-tag-regexp nil t)
1863 (buffer-substring (match-beginning 0) (match-end 0)))
1864 (delete-region (match-beginning 0) (1+ (match-end 0)))
1865 (setq contype (mime-editor/get-contype tag))
1866 (setq encoding (mime-editor/get-encoding tag))
1869 ;; It's a multipart message.
1870 (goto-char (point-min))
1871 (while (re-search-forward
1872 mime-editor/single-part-tag-regexp nil t)
1874 (buffer-substring (match-beginning 0) (match-end 0)))
1875 (delete-region (match-beginning 0) (match-end 0))
1876 (setq contype (mime-editor/get-contype tag))
1877 (setq encoding (mime-editor/get-encoding tag))
1878 (insert "--" boundary "\n")
1879 (insert "Content-Type: " contype "\n")
1881 (insert "Content-Transfer-Encoding: " encoding "\n"))
1883 ;; Define Content-Type as "multipart/mixed".
1885 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1886 ;; Content-Transfer-Encoding must be "7bit".
1887 ;; The following encoding can be `nil', but is
1888 ;; specified as is since there is no way that a user
1890 (setq encoding "7bit")
1891 ;; Insert the trailer.
1892 (goto-char (point-max))
1894 (insert "--" boundary "--\n")
1895 (insert "\n--" boundary "--\n")
1897 (list contype encoding boundary nparts)
1900 (defun mime-editor/normalize-body ()
1901 "Normalize the body part by inserting appropriate message tags."
1902 ;; Insert the first MIME tags if necessary.
1903 (goto-char (point-min))
1904 (if (not (looking-at mime-editor/single-part-tag-regexp))
1905 (insert (mime-make-text-tag) "\n"))
1906 ;; Check each tag, and add new tag or correct it if necessary.
1907 (goto-char (point-min))
1908 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1909 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1910 (contype (mime-editor/get-contype tag))
1911 (charset (mime-get-parameter contype "charset"))
1912 (encoding (mime-editor/get-encoding tag)))
1913 ;; Remove extra whitespaces after the tag.
1914 (if (looking-at "[ \t]+$")
1915 (delete-region (match-beginning 0) (match-end 0)))
1917 ((= (following-char) ?\^M)
1918 ;; It must be image, audio or video.
1920 (end (mime-editor/content-end)))
1921 ;; Insert explicit MIME tags after hidden messages.
1923 (if (and (not (eobp))
1924 (not (looking-at mime-editor/single-part-tag-regexp)))
1926 (insert (mime-make-text-tag) "\n")
1927 (forward-line -1) ;Process it again as text.
1929 ;; Show a hidden message. The point is not altered
1930 ;; after the conversion.
1931 (mime-flag-region beg end ?\n)
1933 ((mime-test-content-type contype "message")
1934 ;; Content-type "message" should be sent as is.
1937 ((mime-test-content-type contype "text")
1938 ;; Define charset for text if necessary.
1939 (setq charset (or charset (mime-editor/choose-charset)))
1940 (mime-editor/define-charset charset)
1941 (cond ((string-equal contype "text/x-rot13-47")
1945 (goto-char (mime-editor/content-end))
1948 ((string-equal contype "text/enriched")
1953 (end (mime-editor/content-end))
1955 (enriched-encode beg end)
1957 (if (search-forward "\n\n")
1958 (delete-region beg (match-end 0))
1961 ;; Point is now on current tag.
1962 ;; Define encoding and encode text if necessary.
1963 (or encoding ;Encoding is not specified.
1967 mime-editor/charset-default-encoding-alist)
1969 (beg (mime-editor/content-beginning))
1971 (mime-charset-encode-region beg (mime-editor/content-end)
1973 (mime-encode-region beg (mime-editor/content-end) encoding)
1974 (mime-editor/define-encoding encoding)
1978 ((null encoding) ;Encoding is not specified.
1979 ;; Application, image, audio, video, and any other
1980 ;; unknown content-type without encoding should be
1982 (let* ((encoding "base64") ;Encode in BASE64 by default.
1983 (beg (mime-editor/content-beginning))
1984 (end (mime-editor/content-end))
1985 (body (buffer-substring beg end))
1987 (mime-encode-region beg end encoding)
1988 (mime-editor/define-encoding encoding))
1994 (defun mime-delete-field (field)
1995 "Delete header FIELD."
1996 (let ((regexp (format "^%s:[ \t]*" field)))
1997 (goto-char (point-min))
1998 (while (re-search-forward regexp nil t)
1999 (delete-region (match-beginning 0)
2000 (progn (forward-line 1) (point)))
2005 ;;; Platform dependent functions
2008 ;; Sun implementations
2010 (defun mime-voice-recorder-for-sun ()
2011 "Record voice in a buffer using Sun audio device, and return the buffer.
2012 If the environment variable AUDIOHOST is defined, its value is used as
2013 a recording host instead of local host."
2014 (let ((buffer (get-buffer-create " *MIME audio*"))
2015 (host (getenv "AUDIOHOST")))
2016 (message "Start the recording on %s. Type C-g to finish the recording..."
2017 (or host (system-name)))
2021 (condition-case errorcode
2022 (let ((selective-display nil) ;Disable ^M to nl translation.
2024 (kanji-flag nil)) ;NEmacs
2025 ;; If AUDIOHOST is defined, use the value as recording host.
2026 (cond ((not (null host))
2027 ;; Disable automatic conversion of coding system if Mule.
2028 (if (featurep 'mule)
2029 (define-program-coding-system nil "rsh" *noconv*))
2039 ;; Disable automatic conversion of coding system if Mule.
2040 (if (featurep 'mule)
2041 (define-program-coding-system nil "cat" *noconv*))
2047 (quit (message "Type C-g to finish recording... done.")
2048 buffer ;Return the buffer
2052 ;;; @ Other useful commands.
2055 ;; Message forwarding commands as content-type "message/rfc822".
2057 (defun mime-editor/insert-message (&optional message)
2059 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2060 (if (and inserter (fboundp inserter))
2062 (mime-editor/insert-tag "message" "rfc822")
2063 (funcall inserter message)
2065 (message "Sorry, I don't have message inserter for your MUA.")
2068 (defun mime-editor/insert-mail (&optional message)
2070 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2071 (if (and inserter (fboundp inserter))
2073 (mime-editor/insert-tag "message" "rfc822")
2074 (funcall inserter message)
2076 (message "Sorry, I don't have mail inserter for your MUA.")
2079 (defun mime-editor/inserted-message-filter ()
2082 (let ((header-start (point))
2083 (case-fold-search t)
2086 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2087 (if (re-search-forward "^$" (mark t))
2088 (narrow-to-region header-start (match-beginning 0))
2090 (goto-char header-start)
2091 (while (and (re-search-forward
2092 mime-editor/yank-ignored-field-regexp nil t)
2093 (setq beg (match-beginning 0))
2094 (setq end (1+ (rfc822/field-end)))
2096 (delete-region beg end)
2101 ;;; @ multipart enclosure
2104 (defun mime-editor/enclose-region (type beg end)
2107 (let ((current (point))
2110 (if (mime-editor/goto-tag)
2111 (or (eq current (match-beginning 0))
2112 (setq exist-prev-tag t)
2115 (narrow-to-region beg end)
2120 (insert (format "--<<%s>>-{\n" type))
2121 (goto-char (point-max))
2122 (insert (format "\n--}-<<%s>>\n" type))
2123 (goto-char (point-max))
2125 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
2127 (insert (mime-make-text-tag) "\n")
2131 (defun mime-editor/enclose-mixed-region (beg end)
2133 (mime-editor/enclose-region "mixed" beg end)
2136 (defun mime-editor/enclose-parallel-region (beg end)
2138 (mime-editor/enclose-region "parallel" beg end)
2141 (defun mime-editor/enclose-digest-region (beg end)
2143 (mime-editor/enclose-region "digest" beg end)
2146 (defun mime-editor/enclose-alternative-region (beg end)
2148 (mime-editor/enclose-region "alternative" beg end)
2151 (defun mime-editor/enclose-signed-region (beg end)
2153 (if mime-editor/signing-type
2154 (mime-editor/enclose-region "signed" beg end)
2155 (message "Please specify signing type.")
2158 (defun mime-editor/enclose-encrypted-region (beg end)
2160 (if mime-editor/signing-type
2161 (mime-editor/enclose-region "encrypted" beg end)
2162 (message "Please specify encrypting type.")
2165 (defun mime-editor/insert-key (&optional arg)
2166 "Insert a pgp public key."
2168 (mime-editor/insert-tag "application" "pgp-keys")
2169 (mime-editor/define-encoding "7bit")
2170 (mc-insert-public-key)
2177 (defun mime-editor/set-split (arg)
2180 (y-or-n-p "Do you want to enable split?")
2182 (setq mime-editor/split-message arg)
2184 (message "This message is enabled to split.")
2185 (message "This message is not enabled to split.")
2188 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2189 "Toggle transfer-level is 7bit or 8bit through.
2191 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2193 (if (numberp transfer-level)
2194 (setq mime-editor/transfer-level transfer-level)
2195 (if (< mime-editor/transfer-level 8)
2196 (setq mime-editor/transfer-level 8)
2197 (setq mime-editor/transfer-level 7)
2199 (setq mime-editor/charset-default-encoding-alist
2200 (mime/make-charset-default-encoding-alist
2201 mime-editor/transfer-level))
2202 (message (format "Current transfer-level is %d bit"
2203 mime-editor/transfer-level))
2204 (setq mime-editor/transfer-level-string
2205 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2206 (force-mode-line-update)
2213 (defun mime-editor/set-sign (arg)
2216 (y-or-n-p "Do you want to sign?")
2219 (if mime-editor/signing-type
2221 (setq mime-editor/pgp-processing 'sign)
2222 (message "This message will be signed.")
2224 (message "Please specify signing type.")
2226 (if (eq mime-editor/pgp-processing 'sign)
2227 (setq mime-editor/pgp-processing nil)
2229 (message "This message will not be signed.")
2232 (defun mime-editor/set-encrypt (arg)
2235 (y-or-n-p "Do you want to encrypt?")
2238 (if mime-editor/encrypting-type
2240 (setq mime-editor/pgp-processing 'encrypt)
2241 (message "This message will be encrypt.")
2243 (message "Please specify encrypting type.")
2245 (if (eq mime-editor/pgp-processing 'encrypt)
2246 (setq mime-editor/pgp-processing nil)
2248 (message "This message will not be encrypt.")
2251 (defvar mime-editor/pgp-processing nil)
2252 (make-variable-buffer-local 'mime-editor/pgp-processing)
2254 (defun mime-editor/pgp-enclose-buffer ()
2255 (let ((beg (save-excursion
2256 (goto-char (point-min))
2257 (if (search-forward (concat "\n" mail-header-separator "\n"))
2263 (cond ((eq mime-editor/pgp-processing 'sign)
2264 (mime-editor/enclose-signed-region beg end)
2266 ((eq mime-editor/pgp-processing 'encrypt)
2267 (mime-editor/enclose-encrypted-region beg end)
2275 (defun mime-editor/insert-partial-header
2276 (fields subject id number total separator)
2278 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2279 (insert (format "Mime-Version: 1.0 (split by tm-edit %s)\n"
2280 mime-editor/version))
2282 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2283 id number total separator))
2286 (defun mime-editor/split-and-send
2287 (&optional cmd lines mime-editor/message-max-length)
2291 (count-lines (point-min) (point-max)))
2293 (or mime-editor/message-max-length
2294 (setq mime-editor/message-max-length
2295 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2296 mime-editor/message-default-max-length))
2298 (let* ((mime-editor/draft-file-name
2299 (or (buffer-file-name)
2301 (expand-file-name "tm-draft" mime/tmp-dir))))
2302 (separator mail-header-separator)
2304 (replace-space-with-underline (current-time-string))
2305 "@" (system-name) "\"")))
2306 (run-hooks 'mime-editor/before-split-hook)
2307 (let ((the-buf (current-buffer))
2308 (copy-buf (get-buffer-create " *Original Message*"))
2309 (header (rfc822/get-header-string-except
2310 mime-editor/split-ignored-field-regexp separator))
2311 (subject (mail-fetch-field "subject"))
2312 (total (+ (/ lines mime-editor/message-max-length)
2313 (if (> (mod lines mime-editor/message-max-length) 0)
2319 mime-editor/split-message-sender-alist))
2321 (mime-editor/partial-number 1)
2324 (set-buffer copy-buf)
2326 (insert-buffer the-buf)
2328 (if (re-search-forward
2329 (concat "^" (regexp-quote separator) "$") nil t)
2330 (let ((he (match-beginning 0)))
2332 (narrow-to-region (point-min) he)
2334 (goto-char (point-min))
2335 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
2336 (delete-region (match-beginning 0)
2337 (1+ (rfc822/field-end)))
2339 (while (< mime-editor/partial-number total)
2342 (set-buffer copy-buf)
2343 (setq data (buffer-substring
2346 (goto-line mime-editor/message-max-length)
2349 (delete-region (point-min)(point))
2351 (mime-editor/insert-partial-header
2352 header subject id mime-editor/partial-number total separator)
2355 (message (format "Sending %d/%d..."
2356 mime-editor/partial-number total))
2357 (call-interactively command)
2358 (message (format "Sending %d/%d... done"
2359 mime-editor/partial-number total))
2361 (setq mime-editor/partial-number
2362 (1+ mime-editor/partial-number))
2366 (set-buffer copy-buf)
2367 (setq data (buffer-string))
2370 (mime-editor/insert-partial-header
2371 header subject id mime-editor/partial-number total separator)
2374 (message (format "Sending %d/%d..."
2375 mime-editor/partial-number total))
2376 (message (format "Sending %d/%d... done"
2377 mime-editor/partial-number total))
2381 (defun mime-editor/maybe-split-and-send (&optional cmd)
2383 (run-hooks 'mime-editor/before-send-hook)
2384 (let ((mime-editor/message-max-length
2385 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2386 mime-editor/message-default-max-length))
2387 (lines (count-lines (point-min) (point-max)))
2389 (if (and (> lines mime-editor/message-max-length)
2390 mime-editor/split-message)
2391 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2395 ;;; @ preview message
2398 (defun mime-editor/preview-message ()
2399 "preview editing MIME message. [tm-edit.el]"
2401 (let* ((str (buffer-string))
2402 (separator mail-header-separator)
2403 (the-buf (current-buffer))
2404 (buf-name (buffer-name))
2405 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2406 (buf (get-buffer temp-buf-name))
2410 (switch-to-buffer buf)
2413 (setq buf (get-buffer-create temp-buf-name))
2414 (switch-to-buffer buf)
2417 (setq major-mode 'mime/temporary-message-mode)
2418 (make-local-variable 'mail-header-separator)
2419 (setq mail-header-separator separator)
2420 (make-local-variable 'mime/editing-buffer)
2421 (setq mime/editing-buffer the-buf)
2423 (run-hooks 'mime-editor/translate-hook)
2424 (mime-editor/translate-buffer)
2425 (goto-char (point-min))
2426 (if (re-search-forward
2427 (concat "^" (regexp-quote separator) "$"))
2433 (defun mime-editor/quitting-method ()
2434 (let ((temp mime::preview/article-buffer)
2436 (mime-viewer/kill-buffer)
2438 (setq buf mime/editing-buffer)
2440 (switch-to-buffer buf)
2443 (set-alist 'mime-viewer/quitting-method-alist
2444 'mime/temporary-message-mode
2445 (function mime-editor/quitting-method)
2451 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2452 ;; Mon, 10 Apr 1995 20:03:07 +0900
2454 (defvar mime-editor/draft-header-separator-alist
2455 '((news-reply-mode . mail-header-separator)
2456 (mh-letter-mode . mail-header-separator)
2459 (defvar mime::article/draft-header-separator nil)
2461 (defun mime-editor/draft-preview ()
2463 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2464 (or (stringp sep) (setq sep (eval sep)))
2465 (make-variable-buffer-local 'mime::article/draft-header-separator)
2466 (goto-char (point-min))
2468 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2469 (setq mime::article/draft-header-separator
2470 (buffer-substring (match-beginning 0) (match-end 0)))
2472 (mime/viewer-mode (current-buffer))
2473 (pop-to-buffer (current-buffer))
2476 (defun mime-viewer::quitting-method/draft-preview ()
2477 (let ((mother mime::preview/mother-buffer))
2479 (switch-to-buffer mother)
2480 (goto-char (point-min))
2484 (regexp-quote mime::article/draft-header-separator)
2488 (insert mime::article/draft-header-separator)
2489 (set-buffer-modified-p (buffer-modified-p))
2491 (mime-viewer/kill-buffer)
2492 (pop-to-buffer mother)
2495 (set-alist 'mime-viewer/quitting-method-alist
2497 (function mime-viewer::quitting-method/draft-preview)
2500 (set-alist 'mime-viewer/quitting-method-alist
2502 (function mime-viewer::quitting-method/draft-preview)
2509 (defun mime-editor::edit-again (code-conversion)
2511 (goto-char (point-min))
2512 (let ((ctl (mime/Content-Type)))
2514 (let ((ctype (car ctl))
2517 (if (string-match "/" ctype)
2519 (setq type (substring ctype 0 (match-beginning 0)))
2520 (setq stype (substring ctype (match-end 0)))
2525 ((string-equal type "multipart")
2526 (let ((boundary (assoc-value "boundary" params)))
2527 (re-search-forward (concat "\n--" boundary) nil t)
2528 (let ((bb (match-beginning 0)) eb tag)
2529 (setq tag (format "\n--<<%s>>-{" stype))
2532 (setq bb (+ bb (length tag)))
2533 (re-search-forward (concat "\n--" boundary "--") nil t)
2534 (setq eb (match-beginning 0))
2535 (replace-match (format "\n--}-<<%s>>" stype))
2537 (narrow-to-region bb eb)
2538 (goto-char (point-min))
2539 (while (re-search-forward
2540 (concat "\n--" boundary "\n") nil t)
2541 (let ((beg (match-beginning 0))
2543 (delete-region beg (match-end 0))
2545 (if (re-search-forward
2546 (concat "\n--" boundary) nil t)
2547 (setq end (match-beginning 0))
2548 (setq end (point-max))
2551 (narrow-to-region beg end)
2552 (mime-editor::edit-again code-conversion)
2553 (goto-char (point-max))
2556 (goto-char (point-min))
2557 (or (= (point-min) 1)
2558 (delete-region (point-min)
2559 (if (re-search-forward "^$" nil t)
2567 (mapconcat (function
2569 (if (string-equal (car attr)
2572 (setq charset (cdr attr))
2574 (concat ";" (car attr)
2582 (if (re-search-forward
2583 "Content-Transfer-Encoding:" nil t)
2584 (let ((beg (match-beginning 0))
2585 (hbeg (match-end 0))
2586 (end (rfc822/field-end)))
2588 (eliminate-top-spaces
2589 (rfc822/unfolding-string
2590 (buffer-substring hbeg end))))
2591 (if (or charset (string-equal type "text"))
2593 (delete-region beg (1+ end))
2594 (goto-char (point-min))
2595 (if (search-forward "\n\n" nil t)
2598 (match-end 0)(point-max) encoding)
2602 (if (or code-conversion encoded)
2604 (mime-charset-decode-region (point-min)(point-max)
2606 (character-decode-region (point-min)(point-max)
2607 mime/default-coding-system)
2610 (if (re-search-forward "^$" nil t)
2614 (if (= (point-min) 1)
2621 (concat type "/" stype pstr) encoding)
2624 (delete-region (point-min) he)
2628 (concat type "/" stype pstr) encoding)
2633 (character-decode-region (point-min) (point-max)
2634 mime/default-coding-system)
2638 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2640 (mime-editor::edit-again code-conversion)
2641 (goto-char (point-min))
2643 (narrow-to-region (point-min)
2644 (if (re-search-forward "^$" nil t)
2648 (goto-char (point-min))
2649 (while (re-search-forward
2650 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2651 (delete-region (match-beginning 0) (1+ (rfc822/field-end)))
2654 (and (re-search-forward "^$")
2655 (replace-match mail-header-separator)
2667 (run-hooks 'tm-edit-load-hook)
2669 ;;; tm-edit.el ends here