2 ;;; mime-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 UMEDA Masanobu's mime.el
11 ;;; 1996/05/24 renamed from tm-edit.el
12 ;;; Version: $Revision: 0.38 $
13 ;;; Keywords: mail, news, MIME, multimedia, multilingual
15 ;;; This file is part of SEMI (September, Emacs MIME Interface)
17 ;;; This program is free software; you can redistribute it and/or
18 ;;; modify it under the terms of the GNU General Public License as
19 ;;; published by the Free Software Foundation; either version 2, or
20 ;;; (at your option) any later version.
22 ;;; This program is distributed in the hope that it will be useful,
23 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 ;;; General Public License for more details.
27 ;;; You should have received a copy of the GNU General Public License
28 ;;; along with This program. If not, write to the Free Software
29 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
33 ;; This is an Emacs minor mode for editing Internet multimedia
34 ;; messages formatted in MIME (RFC 1521 and RFC 1522). All messages in
35 ;; this mode are composed in the tagged MIME format, that are
36 ;; described in the following examples. The messages composed in the
37 ;; tagged MIME format are automatically translated into a MIME
38 ;; compliant message when exiting the mode.
40 ;; Mule (a multilingual extension to Emacs 18 and 19) has a capability
41 ;; of handling multilingual text in limited ISO-2022 manner that is
42 ;; based on early experiences in Japanese Internet community and
43 ;; resulted in RFC 1468 (ISO-2022-JP charset for MIME). In order to
44 ;; enable multilingual capability in single text message in MIME,
45 ;; charset of multilingual text written in Mule is declared as either
46 ;; `ISO-2022-JP-2' [RFC 1554] or `ISO-2022-INT-1'. Mule is required
47 ;; for reading the such messages.
49 ;; This MIME composer can work with Mail mode, mh-e letter Mode, and
50 ;; News mode. First of all, you need the following autoload
51 ;; definition to load mime/editor-mode automatically:
53 ;; (autoload 'mime/editor-mode "mime-edit"
54 ;; "Minor mode for editing MIME message." t)
56 ;; In case of Mail mode (includes VM mode), you need the following
59 ;; (add-hook 'mail-mode-hook 'mime/editor-mode)
60 ;; (add-hook 'mail-send-hook 'mime-editor/maybe-translate)
62 ;; In case of MH-E, you need the following hook definition:
64 ;; (add-hook 'mh-letter-mode-hook
68 ;; (make-local-variable 'mail-header-separator)
69 ;; (setq mail-header-separator "--------")
71 ;; (add-hook 'mh-before-send-letter-hook 'mime-editor/maybe-translate)
73 ;; In case of News mode, you need the following hook definition:
75 ;; (add-hook 'news-reply-mode-hook 'mime/editor-mode)
76 ;; (add-hook 'news-inews-hook 'mime-editor/maybe-translate)
78 ;; In case of Emacs 19, it is possible to emphasize the message tags
79 ;; using font-lock mode as follows:
81 ;; (add-hook 'mime/editor-mode-hook
85 ;; (setq font-lock-keywords (list mime-editor/tag-regexp))
88 ;; The message tag looks like:
90 ;; --[[TYPE/SUBTYPE;PARAMETERS][ENCODING]]
92 ;; The tagged MIME message examples:
94 ;; This is a conventional plain text. It should be translated into
98 ;; This is also a plain text. But, it is explicitly specified as is.
100 ;;--[[text/plain; charset=ISO-2022-JP]]
101 ;;
\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.
103 ;;--[[text/richtext]]
104 ;; <center>This is a richtext.</center>
106 ;;--[[image/gif][base64]]^M...image encoded in base64 comes here...
108 ;;--[[audio/basic][base64]]^M...audio encoded in base64 comes here...
113 (require 'mail-utils)
125 (defconst mime-editor/RCS-ID
126 "$Id: mime-edit.el,v 0.38 1996-07-11 15:00:47 morioka Exp $")
128 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
130 (defconst mime-editor/version-name
131 (concat "SEMI mime-edit " mime-editor/version))
137 (defvar mime-prefix "\C-c\C-x"
138 "*Keymap prefix for MIME commands.")
140 (defvar mime-ignore-preceding-spaces nil
141 "*Ignore preceding white spaces if non-nil.")
143 (defvar mime-ignore-trailing-spaces nil
144 "*Ignore trailing white spaces if non-nil.")
146 (defvar mime-ignore-same-text-tag t
147 "*Ignore preceding text content-type tag that is same with new one.
148 If non-nil, the text tag is not inserted unless something different.")
150 (defvar mime-auto-hide-body t
151 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
153 (defvar mime-voice-recorder
154 (function mime-voice-recorder-for-sun)
155 "*Function to record a voice message and return a buffer that contains it.")
157 (defvar mime/editor-mode-hook nil
158 "*Hook called when enter MIME mode.")
160 (defvar mime-editor/translate-hook nil
161 "*Hook called before translating into a MIME compliant message.
162 To insert a signature file automatically, call the function
163 `mime-editor/insert-signature' from this hook.")
165 (defvar mime-editor/exit-hook nil
166 "*Hook called when exit MIME mode.")
168 (defvar mime-content-types
170 ;; Charset parameter need not to be specified, since it is
171 ;; defined automatically while translation.
173 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
176 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
179 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
182 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
185 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
193 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
194 ("directory" "/pub/GNU/elisp/mime")
196 ("mode" "image" "ascii" "local8"))
201 ("mode" "image" "ascii" "local8"))
202 ("tftp" ("site") ("name"))
203 ("afs" ("site") ("name"))
204 ("local-file" ("site") ("name"))
205 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
210 ("octet-stream" ("type" "" "tar" "shar"))
212 ("x-kiss" ("x-cnf")))
225 "*Alist of content-type, subtype, parameters and its values.")
227 (defvar mime-file-types
229 "text" "richtext" nil
237 "application" "postscript" nil
239 "attachment" (("filename" . file))
244 "inline" (("filename" . file))
249 "inline" (("filename" . file))
254 "inline" (("filename" . file))
259 "inline" (("filename" . file))
264 "inline" (("filename" . file))
269 "inline" (("filename" . file))
274 "inline" (("filename" . file))
279 "attachment" (("filename" . file))
284 "attachment" (("filename" . file))
287 "application" "octet-stream" (("type" . "emacs-lisp"))
289 "attachment" (("filename" . file))
292 "application" "octet-stream" (("type" . "common-lisp"))
294 "attachment" (("filename" . file))
297 "application" "octet-stream" (("type" . "tar+gzip"))
299 "attachment" (("filename" . file))
302 "application" "octet-stream" (("type" . "tar+gzip"))
304 "attachment" (("filename" . file))
307 "application" "octet-stream" (("type" . "tar+compress"))
309 "attachment" (("filename" . file))
312 "application" "octet-stream" (("type" . "tar+compress"))
314 "attachment" (("filename" . file))
317 "application" "octet-stream" (("type" . "gzip"))
319 "attachment" (("filename" . file))
322 "application" "octet-stream" (("type" . "compress"))
324 "attachment" (("filename" . file))
327 "application" "octet-stream" (("type" . "lha"))
329 "attachment" (("filename" . file))
332 "application" "zip" nil
334 "attachment" (("filename" . file))
337 "application" "octet-stream" (("type" . "patch"))
339 "attachment" (("filename" . file))
342 "application" "octet-stream" (("type" . "patch"))
344 "attachment" (("filename" . file))
347 "text" "plain" nil nil)
349 "application" "octet-stream" nil
351 "attachment" (("filename" . file))
354 "*Alist of file name, types, parameters, and default encoding.
355 If encoding is nil, it is determined from its contents.")
357 ;;; @@ about charset, encoding and transfer-level
360 (defvar mime-editor/transfer-level 7
361 "*A number of network transfer level. It should be bigger than 7.")
362 (make-variable-buffer-local 'mime-editor/transfer-level)
364 (defvar mime-editor/transfer-level-string
365 (mime/encoding-name mime-editor/transfer-level 'not-omit)
366 "*A string formatted version of mime/defaul-transfer-level")
367 (make-variable-buffer-local 'mime-editor/transfer-level-string)
369 (defun mime-editor/make-charset-default-encoding-alist (transfer-level)
371 (lambda (charset-type)
372 (let ((charset (car charset-type))
373 (type (nth 1 charset-type))
374 (encoding (nth 2 charset-type))
376 (if (<= type transfer-level)
377 (cons charset (mime/encoding-name type))
378 (cons charset encoding)
380 mime-charset-type-list))
382 (defvar mime-editor/charset-default-encoding-alist
383 (mime-editor/make-charset-default-encoding-alist mime-editor/transfer-level))
384 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
386 ;;; @@ about message inserting
389 (defvar mime-editor/yank-ignored-field-list
390 '("Received" "Approved" "Path" "Replied" "Status" "X-VM-.*" "X-UIDL")
391 "Delete these fields from original message when it is inserted
392 as message/rfc822 part.
393 Each elements are regexp of field-name. [mime-edit.el]")
395 (defvar mime-editor/yank-ignored-field-regexp
397 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
400 (defvar mime-editor/message-inserter-alist nil)
401 (defvar mime-editor/mail-inserter-alist nil)
403 ;;; @@ about message splitting
406 (defvar mime-editor/split-message t
407 "*Split large message if it is non-nil. [mime-edit.el]")
409 (defvar mime-editor/message-default-max-length 1000
410 "*Default maximum size of a message. [mime-edit.el]")
412 (defvar mime-editor/message-max-length-alist
413 '((news-reply-mode . 500)))
415 (defconst mime-editor/split-ignored-field-regexp
416 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
418 (defvar mime-editor/split-blind-field-regexp
419 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
421 (defvar mime-editor/split-message-sender-alist
423 . (lambda (&optional arg)
425 (write-region (point-min) (point-max)
426 mime-editor/draft-file-name nil 'no-message)
428 (pop-to-buffer "MH mail delivery")
430 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
432 mh-send-args mime-editor/draft-file-name)
433 (goto-char (point-max)) ; show the interesting part
437 (apply 'mh-exec-cmd-quiet t mh-send-prog
439 (list "-nopush" "-nodraftfolder"
440 "-noverbose" "-nowatch"
441 mh-send-args mime-editor/draft-file-name)))))
445 (defvar mime-editor/news-reply-mode-server-running nil)
451 (defvar mime-editor/signing-type nil
452 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [mime-edit.el]")
454 (defvar mime-editor/encrypting-type nil
455 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [mime-edit.el]")
457 (if (or mime-editor/signing-type mime-editor/encrypting-type)
465 (defconst mime-editor/single-part-tag-regexp
466 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
467 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
469 (defconst mime-editor/quoted-single-part-tag-regexp
470 (concat "- " (substring mime-editor/single-part-tag-regexp 1)))
472 (defconst mime-editor/multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
474 (defconst mime-editor/multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
476 (defconst mime-editor/beginning-tag-regexp
477 (regexp-or mime-editor/single-part-tag-regexp
478 mime-editor/multipart-beginning-regexp))
480 (defconst mime-editor/end-tag-regexp
481 (regexp-or mime-editor/single-part-tag-regexp
482 mime-editor/multipart-end-regexp))
484 (defconst mime-editor/tag-regexp
485 (regexp-or mime-editor/single-part-tag-regexp
486 mime-editor/multipart-beginning-regexp
487 mime-editor/multipart-end-regexp))
489 (defvar mime-tag-format "--[[%s]]"
490 "*Control-string making a MIME tag.")
492 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
493 "*Control-string making a MIME tag with encoding.")
495 ;;; @@ multipart boundary
498 (defvar mime-multipart-boundary "Multipart"
499 "*Boundary of a multipart message.")
502 ;;; @@ buffer local variables
505 (defvar mime/editor-mode-old-local-map nil)
506 (defvar mime/editor-mode-old-selective-display nil)
507 (defvar mime/editing-buffer nil)
513 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
514 "*Specify MIME tspecials.
515 Tspecials means any character that matches with it in header must be quoted.")
517 (defconst mime-editor/mime-version-value
518 (concat "1.0 (" mime-editor/version-name ")")
519 "MIME version number.")
521 (defconst mime-editor/mime-map (make-sparse-keymap)
522 "Keymap for MIME commands.")
524 ;;; @ keymap and menu
527 (defvar mime/editor-mode-flag nil)
528 (make-variable-buffer-local 'mime/editor-mode-flag)
530 (defun mime-editor/define-keymap (keymap)
531 "Add mime-editor commands to KEYMAP."
532 (if (not (keymapp keymap))
534 (define-key keymap "\C-t" 'mime-editor/insert-text)
535 (define-key keymap "\C-i" 'mime-editor/insert-file)
536 (define-key keymap "\C-e" 'mime-editor/insert-external)
537 (define-key keymap "\C-v" 'mime-editor/insert-voice)
538 (define-key keymap "\C-y" 'mime-editor/insert-message)
539 (define-key keymap "\C-m" 'mime-editor/insert-mail)
540 (define-key keymap "\C-w" 'mime-editor/insert-signature)
541 (define-key keymap "\C-s" 'mime-editor/insert-signature)
542 (define-key keymap "\C-k" 'mime-editor/insert-key)
543 (define-key keymap "t" 'mime-editor/insert-tag)
544 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
545 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
546 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
547 (define-key keymap "d" 'mime-editor/enclose-digest-region)
548 (define-key keymap "s" 'mime-editor/enclose-signed-region)
549 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
550 (define-key keymap "q" 'mime-editor/enclose-quote-region)
551 (define-key keymap "\C-p" 'mime-editor/preview-message)
552 (define-key keymap "\C-z" 'mime-editor/exit)
553 (define-key keymap "?" 'mime-editor/help)
556 (mime-editor/define-keymap mime-editor/mime-map)
558 (defun mime-editor/toggle-mode ()
560 (if mime/editor-mode-flag
561 (mime-editor/exit 'nomime)
565 (cond (running-xemacs
566 (defconst mime-editor/minor-mime-map nil "Keymap for MIME commands.")
567 (or mime-editor/minor-mime-map
569 (setq mime-editor/minor-mime-map
570 (make-sparse-keymap 'mime-editor/minor-mime-map))
572 mime-editor/minor-mime-map mime-prefix mime-editor/mime-map)
574 (add-minor-mode 'mime/editor-mode-flag
575 '((" MIME-Edit " mime-editor/transfer-level-string))
576 mime-editor/minor-mime-map
578 'mime-editor/toggle-mode)
581 (set-alist 'minor-mode-alist
582 'mime/editor-mode-flag
583 '((" MIME-Edit " mime-editor/transfer-level-string))))
586 (defconst mime-editor/menu-title "MIME-Edit")
588 (defconst mime-editor/menu-list
589 '((mime-help "Describe MIME editor mode" mime-editor/help)
590 (file "Insert File" mime-editor/insert-file)
591 (external "Insert External" mime-editor/insert-external)
592 (voice "Insert Voice" mime-editor/insert-voice)
593 (message "Insert Message" mime-editor/insert-message)
594 (mail "Insert Mail" mime-editor/insert-mail)
595 (signature "Insert Signature" mime-editor/insert-signature)
596 (text "Insert Text" mime-editor/insert-text)
597 (tag "Insert Tag" mime-editor/insert-tag)
598 (alternative "Enclose as alternative"
599 mime-editor/enclose-alternative-region)
600 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
601 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
602 (digest "Enclose as digest" mime-editor/enclose-digest-region)
603 (signed "Enclose as signed" mime-editor/enclose-signed-region)
604 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
605 (quote "Verbatim region" mime-editor/enclose-quote-region)
606 (key "Insert Public Key" mime-editor/insert-key)
607 (split "About split" mime-editor/set-split)
608 (sign "About sign" mime-editor/set-sign)
609 (encrypt "About encryption" mime-editor/set-encrypt)
610 (preview "Preview Message" mime-editor/preview-message)
611 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
613 "MIME-edit menubar entry.")
615 (defun mime-editor/define-menu-for-emacs19 ()
616 "Define menu for Emacs 19."
617 (define-key (current-local-map) [menu-bar mime-edit]
618 (cons mime-editor/menu-title
619 (make-sparse-keymap mime-editor/menu-title)))
622 (define-key (current-local-map)
623 (vector 'menu-bar 'mime-edit (car item))
624 (cons (nth 1 item)(nth 2 item))
627 (reverse mime-editor/menu-list)
630 ;;; modified by Pekka Marjola <pema@iki.fi>
631 ;;; 1995/9/5 (c.f. [tm-en:69])
632 (defun mime-editor/define-menu-for-xemacs ()
633 "Define menu for Emacs 19."
634 (cond ((featurep 'menubar)
635 (make-local-variable 'current-menubar)
636 (set-buffer-menubar current-menubar)
638 (cons mime-editor/menu-title
641 (vector (nth 1 item)(nth 2 item)
642 mime/editor-mode-flag)
644 mime-editor/menu-list)))
647 ;;; modified by Steven L. Baur <steve@miranova.com>
648 ;;; 1995/12/6 (c.f. [tm-en:209])
649 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
650 (setq mime-editor/popup-menu-for-xemacs
651 (append '("MIME Commands" "---")
652 (mapcar (function (lambda (item)
656 mime-editor/menu-list)))
665 (defun mime/editor-mode ()
666 "MIME minor mode for editing the tagged MIME message.
668 In this mode, basically, the message is composed in the tagged MIME
669 format. The message tag looks like:
671 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
673 The tag specifies the MIME content type, subtype, optional parameters
674 and transfer encoding of the message following the tag. Messages
675 without any tag are treated as `text/plain' by default. Charset and
676 transfer encoding are automatically defined unless explicitly
677 specified. Binary messages such as audio and image are usually hidden
678 using selective-display facility. The messages in the tagged MIME
679 format are automatically translated into a MIME compliant message when
682 Available charsets depend on Emacs version being used. The following
683 lists the available charsets of each emacs.
685 Emacs18: US-ASCII is only available.
686 NEmacs: US-ASCII and ISO-2022-JP are available.
687 Emacs19: US-ASCII and ISO-8859-1 are available.
688 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-6),
689 ISO-2022-JP, ISO-2022-JP-2 and ISO-2022-INT-1 are available.
691 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in Mule is expected to
692 be used to represent multilingual text in intermixed manner. Any
693 languages that has no registered charset are represented as either
694 ISO-2022-JP-2 or ISO-2022-INT-1 in Mule.
696 Following commands are available in addition to major mode commands:
697 \\[mime-editor/insert-text] insert a text message.
698 \\[mime-editor/insert-file] insert a (binary) file.
699 \\[mime-editor/insert-external] insert a reference to external body.
700 \\[mime-editor/insert-voice] insert a voice message.
701 \\[mime-editor/insert-message] insert a mail or news message.
702 \\[mime-editor/insert-mail] insert a mail message.
703 \\[mime-editor/insert-signature] insert a signature file at end.
704 \\[mime-editor/insert-tag] insert a new MIME tag.
705 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
706 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
707 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
708 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
709 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
710 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
711 \\[mime-editor/insert-key] insert PGP public key.
712 \\[mime-editor/preview-message] preview editing MIME message.
713 \\[mime-editor/exit] exit and translate into a MIME compliant message.
714 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
715 \\[mime-editor/help] show this help.
717 Additional commands are available in some major modes:
718 C-c C-c exit, translate and run the original command.
719 C-c C-s exit, translate and run the original command.
721 The following is a message example written in the tagged MIME format.
722 TABs at the beginning of the line are not a part of the message:
724 This is a conventional plain text. It should be translated
727 This is also a plain text. But, it is explicitly specified as
729 --[[text/plain; charset=ISO-2022-JP]]
730 \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
733 <center>This is a richtext.</center>
734 --[[image/gif][base64]]^M...image encoded in base64 here...
735 --[[audio/basic][base64]]^M...audio encoded in base64 here...
737 User customizable variables (not documented all of them):
739 Specifies a key prefix for MIME minor mode commands.
741 mime-ignore-preceding-spaces
742 Preceding white spaces in a message body are ignored if non-nil.
744 mime-ignore-trailing-spaces
745 Trailing white spaces in a message body are ignored if non-nil.
747 mime-auto-fill-header
748 Fill header fields that contain encoded-words if non-nil.
751 Hide a non-textual body message encoded in base64 after insertion
755 Specifies a function to record a voice message and return a buffer
756 that contains it. The function mime-voice-recorder-for-sun is for
759 mime/editor-mode-hook
760 Turning on MIME mode calls the value of mime/editor-mode-hook, if
763 mime-editor/translate-hook
764 The value of mime-editor/translate-hook is called just before translating
765 the tagged MIME format into a MIME compliant message if it is
766 non-nil. If the hook call the function mime-editor/insert-signature,
767 the signature file will be inserted automatically.
769 mime-editor/exit-hook
770 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
773 (if mime/editor-mode-flag
774 (error "You are already editing a MIME message.")
775 (setq mime/editor-mode-flag t)
776 ;; Remember old key bindings.
779 (make-local-variable 'mime/editor-mode-old-local-map)
780 (setq mime/editor-mode-old-local-map (current-local-map))
781 ;; Add MIME commands to current local map.
782 (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 (cond (running-xemacs
796 (mime-editor/define-menu-for-xemacs))
797 ((>= emacs-major-version 19)
798 (mime-editor/define-menu-for-emacs19)
802 ;; Remember old selective-display.
803 (make-local-variable 'mime/editor-mode-old-selective-display)
804 (setq mime/editor-mode-old-selective-display selective-display)
805 (setq selective-display t)
806 ;; I don't care about saving these.
807 (setq paragraph-start
808 (regexp-or mime-editor/single-part-tag-regexp
810 (setq paragraph-separate
811 (regexp-or mime-editor/single-part-tag-regexp
813 (run-hooks 'mime/editor-mode-hook)
815 (substitute-command-keys
816 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
820 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
821 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
823 (defun mime-editor/exit (&optional nomime no-error)
824 "Translate the tagged MIME message into a MIME compliant message.
825 With no argument encode a message in the buffer into MIME, otherwise
826 just return to previous mode."
828 (if (not mime/editor-mode-flag)
830 (error "You aren't editing a MIME message.")
834 (run-hooks 'mime-editor/translate-hook)
835 (mime-editor/translate-buffer)))
836 ;; Restore previous state.
837 (setq mime/editor-mode-flag nil)
838 (cond (running-xemacs
839 (delete-menu-item (list mime-editor/menu-title)))
841 (use-local-map mime/editor-mode-old-local-map)))
843 (setq selective-display mime/editor-mode-old-selective-display)
844 (set-buffer-modified-p (buffer-modified-p))
845 (run-hooks 'mime-editor/exit-hook)
846 (message "Exit MIME editor mode.")
849 (defun mime-editor/maybe-translate ()
851 (mime-editor/exit nil t)
852 (call-interactively 'mime-editor/maybe-split-and-send)
855 (defun mime-editor/help ()
856 "Show help message about MIME mode."
858 (with-output-to-temp-buffer "*Help*"
859 (princ "MIME editor mode:\n")
860 (princ (documentation 'mime/editor-mode))
861 (print-help-return-message)))
863 (defun mime-editor/insert-text ()
864 "Insert a text message.
865 Charset is automatically obtained from the `mime/lc-charset-alist'."
867 (if (and (mime-editor/insert-tag "text" nil nil)
868 (looking-at mime-editor/single-part-tag-regexp))
870 ;; Make a space between the following message.
875 (defun mime-editor/insert-file (file)
876 "Insert a message from a file."
877 (interactive "fInsert file as MIME message: ")
878 (let* ((guess (mime-find-file-type file))
879 (pritype (nth 0 guess))
880 (subtype (nth 1 guess))
881 (parameters (nth 2 guess))
882 (default (nth 3 guess)) ;Guess encoding from its file name.
883 (disposition-type (nth 4 guess))
884 (disposition-params (nth 5 guess))
886 (if (not (interactive-p))
889 (concat "What transfer encoding"
892 (if (string-equal default "")
898 mime-encoding-method-alist nil t nil))))
899 (if (string-equal encoding "")
900 (setq encoding default))
901 (if (or (consp parameters) (stringp disposition-type))
902 (let ((rest parameters) cell attribute value)
905 (setq cell (car rest))
906 (setq attribute (car cell))
907 (setq value (cdr cell))
909 (setq value (rfc822/wrap-as-quoted-string
910 (file-name-nondirectory file)))
912 (setq parameters (concat parameters "; " attribute "=" value))
913 (setq rest (cdr rest))
918 (concat parameters "\n"
919 "Content-Disposition: " disposition-type))
920 (setq rest disposition-params)
922 (setq cell (car rest))
923 (setq attribute (car cell))
924 (setq value (cdr cell))
926 (setq value (rfc822/wrap-as-quoted-string
927 (file-name-nondirectory file)))
930 (concat parameters "; " attribute "=" value))
931 (setq rest (cdr rest))
935 (mime-editor/insert-tag pritype subtype parameters)
936 (mime-editor/insert-binary-file file encoding)
939 (defun mime-editor/insert-external ()
940 "Insert a reference to external body."
942 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
944 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
946 (let* ((pritype (mime-prompt-for-type))
947 (subtype (mime-prompt-for-subtype pritype))
948 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
951 (insert "Content-Type: "
952 pritype "/" subtype (or parameters "") "\n")))
953 (if (and (not (eobp))
954 (not (looking-at mime-editor/single-part-tag-regexp)))
955 (insert (mime-make-text-tag) "\n")))
957 (defun mime-editor/insert-voice ()
958 "Insert a voice message."
960 (mime-editor/insert-tag "audio" "basic" nil)
961 (let ((buffer (funcall mime-voice-recorder)))
963 (mime-editor/insert-binary-buffer buffer "base64")
967 (defun mime-editor/insert-signature (&optional arg)
968 "Insert a signature file."
970 (let ((signature-insert-hook
973 (apply (function mime-editor/insert-tag)
974 (mime-find-file-type signature-file-name))
977 (insert-signature arg)
981 ;; Insert a new tag around a point.
983 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
984 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
985 If nothing is inserted, return nil."
993 (mime-prompt-for-type)))
996 (mime-prompt-for-subtype pritype)))
999 (mime-prompt-for-parameters pritype subtype delimiter)))
1000 ;; Make a new MIME tag.
1001 (setq newtag (mime-make-tag pritype subtype parameters))
1002 ;; Find an current MIME tag.
1005 (if (mime-editor/goto-tag)
1006 (buffer-substring (match-beginning 0) (match-end 0))
1007 ;; Assume content type is 'text/plan'.
1008 (mime-make-tag "text" "plain")
1010 ;; We are only interested in TEXT.
1012 (not (mime-test-content-type
1013 (mime-editor/get-contype oldtag) "text")))
1016 (if (or (not oldtag) ;Not text
1017 (or mime-ignore-same-text-tag
1018 (not (string-equal oldtag newtag))))
1020 ;; Mark the beginning of the tag for convenience.
1021 (push-mark (point) 'nomsg)
1022 (insert newtag "\n")
1023 (list pritype subtype parameters) ;New tag is created.
1025 ;; Restore previous point.
1027 nil ;Nothing is created.
1031 ;; Insert the binary content after MIME tag.
1032 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1034 (defun mime-editor/insert-binary-file (file &optional encoding)
1035 "Insert binary FILE at point.
1036 Optional argument ENCODING specifies an encoding method such as base64."
1037 (let ((tmpbuf (get-buffer-create " *MIME insert*")))
1041 (let ((mc-flag nil) ;Mule
1042 (file-coding-system-for-read
1043 (if (featurep 'mule) *noconv*))
1044 (kanji-flag nil) ;NEmacs
1045 (emx-binary-mode t) ;Stop CRLF to LF conversion in OS/2
1047 (let (jka-compr-compression-info-list
1048 jam-zcat-filename-list)
1049 (insert-file-contents file))))
1051 (if (and (stringp encoding)
1052 (string-equal (downcase encoding) "x-uue"))
1055 (let ((uuencode-external-encoder
1056 (cons (car uuencode-external-encoder)
1057 (list (file-name-nondirectory file))
1059 (mime-editor/insert-binary-buffer tmpbuf encoding)
1061 (mime-editor/insert-binary-buffer tmpbuf encoding))
1062 (kill-buffer tmpbuf))))
1064 ;; Insert the binary content after MIME tag.
1065 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1067 (defun mime-editor/insert-binary-buffer (buffer &optional encoding)
1068 "Insert binary BUFFER at point.
1069 Optional argument ENCODING specifies an encoding method such as base64."
1070 (let* ((tagend (1- (point))) ;End of the tag
1071 (hide-p (and mime-auto-hide-body
1073 (let ((en (downcase encoding)))
1074 (or (string-equal en "base64")
1075 (string-equal en "x-uue")
1079 (narrow-to-region (1- (point)) (point))
1080 (let ((start (point))
1081 (emx-binary-mode t)) ;Stop LF to CRLF conversion in OS/2
1082 (insert-buffer-substring buffer)
1083 ;; Encode binary message if necessary.
1085 (mime-encode-region start (point-max) encoding)
1089 (invisible-region (point-min) (point-max))
1090 (goto-char (point-max))
1093 ;; Define encoding even if it is 7bit.
1094 (if (stringp encoding)
1096 (goto-char tagend) ;Make sure which line the tag is on.
1097 (mime-editor/define-encoding encoding)))
1101 ;; Commands work on a current message flagment.
1103 (defun mime-editor/goto-tag ()
1104 "Search for the beginning of the tagged MIME message."
1105 (let ((current (point)) multipart)
1106 (if (looking-at mime-editor/tag-regexp)
1108 ;; At first, go to the end.
1109 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1110 (goto-char (1- (match-beginning 0))) ;For multiline tag
1113 (goto-char (point-max))
1115 ;; Then search for the beginning.
1116 (re-search-backward mime-editor/end-tag-regexp nil t)
1117 (or (looking-at mime-editor/beginning-tag-regexp)
1118 ;; Restore previous point.
1125 (defun mime-editor/content-beginning ()
1126 "Return the point of the beginning of content."
1128 (let ((beg (save-excursion
1129 (beginning-of-line) (point))))
1130 (if (mime-editor/goto-tag)
1131 (let ((top (point)))
1132 (goto-char (match-end 0))
1133 (if (and (= beg top)
1134 (= (following-char) ?\^M))
1138 ;; Default text/plain tag.
1139 (goto-char (point-min))
1141 (concat "\n" (regexp-quote mail-header-separator)
1142 (if mime-ignore-preceding-spaces
1143 "[ \t\n]*\n" "\n")) nil 'move)
1147 (defun mime-editor/content-end ()
1148 "Return the point of the end of content."
1150 (let ((beg (point)))
1151 (if (mime-editor/goto-tag)
1152 (let ((top (point)))
1153 (goto-char (match-end 0))
1154 (if (invisible-p (point))
1155 (next-visible-point (point))
1156 ;; Move to the end of this text.
1157 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1158 ;; Don't forget a multiline tag.
1159 (goto-char (match-beginning 0))
1163 ;; Assume the message begins with text/plain.
1164 (goto-char (mime-editor/content-beginning))
1165 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1166 ;; Don't forget a multiline tag.
1167 (goto-char (match-beginning 0)))
1171 (defun mime-editor/define-charset (charset)
1172 "Set charset of current tag to CHARSET."
1174 (if (mime-editor/goto-tag)
1175 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1176 (delete-region (match-beginning 0) (match-end 0))
1179 (mime-editor/set-parameter
1180 (mime-editor/get-contype tag)
1181 "charset" (upcase (symbol-name charset)))
1182 (mime-editor/get-encoding tag)))
1185 (defun mime-editor/define-encoding (encoding)
1186 "Set encoding of current tag to ENCODING."
1188 (if (mime-editor/goto-tag)
1189 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1190 (delete-region (match-beginning 0) (match-end 0))
1191 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1194 (defun mime-editor/choose-charset ()
1195 "Choose charset of a text following current point."
1196 (detect-mime-charset-region (point) (mime-editor/content-end))
1199 (defun mime-make-text-tag (&optional subtype)
1200 "Make a tag for a text after current point.
1201 Subtype of text type can be specified by an optional argument SUBTYPE.
1202 Otherwise, it is obtained from mime-content-types."
1203 (let* ((pritype "text")
1204 (subtype (or subtype
1205 (car (car (cdr (assoc pritype mime-content-types)))))))
1206 ;; Charset should be defined later.
1207 (mime-make-tag pritype subtype)))
1210 ;; Tag handling functions
1212 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1213 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1214 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1218 (defun mime-create-tag (contype &optional encoding)
1219 "Make a tag with CONTENT-TYPE and optional ENCODING."
1220 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1223 (defun mime-editor/get-contype (tag)
1224 "Return Content-Type (including parameters) of TAG."
1226 (or (string-match mime-editor/single-part-tag-regexp tag)
1227 (string-match mime-editor/multipart-beginning-regexp tag)
1228 (string-match mime-editor/multipart-end-regexp tag)
1230 (substring tag (match-beginning 1) (match-end 1))
1233 (defun mime-editor/get-encoding (tag)
1234 "Return encoding of TAG."
1236 (string-match mime-editor/single-part-tag-regexp tag)
1238 (not (= (match-beginning 3) (match-end 3)))
1239 (substring tag (match-beginning 3) (match-end 3))))
1241 (defun mime-get-parameter (contype parameter)
1242 "For given CONTYPE return value for PARAMETER.
1243 Nil if no such parameter."
1247 (regexp-quote parameter)
1248 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1250 (substring contype (match-beginning 1) (match-end 1))
1251 nil ;No such parameter
1254 (defun mime-editor/set-parameter (contype parameter value)
1255 "For given CONTYPE set PARAMETER to VALUE."
1256 (let (ctype opt-fields)
1257 (if (string-match "\n[^ \t\n\r]+:" contype)
1258 (setq ctype (substring contype 0 (match-beginning 0))
1259 opt-fields (substring contype (match-beginning 0)))
1260 (setq ctype contype)
1265 (regexp-quote parameter)
1266 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1269 (concat (substring ctype 0 (match-beginning 1))
1271 (substring contype (match-end 1))
1273 (concat ctype "; " parameter "=" value opt-fields)
1276 (defun mime-strip-parameters (contype)
1277 "Return primary content-type and subtype without parameters for CONTYPE."
1278 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1279 (substring contype (match-beginning 1) (match-end 1)) nil))
1281 (defun mime-test-content-type (contype type &optional subtype)
1282 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1283 (and (stringp contype)
1286 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1287 (downcase contype))))
1292 (defun mime-find-file-type (file)
1293 "Guess Content-Type, subtype, and parameters from FILE."
1295 (guesses mime-file-types))
1296 (while (and (not guess) guesses)
1297 (if (string-match (car (car guesses)) file)
1298 (setq guess (cdr (car guesses))))
1299 (setq guesses (cdr guesses)))
1303 (defun mime-prompt-for-type ()
1304 "Ask for Content-type."
1306 ;; Repeat until primary content type is specified.
1307 (while (string-equal type "")
1309 (completing-read "What content type: "
1312 'require-match ;Type must be specified.
1315 (if (string-equal type "")
1317 (message "Content type is required.")
1325 (defun mime-prompt-for-subtype (pritype)
1326 "Ask for Content-type subtype of Content-Type PRITYPE."
1327 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1332 "What content subtype: (default " default ") ")
1333 "What content subtype: ")
1334 (cdr (assoc pritype mime-content-types))
1336 'require-match ;Subtype must be specified.
1339 (if (string-equal answer "") default answer)))
1341 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1342 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1343 Optional DELIMITER specifies parameter delimiter (';' by default)."
1344 (let* ((delimiter (or delimiter "; "))
1349 (mime-prompt-for-parameters-1
1351 (cdr (assoc pritype mime-content-types))))))
1354 (if (and (stringp parameters)
1355 (not (string-equal parameters "")))
1356 (concat delimiter parameters)
1357 "" ;"" if no parameters
1360 (defun mime-prompt-for-parameters-1 (optlist)
1361 (apply (function append)
1362 (mapcar (function mime-prompt-for-parameter) optlist)))
1364 (defun mime-prompt-for-parameter (parameter)
1366 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1367 (let* ((prompt (car parameter))
1368 (choices (mapcar (function
1370 (if (consp e) e (list e))))
1372 (default (car (car choices)))
1378 (concat "What " prompt
1380 (if (string-equal default "") "\"\"" default)
1382 choices nil nil ""))
1383 ;; If nothing is selected, use default.
1384 (if (string-equal answer "")
1385 (setq answer default)))
1387 (read-string (concat "What " prompt ": "))))
1388 (cons (if (and answer
1389 (not (string-equal answer "")))
1391 ;; Note: control characters ignored!
1392 (if (string-match mime-tspecials-regexp answer)
1393 (concat "\"" answer "\"") answer)))
1394 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1397 (defun mime-flag-region (from to flag)
1398 "Hides or shows lines from FROM to TO, according to FLAG.
1399 If FLAG is `\\n' (newline character) then text is shown,
1400 while if FLAG is `\\^M' (control-M) the text is hidden."
1401 (let ((buffer-read-only nil) ;Okay even if write protected.
1402 (modp (buffer-modified-p)))
1404 (subst-char-in-region from to
1405 (if (= flag ?\n) ?\^M ?\n)
1407 (set-buffer-modified-p modp))))
1410 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1413 (defvar mime-editor/translate-buffer-hook
1414 '(mime-editor/pgp-enclose-buffer
1415 mime/encode-message-header
1416 mime-editor/translate-body))
1418 (defun mime-editor/translate-buffer ()
1419 "Encode the tagged MIME message in current buffer in MIME compliant message."
1421 (if (catch 'mime-editor/error
1423 (run-hooks 'mime-editor/translate-buffer-hook)
1427 (error "Translation error!")
1430 (defun mime-editor/find-inmost ()
1431 (goto-char (point-min))
1432 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1433 (let ((bb (match-beginning 0))
1435 (type (buffer-substring (match-beginning 1)(match-end 1)))
1437 (setq end-exp (format "--}-<<%s>>\n" type))
1439 (if (re-search-forward end-exp nil t)
1441 (setq eb (match-beginning 0))
1442 (setq ee (match-end 0))
1444 (setq eb (point-max))
1445 (setq ee (point-max))
1447 (narrow-to-region be eb)
1449 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1451 (narrow-to-region (match-beginning 0)(point-max))
1452 (mime-editor/find-inmost)
1455 (list type bb be eb)
1458 (defun mime-editor/process-multipart-1 (boundary)
1459 (let ((ret (mime-editor/find-inmost)))
1461 (let ((type (car ret))
1462 (bb (nth 1 ret))(be (nth 2 ret))
1465 (narrow-to-region bb eb)
1466 (delete-region bb be)
1467 (setq bb (point-min))
1468 (setq eb (point-max))
1471 (if (looking-at mime-editor/multipart-end-regexp)
1472 (let ((beg (match-beginning 0))
1475 (delete-region beg end)
1476 (or (looking-at mime-editor/beginning-tag-regexp)
1478 (insert (concat (mime-make-text-tag) "\n"))
1480 (cond ((string-equal type "quote")
1481 (mime-editor/enquote-region bb eb)
1483 ((string-equal type "signed")
1484 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1485 (mime-editor/sign-pgp-elkins bb eb boundary)
1487 ((eq mime-editor/signing-type 'pgp-kazu)
1488 (mime-editor/sign-pgp-kazu bb eb boundary)
1491 ((string-equal type "encrypted")
1492 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1493 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1495 ((eq mime-editor/encrypting-type 'pgp-kazu)
1496 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1500 (nth 2 (mime-editor/translate-region bb eb
1504 (format "--[[multipart/%s;
1505 boundary=\"%s\"][7bit]]\n"
1510 (defun mime-editor/enquote-region (beg end)
1513 (narrow-to-region beg end)
1515 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1516 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1517 (replace-match (concat "- " (substring tag 1)))
1520 (defun mime-editor/dequote-region (beg end)
1523 (narrow-to-region beg end)
1525 (while (re-search-forward
1526 mime-editor/quoted-single-part-tag-regexp nil t)
1527 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1528 (replace-match (concat "-" (substring tag 2)))
1531 (autoload 'mc-pgp-lookup-key "mc-pgp")
1532 (autoload 'mc-pgp-sign-region "mc-pgp")
1533 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1535 (defun tm:mc-pgp-generic-parser (result)
1536 (let ((ret (mc-pgp-generic-parser result)))
1538 (vector (car ret)(cdr ret))
1541 (defun tm:mc-process-region
1542 (beg end passwd program args parser &optional buffer boundary)
1543 (let ((obuf (current-buffer))
1544 (process-connection-type nil)
1545 mybuf result rgn proc)
1548 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1552 (buffer-disable-undo mybuf)
1554 (apply 'start-process "*PGP*" mybuf program args))
1557 (process-send-string proc (concat passwd "\n"))
1558 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1559 (process-send-region proc beg end)
1560 (process-send-eof proc)
1561 (while (eq 'run (process-status proc))
1562 (accept-process-output proc 5))
1563 (setq result (process-exit-status proc))
1564 ;; Hack to force a status_notify() in Emacs 19.29
1565 (delete-process proc)
1567 (goto-char (point-max))
1568 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1569 (delete-region (match-beginning 0) (match-end 0)))
1570 (goto-char (point-min))
1572 (while (search-forward "\r\n" nil t)
1573 (replace-match "\n"))
1574 ;; Hurm. FIXME; must get better result codes.
1575 (if (stringp result)
1576 (error "%s exited abnormally: '%s'" program result)
1577 (setq rgn (funcall parser result))
1578 ;; If the parser found something, migrate it
1584 (narrow-to-region beg end)
1586 (insert (format "--%s\n" boundary))
1587 (goto-char (point-max))
1588 (insert (format "\n--%s
1589 Content-Type: application/pgp-signature
1590 Content-Transfer-Encoding: 7bit
1593 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1594 (goto-char (point-max))
1595 (insert (format "\n--%s--\n" boundary))
1597 (delete-region beg end)
1599 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1602 (delete-region (car rgn) (cdr rgn)))))
1603 ;; Return nil on failure and exit code on success
1605 ;; Cleanup even on nonlocal exit
1606 (if (and proc (eq 'run (process-status proc)))
1607 (interrupt-process proc))
1609 (or buffer (null mybuf) (kill-buffer mybuf)))))
1611 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1612 (if (not (boundp 'mc-pgp-user-id))
1615 (let ((process-environment process-environment)
1616 (buffer (get-buffer-create mc-buffer-name))
1618 (parser (function mc-pgp-generic-parser))
1619 (pgp-path mc-pgp-path)
1621 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1625 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1626 (setenv "PGPPASSFD" "0")
1632 (list "+verbose=1" "+language=en"
1633 (format "+clearsig=%s" (if unclear "off" "on"))
1634 "+batchmode" "-u" (cdr key))))
1636 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1638 (message "Signing as %s ..." (car key))
1639 (if (tm:mc-process-region
1640 start end passwd pgp-path args parser buffer boundary)
1644 (goto-char (point-min))
1647 --[[multipart/signed; protocol=\"application/pgp-signature\";
1648 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1650 (message "Signing as %s ... Done." (car key))
1654 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1657 (narrow-to-region beg end)
1659 (mime-editor/translate-region beg end boundary))
1661 (encoding (nth 1 ret))
1663 (pgp-boundary (concat "pgp-sign-" boundary))
1666 (insert (format "Content-Type: %s\n" ctype))
1668 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1671 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1672 nil nil pgp-boundary)
1673 (throw 'mime-editor/error 'pgp-error)
1677 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1680 (let ((from (rfc822/get-field-body "From"))
1681 (to (rfc822/get-field-body "To"))
1682 (cc (rfc822/get-field-body "cc"))
1684 (narrow-to-region beg end)
1686 (mime-editor/translate-region beg end boundary))
1688 (encoding (nth 1 ret))
1690 (pgp-boundary (concat "pgp-" boundary))
1693 (if (and (stringp from)
1694 (not (string-equal from "")))
1695 (insert (format "From: %s\n" from))
1697 (if (and (stringp to)
1698 (not (string-equal to "")))
1700 (insert (format "To: %s\n" to))
1701 (setq recipients to)
1703 (if (and (stringp cc)
1704 (not (string-equal cc "")))
1706 (insert (format "cc: %s\n" cc))
1708 (setq recipients (concat recipients "," cc))
1709 (setq recipients cc)
1711 (insert (format "Content-Type: %s\n" ctype))
1713 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1717 (let ((mc-pgp-always-sign 'never))
1718 (mc-pgp-encrypt-region
1719 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1720 (point-min) (point-max) from nil)
1722 (throw 'mime-editor/error 'pgp-error)
1725 (insert (format "--[[multipart/encrypted;
1727 protocol=\"application/pgp-encrypted\"][7bit]]
1729 Content-Type: application/pgp-encrypted
1732 Content-Type: application/octet-stream
1733 Content-Transfer-Encoding: 7bit
1735 " pgp-boundary pgp-boundary pgp-boundary))
1736 (goto-char (point-max))
1737 (insert (format "\n--%s--\n" pgp-boundary))
1740 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1743 (narrow-to-region beg end)
1745 (mime-editor/translate-region beg end boundary))
1747 (encoding (nth 1 ret))
1751 (insert (format "Content-Type: %s\n" ctype))
1753 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1756 (or (as-binary-process (mc-pgp-sign-region beg (point-max)))
1757 (throw 'mime-editor/error 'pgp-error)
1761 "--[[application/pgp; format=mime][7bit]]\n")
1765 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1767 (let ((from (rfc822/get-field-body "From"))
1768 (to (rfc822/get-field-body "To"))
1769 (cc (rfc822/get-field-body "cc"))
1772 (narrow-to-region beg end)
1774 (mime-editor/translate-region beg end boundary))
1776 (encoding (nth 1 ret))
1780 (if (and (stringp from)
1781 (not (string-equal from "")))
1782 (insert (format "From: %s\n" from))
1784 (if (and (stringp to)
1785 (not (string-equal to "")))
1787 (insert (format "To: %s\n" to))
1788 (setq recipients to)
1790 (if (and (stringp cc)
1791 (not (string-equal cc "")))
1793 (insert (format "cc: %s\n" cc))
1795 (setq recipients (concat recipients "," cc))
1796 (setq recipients cc)
1798 (insert (format "Content-Type: %s\n" ctype))
1800 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1803 (or (as-binary-process
1804 (mc-pgp-encrypt-region
1805 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1808 (throw 'mime-editor/error 'pgp-error)
1812 "--[[application/pgp; format=mime][7bit]]\n")
1816 (defun mime-editor/translate-body ()
1817 "Encode the tagged MIME body in current buffer in MIME compliant message."
1821 (concat mime-multipart-boundary "_"
1822 (replace-space-with-underline (current-time-string))
1826 (while (mime-editor/process-multipart-1
1827 (format "%s-%d" boundary i))
1831 ;; We are interested in message body.
1834 (goto-char (point-min))
1836 (concat "\n" (regexp-quote mail-header-separator)
1837 (if mime-ignore-preceding-spaces
1838 "[ \t\n]*\n" "\n")) nil 'move)
1842 (goto-char (point-max))
1843 (and mime-ignore-trailing-spaces
1844 (re-search-backward "[^ \t\n]\n" beg t)
1847 (setq ret (mime-editor/translate-region
1849 (format "%s-%d" boundary i)))
1851 (mime-editor/dequote-region (point-min)(point-max))
1852 (let ((contype (car ret)) ;Content-Type
1853 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1855 ;; Make primary MIME headers.
1856 (or (mail-position-on-field "Mime-Version")
1857 (insert mime-editor/mime-version-value))
1858 ;; Remove old Content-Type and other fields.
1860 (goto-char (point-min))
1861 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1862 (narrow-to-region (point-min) (point))
1863 (goto-char (point-min))
1864 (mime-delete-field "Content-Type")
1865 (mime-delete-field "Content-Transfer-Encoding"))
1866 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1867 (mail-position-on-field "Content-Type")
1871 (mail-position-on-field "Content-Transfer-Encoding")
1875 (defun mime-editor/translate-single-part-tag (&optional prefix)
1876 (if (re-search-forward mime-editor/single-part-tag-regexp nil t)
1877 (let* ((beg (match-beginning 0))
1879 (tag (buffer-substring beg end))
1881 (delete-region beg end)
1882 (setq contype (mime-editor/get-contype tag))
1883 (setq encoding (mime-editor/get-encoding tag))
1884 (insert (concat prefix "--" boundary "\n"))
1886 (narrow-to-region (point)(point))
1887 (insert "Content-Type: " contype "\n")
1889 (insert "Content-Transfer-Encoding: " encoding "\n"))
1890 (mime/encode-message-header)
1894 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1897 (concat mime-multipart-boundary "_"
1898 (replace-space-with-underline (current-time-string))))
1902 (narrow-to-region beg end)
1903 (let ((tag nil) ;MIME tag
1904 (contype nil) ;Content-Type
1905 (encoding nil) ;Content-Transfer-Encoding
1906 (nparts 0)) ;Number of body parts
1907 ;; Normalize the body part by inserting appropriate message
1908 ;; tags for every message contents.
1909 (mime-editor/normalize-body)
1910 ;; Counting the number of Content-Type.
1911 (goto-char (point-min))
1912 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1913 (setq nparts (1+ nparts)))
1914 ;; Begin translation.
1916 ((and (<= nparts 1)(not multipart))
1917 ;; It's a singular message.
1918 (goto-char (point-min))
1919 (while (re-search-forward
1920 mime-editor/single-part-tag-regexp nil t)
1922 (buffer-substring (match-beginning 0) (match-end 0)))
1923 (delete-region (match-beginning 0) (1+ (match-end 0)))
1924 (setq contype (mime-editor/get-contype tag))
1925 (setq encoding (mime-editor/get-encoding tag))
1928 ;; It's a multipart message.
1929 (goto-char (point-min))
1930 (and (mime-editor/translate-single-part-tag)
1931 (while (mime-editor/translate-single-part-tag "\n"))
1933 ;; Define Content-Type as "multipart/mixed".
1935 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1936 ;; Content-Transfer-Encoding must be "7bit".
1937 ;; The following encoding can be `nil', but is
1938 ;; specified as is since there is no way that a user
1940 (setq encoding "7bit")
1941 ;; Insert the trailer.
1942 (goto-char (point-max))
1943 (insert "\n--" boundary "--\n")
1945 (list contype encoding boundary nparts)
1948 (defun mime-editor/normalize-body ()
1949 "Normalize the body part by inserting appropriate message tags."
1950 ;; Insert the first MIME tags if necessary.
1951 (goto-char (point-min))
1952 (if (not (looking-at mime-editor/single-part-tag-regexp))
1953 (insert (mime-make-text-tag) "\n"))
1954 ;; Check each tag, and add new tag or correct it if necessary.
1955 (goto-char (point-min))
1956 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1957 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1958 (contype (mime-editor/get-contype tag))
1959 (charset (mime-get-parameter contype "charset"))
1960 (encoding (mime-editor/get-encoding tag)))
1961 ;; Remove extra whitespaces after the tag.
1962 (if (looking-at "[ \t]+$")
1963 (delete-region (match-beginning 0) (match-end 0)))
1965 (end (mime-editor/content-end))
1968 (or (looking-at mime-editor/beginning-tag-regexp)
1970 (insert (mime-make-text-tag) "\n")
1972 (visible-region beg end)
1976 ((mime-test-content-type contype "message")
1977 ;; Content-type "message" should be sent as is.
1980 ((mime-test-content-type contype "text")
1981 ;; Define charset for text if necessary.
1982 (setq charset (if charset
1983 (intern (downcase charset))
1984 (mime-editor/choose-charset)))
1985 (mime-editor/define-charset charset)
1986 (cond ((string-equal contype "text/x-rot13-47")
1990 (goto-char (mime-editor/content-end))
1993 ((string-equal contype "text/enriched")
1998 (end (mime-editor/content-end))
2000 (enriched-encode beg end)
2002 (if (search-forward "\n\n")
2003 (delete-region beg (match-end 0))
2006 ;; Point is now on current tag.
2007 ;; Define encoding and encode text if necessary.
2008 (or encoding ;Encoding is not specified.
2012 mime-editor/charset-default-encoding-alist)
2014 (beg (mime-editor/content-beginning))
2016 (encode-mime-charset-region beg (mime-editor/content-end)
2018 (mime-encode-region beg (mime-editor/content-end) encoding)
2019 (mime-editor/define-encoding encoding)
2021 (goto-char (mime-editor/content-end))
2023 ((null encoding) ;Encoding is not specified.
2024 ;; Application, image, audio, video, and any other
2025 ;; unknown content-type without encoding should be
2027 (let* ((encoding "base64") ;Encode in BASE64 by default.
2028 (beg (mime-editor/content-beginning))
2029 (end (mime-editor/content-end))
2030 (body (buffer-substring beg end))
2032 (mime-encode-region beg end encoding)
2033 (mime-editor/define-encoding encoding))
2038 (defun mime-delete-field (field)
2039 "Delete header FIELD."
2040 (let ((regexp (format "^%s:[ \t]*" field)))
2041 (goto-char (point-min))
2042 (while (re-search-forward regexp nil t)
2043 (delete-region (match-beginning 0)
2044 (progn (forward-line 1) (point)))
2049 ;;; Platform dependent functions
2052 ;; Sun implementations
2054 (defun mime-voice-recorder-for-sun ()
2055 "Record voice in a buffer using Sun audio device, and return the buffer.
2056 If the environment variable AUDIOHOST is defined, its value is used as
2057 a recording host instead of local host."
2058 (let ((buffer (get-buffer-create " *MIME audio*"))
2059 (host (getenv "AUDIOHOST")))
2060 (message "Start the recording on %s. Type C-g to finish the recording..."
2061 (or host (system-name)))
2065 (condition-case errorcode
2066 (let ((selective-display nil) ;Disable ^M to nl translation.
2068 (kanji-flag nil)) ;NEmacs
2069 ;; If AUDIOHOST is defined, use the value as recording host.
2070 (cond ((not (null host))
2071 ;; Disable automatic conversion of coding system if Mule.
2072 (if (featurep 'mule)
2073 (define-program-coding-system nil "rsh" *noconv*))
2083 ;; Disable automatic conversion of coding system if Mule.
2084 (if (featurep 'mule)
2085 (define-program-coding-system nil "cat" *noconv*))
2091 (quit (message "Type C-g to finish recording... done.")
2092 buffer ;Return the buffer
2096 ;;; @ Other useful commands.
2099 ;; Message forwarding commands as content-type "message/rfc822".
2101 (defun mime-editor/insert-message (&optional message)
2103 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2104 (if (and inserter (fboundp inserter))
2106 (mime-editor/insert-tag "message" "rfc822")
2107 (funcall inserter message)
2109 (message "Sorry, I don't have message inserter for your MUA.")
2112 (defun mime-editor/insert-mail (&optional message)
2114 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2115 (if (and inserter (fboundp inserter))
2117 (mime-editor/insert-tag "message" "rfc822")
2118 (funcall inserter message)
2120 (message "Sorry, I don't have mail inserter for your MUA.")
2123 (defun mime-editor/inserted-message-filter ()
2126 (let ((header-start (point))
2127 (case-fold-search t)
2130 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2131 (if (re-search-forward "^$" (mark t))
2132 (narrow-to-region header-start (match-beginning 0))
2134 (goto-char header-start)
2135 (while (and (re-search-forward
2136 mime-editor/yank-ignored-field-regexp nil t)
2137 (setq beg (match-beginning 0))
2138 (setq end (1+ (rfc822/field-end)))
2140 (delete-region beg end)
2145 ;;; @ multipart enclosure
2148 (defun mime-editor/enclose-region (type beg end)
2151 (let ((current (point)))
2153 (narrow-to-region beg end)
2154 (insert (format "--<<%s>>-{\n" type))
2155 (goto-char (point-max))
2156 (insert (format "--}-<<%s>>\n" type))
2157 (goto-char (point-max))
2159 (or (looking-at mime-editor/beginning-tag-regexp)
2161 (insert (mime-make-text-tag) "\n")
2165 (defun mime-editor/enclose-quote-region (beg end)
2167 (mime-editor/enclose-region "quote" beg end)
2170 (defun mime-editor/enclose-mixed-region (beg end)
2172 (mime-editor/enclose-region "mixed" beg end)
2175 (defun mime-editor/enclose-parallel-region (beg end)
2177 (mime-editor/enclose-region "parallel" beg end)
2180 (defun mime-editor/enclose-digest-region (beg end)
2182 (mime-editor/enclose-region "digest" beg end)
2185 (defun mime-editor/enclose-alternative-region (beg end)
2187 (mime-editor/enclose-region "alternative" beg end)
2190 (defun mime-editor/enclose-signed-region (beg end)
2192 (if mime-editor/signing-type
2193 (mime-editor/enclose-region "signed" beg end)
2194 (message "Please specify signing type.")
2197 (defun mime-editor/enclose-encrypted-region (beg end)
2199 (if mime-editor/signing-type
2200 (mime-editor/enclose-region "encrypted" beg end)
2201 (message "Please specify encrypting type.")
2204 (defun mime-editor/insert-key (&optional arg)
2205 "Insert a pgp public key."
2207 (mime-editor/insert-tag "application" "pgp-keys")
2208 (mime-editor/define-encoding "7bit")
2209 (mc-insert-public-key)
2216 (defun mime-editor/set-split (arg)
2219 (y-or-n-p "Do you want to enable split?")
2221 (setq mime-editor/split-message arg)
2223 (message "This message is enabled to split.")
2224 (message "This message is not enabled to split.")
2227 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2228 "Toggle transfer-level is 7bit or 8bit through.
2230 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2232 (if (numberp transfer-level)
2233 (setq mime-editor/transfer-level transfer-level)
2234 (if (< mime-editor/transfer-level 8)
2235 (setq mime-editor/transfer-level 8)
2236 (setq mime-editor/transfer-level 7)
2238 (setq mime-editor/charset-default-encoding-alist
2239 (mime-editor/make-charset-default-encoding-alist
2240 mime-editor/transfer-level))
2241 (message (format "Current transfer-level is %d bit"
2242 mime-editor/transfer-level))
2243 (setq mime-editor/transfer-level-string
2244 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2245 (force-mode-line-update)
2252 (defun mime-editor/set-sign (arg)
2255 (y-or-n-p "Do you want to sign?")
2258 (if mime-editor/signing-type
2260 (setq mime-editor/pgp-processing 'sign)
2261 (message "This message will be signed.")
2263 (message "Please specify signing type.")
2265 (if (eq mime-editor/pgp-processing 'sign)
2266 (setq mime-editor/pgp-processing nil)
2268 (message "This message will not be signed.")
2271 (defun mime-editor/set-encrypt (arg)
2274 (y-or-n-p "Do you want to encrypt?")
2277 (if mime-editor/encrypting-type
2279 (setq mime-editor/pgp-processing 'encrypt)
2280 (message "This message will be encrypt.")
2282 (message "Please specify encrypting type.")
2284 (if (eq mime-editor/pgp-processing 'encrypt)
2285 (setq mime-editor/pgp-processing nil)
2287 (message "This message will not be encrypt.")
2290 (defvar mime-editor/pgp-processing nil)
2291 (make-variable-buffer-local 'mime-editor/pgp-processing)
2293 (defun mime-editor/pgp-enclose-buffer ()
2294 (let ((beg (save-excursion
2295 (goto-char (point-min))
2296 (if (search-forward (concat "\n" mail-header-separator "\n"))
2302 (cond ((eq mime-editor/pgp-processing 'sign)
2303 (mime-editor/enclose-signed-region beg end)
2305 ((eq mime-editor/pgp-processing 'encrypt)
2306 (mime-editor/enclose-encrypted-region beg end)
2314 (defun mime-editor/insert-partial-header
2315 (fields subject id number total separator)
2317 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2318 (insert (format "Mime-Version: 1.0 (split by %s)\n"
2319 mime-editor/version-name))
2321 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2322 id number total separator))
2325 (defun mime-editor/split-and-send
2326 (&optional cmd lines mime-editor/message-max-length)
2330 (count-lines (point-min) (point-max)))
2332 (or mime-editor/message-max-length
2333 (setq mime-editor/message-max-length
2334 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2335 mime-editor/message-default-max-length))
2337 (let* ((mime-editor/draft-file-name
2338 (or (buffer-file-name)
2340 (expand-file-name "tm-draft" mime/tmp-dir))))
2341 (separator mail-header-separator)
2343 (replace-space-with-underline (current-time-string))
2344 "@" (system-name) "\"")))
2345 (run-hooks 'mime-editor/before-split-hook)
2346 (let ((the-buf (current-buffer))
2347 (copy-buf (get-buffer-create " *Original Message*"))
2348 (header (rfc822/get-header-string-except
2349 mime-editor/split-ignored-field-regexp separator))
2350 (subject (mail-fetch-field "subject"))
2351 (total (+ (/ lines mime-editor/message-max-length)
2352 (if (> (mod lines mime-editor/message-max-length) 0)
2358 mime-editor/split-message-sender-alist))
2360 (mime-editor/partial-number 1)
2363 (set-buffer copy-buf)
2365 (insert-buffer the-buf)
2367 (if (re-search-forward
2368 (concat "^" (regexp-quote separator) "$") nil t)
2369 (let ((he (match-beginning 0)))
2371 (narrow-to-region (point-min) he)
2373 (goto-char (point-min))
2374 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
2375 (delete-region (match-beginning 0)
2376 (1+ (rfc822/field-end)))
2378 (while (< mime-editor/partial-number total)
2381 (set-buffer copy-buf)
2382 (setq data (buffer-substring
2385 (goto-line mime-editor/message-max-length)
2388 (delete-region (point-min)(point))
2390 (mime-editor/insert-partial-header
2391 header subject id mime-editor/partial-number total separator)
2394 (message (format "Sending %d/%d..."
2395 mime-editor/partial-number total))
2396 (call-interactively command)
2397 (message (format "Sending %d/%d... done"
2398 mime-editor/partial-number total))
2400 (setq mime-editor/partial-number
2401 (1+ mime-editor/partial-number))
2405 (set-buffer copy-buf)
2406 (setq data (buffer-string))
2409 (mime-editor/insert-partial-header
2410 header subject id mime-editor/partial-number total separator)
2413 (message (format "Sending %d/%d..."
2414 mime-editor/partial-number total))
2415 (message (format "Sending %d/%d... done"
2416 mime-editor/partial-number total))
2420 (defun mime-editor/maybe-split-and-send (&optional cmd)
2422 (run-hooks 'mime-editor/before-send-hook)
2423 (let ((mime-editor/message-max-length
2424 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2425 mime-editor/message-default-max-length))
2426 (lines (count-lines (point-min) (point-max)))
2428 (if (and (> lines mime-editor/message-max-length)
2429 mime-editor/split-message)
2430 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2434 ;;; @ preview message
2437 (defun mime-editor/preview-message ()
2438 "preview editing MIME message. [mime-edit.el]"
2440 (let* ((str (buffer-string))
2441 (separator mail-header-separator)
2442 (the-buf (current-buffer))
2443 (buf-name (buffer-name))
2444 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2445 (buf (get-buffer temp-buf-name))
2449 (switch-to-buffer buf)
2452 (setq buf (get-buffer-create temp-buf-name))
2453 (switch-to-buffer buf)
2456 (setq major-mode 'mime/temporary-message-mode)
2457 (make-local-variable 'mail-header-separator)
2458 (setq mail-header-separator separator)
2459 (make-local-variable 'mime/editing-buffer)
2460 (setq mime/editing-buffer the-buf)
2462 (run-hooks 'mime-editor/translate-hook)
2463 (mime-editor/translate-buffer)
2464 (goto-char (point-min))
2465 (if (re-search-forward
2466 (concat "^" (regexp-quote separator) "$"))
2472 (defun mime-editor/quitting-method ()
2473 (let ((temp mime::preview/article-buffer)
2475 (mime-viewer/kill-buffer)
2477 (setq buf mime/editing-buffer)
2479 (switch-to-buffer buf)
2482 (set-alist 'mime-viewer/quitting-method-alist
2483 'mime/temporary-message-mode
2484 (function mime-editor/quitting-method)
2490 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2491 ;; Mon, 10 Apr 1995 20:03:07 +0900
2493 (defvar mime-editor/draft-header-separator-alist
2494 '((news-reply-mode . mail-header-separator)
2495 (mh-letter-mode . mail-header-separator)
2498 (defvar mime::article/draft-header-separator nil)
2500 (defun mime-editor/draft-preview ()
2502 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2503 (or (stringp sep) (setq sep (eval sep)))
2504 (make-variable-buffer-local 'mime::article/draft-header-separator)
2505 (goto-char (point-min))
2507 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2508 (setq mime::article/draft-header-separator
2509 (buffer-substring (match-beginning 0) (match-end 0)))
2511 (mime/viewer-mode (current-buffer))
2512 (pop-to-buffer (current-buffer))
2515 (defun mime-viewer::quitting-method/draft-preview ()
2516 (let ((mother mime::preview/mother-buffer))
2518 (switch-to-buffer mother)
2519 (goto-char (point-min))
2523 (regexp-quote mime::article/draft-header-separator)
2527 (insert mime::article/draft-header-separator)
2528 (set-buffer-modified-p (buffer-modified-p))
2530 (mime-viewer/kill-buffer)
2531 (pop-to-buffer mother)
2534 (set-alist 'mime-viewer/quitting-method-alist
2536 (function mime-viewer::quitting-method/draft-preview)
2539 (set-alist 'mime-viewer/quitting-method-alist
2541 (function mime-viewer::quitting-method/draft-preview)
2548 (defun mime-editor::edit-again (code-conversion)
2550 (goto-char (point-min))
2551 (let ((ctl (mime/Content-Type)))
2553 (let ((ctype (car ctl))
2556 (if (string-match "/" ctype)
2558 (setq type (substring ctype 0 (match-beginning 0)))
2559 (setq stype (substring ctype (match-end 0)))
2564 ((string-equal type "multipart")
2565 (let* ((boundary (assoc-value "boundary" params))
2567 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2569 (re-search-forward boundary-pat nil t)
2570 (let ((bb (match-beginning 0)) eb tag)
2571 (setq tag (format "\n--<<%s>>-{\n" stype))
2574 (setq bb (+ bb (length tag)))
2576 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2578 (setq eb (match-beginning 0))
2579 (replace-match (format "--}-<<%s>>\n" stype))
2581 (narrow-to-region bb eb)
2582 (goto-char (point-min))
2583 (while (re-search-forward boundary-pat nil t)
2584 (let ((beg (match-beginning 0))
2586 (delete-region beg (match-end 0))
2588 (if (re-search-forward boundary-pat nil t)
2589 (setq end (match-beginning 0))
2590 (setq end (point-max))
2593 (narrow-to-region beg end)
2594 (mime-editor::edit-again code-conversion)
2595 (goto-char (point-max))
2598 (goto-char (point-min))
2599 (or (= (point-min) 1)
2600 (delete-region (point-min)
2601 (if (search-forward "\n\n" nil t)
2609 (mapconcat (function
2611 (if (string-equal (car attr)
2614 (setq charset (cdr attr))
2616 (concat ";" (car attr)
2624 (if (re-search-forward
2625 "Content-Transfer-Encoding:" nil t)
2626 (let ((beg (match-beginning 0))
2627 (hbeg (match-end 0))
2628 (end (rfc822/field-end)))
2630 (eliminate-top-spaces
2631 (rfc822/unfolding-string
2632 (buffer-substring hbeg end))))
2633 (if (or charset (string-equal type "text"))
2635 (delete-region beg (1+ end))
2636 (goto-char (point-min))
2637 (if (search-forward "\n\n" nil t)
2640 (match-end 0)(point-max) encoding)
2644 (if (or code-conversion encoded)
2646 (mime-charset-decode-region (point-min)(point-max)
2648 (character-decode-region (point-min)(point-max)
2649 mime/default-coding-system)
2652 (if (re-search-forward "^$" nil t)
2656 (if (= (point-min) 1)
2662 (concat type "/" stype pstr) encoding)))
2664 (delete-region (point-min) he)
2667 (concat type "/" stype pstr) encoding))
2671 (character-decode-region (point-min) (point-max)
2672 mime/default-coding-system)
2676 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2678 (mime-editor::edit-again code-conversion)
2679 (goto-char (point-min))
2683 (if (re-search-forward
2684 (concat "^\\(" (regexp-quote mail-header-separator) "\\)?$")
2689 (goto-char (point-min))
2690 (while (re-search-forward
2691 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2692 (delete-region (match-beginning 0) (1+ (rfc822/field-end)))
2695 (and (re-search-forward "^$")
2696 (replace-match mail-header-separator)
2706 (provide 'mime-edit)
2709 (if (boundp 'mime-edit-load-hook)
2710 (run-hooks 'mime-edit-load-hook)
2711 (run-hooks 'tm-edit-load-hook)
2714 ;;; mime-edit.el ends here