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.47 $
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.47 1996/03/05 23:19:05 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 charset, encoding and transfer-level
367 (defvar mime-editor/transfer-level 7
368 "*A number of network transfer level. It should be bigger than 7.")
369 (make-variable-buffer-local 'mime-editor/transfer-level)
371 (defvar mime-editor/transfer-level-string
372 (mime/encoding-name mime-editor/transfer-level 'not-omit)
373 "*A string formatted version of mime/defaul-transfer-level")
374 (make-variable-buffer-local 'mime-editor/transfer-level-string)
376 (defvar mime-editor/charset-default-encoding-alist
377 (mime/make-charset-default-encoding-alist mime-editor/transfer-level))
378 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
380 ;;; @@ about message inserting
383 (defvar mime-editor/yank-ignored-field-list
384 '("Received" "Sender" "Approved" "Path" "Status" "X-VM-.*" "X-UIDL")
385 "Delete these fields from original message when it is inserted
386 as message/rfc822 part.
387 Each elements are regexp of field-name. [tm-edit.el]")
389 (defvar mime-editor/yank-ignored-field-regexp
391 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
394 (defvar mime-editor/message-inserter-alist nil)
395 (defvar mime-editor/mail-inserter-alist nil)
397 ;;; @@ about message splitting
400 (defvar mime-editor/split-message t
401 "*Split large message if it is non-nil. [tm-edit.el]")
403 (defvar mime-editor/message-default-max-length 1000
404 "*Default maximum size of a message. [tm-edit.el]")
406 (defvar mime-editor/message-max-length-alist
407 '((news-reply-mode . 500)))
409 (defconst mime-editor/split-ignored-field-regexp
410 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
412 (defvar mime-editor/split-blind-field-regexp
413 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
415 (defvar mime-editor/message-default-sender-alist
416 '((mail-mode . mail-send-and-exit)
417 (mh-letter-mode . mh-send-letter)
418 (news-reply-mode . gnus-inews-news)
421 (defvar mime-editor/split-message-sender-alist
428 . (lambda (&optional arg)
430 (write-region (point-min) (point-max)
431 mime-editor/draft-file-name nil 'no-message)
433 (pop-to-buffer "MH mail delivery")
435 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
437 mh-send-args mime-editor/draft-file-name)
438 (goto-char (point-max)) ; show the interesting part
442 (apply 'mh-exec-cmd-quiet t mh-send-prog
444 (list "-nopush" "-nodraftfolder"
445 "-noverbose" "-nowatch"
446 mh-send-args mime-editor/draft-file-name)))))
450 (defvar mime-editor/window-config-alist
452 (mh-letter-mode . mh-previous-window-config)
453 (news-reply-mode . (cond ((boundp 'gnus-winconf-post-news)
455 gnus-winconf-post-news
456 (setq gnus-winconf-post-news nil)
458 ((boundp 'gnus-prev-winconf)
461 (setq gnus-prev-winconf nil)
466 (defvar mime-editor/news-reply-mode-server-running nil)
472 (defvar mime-editor/signing-type nil
473 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
475 (defvar mime-editor/encrypting-type nil
476 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
478 (if (or mime-editor/signing-type mime-editor/encrypting-type)
486 (defconst mime-editor/single-part-tag-regexp
487 "^--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
488 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
490 (defconst mime-editor/multipart-beginning-regexp "^--<<\\([^<>]+\\)>>-{\n")
492 (defconst mime-editor/multipart-end-regexp "^--}-<<\\([^<>]+\\)>>\n")
494 (defconst mime-editor/beginning-tag-regexp
495 (regexp-or mime-editor/single-part-tag-regexp
496 mime-editor/multipart-beginning-regexp))
498 (defconst mime-editor/end-tag-regexp
499 (regexp-or mime-editor/single-part-tag-regexp
500 mime-editor/multipart-end-regexp))
502 (defconst mime-editor/tag-regexp
503 (regexp-or mime-editor/single-part-tag-regexp
504 mime-editor/multipart-beginning-regexp
505 mime-editor/multipart-end-regexp))
507 (defvar mime-tag-format "--[[%s]]"
508 "*Control-string making a MIME tag.")
510 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
511 "*Control-string making a MIME tag with encoding.")
513 ;;; @@ multipart boundary
516 (defvar mime-multipart-boundary "Multipart"
517 "*Boundary of a multipart message.")
520 ;;; @@ buffer local variables
523 (defvar mime/editor-mode-old-local-map nil)
524 (defvar mime/editor-mode-old-selective-display nil)
525 (defvar mime/editing-buffer nil)
531 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
532 "*Specify MIME tspecials.
533 Tspecials means any character that matches with it in header must be quoted.")
535 (defconst mime-editor/mime-version-value
536 (format "1.0 (generated by tm-edit %s)" mime-editor/version)
537 "MIME version number.")
539 (defconst mime-editor/mime-map (make-sparse-keymap)
540 "Keymap for MIME commands.")
542 ;;; @ keymap and menu
545 (defvar mime/editor-mode-flag nil)
546 (make-variable-buffer-local 'mime/editor-mode-flag)
548 (set-alist 'minor-mode-alist
549 'mime/editor-mode-flag
550 '((" MIME-Edit " mime-editor/transfer-level-string)))
552 (defun mime-editor/define-keymap (keymap)
553 "Add mime-editor commands to KEYMAP."
554 (if (not (keymapp keymap))
556 (define-key keymap "\C-t" 'mime-editor/insert-text)
557 (define-key keymap "\C-i" 'mime-editor/insert-file)
558 (define-key keymap "\C-e" 'mime-editor/insert-external)
559 (define-key keymap "\C-v" 'mime-editor/insert-voice)
560 (define-key keymap "\C-y" 'mime-editor/insert-message)
561 (define-key keymap "\C-m" 'mime-editor/insert-mail)
562 (define-key keymap "\C-w" 'mime-editor/insert-signature)
563 (define-key keymap "\C-s" 'mime-editor/insert-signature)
564 (define-key keymap "\C-k" 'mime-editor/insert-key)
565 (define-key keymap "t" 'mime-editor/insert-tag)
566 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
567 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
568 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
569 (define-key keymap "d" 'mime-editor/enclose-digest-region)
570 (define-key keymap "s" 'mime-editor/enclose-signed-region)
571 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
572 (define-key keymap "\C-p" 'mime-editor/preview-message)
573 (define-key keymap "\C-z" 'mime-editor/exit)
574 (define-key keymap "?" 'mime-editor/help)
577 (mime-editor/define-keymap mime-editor/mime-map)
579 (defconst mime-editor/menu-title "MIME-Edit")
581 (defconst mime-editor/menu-list
582 '((mime-help "Describe MIME editor mode" mime-editor/help)
583 (file "Insert File" mime-editor/insert-file)
584 (external "Insert External" mime-editor/insert-external)
585 (voice "Insert Voice" mime-editor/insert-voice)
586 (message "Insert Message" mime-editor/insert-message)
587 (mail "Insert Mail" mime-editor/insert-mail)
588 (signature "Insert Signature" mime-editor/insert-signature)
589 (text "Insert Text" mime-editor/insert-text)
590 (tag "Insert Tag" mime-editor/insert-tag)
591 (alternative "Enclose as alternative"
592 mime-editor/enclose-alternative-region)
593 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
594 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
595 (digest "Enclose as digest" mime-editor/enclose-digest-region)
596 (signed "Enclose as signed" mime-editor/enclose-signed-region)
597 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
598 (key "Insert Public Key" mime-editor/insert-key)
599 (split "About split" mime-editor/set-split)
600 (sign "About sign" mime-editor/set-sign)
601 (encrypt "About encryption" mime-editor/set-encrypt)
602 (preview "Preview Message" mime-editor/preview-message)
603 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
605 "MIME-edit menubar entry.")
607 (defun mime-editor/define-menu-for-emacs19 ()
608 "Define menu for Emacs 19."
609 (define-key (current-local-map) [menu-bar mime-edit]
610 (cons mime-editor/menu-title
611 (make-sparse-keymap mime-editor/menu-title)))
614 (define-key (current-local-map)
615 (vector 'menu-bar 'mime-edit (car item))
616 (cons (nth 1 item)(nth 2 item))
619 (reverse mime-editor/menu-list)
622 ;;; modified by Pekka Marjola <pema@niksula.hut.fi>
623 ;;; 1995/9/5 (c.f. [tm-en:69])
624 (defun mime-editor/define-menu-for-xemacs ()
625 "Define menu for Emacs 19."
626 (cond ((featurep 'menubar)
627 (make-local-variable 'current-menubar)
628 (set-buffer-menubar current-menubar)
630 (cons mime-editor/menu-title
633 (vector (nth 1 item)(nth 2 item)
634 mime/editor-mode-flag)
636 mime-editor/menu-list)))
639 ;;; modified by Steven L. Baur <steve@miranova.com>
640 ;;; 1995/12/6 (c.f. [tm-en:209])
641 (if (and (string-match "XEmacs\\|Lucid" emacs-version)
642 (not (boundp 'mime-editor/popup-menu-for-xemacs)))
643 (setq mime-editor/popup-menu-for-xemacs
644 (append '("MIME Commands" "---")
645 (mapcar (function (lambda (item)
649 mime-editor/menu-list)))
658 (defun mime/editor-mode ()
659 "MIME minor mode for editing the tagged MIME message.
661 In this mode, basically, the message is composed in the tagged MIME
662 format. The message tag looks like:
664 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
666 The tag specifies the MIME content type, subtype, optional parameters
667 and transfer encoding of the message following the tag. Messages
668 without any tag are treated as `text/plain' by default. Charset and
669 transfer encoding are automatically defined unless explicitly
670 specified. Binary messages such as audio and image are usually hidden
671 using selective-display facility. The messages in the tagged MIME
672 format are automatically translated into a MIME compliant message when
675 Available charsets depend on Emacs version being used. The following
676 lists the available charsets of each emacs.
678 Emacs18: US-ASCII is only available.
679 NEmacs: US-ASCII and ISO-2022-JP are available.
680 Emacs19: US-ASCII and ISO-8859-1 are available.
681 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-6),
682 ISO-2022-JP, ISO-2022-JP-2 and ISO-2022-INT-1 are available.
684 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in Mule is expected to
685 be used to represent multilingual text in intermixed manner. Any
686 languages that has no registered charset are represented as either
687 ISO-2022-JP-2 or ISO-2022-INT-1 in Mule.
689 Following commands are available in addition to major mode commands:
690 \\[mime-editor/insert-text] insert a text message.
691 \\[mime-editor/insert-file] insert a (binary) file.
692 \\[mime-editor/insert-external] insert a reference to external body.
693 \\[mime-editor/insert-voice] insert a voice message.
694 \\[mime-editor/insert-message] insert a mail or news message.
695 \\[mime-editor/insert-mail] insert a mail message.
696 \\[mime-editor/insert-signature] insert a signature file at end.
697 \\[mime-editor/insert-tag] insert a new MIME tag.
698 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
699 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
700 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
701 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
702 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
703 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
704 \\[mime-editor/insert-key] insert PGP public key.
705 \\[mime-editor/preview-message] preview editing MIME message.
706 \\[mime-editor/exit] exit and translate into a MIME compliant message.
707 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
708 \\[mime-editor/help] show this help.
710 Additional commands are available in some major modes:
711 C-c C-c exit, translate and run the original command.
712 C-c C-s exit, translate and run the original command.
714 The following is a message example written in the tagged MIME format.
715 TABs at the beginning of the line are not a part of the message:
717 This is a conventional plain text. It should be translated
720 This is also a plain text. But, it is explicitly specified as
722 --[[text/plain; charset=ISO-2022-JP]]
723 \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
726 <center>This is a richtext.</center>
727 --[[image/gif][base64]]^M...image encoded in base64 here...
728 --[[audio/basic][base64]]^M...audio encoded in base64 here...
730 User customizable variables (not documented all of them):
732 Specifies a key prefix for MIME minor mode commands.
735 Specifies a signature file to be included as part of a multipart
738 mime-ignore-preceding-spaces
739 Preceding white spaces in a message body are ignored if non-nil.
741 mime-ignore-trailing-spaces
742 Trailing white spaces in a message body are ignored if non-nil.
744 mime-auto-fill-header
745 Fill header fields that contain encoded-words if non-nil.
748 Hide a non-textual body message encoded in base64 after insertion
752 Specifies a function to encode a string for given encoding method.
753 The method is a form of (CHARSET . ENCODING).
756 Specifies a function to record a voice message and return a buffer
757 that contains it. The function mime-voice-recorder-for-sun is for
760 mime/editor-mode-hook
761 Turning on MIME mode calls the value of mime/editor-mode-hook, if
764 mime-editor/translate-hook
765 The value of mime-editor/translate-hook is called just before translating
766 the tagged MIME format into a MIME compliant message if it is
767 non-nil. If the hook call the function mime-editor/insert-signature,
768 the signature file will be inserted automatically.
770 mime-editor/exit-hook
771 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
774 (if mime/editor-mode-flag
775 (error "You are already editing a MIME message.")
776 (setq mime/editor-mode-flag t)
777 ;; Remember old key bindings.
778 (if (string-match "XEmacs\\|Lucid" emacs-version)
780 (make-local-variable 'mime/editor-mode-old-local-map)
781 (setq mime/editor-mode-old-local-map (current-local-map))
782 ;; Add MIME commands to current local map.
783 (use-local-map (copy-keymap (current-local-map))))
784 (if (not (lookup-key (current-local-map) mime-prefix))
785 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
787 ;; Set transfer level into mode line
789 (setq mime-editor/transfer-level-string
790 (mime/encoding-name mime-editor/transfer-level 'not-omit))
791 (force-mode-line-update)
793 ;; Define menu. Menus for other emacs implementations are
795 ;; modified by Pekka Marjola <pema@niksula.hut.fi>
796 ;; 1995/9/5 (c.f. [tm-eng:69])
797 (cond ((string-match "XEmacs\\|Lucid" emacs-version)
798 (mime-editor/define-menu-for-xemacs))
799 ((string-match "^19\\." emacs-version)
800 (mime-editor/define-menu-for-emacs19)
804 ;; Remember old selective-display.
805 (make-local-variable 'mime/editor-mode-old-selective-display)
806 (setq mime/editor-mode-old-selective-display selective-display)
807 (setq selective-display t)
808 ;; I don't care about saving these.
809 (setq paragraph-start
810 (regexp-or mime-editor/single-part-tag-regexp
812 (setq paragraph-separate
813 (regexp-or mime-editor/single-part-tag-regexp
815 (run-hooks 'mime/editor-mode-hook)
817 (substitute-command-keys
818 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
822 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
823 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
825 (defun mime-editor/exit (&optional nomime no-error)
826 "Translate the tagged MIME message into a MIME compliant message.
827 With no argument encode a message in the buffer into MIME, otherwise
828 just return to previous mode."
830 (if (not mime/editor-mode-flag)
832 (error "You aren't editing a MIME message.")
836 (run-hooks 'mime-editor/translate-hook)
837 (mime-editor/translate-buffer)))
838 ;; Restore previous state.
839 (setq mime/editor-mode-flag nil)
840 (cond ((string-match "XEmacs\\|Lucid" emacs-version)
841 ;; mime-prefix only defined if binding was nil
842 (if (eq (lookup-key (current-local-map) mime-prefix)
843 mime-editor/mime-map)
844 (define-key (current-local-map) mime-prefix nil))
845 (delete-menu-item (list mime-editor/menu-title)))
847 (use-local-map mime/editor-mode-old-local-map)))
849 (setq selective-display mime/editor-mode-old-selective-display)
850 (set-buffer-modified-p (buffer-modified-p))
851 (run-hooks 'mime-editor/exit-hook)
852 (message "Exit MIME editor mode.")
855 (defun mime-editor/maybe-translate ()
857 (mime-editor/exit nil t)
858 (call-interactively 'mime-editor/maybe-split-and-send)
861 (defun mime-editor/help ()
862 "Show help message about MIME mode."
864 (with-output-to-temp-buffer "*Help*"
865 (princ "MIME editor mode:\n")
866 (princ (documentation 'mime/editor-mode))
867 (print-help-return-message)))
869 (defun mime-editor/insert-text ()
870 "Insert a text message.
871 Charset is automatically obtained from the `mime/lc-charset-alist'."
873 (if (and (mime-editor/insert-tag "text" nil nil)
874 (looking-at mime-editor/single-part-tag-regexp))
876 ;; Make a space between the following message.
881 (defun mime-editor/insert-file (file)
882 "Insert a message from a file."
883 (interactive "fInsert file as MIME message: ")
884 (let* ((guess (mime-find-file-type file))
885 (pritype (nth 0 guess))
886 (subtype (nth 1 guess))
887 (parameters (nth 2 guess))
888 (default (nth 3 guess)) ;Guess encoding from its file name.
889 (disposition-type (nth 4 guess))
890 (disposition-params (nth 5 guess))
892 (if (not (interactive-p))
895 (concat "What transfer encoding"
898 (if (string-equal default "")
904 mime-encoding-method-alist nil t nil))))
905 (if (string-equal encoding "")
906 (setq encoding default))
907 (if (or (consp parameters) (stringp disposition-type))
908 (let ((rest parameters) cell attribute value)
911 (setq cell (car rest))
912 (setq attribute (car cell))
913 (setq value (cdr cell))
915 (setq value (rfc822/wrap-as-quoted-string
916 (file-name-nondirectory file)))
918 (setq parameters (concat parameters "; " attribute "=" value))
919 (setq rest (cdr rest))
924 (concat parameters "\n"
925 "Content-Disposition: " disposition-type))
926 (setq rest disposition-params)
928 (setq cell (car rest))
929 (setq attribute (car cell))
930 (setq value (cdr cell))
932 (setq value (rfc822/wrap-as-quoted-string
933 (file-name-nondirectory file)))
936 (concat parameters "; " attribute "=" value))
937 (setq rest (cdr rest))
941 (mime-editor/insert-tag pritype subtype parameters)
942 (mime-editor/insert-binary-file file encoding)
945 (defun mime-editor/insert-external ()
946 "Insert a reference to external body."
948 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
950 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
952 (let* ((pritype (mime-prompt-for-type))
953 (subtype (mime-prompt-for-subtype pritype))
954 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
957 (insert "Content-Type: "
958 pritype "/" subtype (or parameters "") "\n")))
959 (if (and (not (eobp))
960 (not (looking-at mime-editor/single-part-tag-regexp)))
961 (insert (mime-make-text-tag) "\n")))
963 (defun mime-editor/insert-voice ()
964 "Insert a voice message."
966 (mime-editor/insert-tag "audio" "basic" nil)
967 (let ((buffer (funcall mime-voice-recorder)))
969 (mime-editor/insert-binary-buffer buffer "base64")
973 (defun mime-editor/insert-signature (&optional arg)
974 "Insert a signature file specified by mime-signature-file."
979 (read-file-name "Insert your signature: "
980 (concat signature-file-name "-")
983 (signature/get-signature-file-name))))
985 (if signature-insert-at-eof
986 (goto-char (point-max))
988 (apply (function mime-editor/insert-tag)
989 (mime-find-file-type signature))
990 (if (file-readable-p signature)
992 (goto-char (point-max))
996 (insert-file-contents signature)
997 (set-buffer-modified-p (buffer-modified-p))
998 ; force mode line update
1002 ;; Insert a new tag around a point.
1004 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
1005 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
1006 If nothing is inserted, return nil."
1011 exist-prev-tag exist-next-tag)
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)
1028 (if (eq current (match-beginning 0))
1029 (setq exist-next-tag t)
1030 (setq exist-prev-tag t)
1032 (buffer-substring (match-beginning 0) (match-end 0))
1034 ;; Assume content type is 'text/plan'.
1035 (mime-make-tag "text" "plain")
1037 ;; We are only interested in TEXT.
1039 (not (mime-test-content-type
1040 (mime-editor/get-contype oldtag) "text")))
1042 (cond (exist-prev-tag (insert "\n"))
1043 (exist-next-tag (save-excursion
1052 (if (or (not oldtag) ;Not text
1053 (or mime-ignore-same-text-tag
1054 (not (string-equal oldtag newtag))))
1056 ;; Mark the beginning of the tag for convenience.
1057 (push-mark (point) 'nomsg)
1058 (insert newtag "\n")
1059 (list pritype subtype parameters) ;New tag is created.
1061 ;; Restore previous point.
1063 nil ;Nothing is created.
1067 ;; Insert the binary content after MIME tag.
1068 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1070 (defun mime-editor/insert-binary-file (file &optional encoding)
1071 "Insert binary FILE at point.
1072 Optional argument ENCODING specifies an encoding method such as base64."
1073 (let ((tmpbuf (get-buffer-create " *MIME insert*")))
1077 (let ((mc-flag nil) ;Mule
1078 (file-coding-system-for-read
1079 (if (featurep 'mule) *noconv*))
1080 (kanji-flag nil) ;NEmacs
1081 (emx-binary-mode t) ;Stop CRLF to LF conversion in OS/2
1083 (let (jka-compr-compression-info-list
1084 jam-zcat-filename-list)
1085 (insert-file-contents file))))
1087 (if (and (stringp encoding)
1088 (string-equal (downcase encoding) "x-uue"))
1091 (let ((uuencode-external-encoder
1092 (cons (car uuencode-external-encoder)
1093 (list (file-name-nondirectory file))
1095 (mime-editor/insert-binary-buffer tmpbuf encoding)
1097 (mime-editor/insert-binary-buffer tmpbuf encoding))
1098 (kill-buffer tmpbuf))))
1100 ;; Insert the binary content after MIME tag.
1101 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1103 (defun mime-editor/insert-binary-buffer (buffer &optional encoding)
1104 "Insert binary BUFFER at point.
1105 Optional argument ENCODING specifies an encoding method such as base64."
1106 (let* ((tagend (1- (point))) ;End of the tag
1107 (hide-p (and mime-auto-hide-body
1109 (let ((en (downcase encoding)))
1110 (or (string-equal en "base64")
1111 (string-equal en "x-uue")
1115 (narrow-to-region (1- (point)) (point))
1116 (let ((start (point))
1117 (emx-binary-mode t)) ;Stop LF to CRLF conversion in OS/2
1118 (insert-buffer-substring buffer)
1119 ;; Encode binary message if necessary.
1121 (mime-encode-region encoding start (point-max))))
1124 (mime-flag-region (point-min) (1- (point-max)) ?\^M)
1125 (goto-char (point-max)))
1127 ;; Define encoding even if it is 7bit.
1128 (if (stringp encoding)
1130 (goto-char tagend) ;Make sure which line the tag is on.
1131 (mime-editor/define-encoding encoding)))
1135 ;; Commands work on a current message flagment.
1137 (defun mime-editor/goto-tag ()
1138 "Search for the beginning of the tagged MIME message."
1139 (let ((current (point)) multipart)
1140 (if (looking-at mime-editor/tag-regexp)
1142 ;; At first, go to the end.
1143 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1144 (goto-char (match-beginning 0)) ;For multiline tag
1149 (goto-char (point-max))
1151 ;; Then search for the beginning.
1152 (re-search-backward mime-editor/end-tag-regexp nil t)
1154 (or (looking-at mime-editor/beginning-tag-regexp)
1155 ;; Restore previous point.
1162 (defun mime-editor/content-beginning ()
1163 "Return the point of the beginning of content."
1165 (let ((beg (save-excursion
1166 (beginning-of-line) (point))))
1167 (if (mime-editor/goto-tag)
1168 (let ((top (point)))
1169 (goto-char (match-end 0))
1170 (if (and (= beg top)
1171 (= (following-char) ?\^M))
1175 ;; Default text/plain tag.
1176 (goto-char (point-min))
1178 (concat "\n" (regexp-quote mail-header-separator)
1179 (if mime-ignore-preceding-spaces
1180 "[ \t\n]*\n" "\n")) nil 'move)
1184 (defun mime-editor/content-end ()
1185 "Return the point of the end of content."
1187 (let ((beg (save-excursion
1188 (beginning-of-line) (point))))
1189 (if (mime-editor/goto-tag)
1190 (let ((top (point)))
1191 (goto-char (match-end 0))
1192 (if (and (= beg top) ;Must be on the same line.
1193 (= (following-char) ?\^M))
1197 ;; Move to the end of this text.
1198 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1199 ;; Don't forget a multiline tag.
1200 (goto-char (match-beginning 0)))
1203 ;; Assume the message begins with text/plain.
1204 (goto-char (mime-editor/content-beginning))
1205 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1206 ;; Don't forget a multiline tag.
1207 (goto-char (match-beginning 0)))
1211 (defun mime-editor/define-charset (charset)
1212 "Set charset of current tag to CHARSET."
1214 (if (mime-editor/goto-tag)
1215 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1216 (delete-region (match-beginning 0) (match-end 0))
1218 (mime-create-tag (mime-set-parameter
1219 (mime-editor/get-contype tag) "charset" charset)
1220 (mime-editor/get-encoding tag))))
1223 (defun mime-editor/define-encoding (encoding)
1224 "Set encoding of current tag to ENCODING."
1226 (if (mime-editor/goto-tag)
1227 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1228 (delete-region (match-beginning 0) (match-end 0))
1229 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1232 (defun mime-editor/choose-charset ()
1233 "Choose charset of a text following current point."
1234 (mime/find-charset-region (point) (mime-editor/content-end))
1237 (defun mime-make-text-tag (&optional subtype)
1238 "Make a tag for a text after current point.
1239 Subtype of text type can be specified by an optional argument SUBTYPE.
1240 Otherwise, it is obtained from mime-content-types."
1241 (let* ((pritype "text")
1242 (subtype (or subtype
1243 (car (car (cdr (assoc pritype mime-content-types)))))))
1244 ;; Charset should be defined later.
1245 (mime-make-tag pritype subtype)))
1248 ;; Tag handling functions
1250 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1251 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1252 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1256 (defun mime-create-tag (contype &optional encoding)
1257 "Make a tag with CONTENT-TYPE and optional ENCODING."
1258 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1261 (defun mime-editor/get-contype (tag)
1262 "Return Content-Type (including parameters) of TAG."
1264 (or (string-match mime-editor/single-part-tag-regexp tag)
1265 (string-match mime-editor/multipart-beginning-regexp tag)
1266 (string-match mime-editor/multipart-end-regexp tag)
1268 (substring tag (match-beginning 1) (match-end 1))
1271 (defun mime-editor/get-encoding (tag)
1272 "Return encoding of TAG."
1274 (string-match mime-editor/single-part-tag-regexp tag)
1276 (not (= (match-beginning 3) (match-end 3)))
1277 (substring tag (match-beginning 3) (match-end 3))))
1279 (defun mime-get-parameter (contype parameter)
1280 "For given CONTYPE return value for PARAMETER.
1281 Nil if no such parameter."
1285 (regexp-quote parameter)
1286 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1288 (substring contype (match-beginning 1) (match-end 1))
1289 nil ;No such parameter
1292 (defun mime-set-parameter (contype parameter value)
1293 "For given CONTYPE set PARAMETER to VALUE."
1297 (regexp-quote parameter)
1298 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1301 (concat (substring contype 0 (match-beginning 1))
1303 (substring contype (match-end 1)))
1304 (concat contype "; " parameter "=" value)))
1306 (defun mime-strip-parameters (contype)
1307 "Return primary content-type and subtype without parameters for CONTYPE."
1308 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1309 (substring contype (match-beginning 1) (match-end 1)) nil))
1311 (defun mime-test-content-type (contype type &optional subtype)
1312 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1313 (and (stringp contype)
1316 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1317 (downcase contype))))
1322 (defun mime-find-file-type (file)
1323 "Guess Content-Type, subtype, and parameters from FILE."
1325 (guesses mime-file-types))
1326 (while (and (not guess) guesses)
1327 (if (string-match (car (car guesses)) file)
1328 (setq guess (cdr (car guesses))))
1329 (setq guesses (cdr guesses)))
1333 (defun mime-prompt-for-type ()
1334 "Ask for Content-type."
1336 ;; Repeat until primary content type is specified.
1337 (while (string-equal type "")
1339 (completing-read "What content type: "
1342 'require-match ;Type must be specified.
1345 (if (string-equal type "")
1347 (message "Content type is required.")
1355 (defun mime-prompt-for-subtype (pritype)
1356 "Ask for Content-type subtype of Content-Type PRITYPE."
1357 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1362 "What content subtype: (default " default ") ")
1363 "What content subtype: ")
1364 (cdr (assoc pritype mime-content-types))
1366 'require-match ;Subtype must be specified.
1369 (if (string-equal answer "") default answer)))
1371 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1372 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1373 Optional DELIMITER specifies parameter delimiter (';' by default)."
1374 (let* ((delimiter (or delimiter "; "))
1379 (mime-prompt-for-parameters-1
1381 (cdr (assoc pritype mime-content-types))))))
1384 (if (and (stringp parameters)
1385 (not (string-equal parameters "")))
1386 (concat delimiter parameters)
1387 "" ;"" if no parameters
1390 (defun mime-prompt-for-parameters-1 (optlist)
1391 (apply (function append)
1392 (mapcar (function mime-prompt-for-parameter) optlist)))
1394 (defun mime-prompt-for-parameter (parameter)
1396 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1397 (let* ((prompt (car parameter))
1398 (choices (mapcar (function
1400 (if (consp e) e (list e))))
1402 (default (car (car choices)))
1408 (concat "What " prompt
1410 (if (string-equal default "") "\"\"" default)
1412 choices nil nil ""))
1413 ;; If nothing is selected, use default.
1414 (if (string-equal answer "")
1415 (setq answer default)))
1417 (read-string (concat "What " prompt ": "))))
1418 (cons (if (and answer
1419 (not (string-equal answer "")))
1421 ;; Note: control characters ignored!
1422 (if (string-match mime-tspecials-regexp answer)
1423 (concat "\"" answer "\"") answer)))
1424 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1427 (defun mime-encode-string (encoding string)
1428 "Using ENCODING encode a STRING.
1429 If the STRING is too long, the encoded string may be broken into
1432 (set-buffer (get-buffer-create " *MIME encoding*"))
1435 (mime-encode-region encoding (point-min) (point-max))
1437 (buffer-substring (point-min) (point-max))
1438 (kill-buffer (current-buffer)))))
1440 (defun mime-decode-string (encoding string)
1441 "Using ENCODING decode a STRING."
1443 (set-buffer (get-buffer-create " *MIME decoding*"))
1446 (mime-decode-region encoding (point-min) (point-max))
1448 (buffer-substring (point-min) (point-max))
1449 (kill-buffer (current-buffer)))))
1451 (defun mime-flag-region (from to flag)
1452 "Hides or shows lines from FROM to TO, according to FLAG.
1453 If FLAG is `\\n' (newline character) then text is shown,
1454 while if FLAG is `\\^M' (control-M) the text is hidden."
1455 (let ((buffer-read-only nil) ;Okay even if write protected.
1456 (modp (buffer-modified-p)))
1458 (subst-char-in-region from to
1459 (if (= flag ?\n) ?\^M ?\n)
1461 (set-buffer-modified-p modp))))
1464 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1467 (defun mime-editor/translate-buffer ()
1468 "Encode the tagged MIME message in current buffer in MIME compliant message."
1470 (if (catch 'mime-editor/error
1472 (mime-editor/pgp-enclose-buffer)
1473 (mime/encode-message-header)
1474 (mime-editor/translate-body)
1478 (error "Translation error!")
1481 (defun mime-editor/find-inmost ()
1482 (goto-char (point-min))
1483 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1484 (let ((bb (match-beginning 0))
1486 (type (buffer-substring (match-beginning 1)(match-end 1)))
1488 (setq end-exp (format "^--}-<<%s>>\n" type))
1490 (if (re-search-forward end-exp nil t)
1492 (setq eb (match-beginning 0))
1493 (setq ee (match-end 0))
1495 (setq eb (point-max))
1496 (setq ee (point-max))
1498 (narrow-to-region be eb)
1500 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1502 (narrow-to-region (match-beginning 0)(point-max))
1503 (mime-editor/find-inmost)
1506 ;;(delete-region eb ee)
1507 (list type bb be eb)
1510 (defun mime-editor/process-multipart-1 (boundary)
1511 (let ((ret (mime-editor/find-inmost)))
1513 (let ((type (car ret))
1514 (bb (nth 1 ret))(be (nth 2 ret))
1517 (narrow-to-region bb eb)
1518 (delete-region bb be)
1519 (setq bb (point-min))
1520 (setq eb (point-max))
1523 (if (looking-at mime-editor/multipart-end-regexp)
1524 (let ((beg (match-beginning 0))
1527 (delete-region beg end)
1528 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
1530 (insert (concat (mime-make-text-tag) "\n"))
1532 (cond ((string= type "signed")
1533 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1534 (mime-editor/sign-pgp-elkins bb eb boundary)
1536 ((eq mime-editor/signing-type 'pgp-kazu)
1537 (mime-editor/process-pgp-kazu 'mc-sign
1541 ((string= type "encrypted")
1542 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1543 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1545 ((eq mime-editor/signing-type 'pgp-kazu)
1546 (mime-editor/process-pgp-kazu 'mc-encrypt
1551 (nth 2 (mime-editor/translate-region bb eb
1555 (format "--[[multipart/%s;
1556 boundary=\"%s\"][7bit]]\n"
1561 (defun tm:mc-pgp-generic-parser (result)
1562 (let ((ret (mc-pgp-generic-parser result)))
1564 (vector (car ret)(cdr ret))
1567 (autoload 'mc-pgp-lookup-key "mc-pgp")
1569 (defun tm:mc-process-region
1570 (beg end passwd program args parser &optional buffer boundary)
1571 (let ((obuf (current-buffer))
1572 (process-connection-type nil)
1573 mybuf result rgn proc)
1576 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1580 (buffer-disable-undo mybuf)
1582 (apply 'start-process "*PGP*" mybuf program args))
1585 (process-send-string proc (concat passwd "\n"))
1586 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1587 (process-send-region proc beg end)
1588 (process-send-eof proc)
1589 (while (eq 'run (process-status proc))
1590 (accept-process-output proc 5))
1591 (setq result (process-exit-status proc))
1592 ;; Hack to force a status_notify() in Emacs 19.29
1593 (delete-process proc)
1595 (goto-char (point-max))
1596 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1597 (delete-region (match-beginning 0) (match-end 0)))
1598 (goto-char (point-min))
1600 (while (search-forward "\r\n" nil t)
1601 (replace-match "\n"))
1602 ;; Hurm. FIXME; must get better result codes.
1603 (if (stringp result)
1604 (error "%s exited abnormally: '%s'" program result)
1605 (setq rgn (funcall parser result))
1606 ;; If the parser found something, migrate it
1612 (narrow-to-region beg end)
1614 (insert (format "--%s\n" boundary))
1615 (goto-char (point-max))
1616 (insert (format "\n--%s
1617 Content-Type: application/pgp-signature
1618 Content-Transfer-Encoding: 7bit
1621 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1622 (goto-char (point-max))
1623 (insert (format "\n--%s--\n" boundary))
1625 (delete-region beg end)
1627 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1630 (delete-region (car rgn) (cdr rgn)))))
1631 ;; Return nil on failure and exit code on success
1633 ;; Cleanup even on nonlocal exit
1634 (if (and proc (eq 'run (process-status proc)))
1635 (interrupt-process proc))
1637 (or buffer (null mybuf) (kill-buffer mybuf)))))
1639 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1640 (if (not (boundp 'mc-pgp-user-id))
1643 (let ((process-environment process-environment)
1644 (buffer (get-buffer-create mc-buffer-name))
1646 (parser (function mc-pgp-generic-parser))
1647 (pgp-path mc-pgp-path)
1649 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1653 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1654 (setenv "PGPPASSFD" "0")
1660 (list "+verbose=1" "+language=en"
1661 (format "+clearsig=%s" (if unclear "off" "on"))
1662 "+batchmode" "-u" (cdr key))))
1664 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1666 (message "Signing as %s ..." (car key))
1667 (if (tm:mc-process-region
1668 start end passwd pgp-path args parser buffer boundary)
1672 (goto-char (point-min))
1675 --[[multipart/signed; protocol=\"application/pgp-signature\";
1676 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1678 (message "Signing as %s ... Done." (car key))
1682 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1685 (narrow-to-region beg end)
1687 (mime-editor/translate-region beg end boundary))
1689 (encoding (nth 1 ret))
1691 (pgp-boundary (concat "pgp-sign-" boundary))
1694 (insert (format "Content-Type: %s\n" ctype))
1696 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1699 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1700 nil nil pgp-boundary)
1701 (throw 'mime-editor/error 'pgp-error)
1705 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1707 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1710 (let ((from (rfc822/get-field-body "From"))
1711 (to (rfc822/get-field-body "To"))
1712 (cc (rfc822/get-field-body "cc"))
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))
1723 (if (and (stringp from)
1724 (not (string-equal from "")))
1725 (insert (format "From: %s\n" from))
1727 (if (and (stringp to)
1728 (not (string-equal to "")))
1730 (insert (format "To: %s\n" to))
1731 (setq recipients to)
1733 (if (and (stringp cc)
1734 (not (string-equal cc "")))
1736 (insert (format "cc: %s\n" cc))
1738 (setq recipients (concat recipients "," cc))
1739 (setq recipients cc)
1741 (insert (format "Content-Type: %s\n" ctype))
1743 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1747 (let ((mc-pgp-always-sign 'never))
1748 (mc-pgp-encrypt-region
1749 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1750 (point-min) (point-max) from nil)
1752 (throw 'mime-editor/error 'pgp-error)
1755 (insert (format "--[[multipart/encrypted;
1757 protocol=\"application/pgp-encrypted\"][7bit]]
1759 Content-Type: application/pgp-encrypted
1762 Content-Type: application/octet-stream
1763 Content-Transfer-Encoding: 7bit
1765 " pgp-boundary pgp-boundary pgp-boundary))
1766 (goto-char (point-max))
1767 (insert (format "\n--%s--\n" pgp-boundary))
1770 (defun mime-editor/process-pgp-kazu (type beg end boundary)
1773 (narrow-to-region beg end)
1775 (mime-editor/translate-region beg end boundary))
1777 (encoding (nth 1 ret))
1781 (insert (format "Content-Type: %s\n" ctype))
1783 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1791 (let ((mail-header-separator "="))
1792 (call-interactively type)
1795 (and (search-forward "=\n")
1798 (throw 'mime-editor/error 'pgp-error)
1802 "--[[application/pgp; format=mime][7bit]]\n")
1806 (defun mime-editor/translate-body ()
1807 "Encode the tagged MIME body in current buffer in MIME compliant message."
1811 (concat mime-multipart-boundary "_"
1812 (replace-space-with-underline (current-time-string))
1816 (while (mime-editor/process-multipart-1
1817 (format "%s-%d" boundary i))
1821 ;; We are interested in message body.
1824 (goto-char (point-min))
1826 (concat "\n" (regexp-quote mail-header-separator)
1827 (if mime-ignore-preceding-spaces
1828 "[ \t\n]*\n" "\n")) nil 'move)
1832 (goto-char (point-max))
1833 (and mime-ignore-trailing-spaces
1834 (re-search-backward "[^ \t\n]\n" beg t)
1837 (setq ret (mime-editor/translate-region
1839 (format "%s-%d" boundary i)))
1841 (let ((contype (car ret)) ;Content-Type
1842 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1844 ;; Make primary MIME headers.
1845 (or (mail-position-on-field "Mime-Version")
1846 (insert mime-editor/mime-version-value))
1847 ;; Remove old Content-Type and other fields.
1849 (goto-char (point-min))
1850 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1851 (narrow-to-region (point-min) (point))
1852 (goto-char (point-min))
1853 (mime-delete-field "Content-Type")
1854 (mime-delete-field "Content-Transfer-Encoding"))
1855 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1856 (mail-position-on-field "Content-Type")
1860 (mail-position-on-field "Content-Transfer-Encoding")
1864 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1867 (concat mime-multipart-boundary "_"
1868 (replace-space-with-underline (current-time-string))))
1872 (narrow-to-region beg end)
1873 (let ((tag nil) ;MIME tag
1874 (contype nil) ;Content-Type
1875 (encoding nil) ;Content-Transfer-Encoding
1876 (nparts 0)) ;Number of body parts
1877 ;; Normalize the body part by inserting appropriate message
1878 ;; tags for every message contents.
1879 (mime-editor/normalize-body)
1880 ;; Counting the number of Content-Type.
1881 (goto-char (point-min))
1882 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1883 (setq nparts (1+ nparts)))
1884 ;; Begin translation.
1885 (cond ((and (<= nparts 1)(not multipart))
1886 ;; It's a singular message.
1887 (goto-char (point-min))
1888 (while (re-search-forward
1889 mime-editor/single-part-tag-regexp nil t)
1891 (buffer-substring (match-beginning 0) (match-end 0)))
1892 (delete-region (match-beginning 0) (1+ (match-end 0)))
1893 (setq contype (mime-editor/get-contype tag))
1894 (setq encoding (mime-editor/get-encoding tag))
1897 ;; It's a multipart message.
1898 (goto-char (point-min))
1899 (while (re-search-forward
1900 mime-editor/single-part-tag-regexp nil t)
1902 (buffer-substring (match-beginning 0) (match-end 0)))
1903 (delete-region (match-beginning 0) (match-end 0))
1904 (setq contype (mime-editor/get-contype tag))
1905 (setq encoding (mime-editor/get-encoding tag))
1906 (insert "--" boundary "\n")
1907 (insert "Content-Type: " contype "\n")
1909 (insert "Content-Transfer-Encoding: " encoding "\n"))
1911 ;; Define Content-Type as "multipart/mixed".
1913 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1914 ;; Content-Transfer-Encoding must be "7bit".
1915 ;; The following encoding can be `nil', but is
1916 ;; specified as is since there is no way that a user
1918 (setq encoding "7bit")
1919 ;; Insert the trailer.
1920 (goto-char (point-max))
1922 (insert "--" boundary "--\n")
1923 (insert "\n--" boundary "--\n")
1925 (list contype encoding boundary nparts)
1928 (defun mime-editor/normalize-body ()
1929 "Normalize the body part by inserting appropriate message tags."
1930 ;; Insert the first MIME tags if necessary.
1931 (goto-char (point-min))
1932 (if (not (looking-at mime-editor/single-part-tag-regexp))
1933 (insert (mime-make-text-tag) "\n"))
1934 ;; Check each tag, and add new tag or correct it if necessary.
1935 (goto-char (point-min))
1936 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1937 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1938 (contype (mime-editor/get-contype tag))
1939 (charset (mime-get-parameter contype "charset"))
1940 (encoding (mime-editor/get-encoding tag)))
1941 ;; Remove extra whitespaces after the tag.
1942 (if (looking-at "[ \t]+$")
1943 (delete-region (match-beginning 0) (match-end 0)))
1944 (cond ((= (following-char) ?\^M)
1945 ;; It must be image, audio or video.
1947 (end (mime-editor/content-end)))
1948 ;; Insert explicit MIME tags after hidden messages.
1950 (if (and (not (eobp))
1951 (not (looking-at mime-editor/single-part-tag-regexp)))
1953 (insert (mime-make-text-tag) "\n")
1954 (forward-line -1) ;Process it again as text.
1956 ;; Show a hidden message. The point is not altered
1957 ;; after the conversion.
1958 (mime-flag-region beg end ?\n)))
1959 ((mime-test-content-type contype "message")
1960 ;; Content-type "message" should be sent as is.
1962 ((mime-test-content-type contype "text")
1963 ;; Define charset for text if necessary.
1964 (setq charset (or charset (mime-editor/choose-charset)))
1965 (mime-editor/define-charset charset)
1966 (if (string-equal contype "text/x-rot13-47")
1970 (goto-char (mime-editor/content-end))
1973 ;; Point is now on current tag.
1974 ;; Define encoding and encode text if necessary.
1975 (if (null encoding) ;Encoding is not specified.
1979 mime-editor/charset-default-encoding-alist)
1981 (beg (mime-editor/content-beginning))
1982 (end (mime-editor/content-end))
1983 (body (buffer-substring beg end))
1984 (encoded (funcall mime-string-encoder
1985 (cons charset encoding) body)))
1986 (if (not (string-equal body encoded))
1989 (delete-region beg end)
1992 (mime-editor/define-encoding encoding)))
1994 ((null encoding) ;Encoding is not specified.
1995 ;; Application, image, audio, video, and any other
1996 ;; unknown content-type without encoding should be
1998 (let* ((encoding "base64") ;Encode in BASE64 by default.
1999 (beg (mime-editor/content-beginning))
2000 (end (mime-editor/content-end))
2001 (body (buffer-substring beg end))
2002 (encoded (funcall mime-string-encoder
2003 (cons nil encoding) body)))
2004 (if (not (string-equal body encoded))
2007 (delete-region beg end)
2010 (mime-editor/define-encoding encoding))
2015 (defun mime-delete-field (field)
2016 "Delete header FIELD."
2017 (let ((regexp (format "^%s:[ \t]*" field)))
2018 (goto-char (point-min))
2019 (while (re-search-forward regexp nil t)
2020 (delete-region (match-beginning 0)
2021 (progn (forward-line 1) (point)))
2026 ;;; Platform dependent functions
2029 ;; Emacs 18 implementations
2031 (defun mime-string-encoder-for-emacs18 (method string)
2032 "For given METHOD that is a cons of charset and encoding, encode a STRING."
2033 (let ((charset (car method))
2034 (encoding (cdr method)))
2035 (cond ((stringp encoding)
2036 (mime-encode-string encoding string))
2037 ;; Return string without any encoding.
2042 ;; Emacs 19 implementations
2044 (defun mime-string-encoder-for-emacs19 (method string)
2045 "For given METHOD that is a cons of charset and encoding, encode a STRING."
2046 (let ((charset (car method))
2047 (encoding (cdr method)))
2048 (cond ((stringp encoding)
2049 (mime-encode-string encoding string))
2050 ;; Return string without any encoding.
2055 ;; NEmacs implementations
2057 (defun mime-string-encoder-for-nemacs (method string)
2058 "For given METHOD that is a cons of charset and encoding, encode a STRING.
2059 US-ASCII and ISO-2022-JP are supported on NEmacs."
2060 (let ((charset (car method))
2061 (encoding (cdr method)))
2062 (cond ((stringp encoding)
2063 (mime-encode-string encoding
2064 ;; Convert internal (EUC) to JIS code.
2065 (convert-string-kanji-code string 3 2)
2067 ;; NEmacs can convert into ISO-2022-JP automatically,
2068 ;; but can do it myself as follows:
2069 ;;(t (convert-string-kanji-code string 3 2))
2071 ;; Return string without any encoding.
2076 ;; Mule implementations
2077 ;; Thanks to contributions by wkenji@flab.fujitsu.co.jp (Kenji
2078 ;; WAKAMIYA) and handa@etl.go.jp (Kenichi Handa).
2080 (defun mime-string-encoder-for-mule (method string)
2081 "For given METHOD that is a cons of charset and encoding, encode a
2082 STRING. US-ASCII, ISO-8859-* (except for ISO-8859-6), ISO-2022-JP,
2083 ISO-2022-JP-2 and ISO-2022-INT-1 are supported on Mule. Either of
2084 charset ISO-2022-JP-2 or ISO-2022-INT-1 is used for multilingual
2086 (let* ((charset (car method))
2087 (encoding (cdr method))
2089 (cdr (assoc (and (stringp charset) (upcase charset))
2090 '(("ISO-8859-1" . *ctext*)
2091 ("ISO-8859-2" . *iso-8859-2*)
2092 ("ISO-8859-3" . *iso-8859-3*)
2093 ("ISO-8859-4" . *iso-8859-4*)
2094 ("ISO-8859-5" . *iso-8859-5*)
2095 ;;("ISO-8859-6" . *iso-8859-6*)
2096 ("ISO-8859-7" . *iso-8859-7*)
2097 ("ISO-8859-8" . *iso-8859-8*)
2098 ("ISO-8859-9" . *iso-8859-9*)
2099 ("ISO-2022-JP" . *junet*)
2100 ("ISO-2022-JP-2" . *iso-2022-ss2-7*)
2101 ("ISO-2022-KR" . *korean-mail*)
2102 ("ISO-2022-INT-1" . *iso-2022-int-1*)
2104 ;; In bilingual environment it may be unnecessary to convert the
2105 ;; coding system of the string unless transfer encoding is
2106 ;; required since such conversion may be performed by mule
2108 (if (not (null coding-system))
2109 (setq string (code-convert-string string *internal* coding-system)))
2110 (if (stringp encoding)
2111 (setq string (mime-encode-string encoding string)))
2116 ;; Sun implementations
2118 (defun mime-voice-recorder-for-sun ()
2119 "Record voice in a buffer using Sun audio device, and return the buffer.
2120 If the environment variable AUDIOHOST is defined, its value is used as
2121 a recording host instead of local host."
2122 (let ((buffer (get-buffer-create " *MIME audio*"))
2123 (host (getenv "AUDIOHOST")))
2124 (message "Start the recording on %s. Type C-g to finish the recording..."
2125 (or host (system-name)))
2129 (condition-case errorcode
2130 (let ((selective-display nil) ;Disable ^M to nl translation.
2132 (kanji-flag nil)) ;NEmacs
2133 ;; If AUDIOHOST is defined, use the value as recording host.
2134 (cond ((not (null host))
2135 ;; Disable automatic conversion of coding system if Mule.
2136 (if (featurep 'mule)
2137 (define-program-coding-system nil "rsh" *noconv*))
2147 ;; Disable automatic conversion of coding system if Mule.
2148 (if (featurep 'mule)
2149 (define-program-coding-system nil "cat" *noconv*))
2155 (quit (message "Type C-g to finish recording... done.")
2156 buffer ;Return the buffer
2160 ;;; @ Other useful commands.
2163 ;; Message forwarding commands as content-type "message/rfc822".
2165 (defun mime-editor/insert-message (&optional message)
2167 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2168 (if (and inserter (fboundp inserter))
2170 (mime-editor/insert-tag "message" "rfc822")
2171 (funcall inserter message)
2173 (message "Sorry, I don't have message inserter for your MUA.")
2176 (defun mime-editor/insert-mail (&optional message)
2178 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2179 (if (and inserter (fboundp inserter))
2181 (mime-editor/insert-tag "message" "rfc822")
2182 (funcall inserter message)
2184 (message "Sorry, I don't have mail inserter for your MUA.")
2187 (defun mime-editor/inserted-message-filter ()
2190 (let ((header-start (point))
2191 (case-fold-search t)
2194 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2195 (if (re-search-forward "^$" (mark t))
2196 (narrow-to-region header-start (match-beginning 0))
2198 (goto-char header-start)
2199 (while (and (re-search-forward
2200 mime-editor/yank-ignored-field-regexp nil t)
2201 (setq beg (match-beginning 0))
2202 (setq end (1+ (rfc822/field-end)))
2204 (delete-region beg end)
2209 ;;; @ multipart enclosure
2212 (defun mime-editor/enclose-region (type beg end)
2215 (let ((current (point))
2218 (if (mime-editor/goto-tag)
2219 (or (eq current (match-beginning 0))
2220 (setq exist-prev-tag t)
2223 (narrow-to-region beg end)
2228 (insert (format "--<<%s>>-{\n" type))
2229 (goto-char (point-max))
2230 (insert (format "\n--}-<<%s>>\n" type))
2231 (goto-char (point-max))
2233 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
2235 (insert (mime-make-text-tag) "\n")
2239 (defun mime-editor/enclose-mixed-region (beg end)
2241 (mime-editor/enclose-region "mixed" beg end)
2244 (defun mime-editor/enclose-parallel-region (beg end)
2246 (mime-editor/enclose-region "parallel" beg end)
2249 (defun mime-editor/enclose-digest-region (beg end)
2251 (mime-editor/enclose-region "digest" beg end)
2254 (defun mime-editor/enclose-alternative-region (beg end)
2256 (mime-editor/enclose-region "alternative" beg end)
2259 (defun mime-editor/enclose-signed-region (beg end)
2261 (if mime-editor/signing-type
2262 (mime-editor/enclose-region "signed" beg end)
2263 (message "Please specify signing type.")
2266 (defun mime-editor/enclose-encrypted-region (beg end)
2268 (if mime-editor/signing-type
2269 (mime-editor/enclose-region "encrypted" beg end)
2270 (message "Please specify encrypting type.")
2273 (defun mime-editor/insert-key (&optional arg)
2274 "Insert a pgp public key."
2276 (mime-editor/insert-tag "application" "pgp-keys")
2277 (mime-editor/define-encoding "7bit")
2278 (mc-insert-public-key)
2285 (defun mime-editor/set-split (arg)
2288 (y-or-n-p "Do you want to enable split?")
2290 (setq mime-editor/split-message arg)
2292 (message "This message is enabled to split.")
2293 (message "This message is not enabled to split.")
2296 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2297 "Toggle transfer-level is 7bit or 8bit through.
2299 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2301 (if (numberp transfer-level)
2302 (setq mime-editor/transfer-level transfer-level)
2303 (if (< mime-editor/transfer-level 8)
2304 (setq mime-editor/transfer-level 8)
2305 (setq mime-editor/transfer-level 7)
2307 (setq mime-editor/charset-default-encoding-alist
2308 (mime/make-charset-default-encoding-alist
2309 mime-editor/transfer-level))
2310 (message (format "Current transfer-level is %d bit"
2311 mime-editor/transfer-level))
2312 (setq mime-editor/transfer-level-string
2313 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2314 (force-mode-line-update)
2321 (defun mime-editor/set-sign (arg)
2324 (y-or-n-p "Do you want to sign?")
2327 (if mime-editor/signing-type
2329 (setq mime-editor/pgp-processing 'sign)
2330 (message "This message will be signed.")
2332 (message "Please specify signing type.")
2334 (if (eq mime-editor/pgp-processing 'sign)
2335 (setq mime-editor/pgp-processing nil)
2337 (message "This message will not be signed.")
2340 (defun mime-editor/set-encrypt (arg)
2343 (y-or-n-p "Do you want to encrypt?")
2346 (if mime-editor/encrypting-type
2348 (setq mime-editor/pgp-processing 'encrypt)
2349 (message "This message will be encrypt.")
2351 (message "Please specify encrypting type.")
2353 (if (eq mime-editor/pgp-processing 'encrypt)
2354 (setq mime-editor/pgp-processing nil)
2356 (message "This message will not be encrypt.")
2359 (defvar mime-editor/pgp-processing nil)
2360 (make-variable-buffer-local 'mime-editor/pgp-processing)
2362 (defun mime-editor/pgp-enclose-buffer ()
2363 (let ((beg (save-excursion
2364 (goto-char (point-min))
2365 (if (search-forward (concat "\n" mail-header-separator "\n"))
2371 (cond ((eq mime-editor/pgp-processing 'sign)
2372 (mime-editor/enclose-signed-region beg end)
2374 ((eq mime-editor/pgp-processing 'encrypt)
2375 (mime-editor/enclose-encrypted-region beg end)
2383 (defun mime-editor/insert-partial-header
2384 (fields subject id number total separator)
2386 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2387 (insert (format "Mime-Version: 1.0 (split by tm-edit %s)\n"
2388 mime-editor/version))
2390 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2391 id number total separator))
2394 (defun mime-editor/split-and-send
2395 (&optional cmd lines mime-editor/message-max-length)
2399 (count-lines (point-min) (point-max)))
2401 (or mime-editor/message-max-length
2402 (setq mime-editor/message-max-length
2403 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2404 mime-editor/message-default-max-length))
2406 (let* ((mime-editor/draft-file-name
2407 (or (buffer-file-name)
2409 (expand-file-name "tm-draft" mime/tmp-dir))))
2410 (separator mail-header-separator)
2412 (eval (cdr (assq major-mode mime-editor/window-config-alist))))
2414 (replace-space-with-underline (current-time-string))
2415 "@" (system-name) "\"")))
2416 (run-hooks 'mime-editor/before-split-hook)
2417 (let* ((header (rfc822/get-header-string-except
2418 mime-editor/split-ignored-field-regexp separator))
2419 (subject (mail-fetch-field "subject"))
2420 (total (+ (/ lines mime-editor/message-max-length)
2421 (if (> (mod lines mime-editor/message-max-length) 0)
2423 (the-buf (current-buffer))
2424 (buf (get-buffer "*tmp-send*"))
2429 mime-editor/split-message-sender-alist))
2432 mime-editor/message-default-sender-alist))
2435 (goto-char (point-min))
2436 (if (re-search-forward (concat "^" (regexp-quote separator) "$")
2442 (switch-to-buffer buf)
2444 (switch-to-buffer the-buf)
2446 (setq buf (get-buffer-create "*tmp-send*"))
2448 (switch-to-buffer buf)
2449 (make-local-variable 'mail-header-separator)
2450 (setq mail-header-separator separator)
2451 (switch-to-buffer the-buf)
2452 (goto-char (point-min))
2453 (re-search-forward "^$" nil t)
2454 (let ((mime-editor/partial-number 1))
2455 (setq data (buffer-substring
2458 (goto-line mime-editor/message-max-length)
2461 (delete-region (point-min)(point))
2462 (switch-to-buffer buf)
2463 (mime-editor/insert-partial-header
2464 header subject id mime-editor/partial-number total separator)
2468 (goto-char (point-min))
2469 (search-forward (concat "\n" mail-header-separator "\n"))
2472 (if (re-search-forward "^$" nil t)
2476 (goto-char (point-min))
2477 (while (re-search-forward
2478 mime-editor/split-blind-field-regexp nil t)
2479 (delete-region (match-beginning 0)
2480 (let ((e (rfc822/field-end)))
2481 (if (< e (point-max))
2487 (message (format "Sending %d/%d..."
2488 mime-editor/partial-number total))
2489 (call-interactively command)
2490 (message (format "Sending %d/%d... done"
2491 mime-editor/partial-number total))
2494 (switch-to-buffer the-buf)
2495 (setq mime-editor/partial-number 2)
2496 (while (< mime-editor/partial-number total)
2497 (setq data (buffer-substring
2500 (goto-line mime-editor/message-max-length)
2503 (delete-region (point-min)(point))
2504 (switch-to-buffer buf)
2505 (mime-editor/insert-partial-header
2506 header subject id mime-editor/partial-number total separator)
2509 (message (format "Sending %d/%d..."
2510 mime-editor/partial-number total))
2511 (call-interactively command)
2512 (message (format "Sending %d/%d... done"
2513 mime-editor/partial-number total))
2516 (switch-to-buffer the-buf)
2517 (setq mime-editor/partial-number
2518 (1+ mime-editor/partial-number))
2520 (goto-char (point-min))
2521 (mime-editor/insert-partial-header
2522 header subject id mime-editor/partial-number total separator)
2523 (message (format "Sending %d/%d..."
2524 mime-editor/partial-number total))
2527 (defun mime-editor/maybe-split-and-send (&optional cmd)
2529 (run-hooks 'mime-editor/before-send-hook)
2530 (let ((mime-editor/message-max-length
2531 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2532 mime-editor/message-default-max-length))
2533 (lines (count-lines (point-min) (point-max)))
2535 (if (and (> lines mime-editor/message-max-length)
2536 mime-editor/split-message)
2537 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2541 ;;; @ preview message
2544 (defun mime-editor/preview-message ()
2545 "preview editing MIME message. [tm-edit.el]"
2547 (let* ((str (buffer-string))
2548 (separator mail-header-separator)
2549 (the-buf (current-buffer))
2550 (buf-name (buffer-name))
2551 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2552 (buf (get-buffer temp-buf-name))
2556 (switch-to-buffer buf)
2559 (setq buf (get-buffer-create temp-buf-name))
2560 (switch-to-buffer buf)
2563 (setq major-mode 'mime/temporary-message-mode)
2564 (make-local-variable 'mail-header-separator)
2565 (setq mail-header-separator separator)
2566 (make-local-variable 'mime/editing-buffer)
2567 (setq mime/editing-buffer the-buf)
2569 (run-hooks 'mime-editor/translate-hook)
2570 (mime-editor/translate-buffer)
2571 (goto-char (point-min))
2572 (if (re-search-forward
2573 (concat "^" (regexp-quote separator) "$"))
2579 (defun mime-editor/quitting-method ()
2580 (let ((temp mime::preview/article-buffer)
2582 (mime-viewer/kill-buffer)
2584 (setq buf mime/editing-buffer)
2586 (switch-to-buffer buf)
2589 (set-alist 'mime-viewer/quitting-method-alist
2590 'mime/temporary-message-mode
2591 (function mime-editor/quitting-method)
2597 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2598 ;; Mon, 10 Apr 1995 20:03:07 +0900
2600 (defvar mime-editor/draft-header-separator-alist
2601 '((news-reply-mode . mail-header-separator)
2602 (mh-letter-mode . mail-header-separator)
2605 (defvar mime::article/draft-header-separator nil)
2607 (defun mime-editor/draft-preview ()
2609 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2610 (or (stringp sep) (setq sep (eval sep)))
2611 (make-variable-buffer-local 'mime::article/draft-header-separator)
2612 (goto-char (point-min))
2614 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2615 (setq mime::article/draft-header-separator
2616 (buffer-substring (match-beginning 0) (match-end 0)))
2618 (mime/viewer-mode (current-buffer))
2619 (pop-to-buffer (current-buffer))
2622 (defun mime-viewer::quitting-method/draft-preview ()
2623 (let ((mother mime::preview/mother-buffer))
2625 (switch-to-buffer mother)
2626 (goto-char (point-min))
2630 (regexp-quote mime::article/draft-header-separator)
2634 (insert mime::article/draft-header-separator)
2635 (set-buffer-modified-p (buffer-modified-p))
2637 (mime-viewer/kill-buffer)
2638 (pop-to-buffer mother)
2641 (set-alist 'mime-viewer/quitting-method-alist
2643 (function mime-viewer::quitting-method/draft-preview)
2646 (set-alist 'mime-viewer/quitting-method-alist
2648 (function mime-viewer::quitting-method/draft-preview)
2655 (defun mime-editor::edit-again (code-conversion)
2657 (goto-char (point-min))
2658 (let ((ctl (mime/Content-Type)))
2660 (let ((ctype (car ctl))
2663 (if (string-match "/" ctype)
2665 (setq type (substring ctype 0 (match-beginning 0)))
2666 (setq stype (substring ctype (match-end 0)))
2670 (cond ((string-equal type "multipart")
2671 (let ((boundary (assoc-value "boundary" params)))
2672 (re-search-forward (concat "\n--" boundary) nil t)
2673 (let ((bb (match-beginning 0)) eb tag)
2674 (setq tag (format "\n--<<%s>>-{" stype))
2677 (setq bb (+ bb (length tag)))
2678 (re-search-forward (concat "\n--" boundary "--") nil t)
2679 (setq eb (match-beginning 0))
2680 (replace-match (format "\n--}-<<%s>>" stype))
2682 (narrow-to-region bb eb)
2683 (goto-char (point-min))
2684 (while (re-search-forward
2685 (concat "\n--" boundary "\n") nil t)
2686 (let ((beg (match-beginning 0))
2688 (delete-region beg (match-end 0))
2690 (if (re-search-forward
2691 (concat "\n--" boundary) nil t)
2692 (setq end (match-beginning 0))
2693 (setq end (point-max))
2696 (narrow-to-region beg end)
2697 (mime-editor::edit-again code-conversion)
2698 (goto-char (point-max))
2701 (goto-char (point-min))
2702 (or (= (point-min) 1)
2703 (delete-region (point-min)
2704 (if (re-search-forward "^$" nil t)
2710 (let* ((str (rfc822/get-header-string-except
2711 "^Content-Type" ""))
2714 (mapconcat (function
2716 (if (string-equal (car attr)
2719 (setq charset (cdr attr))
2721 (concat ";" (car attr)
2729 (mime/code-convert-region-to-emacs
2730 (point-min) (point-max) charset)
2731 (code-convert-region
2732 (point-min) (point-max)
2733 mime/default-coding-system *internal*)
2736 (setq pstr (concat pstr "\n" str))
2739 (if (re-search-forward "^$" nil t)
2743 (if (= (point-min) 1)
2749 (mime-create-tag (concat type "/" stype))
2752 (delete-region (point-min) he)
2754 (concat "\n" (mime-create-tag
2755 (concat type "/" stype pstr))))
2759 (code-convert-region (point-min) (point-max)
2760 mime/default-coding-system *internal*)
2764 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2766 (mime-editor::edit-again code-conversion)
2767 (goto-char (point-min))
2769 (narrow-to-region (point-min)
2770 (if (re-search-forward "^$" nil t)
2774 (goto-char (point-min))
2775 (while (re-search-forward
2776 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2777 (delete-region (match-beginning 0) (1+ (rfc822/field-end)))
2780 (and (re-search-forward "^$")
2781 (replace-match mail-header-separator)
2793 (run-hooks 'tm-edit-load-hook)
2795 ;;; tm-edit.el ends here