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.105 $
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.
97 ;;--[[text/plain; charset=ISO-8859-1]]
98 ;; This is also a plain text. But charset is specified as iso-8859-1.
100 ;; ¡Hola! Buenos días. ¿Cómo está usted?
101 ;;--[[text/enriched]]
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.105 1997/02/13 14:29:14 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]")
440 (defconst mime-editor/single-part-tag-regexp
441 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
442 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
444 (defconst mime-editor/quoted-single-part-tag-regexp
445 (concat "- " (substring mime-editor/single-part-tag-regexp 1)))
447 (defconst mime-editor/multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
449 (defconst mime-editor/multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
451 (defconst mime-editor/beginning-tag-regexp
452 (regexp-or mime-editor/single-part-tag-regexp
453 mime-editor/multipart-beginning-regexp))
455 (defconst mime-editor/end-tag-regexp
456 (regexp-or mime-editor/single-part-tag-regexp
457 mime-editor/multipart-end-regexp))
459 (defconst mime-editor/tag-regexp
460 (regexp-or mime-editor/single-part-tag-regexp
461 mime-editor/multipart-beginning-regexp
462 mime-editor/multipart-end-regexp))
464 (defvar mime-tag-format "--[[%s]]"
465 "*Control-string making a MIME tag.")
467 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
468 "*Control-string making a MIME tag with encoding.")
470 ;;; @@ multipart boundary
473 (defvar mime-multipart-boundary "Multipart"
474 "*Boundary of a multipart message.")
477 ;;; @@ buffer local variables
480 (defvar mime/editor-mode-old-local-map nil)
481 (defvar mime/editing-buffer nil)
487 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
488 "*Specify MIME tspecials.
489 Tspecials means any character that matches with it in header must be quoted.")
491 (defconst mime-editor/mime-version-value
492 (concat "1.0 (generated by " mime-editor/version-name ")")
493 "MIME version number.")
495 (defconst mime-editor/mime-map (make-sparse-keymap)
496 "Keymap for MIME commands.")
498 ;;; @ keymap and menu
501 (defvar mime/editor-mode-flag nil)
502 (make-variable-buffer-local 'mime/editor-mode-flag)
504 (defun mime-editor/define-keymap (keymap)
505 "Add mime-editor commands to KEYMAP."
506 (if (not (keymapp keymap))
508 (define-key keymap "\C-t" 'mime-editor/insert-text)
509 (define-key keymap "\C-i" 'mime-editor/insert-file)
510 (define-key keymap "\C-e" 'mime-editor/insert-external)
511 (define-key keymap "\C-v" 'mime-editor/insert-voice)
512 (define-key keymap "\C-y" 'mime-editor/insert-message)
513 (define-key keymap "\C-m" 'mime-editor/insert-mail)
514 (define-key keymap "\C-w" 'mime-editor/insert-signature)
515 (define-key keymap "\C-s" 'mime-editor/insert-signature)
516 (define-key keymap "\C-k" 'mime-editor/insert-key)
517 (define-key keymap "t" 'mime-editor/insert-tag)
518 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
519 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
520 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
521 (define-key keymap "d" 'mime-editor/enclose-digest-region)
522 (define-key keymap "s" 'mime-editor/enclose-signed-region)
523 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
524 (define-key keymap "q" 'mime-editor/enclose-quote-region)
525 (define-key keymap "7" 'mime-editor/set-transfer-level-7bit)
526 (define-key keymap "8" 'mime-editor/set-transfer-level-8bit)
527 (define-key keymap "/" 'mime-editor/set-split)
528 (define-key keymap "v" 'mime-editor/set-sign)
529 (define-key keymap "h" 'mime-editor/set-encrypt)
530 (define-key keymap "\C-p" 'mime-editor/preview-message)
531 (define-key keymap "\C-z" 'mime-editor/exit)
532 (define-key keymap "?" 'mime-editor/help)
535 (mime-editor/define-keymap mime-editor/mime-map)
537 (defun mime-editor/toggle-mode ()
539 (if mime/editor-mode-flag
540 (mime-editor/exit 'nomime)
544 (cond (running-xemacs
545 (defconst mime-editor/minor-mime-map nil "Keymap for MIME commands.")
546 (or mime-editor/minor-mime-map
548 (setq mime-editor/minor-mime-map
549 (make-sparse-keymap 'mime-editor/minor-mime-map))
551 mime-editor/minor-mime-map mime-prefix mime-editor/mime-map)
553 (add-minor-mode 'mime/editor-mode-flag
554 '((" MIME-Edit " mime-editor/transfer-level-string))
555 mime-editor/minor-mime-map
557 'mime-editor/toggle-mode)
560 (set-alist 'minor-mode-alist
561 'mime/editor-mode-flag
562 '((" MIME-Edit " mime-editor/transfer-level-string))))
565 (defconst mime-editor/menu-title "MIME-Edit")
567 (defconst mime-editor/menu-list
568 '((mime-help "Describe MIME editor mode" mime-editor/help)
569 (file "Insert File" mime-editor/insert-file)
570 (external "Insert External" mime-editor/insert-external)
571 (voice "Insert Voice" mime-editor/insert-voice)
572 (message "Insert Message" mime-editor/insert-message)
573 (mail "Insert Mail" mime-editor/insert-mail)
574 (signature "Insert Signature" mime-editor/insert-signature)
575 (text "Insert Text" mime-editor/insert-text)
576 (tag "Insert Tag" mime-editor/insert-tag)
577 (alternative "Enclose as alternative"
578 mime-editor/enclose-alternative-region)
579 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
580 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
581 (digest "Enclose as digest" mime-editor/enclose-digest-region)
582 (signed "Enclose as signed" mime-editor/enclose-signed-region)
583 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
584 (quote "Verbatim region" mime-editor/enclose-quote-region)
585 (key "Insert Public Key" mime-editor/insert-key)
586 (split "About split" mime-editor/set-split)
587 (sign "About sign" mime-editor/set-sign)
588 (encrypt "About encryption" mime-editor/set-encrypt)
589 (preview "Preview Message" mime-editor/preview-message)
590 (level "Toggle transfer-level" mime-editor/toggle-transfer-level)
592 "MIME-edit menubar entry.")
594 (defun mime-editor/define-menu-for-emacs19 ()
595 "Define menu for Emacs 19."
596 (define-key (current-local-map) [menu-bar mime-edit]
597 (cons mime-editor/menu-title
598 (make-sparse-keymap mime-editor/menu-title)))
601 (define-key (current-local-map)
602 (vector 'menu-bar 'mime-edit (car item))
603 (cons (nth 1 item)(nth 2 item))
606 (reverse mime-editor/menu-list)
609 ;;; modified by Pekka Marjola <pema@iki.fi>
610 ;;; 1995/9/5 (c.f. [tm-en:69])
611 (defun mime-editor/define-menu-for-xemacs ()
612 "Define menu for Emacs 19."
613 (cond ((featurep 'menubar)
614 (make-local-variable 'current-menubar)
615 (set-buffer-menubar current-menubar)
617 (cons mime-editor/menu-title
620 (vector (nth 1 item)(nth 2 item)
621 mime/editor-mode-flag)
623 mime-editor/menu-list)))
626 ;;; modified by Steven L. Baur <steve@miranova.com>
627 ;;; 1995/12/6 (c.f. [tm-en:209])
628 (if (and running-xemacs (not (boundp 'mime-editor/popup-menu-for-xemacs)))
629 (setq mime-editor/popup-menu-for-xemacs
630 (append '("MIME Commands" "---")
631 (mapcar (function (lambda (item)
635 mime-editor/menu-list)))
644 (defun mime/editor-mode ()
645 "MIME minor mode for editing the tagged MIME message.
647 In this mode, basically, the message is composed in the tagged MIME
648 format. The message tag looks like:
650 --[[text/plain; charset=ISO-2022-JP][7bit]]
652 The tag specifies the MIME content type, subtype, optional parameters
653 and transfer encoding of the message following the tag. Messages
654 without any tag are treated as `text/plain' by default. Charset and
655 transfer encoding are automatically defined unless explicitly
656 specified. Binary messages such as audio and image are usually hidden.
657 The messages in the tagged MIME format are automatically translated
658 into a MIME compliant message when exiting this mode.
660 Available charsets depend on Emacs version being used. The following
661 lists the available charsets of each emacs.
663 EMACS 18: US-ASCII is only available.
664 NEmacs: US-ASCII and ISO-2022-JP are available.
665 EMACS 19: US-ASCII and ISO-8859-1 (or other charset) are available.
666 XEmacs 19: US-ASCII and ISO-8859-1 (or other charset) are available.
667 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
668 ISO-2022-JP, ISO-2022-JP-2, ISO-2022-KR, BIG5 and
669 ISO-2022-INT-1 are available.
671 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
672 be used to represent multilingual text in intermixed manner. Any
673 languages that has no registered charset are represented as either
674 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
676 If you want to use non-ISO-8859-1 charset in EMACS 19 or XEmacs 19,
677 please set variable `default-mime-charset'. This variable must be
678 symbol of which name is a MIME charset.
680 If you want to add more charsets in mule, please set variable
681 `charsets-mime-charset-alist'. This variable must be alist of which
682 key is list of leading-char/charset and value is symbol of MIME
683 charset. (leading-char is a term of MULE 1.* and 2.*. charset is a
684 term of XEmacs/mule, mule merged EMACS and MULE 3.*) If name of
685 coding-system is different as MIME charset, please set variable
686 `mime-charset-coding-system-alist'. This variable must be alist of
687 which key is MIME charset and value is coding-system.
689 Following commands are available in addition to major mode commands:
692 \\[mime-editor/insert-text] insert a text message.
693 \\[mime-editor/insert-file] insert a (binary) file.
694 \\[mime-editor/insert-external] insert a reference to external body.
695 \\[mime-editor/insert-voice] insert a voice message.
696 \\[mime-editor/insert-message] insert a mail or news message.
697 \\[mime-editor/insert-mail] insert a mail message.
698 \\[mime-editor/insert-signature] insert a signature file at end.
699 \\[mime-editor/insert-key] insert PGP public key.
700 \\[mime-editor/insert-tag] insert a new MIME tag.
702 \[make enclosure (maybe multipart)\]
703 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
704 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
705 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
706 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
707 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
708 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
709 \\[mime-editor/enclose-quote-region] enclose as verbose mode (to avoid to expand tags)
712 \\[mime-editor/set-transfer-level-7bit] set transfer-level as 7.
713 \\[mime-editor/set-transfer-level-8bit] set transfer-level as 8.
714 \\[mime-editor/set-split] set message splitting mode.
715 \\[mime-editor/set-sign] set PGP-sign mode.
716 \\[mime-editor/set-encrypt] set PGP-encryption mode.
717 \\[mime-editor/preview-message] preview editing MIME message.
718 \\[mime-editor/exit] exit and translate into a MIME compliant message.
719 \\[mime-editor/help] show this help.
720 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
722 Additional commands are available in some major modes:
723 C-c C-c exit, translate and run the original command.
724 C-c C-s exit, translate and run the original command.
726 The following is a message example written in the tagged MIME format.
727 TABs at the beginning of the line are not a part of the message:
729 This is a conventional plain text. It should be translated
732 This is also a plain text. But, it is explicitly specified as
734 --[[text/plain; charset=ISO-8859-1]]
735 This is also a plain text. But charset is specified as
738 ¡Hola! Buenos días. ¿Cómo está usted?
740 This is a <bold>enriched text</bold>.
741 --[[image/gif][base64]]...image encoded in base64 here...
742 --[[audio/basic][base64]]...audio encoded in base64 here...
744 User customizable variables (not documented all of them):
746 Specifies a key prefix for MIME minor mode commands.
748 mime-ignore-preceding-spaces
749 Preceding white spaces in a message body are ignored if non-nil.
751 mime-ignore-trailing-spaces
752 Trailing white spaces in a message body are ignored if non-nil.
755 Hide a non-textual body message encoded in base64 after insertion
758 mime-editor/transfer-level
759 A number of network transfer level. It should be bigger than 7.
760 If you are in 8bit-through environment, please set 8.
762 mime-editor/voice-recorder
763 Specifies a function to record a voice message and encode it.
764 The function `mime-editor/voice-recorder-for-sun' is for Sun
767 mime/editor-mode-hook
768 Turning on MIME mode calls the value of mime/editor-mode-hook, if
771 mime-editor/translate-hook
772 The value of mime-editor/translate-hook is called just before translating
773 the tagged MIME format into a MIME compliant message if it is
774 non-nil. If the hook call the function mime-editor/insert-signature,
775 the signature file will be inserted automatically.
777 mime-editor/exit-hook
778 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
781 (if mime/editor-mode-flag
782 (error "You are already editing a MIME message.")
783 (setq mime/editor-mode-flag t)
784 ;; Remember old key bindings.
786 (use-local-map (or (current-local-map) (make-sparse-keymap)))
787 (make-local-variable 'mime/editor-mode-old-local-map)
788 (setq mime/editor-mode-old-local-map (current-local-map))
789 ;; Add MIME commands to current local map.
790 (use-local-map (copy-keymap (or (current-local-map)
791 (make-sparse-keymap))))
793 (if (not (lookup-key (current-local-map) mime-prefix))
794 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
796 ;; Set transfer level into mode line
798 (setq mime-editor/transfer-level-string
799 (mime/encoding-name mime-editor/transfer-level 'not-omit))
800 (force-mode-line-update)
802 ;; Define menu. Menus for other emacs implementations are
804 (cond (running-xemacs
805 (mime-editor/define-menu-for-xemacs))
806 ((>= emacs-major-version 19)
807 (mime-editor/define-menu-for-emacs19)
813 ;; I don't care about saving these.
814 (setq paragraph-start
815 (regexp-or mime-editor/single-part-tag-regexp
817 (setq paragraph-separate
818 (regexp-or mime-editor/single-part-tag-regexp
820 (run-hooks 'mime/editor-mode-hook)
822 (substitute-command-keys
823 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
827 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
828 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
830 (defun mime-editor/exit (&optional nomime no-error)
831 "Translate the tagged MIME message into a MIME compliant message.
832 With no argument encode a message in the buffer into MIME, otherwise
833 just return to previous mode."
835 (if (not mime/editor-mode-flag)
837 (error "You aren't editing a MIME message.")
841 (run-hooks 'mime-editor/translate-hook)
842 (mime-editor/translate-buffer)))
843 ;; Restore previous state.
844 (setq mime/editor-mode-flag nil)
845 (cond (running-xemacs
846 (if (featurep 'menubar)
847 (delete-menu-item (list mime-editor/menu-title))))
849 (use-local-map mime/editor-mode-old-local-map)))
852 (set-buffer-modified-p (buffer-modified-p))
853 (run-hooks 'mime-editor/exit-hook)
854 (message "Exit MIME editor mode.")
857 (defun mime-editor/maybe-translate ()
859 (mime-editor/exit nil t)
860 (call-interactively 'mime-editor/maybe-split-and-send)
863 (defun mime-editor/help ()
864 "Show help message about MIME mode."
866 (with-output-to-temp-buffer "*Help*"
867 (princ "MIME editor mode:\n")
868 (princ (documentation 'mime/editor-mode))
869 (print-help-return-message)))
871 (defun mime-editor/insert-text ()
872 "Insert a text message.
873 Charset is automatically obtained from the `charsets-mime-charset-alist'."
875 (let ((ret (mime-editor/insert-tag "text" nil nil)))
878 (if (looking-at mime-editor/single-part-tag-regexp)
880 ;; Make a space between the following message.
884 (if (and (member (second ret) '("enriched" "richtext"))
885 (fboundp 'enriched-mode)
888 (if (boundp 'enriched-mode)
892 (defun mime-editor/insert-file (file &optional verbose)
893 "Insert a message from a file."
894 (interactive "fInsert file as MIME message: \nP")
895 (let* ((guess (mime-find-file-type file))
897 (subtype (nth 1 guess))
898 (parameters (nth 2 guess))
899 (encoding (nth 3 guess))
900 (disposition-type (nth 4 guess))
901 (disposition-params (nth 5 guess))
904 (setq type (mime-prompt-for-type type)
905 subtype (mime-prompt-for-subtype type subtype)
907 (if (or (interactive-p) verbose)
908 (setq encoding (mime-prompt-for-encoding encoding))
910 (if (or (consp parameters) (stringp disposition-type))
911 (let ((rest parameters) cell attribute value)
914 (setq cell (car rest))
915 (setq attribute (car cell))
916 (setq value (cdr cell))
918 (setq value (std11-wrap-as-quoted-string
919 (file-name-nondirectory file)))
921 (setq parameters (concat parameters "; " attribute "=" value))
922 (setq rest (cdr rest))
927 (concat parameters "\n"
928 "Content-Disposition: " disposition-type))
929 (setq rest disposition-params)
931 (setq cell (car rest))
932 (setq attribute (car cell))
933 (setq value (cdr cell))
935 (setq value (std11-wrap-as-quoted-string
936 (file-name-nondirectory file)))
939 (concat parameters "; " attribute "=" value))
940 (setq rest (cdr rest))
944 (mime-editor/insert-tag type subtype parameters)
945 (mime-editor/insert-binary-file file encoding)
948 (defun mime-editor/insert-external ()
949 "Insert a reference to external body."
951 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
953 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
955 (let* ((pritype (mime-prompt-for-type))
956 (subtype (mime-prompt-for-subtype pritype))
957 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
960 (insert "Content-Type: "
961 pritype "/" subtype (or parameters "") "\n")))
962 (if (and (not (eobp))
963 (not (looking-at mime-editor/single-part-tag-regexp)))
964 (insert (mime-make-text-tag) "\n")))
966 (defun mime-editor/insert-voice ()
967 "Insert a voice message."
971 "What transfer encoding: "
972 mime-file-encoding-method-alist nil t nil)))
973 (mime-editor/insert-tag "audio" "basic" nil)
974 (mime-editor/define-encoding encoding)
976 (narrow-to-region (1- (point))(point))
978 (funcall mime-editor/voice-recorder encoding)
981 (invisible-region (point-min)(point-max))
982 (goto-char (point-max))
985 (defun mime-editor/insert-signature (&optional arg)
986 "Insert a signature file."
988 (let ((signature-insert-hook
991 (apply (function mime-editor/insert-tag)
992 (mime-find-file-type signature-file-name))
995 (insert-signature arg)
999 ;; Insert a new tag around a point.
1001 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
1002 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
1003 If nothing is inserted, return nil."
1006 (mime-editor/goto-tag)
1007 (if (and (re-search-forward mime-editor/tag-regexp nil t)
1008 (< (match-beginning 0) p)
1011 (goto-char (match-beginning 0))
1020 (mime-prompt-for-type)))
1023 (mime-prompt-for-subtype pritype)))
1026 (mime-prompt-for-parameters pritype subtype delimiter)))
1027 ;; Make a new MIME tag.
1028 (setq newtag (mime-make-tag pritype subtype parameters))
1029 ;; Find an current MIME tag.
1032 (if (mime-editor/goto-tag)
1033 (buffer-substring (match-beginning 0) (match-end 0))
1034 ;; Assume content type is 'text/plan'.
1035 (mime-make-tag "text" "plain")
1037 ;; We are only interested in TEXT.
1039 (not (mime-test-content-type
1040 (mime-editor/get-contype oldtag) "text")))
1043 (if (or (not oldtag) ;Not text
1044 (or mime-ignore-same-text-tag
1045 (not (string-equal oldtag newtag))))
1047 ;; Mark the beginning of the tag for convenience.
1048 (push-mark (point) 'nomsg)
1049 (insert newtag "\n")
1050 (list pritype subtype parameters) ;New tag is created.
1052 ;; Restore previous point.
1054 nil ;Nothing is created.
1058 (defun mime-editor/insert-binary-file (file &optional encoding)
1059 "Insert binary FILE at point.
1060 Optional argument ENCODING specifies an encoding method such as base64."
1061 (let* ((tagend (1- (point))) ;End of the tag
1062 (hide-p (and mime-auto-hide-body
1065 (let ((en (downcase encoding)))
1066 (or (string-equal en "7bit")
1067 (string-equal en "8bit")
1068 (string-equal en "binary")
1072 (narrow-to-region tagend (point))
1073 (mime-insert-encoded-file file encoding)
1076 (invisible-region (point-min) (point-max))
1077 (goto-char (point-max))
1079 (goto-char (point-max))
1082 (looking-at mime-editor/tag-regexp)
1083 (= (point)(point-max))
1084 (mime-editor/insert-tag "text" "plain")
1086 ;; Define encoding even if it is 7bit.
1087 (if (stringp encoding)
1089 (goto-char tagend) ; Make sure which line the tag is on.
1090 (mime-editor/define-encoding encoding)
1095 ;; Commands work on a current message flagment.
1097 (defun mime-editor/goto-tag ()
1098 "Search for the beginning of the tagged MIME message."
1099 (let ((current (point)) multipart)
1100 (if (looking-at mime-editor/tag-regexp)
1102 ;; At first, go to the end.
1103 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1104 (goto-char (1- (match-beginning 0))) ;For multiline tag
1107 (goto-char (point-max))
1109 ;; Then search for the beginning.
1110 (re-search-backward mime-editor/end-tag-regexp nil t)
1111 (or (looking-at mime-editor/beginning-tag-regexp)
1112 ;; Restore previous point.
1119 (defun mime-editor/content-beginning ()
1120 "Return the point of the beginning of content."
1122 (let ((beg (save-excursion
1123 (beginning-of-line) (point))))
1124 (if (mime-editor/goto-tag)
1125 (let ((top (point)))
1126 (goto-char (match-end 0))
1127 (if (and (= beg top)
1128 (= (following-char) ?\^M))
1132 ;; Default text/plain tag.
1133 (goto-char (point-min))
1135 (concat "\n" (regexp-quote mail-header-separator)
1136 (if mime-ignore-preceding-spaces
1137 "[ \t\n]*\n" "\n")) nil 'move)
1141 (defun mime-editor/content-end ()
1142 "Return the point of the end of content."
1144 (let ((beg (point)))
1145 (if (mime-editor/goto-tag)
1146 (let ((top (point)))
1147 (goto-char (match-end 0))
1148 (if (invisible-p (point))
1149 (next-visible-point (point))
1150 ;; Move to the end of this text.
1151 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1152 ;; Don't forget a multiline tag.
1153 (goto-char (match-beginning 0))
1157 ;; Assume the message begins with text/plain.
1158 (goto-char (mime-editor/content-beginning))
1159 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1160 ;; Don't forget a multiline tag.
1161 (goto-char (match-beginning 0)))
1165 (defun mime-editor/define-charset (charset)
1166 "Set charset of current tag to CHARSET."
1168 (if (mime-editor/goto-tag)
1169 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1170 (delete-region (match-beginning 0) (match-end 0))
1173 (mime-editor/set-parameter
1174 (mime-editor/get-contype tag)
1175 "charset" (upcase (symbol-name charset)))
1176 (mime-editor/get-encoding tag)))
1179 (defun mime-editor/define-encoding (encoding)
1180 "Set encoding of current tag to ENCODING."
1182 (if (mime-editor/goto-tag)
1183 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1184 (delete-region (match-beginning 0) (match-end 0))
1185 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1188 (defun mime-editor/choose-charset ()
1189 "Choose charset of a text following current point."
1190 (detect-mime-charset-region (point) (mime-editor/content-end))
1193 (defun mime-make-text-tag (&optional subtype)
1194 "Make a tag for a text after current point.
1195 Subtype of text type can be specified by an optional argument SUBTYPE.
1196 Otherwise, it is obtained from mime-content-types."
1197 (let* ((pritype "text")
1198 (subtype (or subtype
1199 (car (car (cdr (assoc pritype mime-content-types)))))))
1200 ;; Charset should be defined later.
1201 (mime-make-tag pritype subtype)))
1204 ;; Tag handling functions
1206 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1207 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1208 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1212 (defun mime-create-tag (contype &optional encoding)
1213 "Make a tag with CONTENT-TYPE and optional ENCODING."
1214 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1217 (defun mime-editor/get-contype (tag)
1218 "Return Content-Type (including parameters) of TAG."
1220 (or (string-match mime-editor/single-part-tag-regexp tag)
1221 (string-match mime-editor/multipart-beginning-regexp tag)
1222 (string-match mime-editor/multipart-end-regexp tag)
1224 (substring tag (match-beginning 1) (match-end 1))
1227 (defun mime-editor/get-encoding (tag)
1228 "Return encoding of TAG."
1230 (string-match mime-editor/single-part-tag-regexp tag)
1232 (not (= (match-beginning 3) (match-end 3)))
1233 (substring tag (match-beginning 3) (match-end 3))))
1235 (defun mime-get-parameter (contype parameter)
1236 "For given CONTYPE return value for PARAMETER.
1237 Nil if no such parameter."
1241 (regexp-quote parameter)
1242 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1244 (substring contype (match-beginning 1) (match-end 1))
1245 nil ;No such parameter
1248 (defun mime-editor/set-parameter (contype parameter value)
1249 "For given CONTYPE set PARAMETER to VALUE."
1250 (let (ctype opt-fields)
1251 (if (string-match "\n[^ \t\n\r]+:" contype)
1252 (setq ctype (substring contype 0 (match-beginning 0))
1253 opt-fields (substring contype (match-beginning 0)))
1254 (setq ctype contype)
1259 (regexp-quote parameter)
1260 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1263 (concat (substring ctype 0 (match-beginning 1))
1265 (substring contype (match-end 1))
1267 (concat ctype "; " parameter "=" value opt-fields)
1270 (defun mime-strip-parameters (contype)
1271 "Return primary content-type and subtype without parameters for CONTYPE."
1272 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1273 (substring contype (match-beginning 1) (match-end 1)) nil))
1275 (defun mime-test-content-type (contype type &optional subtype)
1276 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1277 (and (stringp contype)
1280 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1281 (downcase contype))))
1286 (defun mime-find-file-type (file)
1287 "Guess Content-Type, subtype, and parameters from FILE."
1289 (guesses mime-file-types))
1290 (while (and (not guess) guesses)
1291 (if (string-match (car (car guesses)) file)
1292 (setq guess (cdr (car guesses))))
1293 (setq guesses (cdr guesses)))
1297 (defun mime-prompt-for-type (&optional default)
1298 "Ask for Content-type."
1300 ;; Repeat until primary content type is specified.
1301 (while (string-equal type "")
1303 (completing-read "What content type: "
1306 'require-match ;Type must be specified.
1309 (if (string-equal type "")
1311 (message "Content type is required.")
1318 (defun mime-prompt-for-subtype (type &optional default)
1319 "Ask for subtype of media-type TYPE."
1320 (let ((subtypes (cdr (assoc type mime-content-types))))
1322 (assoc default subtypes))
1323 (setq default (car (car subtypes)))
1329 "What content subtype: (default " default ") ")
1330 "What content subtype: ")
1331 (cdr (assoc type mime-content-types))
1333 'require-match ;Subtype must be specified.
1336 (if (string-equal answer "") default answer)))
1338 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1339 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1340 Optional DELIMITER specifies parameter delimiter (';' by default)."
1341 (let* ((delimiter (or delimiter "; "))
1346 (mime-prompt-for-parameters-1
1348 (cdr (assoc pritype mime-content-types))))))
1351 (if (and (stringp parameters)
1352 (not (string-equal parameters "")))
1353 (concat delimiter parameters)
1354 "" ;"" if no parameters
1357 (defun mime-prompt-for-parameters-1 (optlist)
1358 (apply (function append)
1359 (mapcar (function mime-prompt-for-parameter) optlist)))
1361 (defun mime-prompt-for-parameter (parameter)
1363 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1364 (let* ((prompt (car parameter))
1365 (choices (mapcar (function
1367 (if (consp e) e (list e))))
1369 (default (car (car choices)))
1375 (concat "What " prompt
1377 (if (string-equal default "") "\"\"" default)
1379 choices nil nil ""))
1380 ;; If nothing is selected, use default.
1381 (if (string-equal answer "")
1382 (setq answer default)))
1384 (read-string (concat "What " prompt ": "))))
1385 (cons (if (and answer
1386 (not (string-equal answer "")))
1388 ;; Note: control characters ignored!
1389 (if (string-match mime-tspecials-regexp answer)
1390 (concat "\"" answer "\"") answer)))
1391 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1394 (defun mime-prompt-for-encoding (default)
1395 "Ask for Content-Transfer-Encoding. [tm-edit.el]"
1400 "What transfer encoding: "
1401 mime-file-encoding-method-alist nil t default)
1407 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1410 (defvar mime-editor/translate-buffer-hook
1411 '(mime-editor/pgp-enclose-buffer
1412 mime-editor/translate-header
1413 mime-editor/translate-body))
1415 (defun mime-editor/translate-header ()
1416 "Encode the message header into network representation."
1417 (mime/encode-message-header 'code-conversion)
1418 (run-hooks 'mime-editor/translate-header-hook)
1421 (defun mime-editor/translate-buffer ()
1422 "Encode the tagged MIME message in current buffer in MIME compliant message."
1424 (if (catch 'mime-editor/error
1426 (run-hooks 'mime-editor/translate-buffer-hook)
1430 (error "Translation error!")
1433 (defun mime-editor/find-inmost ()
1434 (goto-char (point-min))
1435 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1436 (let ((bb (match-beginning 0))
1438 (type (buffer-substring (match-beginning 1)(match-end 1)))
1440 (setq end-exp (format "--}-<<%s>>\n" type))
1442 (if (re-search-forward end-exp nil t)
1444 (setq eb (match-beginning 0))
1445 (setq ee (match-end 0))
1447 (setq eb (point-max))
1448 (setq ee (point-max))
1450 (narrow-to-region be eb)
1452 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1454 (narrow-to-region (match-beginning 0)(point-max))
1455 (mime-editor/find-inmost)
1458 (list type bb be eb)
1461 (defun mime-editor/process-multipart-1 (boundary)
1462 (let ((ret (mime-editor/find-inmost)))
1464 (let ((type (car ret))
1465 (bb (nth 1 ret))(be (nth 2 ret))
1468 (narrow-to-region bb eb)
1469 (delete-region bb be)
1470 (setq bb (point-min))
1471 (setq eb (point-max))
1474 (if (looking-at mime-editor/multipart-end-regexp)
1475 (let ((beg (match-beginning 0))
1478 (delete-region beg end)
1479 (or (looking-at mime-editor/beginning-tag-regexp)
1481 (insert (concat (mime-make-text-tag) "\n"))
1483 (cond ((string-equal type "quote")
1484 (mime-editor/enquote-region bb eb)
1486 ((string-equal type "signed")
1487 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1488 (mime-editor/sign-pgp-elkins bb eb boundary)
1490 ((eq mime-editor/signing-type 'pgp-kazu)
1491 (mime-editor/sign-pgp-kazu bb eb boundary)
1494 ((string-equal type "encrypted")
1495 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1496 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1498 ((eq mime-editor/encrypting-type 'pgp-kazu)
1499 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1503 (nth 2 (mime-editor/translate-region bb eb
1507 (format "--[[multipart/%s;
1508 boundary=\"%s\"][7bit]]\n"
1513 (defun mime-editor/enquote-region (beg end)
1516 (narrow-to-region beg end)
1518 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1519 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1520 (replace-match (concat "- " (substring tag 1)))
1523 (defun mime-editor/dequote-region (beg end)
1526 (narrow-to-region beg end)
1528 (while (re-search-forward
1529 mime-editor/quoted-single-part-tag-regexp nil t)
1530 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1531 (replace-match (concat "-" (substring tag 2)))
1534 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1537 (narrow-to-region beg end)
1539 (mime-editor/translate-region beg end boundary))
1541 (encoding (nth 1 ret))
1543 (pgp-boundary (concat "pgp-sign-" boundary))
1546 (insert (format "Content-Type: %s\n" ctype))
1548 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1551 (or (funcall (pgp-function 'mime-sign)
1552 (point-min)(point-max) nil nil pgp-boundary)
1553 (throw 'mime-editor/error 'pgp-error)
1557 (defvar mime-editor/encrypt-recipient-fields-list '("To" "cc"))
1559 (defun mime-editor/make-encrypt-recipient-header ()
1560 (let* ((names mime-editor/encrypt-recipient-fields-list)
1562 (std11-field-bodies (cons "From" names)
1563 nil mail-header-separator))
1566 (setq values (cdr values))))
1567 (header (and (stringp from)
1568 (if (string-equal from "")
1570 (format "From: %s\n" from)
1573 (while (and names values)
1574 (let ((name (car names))
1575 (value (car values))
1577 (and (stringp value)
1578 (or (string-equal value "")
1580 (setq header (concat header name ": " value "\n")
1581 recipients (if recipients
1582 (concat recipients " ," value)
1585 (setq names (cdr names)
1586 values (cdr values))
1588 (vector from recipients header)
1591 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1594 (let (from recipients header)
1595 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1596 (setq from (aref ret 0)
1597 recipients (aref ret 1)
1598 header (aref ret 2))
1600 (narrow-to-region beg end)
1602 (mime-editor/translate-region beg end boundary))
1604 (encoding (nth 1 ret))
1606 (pgp-boundary (concat "pgp-" boundary))
1610 (insert (format "Content-Type: %s\n" ctype))
1612 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1615 (or (funcall (pgp-function 'encrypt)
1616 recipients (point-min) (point-max) from)
1617 (throw 'mime-editor/error 'pgp-error)
1620 (insert (format "--[[multipart/encrypted;
1622 protocol=\"application/pgp-encrypted\"][7bit]]
1624 Content-Type: application/pgp-encrypted
1627 Content-Type: application/octet-stream
1628 Content-Transfer-Encoding: 7bit
1630 " pgp-boundary pgp-boundary pgp-boundary))
1631 (goto-char (point-max))
1632 (insert (format "\n--%s--\n" pgp-boundary))
1635 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1638 (narrow-to-region beg end)
1640 (mime-editor/translate-region beg end boundary))
1642 (encoding (nth 1 ret))
1646 (insert (format "Content-Type: %s\n" ctype))
1648 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1651 (or (as-binary-process
1652 (funcall (pgp-function 'traditional-sign)
1654 (throw 'mime-editor/error 'pgp-error)
1658 "--[[application/pgp; format=mime][7bit]]\n")
1662 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1664 (let (from recipients header)
1665 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1666 (setq from (aref ret 0)
1667 recipients (aref ret 1)
1668 header (aref ret 2))
1671 (narrow-to-region beg end)
1673 (mime-editor/translate-region beg end boundary))
1675 (encoding (nth 1 ret))
1680 (insert (format "Content-Type: %s\n" ctype))
1682 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1685 (or (as-binary-process
1686 (funcall (pgp-function 'encrypt)
1687 recipients beg (point-max) nil 'maybe)
1689 (throw 'mime-editor/error 'pgp-error)
1693 "--[[application/pgp; format=mime][7bit]]\n")
1697 (defun mime-editor/translate-body ()
1698 "Encode the tagged MIME body in current buffer in MIME compliant message."
1702 (concat mime-multipart-boundary "_"
1703 (replace-space-with-underline (current-time-string))
1707 (while (mime-editor/process-multipart-1
1708 (format "%s-%d" boundary i))
1712 ;; We are interested in message body.
1715 (goto-char (point-min))
1717 (concat "\n" (regexp-quote mail-header-separator)
1718 (if mime-ignore-preceding-spaces
1719 "[ \t\n]*\n" "\n")) nil 'move)
1723 (goto-char (point-max))
1724 (and mime-ignore-trailing-spaces
1725 (re-search-backward "[^ \t\n]\n" beg t)
1728 (setq ret (mime-editor/translate-region
1730 (format "%s-%d" boundary i)))
1732 (mime-editor/dequote-region (point-min)(point-max))
1733 (let ((contype (car ret)) ;Content-Type
1734 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1736 ;; Make primary MIME headers.
1737 (or (mail-position-on-field "Mime-Version")
1738 (insert mime-editor/mime-version-value))
1739 ;; Remove old Content-Type and other fields.
1741 (goto-char (point-min))
1742 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1743 (narrow-to-region (point-min) (point))
1744 (goto-char (point-min))
1745 (mime-delete-field "Content-Type")
1746 (mime-delete-field "Content-Transfer-Encoding"))
1747 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1748 (mail-position-on-field "Content-Type")
1752 (mail-position-on-field "Content-Transfer-Encoding")
1756 (defun mime-editor/translate-single-part-tag (&optional prefix)
1757 (if (re-search-forward mime-editor/single-part-tag-regexp nil t)
1758 (let* ((beg (match-beginning 0))
1760 (tag (buffer-substring beg end))
1762 (delete-region beg end)
1763 (setq contype (mime-editor/get-contype tag))
1764 (setq encoding (mime-editor/get-encoding tag))
1765 (insert (concat prefix "--" boundary "\n"))
1767 (narrow-to-region (point)(point))
1768 (insert "Content-Type: " contype "\n")
1770 (insert "Content-Transfer-Encoding: " encoding "\n"))
1771 (mime/encode-message-header)
1775 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1778 (concat mime-multipart-boundary "_"
1779 (replace-space-with-underline (current-time-string))))
1783 (narrow-to-region beg end)
1784 (let ((tag nil) ;MIME tag
1785 (contype nil) ;Content-Type
1786 (encoding nil) ;Content-Transfer-Encoding
1787 (nparts 0)) ;Number of body parts
1788 ;; Normalize the body part by inserting appropriate message
1789 ;; tags for every message contents.
1790 (mime-editor/normalize-body)
1791 ;; Counting the number of Content-Type.
1792 (goto-char (point-min))
1793 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1794 (setq nparts (1+ nparts)))
1795 ;; Begin translation.
1797 ((and (<= nparts 1)(not multipart))
1798 ;; It's a singular message.
1799 (goto-char (point-min))
1800 (while (re-search-forward
1801 mime-editor/single-part-tag-regexp nil t)
1803 (buffer-substring (match-beginning 0) (match-end 0)))
1804 (delete-region (match-beginning 0) (1+ (match-end 0)))
1805 (setq contype (mime-editor/get-contype tag))
1806 (setq encoding (mime-editor/get-encoding tag))
1809 ;; It's a multipart message.
1810 (goto-char (point-min))
1811 (and (mime-editor/translate-single-part-tag)
1812 (while (mime-editor/translate-single-part-tag "\n"))
1814 ;; Define Content-Type as "multipart/mixed".
1816 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1817 ;; Content-Transfer-Encoding must be "7bit".
1818 ;; The following encoding can be `nil', but is
1819 ;; specified as is since there is no way that a user
1821 (setq encoding "7bit")
1822 ;; Insert the trailer.
1823 (goto-char (point-max))
1824 (insert "\n--" boundary "--\n")
1826 (list contype encoding boundary nparts)
1829 (defun mime-editor/normalize-body ()
1830 "Normalize the body part by inserting appropriate message tags."
1831 ;; Insert the first MIME tags if necessary.
1832 (goto-char (point-min))
1833 (if (not (looking-at mime-editor/single-part-tag-regexp))
1834 (insert (mime-make-text-tag) "\n"))
1835 ;; Check each tag, and add new tag or correct it if necessary.
1836 (goto-char (point-min))
1837 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1838 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1839 (contype (mime-editor/get-contype tag))
1840 (charset (mime-get-parameter contype "charset"))
1841 (encoding (mime-editor/get-encoding tag)))
1842 ;; Remove extra whitespaces after the tag.
1843 (if (looking-at "[ \t]+$")
1844 (delete-region (match-beginning 0) (match-end 0)))
1846 (end (mime-editor/content-end))
1848 (if (= end (point-max))
1851 (or (looking-at mime-editor/beginning-tag-regexp)
1853 (insert (mime-make-text-tag) "\n")
1855 (visible-region beg end)
1859 ((mime-test-content-type contype "message")
1860 ;; Content-type "message" should be sent as is.
1863 ((mime-test-content-type contype "text")
1864 ;; Define charset for text if necessary.
1865 (setq charset (if charset
1866 (intern (downcase charset))
1867 (mime-editor/choose-charset)))
1868 (mime-editor/define-charset charset)
1869 (cond ((string-equal contype "text/x-rot13-47")
1873 (goto-char (mime-editor/content-end))
1876 ((string-equal contype "text/enriched")
1881 (end (mime-editor/content-end))
1883 ;; Patch for hard newlines
1886 ;; (while (search-forward "\n" end t)
1887 ;; (put-text-property (match-beginning 0)
1890 ;; End patch for hard newlines
1891 (enriched-encode beg end)
1893 (if (search-forward "\n\n")
1894 (delete-region beg (match-end 0))
1897 ;; Point is now on current tag.
1898 ;; Define encoding and encode text if necessary.
1899 (or encoding ;Encoding is not specified.
1903 mime-editor/charset-default-encoding-alist)
1905 (beg (mime-editor/content-beginning))
1907 (encode-mime-charset-region beg (mime-editor/content-end)
1909 (mime-encode-region beg (mime-editor/content-end) encoding)
1910 (mime-editor/define-encoding encoding)
1912 (goto-char (mime-editor/content-end))
1914 ((null encoding) ;Encoding is not specified.
1915 ;; Application, image, audio, video, and any other
1916 ;; unknown content-type without encoding should be
1918 (let* ((encoding "base64") ;Encode in BASE64 by default.
1919 (beg (mime-editor/content-beginning))
1920 (end (mime-editor/content-end))
1921 (body (buffer-substring beg end))
1923 (mime-encode-region beg end encoding)
1924 (mime-editor/define-encoding encoding))
1929 (defun mime-delete-field (field)
1930 "Delete header FIELD."
1931 (let ((regexp (format "^%s:[ \t]*" field)))
1932 (goto-char (point-min))
1933 (while (re-search-forward regexp nil t)
1934 (delete-region (match-beginning 0)
1935 (progn (forward-line 1) (point)))
1940 ;;; Platform dependent functions
1943 ;; Sun implementations
1945 (defun mime-editor/voice-recorder-for-sun (encoding)
1946 "Record voice in a buffer using Sun audio device,
1947 and insert data encoded as ENCODING. [tm-edit.el]"
1948 (message "Start the recording on %s. Type C-g to finish the recording..."
1950 (mime-insert-encoded-file "/dev/audio" encoding)
1954 ;;; @ Other useful commands.
1957 ;; Message forwarding commands as content-type "message/rfc822".
1959 (defun mime-editor/insert-message (&optional message)
1961 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
1962 (if (and inserter (fboundp inserter))
1964 (mime-editor/insert-tag "message" "rfc822")
1965 (funcall inserter message)
1967 (message "Sorry, I don't have message inserter for your MUA.")
1970 (defun mime-editor/insert-mail (&optional message)
1972 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
1973 (if (and inserter (fboundp inserter))
1975 (mime-editor/insert-tag "message" "rfc822")
1976 (funcall inserter message)
1978 (message "Sorry, I don't have mail inserter for your MUA.")
1981 (defun mime-editor/inserted-message-filter ()
1984 (let ((header-start (point))
1985 (case-fold-search t)
1988 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
1989 (if (re-search-forward "^$" (mark t))
1990 (narrow-to-region header-start (match-beginning 0))
1992 (goto-char header-start)
1993 (while (and (re-search-forward
1994 mime-editor/yank-ignored-field-regexp nil t)
1995 (setq beg (match-beginning 0))
1996 (setq end (1+ (std11-field-end)))
1998 (delete-region beg end)
2003 ;;; @ multipart enclosure
2006 (defun mime-editor/enclose-region (type beg end)
2009 (let ((current (point)))
2011 (narrow-to-region beg end)
2012 (insert (format "--<<%s>>-{\n" type))
2013 (goto-char (point-max))
2014 (insert (format "--}-<<%s>>\n" type))
2015 (goto-char (point-max))
2017 (or (looking-at mime-editor/beginning-tag-regexp)
2019 (insert (mime-make-text-tag) "\n")
2023 (defun mime-editor/enclose-quote-region (beg end)
2025 (mime-editor/enclose-region "quote" beg end)
2028 (defun mime-editor/enclose-mixed-region (beg end)
2030 (mime-editor/enclose-region "mixed" beg end)
2033 (defun mime-editor/enclose-parallel-region (beg end)
2035 (mime-editor/enclose-region "parallel" beg end)
2038 (defun mime-editor/enclose-digest-region (beg end)
2040 (mime-editor/enclose-region "digest" beg end)
2043 (defun mime-editor/enclose-alternative-region (beg end)
2045 (mime-editor/enclose-region "alternative" beg end)
2048 (defun mime-editor/enclose-signed-region (beg end)
2050 (if mime-editor/signing-type
2051 (mime-editor/enclose-region "signed" beg end)
2052 (message "Please specify signing type.")
2055 (defun mime-editor/enclose-encrypted-region (beg end)
2057 (if mime-editor/signing-type
2058 (mime-editor/enclose-region "encrypted" beg end)
2059 (message "Please specify encrypting type.")
2062 (defun mime-editor/insert-key (&optional arg)
2063 "Insert a pgp public key."
2065 (mime-editor/insert-tag "application" "pgp-keys")
2066 (mime-editor/define-encoding "7bit")
2067 (funcall (pgp-function 'insert-key))
2074 (defun mime-editor/set-split (arg)
2077 (y-or-n-p "Do you want to enable split?")
2079 (setq mime-editor/split-message arg)
2081 (message "This message is enabled to split.")
2082 (message "This message is not enabled to split.")
2085 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2086 "Toggle transfer-level is 7bit or 8bit through.
2088 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2090 (if (numberp transfer-level)
2091 (setq mime-editor/transfer-level transfer-level)
2092 (if (< mime-editor/transfer-level 8)
2093 (setq mime-editor/transfer-level 8)
2094 (setq mime-editor/transfer-level 7)
2096 (setq mime-editor/charset-default-encoding-alist
2097 (mime-editor/make-charset-default-encoding-alist
2098 mime-editor/transfer-level))
2099 (message (format "Current transfer-level is %d bit"
2100 mime-editor/transfer-level))
2101 (setq mime-editor/transfer-level-string
2102 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2103 (force-mode-line-update)
2106 (defun mime-editor/set-transfer-level-7bit ()
2108 (mime-editor/toggle-transfer-level 7)
2111 (defun mime-editor/set-transfer-level-8bit ()
2113 (mime-editor/toggle-transfer-level 8)
2120 (defun mime-editor/set-sign (arg)
2123 (y-or-n-p "Do you want to sign?")
2126 (if mime-editor/signing-type
2128 (setq mime-editor/pgp-processing 'sign)
2129 (message "This message will be signed.")
2131 (message "Please specify signing type.")
2133 (if (eq mime-editor/pgp-processing 'sign)
2134 (setq mime-editor/pgp-processing nil)
2136 (message "This message will not be signed.")
2139 (defun mime-editor/set-encrypt (arg)
2142 (y-or-n-p "Do you want to encrypt?")
2145 (if mime-editor/encrypting-type
2147 (setq mime-editor/pgp-processing 'encrypt)
2148 (message "This message will be encrypt.")
2150 (message "Please specify encrypting type.")
2152 (if (eq mime-editor/pgp-processing 'encrypt)
2153 (setq mime-editor/pgp-processing nil)
2155 (message "This message will not be encrypt.")
2158 (defvar mime-editor/pgp-processing nil)
2159 (make-variable-buffer-local 'mime-editor/pgp-processing)
2161 (defun mime-editor/pgp-enclose-buffer ()
2162 (let ((beg (save-excursion
2163 (goto-char (point-min))
2164 (if (search-forward (concat "\n" mail-header-separator "\n"))
2170 (cond ((eq mime-editor/pgp-processing 'sign)
2171 (mime-editor/enclose-signed-region beg end)
2173 ((eq mime-editor/pgp-processing 'encrypt)
2174 (mime-editor/enclose-encrypted-region beg end)
2182 (defun mime-editor/insert-partial-header
2183 (fields subject id number total separator)
2185 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2186 (insert (format "Mime-Version: 1.0 (split by %s)\n"
2187 mime-editor/version-name))
2189 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2190 id number total separator))
2193 (defun mime-editor/split-and-send
2194 (&optional cmd lines mime-editor/message-max-length)
2198 (count-lines (point-min) (point-max)))
2200 (or mime-editor/message-max-length
2201 (setq mime-editor/message-max-length
2202 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
2203 mime-editor/message-default-max-lines))
2205 (let* ((mime-editor/draft-file-name
2206 (or (buffer-file-name)
2208 (expand-file-name "tm-draft" mime/tmp-dir))))
2209 (separator mail-header-separator)
2211 (replace-space-with-underline (current-time-string))
2212 "@" (system-name) "\"")))
2213 (run-hooks 'mime-editor/before-split-hook)
2214 (let ((the-buf (current-buffer))
2215 (copy-buf (get-buffer-create " *Original Message*"))
2216 (header (std11-header-string-except
2217 mime-editor/split-ignored-field-regexp separator))
2218 (subject (mail-fetch-field "subject"))
2219 (total (+ (/ lines mime-editor/message-max-length)
2220 (if (> (mod lines mime-editor/message-max-length) 0)
2226 mime-editor/split-message-sender-alist))
2230 (error "Split sender is not specified for `%s'." major-mode)
2233 (mime-editor/partial-number 1)
2236 (set-buffer copy-buf)
2238 (insert-buffer the-buf)
2240 (if (re-search-forward
2241 (concat "^" (regexp-quote separator) "$") nil t)
2242 (let ((he (match-beginning 0)))
2244 (narrow-to-region (point-min) he)
2246 (goto-char (point-min))
2247 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
2248 (delete-region (match-beginning 0)
2249 (1+ (std11-field-end)))
2251 (while (< mime-editor/partial-number total)
2254 (set-buffer copy-buf)
2255 (setq data (buffer-substring
2258 (goto-line mime-editor/message-max-length)
2261 (delete-region (point-min)(point))
2263 (mime-editor/insert-partial-header
2264 header subject id mime-editor/partial-number total separator)
2267 (message (format "Sending %d/%d..."
2268 mime-editor/partial-number total))
2269 (call-interactively command)
2270 (message (format "Sending %d/%d... done"
2271 mime-editor/partial-number total))
2273 (setq mime-editor/partial-number
2274 (1+ mime-editor/partial-number))
2278 (set-buffer copy-buf)
2279 (setq data (buffer-string))
2282 (mime-editor/insert-partial-header
2283 header subject id mime-editor/partial-number total separator)
2286 (message (format "Sending %d/%d..."
2287 mime-editor/partial-number total))
2288 (message (format "Sending %d/%d... done"
2289 mime-editor/partial-number total))
2293 (defun mime-editor/maybe-split-and-send (&optional cmd)
2295 (run-hooks 'mime-editor/before-send-hook)
2296 (let ((mime-editor/message-max-length
2297 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
2298 mime-editor/message-default-max-lines))
2299 (lines (count-lines (point-min) (point-max)))
2301 (if (and (> lines mime-editor/message-max-length)
2302 mime-editor/split-message)
2303 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2307 ;;; @ preview message
2310 (defun mime-editor/preview-message ()
2311 "preview editing MIME message. [tm-edit.el]"
2313 (let* ((str (buffer-string))
2314 (separator mail-header-separator)
2315 (the-buf (current-buffer))
2316 (buf-name (buffer-name))
2317 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2318 (buf (get-buffer temp-buf-name))
2322 (switch-to-buffer buf)
2325 (setq buf (get-buffer-create temp-buf-name))
2326 (switch-to-buffer buf)
2329 (setq major-mode 'mime/temporary-message-mode)
2330 (make-local-variable 'mail-header-separator)
2331 (setq mail-header-separator separator)
2332 (make-local-variable 'mime/editing-buffer)
2333 (setq mime/editing-buffer the-buf)
2335 (run-hooks 'mime-editor/translate-hook)
2336 (mime-editor/translate-buffer)
2337 (goto-char (point-min))
2338 (if (re-search-forward
2339 (concat "^" (regexp-quote separator) "$"))
2345 (defun mime-editor/quitting-method ()
2346 (let ((temp mime::preview/article-buffer)
2348 (mime-viewer/kill-buffer)
2350 (setq buf mime/editing-buffer)
2352 (switch-to-buffer buf)
2355 (set-alist 'mime-viewer/quitting-method-alist
2356 'mime/temporary-message-mode
2357 (function mime-editor/quitting-method)
2363 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2364 ;; Mon, 10 Apr 1995 20:03:07 +0900
2366 (defvar mime-editor/draft-header-separator-alist
2367 '((news-reply-mode . mail-header-separator)
2368 (mh-letter-mode . mail-header-separator)
2371 (defvar mime::article/draft-header-separator nil)
2373 (defun mime-editor/draft-preview ()
2375 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2376 (or (stringp sep) (setq sep (eval sep)))
2377 (make-variable-buffer-local 'mime::article/draft-header-separator)
2378 (goto-char (point-min))
2380 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2381 (setq mime::article/draft-header-separator
2382 (buffer-substring (match-beginning 0) (match-end 0)))
2384 (mime/viewer-mode (current-buffer))
2385 (pop-to-buffer (current-buffer))
2388 (defun mime-viewer::quitting-method/draft-preview ()
2389 (let ((mother mime::preview/mother-buffer))
2391 (switch-to-buffer mother)
2392 (goto-char (point-min))
2396 (regexp-quote mime::article/draft-header-separator)
2400 (insert mime::article/draft-header-separator)
2401 (set-buffer-modified-p (buffer-modified-p))
2403 (mime-viewer/kill-buffer)
2404 (pop-to-buffer mother)
2407 (set-alist 'mime-viewer/quitting-method-alist
2409 (function mime-viewer::quitting-method/draft-preview)
2412 (set-alist 'mime-viewer/quitting-method-alist
2414 (function mime-viewer::quitting-method/draft-preview)
2421 (defun mime-editor::edit-again (code-conversion)
2423 (goto-char (point-min))
2424 (let ((ctl (mime/Content-Type)))
2426 (let ((ctype (car ctl))
2429 (if (string-match "/" ctype)
2431 (setq type (substring ctype 0 (match-beginning 0)))
2432 (setq stype (substring ctype (match-end 0)))
2437 ((string= ctype "application/pgp-signature")
2438 (delete-region (point-min)(point-max))
2440 ((string= type "multipart")
2441 (let* ((boundary (assoc-value "boundary" params))
2443 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2445 (re-search-forward boundary-pat nil t)
2446 (let ((bb (match-beginning 0)) eb tag)
2447 (setq tag (format "\n--<<%s>>-{\n" stype))
2450 (setq bb (+ bb (length tag)))
2452 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2454 (setq eb (match-beginning 0))
2455 (replace-match (format "--}-<<%s>>\n" stype))
2457 (narrow-to-region bb eb)
2458 (goto-char (point-min))
2459 (while (re-search-forward boundary-pat nil t)
2460 (let ((beg (match-beginning 0))
2462 (delete-region beg (match-end 0))
2464 (if (re-search-forward boundary-pat nil t)
2465 (setq end (match-beginning 0))
2466 (setq end (point-max))
2469 (narrow-to-region beg end)
2470 (mime-editor::edit-again code-conversion)
2471 (goto-char (point-max))
2474 (goto-char (point-min))
2475 (or (= (point-min) 1)
2476 (delete-region (point-min)
2477 (if (search-forward "\n\n" nil t)
2485 (let ((bytes (+ 14 (length ctype))))
2486 (mapconcat (function
2488 (if (string-equal (car attr) "charset")
2490 (setq charset (cdr attr))
2498 (setq bytes (+ bytes bs 2))
2501 (setq bytes (+ bs 1))
2509 (if (re-search-forward
2510 "Content-Transfer-Encoding:" nil t)
2511 (let ((beg (match-beginning 0))
2512 (hbeg (match-end 0))
2513 (end (std11-field-end)))
2515 (eliminate-top-spaces
2516 (std11-unfold-string
2517 (buffer-substring hbeg end))))
2518 (if (or charset (string-equal type "text"))
2520 (delete-region beg (1+ end))
2521 (goto-char (point-min))
2522 (if (search-forward "\n\n" nil t)
2525 (match-end 0)(point-max) encoding)
2529 (if (or code-conversion encoded)
2530 (decode-mime-charset-region
2531 (point-min)(point-max)
2532 (or charset default-mime-charset))
2535 (if (re-search-forward "^$" nil t)
2539 (if (= (point-min) 1)
2545 (concat type "/" stype pstr) encoding)))
2547 (delete-region (point-min) he)
2550 (concat type "/" stype pstr) encoding))
2554 (decode-mime-charset-region (point-min) (point-max)
2555 default-mime-charset)
2559 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2561 (mime-editor::edit-again code-conversion)
2562 (goto-char (point-min))
2566 (if (re-search-forward
2567 (concat "^\\(" (regexp-quote mail-header-separator) "\\)?$")
2572 (goto-char (point-min))
2573 (while (re-search-forward
2574 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2575 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2578 (and (re-search-forward "^$")
2579 (replace-match mail-header-separator)
2591 (run-hooks 'tm-edit-load-hook)
2593 ;;; tm-edit.el ends here