1 ;;; tm-edit.el --- Simple MIME Composer for GNU Emacs
3 ;; Copyright (C) 1993,1994,1995,1996,1997 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.102 $
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 2045, 2046, 2047, 2048 and 2049).
33 ;; All messages in this mode are composed in the tagged MIME format,
34 ;; that are described in the following examples. The messages
35 ;; composed in the tagged MIME format are automatically translated
36 ;; into a MIME 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]. Mule is required for reading the such
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)
122 (defconst mime-editor/RCS-ID
123 "$Id: tm-edit.el,v 7.102 1997/01/30 11:31:36 morioka Exp $")
125 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
127 (defconst mime-editor/version-name
128 (concat "tm-edit " mime-editor/version))
134 (defvar mime-prefix "\C-c\C-x"
135 "*Keymap prefix for MIME commands.")
137 (defvar mime-ignore-preceding-spaces nil
138 "*Ignore preceding white spaces if non-nil.")
140 (defvar mime-ignore-trailing-spaces nil
141 "*Ignore trailing white spaces if non-nil.")
143 (defvar mime-ignore-same-text-tag t
144 "*Ignore preceding text content-type tag that is same with new one.
145 If non-nil, the text tag is not inserted unless something different.")
147 (defvar mime-auto-hide-body t
148 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
150 (defvar mime-editor/voice-recorder
151 (function mime-editor/voice-recorder-for-sun)
152 "*Function to record a voice message and encode it. [tm-edit.el]")
154 (defvar mime/editor-mode-hook nil
155 "*Hook called when enter MIME mode.")
157 (defvar mime-editor/translate-hook nil
158 "*Hook called before translating into a MIME compliant message.
159 To insert a signature file automatically, call the function
160 `mime-editor/insert-signature' from this hook.")
162 (defvar mime-editor/exit-hook nil
163 "*Hook called when exit MIME mode.")
165 (defvar mime-content-types
167 ;; Charset parameter need not to be specified, since it is
168 ;; defined automatically while translation.
170 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
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")
190 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
191 ("directory" "/pub/GNU/elisp/mime")
193 ("mode" "image" "ascii" "local8"))
198 ("mode" "image" "ascii" "local8"))
199 ("tftp" ("site") ("name"))
200 ("afs" ("site") ("name"))
201 ("local-file" ("site") ("name"))
202 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
207 ("octet-stream" ("type" "" "tar" "shar"))
209 ("x-kiss" ("x-cnf")))
222 "*Alist of content-type, subtype, parameters and its values.")
224 (defvar mime-file-types
226 "text" "richtext" nil
234 "application" "postscript" nil
236 "attachment" (("filename" . file))
241 "inline" (("filename" . file))
246 "inline" (("filename" . file))
251 "inline" (("filename" . file))
256 "inline" (("filename" . file))
261 "inline" (("filename" . file))
266 "inline" (("filename" . file))
271 "inline" (("filename" . file))
276 "attachment" (("filename" . file))
281 "attachment" (("filename" . file))
284 "application" "octet-stream" (("type" . "emacs-lisp"))
286 "attachment" (("filename" . file))
289 "application" "octet-stream" (("type" . "common-lisp"))
291 "attachment" (("filename" . file))
294 "application" "octet-stream" (("type" . "tar+gzip"))
296 "attachment" (("filename" . file))
299 "application" "octet-stream" (("type" . "tar+gzip"))
301 "attachment" (("filename" . file))
304 "application" "octet-stream" (("type" . "tar+compress"))
306 "attachment" (("filename" . file))
309 "application" "octet-stream" (("type" . "tar+compress"))
311 "attachment" (("filename" . file))
314 "application" "octet-stream" (("type" . "gzip"))
316 "attachment" (("filename" . file))
319 "application" "octet-stream" (("type" . "compress"))
321 "attachment" (("filename" . file))
324 "application" "octet-stream" (("type" . "lha"))
326 "attachment" (("filename" . file))
329 "application" "zip" nil
331 "attachment" (("filename" . file))
334 "application" "octet-stream" (("type" . "patch"))
336 "attachment" (("filename" . file))
339 "application" "octet-stream" (("type" . "patch"))
341 "attachment" (("filename" . file))
344 "text" "plain" nil nil)
346 "application" "octet-stream" nil
348 "attachment" (("filename" . file))
351 "*Alist of file name, types, parameters, and default encoding.
352 If encoding is nil, it is determined from its contents.")
354 ;;; @@ about charset, encoding and transfer-level
357 (defvar mime-editor/transfer-level 7
358 "*A number of network transfer level. It should be bigger than 7.")
359 (make-variable-buffer-local 'mime-editor/transfer-level)
361 (defvar mime-editor/transfer-level-string
362 (mime/encoding-name mime-editor/transfer-level 'not-omit)
363 "*A string formatted version of mime/defaul-transfer-level")
364 (make-variable-buffer-local 'mime-editor/transfer-level-string)
366 (defun mime-editor/make-charset-default-encoding-alist (transfer-level)
368 (lambda (charset-type)
369 (let ((charset (car charset-type))
370 (type (nth 1 charset-type))
371 (encoding (nth 2 charset-type))
373 (if (<= type transfer-level)
374 (cons charset (mime/encoding-name type))
375 (cons charset encoding)
377 mime-charset-type-list))
379 (defvar mime-editor/charset-default-encoding-alist
380 (mime-editor/make-charset-default-encoding-alist mime-editor/transfer-level))
381 (make-variable-buffer-local 'mime-editor/charset-default-encoding-alist)
383 ;;; @@ about message inserting
386 (defvar mime-editor/yank-ignored-field-list
387 '("Received" "Approved" "Path" "Replied" "Status"
388 "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
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-lines 1000
408 "*Default maximum lines of a message. [tm-edit.el]")
410 (defvar mime-editor/message-max-lines-alist
411 '((news-reply-mode . 500))
412 "Alist of major-mode vs maximum lines of a message.
413 If it is not specified for a major-mode,
414 `mime-editor/message-default-max-lines' is used. [tm-edit.el]")
416 (defconst mime-editor/split-ignored-field-regexp
417 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
419 (defvar mime-editor/split-blind-field-regexp
420 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
422 (defvar mime-editor/split-message-sender-alist nil)
424 (defvar mime-editor/news-reply-mode-server-running nil)
430 (defvar mime-editor/signing-type 'pgp-elkins
431 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
433 (defvar mime-editor/encrypting-type 'pgp-elkins
434 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
436 (defvar mime-editor/pgp-sign-function 'tm:mc-pgp-sign-region)
437 (defvar mime-editor/pgp-encrypt-function 'tm:mc-pgp-encrypt-region)
438 (defvar mime-editor/traditional-pgp-sign-function 'mc-pgp-sign-region)
439 (defvar mime-editor/pgp-insert-public-key-function 'mc-insert-public-key)
441 (autoload mime-editor/pgp-sign-function "tm-edit-mc")
442 (autoload mime-editor/pgp-encrypt-function "tm-edit-mc")
443 (autoload mime-editor/traditional-pgp-sign-function "mc-pgp")
444 (autoload mime-editor/pgp-insert-public-key-function "mc-toplev")
450 (defconst mime-editor/single-part-tag-regexp
451 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
452 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
454 (defconst mime-editor/quoted-single-part-tag-regexp
455 (concat "- " (substring mime-editor/single-part-tag-regexp 1)))
457 (defconst mime-editor/multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
459 (defconst mime-editor/multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
461 (defconst mime-editor/beginning-tag-regexp
462 (regexp-or mime-editor/single-part-tag-regexp
463 mime-editor/multipart-beginning-regexp))
465 (defconst mime-editor/end-tag-regexp
466 (regexp-or mime-editor/single-part-tag-regexp
467 mime-editor/multipart-end-regexp))
469 (defconst mime-editor/tag-regexp
470 (regexp-or mime-editor/single-part-tag-regexp
471 mime-editor/multipart-beginning-regexp
472 mime-editor/multipart-end-regexp))
474 (defvar mime-tag-format "--[[%s]]"
475 "*Control-string making a MIME tag.")
477 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
478 "*Control-string making a MIME tag with encoding.")
480 ;;; @@ multipart boundary
483 (defvar mime-multipart-boundary "Multipart"
484 "*Boundary of a multipart message.")
487 ;;; @@ buffer local variables
490 (defvar mime/editor-mode-old-local-map nil)
491 (defvar mime/editing-buffer nil)
497 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
498 "*Specify MIME tspecials.
499 Tspecials means any character that matches with it in header must be quoted.")
501 (defconst mime-editor/mime-version-value
502 (concat "1.0 (generated by " mime-editor/version-name ")")
503 "MIME version number.")
505 (defconst mime-editor/mime-map (make-sparse-keymap)
506 "Keymap for MIME commands.")
508 ;;; @ keymap and menu
511 (defvar mime/editor-mode-flag nil)
512 (make-variable-buffer-local 'mime/editor-mode-flag)
514 (defun mime-editor/define-keymap (keymap)
515 "Add mime-editor commands to KEYMAP."
516 (if (not (keymapp keymap))
518 (define-key keymap "\C-t" 'mime-editor/insert-text)
519 (define-key keymap "\C-i" 'mime-editor/insert-file)
520 (define-key keymap "\C-e" 'mime-editor/insert-external)
521 (define-key keymap "\C-v" 'mime-editor/insert-voice)
522 (define-key keymap "\C-y" 'mime-editor/insert-message)
523 (define-key keymap "\C-m" 'mime-editor/insert-mail)
524 (define-key keymap "\C-w" 'mime-editor/insert-signature)
525 (define-key keymap "\C-s" 'mime-editor/insert-signature)
526 (define-key keymap "\C-k" 'mime-editor/insert-key)
527 (define-key keymap "t" 'mime-editor/insert-tag)
528 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
529 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
530 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
531 (define-key keymap "d" 'mime-editor/enclose-digest-region)
532 (define-key keymap "s" 'mime-editor/enclose-signed-region)
533 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
534 (define-key keymap "q" 'mime-editor/enclose-quote-region)
535 (define-key keymap "7" 'mime-editor/set-transfer-level-7bit)
536 (define-key keymap "8" 'mime-editor/set-transfer-level-8bit)
537 (define-key keymap "/" 'mime-editor/set-split)
538 (define-key keymap "v" 'mime-editor/set-sign)
539 (define-key keymap "h" 'mime-editor/set-encrypt)
540 (define-key keymap "\C-p" 'mime-editor/preview-message)
541 (define-key keymap "\C-z" 'mime-editor/exit)
542 (define-key keymap "?" 'mime-editor/help)
545 (mime-editor/define-keymap mime-editor/mime-map)
547 (defun mime-editor/toggle-mode ()
549 (if mime/editor-mode-flag
550 (mime-editor/exit 'nomime)
554 (cond (running-xemacs
555 (defconst mime-editor/minor-mime-map nil "Keymap for MIME commands.")
556 (or mime-editor/minor-mime-map
558 (setq mime-editor/minor-mime-map
559 (make-sparse-keymap 'mime-editor/minor-mime-map))
561 mime-editor/minor-mime-map mime-prefix mime-editor/mime-map)
563 (add-minor-mode 'mime/editor-mode-flag
564 '((" MIME-Edit " mime-editor/transfer-level-string))
565 mime-editor/minor-mime-map
567 'mime-editor/toggle-mode)
570 (set-alist 'minor-mode-alist
571 'mime/editor-mode-flag
572 '((" MIME-Edit " mime-editor/transfer-level-string))))
575 (defconst mime-editor/menu-title "MIME-Edit")
577 (defconst mime-editor/menu-list
578 '((mime-help "Describe MIME editor mode" mime-editor/help)
579 (file "Insert File" mime-editor/insert-file)
580 (external "Insert External" mime-editor/insert-external)
581 (voice "Insert Voice" mime-editor/insert-voice)
582 (message "Insert Message" mime-editor/insert-message)
583 (mail "Insert Mail" mime-editor/insert-mail)
584 (signature "Insert Signature" mime-editor/insert-signature)
585 (text "Insert Text" mime-editor/insert-text)
586 (tag "Insert Tag" mime-editor/insert-tag)
587 (alternative "Enclose as alternative"
588 mime-editor/enclose-alternative-region)
589 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
590 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
591 (digest "Enclose as digest" mime-editor/enclose-digest-region)
592 (signed "Enclose as signed" mime-editor/enclose-signed-region)
593 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
594 (quote "Verbatim region" mime-editor/enclose-quote-region)
595 (key "Insert Public Key" mime-editor/insert-key)
596 (split "About split" mime-editor/set-split)
597 (sign "About sign" mime-editor/set-sign)
598 (encrypt "About encryption" mime-editor/set-encrypt)
599 (preview "Preview Message" mime-editor/preview-message)
600 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
602 "MIME-edit menubar entry.")
604 (defun mime-editor/define-menu-for-emacs19 ()
605 "Define menu for Emacs 19."
606 (define-key (current-local-map) [menu-bar mime-edit]
607 (cons mime-editor/menu-title
608 (make-sparse-keymap mime-editor/menu-title)))
611 (define-key (current-local-map)
612 (vector 'menu-bar 'mime-edit (car item))
613 (cons (nth 1 item)(nth 2 item))
616 (reverse mime-editor/menu-list)
619 ;;; modified by Pekka Marjola <pema@iki.fi>
620 ;;; 1995/9/5 (c.f. [tm-en:69])
621 (defun mime-editor/define-menu-for-xemacs ()
622 "Define menu for Emacs 19."
623 (cond ((featurep 'menubar)
624 (make-local-variable 'current-menubar)
625 (set-buffer-menubar current-menubar)
627 (cons mime-editor/menu-title
630 (vector (nth 1 item)(nth 2 item)
631 mime/editor-mode-flag)
633 mime-editor/menu-list)))
636 ;;; modified by Steven L. Baur <steve@miranova.com>
637 ;;; 1995/12/6 (c.f. [tm-en:209])
638 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
639 (setq mime-editor/popup-menu-for-xemacs
640 (append '("MIME Commands" "---")
641 (mapcar (function (lambda (item)
645 mime-editor/menu-list)))
654 (defun mime/editor-mode ()
655 "MIME minor mode for editing the tagged MIME message.
657 In this mode, basically, the message is composed in the tagged MIME
658 format. The message tag looks like:
660 --[[text/plain; charset=ISO-2022-JP][7bit]]
662 The tag specifies the MIME content type, subtype, optional parameters
663 and transfer encoding of the message following the tag. Messages
664 without any tag are treated as `text/plain' by default. Charset and
665 transfer encoding are automatically defined unless explicitly
666 specified. Binary messages such as audio and image are usually hidden.
667 The messages in the tagged MIME format are automatically translated
668 into a MIME compliant message when exiting this mode.
670 Available charsets depend on Emacs version being used. The following
671 lists the available charsets of each emacs.
673 EMACS 18: US-ASCII is only available.
674 NEmacs: US-ASCII and ISO-2022-JP are available.
675 EMACS 19: US-ASCII and ISO-8859-1 (or other charset) are available.
676 XEmacs 19: US-ASCII and ISO-8859-1 (or other charset) are available.
677 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
678 ISO-2022-JP, ISO-2022-JP-2, ISO-2022-KR, BIG5 and
679 ISO-2022-INT-1 are available.
681 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
682 be used to represent multilingual text in intermixed manner. Any
683 languages that has no registered charset are represented as either
684 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
686 If you want to use non-ISO-8859-1 charset in EMACS 19 or XEmacs 19,
687 please set variable `default-mime-charset'. This variable must be
688 symbol of which name is a MIME charset.
690 If you want to add more charsets in mule, please set variable
691 `charsets-mime-charset-alist'. This variable must be alist of which
692 key is list of leading-char/charset and value is symbol of MIME
693 charset. (leading-char is a term of MULE 1.* and 2.*. charset is a
694 term of XEmacs/mule, mule merged EMACS and MULE 3.*) If name of
695 coding-system is different as MIME charset, please set variable
696 `mime-charset-coding-system-alist'. This variable must be alist of
697 which key is MIME charset and value is coding-system.
699 Following commands are available in addition to major mode commands:
702 \\[mime-editor/insert-text] insert a text message.
703 \\[mime-editor/insert-file] insert a (binary) file.
704 \\[mime-editor/insert-external] insert a reference to external body.
705 \\[mime-editor/insert-voice] insert a voice message.
706 \\[mime-editor/insert-message] insert a mail or news message.
707 \\[mime-editor/insert-mail] insert a mail message.
708 \\[mime-editor/insert-signature] insert a signature file at end.
709 \\[mime-editor/insert-key] insert PGP public key.
710 \\[mime-editor/insert-tag] insert a new MIME tag.
712 \[make enclosure (maybe multipart)\]
713 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
714 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
715 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
716 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
717 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
718 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
719 \\[mime-editor/enclose-quote-region] enclose as verbose mode (to avoid to expand tags)
722 \\[mime-editor/set-transfer-level-7bit] set transfer-level as 7.
723 \\[mime-editor/set-transfer-level-8bit] set transfer-level as 8.
724 \\[mime-editor/set-split] set message splitting mode.
725 \\[mime-editor/set-sign] set PGP-sign mode.
726 \\[mime-editor/set-encrypt] set PGP-encryption mode.
727 \\[mime-editor/preview-message] preview editing MIME message.
728 \\[mime-editor/exit] exit and translate into a MIME compliant message.
729 \\[mime-editor/help] show this help.
730 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
732 Additional commands are available in some major modes:
733 C-c C-c exit, translate and run the original command.
734 C-c C-s exit, translate and run the original command.
736 The following is a message example written in the tagged MIME format.
737 TABs at the beginning of the line are not a part of the message:
739 This is a conventional plain text. It should be translated
742 This is also a plain text. But, it is explicitly specified as
744 --[[text/plain; charset=ISO-8859-1]]
745 This is also a plain text. But charset is specified as
748 ¡Hola! Buenos dÃas. ¿Cómo está usted?
750 This is a <bold>enriched text</bold>.
751 --[[image/gif][base64]]...image encoded in base64 here...
752 --[[audio/basic][base64]]...audio encoded in base64 here...
754 User customizable variables (not documented all of them):
756 Specifies a key prefix for MIME minor mode commands.
758 mime-ignore-preceding-spaces
759 Preceding white spaces in a message body are ignored if non-nil.
761 mime-ignore-trailing-spaces
762 Trailing white spaces in a message body are ignored if non-nil.
765 Hide a non-textual body message encoded in base64 after insertion
768 mime-editor/transfer-level
769 A number of network transfer level. It should be bigger than 7.
770 If you are in 8bit-through environment, please set 8.
772 mime-editor/voice-recorder
773 Specifies a function to record a voice message and encode it.
774 The function `mime-editor/voice-recorder-for-sun' is for Sun
777 mime/editor-mode-hook
778 Turning on MIME mode calls the value of mime/editor-mode-hook, if
781 mime-editor/translate-hook
782 The value of mime-editor/translate-hook is called just before translating
783 the tagged MIME format into a MIME compliant message if it is
784 non-nil. If the hook call the function mime-editor/insert-signature,
785 the signature file will be inserted automatically.
787 mime-editor/exit-hook
788 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
791 (if mime/editor-mode-flag
792 (error "You are already editing a MIME message.")
793 (setq mime/editor-mode-flag t)
794 ;; Remember old key bindings.
796 (use-local-map (or (current-local-map) (make-sparse-keymap)))
797 (make-local-variable 'mime/editor-mode-old-local-map)
798 (setq mime/editor-mode-old-local-map (current-local-map))
799 ;; Add MIME commands to current local map.
800 (use-local-map (copy-keymap (or (current-local-map)
801 (make-sparse-keymap))))
803 (if (not (lookup-key (current-local-map) mime-prefix))
804 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
806 ;; Set transfer level into mode line
808 (setq mime-editor/transfer-level-string
809 (mime/encoding-name mime-editor/transfer-level 'not-omit))
810 (force-mode-line-update)
812 ;; Define menu. Menus for other emacs implementations are
814 (cond (running-xemacs
815 (mime-editor/define-menu-for-xemacs))
816 ((>= emacs-major-version 19)
817 (mime-editor/define-menu-for-emacs19)
823 ;; I don't care about saving these.
824 (setq paragraph-start
825 (regexp-or mime-editor/single-part-tag-regexp
827 (setq paragraph-separate
828 (regexp-or mime-editor/single-part-tag-regexp
830 (run-hooks 'mime/editor-mode-hook)
832 (substitute-command-keys
833 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
837 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
838 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
840 (defun mime-editor/exit (&optional nomime no-error)
841 "Translate the tagged MIME message into a MIME compliant message.
842 With no argument encode a message in the buffer into MIME, otherwise
843 just return to previous mode."
845 (if (not mime/editor-mode-flag)
847 (error "You aren't editing a MIME message.")
851 (run-hooks 'mime-editor/translate-hook)
852 (mime-editor/translate-buffer)))
853 ;; Restore previous state.
854 (setq mime/editor-mode-flag nil)
855 (cond (running-xemacs
856 (if (featurep 'menubar)
857 (delete-menu-item (list mime-editor/menu-title))))
859 (use-local-map mime/editor-mode-old-local-map)))
862 (set-buffer-modified-p (buffer-modified-p))
863 (run-hooks 'mime-editor/exit-hook)
864 (message "Exit MIME editor mode.")
867 (defun mime-editor/maybe-translate ()
869 (mime-editor/exit nil t)
870 (call-interactively 'mime-editor/maybe-split-and-send)
873 (defun mime-editor/help ()
874 "Show help message about MIME mode."
876 (with-output-to-temp-buffer "*Help*"
877 (princ "MIME editor mode:\n")
878 (princ (documentation 'mime/editor-mode))
879 (print-help-return-message)))
881 (defun mime-editor/insert-text ()
882 "Insert a text message.
883 Charset is automatically obtained from the `mime/lc-charset-alist'."
885 (let ((ret (mime-editor/insert-tag "text" nil nil)))
888 (if (looking-at mime-editor/single-part-tag-regexp)
890 ;; Make a space between the following message.
894 (if (and (member (second ret) '("enriched" "richtext"))
895 (fboundp 'enriched-mode)
898 (if (boundp 'enriched-mode)
902 (defun mime-editor/insert-file (file &optional verbose)
903 "Insert a message from a file."
904 (interactive "fInsert file as MIME message: \nP")
905 (let* ((guess (mime-find-file-type file))
907 (subtype (nth 1 guess))
908 (parameters (nth 2 guess))
909 (encoding (nth 3 guess))
910 (disposition-type (nth 4 guess))
911 (disposition-params (nth 5 guess))
914 (setq type (mime-prompt-for-type type)
915 subtype (mime-prompt-for-subtype type subtype)
917 (if (or (interactive-p) verbose)
918 (setq encoding (mime-prompt-for-encoding encoding))
920 (if (or (consp parameters) (stringp disposition-type))
921 (let ((rest parameters) cell attribute value)
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)))
931 (setq parameters (concat parameters "; " attribute "=" value))
932 (setq rest (cdr rest))
937 (concat parameters "\n"
938 "Content-Disposition: " disposition-type))
939 (setq rest disposition-params)
941 (setq cell (car rest))
942 (setq attribute (car cell))
943 (setq value (cdr cell))
945 (setq value (std11-wrap-as-quoted-string
946 (file-name-nondirectory file)))
949 (concat parameters "; " attribute "=" value))
950 (setq rest (cdr rest))
954 (mime-editor/insert-tag type subtype parameters)
955 (mime-editor/insert-binary-file file encoding)
958 (defun mime-editor/insert-external ()
959 "Insert a reference to external body."
961 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
963 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
965 (let* ((pritype (mime-prompt-for-type))
966 (subtype (mime-prompt-for-subtype pritype))
967 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
970 (insert "Content-Type: "
971 pritype "/" subtype (or parameters "") "\n")))
972 (if (and (not (eobp))
973 (not (looking-at mime-editor/single-part-tag-regexp)))
974 (insert (mime-make-text-tag) "\n")))
976 (defun mime-editor/insert-voice ()
977 "Insert a voice message."
981 "What transfer encoding: "
982 mime-file-encoding-method-alist nil t nil)))
983 (mime-editor/insert-tag "audio" "basic" nil)
984 (mime-editor/define-encoding encoding)
986 (narrow-to-region (1- (point))(point))
988 (funcall mime-editor/voice-recorder encoding)
991 (invisible-region (point-min)(point-max))
992 (goto-char (point-max))
995 (defun mime-editor/insert-signature (&optional arg)
996 "Insert a signature file."
998 (let ((signature-insert-hook
1001 (apply (function mime-editor/insert-tag)
1002 (mime-find-file-type signature-file-name))
1005 (insert-signature arg)
1009 ;; Insert a new tag around a point.
1011 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
1012 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
1013 If nothing is inserted, return nil."
1016 (mime-editor/goto-tag)
1017 (if (and (re-search-forward mime-editor/tag-regexp nil t)
1018 (< (match-beginning 0) p)
1021 (goto-char (match-beginning 0))
1030 (mime-prompt-for-type)))
1033 (mime-prompt-for-subtype pritype)))
1036 (mime-prompt-for-parameters pritype subtype delimiter)))
1037 ;; Make a new MIME tag.
1038 (setq newtag (mime-make-tag pritype subtype parameters))
1039 ;; Find an current MIME tag.
1042 (if (mime-editor/goto-tag)
1043 (buffer-substring (match-beginning 0) (match-end 0))
1044 ;; Assume content type is 'text/plan'.
1045 (mime-make-tag "text" "plain")
1047 ;; We are only interested in TEXT.
1049 (not (mime-test-content-type
1050 (mime-editor/get-contype oldtag) "text")))
1053 (if (or (not oldtag) ;Not text
1054 (or mime-ignore-same-text-tag
1055 (not (string-equal oldtag newtag))))
1057 ;; Mark the beginning of the tag for convenience.
1058 (push-mark (point) 'nomsg)
1059 (insert newtag "\n")
1060 (list pritype subtype parameters) ;New tag is created.
1062 ;; Restore previous point.
1064 nil ;Nothing is created.
1068 (defun mime-editor/insert-binary-file (file &optional encoding)
1069 "Insert binary FILE at point.
1070 Optional argument ENCODING specifies an encoding method such as base64."
1071 (let* ((tagend (1- (point))) ;End of the tag
1072 (hide-p (and mime-auto-hide-body
1075 (let ((en (downcase encoding)))
1076 (or (string-equal en "7bit")
1077 (string-equal en "8bit")
1078 (string-equal en "binary")
1082 (narrow-to-region tagend (point))
1083 (mime-insert-encoded-file file encoding)
1086 (invisible-region (point-min) (point-max))
1087 (goto-char (point-max))
1089 (goto-char (point-max))
1092 (looking-at mime-editor/tag-regexp)
1093 (= (point)(point-max))
1094 (mime-editor/insert-tag "text" "plain")
1096 ;; Define encoding even if it is 7bit.
1097 (if (stringp encoding)
1099 (goto-char tagend) ; Make sure which line the tag is on.
1100 (mime-editor/define-encoding encoding)
1105 ;; Commands work on a current message flagment.
1107 (defun mime-editor/goto-tag ()
1108 "Search for the beginning of the tagged MIME message."
1109 (let ((current (point)) multipart)
1110 (if (looking-at mime-editor/tag-regexp)
1112 ;; At first, go to the end.
1113 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1114 (goto-char (1- (match-beginning 0))) ;For multiline tag
1117 (goto-char (point-max))
1119 ;; Then search for the beginning.
1120 (re-search-backward mime-editor/end-tag-regexp nil t)
1121 (or (looking-at mime-editor/beginning-tag-regexp)
1122 ;; Restore previous point.
1129 (defun mime-editor/content-beginning ()
1130 "Return the point of the beginning of content."
1132 (let ((beg (save-excursion
1133 (beginning-of-line) (point))))
1134 (if (mime-editor/goto-tag)
1135 (let ((top (point)))
1136 (goto-char (match-end 0))
1137 (if (and (= beg top)
1138 (= (following-char) ?\^M))
1142 ;; Default text/plain tag.
1143 (goto-char (point-min))
1145 (concat "\n" (regexp-quote mail-header-separator)
1146 (if mime-ignore-preceding-spaces
1147 "[ \t\n]*\n" "\n")) nil 'move)
1151 (defun mime-editor/content-end ()
1152 "Return the point of the end of content."
1154 (let ((beg (point)))
1155 (if (mime-editor/goto-tag)
1156 (let ((top (point)))
1157 (goto-char (match-end 0))
1158 (if (invisible-p (point))
1159 (next-visible-point (point))
1160 ;; Move to the end of this text.
1161 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1162 ;; Don't forget a multiline tag.
1163 (goto-char (match-beginning 0))
1167 ;; Assume the message begins with text/plain.
1168 (goto-char (mime-editor/content-beginning))
1169 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1170 ;; Don't forget a multiline tag.
1171 (goto-char (match-beginning 0)))
1175 (defun mime-editor/define-charset (charset)
1176 "Set charset of current tag to CHARSET."
1178 (if (mime-editor/goto-tag)
1179 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1180 (delete-region (match-beginning 0) (match-end 0))
1183 (mime-editor/set-parameter
1184 (mime-editor/get-contype tag)
1185 "charset" (upcase (symbol-name charset)))
1186 (mime-editor/get-encoding tag)))
1189 (defun mime-editor/define-encoding (encoding)
1190 "Set encoding of current tag to ENCODING."
1192 (if (mime-editor/goto-tag)
1193 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1194 (delete-region (match-beginning 0) (match-end 0))
1195 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1198 (defun mime-editor/choose-charset ()
1199 "Choose charset of a text following current point."
1200 (detect-mime-charset-region (point) (mime-editor/content-end))
1203 (defun mime-make-text-tag (&optional subtype)
1204 "Make a tag for a text after current point.
1205 Subtype of text type can be specified by an optional argument SUBTYPE.
1206 Otherwise, it is obtained from mime-content-types."
1207 (let* ((pritype "text")
1208 (subtype (or subtype
1209 (car (car (cdr (assoc pritype mime-content-types)))))))
1210 ;; Charset should be defined later.
1211 (mime-make-tag pritype subtype)))
1214 ;; Tag handling functions
1216 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1217 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1218 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1222 (defun mime-create-tag (contype &optional encoding)
1223 "Make a tag with CONTENT-TYPE and optional ENCODING."
1224 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1227 (defun mime-editor/get-contype (tag)
1228 "Return Content-Type (including parameters) of TAG."
1230 (or (string-match mime-editor/single-part-tag-regexp tag)
1231 (string-match mime-editor/multipart-beginning-regexp tag)
1232 (string-match mime-editor/multipart-end-regexp tag)
1234 (substring tag (match-beginning 1) (match-end 1))
1237 (defun mime-editor/get-encoding (tag)
1238 "Return encoding of TAG."
1240 (string-match mime-editor/single-part-tag-regexp tag)
1242 (not (= (match-beginning 3) (match-end 3)))
1243 (substring tag (match-beginning 3) (match-end 3))))
1245 (defun mime-get-parameter (contype parameter)
1246 "For given CONTYPE return value for PARAMETER.
1247 Nil if no such parameter."
1251 (regexp-quote parameter)
1252 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1254 (substring contype (match-beginning 1) (match-end 1))
1255 nil ;No such parameter
1258 (defun mime-editor/set-parameter (contype parameter value)
1259 "For given CONTYPE set PARAMETER to VALUE."
1260 (let (ctype opt-fields)
1261 (if (string-match "\n[^ \t\n\r]+:" contype)
1262 (setq ctype (substring contype 0 (match-beginning 0))
1263 opt-fields (substring contype (match-beginning 0)))
1264 (setq ctype contype)
1269 (regexp-quote parameter)
1270 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1273 (concat (substring ctype 0 (match-beginning 1))
1275 (substring contype (match-end 1))
1277 (concat ctype "; " parameter "=" value opt-fields)
1280 (defun mime-strip-parameters (contype)
1281 "Return primary content-type and subtype without parameters for CONTYPE."
1282 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1283 (substring contype (match-beginning 1) (match-end 1)) nil))
1285 (defun mime-test-content-type (contype type &optional subtype)
1286 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1287 (and (stringp contype)
1290 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1291 (downcase contype))))
1296 (defun mime-find-file-type (file)
1297 "Guess Content-Type, subtype, and parameters from FILE."
1299 (guesses mime-file-types))
1300 (while (and (not guess) guesses)
1301 (if (string-match (car (car guesses)) file)
1302 (setq guess (cdr (car guesses))))
1303 (setq guesses (cdr guesses)))
1307 (defun mime-prompt-for-type (&optional default)
1308 "Ask for Content-type."
1310 ;; Repeat until primary content type is specified.
1311 (while (string-equal type "")
1313 (completing-read "What content type: "
1316 'require-match ;Type must be specified.
1319 (if (string-equal type "")
1321 (message "Content type is required.")
1328 (defun mime-prompt-for-subtype (type &optional default)
1329 "Ask for subtype of media-type TYPE."
1330 (let ((subtypes (cdr (assoc type mime-content-types))))
1332 (assoc default subtypes))
1333 (setq default (car (car subtypes)))
1339 "What content subtype: (default " default ") ")
1340 "What content subtype: ")
1341 (cdr (assoc type mime-content-types))
1343 'require-match ;Subtype must be specified.
1346 (if (string-equal answer "") default answer)))
1348 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1349 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1350 Optional DELIMITER specifies parameter delimiter (';' by default)."
1351 (let* ((delimiter (or delimiter "; "))
1356 (mime-prompt-for-parameters-1
1358 (cdr (assoc pritype mime-content-types))))))
1361 (if (and (stringp parameters)
1362 (not (string-equal parameters "")))
1363 (concat delimiter parameters)
1364 "" ;"" if no parameters
1367 (defun mime-prompt-for-parameters-1 (optlist)
1368 (apply (function append)
1369 (mapcar (function mime-prompt-for-parameter) optlist)))
1371 (defun mime-prompt-for-parameter (parameter)
1373 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1374 (let* ((prompt (car parameter))
1375 (choices (mapcar (function
1377 (if (consp e) e (list e))))
1379 (default (car (car choices)))
1385 (concat "What " prompt
1387 (if (string-equal default "") "\"\"" default)
1389 choices nil nil ""))
1390 ;; If nothing is selected, use default.
1391 (if (string-equal answer "")
1392 (setq answer default)))
1394 (read-string (concat "What " prompt ": "))))
1395 (cons (if (and answer
1396 (not (string-equal answer "")))
1398 ;; Note: control characters ignored!
1399 (if (string-match mime-tspecials-regexp answer)
1400 (concat "\"" answer "\"") answer)))
1401 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1404 (defun mime-prompt-for-encoding (default)
1405 "Ask for Content-Transfer-Encoding. [tm-edit.el]"
1410 "What transfer encoding: "
1411 mime-file-encoding-method-alist nil t default)
1417 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1420 (defvar mime-editor/translate-buffer-hook
1421 '(mime-editor/pgp-enclose-buffer
1422 mime-editor/translate-header
1423 mime-editor/translate-body))
1425 (defun mime-editor/translate-header ()
1426 "Encode the message header into network representation."
1427 (mime/encode-message-header 'code-conversion)
1428 (run-hooks 'mime-editor/translate-header-hook)
1431 (defun mime-editor/translate-buffer ()
1432 "Encode the tagged MIME message in current buffer in MIME compliant message."
1434 (if (catch 'mime-editor/error
1436 (run-hooks 'mime-editor/translate-buffer-hook)
1440 (error "Translation error!")
1443 (defun mime-editor/find-inmost ()
1444 (goto-char (point-min))
1445 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1446 (let ((bb (match-beginning 0))
1448 (type (buffer-substring (match-beginning 1)(match-end 1)))
1450 (setq end-exp (format "--}-<<%s>>\n" type))
1452 (if (re-search-forward end-exp nil t)
1454 (setq eb (match-beginning 0))
1455 (setq ee (match-end 0))
1457 (setq eb (point-max))
1458 (setq ee (point-max))
1460 (narrow-to-region be eb)
1462 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1464 (narrow-to-region (match-beginning 0)(point-max))
1465 (mime-editor/find-inmost)
1468 (list type bb be eb)
1471 (defun mime-editor/process-multipart-1 (boundary)
1472 (let ((ret (mime-editor/find-inmost)))
1474 (let ((type (car ret))
1475 (bb (nth 1 ret))(be (nth 2 ret))
1478 (narrow-to-region bb eb)
1479 (delete-region bb be)
1480 (setq bb (point-min))
1481 (setq eb (point-max))
1484 (if (looking-at mime-editor/multipart-end-regexp)
1485 (let ((beg (match-beginning 0))
1488 (delete-region beg end)
1489 (or (looking-at mime-editor/beginning-tag-regexp)
1491 (insert (concat (mime-make-text-tag) "\n"))
1493 (cond ((string-equal type "quote")
1494 (mime-editor/enquote-region bb eb)
1496 ((string-equal type "signed")
1497 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1498 (mime-editor/sign-pgp-elkins bb eb boundary)
1500 ((eq mime-editor/signing-type 'pgp-kazu)
1501 (mime-editor/sign-pgp-kazu bb eb boundary)
1504 ((string-equal type "encrypted")
1505 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1506 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1508 ((eq mime-editor/encrypting-type 'pgp-kazu)
1509 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1513 (nth 2 (mime-editor/translate-region bb eb
1517 (format "--[[multipart/%s;
1518 boundary=\"%s\"][7bit]]\n"
1523 (defun mime-editor/enquote-region (beg end)
1526 (narrow-to-region beg end)
1528 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1529 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1530 (replace-match (concat "- " (substring tag 1)))
1533 (defun mime-editor/dequote-region (beg end)
1536 (narrow-to-region beg end)
1538 (while (re-search-forward
1539 mime-editor/quoted-single-part-tag-regexp nil t)
1540 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1541 (replace-match (concat "-" (substring tag 2)))
1544 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1547 (narrow-to-region beg end)
1549 (mime-editor/translate-region beg end boundary))
1551 (encoding (nth 1 ret))
1553 (pgp-boundary (concat "pgp-sign-" boundary))
1556 (insert (format "Content-Type: %s\n" ctype))
1558 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1561 (or (funcall mime-editor/pgp-sign-function
1562 (point-min)(point-max) nil nil pgp-boundary)
1563 (throw 'mime-editor/error 'pgp-error)
1567 (defvar mime-editor/encrypt-recipient-fields-list '("To" "cc"))
1569 (defun mime-editor/make-encrypt-recipient-header ()
1570 (let* ((names mime-editor/encrypt-recipient-fields-list)
1572 (std11-field-bodies (cons "From" names)
1573 nil mail-header-separator))
1576 (setq values (cdr values))))
1577 (header (and (stringp from)
1578 (if (string-equal from "")
1580 (format "From: %s\n" from)
1583 (while (and names values)
1584 (let ((name (car names))
1585 (value (car values))
1587 (and (stringp value)
1588 (or (string-equal value "")
1590 (setq header (concat header name ": " value "\n")
1591 recipients (if recipients
1592 (concat recipients " ," value)
1595 (setq names (cdr names)
1596 values (cdr values))
1598 (vector from recipients header)
1601 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1604 (let (from recipients header)
1605 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1606 (setq from (aref ret 0)
1607 recipients (aref ret 1)
1608 header (aref ret 2))
1610 (narrow-to-region beg end)
1612 (mime-editor/translate-region beg end boundary))
1614 (encoding (nth 1 ret))
1616 (pgp-boundary (concat "pgp-" boundary))
1620 (insert (format "Content-Type: %s\n" ctype))
1622 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1625 (or (funcall mime-editor/pgp-encrypt-function
1626 recipients (point-min) (point-max) from)
1627 (throw 'mime-editor/error 'pgp-error)
1630 (insert (format "--[[multipart/encrypted;
1632 protocol=\"application/pgp-encrypted\"][7bit]]
1634 Content-Type: application/pgp-encrypted
1637 Content-Type: application/octet-stream
1638 Content-Transfer-Encoding: 7bit
1640 " pgp-boundary pgp-boundary pgp-boundary))
1641 (goto-char (point-max))
1642 (insert (format "\n--%s--\n" pgp-boundary))
1645 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1648 (narrow-to-region beg end)
1650 (mime-editor/translate-region beg end boundary))
1652 (encoding (nth 1 ret))
1656 (insert (format "Content-Type: %s\n" ctype))
1658 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1661 (or (as-binary-process
1662 (funcall mime-editor/traditional-pgp-sign-function
1664 (throw 'mime-editor/error 'pgp-error)
1668 "--[[application/pgp; format=mime][7bit]]\n")
1672 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1674 (let (from recipients header)
1675 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1676 (setq from (aref ret 0)
1677 recipients (aref ret 1)
1678 header (aref ret 2))
1681 (narrow-to-region beg end)
1683 (mime-editor/translate-region beg end boundary))
1685 (encoding (nth 1 ret))
1690 (insert (format "Content-Type: %s\n" ctype))
1692 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1695 (or (as-binary-process
1696 (funcall mime-editor/pgp-encrypt-function
1697 recipients beg (point-max) nil 'maybe)
1699 (throw 'mime-editor/error 'pgp-error)
1703 "--[[application/pgp; format=mime][7bit]]\n")
1707 (defun mime-editor/translate-body ()
1708 "Encode the tagged MIME body in current buffer in MIME compliant message."
1712 (concat mime-multipart-boundary "_"
1713 (replace-space-with-underline (current-time-string))
1717 (while (mime-editor/process-multipart-1
1718 (format "%s-%d" boundary i))
1722 ;; We are interested in message body.
1725 (goto-char (point-min))
1727 (concat "\n" (regexp-quote mail-header-separator)
1728 (if mime-ignore-preceding-spaces
1729 "[ \t\n]*\n" "\n")) nil 'move)
1733 (goto-char (point-max))
1734 (and mime-ignore-trailing-spaces
1735 (re-search-backward "[^ \t\n]\n" beg t)
1738 (setq ret (mime-editor/translate-region
1740 (format "%s-%d" boundary i)))
1742 (mime-editor/dequote-region (point-min)(point-max))
1743 (let ((contype (car ret)) ;Content-Type
1744 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1746 ;; Make primary MIME headers.
1747 (or (mail-position-on-field "Mime-Version")
1748 (insert mime-editor/mime-version-value))
1749 ;; Remove old Content-Type and other fields.
1751 (goto-char (point-min))
1752 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1753 (narrow-to-region (point-min) (point))
1754 (goto-char (point-min))
1755 (mime-delete-field "Content-Type")
1756 (mime-delete-field "Content-Transfer-Encoding"))
1757 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1758 (mail-position-on-field "Content-Type")
1762 (mail-position-on-field "Content-Transfer-Encoding")
1766 (defun mime-editor/translate-single-part-tag (&optional prefix)
1767 (if (re-search-forward mime-editor/single-part-tag-regexp nil t)
1768 (let* ((beg (match-beginning 0))
1770 (tag (buffer-substring beg end))
1772 (delete-region beg end)
1773 (setq contype (mime-editor/get-contype tag))
1774 (setq encoding (mime-editor/get-encoding tag))
1775 (insert (concat prefix "--" boundary "\n"))
1777 (narrow-to-region (point)(point))
1778 (insert "Content-Type: " contype "\n")
1780 (insert "Content-Transfer-Encoding: " encoding "\n"))
1781 (mime/encode-message-header)
1785 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1788 (concat mime-multipart-boundary "_"
1789 (replace-space-with-underline (current-time-string))))
1793 (narrow-to-region beg end)
1794 (let ((tag nil) ;MIME tag
1795 (contype nil) ;Content-Type
1796 (encoding nil) ;Content-Transfer-Encoding
1797 (nparts 0)) ;Number of body parts
1798 ;; Normalize the body part by inserting appropriate message
1799 ;; tags for every message contents.
1800 (mime-editor/normalize-body)
1801 ;; Counting the number of Content-Type.
1802 (goto-char (point-min))
1803 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1804 (setq nparts (1+ nparts)))
1805 ;; Begin translation.
1807 ((and (<= nparts 1)(not multipart))
1808 ;; It's a singular message.
1809 (goto-char (point-min))
1810 (while (re-search-forward
1811 mime-editor/single-part-tag-regexp nil t)
1813 (buffer-substring (match-beginning 0) (match-end 0)))
1814 (delete-region (match-beginning 0) (1+ (match-end 0)))
1815 (setq contype (mime-editor/get-contype tag))
1816 (setq encoding (mime-editor/get-encoding tag))
1819 ;; It's a multipart message.
1820 (goto-char (point-min))
1821 (and (mime-editor/translate-single-part-tag)
1822 (while (mime-editor/translate-single-part-tag "\n"))
1824 ;; Define Content-Type as "multipart/mixed".
1826 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1827 ;; Content-Transfer-Encoding must be "7bit".
1828 ;; The following encoding can be `nil', but is
1829 ;; specified as is since there is no way that a user
1831 (setq encoding "7bit")
1832 ;; Insert the trailer.
1833 (goto-char (point-max))
1834 (insert "\n--" boundary "--\n")
1836 (list contype encoding boundary nparts)
1839 (defun mime-editor/normalize-body ()
1840 "Normalize the body part by inserting appropriate message tags."
1841 ;; Insert the first MIME tags if necessary.
1842 (goto-char (point-min))
1843 (if (not (looking-at mime-editor/single-part-tag-regexp))
1844 (insert (mime-make-text-tag) "\n"))
1845 ;; Check each tag, and add new tag or correct it if necessary.
1846 (goto-char (point-min))
1847 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1848 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1849 (contype (mime-editor/get-contype tag))
1850 (charset (mime-get-parameter contype "charset"))
1851 (encoding (mime-editor/get-encoding tag)))
1852 ;; Remove extra whitespaces after the tag.
1853 (if (looking-at "[ \t]+$")
1854 (delete-region (match-beginning 0) (match-end 0)))
1856 (end (mime-editor/content-end))
1858 (if (= end (point-max))
1861 (or (looking-at mime-editor/beginning-tag-regexp)
1863 (insert (mime-make-text-tag) "\n")
1865 (visible-region beg end)
1869 ((mime-test-content-type contype "message")
1870 ;; Content-type "message" should be sent as is.
1873 ((mime-test-content-type contype "text")
1874 ;; Define charset for text if necessary.
1875 (setq charset (if charset
1876 (intern (downcase charset))
1877 (mime-editor/choose-charset)))
1878 (mime-editor/define-charset charset)
1879 (cond ((string-equal contype "text/x-rot13-47")
1883 (goto-char (mime-editor/content-end))
1886 ((string-equal contype "text/enriched")
1891 (end (mime-editor/content-end))
1893 ;; Patch for hard newlines
1896 ;; (while (search-forward "\n" end t)
1897 ;; (put-text-property (match-beginning 0)
1900 ;; End patch for hard newlines
1901 (enriched-encode beg end)
1903 (if (search-forward "\n\n")
1904 (delete-region beg (match-end 0))
1907 ;; Point is now on current tag.
1908 ;; Define encoding and encode text if necessary.
1909 (or encoding ;Encoding is not specified.
1913 mime-editor/charset-default-encoding-alist)
1915 (beg (mime-editor/content-beginning))
1917 (encode-mime-charset-region beg (mime-editor/content-end)
1919 (mime-encode-region beg (mime-editor/content-end) encoding)
1920 (mime-editor/define-encoding encoding)
1922 (goto-char (mime-editor/content-end))
1924 ((null encoding) ;Encoding is not specified.
1925 ;; Application, image, audio, video, and any other
1926 ;; unknown content-type without encoding should be
1928 (let* ((encoding "base64") ;Encode in BASE64 by default.
1929 (beg (mime-editor/content-beginning))
1930 (end (mime-editor/content-end))
1931 (body (buffer-substring beg end))
1933 (mime-encode-region beg end encoding)
1934 (mime-editor/define-encoding encoding))
1939 (defun mime-delete-field (field)
1940 "Delete header FIELD."
1941 (let ((regexp (format "^%s:[ \t]*" field)))
1942 (goto-char (point-min))
1943 (while (re-search-forward regexp nil t)
1944 (delete-region (match-beginning 0)
1945 (progn (forward-line 1) (point)))
1950 ;;; Platform dependent functions
1953 ;; Sun implementations
1955 (defun mime-editor/voice-recorder-for-sun (encoding)
1956 "Record voice in a buffer using Sun audio device,
1957 and insert data encoded as ENCODING. [tm-edit.el]"
1958 (message "Start the recording on %s. Type C-g to finish the recording..."
1960 (mime-insert-encoded-file "/dev/audio" encoding)
1964 ;;; @ Other useful commands.
1967 ;; Message forwarding commands as content-type "message/rfc822".
1969 (defun mime-editor/insert-message (&optional message)
1971 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
1972 (if (and inserter (fboundp inserter))
1974 (mime-editor/insert-tag "message" "rfc822")
1975 (funcall inserter message)
1977 (message "Sorry, I don't have message inserter for your MUA.")
1980 (defun mime-editor/insert-mail (&optional message)
1982 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
1983 (if (and inserter (fboundp inserter))
1985 (mime-editor/insert-tag "message" "rfc822")
1986 (funcall inserter message)
1988 (message "Sorry, I don't have mail inserter for your MUA.")
1991 (defun mime-editor/inserted-message-filter ()
1994 (let ((header-start (point))
1995 (case-fold-search t)
1998 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
1999 (if (re-search-forward "^$" (mark t))
2000 (narrow-to-region header-start (match-beginning 0))
2002 (goto-char header-start)
2003 (while (and (re-search-forward
2004 mime-editor/yank-ignored-field-regexp nil t)
2005 (setq beg (match-beginning 0))
2006 (setq end (1+ (std11-field-end)))
2008 (delete-region beg end)
2013 ;;; @ multipart enclosure
2016 (defun mime-editor/enclose-region (type beg end)
2019 (let ((current (point)))
2021 (narrow-to-region beg end)
2022 (insert (format "--<<%s>>-{\n" type))
2023 (goto-char (point-max))
2024 (insert (format "--}-<<%s>>\n" type))
2025 (goto-char (point-max))
2027 (or (looking-at mime-editor/beginning-tag-regexp)
2029 (insert (mime-make-text-tag) "\n")
2033 (defun mime-editor/enclose-quote-region (beg end)
2035 (mime-editor/enclose-region "quote" beg end)
2038 (defun mime-editor/enclose-mixed-region (beg end)
2040 (mime-editor/enclose-region "mixed" beg end)
2043 (defun mime-editor/enclose-parallel-region (beg end)
2045 (mime-editor/enclose-region "parallel" beg end)
2048 (defun mime-editor/enclose-digest-region (beg end)
2050 (mime-editor/enclose-region "digest" beg end)
2053 (defun mime-editor/enclose-alternative-region (beg end)
2055 (mime-editor/enclose-region "alternative" beg end)
2058 (defun mime-editor/enclose-signed-region (beg end)
2060 (if mime-editor/signing-type
2061 (mime-editor/enclose-region "signed" beg end)
2062 (message "Please specify signing type.")
2065 (defun mime-editor/enclose-encrypted-region (beg end)
2067 (if mime-editor/signing-type
2068 (mime-editor/enclose-region "encrypted" beg end)
2069 (message "Please specify encrypting type.")
2072 (defun mime-editor/insert-key (&optional arg)
2073 "Insert a pgp public key."
2075 (mime-editor/insert-tag "application" "pgp-keys")
2076 (mime-editor/define-encoding "7bit")
2077 (funcall mime-editor/pgp-insert-public-key-function)
2084 (defun mime-editor/set-split (arg)
2087 (y-or-n-p "Do you want to enable split?")
2089 (setq mime-editor/split-message arg)
2091 (message "This message is enabled to split.")
2092 (message "This message is not enabled to split.")
2095 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2096 "Toggle transfer-level is 7bit or 8bit through.
2098 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2100 (if (numberp transfer-level)
2101 (setq mime-editor/transfer-level transfer-level)
2102 (if (< mime-editor/transfer-level 8)
2103 (setq mime-editor/transfer-level 8)
2104 (setq mime-editor/transfer-level 7)
2106 (setq mime-editor/charset-default-encoding-alist
2107 (mime-editor/make-charset-default-encoding-alist
2108 mime-editor/transfer-level))
2109 (message (format "Current transfer-level is %d bit"
2110 mime-editor/transfer-level))
2111 (setq mime-editor/transfer-level-string
2112 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2113 (force-mode-line-update)
2116 (defun mime-editor/set-transfer-level-7bit ()
2118 (mime-editor/toggle-transfer-level 7)
2121 (defun mime-editor/set-transfer-level-8bit ()
2123 (mime-editor/toggle-transfer-level 8)
2130 (defun mime-editor/set-sign (arg)
2133 (y-or-n-p "Do you want to sign?")
2136 (if mime-editor/signing-type
2138 (setq mime-editor/pgp-processing 'sign)
2139 (message "This message will be signed.")
2141 (message "Please specify signing type.")
2143 (if (eq mime-editor/pgp-processing 'sign)
2144 (setq mime-editor/pgp-processing nil)
2146 (message "This message will not be signed.")
2149 (defun mime-editor/set-encrypt (arg)
2152 (y-or-n-p "Do you want to encrypt?")
2155 (if mime-editor/encrypting-type
2157 (setq mime-editor/pgp-processing 'encrypt)
2158 (message "This message will be encrypt.")
2160 (message "Please specify encrypting type.")
2162 (if (eq mime-editor/pgp-processing 'encrypt)
2163 (setq mime-editor/pgp-processing nil)
2165 (message "This message will not be encrypt.")
2168 (defvar mime-editor/pgp-processing nil)
2169 (make-variable-buffer-local 'mime-editor/pgp-processing)
2171 (defun mime-editor/pgp-enclose-buffer ()
2172 (let ((beg (save-excursion
2173 (goto-char (point-min))
2174 (if (search-forward (concat "\n" mail-header-separator "\n"))
2180 (cond ((eq mime-editor/pgp-processing 'sign)
2181 (mime-editor/enclose-signed-region beg end)
2183 ((eq mime-editor/pgp-processing 'encrypt)
2184 (mime-editor/enclose-encrypted-region beg end)
2192 (defun mime-editor/insert-partial-header
2193 (fields subject id number total separator)
2195 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2196 (insert (format "Mime-Version: 1.0 (split by %s)\n"
2197 mime-editor/version-name))
2199 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2200 id number total separator))
2203 (defun mime-editor/split-and-send
2204 (&optional cmd lines mime-editor/message-max-length)
2208 (count-lines (point-min) (point-max)))
2210 (or mime-editor/message-max-length
2211 (setq mime-editor/message-max-length
2212 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
2213 mime-editor/message-default-max-lines))
2215 (let* ((mime-editor/draft-file-name
2216 (or (buffer-file-name)
2218 (expand-file-name "tm-draft" mime/tmp-dir))))
2219 (separator mail-header-separator)
2221 (replace-space-with-underline (current-time-string))
2222 "@" (system-name) "\"")))
2223 (run-hooks 'mime-editor/before-split-hook)
2224 (let ((the-buf (current-buffer))
2225 (copy-buf (get-buffer-create " *Original Message*"))
2226 (header (std11-header-string-except
2227 mime-editor/split-ignored-field-regexp separator))
2228 (subject (mail-fetch-field "subject"))
2229 (total (+ (/ lines mime-editor/message-max-length)
2230 (if (> (mod lines mime-editor/message-max-length) 0)
2236 mime-editor/split-message-sender-alist))
2240 (error "Split sender is not specified for `%s'." major-mode)
2243 (mime-editor/partial-number 1)
2246 (set-buffer copy-buf)
2248 (insert-buffer the-buf)
2250 (if (re-search-forward
2251 (concat "^" (regexp-quote separator) "$") nil t)
2252 (let ((he (match-beginning 0)))
2254 (narrow-to-region (point-min) he)
2256 (goto-char (point-min))
2257 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
2258 (delete-region (match-beginning 0)
2259 (1+ (std11-field-end)))
2261 (while (< mime-editor/partial-number total)
2264 (set-buffer copy-buf)
2265 (setq data (buffer-substring
2268 (goto-line mime-editor/message-max-length)
2271 (delete-region (point-min)(point))
2273 (mime-editor/insert-partial-header
2274 header subject id mime-editor/partial-number total separator)
2277 (message (format "Sending %d/%d..."
2278 mime-editor/partial-number total))
2279 (call-interactively command)
2280 (message (format "Sending %d/%d... done"
2281 mime-editor/partial-number total))
2283 (setq mime-editor/partial-number
2284 (1+ mime-editor/partial-number))
2288 (set-buffer copy-buf)
2289 (setq data (buffer-string))
2292 (mime-editor/insert-partial-header
2293 header subject id mime-editor/partial-number total separator)
2296 (message (format "Sending %d/%d..."
2297 mime-editor/partial-number total))
2298 (message (format "Sending %d/%d... done"
2299 mime-editor/partial-number total))
2303 (defun mime-editor/maybe-split-and-send (&optional cmd)
2305 (run-hooks 'mime-editor/before-send-hook)
2306 (let ((mime-editor/message-max-length
2307 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
2308 mime-editor/message-default-max-lines))
2309 (lines (count-lines (point-min) (point-max)))
2311 (if (and (> lines mime-editor/message-max-length)
2312 mime-editor/split-message)
2313 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2317 ;;; @ preview message
2320 (defun mime-editor/preview-message ()
2321 "preview editing MIME message. [tm-edit.el]"
2323 (let* ((str (buffer-string))
2324 (separator mail-header-separator)
2325 (the-buf (current-buffer))
2326 (buf-name (buffer-name))
2327 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2328 (buf (get-buffer temp-buf-name))
2332 (switch-to-buffer buf)
2335 (setq buf (get-buffer-create temp-buf-name))
2336 (switch-to-buffer buf)
2339 (setq major-mode 'mime/temporary-message-mode)
2340 (make-local-variable 'mail-header-separator)
2341 (setq mail-header-separator separator)
2342 (make-local-variable 'mime/editing-buffer)
2343 (setq mime/editing-buffer the-buf)
2345 (run-hooks 'mime-editor/translate-hook)
2346 (mime-editor/translate-buffer)
2347 (goto-char (point-min))
2348 (if (re-search-forward
2349 (concat "^" (regexp-quote separator) "$"))
2355 (defun mime-editor/quitting-method ()
2356 (let ((temp mime::preview/article-buffer)
2358 (mime-viewer/kill-buffer)
2360 (setq buf mime/editing-buffer)
2362 (switch-to-buffer buf)
2365 (set-alist 'mime-viewer/quitting-method-alist
2366 'mime/temporary-message-mode
2367 (function mime-editor/quitting-method)
2373 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2374 ;; Mon, 10 Apr 1995 20:03:07 +0900
2376 (defvar mime-editor/draft-header-separator-alist
2377 '((news-reply-mode . mail-header-separator)
2378 (mh-letter-mode . mail-header-separator)
2381 (defvar mime::article/draft-header-separator nil)
2383 (defun mime-editor/draft-preview ()
2385 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2386 (or (stringp sep) (setq sep (eval sep)))
2387 (make-variable-buffer-local 'mime::article/draft-header-separator)
2388 (goto-char (point-min))
2390 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2391 (setq mime::article/draft-header-separator
2392 (buffer-substring (match-beginning 0) (match-end 0)))
2394 (mime/viewer-mode (current-buffer))
2395 (pop-to-buffer (current-buffer))
2398 (defun mime-viewer::quitting-method/draft-preview ()
2399 (let ((mother mime::preview/mother-buffer))
2401 (switch-to-buffer mother)
2402 (goto-char (point-min))
2406 (regexp-quote mime::article/draft-header-separator)
2410 (insert mime::article/draft-header-separator)
2411 (set-buffer-modified-p (buffer-modified-p))
2413 (mime-viewer/kill-buffer)
2414 (pop-to-buffer mother)
2417 (set-alist 'mime-viewer/quitting-method-alist
2419 (function mime-viewer::quitting-method/draft-preview)
2422 (set-alist 'mime-viewer/quitting-method-alist
2424 (function mime-viewer::quitting-method/draft-preview)
2431 (defun mime-editor::edit-again (code-conversion)
2433 (goto-char (point-min))
2434 (let ((ctl (mime/Content-Type)))
2436 (let ((ctype (car ctl))
2439 (if (string-match "/" ctype)
2441 (setq type (substring ctype 0 (match-beginning 0)))
2442 (setq stype (substring ctype (match-end 0)))
2447 ((string-equal type "multipart")
2448 (let* ((boundary (assoc-value "boundary" params))
2450 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2452 (re-search-forward boundary-pat nil t)
2453 (let ((bb (match-beginning 0)) eb tag)
2454 (setq tag (format "\n--<<%s>>-{\n" stype))
2457 (setq bb (+ bb (length tag)))
2459 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2461 (setq eb (match-beginning 0))
2462 (replace-match (format "--}-<<%s>>\n" stype))
2464 (narrow-to-region bb eb)
2465 (goto-char (point-min))
2466 (while (re-search-forward boundary-pat nil t)
2467 (let ((beg (match-beginning 0))
2469 (delete-region beg (match-end 0))
2471 (if (re-search-forward boundary-pat nil t)
2472 (setq end (match-beginning 0))
2473 (setq end (point-max))
2476 (narrow-to-region beg end)
2477 (mime-editor::edit-again code-conversion)
2478 (goto-char (point-max))
2481 (goto-char (point-min))
2482 (or (= (point-min) 1)
2483 (delete-region (point-min)
2484 (if (search-forward "\n\n" nil t)
2492 (let ((bytes (+ 14 (length ctype))))
2493 (mapconcat (function
2495 (if (string-equal (car attr) "charset")
2497 (setq charset (cdr attr))
2505 (setq bytes (+ bytes bs 2))
2508 (setq bytes (+ bs 1))
2516 (if (re-search-forward
2517 "Content-Transfer-Encoding:" nil t)
2518 (let ((beg (match-beginning 0))
2519 (hbeg (match-end 0))
2520 (end (std11-field-end)))
2522 (eliminate-top-spaces
2523 (std11-unfold-string
2524 (buffer-substring hbeg end))))
2525 (if (or charset (string-equal type "text"))
2527 (delete-region beg (1+ end))
2528 (goto-char (point-min))
2529 (if (search-forward "\n\n" nil t)
2532 (match-end 0)(point-max) encoding)
2536 (if (or code-conversion encoded)
2537 (decode-mime-charset-region
2538 (point-min)(point-max)
2539 (or charset default-mime-charset))
2542 (if (re-search-forward "^$" nil t)
2546 (if (= (point-min) 1)
2552 (concat type "/" stype pstr) encoding)))
2554 (delete-region (point-min) he)
2557 (concat type "/" stype pstr) encoding))
2561 (decode-mime-charset-region (point-min) (point-max)
2562 default-mime-charset)
2566 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2568 (mime-editor::edit-again code-conversion)
2569 (goto-char (point-min))
2573 (if (re-search-forward
2574 (concat "^\\(" (regexp-quote mail-header-separator) "\\)?$")
2579 (goto-char (point-min))
2580 (while (re-search-forward
2581 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2582 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2585 (and (re-search-forward "^$")
2586 (replace-match mail-header-separator)
2598 (run-hooks 'tm-edit-load-hook)
2600 ;;; tm-edit.el ends here