1 ;;; tm-edit.el --- Simple MIME Composer for GNU Emacs
3 ;; Copyright (C) 1993 .. 1996 Free Software Foundation, Inc.
5 ;; Author: UMEDA Masanobu <umerin@mse.kyutech.ac.jp>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Created: 1994/08/21 renamed from mime.el
9 ;; Version: $Revision: 7.89 $
10 ;; Keywords: mail, news, MIME, multimedia, multilingual
12 ;; This file is part of tm (Tools for MIME).
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
31 ;; This is an Emacs minor mode for editing Internet multimedia
32 ;; messages formatted in MIME (RFC 1521 and RFC 1522). All messages in
33 ;; this mode are composed in the tagged MIME format, that are
34 ;; described in the following examples. The messages composed in the
35 ;; tagged MIME format are automatically translated into a MIME
36 ;; compliant message when exiting the mode.
38 ;; Mule (a multilingual extension to Emacs 18 and 19) has a capability
39 ;; of handling multilingual text in limited ISO-2022 manner that is
40 ;; based on early experiences in Japanese Internet community and
41 ;; resulted in RFC 1468 (ISO-2022-JP charset for MIME). In order to
42 ;; enable multilingual capability in single text message in MIME,
43 ;; charset of multilingual text written in Mule is declared as either
44 ;; `ISO-2022-JP-2' [RFC 1554] or `ISO-2022-INT-1'. Mule is required
45 ;; for reading the such messages.
47 ;; This MIME composer can work with Mail mode, mh-e letter Mode, and
48 ;; News mode. First of all, you need the following autoload
49 ;; definition to load mime/editor-mode automatically:
51 ;; (autoload 'mime/editor-mode "tm-edit"
52 ;; "Minor mode for editing MIME message." t)
54 ;; In case of Mail mode (includes VM mode), you need the following
57 ;; (add-hook 'mail-mode-hook 'mime/editor-mode)
58 ;; (add-hook 'mail-send-hook 'mime-editor/maybe-translate)
60 ;; In case of MH-E, you need the following hook definition:
62 ;; (add-hook 'mh-letter-mode-hook
66 ;; (make-local-variable 'mail-header-separator)
67 ;; (setq mail-header-separator "--------")
69 ;; (add-hook 'mh-before-send-letter-hook 'mime-editor/maybe-translate)
71 ;; In case of News mode, you need the following hook definition:
73 ;; (add-hook 'news-reply-mode-hook 'mime/editor-mode)
74 ;; (add-hook 'news-inews-hook 'mime-editor/maybe-translate)
76 ;; In case of Emacs 19, it is possible to emphasize the message tags
77 ;; using font-lock mode as follows:
79 ;; (add-hook 'mime/editor-mode-hook
83 ;; (setq font-lock-keywords (list mime-editor/tag-regexp))
86 ;; The message tag looks like:
88 ;; --[[TYPE/SUBTYPE;PARAMETERS][ENCODING]]
90 ;; The tagged MIME message examples:
92 ;; This is a conventional plain text. It should be translated into
96 ;; This is also a plain text. But, it is explicitly specified as is.
98 ;;--[[text/plain; charset=ISO-2022-JP]]
99 ;;
\e$B$3$l$O
\e(B charset
\e$B$r
\e(B ISO-2022-JP
\e$B$K;XDj$7$?F|K\8l$N
\e(B plain
\e$B%F%-%9%H$G$9
\e(B.
101 ;;--[[text/richtext]]
102 ;; <center>This is a richtext.</center>
104 ;;--[[image/gif][base64]]^M...image encoded in base64 comes here...
106 ;;--[[audio/basic][base64]]^M...audio encoded in base64 comes here...
111 (require 'mail-utils)
123 (defconst mime-editor/RCS-ID
124 "$Id: tm-edit.el,v 7.89 1996/10/01 13:03:50 morioka Exp $")
126 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
128 (defconst mime-editor/version-name
129 (concat "tm-edit " mime-editor/version))
135 (defvar mime-prefix "\C-c\C-x"
136 "*Keymap prefix for MIME commands.")
138 (defvar mime-ignore-preceding-spaces nil
139 "*Ignore preceding white spaces if non-nil.")
141 (defvar mime-ignore-trailing-spaces nil
142 "*Ignore trailing white spaces if non-nil.")
144 (defvar mime-ignore-same-text-tag t
145 "*Ignore preceding text content-type tag that is same with new one.
146 If non-nil, the text tag is not inserted unless something different.")
148 (defvar mime-auto-hide-body t
149 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
151 (defvar mime-editor/voice-recorder
152 (function mime-editor/voice-recorder-for-sun)
153 "*Function to record a voice message and encode it. [tm-edit.el]")
155 (defvar mime/editor-mode-hook nil
156 "*Hook called when enter MIME mode.")
158 (defvar mime-editor/translate-hook nil
159 "*Hook called before translating into a MIME compliant message.
160 To insert a signature file automatically, call the function
161 `mime-editor/insert-signature' from this hook.")
163 (defvar mime-editor/exit-hook nil
164 "*Hook called when exit MIME mode.")
166 (defvar mime-content-types
168 ;; Charset parameter need not to be specified, since it is
169 ;; defined automatically while translation.
171 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
174 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
177 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
180 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
183 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
191 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
192 ("directory" "/pub/GNU/elisp/mime")
194 ("mode" "image" "ascii" "local8"))
199 ("mode" "image" "ascii" "local8"))
200 ("tftp" ("site") ("name"))
201 ("afs" ("site") ("name"))
202 ("local-file" ("site") ("name"))
203 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
208 ("octet-stream" ("type" "" "tar" "shar"))
210 ("x-kiss" ("x-cnf")))
223 "*Alist of content-type, subtype, parameters and its values.")
225 (defvar mime-file-types
227 "text" "richtext" nil
235 "application" "postscript" nil
237 "attachment" (("filename" . file))
242 "inline" (("filename" . file))
247 "inline" (("filename" . file))
252 "inline" (("filename" . file))
257 "inline" (("filename" . file))
262 "inline" (("filename" . file))
267 "inline" (("filename" . file))
272 "inline" (("filename" . file))
277 "attachment" (("filename" . file))
282 "attachment" (("filename" . file))
285 "application" "octet-stream" (("type" . "emacs-lisp"))
287 "attachment" (("filename" . file))
290 "application" "octet-stream" (("type" . "common-lisp"))
292 "attachment" (("filename" . file))
295 "application" "octet-stream" (("type" . "tar+gzip"))
297 "attachment" (("filename" . file))
300 "application" "octet-stream" (("type" . "tar+gzip"))
302 "attachment" (("filename" . file))
305 "application" "octet-stream" (("type" . "tar+compress"))
307 "attachment" (("filename" . file))
310 "application" "octet-stream" (("type" . "tar+compress"))
312 "attachment" (("filename" . file))
315 "application" "octet-stream" (("type" . "gzip"))
317 "attachment" (("filename" . file))
320 "application" "octet-stream" (("type" . "compress"))
322 "attachment" (("filename" . file))
325 "application" "octet-stream" (("type" . "lha"))
327 "attachment" (("filename" . file))
330 "application" "zip" nil
332 "attachment" (("filename" . file))
335 "application" "octet-stream" (("type" . "patch"))
337 "attachment" (("filename" . file))
340 "application" "octet-stream" (("type" . "patch"))
342 "attachment" (("filename" . file))
345 "text" "plain" nil nil)
347 "application" "octet-stream" nil
349 "attachment" (("filename" . file))
352 "*Alist of file name, types, parameters, and default encoding.
353 If encoding is nil, it is determined from its contents.")
355 ;;; @@ about charset, encoding and transfer-level
358 (defvar mime-editor/transfer-level 7
359 "*A number of network transfer level. It should be bigger than 7.")
360 (make-variable-buffer-local 'mime-editor/transfer-level)
362 (defvar mime-editor/transfer-level-string
363 (mime/encoding-name mime-editor/transfer-level 'not-omit)
364 "*A string formatted version of mime/defaul-transfer-level")
365 (make-variable-buffer-local 'mime-editor/transfer-level-string)
367 (defun mime-editor/make-charset-default-encoding-alist (transfer-level)
369 (lambda (charset-type)
370 (let ((charset (car charset-type))
371 (type (nth 1 charset-type))
372 (encoding (nth 2 charset-type))
374 (if (<= type transfer-level)
375 (cons charset (mime/encoding-name type))
376 (cons charset encoding)
378 mime-charset-type-list))
380 (defvar mime-editor/charset-default-encoding-alist
381 (mime-editor/make-charset-default-encoding-alist mime-editor/transfer-level))
382 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
384 ;;; @@ about message inserting
387 (defvar mime-editor/yank-ignored-field-list
388 '("Received" "Approved" "Path" "Replied" "Status" "X-VM-.*" "X-UIDL")
389 "Delete these fields from original message when it is inserted
390 as message/rfc822 part.
391 Each elements are regexp of field-name. [tm-edit.el]")
393 (defvar mime-editor/yank-ignored-field-regexp
395 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
398 (defvar mime-editor/message-inserter-alist nil)
399 (defvar mime-editor/mail-inserter-alist nil)
401 ;;; @@ about message splitting
404 (defvar mime-editor/split-message t
405 "*Split large message if it is non-nil. [tm-edit.el]")
407 (defvar mime-editor/message-default-max-length 1000
408 "*Default maximum size of a message. [tm-edit.el]")
410 (defvar mime-editor/message-max-length-alist
411 '((news-reply-mode . 500)))
413 (defconst mime-editor/split-ignored-field-regexp
414 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
416 (defvar mime-editor/split-blind-field-regexp
417 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
419 (defvar mime-editor/split-message-sender-alist nil)
421 (defvar mime-editor/news-reply-mode-server-running nil)
427 (defvar mime-editor/signing-type nil
428 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
430 (defvar mime-editor/encrypting-type nil
431 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
433 (if (or mime-editor/signing-type mime-editor/encrypting-type)
441 (defconst mime-editor/single-part-tag-regexp
442 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
443 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
445 (defconst mime-editor/quoted-single-part-tag-regexp
446 (concat "- " (substring mime-editor/single-part-tag-regexp 1)))
448 (defconst mime-editor/multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
450 (defconst mime-editor/multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
452 (defconst mime-editor/beginning-tag-regexp
453 (regexp-or mime-editor/single-part-tag-regexp
454 mime-editor/multipart-beginning-regexp))
456 (defconst mime-editor/end-tag-regexp
457 (regexp-or mime-editor/single-part-tag-regexp
458 mime-editor/multipart-end-regexp))
460 (defconst mime-editor/tag-regexp
461 (regexp-or mime-editor/single-part-tag-regexp
462 mime-editor/multipart-beginning-regexp
463 mime-editor/multipart-end-regexp))
465 (defvar mime-tag-format "--[[%s]]"
466 "*Control-string making a MIME tag.")
468 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
469 "*Control-string making a MIME tag with encoding.")
471 ;;; @@ multipart boundary
474 (defvar mime-multipart-boundary "Multipart"
475 "*Boundary of a multipart message.")
478 ;;; @@ buffer local variables
481 (defvar mime/editor-mode-old-local-map nil)
482 (defvar mime/editing-buffer nil)
488 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
489 "*Specify MIME tspecials.
490 Tspecials means any character that matches with it in header must be quoted.")
492 (defconst mime-editor/mime-version-value
493 (concat "1.0 (generated by " mime-editor/version-name ")")
494 "MIME version number.")
496 (defconst mime-editor/mime-map (make-sparse-keymap)
497 "Keymap for MIME commands.")
499 ;;; @ keymap and menu
502 (defvar mime/editor-mode-flag nil)
503 (make-variable-buffer-local 'mime/editor-mode-flag)
505 (defun mime-editor/define-keymap (keymap)
506 "Add mime-editor commands to KEYMAP."
507 (if (not (keymapp keymap))
509 (define-key keymap "\C-t" 'mime-editor/insert-text)
510 (define-key keymap "\C-i" 'mime-editor/insert-file)
511 (define-key keymap "\C-e" 'mime-editor/insert-external)
512 (define-key keymap "\C-v" 'mime-editor/insert-voice)
513 (define-key keymap "\C-y" 'mime-editor/insert-message)
514 (define-key keymap "\C-m" 'mime-editor/insert-mail)
515 (define-key keymap "\C-w" 'mime-editor/insert-signature)
516 (define-key keymap "\C-s" 'mime-editor/insert-signature)
517 (define-key keymap "\C-k" 'mime-editor/insert-key)
518 (define-key keymap "t" 'mime-editor/insert-tag)
519 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
520 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
521 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
522 (define-key keymap "d" 'mime-editor/enclose-digest-region)
523 (define-key keymap "s" 'mime-editor/enclose-signed-region)
524 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
525 (define-key keymap "q" 'mime-editor/enclose-quote-region)
526 (define-key keymap "7" 'mime-editor/set-transfer-level-7bit)
527 (define-key keymap "8" 'mime-editor/set-transfer-level-8bit)
528 (define-key keymap "/" 'mime-editor/set-split)
529 (define-key keymap "v" 'mime-editor/set-sign)
530 (define-key keymap "h" 'mime-editor/set-encrypt)
531 (define-key keymap "\C-p" 'mime-editor/preview-message)
532 (define-key keymap "\C-z" 'mime-editor/exit)
533 (define-key keymap "?" 'mime-editor/help)
536 (mime-editor/define-keymap mime-editor/mime-map)
538 (defun mime-editor/toggle-mode ()
540 (if mime/editor-mode-flag
541 (mime-editor/exit 'nomime)
545 (cond (running-xemacs
546 (defconst mime-editor/minor-mime-map nil "Keymap for MIME commands.")
547 (or mime-editor/minor-mime-map
549 (setq mime-editor/minor-mime-map
550 (make-sparse-keymap 'mime-editor/minor-mime-map))
552 mime-editor/minor-mime-map mime-prefix mime-editor/mime-map)
554 (add-minor-mode 'mime/editor-mode-flag
555 '((" MIME-Edit " mime-editor/transfer-level-string))
556 mime-editor/minor-mime-map
558 'mime-editor/toggle-mode)
561 (set-alist 'minor-mode-alist
562 'mime/editor-mode-flag
563 '((" MIME-Edit " mime-editor/transfer-level-string))))
566 (defconst mime-editor/menu-title "MIME-Edit")
568 (defconst mime-editor/menu-list
569 '((mime-help "Describe MIME editor mode" mime-editor/help)
570 (file "Insert File" mime-editor/insert-file)
571 (external "Insert External" mime-editor/insert-external)
572 (voice "Insert Voice" mime-editor/insert-voice)
573 (message "Insert Message" mime-editor/insert-message)
574 (mail "Insert Mail" mime-editor/insert-mail)
575 (signature "Insert Signature" mime-editor/insert-signature)
576 (text "Insert Text" mime-editor/insert-text)
577 (tag "Insert Tag" mime-editor/insert-tag)
578 (alternative "Enclose as alternative"
579 mime-editor/enclose-alternative-region)
580 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
581 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
582 (digest "Enclose as digest" mime-editor/enclose-digest-region)
583 (signed "Enclose as signed" mime-editor/enclose-signed-region)
584 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
585 (quote "Verbatim region" mime-editor/enclose-quote-region)
586 (key "Insert Public Key" mime-editor/insert-key)
587 (split "About split" mime-editor/set-split)
588 (sign "About sign" mime-editor/set-sign)
589 (encrypt "About encryption" mime-editor/set-encrypt)
590 (preview "Preview Message" mime-editor/preview-message)
591 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
593 "MIME-edit menubar entry.")
595 (defun mime-editor/define-menu-for-emacs19 ()
596 "Define menu for Emacs 19."
597 (define-key (current-local-map) [menu-bar mime-edit]
598 (cons mime-editor/menu-title
599 (make-sparse-keymap mime-editor/menu-title)))
602 (define-key (current-local-map)
603 (vector 'menu-bar 'mime-edit (car item))
604 (cons (nth 1 item)(nth 2 item))
607 (reverse mime-editor/menu-list)
610 ;;; modified by Pekka Marjola <pema@iki.fi>
611 ;;; 1995/9/5 (c.f. [tm-en:69])
612 (defun mime-editor/define-menu-for-xemacs ()
613 "Define menu for Emacs 19."
614 (cond ((featurep 'menubar)
615 (make-local-variable 'current-menubar)
616 (set-buffer-menubar current-menubar)
618 (cons mime-editor/menu-title
621 (vector (nth 1 item)(nth 2 item)
622 mime/editor-mode-flag)
624 mime-editor/menu-list)))
627 ;;; modified by Steven L. Baur <steve@miranova.com>
628 ;;; 1995/12/6 (c.f. [tm-en:209])
629 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
630 (setq mime-editor/popup-menu-for-xemacs
631 (append '("MIME Commands" "---")
632 (mapcar (function (lambda (item)
636 mime-editor/menu-list)))
645 (defun mime/editor-mode ()
646 "MIME minor mode for editing the tagged MIME message.
648 In this mode, basically, the message is composed in the tagged MIME
649 format. The message tag looks like:
651 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
653 The tag specifies the MIME content type, subtype, optional parameters
654 and transfer encoding of the message following the tag. Messages
655 without any tag are treated as `text/plain' by default. Charset and
656 transfer encoding are automatically defined unless explicitly
657 specified. Binary messages such as audio and image are usually hidden.
658 The messages in the tagged MIME format are automatically translated
659 into a MIME compliant message when exiting this mode.
661 Available charsets depend on Emacs version being used. The following
662 lists the available charsets of each emacs.
664 EMACS 18: US-ASCII is only available.
665 NEmacs: US-ASCII and ISO-2022-JP are available.
666 EMACS 19: US-ASCII and ISO-8859-1 (or other charset) are available.
667 XEmacs 19: US-ASCII and ISO-8859-1 (or other charset) are available.
668 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
669 ISO-2022-JP, ISO-2022-JP-2, ISO-2022-KR, BIG5 and
670 ISO-2022-INT-1 are available.
672 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
673 be used to represent multilingual text in intermixed manner. Any
674 languages that has no registered charset are represented as either
675 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
677 If you want to use non-ISO-8859-1 charset in EMACS 19 or XEmacs 19,
678 please set variable `default-mime-charset'. This variable must be
679 symbol of which name is a MIME charset.
681 If you want to add more charsets in mule, please set variable
682 `charsets-mime-charset-alist'. This variable must be alist of which
683 key is list of leading-char/charset and value is symbol of MIME
684 charset. (leading-char is a term of MULE 1.* and 2.*. charset is a
685 term of XEmacs/mule, mule merged EMACS and MULE 3.*) If name of
686 coding-system is different as MIME charset, please set variable
687 `mime-charset-coding-system-alist'. This variable must be alist of
688 which key is MIME charset and value is coding-system.
690 Following commands are available in addition to major mode commands:
691 \\[mime-editor/insert-text] insert a text message.
692 \\[mime-editor/insert-file] insert a (binary) file.
693 \\[mime-editor/insert-external] insert a reference to external body.
694 \\[mime-editor/insert-voice] insert a voice message.
695 \\[mime-editor/insert-message] insert a mail or news message.
696 \\[mime-editor/insert-mail] insert a mail message.
697 \\[mime-editor/insert-signature] insert a signature file at end.
698 \\[mime-editor/insert-tag] insert a new MIME tag.
699 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
700 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
701 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
702 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
703 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
704 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
705 \\[mime-editor/insert-key] insert PGP public key.
706 \\[mime-editor/preview-message] preview editing MIME message.
707 \\[mime-editor/exit] exit and translate into a MIME compliant message.
708 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
709 \\[mime-editor/help] show this help.
711 Additional commands are available in some major modes:
712 C-c C-c exit, translate and run the original command.
713 C-c C-s exit, translate and run the original command.
715 The following is a message example written in the tagged MIME format.
716 TABs at the beginning of the line are not a part of the message:
718 This is a conventional plain text. It should be translated
721 This is also a plain text. But, it is explicitly specified as
723 --[[text/plain; charset=ISO-2022-JP]]
724 \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
727 <center>This is a richtext.</center>
728 --[[image/gif][base64]]^M...image encoded in base64 here...
729 --[[audio/basic][base64]]^M...audio encoded in base64 here...
731 User customizable variables (not documented all of them):
733 Specifies a key prefix for MIME minor mode commands.
735 mime-ignore-preceding-spaces
736 Preceding white spaces in a message body are ignored if non-nil.
738 mime-ignore-trailing-spaces
739 Trailing white spaces in a message body are ignored if non-nil.
741 mime-auto-fill-header
742 Fill header fields that contain encoded-words if non-nil.
745 Hide a non-textual body message encoded in base64 after insertion
748 mime-editor/voice-recorder
749 Specifies a function to record a voice message and encode it.
750 The function `mime-editor/voice-recorder-for-sun' is for Sun
753 mime/editor-mode-hook
754 Turning on MIME mode calls the value of mime/editor-mode-hook, if
757 mime-editor/translate-hook
758 The value of mime-editor/translate-hook is called just before translating
759 the tagged MIME format into a MIME compliant message if it is
760 non-nil. If the hook call the function mime-editor/insert-signature,
761 the signature file will be inserted automatically.
763 mime-editor/exit-hook
764 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
767 (if mime/editor-mode-flag
768 (error "You are already editing a MIME message.")
769 (setq mime/editor-mode-flag t)
770 ;; Remember old key bindings.
772 (use-local-map (or (current-local-map) (make-sparse-keymap)))
773 (make-local-variable 'mime/editor-mode-old-local-map)
774 (setq mime/editor-mode-old-local-map (current-local-map))
775 ;; Add MIME commands to current local map.
776 (use-local-map (copy-keymap (or (current-local-map)
777 (make-sparse-keymap))))
779 (if (not (lookup-key (current-local-map) mime-prefix))
780 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
782 ;; Set transfer level into mode line
784 (setq mime-editor/transfer-level-string
785 (mime/encoding-name mime-editor/transfer-level 'not-omit))
786 (force-mode-line-update)
788 ;; Define menu. Menus for other emacs implementations are
790 (cond (running-xemacs
791 (mime-editor/define-menu-for-xemacs))
792 ((>= emacs-major-version 19)
793 (mime-editor/define-menu-for-emacs19)
799 ;; I don't care about saving these.
800 (setq paragraph-start
801 (regexp-or mime-editor/single-part-tag-regexp
803 (setq paragraph-separate
804 (regexp-or mime-editor/single-part-tag-regexp
806 (run-hooks 'mime/editor-mode-hook)
808 (substitute-command-keys
809 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
813 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
814 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
816 (defun mime-editor/exit (&optional nomime no-error)
817 "Translate the tagged MIME message into a MIME compliant message.
818 With no argument encode a message in the buffer into MIME, otherwise
819 just return to previous mode."
821 (if (not mime/editor-mode-flag)
823 (error "You aren't editing a MIME message.")
827 (run-hooks 'mime-editor/translate-hook)
828 (mime-editor/translate-buffer)))
829 ;; Restore previous state.
830 (setq mime/editor-mode-flag nil)
831 (cond (running-xemacs
832 (delete-menu-item (list mime-editor/menu-title)))
834 (use-local-map mime/editor-mode-old-local-map)))
837 (set-buffer-modified-p (buffer-modified-p))
838 (run-hooks 'mime-editor/exit-hook)
839 (message "Exit MIME editor mode.")
842 (defun mime-editor/maybe-translate ()
844 (mime-editor/exit nil t)
845 (call-interactively 'mime-editor/maybe-split-and-send)
848 (defun mime-editor/help ()
849 "Show help message about MIME mode."
851 (with-output-to-temp-buffer "*Help*"
852 (princ "MIME editor mode:\n")
853 (princ (documentation 'mime/editor-mode))
854 (print-help-return-message)))
856 (defun mime-editor/insert-text ()
857 "Insert a text message.
858 Charset is automatically obtained from the `mime/lc-charset-alist'."
860 (let ((ret (mime-editor/insert-tag "text" nil nil)))
863 (if (looking-at mime-editor/single-part-tag-regexp)
865 ;; Make a space between the following message.
869 (if (and (member (second ret) '("enriched" "richtext"))
870 (fboundp 'enriched-mode)
873 (if (boundp 'enriched-mode)
877 (defun mime-editor/insert-file (file)
878 "Insert a message from a file."
879 (interactive "fInsert file as MIME message: ")
880 (let* ((guess (mime-find-file-type file))
881 (pritype (nth 0 guess))
882 (subtype (nth 1 guess))
883 (parameters (nth 2 guess))
884 (default (nth 3 guess)) ;Guess encoding from its file name.
885 (disposition-type (nth 4 guess))
886 (disposition-params (nth 5 guess))
888 (if (not (interactive-p))
891 (concat "What transfer encoding"
894 (if (string-equal default "")
900 mime-file-encoding-method-alist nil t nil))))
901 (if (string-equal encoding "")
902 (setq encoding default))
903 (if (or (consp parameters) (stringp disposition-type))
904 (let ((rest parameters) cell attribute value)
907 (setq cell (car rest))
908 (setq attribute (car cell))
909 (setq value (cdr cell))
911 (setq value (std11-wrap-as-quoted-string
912 (file-name-nondirectory file)))
914 (setq parameters (concat parameters "; " attribute "=" value))
915 (setq rest (cdr rest))
920 (concat parameters "\n"
921 "Content-Disposition: " disposition-type))
922 (setq rest disposition-params)
924 (setq cell (car rest))
925 (setq attribute (car cell))
926 (setq value (cdr cell))
928 (setq value (std11-wrap-as-quoted-string
929 (file-name-nondirectory file)))
932 (concat parameters "; " attribute "=" value))
933 (setq rest (cdr rest))
937 (mime-editor/insert-tag pritype subtype parameters)
938 (mime-editor/insert-binary-file file encoding)
941 (defun mime-editor/insert-external ()
942 "Insert a reference to external body."
944 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
946 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
948 (let* ((pritype (mime-prompt-for-type))
949 (subtype (mime-prompt-for-subtype pritype))
950 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
953 (insert "Content-Type: "
954 pritype "/" subtype (or parameters "") "\n")))
955 (if (and (not (eobp))
956 (not (looking-at mime-editor/single-part-tag-regexp)))
957 (insert (mime-make-text-tag) "\n")))
959 (defun mime-editor/insert-voice ()
960 "Insert a voice message."
964 "What transfer encoding: "
965 mime-file-encoding-method-alist nil t nil)))
966 (mime-editor/insert-tag "audio" "basic" nil)
967 (mime-editor/define-encoding encoding)
969 (narrow-to-region (1- (point))(point))
971 (funcall mime-editor/voice-recorder encoding)
974 (invisible-region (point-min)(point-max))
975 (goto-char (point-max))
978 (defun mime-editor/insert-signature (&optional arg)
979 "Insert a signature file."
981 (let ((signature-insert-hook
984 (apply (function mime-editor/insert-tag)
985 (mime-find-file-type signature-file-name))
988 (insert-signature arg)
992 ;; Insert a new tag around a point.
994 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
995 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
996 If nothing is inserted, return nil."
999 (mime-editor/goto-tag)
1000 (if (and (re-search-forward mime-editor/tag-regexp nil t)
1001 (< (match-beginning 0) p)
1004 (goto-char (match-beginning 0))
1013 (mime-prompt-for-type)))
1016 (mime-prompt-for-subtype pritype)))
1019 (mime-prompt-for-parameters pritype subtype delimiter)))
1020 ;; Make a new MIME tag.
1021 (setq newtag (mime-make-tag pritype subtype parameters))
1022 ;; Find an current MIME tag.
1025 (if (mime-editor/goto-tag)
1026 (buffer-substring (match-beginning 0) (match-end 0))
1027 ;; Assume content type is 'text/plan'.
1028 (mime-make-tag "text" "plain")
1030 ;; We are only interested in TEXT.
1032 (not (mime-test-content-type
1033 (mime-editor/get-contype oldtag) "text")))
1036 (if (or (not oldtag) ;Not text
1037 (or mime-ignore-same-text-tag
1038 (not (string-equal oldtag newtag))))
1040 ;; Mark the beginning of the tag for convenience.
1041 (push-mark (point) 'nomsg)
1042 (insert newtag "\n")
1043 (list pritype subtype parameters) ;New tag is created.
1045 ;; Restore previous point.
1047 nil ;Nothing is created.
1051 (defun mime-editor/insert-binary-file (file &optional encoding)
1052 "Insert binary FILE at point.
1053 Optional argument ENCODING specifies an encoding method such as base64."
1054 (let* ((tagend (1- (point))) ;End of the tag
1055 (hide-p (and mime-auto-hide-body
1058 (let ((en (downcase encoding)))
1059 (or (string-equal en "7bit")
1060 (string-equal en "8bit")
1061 (string-equal en "binary")
1065 (narrow-to-region tagend (point))
1066 (mime-insert-encoded-file file encoding)
1069 (invisible-region (point-min) (point-max))
1070 (goto-char (point-max))
1072 (goto-char (point-max))
1075 (looking-at mime-editor/tag-regexp)
1076 (= (point)(point-max))
1077 (mime-editor/insert-tag "text" "plain")
1079 ;; Define encoding even if it is 7bit.
1080 (if (stringp encoding)
1082 (goto-char tagend) ; Make sure which line the tag is on.
1083 (mime-editor/define-encoding encoding)
1088 ;; Commands work on a current message flagment.
1090 (defun mime-editor/goto-tag ()
1091 "Search for the beginning of the tagged MIME message."
1092 (let ((current (point)) multipart)
1093 (if (looking-at mime-editor/tag-regexp)
1095 ;; At first, go to the end.
1096 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1097 (goto-char (1- (match-beginning 0))) ;For multiline tag
1100 (goto-char (point-max))
1102 ;; Then search for the beginning.
1103 (re-search-backward mime-editor/end-tag-regexp nil t)
1104 (or (looking-at mime-editor/beginning-tag-regexp)
1105 ;; Restore previous point.
1112 (defun mime-editor/content-beginning ()
1113 "Return the point of the beginning of content."
1115 (let ((beg (save-excursion
1116 (beginning-of-line) (point))))
1117 (if (mime-editor/goto-tag)
1118 (let ((top (point)))
1119 (goto-char (match-end 0))
1120 (if (and (= beg top)
1121 (= (following-char) ?\^M))
1125 ;; Default text/plain tag.
1126 (goto-char (point-min))
1128 (concat "\n" (regexp-quote mail-header-separator)
1129 (if mime-ignore-preceding-spaces
1130 "[ \t\n]*\n" "\n")) nil 'move)
1134 (defun mime-editor/content-end ()
1135 "Return the point of the end of content."
1137 (let ((beg (point)))
1138 (if (mime-editor/goto-tag)
1139 (let ((top (point)))
1140 (goto-char (match-end 0))
1141 (if (invisible-p (point))
1142 (next-visible-point (point))
1143 ;; Move to the end of this text.
1144 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1145 ;; Don't forget a multiline tag.
1146 (goto-char (match-beginning 0))
1150 ;; Assume the message begins with text/plain.
1151 (goto-char (mime-editor/content-beginning))
1152 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1153 ;; Don't forget a multiline tag.
1154 (goto-char (match-beginning 0)))
1158 (defun mime-editor/define-charset (charset)
1159 "Set charset of current tag to CHARSET."
1161 (if (mime-editor/goto-tag)
1162 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1163 (delete-region (match-beginning 0) (match-end 0))
1166 (mime-editor/set-parameter
1167 (mime-editor/get-contype tag)
1168 "charset" (upcase (symbol-name charset)))
1169 (mime-editor/get-encoding tag)))
1172 (defun mime-editor/define-encoding (encoding)
1173 "Set encoding of current tag to ENCODING."
1175 (if (mime-editor/goto-tag)
1176 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1177 (delete-region (match-beginning 0) (match-end 0))
1178 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1181 (defun mime-editor/choose-charset ()
1182 "Choose charset of a text following current point."
1183 (detect-mime-charset-region (point) (mime-editor/content-end))
1186 (defun mime-make-text-tag (&optional subtype)
1187 "Make a tag for a text after current point.
1188 Subtype of text type can be specified by an optional argument SUBTYPE.
1189 Otherwise, it is obtained from mime-content-types."
1190 (let* ((pritype "text")
1191 (subtype (or subtype
1192 (car (car (cdr (assoc pritype mime-content-types)))))))
1193 ;; Charset should be defined later.
1194 (mime-make-tag pritype subtype)))
1197 ;; Tag handling functions
1199 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1200 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1201 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1205 (defun mime-create-tag (contype &optional encoding)
1206 "Make a tag with CONTENT-TYPE and optional ENCODING."
1207 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1210 (defun mime-editor/get-contype (tag)
1211 "Return Content-Type (including parameters) of TAG."
1213 (or (string-match mime-editor/single-part-tag-regexp tag)
1214 (string-match mime-editor/multipart-beginning-regexp tag)
1215 (string-match mime-editor/multipart-end-regexp tag)
1217 (substring tag (match-beginning 1) (match-end 1))
1220 (defun mime-editor/get-encoding (tag)
1221 "Return encoding of TAG."
1223 (string-match mime-editor/single-part-tag-regexp tag)
1225 (not (= (match-beginning 3) (match-end 3)))
1226 (substring tag (match-beginning 3) (match-end 3))))
1228 (defun mime-get-parameter (contype parameter)
1229 "For given CONTYPE return value for PARAMETER.
1230 Nil if no such parameter."
1234 (regexp-quote parameter)
1235 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1237 (substring contype (match-beginning 1) (match-end 1))
1238 nil ;No such parameter
1241 (defun mime-editor/set-parameter (contype parameter value)
1242 "For given CONTYPE set PARAMETER to VALUE."
1243 (let (ctype opt-fields)
1244 (if (string-match "\n[^ \t\n\r]+:" contype)
1245 (setq ctype (substring contype 0 (match-beginning 0))
1246 opt-fields (substring contype (match-beginning 0)))
1247 (setq ctype contype)
1252 (regexp-quote parameter)
1253 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1256 (concat (substring ctype 0 (match-beginning 1))
1258 (substring contype (match-end 1))
1260 (concat ctype "; " parameter "=" value opt-fields)
1263 (defun mime-strip-parameters (contype)
1264 "Return primary content-type and subtype without parameters for CONTYPE."
1265 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1266 (substring contype (match-beginning 1) (match-end 1)) nil))
1268 (defun mime-test-content-type (contype type &optional subtype)
1269 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1270 (and (stringp contype)
1273 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1274 (downcase contype))))
1279 (defun mime-find-file-type (file)
1280 "Guess Content-Type, subtype, and parameters from FILE."
1282 (guesses mime-file-types))
1283 (while (and (not guess) guesses)
1284 (if (string-match (car (car guesses)) file)
1285 (setq guess (cdr (car guesses))))
1286 (setq guesses (cdr guesses)))
1290 (defun mime-prompt-for-type ()
1291 "Ask for Content-type."
1293 ;; Repeat until primary content type is specified.
1294 (while (string-equal type "")
1296 (completing-read "What content type: "
1299 'require-match ;Type must be specified.
1302 (if (string-equal type "")
1304 (message "Content type is required.")
1312 (defun mime-prompt-for-subtype (pritype)
1313 "Ask for Content-type subtype of Content-Type PRITYPE."
1314 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1319 "What content subtype: (default " default ") ")
1320 "What content subtype: ")
1321 (cdr (assoc pritype mime-content-types))
1323 'require-match ;Subtype must be specified.
1326 (if (string-equal answer "") default answer)))
1328 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1329 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1330 Optional DELIMITER specifies parameter delimiter (';' by default)."
1331 (let* ((delimiter (or delimiter "; "))
1336 (mime-prompt-for-parameters-1
1338 (cdr (assoc pritype mime-content-types))))))
1341 (if (and (stringp parameters)
1342 (not (string-equal parameters "")))
1343 (concat delimiter parameters)
1344 "" ;"" if no parameters
1347 (defun mime-prompt-for-parameters-1 (optlist)
1348 (apply (function append)
1349 (mapcar (function mime-prompt-for-parameter) optlist)))
1351 (defun mime-prompt-for-parameter (parameter)
1353 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1354 (let* ((prompt (car parameter))
1355 (choices (mapcar (function
1357 (if (consp e) e (list e))))
1359 (default (car (car choices)))
1365 (concat "What " prompt
1367 (if (string-equal default "") "\"\"" default)
1369 choices nil nil ""))
1370 ;; If nothing is selected, use default.
1371 (if (string-equal answer "")
1372 (setq answer default)))
1374 (read-string (concat "What " prompt ": "))))
1375 (cons (if (and answer
1376 (not (string-equal answer "")))
1378 ;; Note: control characters ignored!
1379 (if (string-match mime-tspecials-regexp answer)
1380 (concat "\"" answer "\"") answer)))
1381 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1384 (defun mime-flag-region (from to flag)
1385 "Hides or shows lines from FROM to TO, according to FLAG.
1386 If FLAG is `\\n' (newline character) then text is shown,
1387 while if FLAG is `\\^M' (control-M) the text is hidden."
1388 (let ((buffer-read-only nil) ;Okay even if write protected.
1389 (modp (buffer-modified-p)))
1391 (subst-char-in-region from to
1392 (if (= flag ?\n) ?\^M ?\n)
1394 (set-buffer-modified-p modp))))
1397 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1400 (defvar mime-editor/translate-buffer-hook
1401 '(mime-editor/pgp-enclose-buffer
1402 mime-editor/translate-header
1403 mime-editor/translate-body))
1405 (defun mime-editor/translate-header ()
1406 "Encode the message header into network representation."
1407 (mime/encode-message-header 'code-conversion)
1408 (run-hooks 'mime-editor/translate-header-hook)
1411 (defun mime-editor/translate-buffer ()
1412 "Encode the tagged MIME message in current buffer in MIME compliant message."
1414 (if (catch 'mime-editor/error
1416 (run-hooks 'mime-editor/translate-buffer-hook)
1420 (error "Translation error!")
1423 (defun mime-editor/find-inmost ()
1424 (goto-char (point-min))
1425 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1426 (let ((bb (match-beginning 0))
1428 (type (buffer-substring (match-beginning 1)(match-end 1)))
1430 (setq end-exp (format "--}-<<%s>>\n" type))
1432 (if (re-search-forward end-exp nil t)
1434 (setq eb (match-beginning 0))
1435 (setq ee (match-end 0))
1437 (setq eb (point-max))
1438 (setq ee (point-max))
1440 (narrow-to-region be eb)
1442 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1444 (narrow-to-region (match-beginning 0)(point-max))
1445 (mime-editor/find-inmost)
1448 (list type bb be eb)
1451 (defun mime-editor/process-multipart-1 (boundary)
1452 (let ((ret (mime-editor/find-inmost)))
1454 (let ((type (car ret))
1455 (bb (nth 1 ret))(be (nth 2 ret))
1458 (narrow-to-region bb eb)
1459 (delete-region bb be)
1460 (setq bb (point-min))
1461 (setq eb (point-max))
1464 (if (looking-at mime-editor/multipart-end-regexp)
1465 (let ((beg (match-beginning 0))
1468 (delete-region beg end)
1469 (or (looking-at mime-editor/beginning-tag-regexp)
1471 (insert (concat (mime-make-text-tag) "\n"))
1473 (cond ((string-equal type "quote")
1474 (mime-editor/enquote-region bb eb)
1476 ((string-equal type "signed")
1477 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1478 (mime-editor/sign-pgp-elkins bb eb boundary)
1480 ((eq mime-editor/signing-type 'pgp-kazu)
1481 (mime-editor/sign-pgp-kazu bb eb boundary)
1484 ((string-equal type "encrypted")
1485 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1486 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1488 ((eq mime-editor/encrypting-type 'pgp-kazu)
1489 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1493 (nth 2 (mime-editor/translate-region bb eb
1497 (format "--[[multipart/%s;
1498 boundary=\"%s\"][7bit]]\n"
1503 (defun mime-editor/enquote-region (beg end)
1506 (narrow-to-region beg end)
1508 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1509 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1510 (replace-match (concat "- " (substring tag 1)))
1513 (defun mime-editor/dequote-region (beg end)
1516 (narrow-to-region beg end)
1518 (while (re-search-forward
1519 mime-editor/quoted-single-part-tag-regexp nil t)
1520 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1521 (replace-match (concat "-" (substring tag 2)))
1524 (autoload 'mc-pgp-lookup-key "mc-pgp")
1525 (autoload 'mc-pgp-sign-region "mc-pgp")
1526 (autoload 'mc-pgp-encrypt-region "mc-pgp")
1528 (defun tm:mc-pgp-generic-parser (result)
1529 (let ((ret (mc-pgp-generic-parser result)))
1531 (vector (car ret)(cdr ret))
1534 (defun tm:mc-process-region
1535 (beg end passwd program args parser &optional buffer boundary)
1536 (let ((obuf (current-buffer))
1537 (process-connection-type nil)
1538 mybuf result rgn proc)
1541 (setq mybuf (or buffer (generate-new-buffer " *mailcrypt temp")))
1545 (buffer-disable-undo mybuf)
1547 (apply 'start-process "*PGP*" mybuf program args))
1550 (process-send-string proc (concat passwd "\n"))
1551 (or mc-passwd-timeout (mc-deactivate-passwd t))))
1552 (process-send-region proc beg end)
1553 (process-send-eof proc)
1554 (while (eq 'run (process-status proc))
1555 (accept-process-output proc 5))
1556 (setq result (process-exit-status proc))
1557 ;; Hack to force a status_notify() in Emacs 19.29
1558 (delete-process proc)
1560 (goto-char (point-max))
1561 (if (re-search-backward "\nProcess \\*PGP.*\n\\'" nil t)
1562 (delete-region (match-beginning 0) (match-end 0)))
1563 (goto-char (point-min))
1565 (while (search-forward "\r\n" nil t)
1566 (replace-match "\n"))
1567 ;; Hurm. FIXME; must get better result codes.
1568 (if (stringp result)
1569 (error "%s exited abnormally: '%s'" program result)
1570 (setq rgn (funcall parser result))
1571 ;; If the parser found something, migrate it
1577 (narrow-to-region beg end)
1579 (insert (format "--%s\n" boundary))
1580 (goto-char (point-max))
1581 (insert (format "\n--%s
1582 Content-Type: application/pgp-signature
1583 Content-Transfer-Encoding: 7bit
1586 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1587 (goto-char (point-max))
1588 (insert (format "\n--%s--\n" boundary))
1590 (delete-region beg end)
1592 (insert-buffer-substring mybuf (car rgn) (cdr rgn))
1595 (delete-region (car rgn) (cdr rgn)))))
1596 ;; Return nil on failure and exit code on success
1598 ;; Cleanup even on nonlocal exit
1599 (if (and proc (eq 'run (process-status proc)))
1600 (interrupt-process proc))
1602 (or buffer (null mybuf) (kill-buffer mybuf)))))
1604 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1605 (if (not (boundp 'mc-pgp-user-id))
1608 (let ((process-environment process-environment)
1609 (buffer (get-buffer-create mc-buffer-name))
1611 (parser (function mc-pgp-generic-parser))
1612 (pgp-path mc-pgp-path)
1614 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1618 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1619 (setenv "PGPPASSFD" "0")
1625 (list "+verbose=1" "+language=en"
1626 (format "+clearsig=%s" (if unclear "off" "on"))
1627 "+batchmode" "-u" (cdr key))))
1629 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1631 (message "Signing as %s ..." (car key))
1632 (if (tm:mc-process-region
1633 start end passwd pgp-path args parser buffer boundary)
1637 (goto-char (point-min))
1640 --[[multipart/signed; protocol=\"application/pgp-signature\";
1641 boundary=\"%s\"; micalg=pgp-md5][7bit]]\n" boundary))
1643 (message "Signing as %s ... Done." (car key))
1647 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1650 (narrow-to-region beg end)
1652 (mime-editor/translate-region beg end boundary))
1654 (encoding (nth 1 ret))
1656 (pgp-boundary (concat "pgp-sign-" boundary))
1659 (insert (format "Content-Type: %s\n" ctype))
1661 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1664 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1665 nil nil pgp-boundary)
1666 (throw 'mime-editor/error 'pgp-error)
1670 (defvar mime-editor/encrypt-recipient-fields-list '("To" "cc"))
1672 (defun mime-editor/make-encrypt-recipient-header ()
1673 (let* ((names mime-editor/encrypt-recipient-fields-list)
1675 (std11-field-bodies (cons "From" names)
1676 nil mail-header-separator))
1679 (setq values (cdr values))))
1680 (header (and (stringp from)
1681 (if (string-equal from "")
1683 (format "From: %s\n" from)
1686 (while (and names values)
1687 (let ((name (car names))
1688 (value (car values))
1690 (and (stringp value)
1691 (or (string-equal value "")
1693 (setq header (concat header name ": " value "\n")
1694 recipients (if recipients
1695 (concat recipients " ," value)
1698 (setq names (cdr names)
1699 values (cdr values))
1701 (vector from recipients header)
1704 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1707 (let (from recipients header)
1708 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1709 (setq from (aref ret 0)
1710 recipients (aref ret 1)
1711 header (aref ret 2))
1713 (narrow-to-region beg end)
1715 (mime-editor/translate-region beg end boundary))
1717 (encoding (nth 1 ret))
1719 (pgp-boundary (concat "pgp-" boundary))
1723 (insert (format "Content-Type: %s\n" ctype))
1725 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1729 (let ((mc-pgp-always-sign 'never))
1730 (mc-pgp-encrypt-region
1731 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1732 (point-min) (point-max) from nil)
1734 (throw 'mime-editor/error 'pgp-error)
1737 (insert (format "--[[multipart/encrypted;
1739 protocol=\"application/pgp-encrypted\"][7bit]]
1741 Content-Type: application/pgp-encrypted
1744 Content-Type: application/octet-stream
1745 Content-Transfer-Encoding: 7bit
1747 " pgp-boundary pgp-boundary pgp-boundary))
1748 (goto-char (point-max))
1749 (insert (format "\n--%s--\n" pgp-boundary))
1752 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1755 (narrow-to-region beg end)
1757 (mime-editor/translate-region beg end boundary))
1759 (encoding (nth 1 ret))
1763 (insert (format "Content-Type: %s\n" ctype))
1765 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1768 (or (as-binary-process (mc-pgp-sign-region beg (point-max)))
1769 (throw 'mime-editor/error 'pgp-error)
1773 "--[[application/pgp; format=mime][7bit]]\n")
1777 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1779 (let (from recipients header)
1780 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1781 (setq from (aref ret 0)
1782 recipients (aref ret 1)
1783 header (aref ret 2))
1786 (narrow-to-region beg end)
1788 (mime-editor/translate-region beg end boundary))
1790 (encoding (nth 1 ret))
1795 (insert (format "Content-Type: %s\n" ctype))
1797 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1800 (or (as-binary-process
1801 (mc-pgp-encrypt-region
1802 (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
1805 (throw 'mime-editor/error 'pgp-error)
1809 "--[[application/pgp; format=mime][7bit]]\n")
1813 (defun mime-editor/translate-body ()
1814 "Encode the tagged MIME body in current buffer in MIME compliant message."
1818 (concat mime-multipart-boundary "_"
1819 (replace-space-with-underline (current-time-string))
1823 (while (mime-editor/process-multipart-1
1824 (format "%s-%d" boundary i))
1828 ;; We are interested in message body.
1831 (goto-char (point-min))
1833 (concat "\n" (regexp-quote mail-header-separator)
1834 (if mime-ignore-preceding-spaces
1835 "[ \t\n]*\n" "\n")) nil 'move)
1839 (goto-char (point-max))
1840 (and mime-ignore-trailing-spaces
1841 (re-search-backward "[^ \t\n]\n" beg t)
1844 (setq ret (mime-editor/translate-region
1846 (format "%s-%d" boundary i)))
1848 (mime-editor/dequote-region (point-min)(point-max))
1849 (let ((contype (car ret)) ;Content-Type
1850 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1852 ;; Make primary MIME headers.
1853 (or (mail-position-on-field "Mime-Version")
1854 (insert mime-editor/mime-version-value))
1855 ;; Remove old Content-Type and other fields.
1857 (goto-char (point-min))
1858 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1859 (narrow-to-region (point-min) (point))
1860 (goto-char (point-min))
1861 (mime-delete-field "Content-Type")
1862 (mime-delete-field "Content-Transfer-Encoding"))
1863 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1864 (mail-position-on-field "Content-Type")
1868 (mail-position-on-field "Content-Transfer-Encoding")
1872 (defun mime-editor/translate-single-part-tag (&optional prefix)
1873 (if (re-search-forward mime-editor/single-part-tag-regexp nil t)
1874 (let* ((beg (match-beginning 0))
1876 (tag (buffer-substring beg end))
1878 (delete-region beg end)
1879 (setq contype (mime-editor/get-contype tag))
1880 (setq encoding (mime-editor/get-encoding tag))
1881 (insert (concat prefix "--" boundary "\n"))
1883 (narrow-to-region (point)(point))
1884 (insert "Content-Type: " contype "\n")
1886 (insert "Content-Transfer-Encoding: " encoding "\n"))
1887 (mime/encode-message-header)
1891 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1894 (concat mime-multipart-boundary "_"
1895 (replace-space-with-underline (current-time-string))))
1899 (narrow-to-region beg end)
1900 (let ((tag nil) ;MIME tag
1901 (contype nil) ;Content-Type
1902 (encoding nil) ;Content-Transfer-Encoding
1903 (nparts 0)) ;Number of body parts
1904 ;; Normalize the body part by inserting appropriate message
1905 ;; tags for every message contents.
1906 (mime-editor/normalize-body)
1907 ;; Counting the number of Content-Type.
1908 (goto-char (point-min))
1909 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1910 (setq nparts (1+ nparts)))
1911 ;; Begin translation.
1913 ((and (<= nparts 1)(not multipart))
1914 ;; It's a singular message.
1915 (goto-char (point-min))
1916 (while (re-search-forward
1917 mime-editor/single-part-tag-regexp nil t)
1919 (buffer-substring (match-beginning 0) (match-end 0)))
1920 (delete-region (match-beginning 0) (1+ (match-end 0)))
1921 (setq contype (mime-editor/get-contype tag))
1922 (setq encoding (mime-editor/get-encoding tag))
1925 ;; It's a multipart message.
1926 (goto-char (point-min))
1927 (and (mime-editor/translate-single-part-tag)
1928 (while (mime-editor/translate-single-part-tag "\n"))
1930 ;; Define Content-Type as "multipart/mixed".
1932 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1933 ;; Content-Transfer-Encoding must be "7bit".
1934 ;; The following encoding can be `nil', but is
1935 ;; specified as is since there is no way that a user
1937 (setq encoding "7bit")
1938 ;; Insert the trailer.
1939 (goto-char (point-max))
1940 (insert "\n--" boundary "--\n")
1942 (list contype encoding boundary nparts)
1945 (defun mime-editor/normalize-body ()
1946 "Normalize the body part by inserting appropriate message tags."
1947 ;; Insert the first MIME tags if necessary.
1948 (goto-char (point-min))
1949 (if (not (looking-at mime-editor/single-part-tag-regexp))
1950 (insert (mime-make-text-tag) "\n"))
1951 ;; Check each tag, and add new tag or correct it if necessary.
1952 (goto-char (point-min))
1953 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1954 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1955 (contype (mime-editor/get-contype tag))
1956 (charset (mime-get-parameter contype "charset"))
1957 (encoding (mime-editor/get-encoding tag)))
1958 ;; Remove extra whitespaces after the tag.
1959 (if (looking-at "[ \t]+$")
1960 (delete-region (match-beginning 0) (match-end 0)))
1962 (end (mime-editor/content-end))
1964 (if (= end (point-max))
1967 (or (looking-at mime-editor/beginning-tag-regexp)
1969 (insert (mime-make-text-tag) "\n")
1971 (visible-region beg end)
1975 ((mime-test-content-type contype "message")
1976 ;; Content-type "message" should be sent as is.
1979 ((mime-test-content-type contype "text")
1980 ;; Define charset for text if necessary.
1981 (setq charset (if charset
1982 (intern (downcase charset))
1983 (mime-editor/choose-charset)))
1984 (mime-editor/define-charset charset)
1985 (cond ((string-equal contype "text/x-rot13-47")
1989 (goto-char (mime-editor/content-end))
1992 ((string-equal contype "text/enriched")
1997 (end (mime-editor/content-end))
1999 ;; Patch for hard newlines
2002 ;; (while (search-forward "\n" end t)
2003 ;; (put-text-property (match-beginning 0)
2006 ;; End patch for hard newlines
2007 (enriched-encode beg end)
2009 (if (search-forward "\n\n")
2010 (delete-region beg (match-end 0))
2013 ;; Point is now on current tag.
2014 ;; Define encoding and encode text if necessary.
2015 (or encoding ;Encoding is not specified.
2019 mime-editor/charset-default-encoding-alist)
2021 (beg (mime-editor/content-beginning))
2023 (encode-mime-charset-region beg (mime-editor/content-end)
2025 (mime-encode-region beg (mime-editor/content-end) encoding)
2026 (mime-editor/define-encoding encoding)
2028 (goto-char (mime-editor/content-end))
2030 ((null encoding) ;Encoding is not specified.
2031 ;; Application, image, audio, video, and any other
2032 ;; unknown content-type without encoding should be
2034 (let* ((encoding "base64") ;Encode in BASE64 by default.
2035 (beg (mime-editor/content-beginning))
2036 (end (mime-editor/content-end))
2037 (body (buffer-substring beg end))
2039 (mime-encode-region beg end encoding)
2040 (mime-editor/define-encoding encoding))
2045 (defun mime-delete-field (field)
2046 "Delete header FIELD."
2047 (let ((regexp (format "^%s:[ \t]*" field)))
2048 (goto-char (point-min))
2049 (while (re-search-forward regexp nil t)
2050 (delete-region (match-beginning 0)
2051 (progn (forward-line 1) (point)))
2056 ;;; Platform dependent functions
2059 ;; Sun implementations
2061 (defun mime-editor/voice-recorder-for-sun (encoding)
2062 "Record voice in a buffer using Sun audio device,
2063 and insert data encoded as ENCODING. [tm-edit.el]"
2064 (message "Start the recording on %s. Type C-g to finish the recording..."
2066 (mime-insert-encoded-file "/dev/audio" encoding)
2070 ;;; @ Other useful commands.
2073 ;; Message forwarding commands as content-type "message/rfc822".
2075 (defun mime-editor/insert-message (&optional message)
2077 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2078 (if (and inserter (fboundp inserter))
2080 (mime-editor/insert-tag "message" "rfc822")
2081 (funcall inserter message)
2083 (message "Sorry, I don't have message inserter for your MUA.")
2086 (defun mime-editor/insert-mail (&optional message)
2088 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2089 (if (and inserter (fboundp inserter))
2091 (mime-editor/insert-tag "message" "rfc822")
2092 (funcall inserter message)
2094 (message "Sorry, I don't have mail inserter for your MUA.")
2097 (defun mime-editor/inserted-message-filter ()
2100 (let ((header-start (point))
2101 (case-fold-search t)
2104 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2105 (if (re-search-forward "^$" (mark t))
2106 (narrow-to-region header-start (match-beginning 0))
2108 (goto-char header-start)
2109 (while (and (re-search-forward
2110 mime-editor/yank-ignored-field-regexp nil t)
2111 (setq beg (match-beginning 0))
2112 (setq end (1+ (std11-field-end)))
2114 (delete-region beg end)
2119 ;;; @ multipart enclosure
2122 (defun mime-editor/enclose-region (type beg end)
2125 (let ((current (point)))
2127 (narrow-to-region beg end)
2128 (insert (format "--<<%s>>-{\n" type))
2129 (goto-char (point-max))
2130 (insert (format "--}-<<%s>>\n" type))
2131 (goto-char (point-max))
2133 (or (looking-at mime-editor/beginning-tag-regexp)
2135 (insert (mime-make-text-tag) "\n")
2139 (defun mime-editor/enclose-quote-region (beg end)
2141 (mime-editor/enclose-region "quote" beg end)
2144 (defun mime-editor/enclose-mixed-region (beg end)
2146 (mime-editor/enclose-region "mixed" beg end)
2149 (defun mime-editor/enclose-parallel-region (beg end)
2151 (mime-editor/enclose-region "parallel" beg end)
2154 (defun mime-editor/enclose-digest-region (beg end)
2156 (mime-editor/enclose-region "digest" beg end)
2159 (defun mime-editor/enclose-alternative-region (beg end)
2161 (mime-editor/enclose-region "alternative" beg end)
2164 (defun mime-editor/enclose-signed-region (beg end)
2166 (if mime-editor/signing-type
2167 (mime-editor/enclose-region "signed" beg end)
2168 (message "Please specify signing type.")
2171 (defun mime-editor/enclose-encrypted-region (beg end)
2173 (if mime-editor/signing-type
2174 (mime-editor/enclose-region "encrypted" beg end)
2175 (message "Please specify encrypting type.")
2178 (defun mime-editor/insert-key (&optional arg)
2179 "Insert a pgp public key."
2181 (mime-editor/insert-tag "application" "pgp-keys")
2182 (mime-editor/define-encoding "7bit")
2183 (mc-insert-public-key)
2190 (defun mime-editor/set-split (arg)
2193 (y-or-n-p "Do you want to enable split?")
2195 (setq mime-editor/split-message arg)
2197 (message "This message is enabled to split.")
2198 (message "This message is not enabled to split.")
2201 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2202 "Toggle transfer-level is 7bit or 8bit through.
2204 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2206 (if (numberp transfer-level)
2207 (setq mime-editor/transfer-level transfer-level)
2208 (if (< mime-editor/transfer-level 8)
2209 (setq mime-editor/transfer-level 8)
2210 (setq mime-editor/transfer-level 7)
2212 (setq mime-editor/charset-default-encoding-alist
2213 (mime-editor/make-charset-default-encoding-alist
2214 mime-editor/transfer-level))
2215 (message (format "Current transfer-level is %d bit"
2216 mime-editor/transfer-level))
2217 (setq mime-editor/transfer-level-string
2218 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2219 (force-mode-line-update)
2222 (defun mime-editor/set-transfer-level-7bit ()
2224 (mime-editor/toggle-transfer-level 7)
2227 (defun mime-editor/set-transfer-level-8bit ()
2229 (mime-editor/toggle-transfer-level 8)
2236 (defun mime-editor/set-sign (arg)
2239 (y-or-n-p "Do you want to sign?")
2242 (if mime-editor/signing-type
2244 (setq mime-editor/pgp-processing 'sign)
2245 (message "This message will be signed.")
2247 (message "Please specify signing type.")
2249 (if (eq mime-editor/pgp-processing 'sign)
2250 (setq mime-editor/pgp-processing nil)
2252 (message "This message will not be signed.")
2255 (defun mime-editor/set-encrypt (arg)
2258 (y-or-n-p "Do you want to encrypt?")
2261 (if mime-editor/encrypting-type
2263 (setq mime-editor/pgp-processing 'encrypt)
2264 (message "This message will be encrypt.")
2266 (message "Please specify encrypting type.")
2268 (if (eq mime-editor/pgp-processing 'encrypt)
2269 (setq mime-editor/pgp-processing nil)
2271 (message "This message will not be encrypt.")
2274 (defvar mime-editor/pgp-processing nil)
2275 (make-variable-buffer-local 'mime-editor/pgp-processing)
2277 (defun mime-editor/pgp-enclose-buffer ()
2278 (let ((beg (save-excursion
2279 (goto-char (point-min))
2280 (if (search-forward (concat "\n" mail-header-separator "\n"))
2286 (cond ((eq mime-editor/pgp-processing 'sign)
2287 (mime-editor/enclose-signed-region beg end)
2289 ((eq mime-editor/pgp-processing 'encrypt)
2290 (mime-editor/enclose-encrypted-region beg end)
2298 (defun mime-editor/insert-partial-header
2299 (fields subject id number total separator)
2301 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2302 (insert (format "Mime-Version: 1.0 (split by %s)\n"
2303 mime-editor/version-name))
2305 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2306 id number total separator))
2309 (defun mime-editor/split-and-send
2310 (&optional cmd lines mime-editor/message-max-length)
2314 (count-lines (point-min) (point-max)))
2316 (or mime-editor/message-max-length
2317 (setq mime-editor/message-max-length
2318 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2319 mime-editor/message-default-max-length))
2321 (let* ((mime-editor/draft-file-name
2322 (or (buffer-file-name)
2324 (expand-file-name "tm-draft" mime/tmp-dir))))
2325 (separator mail-header-separator)
2327 (replace-space-with-underline (current-time-string))
2328 "@" (system-name) "\"")))
2329 (run-hooks 'mime-editor/before-split-hook)
2330 (let ((the-buf (current-buffer))
2331 (copy-buf (get-buffer-create " *Original Message*"))
2332 (header (rfc822/get-header-string-except
2333 mime-editor/split-ignored-field-regexp separator))
2334 (subject (mail-fetch-field "subject"))
2335 (total (+ (/ lines mime-editor/message-max-length)
2336 (if (> (mod lines mime-editor/message-max-length) 0)
2342 mime-editor/split-message-sender-alist))
2344 (mime-editor/partial-number 1)
2347 (set-buffer copy-buf)
2349 (insert-buffer the-buf)
2351 (if (re-search-forward
2352 (concat "^" (regexp-quote separator) "$") nil t)
2353 (let ((he (match-beginning 0)))
2355 (narrow-to-region (point-min) he)
2357 (goto-char (point-min))
2358 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
2359 (delete-region (match-beginning 0)
2360 (1+ (std11-field-end)))
2362 (while (< mime-editor/partial-number total)
2365 (set-buffer copy-buf)
2366 (setq data (buffer-substring
2369 (goto-line mime-editor/message-max-length)
2372 (delete-region (point-min)(point))
2374 (mime-editor/insert-partial-header
2375 header subject id mime-editor/partial-number total separator)
2378 (message (format "Sending %d/%d..."
2379 mime-editor/partial-number total))
2380 (call-interactively command)
2381 (message (format "Sending %d/%d... done"
2382 mime-editor/partial-number total))
2384 (setq mime-editor/partial-number
2385 (1+ mime-editor/partial-number))
2389 (set-buffer copy-buf)
2390 (setq data (buffer-string))
2393 (mime-editor/insert-partial-header
2394 header subject id mime-editor/partial-number total separator)
2397 (message (format "Sending %d/%d..."
2398 mime-editor/partial-number total))
2399 (message (format "Sending %d/%d... done"
2400 mime-editor/partial-number total))
2404 (defun mime-editor/maybe-split-and-send (&optional cmd)
2406 (run-hooks 'mime-editor/before-send-hook)
2407 (let ((mime-editor/message-max-length
2408 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2409 mime-editor/message-default-max-length))
2410 (lines (count-lines (point-min) (point-max)))
2412 (if (and (> lines mime-editor/message-max-length)
2413 mime-editor/split-message)
2414 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2418 ;;; @ preview message
2421 (defun mime-editor/preview-message ()
2422 "preview editing MIME message. [tm-edit.el]"
2424 (let* ((str (buffer-string))
2425 (separator mail-header-separator)
2426 (the-buf (current-buffer))
2427 (buf-name (buffer-name))
2428 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2429 (buf (get-buffer temp-buf-name))
2433 (switch-to-buffer buf)
2436 (setq buf (get-buffer-create temp-buf-name))
2437 (switch-to-buffer buf)
2440 (setq major-mode 'mime/temporary-message-mode)
2441 (make-local-variable 'mail-header-separator)
2442 (setq mail-header-separator separator)
2443 (make-local-variable 'mime/editing-buffer)
2444 (setq mime/editing-buffer the-buf)
2446 (run-hooks 'mime-editor/translate-hook)
2447 (mime-editor/translate-buffer)
2448 (goto-char (point-min))
2449 (if (re-search-forward
2450 (concat "^" (regexp-quote separator) "$"))
2456 (defun mime-editor/quitting-method ()
2457 (let ((temp mime::preview/article-buffer)
2459 (mime-viewer/kill-buffer)
2461 (setq buf mime/editing-buffer)
2463 (switch-to-buffer buf)
2466 (set-alist 'mime-viewer/quitting-method-alist
2467 'mime/temporary-message-mode
2468 (function mime-editor/quitting-method)
2474 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2475 ;; Mon, 10 Apr 1995 20:03:07 +0900
2477 (defvar mime-editor/draft-header-separator-alist
2478 '((news-reply-mode . mail-header-separator)
2479 (mh-letter-mode . mail-header-separator)
2482 (defvar mime::article/draft-header-separator nil)
2484 (defun mime-editor/draft-preview ()
2486 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2487 (or (stringp sep) (setq sep (eval sep)))
2488 (make-variable-buffer-local 'mime::article/draft-header-separator)
2489 (goto-char (point-min))
2491 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2492 (setq mime::article/draft-header-separator
2493 (buffer-substring (match-beginning 0) (match-end 0)))
2495 (mime/viewer-mode (current-buffer))
2496 (pop-to-buffer (current-buffer))
2499 (defun mime-viewer::quitting-method/draft-preview ()
2500 (let ((mother mime::preview/mother-buffer))
2502 (switch-to-buffer mother)
2503 (goto-char (point-min))
2507 (regexp-quote mime::article/draft-header-separator)
2511 (insert mime::article/draft-header-separator)
2512 (set-buffer-modified-p (buffer-modified-p))
2514 (mime-viewer/kill-buffer)
2515 (pop-to-buffer mother)
2518 (set-alist 'mime-viewer/quitting-method-alist
2520 (function mime-viewer::quitting-method/draft-preview)
2523 (set-alist 'mime-viewer/quitting-method-alist
2525 (function mime-viewer::quitting-method/draft-preview)
2532 (defun mime-editor::edit-again (code-conversion)
2534 (goto-char (point-min))
2535 (let ((ctl (mime/Content-Type)))
2537 (let ((ctype (car ctl))
2540 (if (string-match "/" ctype)
2542 (setq type (substring ctype 0 (match-beginning 0)))
2543 (setq stype (substring ctype (match-end 0)))
2548 ((string-equal type "multipart")
2549 (let* ((boundary (assoc-value "boundary" params))
2551 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2553 (re-search-forward boundary-pat nil t)
2554 (let ((bb (match-beginning 0)) eb tag)
2555 (setq tag (format "\n--<<%s>>-{\n" stype))
2558 (setq bb (+ bb (length tag)))
2560 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2562 (setq eb (match-beginning 0))
2563 (replace-match (format "--}-<<%s>>\n" stype))
2565 (narrow-to-region bb eb)
2566 (goto-char (point-min))
2567 (while (re-search-forward boundary-pat nil t)
2568 (let ((beg (match-beginning 0))
2570 (delete-region beg (match-end 0))
2572 (if (re-search-forward boundary-pat nil t)
2573 (setq end (match-beginning 0))
2574 (setq end (point-max))
2577 (narrow-to-region beg end)
2578 (mime-editor::edit-again code-conversion)
2579 (goto-char (point-max))
2582 (goto-char (point-min))
2583 (or (= (point-min) 1)
2584 (delete-region (point-min)
2585 (if (search-forward "\n\n" nil t)
2593 (mapconcat (function
2595 (if (string-equal (car attr)
2598 (setq charset (cdr attr))
2600 (concat ";" (car attr)
2608 (if (re-search-forward
2609 "Content-Transfer-Encoding:" nil t)
2610 (let ((beg (match-beginning 0))
2611 (hbeg (match-end 0))
2612 (end (std11-field-end)))
2614 (eliminate-top-spaces
2615 (rfc822/unfolding-string
2616 (buffer-substring hbeg end))))
2617 (if (or charset (string-equal type "text"))
2619 (delete-region beg (1+ end))
2620 (goto-char (point-min))
2621 (if (search-forward "\n\n" nil t)
2624 (match-end 0)(point-max) encoding)
2628 (if (or code-conversion encoded)
2629 (decode-mime-charset-region
2630 (point-min)(point-max)
2631 (or charset default-mime-charset))
2634 (if (re-search-forward "^$" nil t)
2638 (if (= (point-min) 1)
2644 (concat type "/" stype pstr) encoding)))
2646 (delete-region (point-min) he)
2649 (concat type "/" stype pstr) encoding))
2653 (decode-mime-charset-region (point-min) (point-max)
2654 default-mime-charset)
2658 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2660 (mime-editor::edit-again code-conversion)
2661 (goto-char (point-min))
2665 (if (re-search-forward
2666 (concat "^\\(" (regexp-quote mail-header-separator) "\\)?$")
2671 (goto-char (point-min))
2672 (while (re-search-forward
2673 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2674 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2677 (and (re-search-forward "^$")
2678 (replace-match mail-header-separator)
2690 (run-hooks 'tm-edit-load-hook)
2692 ;;; tm-edit.el ends here