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.45 $
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.45 1996/02/26 08:43:36 morioka Exp $")
127 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
133 (defvar mime-prefix "\C-c\C-x"
134 "*Keymap prefix for MIME commands.")
136 (defvar mime-signature-file "~/.signature.rtf"
137 "*Signature file to be included as a part of a multipart message.")
139 (defvar mime-ignore-preceding-spaces nil
140 "*Ignore preceding white spaces if non-nil.")
142 (defvar mime-ignore-trailing-spaces nil
143 "*Ignore trailing white spaces if non-nil.")
145 (defvar mime-ignore-same-text-tag t
146 "*Ignore preceding text content-type tag that is same with new one.
147 If non-nil, the text tag is not inserted unless something different.")
149 (defvar mime-auto-hide-body t
150 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
152 (defvar mime-string-encoder
153 (cond ((boundp 'NEMACS)
154 (function mime-string-encoder-for-nemacs))
156 (function mime-string-encoder-for-mule))
157 ((string-match "^19\\." emacs-version)
158 (function mime-string-encoder-for-emacs19))
160 (function mime-string-encoder-for-emacs18)))
161 "*Function to encode a string for given encoding method.
162 The method is a form of (CHARSET . ENCODING).")
164 (defvar mime-voice-recorder
165 (function mime-voice-recorder-for-sun)
166 "*Function to record a voice message and return a buffer that contains it.")
168 (defvar mime/editor-mode-hook nil
169 "*Hook called when enter MIME mode.")
171 (defvar mime-editor/translate-hook nil
172 "*Hook called before translating into a MIME compliant message.
173 To insert a signature file specified by mime-signature-file
174 (`.signature.rtf' by default) automatically, call the function
175 `mime-editor/insert-signature' from this hook.")
177 (defvar mime-editor/exit-hook nil
178 "*Hook called when exit MIME mode.")
180 (defvar mime-content-types
182 ;; Charset parameter need not to be specified, since it is
183 ;; defined automatically while translation.
185 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
188 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
191 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
194 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
197 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
205 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
206 ("directory" "/pub/GNU/elisp/mime")
208 ("mode" "image" "ascii" "local8"))
213 ("mode" "image" "ascii" "local8"))
214 ("tftp" ("site") ("name"))
215 ("afs" ("site") ("name"))
216 ("local-file" ("site") ("name"))
217 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
222 ("octet-stream" ("type" "" "tar" "shar"))
224 ("x-kiss" ("x-cnf")))
237 "*Alist of content-type, subtype, parameters and its values.")
239 (defvar mime-file-types
241 "text" "richtext" nil
249 "application" "postscript" nil
251 "attachment" (("filename" . file))
256 "inline" (("filename" . file))
261 "inline" (("filename" . file))
266 "inline" (("filename" . file))
271 "inline" (("filename" . file))
276 "inline" (("filename" . file))
281 "inline" (("filename" . file))
286 "inline" (("filename" . file))
291 "attachment" (("filename" . file))
296 "attachment" (("filename" . file))
299 "application" "octet-stream" (("type" . "emacs-lisp"))
301 "attachment" (("filename" . file))
304 "application" "octet-stream" (("type" . "common-lisp"))
306 "attachment" (("filename" . file))
309 "application" "octet-stream" (("type" . "tar+gzip"))
311 "attachment" (("filename" . file))
314 "application" "octet-stream" (("type" . "tar+gzip"))
316 "attachment" (("filename" . file))
319 "application" "octet-stream" (("type" . "tar+compress"))
321 "attachment" (("filename" . file))
324 "application" "octet-stream" (("type" . "tar+compress"))
326 "attachment" (("filename" . file))
329 "application" "octet-stream" (("type" . "gzip"))
331 "attachment" (("filename" . file))
334 "application" "octet-stream" (("type" . "compress"))
336 "attachment" (("filename" . file))
339 "application" "octet-stream" (("type" . "lha"))
341 "attachment" (("filename" . file))
344 "application" "zip" nil
346 "attachment" (("filename" . file))
349 "application" "octet-stream" (("type" . "patch"))
351 "attachment" (("filename" . file))
354 "text" "plain" nil nil)
356 "application" "octet-stream" nil
358 "attachment" (("filename" . file))
361 "*Alist of file name, types, parameters, and default encoding.
362 If encoding is nil, it is determined from its contents.")
364 ;;; @@ about message inserting
367 (defvar mime-editor/yank-ignored-field-list
368 '("Received" "Sender" "Approved" "Path" "Status" "X-VM-.*" "X-UIDL")
369 "Delete these fields from original message when it is inserted
370 as message/rfc822 part.
371 Each elements are regexp of field-name. [tm-edit.el]")
373 (defvar mime-editor/yank-ignored-field-regexp
375 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
378 (defvar mime-editor/message-inserter-alist nil)
379 (defvar mime-editor/mail-inserter-alist nil)
381 ;;; @@ about message splitting
384 (defvar mime-editor/split-message t
385 "*Split large message if it is non-nil. [tm-edit.el]")
387 (defvar mime-editor/message-default-max-length 1000
388 "*Default maximum size of a message. [tm-edit.el]")
390 (defvar mime-editor/message-max-length-alist
391 '((news-reply-mode . 500)))
393 (defconst mime-editor/split-ignored-field-regexp
394 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
396 (defvar mime-editor/split-blind-field-regexp
397 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
399 (defvar mime-editor/message-default-sender-alist
400 '((mail-mode . mail-send-and-exit)
401 (mh-letter-mode . mh-send-letter)
402 (news-reply-mode . gnus-inews-news)
405 (defvar mime-editor/split-message-sender-alist
412 . (lambda (&optional arg)
414 (write-region (point-min) (point-max)
415 mime-editor/draft-file-name nil 'no-message)
417 (pop-to-buffer "MH mail delivery")
419 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
421 mh-send-args mime-editor/draft-file-name)
422 (goto-char (point-max)) ; show the interesting part
426 (apply 'mh-exec-cmd-quiet t mh-send-prog
428 (list "-nopush" "-nodraftfolder"
429 "-noverbose" "-nowatch"
430 mh-send-args mime-editor/draft-file-name)))))
434 (defvar mime-editor/window-config-alist
436 (mh-letter-mode . mh-previous-window-config)
437 (news-reply-mode . (cond ((boundp 'gnus-winconf-post-news)
439 gnus-winconf-post-news
440 (setq gnus-winconf-post-news nil)
442 ((boundp 'gnus-prev-winconf)
445 (setq gnus-prev-winconf nil)
450 (defvar mime-editor/news-reply-mode-server-running nil)
456 (defvar mime-editor/signing-type nil
457 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
459 (defvar mime-editor/encrypting-type nil
460 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
462 (if (or mime-editor/signing-type mime-editor/encrypting-type)
470 (defconst mime-editor/single-part-tag-regexp
471 "^--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
472 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
474 (defconst mime-editor/multipart-beginning-regexp "^--<<\\([^<>]+\\)>>-{\n")
476 (defconst mime-editor/multipart-end-regexp "^--}-<<\\([^<>]+\\)>>\n")
478 (defconst mime-editor/beginning-tag-regexp
479 (regexp-or mime-editor/single-part-tag-regexp
480 mime-editor/multipart-beginning-regexp))
482 (defconst mime-editor/end-tag-regexp
483 (regexp-or mime-editor/single-part-tag-regexp
484 mime-editor/multipart-end-regexp))
486 (defconst mime-editor/tag-regexp
487 (regexp-or mime-editor/single-part-tag-regexp
488 mime-editor/multipart-beginning-regexp
489 mime-editor/multipart-end-regexp))
491 (defvar mime-tag-format "--[[%s]]"
492 "*Control-string making a MIME tag.")
494 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
495 "*Control-string making a MIME tag with encoding.")
497 ;;; @@ multipart boundary
500 (defvar mime-multipart-boundary "Multipart"
501 "*Boundary of a multipart message.")
504 ;;; @@ buffer local variables
507 (defvar mime/editor-mode-old-local-map nil)
508 (defvar mime/editor-mode-old-selective-display nil)
509 (defvar mime/editing-buffer nil)
515 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
516 "*Specify MIME tspecials.
517 Tspecials means any character that matches with it in header must be quoted.")
519 (defconst mime-editor/mime-version-value
520 (format "1.0 (generated by tm-edit %s)" mime-editor/version)
521 "MIME version number.")
523 (defconst mime-editor/mime-map (make-sparse-keymap)
524 "Keymap for MIME commands.")
526 ;;; @ keymap and menu
529 (defvar mime/editor-mode-flag nil)
530 (make-variable-buffer-local 'mime/editor-mode-flag)
532 (set-alist 'minor-mode-alist 'mime/editor-mode-flag '(" MIME-Edit"))
534 (defun mime-editor/define-keymap (keymap)
535 "Add mime-editor commands to KEYMAP."
536 (if (not (keymapp keymap))
538 (define-key keymap "\C-t" 'mime-editor/insert-text)
539 (define-key keymap "\C-i" 'mime-editor/insert-file)
540 (define-key keymap "\C-e" 'mime-editor/insert-external)
541 (define-key keymap "\C-v" 'mime-editor/insert-voice)
542 (define-key keymap "\C-y" 'mime-editor/insert-message)
543 (define-key keymap "\C-m" 'mime-editor/insert-mail)
544 (define-key keymap "\C-w" 'mime-editor/insert-signature)
545 (define-key keymap "\C-s" 'mime-editor/insert-signature)
546 (define-key keymap "\C-k" 'mime-editor/insert-key)
547 (define-key keymap "t" 'mime-editor/insert-tag)
548 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
549 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
550 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
551 (define-key keymap "d" 'mime-editor/enclose-digest-region)
552 (define-key keymap "s" 'mime-editor/enclose-signed-region)
553 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
554 (define-key keymap "\C-p" 'mime-editor/preview-message)
555 (define-key keymap "\C-z" 'mime-editor/exit)
556 (define-key keymap "?" 'mime-editor/help)
559 (mime-editor/define-keymap mime-editor/mime-map)
561 (defconst mime-editor/menu-title "MIME-Edit")
563 (defconst mime-editor/menu-list
564 '((mime-help "Describe MIME editor mode" mime-editor/help)
565 (file "Insert File" mime-editor/insert-file)
566 (external "Insert External" mime-editor/insert-external)
567 (voice "Insert Voice" mime-editor/insert-voice)
568 (message "Insert Message" mime-editor/insert-message)
569 (mail "Insert Mail" mime-editor/insert-mail)
570 (signature "Insert Signature" mime-editor/insert-signature)
571 (text "Insert Text" mime-editor/insert-text)
572 (tag "Insert Tag" mime-editor/insert-tag)
573 (alternative "Enclose as alternative"
574 mime-editor/enclose-alternative-region)
575 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
576 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
577 (digest "Enclose as digest" mime-editor/enclose-digest-region)
578 (signed "Enclose as signed" mime-editor/enclose-signed-region)
579 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
580 (key "Insert Public Key" mime-editor/insert-key)
581 (split "About split" mime-editor/set-split)
582 (sign "About sign" mime-editor/set-sign)
583 (encrypt "About encryption" mime-editor/set-encrypt)
584 (preview "Preview Message" mime-editor/preview-message)
586 "MIME-edit menubar entry.")
588 (defun mime-editor/define-menu-for-emacs19 ()
589 "Define menu for Emacs 19."
590 (define-key (current-local-map) [menu-bar mime-edit]
591 (cons mime-editor/menu-title
592 (make-sparse-keymap mime-editor/menu-title)))
595 (define-key (current-local-map)
596 (vector 'menu-bar 'mime-edit (car item))
597 (cons (nth 1 item)(nth 2 item))
600 (reverse mime-editor/menu-list)
603 ;;; modified by Pekka Marjola <pema@niksula.hut.fi>
604 ;;; 1995/9/5 (c.f. [tm-en:69])
605 (defun mime-editor/define-menu-for-xemacs ()
606 "Define menu for Emacs 19."
607 (cond ((featurep 'menubar)
608 (make-local-variable 'current-menubar)
609 (set-buffer-menubar current-menubar)
611 (cons mime-editor/menu-title
614 (vector (nth 1 item)(nth 2 item)
615 mime/editor-mode-flag)
617 mime-editor/menu-list)))
620 ;;; modified by Steven L. Baur <steve@miranova.com>
621 ;;; 1995/12/6 (c.f. [tm-en:209])
622 (if (and (string-match "XEmacs\\|Lucid" emacs-version)
623 (not (boundp 'mime-editor/popup-menu-for-xemacs)))
624 (setq mime-editor/popup-menu-for-xemacs
625 (append '("MIME Commands" "---")
626 (mapcar (function (lambda (item)
630 mime-editor/menu-list)))
639 (defun mime/editor-mode ()
640 "MIME minor mode for editing the tagged MIME message.
642 In this mode, basically, the message is composed in the tagged MIME
643 format. The message tag looks like:
645 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
647 The tag specifies the MIME content type, subtype, optional parameters
648 and transfer encoding of the message following the tag. Messages
649 without any tag are treated as `text/plain' by default. Charset and
650 transfer encoding are automatically defined unless explicitly
651 specified. Binary messages such as audio and image are usually hidden
652 using selective-display facility. The messages in the tagged MIME
653 format are automatically translated into a MIME compliant message when
656 Available charsets depend on Emacs version being used. The following
657 lists the available charsets of each emacs.
659 Emacs18: US-ASCII is only available.
660 NEmacs: US-ASCII and ISO-2022-JP are available.
661 Emacs19: US-ASCII and ISO-8859-1 are available.
662 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-6),
663 ISO-2022-JP, ISO-2022-JP-2 and ISO-2022-INT-1 are available.
665 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in Mule is expected to
666 be used to represent multilingual text in intermixed manner. Any
667 languages that has no registered charset are represented as either
668 ISO-2022-JP-2 or ISO-2022-INT-1 in Mule.
670 Following commands are available in addition to major mode commands:
671 \\[mime-editor/insert-text] insert a text message.
672 \\[mime-editor/insert-file] insert a (binary) file.
673 \\[mime-editor/insert-external] insert a reference to external body.
674 \\[mime-editor/insert-voice] insert a voice message.
675 \\[mime-editor/insert-message] insert a mail or news message.
676 \\[mime-editor/insert-mail] insert a mail message.
677 \\[mime-editor/insert-signature] insert a signature file at end.
678 \\[mime-editor/insert-tag] insert a new MIME tag.
679 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
680 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
681 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
682 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
683 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
684 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
685 \\[mime-editor/insert-key] insert PGP public key.
686 \\[mime-editor/preview-message] preview editing MIME message.
687 \\[mime-editor/exit] exit and translate into a MIME compliant message.
688 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
689 \\[mime-editor/help] show this help.
691 Additional commands are available in some major modes:
692 C-c C-c exit, translate and run the original command.
693 C-c C-s exit, translate and run the original command.
695 The following is a message example written in the tagged MIME format.
696 TABs at the beginning of the line are not a part of the message:
698 This is a conventional plain text. It should be translated
701 This is also a plain text. But, it is explicitly specified as
703 --[[text/plain; charset=ISO-2022-JP]]
704 \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
707 <center>This is a richtext.</center>
708 --[[image/gif][base64]]^M...image encoded in base64 here...
709 --[[audio/basic][base64]]^M...audio encoded in base64 here...
711 User customizable variables (not documented all of them):
713 Specifies a key prefix for MIME minor mode commands.
716 Specifies a signature file to be included as part of a multipart
719 mime-ignore-preceding-spaces
720 Preceding white spaces in a message body are ignored if non-nil.
722 mime-ignore-trailing-spaces
723 Trailing white spaces in a message body are ignored if non-nil.
725 mime-auto-fill-header
726 Fill header fields that contain encoded-words if non-nil.
729 Hide a non-textual body message encoded in base64 after insertion
733 Specifies a function to encode a string for given encoding method.
734 The method is a form of (CHARSET . ENCODING).
737 Specifies a function to record a voice message and return a buffer
738 that contains it. The function mime-voice-recorder-for-sun is for
741 mime/editor-mode-hook
742 Turning on MIME mode calls the value of mime/editor-mode-hook, if
745 mime-editor/translate-hook
746 The value of mime-editor/translate-hook is called just before translating
747 the tagged MIME format into a MIME compliant message if it is
748 non-nil. If the hook call the function mime-editor/insert-signature,
749 the signature file will be inserted automatically.
751 mime-editor/exit-hook
752 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
755 (if mime/editor-mode-flag
756 (error "You are already editing a MIME message.")
757 (setq mime/editor-mode-flag t)
758 ;; Remember old key bindings.
759 (if (string-match "XEmacs\\|Lucid" emacs-version)
761 (make-local-variable 'mime/editor-mode-old-local-map)
762 (setq mime/editor-mode-old-local-map (current-local-map))
763 ;; Add MIME commands to current local map.
764 (use-local-map (copy-keymap (current-local-map))))
765 (if (not (lookup-key (current-local-map) mime-prefix))
766 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
768 ;; Define menu. Menus for other emacs implementations are
770 ;; modified by Pekka Marjola <pema@niksula.hut.fi>
771 ;; 1995/9/5 (c.f. [tm-eng:69])
772 (cond ((string-match "XEmacs\\|Lucid" emacs-version)
773 (mime-editor/define-menu-for-xemacs))
774 ((string-match "^19\\." emacs-version)
775 (mime-editor/define-menu-for-emacs19)
779 ;; Remember old selective-display.
780 (make-local-variable 'mime/editor-mode-old-selective-display)
781 (setq mime/editor-mode-old-selective-display selective-display)
782 (setq selective-display t)
783 ;; I don't care about saving these.
784 (setq paragraph-start
785 (regexp-or mime-editor/single-part-tag-regexp
787 (setq paragraph-separate
788 (regexp-or mime-editor/single-part-tag-regexp
790 (run-hooks 'mime/editor-mode-hook)
792 (substitute-command-keys
793 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
797 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
798 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
800 (defun mime-editor/exit (&optional nomime no-error)
801 "Translate the tagged MIME message into a MIME compliant message.
802 With no argument encode a message in the buffer into MIME, otherwise
803 just return to previous mode."
805 (if (not mime/editor-mode-flag)
807 (error "You aren't editing a MIME message.")
811 (run-hooks 'mime-editor/translate-hook)
812 (mime-editor/translate-buffer)))
813 ;; Restore previous state.
814 (setq mime/editor-mode-flag nil)
815 (cond ((string-match "XEmacs\\|Lucid" emacs-version)
816 ;; mime-prefix only defined if binding was nil
817 (if (eq (lookup-key (current-local-map) mime-prefix)
818 mime-editor/mime-map)
819 (define-key (current-local-map) mime-prefix nil))
820 (delete-menu-item (list mime-editor/menu-title)))
822 (use-local-map mime/editor-mode-old-local-map)))
824 (setq selective-display mime/editor-mode-old-selective-display)
825 (set-buffer-modified-p (buffer-modified-p))
826 (run-hooks 'mime-editor/exit-hook)
827 (message "Exit MIME editor mode.")
830 (defun mime-editor/maybe-translate ()
832 (mime-editor/exit nil t)
833 (call-interactively 'mime-editor/maybe-split-and-send)
836 (defun mime-editor/help ()
837 "Show help message about MIME mode."
839 (with-output-to-temp-buffer "*Help*"
840 (princ "MIME editor mode:\n")
841 (princ (documentation 'mime/editor-mode))
842 (print-help-return-message)))
844 (defun mime-editor/insert-text ()
845 "Insert a text message.
846 Charset is automatically obtained from the `mime/lc-charset-alist'."
848 (if (and (mime-editor/insert-tag "text" nil nil)
849 (looking-at mime-editor/single-part-tag-regexp))
851 ;; Make a space between the following message.
856 (defun mime-editor/insert-file (file)
857 "Insert a message from a file."
858 (interactive "fInsert file as MIME message: ")
859 (let* ((guess (mime-find-file-type file))
860 (pritype (nth 0 guess))
861 (subtype (nth 1 guess))
862 (parameters (nth 2 guess))
863 (default (nth 3 guess)) ;Guess encoding from its file name.
864 (disposition-type (nth 4 guess))
865 (disposition-params (nth 5 guess))
867 (if (not (interactive-p))
870 (concat "What transfer encoding"
873 (if (string-equal default "")
879 mime-encoding-method-alist nil t nil))))
880 (if (string-equal encoding "")
881 (setq encoding default))
882 (if (or (consp parameters) (stringp disposition-type))
883 (let ((rest parameters) cell attribute value)
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)))
893 (setq parameters (concat parameters "; " attribute "=" value))
894 (setq rest (cdr rest))
899 (concat parameters "\n"
900 "Content-Disposition: " disposition-type))
901 (setq rest disposition-params)
903 (setq cell (car rest))
904 (setq attribute (car cell))
905 (setq value (cdr cell))
907 (setq value (rfc822/wrap-as-quoted-string
908 (file-name-nondirectory file)))
911 (concat parameters "; " attribute "=" value))
912 (setq rest (cdr rest))
916 (mime-editor/insert-tag pritype subtype parameters)
917 (mime-editor/insert-binary-file file encoding)
920 (defun mime-editor/insert-external ()
921 "Insert a reference to external body."
923 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
925 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
927 (let* ((pritype (mime-prompt-for-type))
928 (subtype (mime-prompt-for-subtype pritype))
929 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
932 (insert "Content-Type: "
933 pritype "/" subtype (or parameters "") "\n")))
934 (if (and (not (eobp))
935 (not (looking-at mime-editor/single-part-tag-regexp)))
936 (insert (mime-make-text-tag) "\n")))
938 (defun mime-editor/insert-voice ()
939 "Insert a voice message."
941 (mime-editor/insert-tag "audio" "basic" nil)
942 (let ((buffer (funcall mime-voice-recorder)))
944 (mime-editor/insert-binary-buffer buffer "base64")
948 (defun mime-editor/insert-signature (&optional arg)
949 "Insert a signature file specified by mime-signature-file."
954 (read-file-name "Insert your signature: "
955 (concat signature-file-name "-")
958 (signature/get-signature-file-name))))
960 (if signature-insert-at-eof
961 (goto-char (point-max))
963 (apply (function mime-editor/insert-tag)
964 (mime-find-file-type signature))
965 (if (file-readable-p signature)
967 (goto-char (point-max))
971 (insert-file-contents signature)
972 (set-buffer-modified-p (buffer-modified-p))
973 ; force mode line update
977 ;; Insert a new tag around a point.
979 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
980 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
981 If nothing is inserted, return nil."
986 exist-prev-tag exist-next-tag)
989 (mime-prompt-for-type)))
992 (mime-prompt-for-subtype pritype)))
995 (mime-prompt-for-parameters pritype subtype delimiter)))
996 ;; Make a new MIME tag.
997 (setq newtag (mime-make-tag pritype subtype parameters))
998 ;; Find an current MIME tag.
1001 (if (mime-editor/goto-tag)
1003 (if (eq current (match-beginning 0))
1004 (setq exist-next-tag t)
1005 (setq exist-prev-tag t)
1007 (buffer-substring (match-beginning 0) (match-end 0))
1009 ;; Assume content type is 'text/plan'.
1010 (mime-make-tag "text" "plain")
1012 ;; We are only interested in TEXT.
1014 (not (mime-test-content-type
1015 (mime-editor/get-contype oldtag) "text")))
1017 (cond (exist-prev-tag (insert "\n"))
1018 (exist-next-tag (save-excursion
1027 (if (or (not oldtag) ;Not text
1028 (or mime-ignore-same-text-tag
1029 (not (string-equal oldtag newtag))))
1031 ;; Mark the beginning of the tag for convenience.
1032 (push-mark (point) 'nomsg)
1033 (insert newtag "\n")
1034 (list pritype subtype parameters) ;New tag is created.
1036 ;; Restore previous point.
1038 nil ;Nothing is created.
1042 ;; Insert the binary content after MIME tag.
1043 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1045 (defun mime-editor/insert-binary-file (file &optional encoding)
1046 "Insert binary FILE at point.
1047 Optional argument ENCODING specifies an encoding method such as base64."
1048 (let ((tmpbuf (get-buffer-create " *MIME insert*")))
1052 (let ((mc-flag nil) ;Mule
1053 (file-coding-system-for-read
1054 (if (featurep 'mule) *noconv*))
1055 (kanji-flag nil) ;NEmacs
1056 (emx-binary-mode t) ;Stop CRLF to LF conversion in OS/2
1058 (let (jka-compr-compression-info-list
1059 jam-zcat-filename-list)
1060 (insert-file-contents file))))
1062 (if (and (stringp encoding)
1063 (string-equal (downcase encoding) "x-uue"))
1066 (let ((uuencode-external-encoder
1067 (cons (car uuencode-external-encoder)
1068 (list (file-name-nondirectory file))
1070 (mime-editor/insert-binary-buffer tmpbuf encoding)
1072 (mime-editor/insert-binary-buffer tmpbuf encoding))
1073 (kill-buffer tmpbuf))))
1075 ;; Insert the binary content after MIME tag.
1076 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1078 (defun mime-editor/insert-binary-buffer (buffer &optional encoding)
1079 "Insert binary BUFFER at point.
1080 Optional argument ENCODING specifies an encoding method such as base64."
1081 (let* ((tagend (1- (point))) ;End of the tag
1082 (hide-p (and mime-auto-hide-body
1084 (let ((en (downcase encoding)))
1085 (or (string-equal en "base64")
1086 (string-equal en "x-uue")
1090 (narrow-to-region (1- (point)) (point))
1091 (let ((start (point))
1092 (emx-binary-mode t)) ;Stop LF to CRLF conversion in OS/2
1093 (insert-buffer-substring buffer)
1094 ;; Encode binary message if necessary.
1096 (mime-encode-region encoding start (point-max))))
1099 (mime-flag-region (point-min) (1- (point-max)) ?\^M)
1100 (goto-char (point-max)))
1102 ;; Define encoding even if it is 7bit.
1103 (if (stringp encoding)
1105 (goto-char tagend) ;Make sure which line the tag is on.
1106 (mime-editor/define-encoding encoding)))
1110 ;; Commands work on a current message flagment.
1112 (defun mime-editor/goto-tag ()
1113 "Search for the beginning of the tagged MIME message."
1114 (let ((current (point)) multipart)
1115 (if (looking-at mime-editor/tag-regexp)
1117 ;; At first, go to the end.
1118 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1119 (goto-char (match-beginning 0)) ;For multiline tag
1124 (goto-char (point-max))
1126 ;; Then search for the beginning.
1127 (re-search-backward mime-editor/end-tag-regexp nil t)
1129 (or (looking-at mime-editor/beginning-tag-regexp)
1130 ;; Restore previous point.
1137 (defun mime-editor/content-beginning ()
1138 "Return the point of the beginning of content."
1140 (let ((beg (save-excursion
1141 (beginning-of-line) (point))))
1142 (if (mime-editor/goto-tag)
1143 (let ((top (point)))
1144 (goto-char (match-end 0))
1145 (if (and (= beg top)
1146 (= (following-char) ?\^M))
1150 ;; Default text/plain tag.
1151 (goto-char (point-min))
1153 (concat "\n" (regexp-quote mail-header-separator)
1154 (if mime-ignore-preceding-spaces
1155 "[ \t\n]*\n" "\n")) nil 'move)
1159 (defun mime-editor/content-end ()
1160 "Return the point of the end of content."
1162 (let ((beg (save-excursion
1163 (beginning-of-line) (point))))
1164 (if (mime-editor/goto-tag)
1165 (let ((top (point)))
1166 (goto-char (match-end 0))
1167 (if (and (= beg top) ;Must be on the same line.
1168 (= (following-char) ?\^M))
1172 ;; Move to the end of this text.
1173 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1174 ;; Don't forget a multiline tag.
1175 (goto-char (match-beginning 0)))
1178 ;; Assume the message begins with text/plain.
1179 (goto-char (mime-editor/content-beginning))
1180 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1181 ;; Don't forget a multiline tag.
1182 (goto-char (match-beginning 0)))
1186 (defun mime-editor/define-charset (charset)
1187 "Set charset of current tag to CHARSET."
1189 (if (mime-editor/goto-tag)
1190 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1191 (delete-region (match-beginning 0) (match-end 0))
1193 (mime-create-tag (mime-set-parameter
1194 (mime-editor/get-contype tag) "charset" charset)
1195 (mime-editor/get-encoding tag))))
1198 (defun mime-editor/define-encoding (encoding)
1199 "Set encoding of current tag to ENCODING."
1201 (if (mime-editor/goto-tag)
1202 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1203 (delete-region (match-beginning 0) (match-end 0))
1204 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1207 (defun mime-editor/choose-charset ()
1208 "Choose charset of a text following current point."
1209 (mime/find-charset-region (point) (mime-editor/content-end))
1212 (defun mime-make-text-tag (&optional subtype)
1213 "Make a tag for a text after current point.
1214 Subtype of text type can be specified by an optional argument SUBTYPE.
1215 Otherwise, it is obtained from mime-content-types."
1216 (let* ((pritype "text")
1217 (subtype (or subtype
1218 (car (car (cdr (assoc pritype mime-content-types)))))))
1219 ;; Charset should be defined later.
1220 (mime-make-tag pritype subtype)))
1223 ;; Tag handling functions
1225 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1226 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1227 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1231 (defun mime-create-tag (contype &optional encoding)
1232 "Make a tag with CONTENT-TYPE and optional ENCODING."
1233 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1236 (defun mime-editor/get-contype (tag)
1237 "Return Content-Type (including parameters) of TAG."
1239 (or (string-match mime-editor/single-part-tag-regexp tag)
1240 (string-match mime-editor/multipart-beginning-regexp tag)
1241 (string-match mime-editor/multipart-end-regexp tag)
1243 (substring tag (match-beginning 1) (match-end 1))
1246 (defun mime-editor/get-encoding (tag)
1247 "Return encoding of TAG."
1249 (string-match mime-editor/single-part-tag-regexp tag)
1251 (not (= (match-beginning 3) (match-end 3)))
1252 (substring tag (match-beginning 3) (match-end 3))))
1254 (defun mime-get-parameter (contype parameter)
1255 "For given CONTYPE return value for PARAMETER.
1256 Nil if no such parameter."
1260 (regexp-quote parameter)
1261 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1263 (substring contype (match-beginning 1) (match-end 1))
1264 nil ;No such parameter
1267 (defun mime-set-parameter (contype parameter value)
1268 "For given CONTYPE set PARAMETER to VALUE."
1272 (regexp-quote parameter)
1273 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1276 (concat (substring contype 0 (match-beginning 1))
1278 (substring contype (match-end 1)))
1279 (concat contype "; " parameter "=" value)))
1281 (defun mime-strip-parameters (contype)
1282 "Return primary content-type and subtype without parameters for CONTYPE."
1283 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1284 (substring contype (match-beginning 1) (match-end 1)) nil))
1286 (defun mime-test-content-type (contype type &optional subtype)
1287 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1288 (and (stringp contype)
1291 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1292 (downcase contype))))
1297 (defun mime-find-file-type (file)
1298 "Guess Content-Type, subtype, and parameters from FILE."
1300 (guesses mime-file-types))
1301 (while (and (not guess) guesses)
1302 (if (string-match (car (car guesses)) file)
1303 (setq guess (cdr (car guesses))))
1304 (setq guesses (cdr guesses)))
1308 (defun mime-prompt-for-type ()
1309 "Ask for Content-type."
1311 ;; Repeat until primary content type is specified.
1312 (while (string-equal type "")
1314 (completing-read "What content type: "
1317 'require-match ;Type must be specified.
1320 (if (string-equal type "")
1322 (message "Content type is required.")
1330 (defun mime-prompt-for-subtype (pritype)
1331 "Ask for Content-type subtype of Content-Type PRITYPE."
1332 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1337 "What content subtype: (default " default ") ")
1338 "What content subtype: ")
1339 (cdr (assoc pritype mime-content-types))
1341 'require-match ;Subtype must be specified.
1344 (if (string-equal answer "") default answer)))
1346 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1347 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1348 Optional DELIMITER specifies parameter delimiter (';' by default)."
1349 (let* ((delimiter (or delimiter "; "))
1354 (mime-prompt-for-parameters-1
1356 (cdr (assoc pritype mime-content-types))))))
1359 (if (and (stringp parameters)
1360 (not (string-equal parameters "")))
1361 (concat delimiter parameters)
1362 "" ;"" if no parameters
1365 (defun mime-prompt-for-parameters-1 (optlist)
1366 (apply (function append)
1367 (mapcar (function mime-prompt-for-parameter) optlist)))
1369 (defun mime-prompt-for-parameter (parameter)
1371 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1372 (let* ((prompt (car parameter))
1373 (choices (mapcar (function
1375 (if (consp e) e (list e))))
1377 (default (car (car choices)))
1383 (concat "What " prompt
1385 (if (string-equal default "") "\"\"" default)
1387 choices nil nil ""))
1388 ;; If nothing is selected, use default.
1389 (if (string-equal answer "")
1390 (setq answer default)))
1392 (read-string (concat "What " prompt ": "))))
1393 (cons (if (and answer
1394 (not (string-equal answer "")))
1396 ;; Note: control characters ignored!
1397 (if (string-match mime-tspecials-regexp answer)
1398 (concat "\"" answer "\"") answer)))
1399 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1402 (defun mime-encode-string (encoding string)
1403 "Using ENCODING encode a STRING.
1404 If the STRING is too long, the encoded string may be broken into
1407 (set-buffer (get-buffer-create " *MIME encoding*"))
1410 (mime-encode-region encoding (point-min) (point-max))
1412 (buffer-substring (point-min) (point-max))
1413 (kill-buffer (current-buffer)))))
1415 (defun mime-decode-string (encoding string)
1416 "Using ENCODING decode a STRING."
1418 (set-buffer (get-buffer-create " *MIME decoding*"))
1421 (mime-decode-region encoding (point-min) (point-max))
1423 (buffer-substring (point-min) (point-max))
1424 (kill-buffer (current-buffer)))))
1426 (defun mime-flag-region (from to flag)
1427 "Hides or shows lines from FROM to TO, according to FLAG.
1428 If FLAG is `\\n' (newline character) then text is shown,
1429 while if FLAG is `\\^M' (control-M) the text is hidden."
1430 (let ((buffer-read-only nil) ;Okay even if write protected.
1431 (modp (buffer-modified-p)))
1433 (subst-char-in-region from to
1434 (if (= flag ?\n) ?\^M ?\n)
1436 (set-buffer-modified-p modp))))
1439 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1442 (defun mime-editor/translate-buffer ()
1443 "Encode the tagged MIME message in current buffer in MIME compliant message."
1445 (if (catch 'mime-editor/error
1447 (mime-editor/pgp-enclose-buffer)
1448 (mime/encode-message-header)
1449 (mime-editor/translate-body)
1453 (error "Translation error!")
1456 (defun mime-editor/find-inmost ()
1457 (goto-char (point-min))
1458 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1459 (let ((bb (match-beginning 0))
1461 (type (buffer-substring (match-beginning 1)(match-end 1)))
1463 (setq end-exp (format "^--}-<<%s>>\n" type))
1465 (if (re-search-forward end-exp nil t)
1467 (setq eb (match-beginning 0))
1468 (setq ee (match-end 0))
1470 (setq eb (point-max))
1471 (setq ee (point-max))
1473 (narrow-to-region be eb)
1475 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1477 (narrow-to-region (match-beginning 0)(point-max))
1478 (mime-editor/find-inmost)
1481 ;;(delete-region eb ee)
1482 (list type bb be eb)
1485 (defun mime-editor/process-multipart-1 (boundary)
1486 (let ((ret (mime-editor/find-inmost)))
1488 (let ((type (car ret))
1489 (bb (nth 1 ret))(be (nth 2 ret))
1492 (narrow-to-region bb eb)
1493 (delete-region bb be)
1494 (setq bb (point-min))
1495 (setq eb (point-max))
1498 (if (looking-at mime-editor/multipart-end-regexp)
1499 (let ((beg (match-beginning 0))
1502 (delete-region beg end)
1503 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
1505 (insert (concat (mime-make-text-tag) "\n"))
1507 (cond ((string= type "signed")
1508 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1509 (mime-editor/sign-pgp-elkins bb eb boundary)
1511 ((eq mime-editor/signing-type 'pgp-kazu)
1512 (mime-editor/process-pgp-kazu 'mc-sign
1516 ((string= type "encrypted")
1517 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1518 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1520 ((eq mime-editor/signing-type 'pgp-kazu)
1521 (mime-editor/process-pgp-kazu 'mc-encrypt
1526 (nth 2 (mime-editor/translate-region bb eb
1530 (format "--[[multipart/%s;
1531 boundary=\"%s\"][7bit]]\n"
1536 (defun tm:mc-pgp-generic-parser (result)
1537 (let ((ret (mc-pgp-generic-parser result)))
1539 (vector (car ret)(cdr ret))
1542 (autoload 'mc-pgp-lookup-key "mc-pgp")
1544 (defun tm:mc-process-region
1545 (beg end passwd program args parser &optional buffer boundary)
1546 (let ((obuf (current-buffer))
1547 (process-connection-type nil)
1548 mybuf result rgn proc)
1551 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1555 (buffer-disable-undo mybuf)
1557 (apply 'start-process "*PGP*" mybuf program args))
1560 (process-send-string proc (concat passwd "\n"))
1561 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1562 (process-send-region proc beg end)
1563 (process-send-eof proc)
1564 (while (eq 'run (process-status proc))
1565 (accept-process-output proc 5))
1566 (setq result (process-exit-status proc))
1567 ;; Hack to force a status_notify() in Emacs 19.29
1568 (delete-process proc)
1570 (goto-char (point-max))
1571 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1572 (delete-region (match-beginning 0) (match-end 0)))
1573 (goto-char (point-min))
1575 (while (search-forward "\r\n" nil t)
1576 (replace-match "\n"))
1577 ;; Hurm. FIXME; must get better result codes.
1578 (if (stringp result)
1579 (error "%s exited abnormally: '%s'" program result)
1580 (setq rgn (funcall parser result))
1581 ;; If the parser found something, migrate it
1587 (narrow-to-region beg end)
1589 (insert (format "--%s\n" boundary))
1590 (goto-char (point-max))
1591 (insert (format "\n--%s
1592 Content-Type: application/pgp-signature
1593 Content-Transfer-Encoding: 7bit
1596 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1597 (goto-char (point-max))
1598 (insert (format "\n--%s--\n" boundary))
1600 (delete-region beg end)
1602 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1605 (delete-region (car rgn) (cdr rgn)))))
1606 ;; Return nil on failure and exit code on success
1608 ;; Cleanup even on nonlocal exit
1609 (if (and proc (eq 'run (process-status proc)))
1610 (interrupt-process proc))
1612 (or buffer (null mybuf) (kill-buffer mybuf)))))
1614 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1615 (if (not (boundp 'mc-pgp-user-id))
1618 (let ((process-environment process-environment)
1619 (buffer (get-buffer-create mc-buffer-name))
1621 (parser (function mc-pgp-generic-parser))
1622 (pgp-path mc-pgp-path)
1624 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1628 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1629 (setenv "PGPPASSFD" "0")
1635 (list "+verbose=1" "+language=en"
1636 (format "+clearsig=%s" (if unclear "off" "on"))
1637 "+batchmode" "-u" (cdr key))))
1639 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1641 (message "Signing as %s ..." (car key))
1642 (if (tm:mc-process-region
1643 start end passwd pgp-path args parser buffer boundary)
1647 (goto-char (point-min))
1650 --[[multipart/signed; protocol=\"application/pgp-signature\";
1651 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1653 (message "Signing as %s ... Done." (car key))
1657 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1660 (narrow-to-region beg end)
1662 (mime-editor/translate-region beg end boundary))
1664 (encoding (nth 1 ret))
1666 (pgp-boundary (concat "pgp-sign-" boundary))
1669 (insert (format "Content-Type: %s\n" ctype))
1671 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1674 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1675 nil nil pgp-boundary)
1676 (throw 'mime-editor/error 'pgp-error)
1680 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1682 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1685 (let ((from (rfc822/get-field-body "From"))
1686 (to (rfc822/get-field-body "To"))
1687 (cc (rfc822/get-field-body "cc"))
1689 (narrow-to-region beg end)
1691 (mime-editor/translate-region beg end boundary))
1693 (encoding (nth 1 ret))
1695 (pgp-boundary (concat "pgp-" boundary))
1698 (if (and (stringp from)
1699 (not (string-equal from "")))
1700 (insert (format "From: %s\n" from))
1702 (if (and (stringp to)
1703 (not (string-equal to "")))
1705 (insert (format "To: %s\n" to))
1706 (setq recipients to)
1708 (if (and (stringp cc)
1709 (not (string-equal cc "")))
1711 (insert (format "cc: %s\n" cc))
1713 (setq recipients (concat recipients "," cc))
1714 (setq recipients cc)
1716 (insert (format "Content-Type: %s\n" ctype))
1718 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1722 (let ((mc-pgp-always-sign 'never))
1723 (mc-pgp-encrypt-region
1724 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1725 (point-min) (point-max) from nil)
1727 (throw 'mime-editor/error 'pgp-error)
1730 (insert (format "--[[multipart/encrypted;
1732 protocol=\"application/pgp-encrypted\"][7bit]]
1734 Content-Type: application/pgp-encrypted
1737 Content-Type: application/octet-stream
1738 Content-Transfer-Encoding: 7bit
1740 " pgp-boundary pgp-boundary pgp-boundary))
1741 (goto-char (point-max))
1742 (insert (format "\n--%s--\n" pgp-boundary))
1745 (defun mime-editor/process-pgp-kazu (type beg end boundary)
1748 (narrow-to-region beg end)
1750 (mime-editor/translate-region beg end boundary))
1752 (encoding (nth 1 ret))
1756 (insert (format "Content-Type: %s\n" ctype))
1758 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1766 (let ((mail-header-separator "="))
1767 (call-interactively type)
1770 (and (search-forward "=\n")
1773 (throw 'mime-editor/error 'pgp-error)
1777 "--[[application/pgp; format=mime][7bit]]\n")
1781 (defun mime-editor/translate-body ()
1782 "Encode the tagged MIME body in current buffer in MIME compliant message."
1786 (concat mime-multipart-boundary "_"
1787 (replace-space-with-underline (current-time-string))
1791 (while (mime-editor/process-multipart-1
1792 (format "%s-%d" boundary i))
1796 ;; We are interested in message body.
1799 (goto-char (point-min))
1801 (concat "\n" (regexp-quote mail-header-separator)
1802 (if mime-ignore-preceding-spaces
1803 "[ \t\n]*\n" "\n")) nil 'move)
1807 (goto-char (point-max))
1808 (and mime-ignore-trailing-spaces
1809 (re-search-backward "[^ \t\n]\n" beg t)
1812 (setq ret (mime-editor/translate-region
1814 (format "%s-%d" boundary i)))
1816 (let ((contype (car ret)) ;Content-Type
1817 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1819 ;; Make primary MIME headers.
1820 (or (mail-position-on-field "Mime-Version")
1821 (insert mime-editor/mime-version-value))
1822 ;; Remove old Content-Type and other fields.
1824 (goto-char (point-min))
1825 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1826 (narrow-to-region (point-min) (point))
1827 (goto-char (point-min))
1828 (mime-delete-field "Content-Type")
1829 (mime-delete-field "Content-Transfer-Encoding"))
1830 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1831 (mail-position-on-field "Content-Type")
1835 (mail-position-on-field "Content-Transfer-Encoding")
1839 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1842 (concat mime-multipart-boundary "_"
1843 (replace-space-with-underline (current-time-string))))
1847 (narrow-to-region beg end)
1848 (let ((tag nil) ;MIME tag
1849 (contype nil) ;Content-Type
1850 (encoding nil) ;Content-Transfer-Encoding
1851 (nparts 0)) ;Number of body parts
1852 ;; Normalize the body part by inserting appropriate message
1853 ;; tags for every message contents.
1854 (mime-editor/normalize-body)
1855 ;; Counting the number of Content-Type.
1856 (goto-char (point-min))
1857 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1858 (setq nparts (1+ nparts)))
1859 ;; Begin translation.
1860 (cond ((and (<= nparts 1)(not multipart))
1861 ;; It's a singular message.
1862 (goto-char (point-min))
1863 (while (re-search-forward
1864 mime-editor/single-part-tag-regexp nil t)
1866 (buffer-substring (match-beginning 0) (match-end 0)))
1867 (delete-region (match-beginning 0) (1+ (match-end 0)))
1868 (setq contype (mime-editor/get-contype tag))
1869 (setq encoding (mime-editor/get-encoding tag))
1872 ;; It's a multipart message.
1873 (goto-char (point-min))
1874 (while (re-search-forward
1875 mime-editor/single-part-tag-regexp nil t)
1877 (buffer-substring (match-beginning 0) (match-end 0)))
1878 (delete-region (match-beginning 0) (match-end 0))
1879 (setq contype (mime-editor/get-contype tag))
1880 (setq encoding (mime-editor/get-encoding tag))
1881 (insert "--" boundary "\n")
1882 (insert "Content-Type: " contype "\n")
1884 (insert "Content-Transfer-Encoding: " encoding "\n"))
1886 ;; Define Content-Type as "multipart/mixed".
1888 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1889 ;; Content-Transfer-Encoding must be "7bit".
1890 ;; The following encoding can be `nil', but is
1891 ;; specified as is since there is no way that a user
1893 (setq encoding "7bit")
1894 ;; Insert the trailer.
1895 (goto-char (point-max))
1897 (insert "--" boundary "--\n")
1898 (insert "\n--" boundary "--\n")
1900 (list contype encoding boundary nparts)
1903 (defun mime-editor/normalize-body ()
1904 "Normalize the body part by inserting appropriate message tags."
1905 ;; Insert the first MIME tags if necessary.
1906 (goto-char (point-min))
1907 (if (not (looking-at mime-editor/single-part-tag-regexp))
1908 (insert (mime-make-text-tag) "\n"))
1909 ;; Check each tag, and add new tag or correct it if necessary.
1910 (goto-char (point-min))
1911 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1912 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1913 (contype (mime-editor/get-contype tag))
1914 (charset (mime-get-parameter contype "charset"))
1915 (encoding (mime-editor/get-encoding tag)))
1916 ;; Remove extra whitespaces after the tag.
1917 (if (looking-at "[ \t]+$")
1918 (delete-region (match-beginning 0) (match-end 0)))
1919 (cond ((= (following-char) ?\^M)
1920 ;; It must be image, audio or video.
1922 (end (mime-editor/content-end)))
1923 ;; Insert explicit MIME tags after hidden messages.
1925 (if (and (not (eobp))
1926 (not (looking-at mime-editor/single-part-tag-regexp)))
1928 (insert (mime-make-text-tag) "\n")
1929 (forward-line -1) ;Process it again as text.
1931 ;; Show a hidden message. The point is not altered
1932 ;; after the conversion.
1933 (mime-flag-region beg end ?\n)))
1934 ((mime-test-content-type contype "message")
1935 ;; 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 (if (string-equal contype "text/x-rot13-47")
1945 (goto-char (mime-editor/content-end))
1948 ;; Point is now on current tag.
1949 ;; Define encoding and encode text if necessary.
1950 (if (null encoding) ;Encoding is not specified.
1953 (assoc charset mime/charset-default-encoding-alist)
1955 (beg (mime-editor/content-beginning))
1956 (end (mime-editor/content-end))
1957 (body (buffer-substring beg end))
1958 (encoded (funcall mime-string-encoder
1959 (cons charset encoding) body)))
1960 (if (not (string-equal body encoded))
1963 (delete-region beg end)
1966 (mime-editor/define-encoding encoding)))
1968 ((null encoding) ;Encoding is not specified.
1969 ;; Application, image, audio, video, and any other
1970 ;; unknown content-type without encoding should be
1972 (let* ((encoding "base64") ;Encode in BASE64 by default.
1973 (beg (mime-editor/content-beginning))
1974 (end (mime-editor/content-end))
1975 (body (buffer-substring beg end))
1976 (encoded (funcall mime-string-encoder
1977 (cons nil encoding) body)))
1978 (if (not (string-equal body encoded))
1981 (delete-region beg end)
1984 (mime-editor/define-encoding encoding))
1989 (defun mime-delete-field (field)
1990 "Delete header FIELD."
1991 (let ((regexp (format "^%s:[ \t]*" field)))
1992 (goto-char (point-min))
1993 (while (re-search-forward regexp nil t)
1994 (delete-region (match-beginning 0)
1995 (progn (forward-line 1) (point)))
2000 ;;; Platform dependent functions
2003 ;; Emacs 18 implementations
2005 (defun mime-string-encoder-for-emacs18 (method string)
2006 "For given METHOD that is a cons of charset and encoding, encode a STRING."
2007 (let ((charset (car method))
2008 (encoding (cdr method)))
2009 (cond ((stringp encoding)
2010 (mime-encode-string encoding string))
2011 ;; Return string without any encoding.
2016 ;; Emacs 19 implementations
2018 (defun mime-string-encoder-for-emacs19 (method string)
2019 "For given METHOD that is a cons of charset and encoding, encode a STRING."
2020 (let ((charset (car method))
2021 (encoding (cdr method)))
2022 (cond ((stringp encoding)
2023 (mime-encode-string encoding string))
2024 ;; Return string without any encoding.
2029 ;; NEmacs implementations
2031 (defun mime-string-encoder-for-nemacs (method string)
2032 "For given METHOD that is a cons of charset and encoding, encode a STRING.
2033 US-ASCII and ISO-2022-JP are supported on NEmacs."
2034 (let ((charset (car method))
2035 (encoding (cdr method)))
2036 (cond ((stringp encoding)
2037 (mime-encode-string encoding
2038 ;; Convert internal (EUC) to JIS code.
2039 (convert-string-kanji-code string 3 2)
2041 ;; NEmacs can convert into ISO-2022-JP automatically,
2042 ;; but can do it myself as follows:
2043 ;;(t (convert-string-kanji-code string 3 2))
2045 ;; Return string without any encoding.
2050 ;; Mule implementations
2051 ;; Thanks to contributions by wkenji@flab.fujitsu.co.jp (Kenji
2052 ;; WAKAMIYA) and handa@etl.go.jp (Kenichi Handa).
2054 (defun mime-string-encoder-for-mule (method string)
2055 "For given METHOD that is a cons of charset and encoding, encode a
2056 STRING. US-ASCII, ISO-8859-* (except for ISO-8859-6), ISO-2022-JP,
2057 ISO-2022-JP-2 and ISO-2022-INT-1 are supported on Mule. Either of
2058 charset ISO-2022-JP-2 or ISO-2022-INT-1 is used for multilingual
2060 (let* ((charset (car method))
2061 (encoding (cdr method))
2063 (cdr (assoc (and (stringp charset) (upcase charset))
2064 '(("ISO-8859-1" . *ctext*)
2065 ("ISO-8859-2" . *iso-8859-2*)
2066 ("ISO-8859-3" . *iso-8859-3*)
2067 ("ISO-8859-4" . *iso-8859-4*)
2068 ("ISO-8859-5" . *iso-8859-5*)
2069 ;;("ISO-8859-6" . *iso-8859-6*)
2070 ("ISO-8859-7" . *iso-8859-7*)
2071 ("ISO-8859-8" . *iso-8859-8*)
2072 ("ISO-8859-9" . *iso-8859-9*)
2073 ("ISO-2022-JP" . *junet*)
2074 ("ISO-2022-JP-2" . *iso-2022-ss2-7*)
2075 ("ISO-2022-KR" . *korean-mail*)
2076 ("ISO-2022-INT-1" . *iso-2022-int-1*)
2078 ;; In bilingual environment it may be unnecessary to convert the
2079 ;; coding system of the string unless transfer encoding is
2080 ;; required since such conversion may be performed by mule
2082 (if (not (null coding-system))
2083 (setq string (code-convert-string string *internal* coding-system)))
2084 (if (stringp encoding)
2085 (setq string (mime-encode-string encoding string)))
2090 ;; Sun implementations
2092 (defun mime-voice-recorder-for-sun ()
2093 "Record voice in a buffer using Sun audio device, and return the buffer.
2094 If the environment variable AUDIOHOST is defined, its value is used as
2095 a recording host instead of local host."
2096 (let ((buffer (get-buffer-create " *MIME audio*"))
2097 (host (getenv "AUDIOHOST")))
2098 (message "Start the recording on %s. Type C-g to finish the recording..."
2099 (or host (system-name)))
2103 (condition-case errorcode
2104 (let ((selective-display nil) ;Disable ^M to nl translation.
2106 (kanji-flag nil)) ;NEmacs
2107 ;; If AUDIOHOST is defined, use the value as recording host.
2108 (cond ((not (null host))
2109 ;; Disable automatic conversion of coding system if Mule.
2110 (if (featurep 'mule)
2111 (define-program-coding-system nil "rsh" *noconv*))
2121 ;; Disable automatic conversion of coding system if Mule.
2122 (if (featurep 'mule)
2123 (define-program-coding-system nil "cat" *noconv*))
2129 (quit (message "Type C-g to finish recording... done.")
2130 buffer ;Return the buffer
2134 ;;; @ Other useful commands.
2137 ;; Message forwarding commands as content-type "message/rfc822".
2139 (defun mime-editor/insert-message (&optional message)
2141 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2142 (if (and inserter (fboundp inserter))
2144 (mime-editor/insert-tag "message" "rfc822")
2145 (funcall inserter message)
2147 (message "Sorry, I don't have message inserter for your MUA.")
2150 (defun mime-editor/insert-mail (&optional message)
2152 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2153 (if (and inserter (fboundp inserter))
2155 (mime-editor/insert-tag "message" "rfc822")
2156 (funcall inserter message)
2158 (message "Sorry, I don't have mail inserter for your MUA.")
2161 (defun mime-editor/inserted-message-filter ()
2164 (let ((header-start (point))
2165 (case-fold-search t)
2168 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2169 (if (re-search-forward "^$" (mark t))
2170 (narrow-to-region header-start (match-beginning 0))
2172 (goto-char header-start)
2173 (while (and (re-search-forward
2174 mime-editor/yank-ignored-field-regexp nil t)
2175 (setq beg (match-beginning 0))
2176 (setq end (1+ (rfc822/field-end)))
2178 (delete-region beg end)
2183 ;;; @ multipart enclosure
2186 (defun mime-editor/enclose-region (type beg end)
2189 (let ((current (point))
2192 (if (mime-editor/goto-tag)
2193 (or (eq current (match-beginning 0))
2194 (setq exist-prev-tag t)
2197 (narrow-to-region beg end)
2202 (insert (format "--<<%s>>-{\n" type))
2203 (goto-char (point-max))
2204 (insert (format "\n--}-<<%s>>\n" type))
2205 (goto-char (point-max))
2207 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
2209 (insert (mime-make-text-tag) "\n")
2213 (defun mime-editor/enclose-mixed-region (beg end)
2215 (mime-editor/enclose-region "mixed" beg end)
2218 (defun mime-editor/enclose-parallel-region (beg end)
2220 (mime-editor/enclose-region "parallel" beg end)
2223 (defun mime-editor/enclose-digest-region (beg end)
2225 (mime-editor/enclose-region "digest" beg end)
2228 (defun mime-editor/enclose-alternative-region (beg end)
2230 (mime-editor/enclose-region "alternative" beg end)
2233 (defun mime-editor/enclose-signed-region (beg end)
2235 (if mime-editor/signing-type
2236 (mime-editor/enclose-region "signed" beg end)
2237 (message "Please specify signing type.")
2240 (defun mime-editor/enclose-encrypted-region (beg end)
2242 (if mime-editor/signing-type
2243 (mime-editor/enclose-region "encrypted" beg end)
2244 (message "Please specify encrypting type.")
2247 (defun mime-editor/insert-key (&optional arg)
2248 "Insert a pgp public key."
2250 (mime-editor/insert-tag "application" "pgp-keys")
2251 (mime-editor/define-encoding "7bit")
2252 (mc-insert-public-key)
2259 (defun mime-editor/set-split (arg)
2262 (y-or-n-p "Do you want to enable split?")
2264 (setq mime-editor/split-message arg)
2266 (message "This message is enabled to split.")
2267 (message "This message is not enabled to split.")
2274 (defun mime-editor/set-sign (arg)
2277 (y-or-n-p "Do you want to sign?")
2280 (if mime-editor/signing-type
2282 (setq mime-editor/pgp-processing 'sign)
2283 (message "This message will be signed.")
2285 (message "Please specify signing type.")
2287 (if (eq mime-editor/pgp-processing 'sign)
2288 (setq mime-editor/pgp-processing nil)
2290 (message "This message will not be signed.")
2293 (defun mime-editor/set-encrypt (arg)
2296 (y-or-n-p "Do you want to encrypt?")
2299 (if mime-editor/encrypting-type
2301 (setq mime-editor/pgp-processing 'encrypt)
2302 (message "This message will be encrypt.")
2304 (message "Please specify encrypting type.")
2306 (if (eq mime-editor/pgp-processing 'encrypt)
2307 (setq mime-editor/pgp-processing nil)
2309 (message "This message will not be encrypt.")
2312 (defvar mime-editor/pgp-processing nil)
2313 (make-variable-buffer-local 'mime-editor/pgp-processing)
2315 (defun mime-editor/pgp-enclose-buffer ()
2316 (let ((beg (save-excursion
2317 (goto-char (point-min))
2318 (if (search-forward (concat "\n" mail-header-separator "\n"))
2324 (cond ((eq mime-editor/pgp-processing 'sign)
2325 (mime-editor/enclose-signed-region beg end)
2327 ((eq mime-editor/pgp-processing 'encrypt)
2328 (mime-editor/enclose-encrypted-region beg end)
2336 (defun mime-editor/insert-partial-header
2337 (fields subject id number total separator)
2339 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2340 (insert (format "Mime-Version: 1.0 (split by tm-edit %s)\n"
2341 mime-editor/version))
2343 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2344 id number total separator))
2347 (defun mime-editor/split-and-send
2348 (&optional cmd lines mime-editor/message-max-length)
2352 (count-lines (point-min) (point-max)))
2354 (or mime-editor/message-max-length
2355 (setq mime-editor/message-max-length
2356 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2357 mime-editor/message-default-max-length))
2359 (let* ((mime-editor/draft-file-name
2360 (or (buffer-file-name)
2362 (expand-file-name "tm-draft" mime/tmp-dir))))
2363 (separator mail-header-separator)
2365 (eval (cdr (assq major-mode mime-editor/window-config-alist))))
2367 (replace-space-with-underline (current-time-string))
2368 "@" (system-name) "\"")))
2369 (run-hooks 'mime-editor/before-split-hook)
2370 (let* ((header (rfc822/get-header-string-except
2371 mime-editor/split-ignored-field-regexp separator))
2372 (subject (mail-fetch-field "subject"))
2373 (total (+ (/ lines mime-editor/message-max-length)
2374 (if (> (mod lines mime-editor/message-max-length) 0)
2376 (the-buf (current-buffer))
2377 (buf (get-buffer "*tmp-send*"))
2382 mime-editor/split-message-sender-alist))
2385 mime-editor/message-default-sender-alist))
2388 (goto-char (point-min))
2389 (if (re-search-forward (concat "^" (regexp-quote separator) "$")
2395 (switch-to-buffer buf)
2397 (switch-to-buffer the-buf)
2399 (setq buf (get-buffer-create "*tmp-send*"))
2401 (switch-to-buffer buf)
2402 (make-local-variable 'mail-header-separator)
2403 (setq mail-header-separator separator)
2404 (switch-to-buffer the-buf)
2405 (goto-char (point-min))
2406 (re-search-forward "^$" nil t)
2407 (let ((mime-editor/partial-number 1))
2408 (setq data (buffer-substring
2411 (goto-line mime-editor/message-max-length)
2414 (delete-region (point-min)(point))
2415 (switch-to-buffer buf)
2416 (mime-editor/insert-partial-header
2417 header subject id mime-editor/partial-number total separator)
2421 (goto-char (point-min))
2422 (search-forward (concat "\n" mail-header-separator "\n"))
2425 (if (re-search-forward "^$" nil t)
2429 (goto-char (point-min))
2430 (while (re-search-forward
2431 mime-editor/split-blind-field-regexp nil t)
2432 (delete-region (match-beginning 0)
2433 (let ((e (rfc822/field-end)))
2434 (if (< e (point-max))
2440 (message (format "Sending %d/%d..."
2441 mime-editor/partial-number total))
2442 (call-interactively command)
2443 (message (format "Sending %d/%d... done"
2444 mime-editor/partial-number total))
2447 (switch-to-buffer the-buf)
2448 (setq mime-editor/partial-number 2)
2449 (while (< mime-editor/partial-number total)
2450 (setq data (buffer-substring
2453 (goto-line mime-editor/message-max-length)
2456 (delete-region (point-min)(point))
2457 (switch-to-buffer buf)
2458 (mime-editor/insert-partial-header
2459 header subject id mime-editor/partial-number total separator)
2462 (message (format "Sending %d/%d..."
2463 mime-editor/partial-number total))
2464 (call-interactively command)
2465 (message (format "Sending %d/%d... done"
2466 mime-editor/partial-number total))
2469 (switch-to-buffer the-buf)
2470 (setq mime-editor/partial-number
2471 (1+ mime-editor/partial-number))
2473 (goto-char (point-min))
2474 (mime-editor/insert-partial-header
2475 header subject id mime-editor/partial-number total separator)
2476 (message (format "Sending %d/%d..."
2477 mime-editor/partial-number total))
2480 (defun mime-editor/maybe-split-and-send (&optional cmd)
2482 (run-hooks 'mime-editor/before-send-hook)
2483 (let ((mime-editor/message-max-length
2484 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2485 mime-editor/message-default-max-length))
2486 (lines (count-lines (point-min) (point-max)))
2488 (if (and (> lines mime-editor/message-max-length)
2489 mime-editor/split-message)
2490 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2494 ;;; @ preview message
2497 (defun mime-editor/preview-message ()
2498 "preview editing MIME message. [tm-edit.el]"
2500 (let* ((str (buffer-string))
2501 (separator mail-header-separator)
2502 (the-buf (current-buffer))
2503 (buf-name (buffer-name))
2504 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2505 (buf (get-buffer temp-buf-name))
2509 (switch-to-buffer buf)
2512 (setq buf (get-buffer-create temp-buf-name))
2513 (switch-to-buffer buf)
2516 (setq major-mode 'mime/temporary-message-mode)
2517 (make-local-variable 'mail-header-separator)
2518 (setq mail-header-separator separator)
2519 (make-local-variable 'mime/editing-buffer)
2520 (setq mime/editing-buffer the-buf)
2522 (run-hooks 'mime-editor/translate-hook)
2523 (mime-editor/translate-buffer)
2524 (goto-char (point-min))
2525 (if (re-search-forward
2526 (concat "^" (regexp-quote separator) "$"))
2532 (defun mime-editor/quitting-method ()
2533 (let ((temp mime::preview/article-buffer)
2535 (mime-viewer/kill-buffer)
2537 (setq buf mime/editing-buffer)
2539 (switch-to-buffer buf)
2542 (set-alist 'mime-viewer/quitting-method-alist
2543 'mime/temporary-message-mode
2544 (function mime-editor/quitting-method)
2550 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2551 ;; Mon, 10 Apr 1995 20:03:07 +0900
2553 (defvar mime-editor/draft-header-separator-alist
2554 '((news-reply-mode . mail-header-separator)
2555 (mh-letter-mode . mail-header-separator)
2558 (defvar mime::article/draft-header-separator nil)
2560 (defun mime-editor/draft-preview ()
2562 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2563 (or (stringp sep) (setq sep (eval sep)))
2564 (make-variable-buffer-local 'mime::article/draft-header-separator)
2565 (goto-char (point-min))
2567 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2568 (setq mime::article/draft-header-separator
2569 (buffer-substring (match-beginning 0) (match-end 0)))
2571 (mime/viewer-mode (current-buffer))
2572 (pop-to-buffer (current-buffer))
2575 (defun mime-viewer::quitting-method/draft-preview ()
2576 (let ((mother mime::preview/mother-buffer))
2578 (switch-to-buffer mother)
2579 (goto-char (point-min))
2583 (regexp-quote mime::article/draft-header-separator)
2587 (insert mime::article/draft-header-separator)
2588 (set-buffer-modified-p (buffer-modified-p))
2590 (mime-viewer/kill-buffer)
2591 (pop-to-buffer mother)
2594 (set-alist 'mime-viewer/quitting-method-alist
2596 (function mime-viewer::quitting-method/draft-preview)
2599 (set-alist 'mime-viewer/quitting-method-alist
2601 (function mime-viewer::quitting-method/draft-preview)
2608 (defun mime-editor::edit-again ()
2610 (goto-char (point-min))
2611 (let ((ctl (mime/Content-Type)))
2613 (let ((ctype (car ctl))
2616 (if (string-match "/" ctype)
2618 (setq type (substring ctype 0 (match-beginning 0)))
2619 (setq stype (substring ctype (match-end 0)))
2623 (cond ((string-equal type "multipart")
2624 (let ((boundary (assoc-value "boundary" params)))
2625 (re-search-forward (concat "--" boundary) nil t)
2626 (let ((bb (match-beginning 0))
2628 (re-search-forward (concat "\n--" boundary "--") nil t)
2629 (setq eb (match-beginning 0))
2630 (setq ee (match-end 0))
2631 (delete-region eb ee)
2633 (narrow-to-region bb eb)
2634 (goto-char (point-min))
2635 (while (re-search-forward
2636 (concat "\\(\n\\|^\\)--" boundary "\n") nil t)
2637 (let ((beg (match-beginning 0))
2639 (delete-region beg (match-end 0))
2641 (if (re-search-forward
2642 (concat "\n--" boundary) nil t)
2643 (setq end (match-beginning 0))
2644 (setq end (point-max))
2647 (narrow-to-region beg end)
2648 (mime-editor::edit-again)
2649 (goto-char (point-max))
2652 (goto-char (point-min))
2653 (insert (format "--<<%s>>-{\n" stype))
2654 (goto-char (point-max))
2655 (insert (format "\n--}-<<%s>>" stype))
2657 (goto-char (point-min))
2658 (or (= (point-min) 1)
2659 (delete-region (point-min)
2660 (if (re-search-forward "^$" nil t)
2666 (let* ((str (rfc822/get-header-string-except
2667 "^Content-Type" ""))
2670 (mapconcat (function
2672 (if (string-equal (car attr)
2675 (setq charset (cdr attr))
2677 (concat ";" (car attr)
2684 (mime/code-convert-region-to-emacs (point-min)
2689 (setq pstr (concat pstr "\n" str))
2691 (or (= (point-min) 1)
2692 (delete-region (point-min)
2693 (if (re-search-forward "^$" nil t)
2697 (insert (mime-create-tag
2698 (concat type "/" stype pstr)))
2701 (defun mime/edit-again (&optional no-separator no-mode)
2703 (mime-editor::edit-again)
2704 (goto-char (point-min))
2706 (narrow-to-region (point-min)
2707 (if (re-search-forward "^$" nil t)
2711 (goto-char (point-min))
2712 (while (re-search-forward
2713 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2714 (delete-region (match-beginning 0) (1+ (rfc822/field-end)))
2717 (and (re-search-forward "^$")
2718 (replace-match mail-header-separator)
2728 (defun replace-space-with-underline (str)
2729 (mapconcat (function
2743 (run-hooks 'tm-edit-load-hook)
2745 ;;; tm-edit.el ends here