1 ;;; tm-edit.el --- Simple MIME Composer for GNU Emacs
3 ;; Copyright (C) 1993 .. 1996 Free Software Foundation, Inc.
5 ;; Author: UMEDA Masanobu <umerin@mse.kyutech.ac.jp>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; Created: 1994/08/21 renamed from mime.el
9 ;; Version: $Revision: 7.98 $
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] or `ISO-2022-INT-1'. Mule is required
45 ;; for reading the such messages.
47 ;; This MIME composer can work with Mail mode, mh-e letter Mode, and
48 ;; News mode. First of all, you need the following autoload
49 ;; definition to load mime/editor-mode automatically:
51 ;; (autoload 'mime/editor-mode "tm-edit"
52 ;; "Minor mode for editing MIME message." t)
54 ;; In case of Mail mode (includes VM mode), you need the following
57 ;; (add-hook 'mail-mode-hook 'mime/editor-mode)
58 ;; (add-hook 'mail-send-hook 'mime-editor/maybe-translate)
60 ;; In case of MH-E, you need the following hook definition:
62 ;; (add-hook 'mh-letter-mode-hook
66 ;; (make-local-variable 'mail-header-separator)
67 ;; (setq mail-header-separator "--------")
69 ;; (add-hook 'mh-before-send-letter-hook 'mime-editor/maybe-translate)
71 ;; In case of News mode, you need the following hook definition:
73 ;; (add-hook 'news-reply-mode-hook 'mime/editor-mode)
74 ;; (add-hook 'news-inews-hook 'mime-editor/maybe-translate)
76 ;; In case of Emacs 19, it is possible to emphasize the message tags
77 ;; using font-lock mode as follows:
79 ;; (add-hook 'mime/editor-mode-hook
83 ;; (setq font-lock-keywords (list mime-editor/tag-regexp))
86 ;; The message tag looks like:
88 ;; --[[TYPE/SUBTYPE;PARAMETERS][ENCODING]]
90 ;; The tagged MIME message examples:
92 ;; This is a conventional plain text. It should be translated into
96 ;; This is also a plain text. But, it is explicitly specified as is.
98 ;;--[[text/plain; charset=ISO-2022-JP]]
99 ;;
\e$B$3$l$O
\e(B charset
\e$B$r
\e(B ISO-2022-JP
\e$B$K;XDj$7$?F|K\8l$N
\e(B plain
\e$B%F%-%9%H$G$9
\e(B.
101 ;;--[[text/richtext]]
102 ;; <center>This is a richtext.</center>
104 ;;--[[image/gif][base64]]^M...image encoded in base64 comes here...
106 ;;--[[audio/basic][base64]]^M...audio encoded in base64 comes here...
111 (require 'mail-utils)
122 (defconst mime-editor/RCS-ID
123 "$Id: tm-edit.el,v 7.98 1996/12/23 14:49:34 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:
700 \\[mime-editor/insert-text] insert a text message.
701 \\[mime-editor/insert-file] insert a (binary) file.
702 \\[mime-editor/insert-external] insert a reference to external body.
703 \\[mime-editor/insert-voice] insert a voice message.
704 \\[mime-editor/insert-message] insert a mail or news message.
705 \\[mime-editor/insert-mail] insert a mail message.
706 \\[mime-editor/insert-signature] insert a signature file at end.
707 \\[mime-editor/insert-tag] insert a new MIME tag.
708 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
709 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
710 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
711 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
712 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
713 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
714 \\[mime-editor/insert-key] insert PGP public key.
715 \\[mime-editor/preview-message] preview editing MIME message.
716 \\[mime-editor/exit] exit and translate into a MIME compliant message.
717 \\[mime-editor/maybe-translate] exit and translate if in MIME mode, then split.
718 \\[mime-editor/help] show this help.
720 Additional commands are available in some major modes:
721 C-c C-c exit, translate and run the original command.
722 C-c C-s exit, translate and run the original command.
724 The following is a message example written in the tagged MIME format.
725 TABs at the beginning of the line are not a part of the message:
727 This is a conventional plain text. It should be translated
730 This is also a plain text. But, it is explicitly specified as
732 --[[text/plain; charset=ISO-2022-JP]]
733 \e$B$3$l$O
\e(B charset
\e$B$r
\e(B ISO-2022-JP
\e$B$K;XDj$7$?F|K\8l$N
\e(B plain
\e$B%F%-%9
\e(B
736 <center>This is a richtext.</center>
737 --[[image/gif][base64]]^M...image encoded in base64 here...
738 --[[audio/basic][base64]]^M...audio encoded in base64 here...
740 User customizable variables (not documented all of them):
742 Specifies a key prefix for MIME minor mode commands.
744 mime-ignore-preceding-spaces
745 Preceding white spaces in a message body are ignored if non-nil.
747 mime-ignore-trailing-spaces
748 Trailing white spaces in a message body are ignored if non-nil.
750 mime-auto-fill-header
751 Fill header fields that contain encoded-words if non-nil.
754 Hide a non-textual body message encoded in base64 after insertion
757 mime-editor/voice-recorder
758 Specifies a function to record a voice message and encode it.
759 The function `mime-editor/voice-recorder-for-sun' is for Sun
762 mime/editor-mode-hook
763 Turning on MIME mode calls the value of mime/editor-mode-hook, if
766 mime-editor/translate-hook
767 The value of mime-editor/translate-hook is called just before translating
768 the tagged MIME format into a MIME compliant message if it is
769 non-nil. If the hook call the function mime-editor/insert-signature,
770 the signature file will be inserted automatically.
772 mime-editor/exit-hook
773 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
776 (if mime/editor-mode-flag
777 (error "You are already editing a MIME message.")
778 (setq mime/editor-mode-flag t)
779 ;; Remember old key bindings.
781 (use-local-map (or (current-local-map) (make-sparse-keymap)))
782 (make-local-variable 'mime/editor-mode-old-local-map)
783 (setq mime/editor-mode-old-local-map (current-local-map))
784 ;; Add MIME commands to current local map.
785 (use-local-map (copy-keymap (or (current-local-map)
786 (make-sparse-keymap))))
788 (if (not (lookup-key (current-local-map) mime-prefix))
789 (define-key (current-local-map) mime-prefix mime-editor/mime-map))
791 ;; Set transfer level into mode line
793 (setq mime-editor/transfer-level-string
794 (mime/encoding-name mime-editor/transfer-level 'not-omit))
795 (force-mode-line-update)
797 ;; Define menu. Menus for other emacs implementations are
799 (cond (running-xemacs
800 (mime-editor/define-menu-for-xemacs))
801 ((>= emacs-major-version 19)
802 (mime-editor/define-menu-for-emacs19)
808 ;; I don't care about saving these.
809 (setq paragraph-start
810 (regexp-or mime-editor/single-part-tag-regexp
812 (setq paragraph-separate
813 (regexp-or mime-editor/single-part-tag-regexp
815 (run-hooks 'mime/editor-mode-hook)
817 (substitute-command-keys
818 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
822 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
823 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
825 (defun mime-editor/exit (&optional nomime no-error)
826 "Translate the tagged MIME message into a MIME compliant message.
827 With no argument encode a message in the buffer into MIME, otherwise
828 just return to previous mode."
830 (if (not mime/editor-mode-flag)
832 (error "You aren't editing a MIME message.")
836 (run-hooks 'mime-editor/translate-hook)
837 (mime-editor/translate-buffer)))
838 ;; Restore previous state.
839 (setq mime/editor-mode-flag nil)
840 (cond (running-xemacs
841 (delete-menu-item (list mime-editor/menu-title)))
843 (use-local-map mime/editor-mode-old-local-map)))
846 (set-buffer-modified-p (buffer-modified-p))
847 (run-hooks 'mime-editor/exit-hook)
848 (message "Exit MIME editor mode.")
851 (defun mime-editor/maybe-translate ()
853 (mime-editor/exit nil t)
854 (call-interactively 'mime-editor/maybe-split-and-send)
857 (defun mime-editor/help ()
858 "Show help message about MIME mode."
860 (with-output-to-temp-buffer "*Help*"
861 (princ "MIME editor mode:\n")
862 (princ (documentation 'mime/editor-mode))
863 (print-help-return-message)))
865 (defun mime-editor/insert-text ()
866 "Insert a text message.
867 Charset is automatically obtained from the `mime/lc-charset-alist'."
869 (let ((ret (mime-editor/insert-tag "text" nil nil)))
872 (if (looking-at mime-editor/single-part-tag-regexp)
874 ;; Make a space between the following message.
878 (if (and (member (second ret) '("enriched" "richtext"))
879 (fboundp 'enriched-mode)
882 (if (boundp 'enriched-mode)
886 (defun mime-editor/insert-file (file &optional verbose)
887 "Insert a message from a file."
888 (interactive "fInsert file as MIME message: \nP")
889 (let* ((guess (mime-find-file-type file))
891 (subtype (nth 1 guess))
892 (parameters (nth 2 guess))
893 (encoding (nth 3 guess))
894 (disposition-type (nth 4 guess))
895 (disposition-params (nth 5 guess))
898 (setq type (mime-prompt-for-type type)
899 subtype (mime-prompt-for-subtype type subtype)
902 (setq encoding (mime-prompt-for-encoding encoding))
904 (if (or (consp parameters) (stringp disposition-type))
905 (let ((rest parameters) cell attribute value)
908 (setq cell (car rest))
909 (setq attribute (car cell))
910 (setq value (cdr cell))
912 (setq value (std11-wrap-as-quoted-string
913 (file-name-nondirectory file)))
915 (setq parameters (concat parameters "; " attribute "=" value))
916 (setq rest (cdr rest))
921 (concat parameters "\n"
922 "Content-Disposition: " disposition-type))
923 (setq rest disposition-params)
925 (setq cell (car rest))
926 (setq attribute (car cell))
927 (setq value (cdr cell))
929 (setq value (std11-wrap-as-quoted-string
930 (file-name-nondirectory file)))
933 (concat parameters "; " attribute "=" value))
934 (setq rest (cdr rest))
938 (mime-editor/insert-tag type subtype parameters)
939 (mime-editor/insert-binary-file file encoding)
942 (defun mime-editor/insert-external ()
943 "Insert a reference to external body."
945 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
947 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
949 (let* ((pritype (mime-prompt-for-type))
950 (subtype (mime-prompt-for-subtype pritype))
951 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
954 (insert "Content-Type: "
955 pritype "/" subtype (or parameters "") "\n")))
956 (if (and (not (eobp))
957 (not (looking-at mime-editor/single-part-tag-regexp)))
958 (insert (mime-make-text-tag) "\n")))
960 (defun mime-editor/insert-voice ()
961 "Insert a voice message."
965 "What transfer encoding: "
966 mime-file-encoding-method-alist nil t nil)))
967 (mime-editor/insert-tag "audio" "basic" nil)
968 (mime-editor/define-encoding encoding)
970 (narrow-to-region (1- (point))(point))
972 (funcall mime-editor/voice-recorder encoding)
975 (invisible-region (point-min)(point-max))
976 (goto-char (point-max))
979 (defun mime-editor/insert-signature (&optional arg)
980 "Insert a signature file."
982 (let ((signature-insert-hook
985 (apply (function mime-editor/insert-tag)
986 (mime-find-file-type signature-file-name))
989 (insert-signature arg)
993 ;; Insert a new tag around a point.
995 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
996 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
997 If nothing is inserted, return nil."
1000 (mime-editor/goto-tag)
1001 (if (and (re-search-forward mime-editor/tag-regexp nil t)
1002 (< (match-beginning 0) p)
1005 (goto-char (match-beginning 0))
1014 (mime-prompt-for-type)))
1017 (mime-prompt-for-subtype pritype)))
1020 (mime-prompt-for-parameters pritype subtype delimiter)))
1021 ;; Make a new MIME tag.
1022 (setq newtag (mime-make-tag pritype subtype parameters))
1023 ;; Find an current MIME tag.
1026 (if (mime-editor/goto-tag)
1027 (buffer-substring (match-beginning 0) (match-end 0))
1028 ;; Assume content type is 'text/plan'.
1029 (mime-make-tag "text" "plain")
1031 ;; We are only interested in TEXT.
1033 (not (mime-test-content-type
1034 (mime-editor/get-contype oldtag) "text")))
1037 (if (or (not oldtag) ;Not text
1038 (or mime-ignore-same-text-tag
1039 (not (string-equal oldtag newtag))))
1041 ;; Mark the beginning of the tag for convenience.
1042 (push-mark (point) 'nomsg)
1043 (insert newtag "\n")
1044 (list pritype subtype parameters) ;New tag is created.
1046 ;; Restore previous point.
1048 nil ;Nothing is created.
1052 (defun mime-editor/insert-binary-file (file &optional encoding)
1053 "Insert binary FILE at point.
1054 Optional argument ENCODING specifies an encoding method such as base64."
1055 (let* ((tagend (1- (point))) ;End of the tag
1056 (hide-p (and mime-auto-hide-body
1059 (let ((en (downcase encoding)))
1060 (or (string-equal en "7bit")
1061 (string-equal en "8bit")
1062 (string-equal en "binary")
1066 (narrow-to-region tagend (point))
1067 (mime-insert-encoded-file file encoding)
1070 (invisible-region (point-min) (point-max))
1071 (goto-char (point-max))
1073 (goto-char (point-max))
1076 (looking-at mime-editor/tag-regexp)
1077 (= (point)(point-max))
1078 (mime-editor/insert-tag "text" "plain")
1080 ;; Define encoding even if it is 7bit.
1081 (if (stringp encoding)
1083 (goto-char tagend) ; Make sure which line the tag is on.
1084 (mime-editor/define-encoding encoding)
1089 ;; Commands work on a current message flagment.
1091 (defun mime-editor/goto-tag ()
1092 "Search for the beginning of the tagged MIME message."
1093 (let ((current (point)) multipart)
1094 (if (looking-at mime-editor/tag-regexp)
1096 ;; At first, go to the end.
1097 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1098 (goto-char (1- (match-beginning 0))) ;For multiline tag
1101 (goto-char (point-max))
1103 ;; Then search for the beginning.
1104 (re-search-backward mime-editor/end-tag-regexp nil t)
1105 (or (looking-at mime-editor/beginning-tag-regexp)
1106 ;; Restore previous point.
1113 (defun mime-editor/content-beginning ()
1114 "Return the point of the beginning of content."
1116 (let ((beg (save-excursion
1117 (beginning-of-line) (point))))
1118 (if (mime-editor/goto-tag)
1119 (let ((top (point)))
1120 (goto-char (match-end 0))
1121 (if (and (= beg top)
1122 (= (following-char) ?\^M))
1126 ;; Default text/plain tag.
1127 (goto-char (point-min))
1129 (concat "\n" (regexp-quote mail-header-separator)
1130 (if mime-ignore-preceding-spaces
1131 "[ \t\n]*\n" "\n")) nil 'move)
1135 (defun mime-editor/content-end ()
1136 "Return the point of the end of content."
1138 (let ((beg (point)))
1139 (if (mime-editor/goto-tag)
1140 (let ((top (point)))
1141 (goto-char (match-end 0))
1142 (if (invisible-p (point))
1143 (next-visible-point (point))
1144 ;; Move to the end of this text.
1145 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1146 ;; Don't forget a multiline tag.
1147 (goto-char (match-beginning 0))
1151 ;; Assume the message begins with text/plain.
1152 (goto-char (mime-editor/content-beginning))
1153 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1154 ;; Don't forget a multiline tag.
1155 (goto-char (match-beginning 0)))
1159 (defun mime-editor/define-charset (charset)
1160 "Set charset of current tag to CHARSET."
1162 (if (mime-editor/goto-tag)
1163 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1164 (delete-region (match-beginning 0) (match-end 0))
1167 (mime-editor/set-parameter
1168 (mime-editor/get-contype tag)
1169 "charset" (upcase (symbol-name charset)))
1170 (mime-editor/get-encoding tag)))
1173 (defun mime-editor/define-encoding (encoding)
1174 "Set encoding of current tag to ENCODING."
1176 (if (mime-editor/goto-tag)
1177 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1178 (delete-region (match-beginning 0) (match-end 0))
1179 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1182 (defun mime-editor/choose-charset ()
1183 "Choose charset of a text following current point."
1184 (detect-mime-charset-region (point) (mime-editor/content-end))
1187 (defun mime-make-text-tag (&optional subtype)
1188 "Make a tag for a text after current point.
1189 Subtype of text type can be specified by an optional argument SUBTYPE.
1190 Otherwise, it is obtained from mime-content-types."
1191 (let* ((pritype "text")
1192 (subtype (or subtype
1193 (car (car (cdr (assoc pritype mime-content-types)))))))
1194 ;; Charset should be defined later.
1195 (mime-make-tag pritype subtype)))
1198 ;; Tag handling functions
1200 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1201 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1202 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1206 (defun mime-create-tag (contype &optional encoding)
1207 "Make a tag with CONTENT-TYPE and optional ENCODING."
1208 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1211 (defun mime-editor/get-contype (tag)
1212 "Return Content-Type (including parameters) of TAG."
1214 (or (string-match mime-editor/single-part-tag-regexp tag)
1215 (string-match mime-editor/multipart-beginning-regexp tag)
1216 (string-match mime-editor/multipart-end-regexp tag)
1218 (substring tag (match-beginning 1) (match-end 1))
1221 (defun mime-editor/get-encoding (tag)
1222 "Return encoding of TAG."
1224 (string-match mime-editor/single-part-tag-regexp tag)
1226 (not (= (match-beginning 3) (match-end 3)))
1227 (substring tag (match-beginning 3) (match-end 3))))
1229 (defun mime-get-parameter (contype parameter)
1230 "For given CONTYPE return value for PARAMETER.
1231 Nil if no such parameter."
1235 (regexp-quote parameter)
1236 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1238 (substring contype (match-beginning 1) (match-end 1))
1239 nil ;No such parameter
1242 (defun mime-editor/set-parameter (contype parameter value)
1243 "For given CONTYPE set PARAMETER to VALUE."
1244 (let (ctype opt-fields)
1245 (if (string-match "\n[^ \t\n\r]+:" contype)
1246 (setq ctype (substring contype 0 (match-beginning 0))
1247 opt-fields (substring contype (match-beginning 0)))
1248 (setq ctype contype)
1253 (regexp-quote parameter)
1254 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1257 (concat (substring ctype 0 (match-beginning 1))
1259 (substring contype (match-end 1))
1261 (concat ctype "; " parameter "=" value opt-fields)
1264 (defun mime-strip-parameters (contype)
1265 "Return primary content-type and subtype without parameters for CONTYPE."
1266 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1267 (substring contype (match-beginning 1) (match-end 1)) nil))
1269 (defun mime-test-content-type (contype type &optional subtype)
1270 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1271 (and (stringp contype)
1274 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1275 (downcase contype))))
1280 (defun mime-find-file-type (file)
1281 "Guess Content-Type, subtype, and parameters from FILE."
1283 (guesses mime-file-types))
1284 (while (and (not guess) guesses)
1285 (if (string-match (car (car guesses)) file)
1286 (setq guess (cdr (car guesses))))
1287 (setq guesses (cdr guesses)))
1291 (defun mime-prompt-for-type (&optional default)
1292 "Ask for Content-type."
1294 ;; Repeat until primary content type is specified.
1295 (while (string-equal type "")
1297 (completing-read "What content type: "
1300 'require-match ;Type must be specified.
1303 (if (string-equal type "")
1305 (message "Content type is required.")
1312 (defun mime-prompt-for-subtype (type &optional default)
1313 "Ask for subtype of media-type TYPE."
1314 (let ((subtypes (cdr (assoc type mime-content-types))))
1316 (assoc default subtypes))
1317 (setq default (car (car subtypes)))
1323 "What content subtype: (default " default ") ")
1324 "What content subtype: ")
1325 (cdr (assoc type mime-content-types))
1327 'require-match ;Subtype must be specified.
1330 (if (string-equal answer "") default answer)))
1332 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1333 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1334 Optional DELIMITER specifies parameter delimiter (';' by default)."
1335 (let* ((delimiter (or delimiter "; "))
1340 (mime-prompt-for-parameters-1
1342 (cdr (assoc pritype mime-content-types))))))
1345 (if (and (stringp parameters)
1346 (not (string-equal parameters "")))
1347 (concat delimiter parameters)
1348 "" ;"" if no parameters
1351 (defun mime-prompt-for-parameters-1 (optlist)
1352 (apply (function append)
1353 (mapcar (function mime-prompt-for-parameter) optlist)))
1355 (defun mime-prompt-for-parameter (parameter)
1357 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1358 (let* ((prompt (car parameter))
1359 (choices (mapcar (function
1361 (if (consp e) e (list e))))
1363 (default (car (car choices)))
1369 (concat "What " prompt
1371 (if (string-equal default "") "\"\"" default)
1373 choices nil nil ""))
1374 ;; If nothing is selected, use default.
1375 (if (string-equal answer "")
1376 (setq answer default)))
1378 (read-string (concat "What " prompt ": "))))
1379 (cons (if (and answer
1380 (not (string-equal answer "")))
1382 ;; Note: control characters ignored!
1383 (if (string-match mime-tspecials-regexp answer)
1384 (concat "\"" answer "\"") answer)))
1385 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1388 (defun mime-prompt-for-encoding (default)
1389 "Ask for Content-Transfer-Encoding. [tm-edit.el]"
1392 (concat "What transfer encoding"
1394 (concat " (default "
1395 (if (string-equal default "")
1401 mime-file-encoding-method-alist nil t nil)
1403 (if (string= ret "")
1408 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1411 (defvar mime-editor/translate-buffer-hook
1412 '(mime-editor/pgp-enclose-buffer
1413 mime-editor/translate-header
1414 mime-editor/translate-body))
1416 (defun mime-editor/translate-header ()
1417 "Encode the message header into network representation."
1418 (mime/encode-message-header 'code-conversion)
1419 (run-hooks 'mime-editor/translate-header-hook)
1422 (defun mime-editor/translate-buffer ()
1423 "Encode the tagged MIME message in current buffer in MIME compliant message."
1425 (if (catch 'mime-editor/error
1427 (run-hooks 'mime-editor/translate-buffer-hook)
1431 (error "Translation error!")
1434 (defun mime-editor/find-inmost ()
1435 (goto-char (point-min))
1436 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1437 (let ((bb (match-beginning 0))
1439 (type (buffer-substring (match-beginning 1)(match-end 1)))
1441 (setq end-exp (format "--}-<<%s>>\n" type))
1443 (if (re-search-forward end-exp nil t)
1445 (setq eb (match-beginning 0))
1446 (setq ee (match-end 0))
1448 (setq eb (point-max))
1449 (setq ee (point-max))
1451 (narrow-to-region be eb)
1453 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1455 (narrow-to-region (match-beginning 0)(point-max))
1456 (mime-editor/find-inmost)
1459 (list type bb be eb)
1462 (defun mime-editor/process-multipart-1 (boundary)
1463 (let ((ret (mime-editor/find-inmost)))
1465 (let ((type (car ret))
1466 (bb (nth 1 ret))(be (nth 2 ret))
1469 (narrow-to-region bb eb)
1470 (delete-region bb be)
1471 (setq bb (point-min))
1472 (setq eb (point-max))
1475 (if (looking-at mime-editor/multipart-end-regexp)
1476 (let ((beg (match-beginning 0))
1479 (delete-region beg end)
1480 (or (looking-at mime-editor/beginning-tag-regexp)
1482 (insert (concat (mime-make-text-tag) "\n"))
1484 (cond ((string-equal type "quote")
1485 (mime-editor/enquote-region bb eb)
1487 ((string-equal type "signed")
1488 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1489 (mime-editor/sign-pgp-elkins bb eb boundary)
1491 ((eq mime-editor/signing-type 'pgp-kazu)
1492 (mime-editor/sign-pgp-kazu bb eb boundary)
1495 ((string-equal type "encrypted")
1496 (cond ((eq mime-editor/encrypting-type 'pgp-elkins)
1497 (mime-editor/encrypt-pgp-elkins bb eb boundary)
1499 ((eq mime-editor/encrypting-type 'pgp-kazu)
1500 (mime-editor/encrypt-pgp-kazu bb eb boundary)
1504 (nth 2 (mime-editor/translate-region bb eb
1508 (format "--[[multipart/%s;
1509 boundary=\"%s\"][7bit]]\n"
1514 (defun mime-editor/enquote-region (beg end)
1517 (narrow-to-region beg end)
1519 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1520 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1521 (replace-match (concat "- " (substring tag 1)))
1524 (defun mime-editor/dequote-region (beg end)
1527 (narrow-to-region beg end)
1529 (while (re-search-forward
1530 mime-editor/quoted-single-part-tag-regexp nil t)
1531 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1532 (replace-match (concat "-" (substring tag 2)))
1535 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1538 (narrow-to-region beg end)
1540 (mime-editor/translate-region beg end boundary))
1542 (encoding (nth 1 ret))
1544 (pgp-boundary (concat "pgp-sign-" boundary))
1547 (insert (format "Content-Type: %s\n" ctype))
1549 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1552 (or (funcall mime-editor/pgp-sign-function
1553 (point-min)(point-max) nil nil pgp-boundary)
1554 (throw 'mime-editor/error 'pgp-error)
1558 (defvar mime-editor/encrypt-recipient-fields-list '("To" "cc"))
1560 (defun mime-editor/make-encrypt-recipient-header ()
1561 (let* ((names mime-editor/encrypt-recipient-fields-list)
1563 (std11-field-bodies (cons "From" names)
1564 nil mail-header-separator))
1567 (setq values (cdr values))))
1568 (header (and (stringp from)
1569 (if (string-equal from "")
1571 (format "From: %s\n" from)
1574 (while (and names values)
1575 (let ((name (car names))
1576 (value (car values))
1578 (and (stringp value)
1579 (or (string-equal value "")
1581 (setq header (concat header name ": " value "\n")
1582 recipients (if recipients
1583 (concat recipients " ," value)
1586 (setq names (cdr names)
1587 values (cdr values))
1589 (vector from recipients header)
1592 (defun mime-editor/encrypt-pgp-elkins (beg end boundary)
1595 (let (from recipients header)
1596 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1597 (setq from (aref ret 0)
1598 recipients (aref ret 1)
1599 header (aref ret 2))
1601 (narrow-to-region beg end)
1603 (mime-editor/translate-region beg end boundary))
1605 (encoding (nth 1 ret))
1607 (pgp-boundary (concat "pgp-" boundary))
1611 (insert (format "Content-Type: %s\n" ctype))
1613 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1616 (or (funcall mime-editor/pgp-encrypt-function
1617 recipients (point-min) (point-max) from)
1618 (throw 'mime-editor/error 'pgp-error)
1621 (insert (format "--[[multipart/encrypted;
1623 protocol=\"application/pgp-encrypted\"][7bit]]
1625 Content-Type: application/pgp-encrypted
1628 Content-Type: application/octet-stream
1629 Content-Transfer-Encoding: 7bit
1631 " pgp-boundary pgp-boundary pgp-boundary))
1632 (goto-char (point-max))
1633 (insert (format "\n--%s--\n" pgp-boundary))
1636 (defun mime-editor/sign-pgp-kazu (beg end boundary)
1639 (narrow-to-region beg end)
1641 (mime-editor/translate-region beg end boundary))
1643 (encoding (nth 1 ret))
1647 (insert (format "Content-Type: %s\n" ctype))
1649 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1652 (or (as-binary-process
1653 (funcall mime-editor/traditional-pgp-sign-function
1655 (throw 'mime-editor/error 'pgp-error)
1659 "--[[application/pgp; format=mime][7bit]]\n")
1663 (defun mime-editor/encrypt-pgp-kazu (beg end boundary)
1665 (let (from recipients header)
1666 (let ((ret (mime-editor/make-encrypt-recipient-header)))
1667 (setq from (aref ret 0)
1668 recipients (aref ret 1)
1669 header (aref ret 2))
1672 (narrow-to-region beg end)
1674 (mime-editor/translate-region beg end boundary))
1676 (encoding (nth 1 ret))
1681 (insert (format "Content-Type: %s\n" ctype))
1683 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1686 (or (as-binary-process
1687 (funcall mime-editor/pgp-encrypt-function
1688 recipients beg (point-max) nil 'maybe)
1690 (throw 'mime-editor/error 'pgp-error)
1694 "--[[application/pgp; format=mime][7bit]]\n")
1698 (defun mime-editor/translate-body ()
1699 "Encode the tagged MIME body in current buffer in MIME compliant message."
1703 (concat mime-multipart-boundary "_"
1704 (replace-space-with-underline (current-time-string))
1708 (while (mime-editor/process-multipart-1
1709 (format "%s-%d" boundary i))
1713 ;; We are interested in message body.
1716 (goto-char (point-min))
1718 (concat "\n" (regexp-quote mail-header-separator)
1719 (if mime-ignore-preceding-spaces
1720 "[ \t\n]*\n" "\n")) nil 'move)
1724 (goto-char (point-max))
1725 (and mime-ignore-trailing-spaces
1726 (re-search-backward "[^ \t\n]\n" beg t)
1729 (setq ret (mime-editor/translate-region
1731 (format "%s-%d" boundary i)))
1733 (mime-editor/dequote-region (point-min)(point-max))
1734 (let ((contype (car ret)) ;Content-Type
1735 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1737 ;; Make primary MIME headers.
1738 (or (mail-position-on-field "Mime-Version")
1739 (insert mime-editor/mime-version-value))
1740 ;; Remove old Content-Type and other fields.
1742 (goto-char (point-min))
1743 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1744 (narrow-to-region (point-min) (point))
1745 (goto-char (point-min))
1746 (mime-delete-field "Content-Type")
1747 (mime-delete-field "Content-Transfer-Encoding"))
1748 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1749 (mail-position-on-field "Content-Type")
1753 (mail-position-on-field "Content-Transfer-Encoding")
1757 (defun mime-editor/translate-single-part-tag (&optional prefix)
1758 (if (re-search-forward mime-editor/single-part-tag-regexp nil t)
1759 (let* ((beg (match-beginning 0))
1761 (tag (buffer-substring beg end))
1763 (delete-region beg end)
1764 (setq contype (mime-editor/get-contype tag))
1765 (setq encoding (mime-editor/get-encoding tag))
1766 (insert (concat prefix "--" boundary "\n"))
1768 (narrow-to-region (point)(point))
1769 (insert "Content-Type: " contype "\n")
1771 (insert "Content-Transfer-Encoding: " encoding "\n"))
1772 (mime/encode-message-header)
1776 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1779 (concat mime-multipart-boundary "_"
1780 (replace-space-with-underline (current-time-string))))
1784 (narrow-to-region beg end)
1785 (let ((tag nil) ;MIME tag
1786 (contype nil) ;Content-Type
1787 (encoding nil) ;Content-Transfer-Encoding
1788 (nparts 0)) ;Number of body parts
1789 ;; Normalize the body part by inserting appropriate message
1790 ;; tags for every message contents.
1791 (mime-editor/normalize-body)
1792 ;; Counting the number of Content-Type.
1793 (goto-char (point-min))
1794 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1795 (setq nparts (1+ nparts)))
1796 ;; Begin translation.
1798 ((and (<= nparts 1)(not multipart))
1799 ;; It's a singular message.
1800 (goto-char (point-min))
1801 (while (re-search-forward
1802 mime-editor/single-part-tag-regexp nil t)
1804 (buffer-substring (match-beginning 0) (match-end 0)))
1805 (delete-region (match-beginning 0) (1+ (match-end 0)))
1806 (setq contype (mime-editor/get-contype tag))
1807 (setq encoding (mime-editor/get-encoding tag))
1810 ;; It's a multipart message.
1811 (goto-char (point-min))
1812 (and (mime-editor/translate-single-part-tag)
1813 (while (mime-editor/translate-single-part-tag "\n"))
1815 ;; Define Content-Type as "multipart/mixed".
1817 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1818 ;; Content-Transfer-Encoding must be "7bit".
1819 ;; The following encoding can be `nil', but is
1820 ;; specified as is since there is no way that a user
1822 (setq encoding "7bit")
1823 ;; Insert the trailer.
1824 (goto-char (point-max))
1825 (insert "\n--" boundary "--\n")
1827 (list contype encoding boundary nparts)
1830 (defun mime-editor/normalize-body ()
1831 "Normalize the body part by inserting appropriate message tags."
1832 ;; Insert the first MIME tags if necessary.
1833 (goto-char (point-min))
1834 (if (not (looking-at mime-editor/single-part-tag-regexp))
1835 (insert (mime-make-text-tag) "\n"))
1836 ;; Check each tag, and add new tag or correct it if necessary.
1837 (goto-char (point-min))
1838 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1839 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1840 (contype (mime-editor/get-contype tag))
1841 (charset (mime-get-parameter contype "charset"))
1842 (encoding (mime-editor/get-encoding tag)))
1843 ;; Remove extra whitespaces after the tag.
1844 (if (looking-at "[ \t]+$")
1845 (delete-region (match-beginning 0) (match-end 0)))
1847 (end (mime-editor/content-end))
1849 (if (= end (point-max))
1852 (or (looking-at mime-editor/beginning-tag-regexp)
1854 (insert (mime-make-text-tag) "\n")
1856 (visible-region beg end)
1860 ((mime-test-content-type contype "message")
1861 ;; Content-type "message" should be sent as is.
1864 ((mime-test-content-type contype "text")
1865 ;; Define charset for text if necessary.
1866 (setq charset (if charset
1867 (intern (downcase charset))
1868 (mime-editor/choose-charset)))
1869 (mime-editor/define-charset charset)
1870 (cond ((string-equal contype "text/x-rot13-47")
1874 (goto-char (mime-editor/content-end))
1877 ((string-equal contype "text/enriched")
1882 (end (mime-editor/content-end))
1884 ;; Patch for hard newlines
1887 ;; (while (search-forward "\n" end t)
1888 ;; (put-text-property (match-beginning 0)
1891 ;; End patch for hard newlines
1892 (enriched-encode beg end)
1894 (if (search-forward "\n\n")
1895 (delete-region beg (match-end 0))
1898 ;; Point is now on current tag.
1899 ;; Define encoding and encode text if necessary.
1900 (or encoding ;Encoding is not specified.
1904 mime-editor/charset-default-encoding-alist)
1906 (beg (mime-editor/content-beginning))
1908 (encode-mime-charset-region beg (mime-editor/content-end)
1910 (mime-encode-region beg (mime-editor/content-end) encoding)
1911 (mime-editor/define-encoding encoding)
1913 (goto-char (mime-editor/content-end))
1915 ((null encoding) ;Encoding is not specified.
1916 ;; Application, image, audio, video, and any other
1917 ;; unknown content-type without encoding should be
1919 (let* ((encoding "base64") ;Encode in BASE64 by default.
1920 (beg (mime-editor/content-beginning))
1921 (end (mime-editor/content-end))
1922 (body (buffer-substring beg end))
1924 (mime-encode-region beg end encoding)
1925 (mime-editor/define-encoding encoding))
1930 (defun mime-delete-field (field)
1931 "Delete header FIELD."
1932 (let ((regexp (format "^%s:[ \t]*" field)))
1933 (goto-char (point-min))
1934 (while (re-search-forward regexp nil t)
1935 (delete-region (match-beginning 0)
1936 (progn (forward-line 1) (point)))
1941 ;;; Platform dependent functions
1944 ;; Sun implementations
1946 (defun mime-editor/voice-recorder-for-sun (encoding)
1947 "Record voice in a buffer using Sun audio device,
1948 and insert data encoded as ENCODING. [tm-edit.el]"
1949 (message "Start the recording on %s. Type C-g to finish the recording..."
1951 (mime-insert-encoded-file "/dev/audio" encoding)
1955 ;;; @ Other useful commands.
1958 ;; Message forwarding commands as content-type "message/rfc822".
1960 (defun mime-editor/insert-message (&optional message)
1962 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
1963 (if (and inserter (fboundp inserter))
1965 (mime-editor/insert-tag "message" "rfc822")
1966 (funcall inserter message)
1968 (message "Sorry, I don't have message inserter for your MUA.")
1971 (defun mime-editor/insert-mail (&optional message)
1973 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
1974 (if (and inserter (fboundp inserter))
1976 (mime-editor/insert-tag "message" "rfc822")
1977 (funcall inserter message)
1979 (message "Sorry, I don't have mail inserter for your MUA.")
1982 (defun mime-editor/inserted-message-filter ()
1985 (let ((header-start (point))
1986 (case-fold-search t)
1989 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
1990 (if (re-search-forward "^$" (mark t))
1991 (narrow-to-region header-start (match-beginning 0))
1993 (goto-char header-start)
1994 (while (and (re-search-forward
1995 mime-editor/yank-ignored-field-regexp nil t)
1996 (setq beg (match-beginning 0))
1997 (setq end (1+ (std11-field-end)))
1999 (delete-region beg end)
2004 ;;; @ multipart enclosure
2007 (defun mime-editor/enclose-region (type beg end)
2010 (let ((current (point)))
2012 (narrow-to-region beg end)
2013 (insert (format "--<<%s>>-{\n" type))
2014 (goto-char (point-max))
2015 (insert (format "--}-<<%s>>\n" type))
2016 (goto-char (point-max))
2018 (or (looking-at mime-editor/beginning-tag-regexp)
2020 (insert (mime-make-text-tag) "\n")
2024 (defun mime-editor/enclose-quote-region (beg end)
2026 (mime-editor/enclose-region "quote" beg end)
2029 (defun mime-editor/enclose-mixed-region (beg end)
2031 (mime-editor/enclose-region "mixed" beg end)
2034 (defun mime-editor/enclose-parallel-region (beg end)
2036 (mime-editor/enclose-region "parallel" beg end)
2039 (defun mime-editor/enclose-digest-region (beg end)
2041 (mime-editor/enclose-region "digest" beg end)
2044 (defun mime-editor/enclose-alternative-region (beg end)
2046 (mime-editor/enclose-region "alternative" beg end)
2049 (defun mime-editor/enclose-signed-region (beg end)
2051 (if mime-editor/signing-type
2052 (mime-editor/enclose-region "signed" beg end)
2053 (message "Please specify signing type.")
2056 (defun mime-editor/enclose-encrypted-region (beg end)
2058 (if mime-editor/signing-type
2059 (mime-editor/enclose-region "encrypted" beg end)
2060 (message "Please specify encrypting type.")
2063 (defun mime-editor/insert-key (&optional arg)
2064 "Insert a pgp public key."
2066 (mime-editor/insert-tag "application" "pgp-keys")
2067 (mime-editor/define-encoding "7bit")
2068 (funcall mime-editor/pgp-insert-public-key-function)
2075 (defun mime-editor/set-split (arg)
2078 (y-or-n-p "Do you want to enable split?")
2080 (setq mime-editor/split-message arg)
2082 (message "This message is enabled to split.")
2083 (message "This message is not enabled to split.")
2086 (defun mime-editor/toggle-transfer-level (&optional transfer-level)
2087 "Toggle transfer-level is 7bit or 8bit through.
2089 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2091 (if (numberp transfer-level)
2092 (setq mime-editor/transfer-level transfer-level)
2093 (if (< mime-editor/transfer-level 8)
2094 (setq mime-editor/transfer-level 8)
2095 (setq mime-editor/transfer-level 7)
2097 (setq mime-editor/charset-default-encoding-alist
2098 (mime-editor/make-charset-default-encoding-alist
2099 mime-editor/transfer-level))
2100 (message (format "Current transfer-level is %d bit"
2101 mime-editor/transfer-level))
2102 (setq mime-editor/transfer-level-string
2103 (mime/encoding-name mime-editor/transfer-level 'not-omit))
2104 (force-mode-line-update)
2107 (defun mime-editor/set-transfer-level-7bit ()
2109 (mime-editor/toggle-transfer-level 7)
2112 (defun mime-editor/set-transfer-level-8bit ()
2114 (mime-editor/toggle-transfer-level 8)
2121 (defun mime-editor/set-sign (arg)
2124 (y-or-n-p "Do you want to sign?")
2127 (if mime-editor/signing-type
2129 (setq mime-editor/pgp-processing 'sign)
2130 (message "This message will be signed.")
2132 (message "Please specify signing type.")
2134 (if (eq mime-editor/pgp-processing 'sign)
2135 (setq mime-editor/pgp-processing nil)
2137 (message "This message will not be signed.")
2140 (defun mime-editor/set-encrypt (arg)
2143 (y-or-n-p "Do you want to encrypt?")
2146 (if mime-editor/encrypting-type
2148 (setq mime-editor/pgp-processing 'encrypt)
2149 (message "This message will be encrypt.")
2151 (message "Please specify encrypting type.")
2153 (if (eq mime-editor/pgp-processing 'encrypt)
2154 (setq mime-editor/pgp-processing nil)
2156 (message "This message will not be encrypt.")
2159 (defvar mime-editor/pgp-processing nil)
2160 (make-variable-buffer-local 'mime-editor/pgp-processing)
2162 (defun mime-editor/pgp-enclose-buffer ()
2163 (let ((beg (save-excursion
2164 (goto-char (point-min))
2165 (if (search-forward (concat "\n" mail-header-separator "\n"))
2171 (cond ((eq mime-editor/pgp-processing 'sign)
2172 (mime-editor/enclose-signed-region beg end)
2174 ((eq mime-editor/pgp-processing 'encrypt)
2175 (mime-editor/enclose-encrypted-region beg end)
2183 (defun mime-editor/insert-partial-header
2184 (fields subject id number total separator)
2186 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2187 (insert (format "Mime-Version: 1.0 (split by %s)\n"
2188 mime-editor/version-name))
2190 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2191 id number total separator))
2194 (defun mime-editor/split-and-send
2195 (&optional cmd lines mime-editor/message-max-length)
2199 (count-lines (point-min) (point-max)))
2201 (or mime-editor/message-max-length
2202 (setq mime-editor/message-max-length
2203 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
2204 mime-editor/message-default-max-lines))
2206 (let* ((mime-editor/draft-file-name
2207 (or (buffer-file-name)
2209 (expand-file-name "tm-draft" mime/tmp-dir))))
2210 (separator mail-header-separator)
2212 (replace-space-with-underline (current-time-string))
2213 "@" (system-name) "\"")))
2214 (run-hooks 'mime-editor/before-split-hook)
2215 (let ((the-buf (current-buffer))
2216 (copy-buf (get-buffer-create " *Original Message*"))
2217 (header (std11-header-string-except
2218 mime-editor/split-ignored-field-regexp separator))
2219 (subject (mail-fetch-field "subject"))
2220 (total (+ (/ lines mime-editor/message-max-length)
2221 (if (> (mod lines mime-editor/message-max-length) 0)
2227 mime-editor/split-message-sender-alist))
2231 (error "Split sender is not specified for `%s'." major-mode)
2234 (mime-editor/partial-number 1)
2237 (set-buffer copy-buf)
2239 (insert-buffer the-buf)
2241 (if (re-search-forward
2242 (concat "^" (regexp-quote separator) "$") nil t)
2243 (let ((he (match-beginning 0)))
2245 (narrow-to-region (point-min) he)
2247 (goto-char (point-min))
2248 (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
2249 (delete-region (match-beginning 0)
2250 (1+ (std11-field-end)))
2252 (while (< mime-editor/partial-number total)
2255 (set-buffer copy-buf)
2256 (setq data (buffer-substring
2259 (goto-line mime-editor/message-max-length)
2262 (delete-region (point-min)(point))
2264 (mime-editor/insert-partial-header
2265 header subject id mime-editor/partial-number total separator)
2268 (message (format "Sending %d/%d..."
2269 mime-editor/partial-number total))
2270 (call-interactively command)
2271 (message (format "Sending %d/%d... done"
2272 mime-editor/partial-number total))
2274 (setq mime-editor/partial-number
2275 (1+ mime-editor/partial-number))
2279 (set-buffer copy-buf)
2280 (setq data (buffer-string))
2283 (mime-editor/insert-partial-header
2284 header subject id mime-editor/partial-number total separator)
2287 (message (format "Sending %d/%d..."
2288 mime-editor/partial-number total))
2289 (message (format "Sending %d/%d... done"
2290 mime-editor/partial-number total))
2294 (defun mime-editor/maybe-split-and-send (&optional cmd)
2296 (run-hooks 'mime-editor/before-send-hook)
2297 (let ((mime-editor/message-max-length
2298 (or (cdr (assq major-mode mime-editor/message-max-lines-alist))
2299 mime-editor/message-default-max-lines))
2300 (lines (count-lines (point-min) (point-max)))
2302 (if (and (> lines mime-editor/message-max-length)
2303 mime-editor/split-message)
2304 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2308 ;;; @ preview message
2311 (defun mime-editor/preview-message ()
2312 "preview editing MIME message. [tm-edit.el]"
2314 (let* ((str (buffer-string))
2315 (separator mail-header-separator)
2316 (the-buf (current-buffer))
2317 (buf-name (buffer-name))
2318 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2319 (buf (get-buffer temp-buf-name))
2323 (switch-to-buffer buf)
2326 (setq buf (get-buffer-create temp-buf-name))
2327 (switch-to-buffer buf)
2330 (setq major-mode 'mime/temporary-message-mode)
2331 (make-local-variable 'mail-header-separator)
2332 (setq mail-header-separator separator)
2333 (make-local-variable 'mime/editing-buffer)
2334 (setq mime/editing-buffer the-buf)
2336 (run-hooks 'mime-editor/translate-hook)
2337 (mime-editor/translate-buffer)
2338 (goto-char (point-min))
2339 (if (re-search-forward
2340 (concat "^" (regexp-quote separator) "$"))
2346 (defun mime-editor/quitting-method ()
2347 (let ((temp mime::preview/article-buffer)
2349 (mime-viewer/kill-buffer)
2351 (setq buf mime/editing-buffer)
2353 (switch-to-buffer buf)
2356 (set-alist 'mime-viewer/quitting-method-alist
2357 'mime/temporary-message-mode
2358 (function mime-editor/quitting-method)
2364 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2365 ;; Mon, 10 Apr 1995 20:03:07 +0900
2367 (defvar mime-editor/draft-header-separator-alist
2368 '((news-reply-mode . mail-header-separator)
2369 (mh-letter-mode . mail-header-separator)
2372 (defvar mime::article/draft-header-separator nil)
2374 (defun mime-editor/draft-preview ()
2376 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2377 (or (stringp sep) (setq sep (eval sep)))
2378 (make-variable-buffer-local 'mime::article/draft-header-separator)
2379 (goto-char (point-min))
2381 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2382 (setq mime::article/draft-header-separator
2383 (buffer-substring (match-beginning 0) (match-end 0)))
2385 (mime/viewer-mode (current-buffer))
2386 (pop-to-buffer (current-buffer))
2389 (defun mime-viewer::quitting-method/draft-preview ()
2390 (let ((mother mime::preview/mother-buffer))
2392 (switch-to-buffer mother)
2393 (goto-char (point-min))
2397 (regexp-quote mime::article/draft-header-separator)
2401 (insert mime::article/draft-header-separator)
2402 (set-buffer-modified-p (buffer-modified-p))
2404 (mime-viewer/kill-buffer)
2405 (pop-to-buffer mother)
2408 (set-alist 'mime-viewer/quitting-method-alist
2410 (function mime-viewer::quitting-method/draft-preview)
2413 (set-alist 'mime-viewer/quitting-method-alist
2415 (function mime-viewer::quitting-method/draft-preview)
2422 (defun mime-editor::edit-again (code-conversion)
2424 (goto-char (point-min))
2425 (let ((ctl (mime/Content-Type)))
2427 (let ((ctype (car ctl))
2430 (if (string-match "/" ctype)
2432 (setq type (substring ctype 0 (match-beginning 0)))
2433 (setq stype (substring ctype (match-end 0)))
2438 ((string-equal type "multipart")
2439 (let* ((boundary (assoc-value "boundary" params))
2441 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2443 (re-search-forward boundary-pat nil t)
2444 (let ((bb (match-beginning 0)) eb tag)
2445 (setq tag (format "\n--<<%s>>-{\n" stype))
2448 (setq bb (+ bb (length tag)))
2450 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2452 (setq eb (match-beginning 0))
2453 (replace-match (format "--}-<<%s>>\n" stype))
2455 (narrow-to-region bb eb)
2456 (goto-char (point-min))
2457 (while (re-search-forward boundary-pat nil t)
2458 (let ((beg (match-beginning 0))
2460 (delete-region beg (match-end 0))
2462 (if (re-search-forward boundary-pat nil t)
2463 (setq end (match-beginning 0))
2464 (setq end (point-max))
2467 (narrow-to-region beg end)
2468 (mime-editor::edit-again code-conversion)
2469 (goto-char (point-max))
2472 (goto-char (point-min))
2473 (or (= (point-min) 1)
2474 (delete-region (point-min)
2475 (if (search-forward "\n\n" nil t)
2483 (let ((bytes (+ 14 (length ctype))))
2484 (mapconcat (function
2486 (if (string-equal (car attr) "charset")
2488 (setq charset (cdr attr))
2496 (setq bytes (+ bytes bs 2))
2499 (setq bytes (+ bs 1))
2507 (if (re-search-forward
2508 "Content-Transfer-Encoding:" nil t)
2509 (let ((beg (match-beginning 0))
2510 (hbeg (match-end 0))
2511 (end (std11-field-end)))
2513 (eliminate-top-spaces
2514 (std11-unfold-string
2515 (buffer-substring hbeg end))))
2516 (if (or charset (string-equal type "text"))
2518 (delete-region beg (1+ end))
2519 (goto-char (point-min))
2520 (if (search-forward "\n\n" nil t)
2523 (match-end 0)(point-max) encoding)
2527 (if (or code-conversion encoded)
2528 (decode-mime-charset-region
2529 (point-min)(point-max)
2530 (or charset default-mime-charset))
2533 (if (re-search-forward "^$" nil t)
2537 (if (= (point-min) 1)
2543 (concat type "/" stype pstr) encoding)))
2545 (delete-region (point-min) he)
2548 (concat type "/" stype pstr) encoding))
2552 (decode-mime-charset-region (point-min) (point-max)
2553 default-mime-charset)
2557 (defun mime/edit-again (&optional code-conversion no-separator no-mode)
2559 (mime-editor::edit-again code-conversion)
2560 (goto-char (point-min))
2564 (if (re-search-forward
2565 (concat "^\\(" (regexp-quote mail-header-separator) "\\)?$")
2570 (goto-char (point-min))
2571 (while (re-search-forward
2572 "^\\(Content-.*\\|Mime-Version\\):" nil t)
2573 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2576 (and (re-search-forward "^$")
2577 (replace-match mail-header-separator)
2589 (run-hooks 'tm-edit-load-hook)
2591 ;;; tm-edit.el ends here