1 ;;; tm-edit.el --- Simple MIME Composer for GNU Emacs
3 ;; Copyright (C) 1993 .. 1996 Free Software Foundation, Inc.
5 ;; Author: UMEDA Masanobu <umerin@mse.kyutech.ac.jp>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Created: 1994/08/21 renamed from mime.el
9 ;; Version: $Revision: 7.90 $
10 ;; Keywords: mail, news, MIME, multimedia, multilingual
12 ;; This file is part of tm (Tools for MIME).
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;; This is an Emacs minor mode for editing Internet multimedia
32 ;; messages formatted in MIME (RFC 1521 and RFC 1522). All messages in
33 ;; this mode are composed in the tagged MIME format, that are
34 ;; described in the following examples. The messages composed in the
35 ;; tagged MIME format are automatically translated into a MIME
36 ;; compliant message when exiting the mode.
38 ;; Mule (a multilingual extension to Emacs 18 and 19) has a capability
39 ;; of handling multilingual text in limited ISO-2022 manner that is
40 ;; based on early experiences in Japanese Internet community and
41 ;; resulted in RFC 1468 (ISO-2022-JP charset for MIME). In order to
42 ;; enable multilingual capability in single text message in MIME,
43 ;; charset of multilingual text written in Mule is declared as either
44 ;; `ISO-2022-JP-2' [RFC 1554] or `ISO-2022-INT-1'. Mule is required
45 ;; for reading the such messages.
47 ;; This MIME composer can work with Mail mode, mh-e letter Mode, and
48 ;; News mode. First of all, you need the following autoload
49 ;; definition to load mime/editor-mode automatically:
51 ;; (autoload 'mime/editor-mode "tm-edit"
52 ;; "Minor mode for editing MIME message." t)
54 ;; In case of Mail mode (includes VM mode), you need the following
57 ;; (add-hook 'mail-mode-hook 'mime/editor-mode)
58 ;; (add-hook 'mail-send-hook 'mime-editor/maybe-translate)
60 ;; In case of MH-E, you need the following hook definition:
62 ;; (add-hook 'mh-letter-mode-hook
66 ;; (make-local-variable 'mail-header-separator)
67 ;; (setq mail-header-separator "--------")
69 ;; (add-hook 'mh-before-send-letter-hook 'mime-editor/maybe-translate)
71 ;; In case of News mode, you need the following hook definition:
73 ;; (add-hook 'news-reply-mode-hook 'mime/editor-mode)
74 ;; (add-hook 'news-inews-hook 'mime-editor/maybe-translate)
76 ;; In case of Emacs 19, it is possible to emphasize the message tags
77 ;; using font-lock mode as follows:
79 ;; (add-hook 'mime/editor-mode-hook
83 ;; (setq font-lock-keywords (list mime-editor/tag-regexp))
86 ;; The message tag looks like:
88 ;; --[[TYPE/SUBTYPE;PARAMETERS][ENCODING]]
90 ;; The tagged MIME message examples:
92 ;; This is a conventional plain text. It should be translated into
96 ;; This is also a plain text. But, it is explicitly specified as is.
98 ;;--[[text/plain; charset=ISO-2022-JP]]
99 ;;
\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.
101 ;;--[[text/richtext]]
102 ;; <center>This is a richtext.</center>
104 ;;--[[image/gif][base64]]^M...image encoded in base64 comes here...
106 ;;--[[audio/basic][base64]]^M...audio encoded in base64 comes here...
111 (require 'mail-utils)
123 (defconst mime-editor/RCS-ID
124 "$Id: tm-edit.el,v 7.90 1996/10/07 14:30:50 shuhei-k Exp $")
126 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
128 (defconst mime-editor/version-name
129 (concat "tm-edit " mime-editor/version))
135 (defvar mime-prefix "\C-c\C-x"
136 "*Keymap prefix for MIME commands.")
138 (defvar mime-ignore-preceding-spaces nil
139 "*Ignore preceding white spaces if non-nil.")
141 (defvar mime-ignore-trailing-spaces nil
142 "*Ignore trailing white spaces if non-nil.")
144 (defvar mime-ignore-same-text-tag t
145 "*Ignore preceding text content-type tag that is same with new one.
146 If non-nil, the text tag is not inserted unless something different.")
148 (defvar mime-auto-hide-body t
149 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
151 (defvar mime-editor/voice-recorder
152 (function mime-editor/voice-recorder-for-sun)
153 "*Function to record a voice message and encode it. [tm-edit.el]")
155 (defvar mime/editor-mode-hook nil
156 "*Hook called when enter MIME mode.")
158 (defvar mime-editor/translate-hook nil
159 "*Hook called before translating into a MIME compliant message.
160 To insert a signature file automatically, call the function
161 `mime-editor/insert-signature' from this hook.")
163 (defvar mime-editor/exit-hook nil
164 "*Hook called when exit MIME mode.")
166 (defvar mime-content-types
168 ;; Charset parameter need not to be specified, since it is
169 ;; defined automatically while translation.
171 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
174 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
177 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
180 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
183 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
191 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
192 ("directory" "/pub/GNU/elisp/mime")
194 ("mode" "image" "ascii" "local8"))
199 ("mode" "image" "ascii" "local8"))
200 ("tftp" ("site") ("name"))
201 ("afs" ("site") ("name"))
202 ("local-file" ("site") ("name"))
203 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
208 ("octet-stream" ("type" "" "tar" "shar"))
210 ("x-kiss" ("x-cnf")))
223 "*Alist of content-type, subtype, parameters and its values.")
225 (defvar mime-file-types
227 "text" "richtext" nil
235 "application" "postscript" nil
237 "attachment" (("filename" . file))
242 "inline" (("filename" . file))
247 "inline" (("filename" . file))
252 "inline" (("filename" . file))
257 "inline" (("filename" . file))
262 "inline" (("filename" . file))
267 "inline" (("filename" . file))
272 "inline" (("filename" . file))
277 "attachment" (("filename" . file))
282 "attachment" (("filename" . file))
285 "application" "octet-stream" (("type" . "emacs-lisp"))
287 "attachment" (("filename" . file))
290 "application" "octet-stream" (("type" . "common-lisp"))
292 "attachment" (("filename" . file))
295 "application" "octet-stream" (("type" . "tar+gzip"))
297 "attachment" (("filename" . file))
300 "application" "octet-stream" (("type" . "tar+gzip"))
302 "attachment" (("filename" . file))
305 "application" "octet-stream" (("type" . "tar+compress"))
307 "attachment" (("filename" . file))
310 "application" "octet-stream" (("type" . "tar+compress"))
312 "attachment" (("filename" . file))
315 "application" "octet-stream" (("type" . "gzip"))
317 "attachment" (("filename" . file))
320 "application" "octet-stream" (("type" . "compress"))
322 "attachment" (("filename" . file))
325 "application" "octet-stream" (("type" . "lha"))
327 "attachment" (("filename" . file))
330 "application" "zip" nil
332 "attachment" (("filename" . file))
335 "application" "octet-stream" (("type" . "patch"))
337 "attachment" (("filename" . file))
340 "application" "octet-stream" (("type" . "patch"))
342 "attachment" (("filename" . file))
345 "text" "plain" nil nil)
347 "application" "octet-stream" nil
349 "attachment" (("filename" . file))
352 "*Alist of file name, types, parameters, and default encoding.
353 If encoding is nil, it is determined from its contents.")
355 ;;; @@ about charset, encoding and transfer-level
358 (defvar mime-editor/transfer-level 7
359 "*A number of network transfer level. It should be bigger than 7.")
360 (make-variable-buffer-local 'mime-editor/transfer-level)
362 (defvar mime-editor/transfer-level-string
363 (mime/encoding-name mime-editor/transfer-level 'not-omit)
364 "*A string formatted version of mime/defaul-transfer-level")
365 (make-variable-buffer-local 'mime-editor/transfer-level-string)
367 (defun mime-editor/make-charset-default-encoding-alist (transfer-level)
369 (lambda (charset-type)
370 (let ((charset (car charset-type))
371 (type (nth 1 charset-type))
372 (encoding (nth 2 charset-type))
374 (if (<= type transfer-level)
375 (cons charset (mime/encoding-name type))
376 (cons charset encoding)
378 mime-charset-type-list))
380 (defvar mime-editor/charset-default-encoding-alist
381 (mime-editor/make-charset-default-encoding-alist mime-editor/transfer-level))
382 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
384 ;;; @@ about message inserting
387 (defvar mime-editor/yank-ignored-field-list
388 '("Received" "Approved" "Path" "Replied" "Status"
389 "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
390 "Delete these fields from original message when it is inserted
391 as message/rfc822 part.
392 Each elements are regexp of field-name. [tm-edit.el]")
394 (defvar mime-editor/yank-ignored-field-regexp
396 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
399 (defvar mime-editor/message-inserter-alist nil)
400 (defvar mime-editor/mail-inserter-alist nil)
402 ;;; @@ about message splitting
405 (defvar mime-editor/split-message t
406 "*Split large message if it is non-nil. [tm-edit.el]")
408 (defvar mime-editor/message-default-max-length 1000
409 "*Default maximum size of a message. [tm-edit.el]")
411 (defvar mime-editor/message-max-length-alist
412 '((news-reply-mode . 500)))
414 (defconst mime-editor/split-ignored-field-regexp
415 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
417 (defvar mime-editor/split-blind-field-regexp
418 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
420 (defvar mime-editor/split-message-sender-alist nil)
422 (defvar mime-editor/news-reply-mode-server-running nil)
428 (defvar mime-editor/signing-type nil
429 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
431 (defvar mime-editor/encrypting-type nil
432 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
434 (if (or mime-editor/signing-type mime-editor/encrypting-type)
442 (defconst mime-editor/single-part-tag-regexp
443 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
444 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
446 (defconst mime-editor/quoted-single-part-tag-regexp
447 (concat "- " (substring mime-editor/single-part-tag-regexp 1)))
449 (defconst mime-editor/multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
451 (defconst mime-editor/multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
453 (defconst mime-editor/beginning-tag-regexp
454 (regexp-or mime-editor/single-part-tag-regexp
455 mime-editor/multipart-beginning-regexp))
457 (defconst mime-editor/end-tag-regexp
458 (regexp-or mime-editor/single-part-tag-regexp
459 mime-editor/multipart-end-regexp))
461 (defconst mime-editor/tag-regexp
462 (regexp-or mime-editor/single-part-tag-regexp
463 mime-editor/multipart-beginning-regexp
464 mime-editor/multipart-end-regexp))
466 (defvar mime-tag-format "--[[%s]]"
467 "*Control-string making a MIME tag.")
469 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
470 "*Control-string making a MIME tag with encoding.")
472 ;;; @@ multipart boundary
475 (defvar mime-multipart-boundary "Multipart"
476 "*Boundary of a multipart message.")
479 ;;; @@ buffer local variables
482 (defvar mime/editor-mode-old-local-map nil)
483 (defvar mime/editing-buffer nil)
489 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
490 "*Specify MIME tspecials.
491 Tspecials means any character that matches with it in header must be quoted.")
493 (defconst mime-editor/mime-version-value
494 (concat "1.0 (generated by " mime-editor/version-name ")")
495 "MIME version number.")
497 (defconst mime-editor/mime-map (make-sparse-keymap)
498 "Keymap for MIME commands.")
500 ;;; @ keymap and menu
503 (defvar mime/editor-mode-flag nil)
504 (make-variable-buffer-local 'mime/editor-mode-flag)
506 (defun mime-editor/define-keymap (keymap)
507 "Add mime-editor commands to KEYMAP."
508 (if (not (keymapp keymap))
510 (define-key keymap "\C-t" 'mime-editor/insert-text)
511 (define-key keymap "\C-i" 'mime-editor/insert-file)
512 (define-key keymap "\C-e" 'mime-editor/insert-external)
513 (define-key keymap "\C-v" 'mime-editor/insert-voice)
514 (define-key keymap "\C-y" 'mime-editor/insert-message)
515 (define-key keymap "\C-m" 'mime-editor/insert-mail)
516 (define-key keymap "\C-w" 'mime-editor/insert-signature)
517 (define-key keymap "\C-s" 'mime-editor/insert-signature)
518 (define-key keymap "\C-k" 'mime-editor/insert-key)
519 (define-key keymap "t" 'mime-editor/insert-tag)
520 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
521 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
522 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
523 (define-key keymap "d" 'mime-editor/enclose-digest-region)
524 (define-key keymap "s" 'mime-editor/enclose-signed-region)
525 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
526 (define-key keymap "q" 'mime-editor/enclose-quote-region)
527 (define-key keymap "7" 'mime-editor/set-transfer-level-7bit)
528 (define-key keymap "8" 'mime-editor/set-transfer-level-8bit)
529 (define-key keymap "/" 'mime-editor/set-split)
530 (define-key keymap "v" 'mime-editor/set-sign)
531 (define-key keymap "h" 'mime-editor/set-encrypt)
532 (define-key keymap "\C-p" 'mime-editor/preview-message)
533 (define-key keymap "\C-z" 'mime-editor/exit)
534 (define-key keymap "?" 'mime-editor/help)
537 (mime-editor/define-keymap mime-editor/mime-map)
539 (defun mime-editor/toggle-mode ()
541 (if mime/editor-mode-flag
542 (mime-editor/exit 'nomime)
546 (cond (running-xemacs
547 (defconst mime-editor/minor-mime-map nil "Keymap for MIME commands.")
548 (or mime-editor/minor-mime-map
550 (setq mime-editor/minor-mime-map
551 (make-sparse-keymap 'mime-editor/minor-mime-map))
553 mime-editor/minor-mime-map mime-prefix mime-editor/mime-map)
555 (add-minor-mode 'mime/editor-mode-flag
556 '((" MIME-Edit " mime-editor/transfer-level-string))
557 mime-editor/minor-mime-map
559 'mime-editor/toggle-mode)
562 (set-alist 'minor-mode-alist
563 'mime/editor-mode-flag
564 '((" MIME-Edit " mime-editor/transfer-level-string))))
567 (defconst mime-editor/menu-title "MIME-Edit")
569 (defconst mime-editor/menu-list
570 '((mime-help "Describe MIME editor mode" mime-editor/help)
571 (file "Insert File" mime-editor/insert-file)
572 (external "Insert External" mime-editor/insert-external)
573 (voice "Insert Voice" mime-editor/insert-voice)
574 (message "Insert Message" mime-editor/insert-message)
575 (mail "Insert Mail" mime-editor/insert-mail)
576 (signature "Insert Signature" mime-editor/insert-signature)
577 (text "Insert Text" mime-editor/insert-text)
578 (tag "Insert Tag" mime-editor/insert-tag)
579 (alternative "Enclose as alternative"
580 mime-editor/enclose-alternative-region)
581 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
582 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
583 (digest "Enclose as digest" mime-editor/enclose-digest-region)
584 (signed "Enclose as signed" mime-editor/enclose-signed-region)
585 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
586 (quote "Verbatim region" mime-editor/enclose-quote-region)
587 (key "Insert Public Key" mime-editor/insert-key)
588 (split "About split" mime-editor/set-split)
589 (sign "About sign" mime-editor/set-sign)
590 (encrypt "About encryption" mime-editor/set-encrypt)
591 (preview "Preview Message" mime-editor/preview-message)
592 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
594 "MIME-edit menubar entry.")
596 (defun mime-editor/define-menu-for-emacs19 ()
597 "Define menu for Emacs 19."
598 (define-key (current-local-map) [menu-bar mime-edit]
599 (cons mime-editor/menu-title
600 (make-sparse-keymap mime-editor/menu-title)))
603 (define-key (current-local-map)
604 (vector 'menu-bar 'mime-edit (car item))
605 (cons (nth 1 item)(nth 2 item))
608 (reverse mime-editor/menu-list)
611 ;;; modified by Pekka Marjola <pema@iki.fi>
612 ;;; 1995/9/5 (c.f. [tm-en:69])
613 (defun mime-editor/define-menu-for-xemacs ()
614 "Define menu for Emacs 19."
615 (cond ((featurep 'menubar)
616 (make-local-variable 'current-menubar)
617 (set-buffer-menubar current-menubar)
619 (cons mime-editor/menu-title
622 (vector (nth 1 item)(nth 2 item)
623 mime/editor-mode-flag)
625 mime-editor/menu-list)))
628 ;;; modified by Steven L. Baur <steve@miranova.com>
629 ;;; 1995/12/6 (c.f. [tm-en:209])
630 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
631 (setq mime-editor/popup-menu-for-xemacs
632 (append '("MIME Commands" "---")
633 (mapcar (function (lambda (item)
637 mime-editor/menu-list)))
646 (defun mime/editor-mode ()
647 "MIME minor mode for editing the tagged MIME message.
649 In this mode, basically, the message is composed in the tagged MIME
650 format. The message tag looks like:
652 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
654 The tag specifies the MIME content type, subtype, optional parameters
655 and transfer encoding of the message following the tag. Messages
656 without any tag are treated as `text/plain' by default. Charset and
657 transfer encoding are automatically defined unless explicitly
658 specified. Binary messages such as audio and image are usually hidden.
659 The messages in the tagged MIME format are automatically translated
660 into a MIME compliant message when exiting this mode.
662 Available charsets depend on Emacs version being used. The following
663 lists the available charsets of each emacs.
665 EMACS 18: US-ASCII is only available.
666 NEmacs: US-ASCII and ISO-2022-JP are available.
667 EMACS 19: US-ASCII and ISO-8859-1 (or other charset) are available.
668 XEmacs 19: US-ASCII and ISO-8859-1 (or other charset) are available.
669 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
670 ISO-2022-JP, ISO-2022-JP-2, ISO-2022-KR, BIG5 and
671 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 If you want to use non-ISO-8859-1 charset in EMACS 19 or XEmacs 19,
679 please set variable `default-mime-charset'. This variable must be
680 symbol of which name is a MIME charset.
682 If you want to add more charsets in mule, please set variable
683 `charsets-mime-charset-alist'. This variable must be alist of which
684 key is list of leading-char/charset and value is symbol of MIME
685 charset. (leading-char is a term of MULE 1.* and 2.*. charset is a
686 term of XEmacs/mule, mule merged EMACS and MULE 3.*) If name of
687 coding-system is different as MIME charset, please set variable
688 `mime-charset-coding-system-alist'. This variable must be alist of
689 which key is MIME charset and value is coding-system.
691 Following commands are available in addition to major mode commands:
692 \\[mime-editor/insert-text] insert a text message.
693 \\[mime-editor/insert-file] insert a (binary) file.
694 \\[mime-editor/insert-external] insert a reference to external body.
695 \\[mime-editor/insert-voice] insert a voice message.
696 \\[mime-editor/insert-message] insert a mail or news message.
697 \\[mime-editor/insert-mail] insert a mail message.
698 \\[mime-editor/insert-signature] insert a signature file at end.
699 \\[mime-editor/insert-tag] insert a new MIME tag.
700 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
701 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
702 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
703 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
704 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
705 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
706 \\[mime-editor/insert-key] insert PGP public key.
707 \\[mime-editor/preview-message] preview editing MIME message.
708 \\[mime-editor/exit] exit and translate into a MIME compliant message.
709 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
710 \\[mime-editor/help] show this help.
712 Additional commands are available in some major modes:
713 C-c C-c exit, translate and run the original command.
714 C-c C-s exit, translate and run the original command.
716 The following is a message example written in the tagged MIME format.
717 TABs at the beginning of the line are not a part of the message:
719 This is a conventional plain text. It should be translated
722 This is also a plain text. But, it is explicitly specified as
724 --[[text/plain; charset=ISO-2022-JP]]
725 \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
728 <center>This is a richtext.</center>
729 --[[image/gif][base64]]^M...image encoded in base64 here...
730 --[[audio/basic][base64]]^M...audio encoded in base64 here...
732 User customizable variables (not documented all of them):
734 Specifies a key prefix for MIME minor mode commands.
736 mime-ignore-preceding-spaces
737 Preceding white spaces in a message body are ignored if non-nil.
739 mime-ignore-trailing-spaces
740 Trailing white spaces in a message body are ignored if non-nil.
742 mime-auto-fill-header
743 Fill header fields that contain encoded-words if non-nil.
746 Hide a non-textual body message encoded in base64 after insertion
749 mime-editor/voice-recorder
750 Specifies a function to record a voice message and encode it.
751 The function `mime-editor/voice-recorder-for-sun' is for Sun
754 mime/editor-mode-hook
755 Turning on MIME mode calls the value of mime/editor-mode-hook, if
758 mime-editor/translate-hook
759 The value of mime-editor/translate-hook is called just before translating
760 the tagged MIME format into a MIME compliant message if it is
761 non-nil. If the hook call the function mime-editor/insert-signature,
762 the signature file will be inserted automatically.
764 mime-editor/exit-hook
765 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
768 (if mime/editor-mode-flag
769 (error "You are already editing a MIME message.")
770 (setq mime/editor-mode-flag t)
771 ;; Remember old key bindings.
773 (use-local-map (or (current-local-map) (make-sparse-keymap)))
774 (make-local-variable 'mime/editor-mode-old-local-map)
775 (setq mime/editor-mode-old-local-map (current-local-map))
776 ;; Add MIME commands to current local map.
777 (use-local-map (copy-keymap (or (current-local-map)
778 (make-sparse-keymap))))
780 (if (not (lookup-key (current-local-map) mime-prefix))
781 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
783 ;; Set transfer level into mode line
785 (setq mime-editor/transfer-level-string
786 (mime/encoding-name mime-editor/transfer-level 'not-omit))
787 (force-mode-line-update)
789 ;; Define menu. Menus for other emacs implementations are
791 (cond (running-xemacs
792 (mime-editor/define-menu-for-xemacs))
793 ((>= emacs-major-version 19)
794 (mime-editor/define-menu-for-emacs19)
800 ;; I don't care about saving these.
801 (setq paragraph-start
802 (regexp-or mime-editor/single-part-tag-regexp
804 (setq paragraph-separate
805 (regexp-or mime-editor/single-part-tag-regexp
807 (run-hooks 'mime/editor-mode-hook)
809 (substitute-command-keys
810 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
814 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
815 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
817 (defun mime-editor/exit (&optional nomime no-error)
818 "Translate the tagged MIME message into a MIME compliant message.
819 With no argument encode a message in the buffer into MIME, otherwise
820 just return to previous mode."
822 (if (not mime/editor-mode-flag)
824 (error "You aren't editing a MIME message.")
828 (run-hooks 'mime-editor/translate-hook)
829 (mime-editor/translate-buffer)))
830 ;; Restore previous state.
831 (setq mime/editor-mode-flag nil)
832 (cond (running-xemacs
833 (delete-menu-item (list mime-editor/menu-title)))
835 (use-local-map mime/editor-mode-old-local-map)))
838 (set-buffer-modified-p (buffer-modified-p))
839 (run-hooks 'mime-editor/exit-hook)
840 (message "Exit MIME editor mode.")
843 (defun mime-editor/maybe-translate ()
845 (mime-editor/exit nil t)
846 (call-interactively 'mime-editor/maybe-split-and-send)
849 (defun mime-editor/help ()
850 "Show help message about MIME mode."
852 (with-output-to-temp-buffer "*Help*"
853 (princ "MIME editor mode:\n")
854 (princ (documentation 'mime/editor-mode))
855 (print-help-return-message)))
857 (defun mime-editor/insert-text ()
858 "Insert a text message.
859 Charset is automatically obtained from the `mime/lc-charset-alist'."
861 (let ((ret (mime-editor/insert-tag "text" nil nil)))
864 (if (looking-at mime-editor/single-part-tag-regexp)
866 ;; Make a space between the following message.
870 (if (and (member (second ret) '("enriched" "richtext"))
871 (fboundp 'enriched-mode)
874 (if (boundp 'enriched-mode)
878 (defun mime-editor/insert-file (file)
879 "Insert a message from a file."
880 (interactive "fInsert file as MIME message: ")
881 (let* ((guess (mime-find-file-type file))
882 (pritype (nth 0 guess))
883 (subtype (nth 1 guess))
884 (parameters (nth 2 guess))
885 (default (nth 3 guess)) ;Guess encoding from its file name.
886 (disposition-type (nth 4 guess))
887 (disposition-params (nth 5 guess))
889 (if (not (interactive-p))
892 (concat "What transfer encoding"
895 (if (string-equal default "")
901 mime-file-encoding-method-alist nil t nil))))
902 (if (string-equal encoding "")
903 (setq encoding default))
904 (if (or (consp parameters) (stringp disposition-type))
905 (let ((rest parameters) cell attribute value)
908 (setq cell (car rest))
909 (setq attribute (car cell))
910 (setq value (cdr cell))
912 (setq value (std11-wrap-as-quoted-string
913 (file-name-nondirectory file)))
915 (setq parameters (concat parameters "; " attribute "=" value))
916 (setq rest (cdr rest))
921 (concat parameters "\n"
922 "Content-Disposition: " disposition-type))
923 (setq rest disposition-params)
925 (setq cell (car rest))
926 (setq attribute (car cell))
927 (setq value (cdr cell))
929 (setq value (std11-wrap-as-quoted-string
930 (file-name-nondirectory file)))
933 (concat parameters "; " attribute "=" value))
934 (setq rest (cdr rest))
938 (mime-editor/insert-tag pritype subtype parameters)
939 (mime-editor/insert-binary-file file encoding)
942 (defun mime-editor/insert-external ()
943 "Insert a reference to external body."
945 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
947 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
949 (let* ((pritype (mime-prompt-for-type))
950 (subtype (mime-prompt-for-subtype pritype))
951 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
954 (insert "Content-Type: "
955 pritype "/" subtype (or parameters "") "\n")))
956 (if (and (not (eobp))
957 (not (looking-at mime-editor/single-part-tag-regexp)))
958 (insert (mime-make-text-tag) "\n")))
960 (defun mime-editor/insert-voice ()
961 "Insert a voice message."
965 "What transfer encoding: "
966 mime-file-encoding-method-alist nil t nil)))
967 (mime-editor/insert-tag "audio" "basic" nil)
968 (mime-editor/define-encoding encoding)
970 (narrow-to-region (1- (point))(point))
972 (funcall mime-editor/voice-recorder encoding)
975 (invisible-region (point-min)(point-max))
976 (goto-char (point-max))
979 (defun mime-editor/insert-signature (&optional arg)
980 "Insert a signature file."
982 (let ((signature-insert-hook
985 (apply (function mime-editor/insert-tag)
986 (mime-find-file-type signature-file-name))
989 (insert-signature arg)
993 ;; Insert a new tag around a point.
995 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
996 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
997 If nothing is inserted, return nil."
1000 (mime-editor/goto-tag)
1001 (if (and (re-search-forward mime-editor/tag-regexp nil t)
1002 (< (match-beginning 0) p)
1005 (goto-char (match-beginning 0))
1014 (mime-prompt-for-type)))
1017 (mime-prompt-for-subtype pritype)))
1020 (mime-prompt-for-parameters pritype subtype delimiter)))
1021 ;; Make a new MIME tag.
1022 (setq newtag (mime-make-tag pritype subtype parameters))
1023 ;; Find an current MIME tag.
1026 (if (mime-editor/goto-tag)
1027 (buffer-substring (match-beginning 0) (match-end 0))
1028 ;; Assume content type is 'text/plan'.
1029 (mime-make-tag "text" "plain")
1031 ;; We are only interested in TEXT.
1033 (not (mime-test-content-type
1034 (mime-editor/get-contype oldtag) "text")))
1037 (if (or (not oldtag) ;Not text
1038 (or mime-ignore-same-text-tag
1039 (not (string-equal oldtag newtag))))
1041 ;; Mark the beginning of the tag for convenience.
1042 (push-mark (point) 'nomsg)
1043 (insert newtag "\n")
1044 (list pritype subtype parameters) ;New tag is created.
1046 ;; Restore previous point.
1048 nil ;Nothing is created.
1052 (defun mime-editor/insert-binary-file (file &optional encoding)
1053 "Insert binary FILE at point.
1054 Optional argument ENCODING specifies an encoding method such as base64."
1055 (let* ((tagend (1- (point))) ;End of the tag
1056 (hide-p (and mime-auto-hide-body
1059 (let ((en (downcase encoding)))
1060 (or (string-equal en "7bit")
1061 (string-equal en "8bit")
1062 (string-equal en "binary")
1066 (narrow-to-region tagend (point))
1067 (mime-insert-encoded-file file encoding)
1070 (invisible-region (point-min) (point-max))
1071 (goto-char (point-max))
1073 (goto-char (point-max))
1076 (looking-at mime-editor/tag-regexp)
1077 (= (point)(point-max))
1078 (mime-editor/insert-tag "text" "plain")
1080 ;; Define encoding even if it is 7bit.
1081 (if (stringp encoding)
1083 (goto-char tagend) ; Make sure which line the tag is on.
1084 (mime-editor/define-encoding encoding)
1089 ;; Commands work on a current message flagment.
1091 (defun mime-editor/goto-tag ()
1092 "Search for the beginning of the tagged MIME message."
1093 (let ((current (point)) multipart)
1094 (if (looking-at mime-editor/tag-regexp)
1096 ;; At first, go to the end.
1097 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1098 (goto-char (1- (match-beginning 0))) ;For multiline tag
1101 (goto-char (point-max))
1103 ;; Then search for the beginning.
1104 (re-search-backward mime-editor/end-tag-regexp nil t)
1105 (or (looking-at mime-editor/beginning-tag-regexp)
1106 ;; Restore previous point.
1113 (defun mime-editor/content-beginning ()
1114 "Return the point of the beginning of content."
1116 (let ((beg (save-excursion
1117 (beginning-of-line) (point))))
1118 (if (mime-editor/goto-tag)
1119 (let ((top (point)))
1120 (goto-char (match-end 0))
1121 (if (and (= beg top)
1122 (= (following-char) ?\^M))
1126 ;; Default text/plain tag.
1127 (goto-char (point-min))
1129 (concat "\n" (regexp-quote mail-header-separator)
1130 (if mime-ignore-preceding-spaces
1131 "[ \t\n]*\n" "\n")) nil 'move)
1135 (defun mime-editor/content-end ()
1136 "Return the point of the end of content."
1138 (let ((beg (point)))
1139 (if (mime-editor/goto-tag)
1140 (let ((top (point)))
1141 (goto-char (match-end 0))
1142 (if (invisible-p (point))
1143 (next-visible-point (point))
1144 ;; Move to the end of this text.
1145 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1146 ;; Don't forget a multiline tag.
1147 (goto-char (match-beginning 0))
1151 ;; Assume the message begins with text/plain.
1152 (goto-char (mime-editor/content-beginning))
1153 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1154 ;; Don't forget a multiline tag.
1155 (goto-char (match-beginning 0)))
1159 (defun mime-editor/define-charset (charset)
1160 "Set charset of current tag to CHARSET."
1162 (if (mime-editor/goto-tag)
1163 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1164 (delete-region (match-beginning 0) (match-end 0))
1167 (mime-editor/set-parameter
1168 (mime-editor/get-contype tag)
1169 "charset" (upcase (symbol-name charset)))
1170 (mime-editor/get-encoding tag)))
1173 (defun mime-editor/define-encoding (encoding)
1174 "Set encoding of current tag to ENCODING."
1176 (if (mime-editor/goto-tag)
1177 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1178 (delete-region (match-beginning 0) (match-end 0))
1179 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1182 (defun mime-editor/choose-charset ()
1183 "Choose charset of a text following current point."
1184 (detect-mime-charset-region (point) (mime-editor/content-end))
1187 (defun mime-make-text-tag (&optional subtype)
1188 "Make a tag for a text after current point.
1189 Subtype of text type can be specified by an optional argument SUBTYPE.
1190 Otherwise, it is obtained from mime-content-types."
1191 (let* ((pritype "text")
1192 (subtype (or subtype
1193 (car (car (cdr (assoc pritype mime-content-types)))))))
1194 ;; Charset should be defined later.
1195 (mime-make-tag pritype subtype)))
1198 ;; Tag handling functions
1200 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1201 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1202 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1206 (defun mime-create-tag (contype &optional encoding)
1207 "Make a tag with CONTENT-TYPE and optional ENCODING."
1208 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1211 (defun mime-editor/get-contype (tag)
1212 "Return Content-Type (including parameters) of TAG."
1214 (or (string-match mime-editor/single-part-tag-regexp tag)
1215 (string-match mime-editor/multipart-beginning-regexp tag)
1216 (string-match mime-editor/multipart-end-regexp tag)
1218 (substring tag (match-beginning 1) (match-end 1))
1221 (defun mime-editor/get-encoding (tag)
1222 "Return encoding of TAG."
1224 (string-match mime-editor/single-part-tag-regexp tag)
1226 (not (= (match-beginning 3) (match-end 3)))
1227 (substring tag (match-beginning 3) (match-end 3))))
1229 (defun mime-get-parameter (contype parameter)
1230 "For given CONTYPE return value for PARAMETER.
1231 Nil if no such parameter."
1235 (regexp-quote parameter)
1236 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1238 (substring contype (match-beginning 1) (match-end 1))
1239 nil ;No such parameter
1242 (defun mime-editor/set-parameter (contype parameter value)
1243 "For given CONTYPE set PARAMETER to VALUE."
1244 (let (ctype opt-fields)
1245 (if (string-match "\n[^ \t\n\r]+:" contype)
1246 (setq ctype (substring contype 0 (match-beginning 0))
1247 opt-fields (substring contype (match-beginning 0)))
1248 (setq ctype contype)
1253 (regexp-quote parameter)
1254 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1257 (concat (substring ctype 0 (match-beginning 1))
1259 (substring contype (match-end 1))
1261 (concat ctype "; " parameter "=" value opt-fields)
1264 (defun mime-strip-parameters (contype)
1265 "Return primary content-type and subtype without parameters for CONTYPE."
1266 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1267 (substring contype (match-beginning 1) (match-end 1)) nil))
1269 (defun mime-test-content-type (contype type &optional subtype)
1270 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1271 (and (stringp contype)
1274 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1275 (downcase contype))))
1280 (defun mime-find-file-type (file)
1281 "Guess Content-Type, subtype, and parameters from FILE."
1283 (guesses mime-file-types))
1284 (while (and (not guess) guesses)
1285 (if (string-match (car (car guesses)) file)
1286 (setq guess (cdr (car guesses))))
1287 (setq guesses (cdr guesses)))
1291 (defun mime-prompt-for-type ()
1292 "Ask for Content-type."
1294 ;; Repeat until primary content type is specified.
1295 (while (string-equal type "")
1297 (completing-read "What content type: "
1300 'require-match ;Type must be specified.
1303 (if (string-equal type "")
1305 (message "Content type is required.")
1313 (defun mime-prompt-for-subtype (pritype)
1314 "Ask for Content-type subtype of Content-Type PRITYPE."
1315 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1320 "What content subtype: (default " default ") ")
1321 "What content subtype: ")
1322 (cdr (assoc pritype mime-content-types))
1324 'require-match ;Subtype must be specified.
1327 (if (string-equal answer "") default answer)))
1329 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1330 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1331 Optional DELIMITER specifies parameter delimiter (';' by default)."
1332 (let* ((delimiter (or delimiter "; "))
1337 (mime-prompt-for-parameters-1
1339 (cdr (assoc pritype mime-content-types))))))
1342 (if (and (stringp parameters)
1343 (not (string-equal parameters "")))
1344 (concat delimiter parameters)
1345 "" ;"" if no parameters
1348 (defun mime-prompt-for-parameters-1 (optlist)
1349 (apply (function append)
1350 (mapcar (function mime-prompt-for-parameter) optlist)))
1352 (defun mime-prompt-for-parameter (parameter)
1354 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1355 (let* ((prompt (car parameter))
1356 (choices (mapcar (function
1358 (if (consp e) e (list e))))
1360 (default (car (car choices)))
1366 (concat "What " prompt
1368 (if (string-equal default "") "\"\"" default)
1370 choices nil nil ""))
1371 ;; If nothing is selected, use default.
1372 (if (string-equal answer "")
1373 (setq answer default)))
1375 (read-string (concat "What " prompt ": "))))
1376 (cons (if (and answer
1377 (not (string-equal answer "")))
1379 ;; Note: control characters ignored!
1380 (if (string-match mime-tspecials-regexp answer)
1381 (concat "\"" answer "\"") answer)))
1382 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1385 (defun mime-flag-region (from to flag)
1386 "Hides or shows lines from FROM to TO, according to FLAG.
1387 If FLAG is `\\n' (newline character) then text is shown,
1388 while if FLAG is `\\^M' (control-M) the text is hidden."
1389 (let ((buffer-read-only nil) ;Okay even if write protected.
1390 (modp (buffer-modified-p)))
1392 (subst-char-in-region from to
1393 (if (= flag ?\n) ?\^M ?\n)
1395 (set-buffer-modified-p modp))))
1398 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1401 (defvar mime-editor/translate-buffer-hook
1402 '(mime-editor/pgp-enclose-buffer
1403 mime-editor/translate-header
1404 mime-editor/translate-body))
1406 (defun mime-editor/translate-header ()
1407 "Encode the message header into network representation."
1408 (mime/encode-message-header 'code-conversion)
1409 (run-hooks 'mime-editor/translate-header-hook)
1412 (defun mime-editor/translate-buffer ()
1413 "Encode the tagged MIME message in current buffer in MIME compliant message."
1415 (if (catch 'mime-editor/error
1417 (run-hooks 'mime-editor/translate-buffer-hook)
1421 (error "Translation error!")
1424 (defun mime-editor/find-inmost ()
1425 (goto-char (point-min))
1426 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1427 (let ((bb (match-beginning 0))
1429 (type (buffer-substring (match-beginning 1)(match-end 1)))
1431 (setq end-exp (format "--}-<<%s>>\n" type))
1433 (if (re-search-forward end-exp nil t)
1435 (setq eb (match-beginning 0))
1436 (setq ee (match-end 0))
1438 (setq eb (point-max))
1439 (setq ee (point-max))
1441 (narrow-to-region be eb)
1443 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1445 (narrow-to-region (match-beginning 0)(point-max))
1446 (mime-editor/find-inmost)
1449 (list type bb be eb)
1452 (defun mime-editor/process-multipart-1 (boundary)
1453 (let ((ret (mime-editor/find-inmost)))
1455 (let ((type (car ret))
1456 (bb (nth 1 ret))(be (nth 2 ret))
1459 (narrow-to-region bb eb)
1460 (delete-region bb be)
1461 (setq bb (point-min))
1462 (setq eb (point-max))
1465 (if (looking-at mime-editor/multipart-end-regexp)
1466 (let ((beg (match-beginning 0))
1469 (delete-region beg end)
1470 (or (looking-at mime-editor/beginning-tag-regexp)
1472 (insert (concat (mime-make-text-tag) "\n"))
1474 (cond ((string-equal type "quote")
1475 (mime-editor/enquote-region bb eb)
1477 ((string-equal 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-equal 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"
1504 (defun mime-editor/enquote-region (beg end)
1507 (narrow-to-region beg end)
1509 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1510 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1511 (replace-match (concat "- " (substring tag 1)))
1514 (defun mime-editor/dequote-region (beg end)
1517 (narrow-to-region beg end)
1519 (while (re-search-forward
1520 mime-editor/quoted-single-part-tag-regexp nil t)
1521 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1522 (replace-match (concat "-" (substring tag 2)))
1525 (autoload 'mc-pgp-lookup-key "mc-pgp")
1526 (autoload 'mc-pgp-sign-region "mc-pgp")
1527 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1529 (defun tm:mc-pgp-generic-parser (result)
1530 (let ((ret (mc-pgp-generic-parser result)))
1532 (vector (car ret)(cdr ret))
1535 (defun tm:mc-process-region
1536 (beg end passwd program args parser &optional buffer boundary)
1537 (let ((obuf (current-buffer))
1538 (process-connection-type nil)
1539 mybuf result rgn proc)
1542 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1546 (buffer-disable-undo mybuf)
1548 (apply 'start-process "*PGP*" mybuf program args))
1551 (process-send-string proc (concat passwd "\n"))
1552 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1553 (process-send-region proc beg end)
1554 (process-send-eof proc)
1555 (while (eq 'run (process-status proc))
1556 (accept-process-output proc 5))
1557 (setq result (process-exit-status proc))
1558 ;; Hack to force a status_notify() in Emacs 19.29
1559 (delete-process proc)
1561 (goto-char (point-max))
1562 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1563 (delete-region (match-beginning 0) (match-end 0)))
1564 (goto-char (point-min))
1566 (while (search-forward "\r\n" nil t)
1567 (replace-match "\n"))
1568 ;; Hurm. FIXME; must get better result codes.
1569 (if (stringp result)
1570 (error "%s exited abnormally: '%s'" program result)
1571 (setq rgn (funcall parser result))
1572 ;; If the parser found something, migrate it
1578 (narrow-to-region beg end)
1580 (insert (format "--%s\n" boundary))
1581 (goto-char (point-max))
1582 (insert (format "\n--%s
1583 Content-Type: application/pgp-signature
1584 Content-Transfer-Encoding: 7bit
1587 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1588 (goto-char (point-max))
1589 (insert (format "\n--%s--\n" boundary))
1591 (delete-region beg end)
1593 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1596 (delete-region (car rgn) (cdr rgn)))))
1597 ;; Return nil on failure and exit code on success
1599 ;; Cleanup even on nonlocal exit
1600 (if (and proc (eq 'run (process-status proc)))
1601 (interrupt-process proc))
1603 (or buffer (null mybuf) (kill-buffer mybuf)))))
1605 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1606 (if (not (boundp 'mc-pgp-user-id))
1609 (let ((process-environment process-environment)
1610 (buffer (get-buffer-create mc-buffer-name))
1612 (parser (function mc-pgp-generic-parser))
1613 (pgp-path mc-pgp-path)
1615 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1619 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1620 (setenv "PGPPASSFD" "0")
1626 (list "+verbose=1" "+language=en"
1627 (format "+clearsig=%s" (if unclear "off" "on"))
1628 "+batchmode" "-u" (cdr key))))
1630 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1632 (message "Signing as %s ..." (car key))
1633 (if (tm:mc-process-region
1634 start end passwd pgp-path args parser buffer boundary)
1638 (goto-char (point-min))
1641 --[[multipart/signed; protocol=\"application/pgp-signature\";
1642 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1644 (message "Signing as %s ... Done." (car key))
1648 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1651 (narrow-to-region beg end)
1653 (mime-editor/translate-region beg end boundary))
1655 (encoding (nth 1 ret))
1657 (pgp-boundary (concat "pgp-sign-" boundary))
1660 (insert (format "Content-Type: %s\n" ctype))
1662 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1665 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1666 nil nil pgp-boundary)
1667 (throw 'mime-editor/error 'pgp-error)
1671 (defvar mime-editor/encrypt-recipient-fields-list '("To" "cc"))
1673 (defun mime-editor/make-encrypt-recipient-header ()
1674 (let* ((names mime-editor/encrypt-recipient-fields-list)
1676 (std11-field-bodies (cons "From" names)
1677 nil mail-header-separator))
1680 (setq values (cdr values))))
1681 (header (and (stringp from)
1682 (if (string-equal from "")
1684 (format "From: %s\n" from)
1687 (while (and names values)
1688 (let ((name (car names))
1689 (value (car values))
1691 (and (stringp value)
1692 (or (string-equal value "")
1694 (setq header (concat header name ": " value "\n")
1695 recipients (if recipients
1696 (concat recipients " ," value)
1699 (setq names (cdr names)
1700 values (cdr values))
1702 (vector from recipients header)
1705 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1708 (let (from recipients header)
1709 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1710 (setq from (aref ret 0)
1711 recipients (aref ret 1)
1712 header (aref ret 2))
1714 (narrow-to-region beg end)
1716 (mime-editor/translate-region beg end boundary))
1718 (encoding (nth 1 ret))
1720 (pgp-boundary (concat "pgp-" boundary))
1724 (insert (format "Content-Type: %s\n" ctype))
1726 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1730 (let ((mc-pgp-always-sign 'never))
1731 (mc-pgp-encrypt-region
1732 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1733 (point-min) (point-max) from nil)
1735 (throw 'mime-editor/error 'pgp-error)
1738 (insert (format "--[[multipart/encrypted;
1740 protocol=\"application/pgp-encrypted\"][7bit]]
1742 Content-Type: application/pgp-encrypted
1745 Content-Type: application/octet-stream
1746 Content-Transfer-Encoding: 7bit
1748 " pgp-boundary pgp-boundary pgp-boundary))
1749 (goto-char (point-max))
1750 (insert (format "\n--%s--\n" pgp-boundary))
1753 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1756 (narrow-to-region beg end)
1758 (mime-editor/translate-region beg end boundary))
1760 (encoding (nth 1 ret))
1764 (insert (format "Content-Type: %s\n" ctype))
1766 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1769 (or (as-binary-process (mc-pgp-sign-region beg (point-max)))
1770 (throw 'mime-editor/error 'pgp-error)
1774 "--[[application/pgp; format=mime][7bit]]\n")
1778 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1780 (let (from recipients header)
1781 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1782 (setq from (aref ret 0)
1783 recipients (aref ret 1)
1784 header (aref ret 2))
1787 (narrow-to-region beg end)
1789 (mime-editor/translate-region beg end boundary))
1791 (encoding (nth 1 ret))
1796 (insert (format "Content-Type: %s\n" ctype))
1798 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1801 (or (as-binary-process
1802 (mc-pgp-encrypt-region
1803 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1806 (throw 'mime-editor/error 'pgp-error)
1810 "--[[application/pgp; format=mime][7bit]]\n")
1814 (defun mime-editor/translate-body ()
1815 "Encode the tagged MIME body in current buffer in MIME compliant message."
1819 (concat mime-multipart-boundary "_"
1820 (replace-space-with-underline (current-time-string))
1824 (while (mime-editor/process-multipart-1
1825 (format "%s-%d" boundary i))
1829 ;; We are interested in message body.
1832 (goto-char (point-min))
1834 (concat "\n" (regexp-quote mail-header-separator)
1835 (if mime-ignore-preceding-spaces
1836 "[ \t\n]*\n" "\n")) nil 'move)
1840 (goto-char (point-max))
1841 (and mime-ignore-trailing-spaces
1842 (re-search-backward "[^ \t\n]\n" beg t)
1845 (setq ret (mime-editor/translate-region
1847 (format "%s-%d" boundary i)))
1849 (mime-editor/dequote-region (point-min)(point-max))
1850 (let ((contype (car ret)) ;Content-Type
1851 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1853 ;; Make primary MIME headers.
1854 (or (mail-position-on-field "Mime-Version")
1855 (insert mime-editor/mime-version-value))
1856 ;; Remove old Content-Type and other fields.
1858 (goto-char (point-min))
1859 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1860 (narrow-to-region (point-min) (point))
1861 (goto-char (point-min))
1862 (mime-delete-field "Content-Type")
1863 (mime-delete-field "Content-Transfer-Encoding"))
1864 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1865 (mail-position-on-field "Content-Type")
1869 (mail-position-on-field "Content-Transfer-Encoding")
1873 (defun mime-editor/translate-single-part-tag (&optional prefix)
1874 (if (re-search-forward mime-editor/single-part-tag-regexp nil t)
1875 (let* ((beg (match-beginning 0))
1877 (tag (buffer-substring beg end))
1879 (delete-region beg end)
1880 (setq contype (mime-editor/get-contype tag))
1881 (setq encoding (mime-editor/get-encoding tag))
1882 (insert (concat prefix "--" boundary "\n"))
1884 (narrow-to-region (point)(point))
1885 (insert "Content-Type: " contype "\n")
1887 (insert "Content-Transfer-Encoding: " encoding "\n"))
1888 (mime/encode-message-header)
1892 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1895 (concat mime-multipart-boundary "_"
1896 (replace-space-with-underline (current-time-string))))
1900 (narrow-to-region beg end)
1901 (let ((tag nil) ;MIME tag
1902 (contype nil) ;Content-Type
1903 (encoding nil) ;Content-Transfer-Encoding
1904 (nparts 0)) ;Number of body parts
1905 ;; Normalize the body part by inserting appropriate message
1906 ;; tags for every message contents.
1907 (mime-editor/normalize-body)
1908 ;; Counting the number of Content-Type.
1909 (goto-char (point-min))
1910 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1911 (setq nparts (1+ nparts)))
1912 ;; Begin translation.
1914 ((and (<= nparts 1)(not multipart))
1915 ;; It's a singular message.
1916 (goto-char (point-min))
1917 (while (re-search-forward
1918 mime-editor/single-part-tag-regexp nil t)
1920 (buffer-substring (match-beginning 0) (match-end 0)))
1921 (delete-region (match-beginning 0) (1+ (match-end 0)))
1922 (setq contype (mime-editor/get-contype tag))
1923 (setq encoding (mime-editor/get-encoding tag))
1926 ;; It's a multipart message.
1927 (goto-char (point-min))
1928 (and (mime-editor/translate-single-part-tag)
1929 (while (mime-editor/translate-single-part-tag "\n"))
1931 ;; Define Content-Type as "multipart/mixed".
1933 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1934 ;; Content-Transfer-Encoding must be "7bit".
1935 ;; The following encoding can be `nil', but is
1936 ;; specified as is since there is no way that a user
1938 (setq encoding "7bit")
1939 ;; Insert the trailer.
1940 (goto-char (point-max))
1941 (insert "\n--" boundary "--\n")
1943 (list contype encoding boundary nparts)
1946 (defun mime-editor/normalize-body ()
1947 "Normalize the body part by inserting appropriate message tags."
1948 ;; Insert the first MIME tags if necessary.
1949 (goto-char (point-min))
1950 (if (not (looking-at mime-editor/single-part-tag-regexp))
1951 (insert (mime-make-text-tag) "\n"))
1952 ;; Check each tag, and add new tag or correct it if necessary.
1953 (goto-char (point-min))
1954 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1955 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1956 (contype (mime-editor/get-contype tag))
1957 (charset (mime-get-parameter contype "charset"))
1958 (encoding (mime-editor/get-encoding tag)))
1959 ;; Remove extra whitespaces after the tag.
1960 (if (looking-at "[ \t]+$")
1961 (delete-region (match-beginning 0) (match-end 0)))
1963 (end (mime-editor/content-end))
1965 (if (= end (point-max))
1968 (or (looking-at mime-editor/beginning-tag-regexp)
1970 (insert (mime-make-text-tag) "\n")
1972 (visible-region beg end)
1976 ((mime-test-content-type contype "message")
1977 ;; Content-type "message" should be sent as is.
1980 ((mime-test-content-type contype "text")
1981 ;; Define charset for text if necessary.
1982 (setq charset (if charset
1983 (intern (downcase charset))
1984 (mime-editor/choose-charset)))
1985 (mime-editor/define-charset charset)
1986 (cond ((string-equal contype "text/x-rot13-47")
1990 (goto-char (mime-editor/content-end))
1993 ((string-equal contype "text/enriched")
1998 (end (mime-editor/content-end))
2000 ;; Patch for hard newlines
2003 ;; (while (search-forward "\n" end t)
2004 ;; (put-text-property (match-beginning 0)
2007 ;; End patch for hard newlines
2008 (enriched-encode beg end)
2010 (if (search-forward "\n\n")
2011 (delete-region beg (match-end 0))
2014 ;; Point is now on current tag.
2015 ;; Define encoding and encode text if necessary.
2016 (or encoding ;Encoding is not specified.
2020 mime-editor/charset-default-encoding-alist)
2022 (beg (mime-editor/content-beginning))
2024 (encode-mime-charset-region beg (mime-editor/content-end)
2026 (mime-encode-region beg (mime-editor/content-end) encoding)
2027 (mime-editor/define-encoding encoding)
2029 (goto-char (mime-editor/content-end))
2031 ((null encoding) ;Encoding is not specified.
2032 ;; Application, image, audio, video, and any other
2033 ;; unknown content-type without encoding should be
2035 (let* ((encoding "base64") ;Encode in BASE64 by default.
2036 (beg (mime-editor/content-beginning))
2037 (end (mime-editor/content-end))
2038 (body (buffer-substring beg end))
2040 (mime-encode-region beg end encoding)
2041 (mime-editor/define-encoding encoding))
2046 (defun mime-delete-field (field)
2047 "Delete header FIELD."
2048 (let ((regexp (format "^%s:[ \t]*" field)))
2049 (goto-char (point-min))
2050 (while (re-search-forward regexp nil t)
2051 (delete-region (match-beginning 0)
2052 (progn (forward-line 1) (point)))
2057 ;;; Platform dependent functions
2060 ;; Sun implementations
2062 (defun mime-editor/voice-recorder-for-sun (encoding)
2063 "Record voice in a buffer using Sun audio device,
2064 and insert data encoded as ENCODING. [tm-edit.el]"
2065 (message "Start the recording on %s. Type C-g to finish the recording..."
2067 (mime-insert-encoded-file "/dev/audio" encoding)
2071 ;;; @ Other useful commands.
2074 ;; Message forwarding commands as content-type "message/rfc822".
2076 (defun mime-editor/insert-message (&optional message)
2078 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2079 (if (and inserter (fboundp inserter))
2081 (mime-editor/insert-tag "message" "rfc822")
2082 (funcall inserter message)
2084 (message "Sorry, I don't have message inserter for your MUA.")
2087 (defun mime-editor/insert-mail (&optional message)
2089 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2090 (if (and inserter (fboundp inserter))
2092 (mime-editor/insert-tag "message" "rfc822")
2093 (funcall inserter message)
2095 (message "Sorry, I don't have mail inserter for your MUA.")
2098 (defun mime-editor/inserted-message-filter ()
2101 (let ((header-start (point))
2102 (case-fold-search t)
2105 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2106 (if (re-search-forward "^$" (mark t))
2107 (narrow-to-region header-start (match-beginning 0))
2109 (goto-char header-start)
2110 (while (and (re-search-forward
2111 mime-editor/yank-ignored-field-regexp nil t)
2112 (setq beg (match-beginning 0))
2113 (setq end (1+ (std11-field-end)))
2115 (delete-region beg end)
2120 ;;; @ multipart enclosure
2123 (defun mime-editor/enclose-region (type beg end)
2126 (let ((current (point)))
2128 (narrow-to-region beg end)
2129 (insert (format "--<<%s>>-{\n" type))
2130 (goto-char (point-max))
2131 (insert (format "--}-<<%s>>\n" type))
2132 (goto-char (point-max))
2134 (or (looking-at mime-editor/beginning-tag-regexp)
2136 (insert (mime-make-text-tag) "\n")
2140 (defun mime-editor/enclose-quote-region (beg end)
2142 (mime-editor/enclose-region "quote" beg end)
2145 (defun mime-editor/enclose-mixed-region (beg end)
2147 (mime-editor/enclose-region "mixed" beg end)
2150 (defun mime-editor/enclose-parallel-region (beg end)
2152 (mime-editor/enclose-region "parallel" beg end)
2155 (defun mime-editor/enclose-digest-region (beg end)
2157 (mime-editor/enclose-region "digest" beg end)
2160 (defun mime-editor/enclose-alternative-region (beg end)
2162 (mime-editor/enclose-region "alternative" beg end)
2165 (defun mime-editor/enclose-signed-region (beg end)
2167 (if mime-editor/signing-type
2168 (mime-editor/enclose-region "signed" beg end)
2169 (message "Please specify signing type.")
2172 (defun mime-editor/enclose-encrypted-region (beg end)
2174 (if mime-editor/signing-type
2175 (mime-editor/enclose-region "encrypted" beg end)
2176 (message "Please specify encrypting type.")
2179 (defun mime-editor/insert-key (&optional arg)
2180 "Insert a pgp public key."
2182 (mime-editor/insert-tag "application" "pgp-keys")
2183 (mime-editor/define-encoding "7bit")
2184 (mc-insert-public-key)
2191 (defun mime-editor/set-split (arg)
2194 (y-or-n-p "Do you want to enable split?")
2196 (setq mime-editor/split-message arg)
2198 (message "This message is enabled to split.")
2199 (message "This message is not enabled to split.")
2202 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2203 "Toggle transfer-level is 7bit or 8bit through.
2205 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2207 (if (numberp transfer-level)
2208 (setq mime-editor/transfer-level transfer-level)
2209 (if (< mime-editor/transfer-level 8)
2210 (setq mime-editor/transfer-level 8)
2211 (setq mime-editor/transfer-level 7)
2213 (setq mime-editor/charset-default-encoding-alist
2214 (mime-editor/make-charset-default-encoding-alist
2215 mime-editor/transfer-level))
2216 (message (format "Current transfer-level is %d bit"
2217 mime-editor/transfer-level))
2218 (setq mime-editor/transfer-level-string
2219 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2220 (force-mode-line-update)
2223 (defun mime-editor/set-transfer-level-7bit ()
2225 (mime-editor/toggle-transfer-level 7)
2228 (defun mime-editor/set-transfer-level-8bit ()
2230 (mime-editor/toggle-transfer-level 8)
2237 (defun mime-editor/set-sign (arg)
2240 (y-or-n-p "Do you want to sign?")
2243 (if mime-editor/signing-type
2245 (setq mime-editor/pgp-processing 'sign)
2246 (message "This message will be signed.")
2248 (message "Please specify signing type.")
2250 (if (eq mime-editor/pgp-processing 'sign)
2251 (setq mime-editor/pgp-processing nil)
2253 (message "This message will not be signed.")
2256 (defun mime-editor/set-encrypt (arg)
2259 (y-or-n-p "Do you want to encrypt?")
2262 (if mime-editor/encrypting-type
2264 (setq mime-editor/pgp-processing 'encrypt)
2265 (message "This message will be encrypt.")
2267 (message "Please specify encrypting type.")
2269 (if (eq mime-editor/pgp-processing 'encrypt)
2270 (setq mime-editor/pgp-processing nil)
2272 (message "This message will not be encrypt.")
2275 (defvar mime-editor/pgp-processing nil)
2276 (make-variable-buffer-local 'mime-editor/pgp-processing)
2278 (defun mime-editor/pgp-enclose-buffer ()
2279 (let ((beg (save-excursion
2280 (goto-char (point-min))
2281 (if (search-forward (concat "\n" mail-header-separator "\n"))
2287 (cond ((eq mime-editor/pgp-processing 'sign)
2288 (mime-editor/enclose-signed-region beg end)
2290 ((eq mime-editor/pgp-processing 'encrypt)
2291 (mime-editor/enclose-encrypted-region beg end)
2299 (defun mime-editor/insert-partial-header
2300 (fields subject id number total separator)
2302 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2303 (insert (format "Mime-Version: 1.0 (split by %s)\n"
2304 mime-editor/version-name))
2306 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2307 id number total separator))
2310 (defun mime-editor/split-and-send
2311 (&optional cmd lines mime-editor/message-max-length)
2315 (count-lines (point-min) (point-max)))
2317 (or mime-editor/message-max-length
2318 (setq mime-editor/message-max-length
2319 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2320 mime-editor/message-default-max-length))
2322 (let* ((mime-editor/draft-file-name
2323 (or (buffer-file-name)
2325 (expand-file-name "tm-draft" mime/tmp-dir))))
2326 (separator mail-header-separator)
2328 (replace-space-with-underline (current-time-string))
2329 "@" (system-name) "\"")))
2330 (run-hooks 'mime-editor/before-split-hook)
2331 (let ((the-buf (current-buffer))
2332 (copy-buf (get-buffer-create " *Original Message*"))
2333 (header (rfc822/get-header-string-except
2334 mime-editor/split-ignored-field-regexp separator))
2335 (subject (mail-fetch-field "subject"))
2336 (total (+ (/ lines mime-editor/message-max-length)
2337 (if (> (mod lines mime-editor/message-max-length) 0)
2343 mime-editor/split-message-sender-alist))
2345 (mime-editor/partial-number 1)
2348 (set-buffer copy-buf)
2350 (insert-buffer the-buf)
2352 (if (re-search-forward
2353 (concat "^" (regexp-quote separator) "$") nil t)
2354 (let ((he (match-beginning 0)))
2356 (narrow-to-region (point-min) he)
2358 (goto-char (point-min))
2359 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
2360 (delete-region (match-beginning 0)
2361 (1+ (std11-field-end)))
2363 (while (< mime-editor/partial-number total)
2366 (set-buffer copy-buf)
2367 (setq data (buffer-substring
2370 (goto-line mime-editor/message-max-length)
2373 (delete-region (point-min)(point))
2375 (mime-editor/insert-partial-header
2376 header subject id mime-editor/partial-number total separator)
2379 (message (format "Sending %d/%d..."
2380 mime-editor/partial-number total))
2381 (call-interactively command)
2382 (message (format "Sending %d/%d... done"
2383 mime-editor/partial-number total))
2385 (setq mime-editor/partial-number
2386 (1+ mime-editor/partial-number))
2390 (set-buffer copy-buf)
2391 (setq data (buffer-string))
2394 (mime-editor/insert-partial-header
2395 header subject id mime-editor/partial-number total separator)
2398 (message (format "Sending %d/%d..."
2399 mime-editor/partial-number total))
2400 (message (format "Sending %d/%d... done"
2401 mime-editor/partial-number total))
2405 (defun mime-editor/maybe-split-and-send (&optional cmd)
2407 (run-hooks 'mime-editor/before-send-hook)
2408 (let ((mime-editor/message-max-length
2409 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2410 mime-editor/message-default-max-length))
2411 (lines (count-lines (point-min) (point-max)))
2413 (if (and (> lines mime-editor/message-max-length)
2414 mime-editor/split-message)
2415 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2419 ;;; @ preview message
2422 (defun mime-editor/preview-message ()
2423 "preview editing MIME message. [tm-edit.el]"
2425 (let* ((str (buffer-string))
2426 (separator mail-header-separator)
2427 (the-buf (current-buffer))
2428 (buf-name (buffer-name))
2429 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2430 (buf (get-buffer temp-buf-name))
2434 (switch-to-buffer buf)
2437 (setq buf (get-buffer-create temp-buf-name))
2438 (switch-to-buffer buf)
2441 (setq major-mode 'mime/temporary-message-mode)
2442 (make-local-variable 'mail-header-separator)
2443 (setq mail-header-separator separator)
2444 (make-local-variable 'mime/editing-buffer)
2445 (setq mime/editing-buffer the-buf)
2447 (run-hooks 'mime-editor/translate-hook)
2448 (mime-editor/translate-buffer)
2449 (goto-char (point-min))
2450 (if (re-search-forward
2451 (concat "^" (regexp-quote separator) "$"))
2457 (defun mime-editor/quitting-method ()
2458 (let ((temp mime::preview/article-buffer)
2460 (mime-viewer/kill-buffer)
2462 (setq buf mime/editing-buffer)
2464 (switch-to-buffer buf)
2467 (set-alist 'mime-viewer/quitting-method-alist
2468 'mime/temporary-message-mode
2469 (function mime-editor/quitting-method)
2475 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2476 ;; Mon, 10 Apr 1995 20:03:07 +0900
2478 (defvar mime-editor/draft-header-separator-alist
2479 '((news-reply-mode . mail-header-separator)
2480 (mh-letter-mode . mail-header-separator)
2483 (defvar mime::article/draft-header-separator nil)
2485 (defun mime-editor/draft-preview ()
2487 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2488 (or (stringp sep) (setq sep (eval sep)))
2489 (make-variable-buffer-local 'mime::article/draft-header-separator)
2490 (goto-char (point-min))
2492 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2493 (setq mime::article/draft-header-separator
2494 (buffer-substring (match-beginning 0) (match-end 0)))
2496 (mime/viewer-mode (current-buffer))
2497 (pop-to-buffer (current-buffer))
2500 (defun mime-viewer::quitting-method/draft-preview ()
2501 (let ((mother mime::preview/mother-buffer))
2503 (switch-to-buffer mother)
2504 (goto-char (point-min))
2508 (regexp-quote mime::article/draft-header-separator)
2512 (insert mime::article/draft-header-separator)
2513 (set-buffer-modified-p (buffer-modified-p))
2515 (mime-viewer/kill-buffer)
2516 (pop-to-buffer mother)
2519 (set-alist 'mime-viewer/quitting-method-alist
2521 (function mime-viewer::quitting-method/draft-preview)
2524 (set-alist 'mime-viewer/quitting-method-alist
2526 (function mime-viewer::quitting-method/draft-preview)
2533 (defun mime-editor::edit-again (code-conversion)
2535 (goto-char (point-min))
2536 (let ((ctl (mime/Content-Type)))
2538 (let ((ctype (car ctl))
2541 (if (string-match "/" ctype)
2543 (setq type (substring ctype 0 (match-beginning 0)))
2544 (setq stype (substring ctype (match-end 0)))
2549 ((string-equal type "multipart")
2550 (let* ((boundary (assoc-value "boundary" params))
2552 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2554 (re-search-forward boundary-pat nil t)
2555 (let ((bb (match-beginning 0)) eb tag)
2556 (setq tag (format "\n--<<%s>>-{\n" stype))
2559 (setq bb (+ bb (length tag)))
2561 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2563 (setq eb (match-beginning 0))
2564 (replace-match (format "--}-<<%s>>\n" stype))
2566 (narrow-to-region bb eb)
2567 (goto-char (point-min))
2568 (while (re-search-forward boundary-pat nil t)
2569 (let ((beg (match-beginning 0))
2571 (delete-region beg (match-end 0))
2573 (if (re-search-forward boundary-pat nil t)
2574 (setq end (match-beginning 0))
2575 (setq end (point-max))
2578 (narrow-to-region beg end)
2579 (mime-editor::edit-again code-conversion)
2580 (goto-char (point-max))
2583 (goto-char (point-min))
2584 (or (= (point-min) 1)
2585 (delete-region (point-min)
2586 (if (search-forward "\n\n" nil t)
2594 (mapconcat (function
2596 (if (string-equal (car attr)
2599 (setq charset (cdr attr))
2601 (concat ";" (car attr)
2609 (if (re-search-forward
2610 "Content-Transfer-Encoding:" nil t)
2611 (let ((beg (match-beginning 0))
2612 (hbeg (match-end 0))
2613 (end (std11-field-end)))
2615 (eliminate-top-spaces
2616 (rfc822/unfolding-string
2617 (buffer-substring hbeg end))))
2618 (if (or charset (string-equal type "text"))
2620 (delete-region beg (1+ end))
2621 (goto-char (point-min))
2622 (if (search-forward "\n\n" nil t)
2625 (match-end 0)(point-max) encoding)
2629 (if (or code-conversion encoded)
2630 (decode-mime-charset-region
2631 (point-min)(point-max)
2632 (or charset default-mime-charset))
2635 (if (re-search-forward "^$" nil t)
2639 (if (= (point-min) 1)
2645 (concat type "/" stype pstr) encoding)))
2647 (delete-region (point-min) he)
2650 (concat type "/" stype pstr) encoding))
2654 (decode-mime-charset-region (point-min) (point-max)
2655 default-mime-charset)
2659 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2661 (mime-editor::edit-again code-conversion)
2662 (goto-char (point-min))
2666 (if (re-search-forward
2667 (concat "^\\(" (regexp-quote mail-header-separator) "\\)?$")
2672 (goto-char (point-min))
2673 (while (re-search-forward
2674 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2675 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2678 (and (re-search-forward "^$")
2679 (replace-match mail-header-separator)
2691 (run-hooks 'tm-edit-load-hook)
2693 ;;; tm-edit.el ends here