1 ;;; mime-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 ;; Renamed: 1997/2/21 from tm-edit.el
10 ;; Version: $Revision: 0.73 $
11 ;; Keywords: MIME, multimedia, multilingual, mail, news
13 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
15 ;; This program is free software; you can redistribute it and/or
16 ;; modify it under the terms of the GNU General Public License as
17 ;; published by the Free Software Foundation; either version 2, or (at
18 ;; your option) any later version.
20 ;; This program is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
32 ;; This is an Emacs minor mode for editing Internet multimedia
33 ;; messages formatted in MIME (RFC 2045, 2046, 2047, 2048 and 2049).
34 ;; All messages in this mode are composed in the tagged MIME format,
35 ;; that are described in the following examples. The messages
36 ;; composed in the tagged MIME format are automatically translated
37 ;; into a MIME compliant message when exiting the mode.
39 ;; Mule (multilingual feature of Emacs 20 and multilingual extension
40 ;; for XEmacs 20) has a capability of handling multilingual text in
41 ;; limited ISO-2022 manner that is based on early experiences in
42 ;; Japanese Internet community and resulted in RFC 1468 (ISO-2022-JP
43 ;; charset for MIME). In order to enable multilingual capability in
44 ;; single text message in MIME, charset of multilingual text written
45 ;; in Mule is declared as either `ISO-2022-JP-2' [RFC 1554]. Mule is
46 ;; required for reading the such messages.
48 ;; This MIME composer can work with Mail mode, mh-e letter Mode, and
49 ;; News mode. First of all, you need the following autoload
50 ;; definition to load mime-edit-mode automatically:
52 ;; (autoload 'turn-on-mime-edit "mime-edit"
53 ;; "Minor mode for editing MIME message." t)
55 ;; In case of Mail mode (includes VM mode), you need the following
58 ;; (add-hook 'mail-mode-hook 'turn-on-mime-edit)
59 ;; (add-hook 'mail-send-hook 'mime-edit-maybe-translate)
61 ;; In case of MH-E, you need the following hook definition:
63 ;; (add-hook 'mh-letter-mode-hook
66 ;; (turn-on-mime-edit)
67 ;; (make-local-variable 'mail-header-separator)
68 ;; (setq mail-header-separator "--------")
70 ;; (add-hook 'mh-before-send-letter-hook 'mime-edit-maybe-translate)
72 ;; In case of News mode, you need the following hook definition:
74 ;; (add-hook 'news-reply-mode-hook 'turn-on-mime-edit)
75 ;; (add-hook 'news-inews-hook 'mime-edit-maybe-translate)
77 ;; In case of Emacs 19, it is possible to emphasize the message tags
78 ;; using font-lock mode as follows:
80 ;; (add-hook 'mime-edit-mode-hook
84 ;; (setq font-lock-keywords (list mime-edit-tag-regexp))
87 ;; The message tag looks like:
89 ;; --[[TYPE/SUBTYPE;PARAMETERS][ENCODING]]
91 ;; The tagged MIME message examples:
93 ;; This is a conventional plain text. It should be translated into
97 ;; This is also a plain text. But, it is explicitly specified as is.
98 ;;--[[text/plain; charset=ISO-8859-1]]
99 ;; This is also a plain text. But charset is specified as iso-8859-1.
101 ;; ¡Hola! Buenos días. ¿Cómo está usted?
102 ;;--[[text/enriched]]
103 ;; <center>This is a richtext.</center>
105 ;;--[[image/gif][base64]]^M...image encoded in base64 comes here...
107 ;;--[[audio/basic][base64]]^M...audio encoded in base64 comes here...
113 (require 'mail-utils)
116 (require 'eword-encode)
124 (defconst mime-edit-RCS-ID
125 "$Id: mime-edit.el,v 0.73 1997-03-15 20:36:32 morioka Exp $")
127 (defconst mime-edit-version (get-version-string mime-edit-RCS-ID))
129 (defconst mime-edit-version-name
130 (concat "SEMI MIME-Edit " mime-edit-version))
136 (defvar mime-ignore-preceding-spaces nil
137 "*Ignore preceding white spaces if non-nil.")
139 (defvar mime-ignore-trailing-spaces nil
140 "*Ignore trailing white spaces if non-nil.")
142 (defvar mime-ignore-same-text-tag t
143 "*Ignore preceding text content-type tag that is same with new one.
144 If non-nil, the text tag is not inserted unless something different.")
146 (defvar mime-auto-hide-body t
147 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
149 (defvar mime-edit-voice-recorder
150 (function mime-edit-voice-recorder-for-sun)
151 "*Function to record a voice message and encode it. [mime-edit.el]")
153 (defvar mime-edit-mode-hook nil
154 "*Hook called when enter MIME mode.")
156 (defvar mime-edit-translate-hook nil
157 "*Hook called before translating into a MIME compliant message.
158 To insert a signature file automatically, call the function
159 `mime-edit-insert-signature' from this hook.")
161 (defvar mime-edit-exit-hook nil
162 "*Hook called when exit MIME mode.")
164 (defvar mime-content-types
166 ;; Charset parameter need not to be specified, since it is
167 ;; defined automatically while translation.
169 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
172 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
175 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
178 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
181 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
189 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
190 ("directory" "/pub/GNU/elisp/mime")
192 ("mode" "image" "ascii" "local8"))
197 ("mode" "image" "ascii" "local8"))
198 ("tftp" ("site") ("name"))
199 ("afs" ("site") ("name"))
200 ("local-file" ("site") ("name"))
201 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
206 ("octet-stream" ("type" "" "tar" "shar"))
208 ("x-kiss" ("x-cnf")))
221 "*Alist of content-type, subtype, parameters and its values.")
223 (defvar mime-file-types
225 "text" "richtext" nil
233 "application" "postscript" nil
235 "attachment" (("filename" . file))
240 "inline" (("filename" . file))
245 "inline" (("filename" . file))
250 "inline" (("filename" . file))
255 "inline" (("filename" . file))
260 "inline" (("filename" . file))
265 "inline" (("filename" . file))
270 "inline" (("filename" . file))
275 "attachment" (("filename" . file))
280 "attachment" (("filename" . file))
283 "application" "octet-stream" (("type" . "emacs-lisp"))
285 "attachment" (("filename" . file))
288 "application" "octet-stream" (("type" . "common-lisp"))
290 "attachment" (("filename" . file))
293 "application" "octet-stream" (("type" . "tar+gzip"))
295 "attachment" (("filename" . file))
298 "application" "octet-stream" (("type" . "tar+gzip"))
300 "attachment" (("filename" . file))
303 "application" "octet-stream" (("type" . "tar+compress"))
305 "attachment" (("filename" . file))
308 "application" "octet-stream" (("type" . "tar+compress"))
310 "attachment" (("filename" . file))
313 "application" "octet-stream" (("type" . "gzip"))
315 "attachment" (("filename" . file))
318 "application" "octet-stream" (("type" . "compress"))
320 "attachment" (("filename" . file))
323 "application" "octet-stream" (("type" . "lha"))
325 "attachment" (("filename" . file))
328 "application" "zip" nil
330 "attachment" (("filename" . file))
333 "application" "octet-stream" (("type" . "patch"))
335 "attachment" (("filename" . file))
338 "application" "octet-stream" (("type" . "patch"))
340 "attachment" (("filename" . file))
343 "text" "plain" nil nil)
345 "application" "octet-stream" nil
347 "attachment" (("filename" . file))
350 "*Alist of file name, types, parameters, and default encoding.
351 If encoding is nil, it is determined from its contents.")
354 ;;; @@ about charset, encoding and transfer-level
357 (defvar mime-charset-type-list
359 (iso-8859-1 8 "quoted-printable")
360 (iso-8859-2 8 "quoted-printable")
361 (iso-8859-3 8 "quoted-printable")
362 (iso-8859-4 8 "quoted-printable")
363 (iso-8859-5 8 "quoted-printable")
364 (koi8-r 8 "quoted-printable")
365 (iso-8859-7 8 "quoted-printable")
366 (iso-8859-8 8 "quoted-printable")
367 (iso-8859-9 8 "quoted-printable")
368 (iso-2022-jp 7 "base64")
369 (iso-2022-kr 7 "base64")
371 (cn-gb2312 8 "quoted-printable")
373 (gb2312 8 "quoted-printable")
375 (iso-2022-jp-2 7 "base64")
376 (iso-2022-int-1 7 "base64")
379 (defvar mime-transfer-level 7
380 "*A number of network transfer level. It should be bigger than 7.")
381 (make-variable-buffer-local 'mime-transfer-level)
383 (defsubst mime-encoding-name (transfer-level &optional not-omit)
384 (cond ((> transfer-level 8) "binary")
385 ((= transfer-level 8) "8bit")
389 (defvar mime-transfer-level-string
390 (mime-encoding-name mime-transfer-level 'not-omit)
391 "A string formatted version of mime-transfer-level")
392 (make-variable-buffer-local 'mime-transfer-level-string)
394 (defun mime-make-charset-default-encoding-alist (transfer-level)
396 (lambda (charset-type)
397 (let ((charset (car charset-type))
398 (type (nth 1 charset-type))
399 (encoding (nth 2 charset-type))
401 (if (<= type transfer-level)
402 (cons charset (mime-encoding-name type))
403 (cons charset encoding)
405 mime-charset-type-list))
407 (defvar mime-edit-charset-default-encoding-alist
408 (mime-make-charset-default-encoding-alist mime-transfer-level))
409 (make-variable-buffer-local 'mime-edit-charset-default-encoding-alist)
412 ;;; @@ about message inserting
415 (defvar mime-edit-yank-ignored-field-list
416 '("Received" "Approved" "Path" "Replied" "Status"
417 "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
418 "Delete these fields from original message when it is inserted
419 as message/rfc822 part.
420 Each elements are regexp of field-name. [mime-edit.el]")
422 (defvar mime-edit-yank-ignored-field-regexp
424 (apply (function regexp-or) mime-edit-yank-ignored-field-list)
427 (defvar mime-edit-message-inserter-alist nil)
428 (defvar mime-edit-mail-inserter-alist nil)
431 ;;; @@ about message splitting
434 (defvar mime-edit-split-message t
435 "*Split large message if it is non-nil. [mime-edit.el]")
437 (defvar mime-edit-message-default-max-lines 1000
438 "*Default maximum lines of a message. [mime-edit.el]")
440 (defvar mime-edit-message-max-lines-alist
441 '((news-reply-mode . 500))
442 "Alist of major-mode vs maximum lines of a message.
443 If it is not specified for a major-mode,
444 `mime-edit-message-default-max-lines' is used. [mime-edit.el]")
446 (defconst mime-edit-split-ignored-field-regexp
447 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
449 (defvar mime-edit-split-blind-field-regexp
450 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
452 (defvar mime-edit-split-message-sender-alist nil)
454 (defvar mime-edit-news-reply-mode-server-running nil)
460 (defvar mime-edit-signing-type 'pgp-elkins
461 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [mime-edit.el]")
463 (defvar mime-edit-encrypting-type 'pgp-elkins
464 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [mime-edit.el]")
470 (defconst mime-edit-single-part-tag-regexp
471 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
472 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
474 (defconst mime-edit-quoted-single-part-tag-regexp
475 (concat "- " (substring mime-edit-single-part-tag-regexp 1)))
477 (defconst mime-edit-multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
479 (defconst mime-edit-multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
481 (defconst mime-edit-beginning-tag-regexp
482 (regexp-or mime-edit-single-part-tag-regexp
483 mime-edit-multipart-beginning-regexp))
485 (defconst mime-edit-end-tag-regexp
486 (regexp-or mime-edit-single-part-tag-regexp
487 mime-edit-multipart-end-regexp))
489 (defconst mime-edit-tag-regexp
490 (regexp-or mime-edit-single-part-tag-regexp
491 mime-edit-multipart-beginning-regexp
492 mime-edit-multipart-end-regexp))
494 (defvar mime-tag-format "--[[%s]]"
495 "*Control-string making a MIME tag.")
497 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
498 "*Control-string making a MIME tag with encoding.")
501 ;;; @@ multipart boundary
504 (defvar mime-multipart-boundary "Multipart"
505 "*Boundary of a multipart message.")
508 ;;; @@ optional header fields
511 (defvar mime-edit-insert-x-emacs-field t
512 "*If non-nil, insert X-Emacs header field.")
514 (defvar mime-edit-x-emacs-value
516 (concat emacs-version
520 (let ((ver (if (string-match "\\.[0-9]+$" emacs-version)
521 (substring emacs-version 0 (match-beginning 0))
524 (concat "Emacs " ver ", MULE " mule-version)
531 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
532 "*Specify MIME tspecials.
533 Tspecials means any character that matches with it in header must be quoted.")
535 (defconst mime-edit-mime-version-value
536 (concat "1.0 (generated by " mime-edit-version-name ")")
537 "MIME version number.")
540 ;;; @ keymap and menu
543 (defvar mime-edit-mode-flag nil)
544 (make-variable-buffer-local 'mime-edit-mode-flag)
546 (defvar mime-edit-mode-map (make-sparse-keymap)
547 "Keymap for MIME-Edit mode commands.")
549 (define-key mime-edit-mode-map
550 "\C-c\C-x\C-t" 'mime-edit-insert-text)
551 (define-key mime-edit-mode-map
552 "\C-c\C-x\C-i" 'mime-edit-insert-file)
553 (define-key mime-edit-mode-map
554 "\C-c\C-x\C-e" 'mime-edit-insert-external)
555 (define-key mime-edit-mode-map
556 "\C-c\C-x\C-v" 'mime-edit-insert-voice)
557 (define-key mime-edit-mode-map
558 "\C-c\C-x\C-y" 'mime-edit-insert-message)
559 (define-key mime-edit-mode-map
560 "\C-c\C-x\C-m" 'mime-edit-insert-mail)
561 (define-key mime-edit-mode-map
562 "\C-c\C-x\C-w" 'mime-edit-insert-signature)
563 (define-key mime-edit-mode-map
564 "\C-c\C-x\C-s" 'mime-edit-insert-signature)
565 (define-key mime-edit-mode-map
566 "\C-c\C-x\C-k" 'mime-edit-insert-key)
567 (define-key mime-edit-mode-map
568 "\C-c\C-xt" 'mime-edit-insert-tag)
570 (define-key mime-edit-mode-map
571 "\C-c\C-m\C-a" 'mime-edit-enclose-alternative-region)
572 (define-key mime-edit-mode-map
573 "\C-c\C-m\C-p" 'mime-edit-enclose-parallel-region)
574 (define-key mime-edit-mode-map
575 "\C-c\C-m\C-m" 'mime-edit-enclose-mixed-region)
576 (define-key mime-edit-mode-map
577 "\C-c\C-m\C-d" 'mime-edit-enclose-digest-region)
578 (define-key mime-edit-mode-map
579 "\C-c\C-m\C-s" 'mime-edit-enclose-signed-region)
580 (define-key mime-edit-mode-map
581 "\C-c\C-m\C-e" 'mime-edit-enclose-encrypted-region)
582 (define-key mime-edit-mode-map
583 "\C-c\C-m\C-q" 'mime-edit-enclose-quote-region)
585 (define-key mime-edit-mode-map
586 "\C-c\C-x7" 'mime-edit-set-transfer-level-7bit)
587 (define-key mime-edit-mode-map
588 "\C-c\C-x8" 'mime-edit-set-transfer-level-8bit)
589 (define-key mime-edit-mode-map
590 "\C-c\C-x/" 'mime-edit-set-split)
591 (define-key mime-edit-mode-map
592 "\C-c\C-xs" 'mime-edit-set-sign)
593 (define-key mime-edit-mode-map
594 "\C-c\C-xv" 'mime-edit-set-sign)
595 (define-key mime-edit-mode-map
596 "\C-c\C-xe" 'mime-edit-set-encrypt)
597 (define-key mime-edit-mode-map
598 "\C-c\C-xh" 'mime-edit-set-encrypt)
599 (define-key mime-edit-mode-map
600 "\C-c\C-x\C-p" 'mime-edit-preview-message)
601 (define-key mime-edit-mode-map
602 "\C-c\C-x\C-z" 'mime-edit-exit)
603 (define-key mime-edit-mode-map
604 "\C-c\C-x?" 'mime-edit-help)
606 (defconst mime-edit-menu-title "MIME-Edit")
608 (defconst mime-edit-menu-list
609 '((mime-help "Describe MIME editor mode" mime-edit-help)
610 (file "Insert File" mime-edit-insert-file)
611 (external "Insert External" mime-edit-insert-external)
612 (voice "Insert Voice" mime-edit-insert-voice)
613 (message "Insert Message" mime-edit-insert-message)
614 (mail "Insert Mail" mime-edit-insert-mail)
615 (signature "Insert Signature" mime-edit-insert-signature)
616 (text "Insert Text" mime-edit-insert-text)
617 (tag "Insert Tag" mime-edit-insert-tag)
618 (alternative "Enclose as alternative"
619 mime-edit-enclose-alternative-region)
620 (parallel "Enclose as parallel" mime-edit-enclose-parallel-region)
621 (mixed "Enclose as serial" mime-edit-enclose-mixed-region)
622 (digest "Enclose as digest" mime-edit-enclose-digest-region)
623 (signed "Enclose as signed" mime-edit-enclose-signed-region)
624 (encrypted "Enclose as encrypted" mime-edit-enclose-encrypted-region)
625 (quote "Verbatim region" mime-edit-enclose-quote-region)
626 (key "Insert Public Key" mime-edit-insert-key)
627 (split "About split" mime-edit-set-split)
628 (sign "About sign" mime-edit-set-sign)
629 (encrypt "About encryption" mime-edit-set-encrypt)
630 (preview "Preview Message" mime-edit-preview-message)
631 (level "Toggle transfer-level" mime-edit-toggle-transfer-level)
633 "MIME-edit menubar entry.")
635 (cond (running-xemacs
636 ;; modified by Pekka Marjola <pema@iki.fi>
637 ;; 1995/9/5 (c.f. [tm-en:69])
638 (defun mime-edit-define-menu-for-xemacs ()
639 "Define menu for Emacs 19."
640 (cond ((featurep 'menubar)
641 (make-local-variable 'current-menubar)
642 (set-buffer-menubar current-menubar)
645 (cons mime-edit-menu-title
648 (vector (nth 1 item)(nth 2 item)
651 mime-edit-menu-list)))
654 ;; modified by Steven L. Baur <steve@miranova.com>
655 ;; 1995/12/6 (c.f. [tm-en:209])
656 (or (boundp 'mime-edit-popup-menu-for-xemacs)
657 (setq mime-edit-popup-menu-for-xemacs
658 (append '("MIME Commands" "---")
659 (mapcar (function (lambda (item)
663 mime-edit-menu-list)))
666 ((>= emacs-major-version 19)
667 (define-key mime-edit-mode-map [menu-bar mime-edit]
668 (cons mime-edit-menu-title
669 (make-sparse-keymap mime-edit-menu-title)))
672 (define-key mime-edit-mode-map
673 (vector 'menu-bar 'mime-edit (car item))
674 (cons (nth 1 item)(nth 2 item))
677 (reverse mime-edit-menu-list)
686 (defun mime-edit-mode ()
687 "MIME minor mode for editing the tagged MIME message.
689 In this mode, basically, the message is composed in the tagged MIME
690 format. The message tag looks like:
692 --[[text/plain; charset=ISO-2022-JP][7bit]]
694 The tag specifies the MIME content type, subtype, optional parameters
695 and transfer encoding of the message following the tag. Messages
696 without any tag are treated as `text/plain' by default. Charset and
697 transfer encoding are automatically defined unless explicitly
698 specified. Binary messages such as audio and image are usually
699 hidden. The messages in the tagged MIME format are automatically
700 translated into a MIME compliant message when exiting this mode.
702 Available charsets depend on Emacs version being used. The following
703 lists the available charsets of each emacs.
705 Without mule: US-ASCII and ISO-8859-1 (or other charset) are available.
706 With mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
707 ISO-2022-JP, ISO-2022-JP-2, EUC-KR, CN-GB-2312,
708 CN-BIG5 and ISO-2022-INT-1 are available.
710 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
711 be used to represent multilingual text in intermixed manner. Any
712 languages that has no registered charset are represented as either
713 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
715 If you want to use non-ISO-8859-1 charset in Emacs 19 or XEmacs
716 without mule, please set variable `default-mime-charset'. This
717 variable must be symbol of which name is a MIME charset.
719 If you want to add more charsets in mule, please set variable
720 `charsets-mime-charset-alist'. This variable must be alist of which
721 key is list of charset and value is symbol of MIME charset. If name
722 of coding-system is different as MIME charset, please set variable
723 `mime-charset-coding-system-alist'. This variable must be alist of
724 which key is MIME charset and value is coding-system.
726 Following commands are available in addition to major mode commands:
729 \\[mime-edit-insert-text] insert a text message.
730 \\[mime-edit-insert-file] insert a (binary) file.
731 \\[mime-edit-insert-external] insert a reference to external body.
732 \\[mime-edit-insert-voice] insert a voice message.
733 \\[mime-edit-insert-message] insert a mail or news message.
734 \\[mime-edit-insert-mail] insert a mail message.
735 \\[mime-edit-insert-signature] insert a signature file at end.
736 \\[mime-edit-insert-key] insert PGP public key.
737 \\[mime-edit-insert-tag] insert a new MIME tag.
739 \[make enclosure (maybe multipart)\]
740 \\[mime-edit-enclose-alternative-region] enclose as multipart/alternative.
741 \\[mime-edit-enclose-parallel-region] enclose as multipart/parallel.
742 \\[mime-edit-enclose-mixed-region] enclose as multipart/mixed.
743 \\[mime-edit-enclose-digest-region] enclose as multipart/digest.
744 \\[mime-edit-enclose-signed-region] enclose as PGP signed.
745 \\[mime-edit-enclose-encrypted-region] enclose as PGP encrypted.
746 \\[mime-edit-enclose-quote-region] enclose as verbose mode (to avoid to expand tags)
749 \\[mime-edit-set-transfer-level-7bit] set transfer-level as 7.
750 \\[mime-edit-set-transfer-level-8bit] set transfer-level as 8.
751 \\[mime-edit-set-split] set message splitting mode.
752 \\[mime-edit-set-sign] set PGP-sign mode.
753 \\[mime-edit-set-encrypt] set PGP-encryption mode.
754 \\[mime-edit-preview-message] preview editing MIME message.
755 \\[mime-edit-exit] exit and translate into a MIME compliant message.
756 \\[mime-edit-help] show this help.
757 \\[mime-edit-maybe-translate] exit and translate if in MIME mode, then split.
759 Additional commands are available in some major modes:
760 C-c C-c exit, translate and run the original command.
761 C-c C-s exit, translate and run the original command.
763 The following is a message example written in the tagged MIME format.
764 TABs at the beginning of the line are not a part of the message:
766 This is a conventional plain text. It should be translated
769 This is also a plain text. But, it is explicitly specified as
771 --[[text/plain; charset=ISO-8859-1]]
772 This is also a plain text. But charset is specified as
775 ¡Hola! Buenos días. ¿Cómo está usted?
777 This is a <bold>enriched text</bold>.
778 --[[image/gif][base64]]...image encoded in base64 here...
779 --[[audio/basic][base64]]...audio encoded in base64 here...
781 User customizable variables (not documented all of them):
783 Specifies a key prefix for MIME minor mode commands.
785 mime-ignore-preceding-spaces
786 Preceding white spaces in a message body are ignored if non-nil.
788 mime-ignore-trailing-spaces
789 Trailing white spaces in a message body are ignored if non-nil.
792 Hide a non-textual body message encoded in base64 after insertion
796 A number of network transfer level. It should be bigger than 7.
797 If you are in 8bit-through environment, please set 8.
799 mime-edit-voice-recorder
800 Specifies a function to record a voice message and encode it.
801 The function `mime-edit-voice-recorder-for-sun' is for Sun
805 Turning on MIME mode calls the value of mime-edit-mode-hook, if
808 mime-edit-translate-hook
809 The value of mime-edit-translate-hook is called just before translating
810 the tagged MIME format into a MIME compliant message if it is
811 non-nil. If the hook call the function mime-edit-insert-signature,
812 the signature file will be inserted automatically.
815 Turning off MIME mode calls the value of mime-edit-exit-hook, if it is
818 (if mime-edit-mode-flag
820 (if (and (boundp 'mime-edit-touched-flag)
821 mime-edit-touched-flag)
823 (make-local-variable 'mime-edit-touched-flag)
824 (setq mime-edit-touched-flag t)
829 (cond (running-xemacs
830 (add-minor-mode 'mime-edit-mode-flag
831 '((" MIME-Edit " mime-transfer-level-string))
837 (set-alist 'minor-mode-alist
839 '((" MIME-Edit " mime-transfer-level-string)))
840 (set-alist 'minor-mode-map-alist
847 (defun turn-on-mime-edit ()
848 "Unconditionally turn on MIME-Edit mode."
850 (if mime-edit-mode-flag
851 (error "You are already editing a MIME message.")
852 (setq mime-edit-mode-flag t)
854 ;; Set transfer level into mode line
856 (setq mime-transfer-level-string
857 (mime-encoding-name mime-transfer-level 'not-omit))
858 (force-mode-line-update)
860 ;; Define menu for XEmacs.
862 (mime-edit-define-menu-for-xemacs)
867 ;; I don't care about saving these.
868 (setq paragraph-start
869 (regexp-or mime-edit-single-part-tag-regexp
871 (setq paragraph-separate
872 (regexp-or mime-edit-single-part-tag-regexp
874 (run-hooks 'mime-edit-mode-hook)
876 (substitute-command-keys
877 "Type \\[mime-edit-exit] to exit MIME mode, and type \\[mime-edit-help] to get help."))
881 (defalias 'edit-mime 'turn-on-mime-edit) ; for convenience
884 (defun mime-edit-exit (&optional nomime no-error)
885 "Translate the tagged MIME message into a MIME compliant message.
886 With no argument encode a message in the buffer into MIME, otherwise
887 just return to previous mode."
889 (if (not mime-edit-mode-flag)
891 (error "You aren't editing a MIME message.")
895 (run-hooks 'mime-edit-translate-hook)
896 (mime-edit-translate-buffer)))
897 ;; Restore previous state.
898 (setq mime-edit-mode-flag nil)
899 (if (and running-xemacs
901 (delete-menu-item (list mime-edit-menu-title))
904 (set-buffer-modified-p (buffer-modified-p))
905 (run-hooks 'mime-edit-exit-hook)
906 (message "Exit MIME editor mode.")
909 (defun mime-edit-maybe-translate ()
911 (mime-edit-exit nil t)
912 (call-interactively 'mime-edit-maybe-split-and-send)
915 (defun mime-edit-help ()
916 "Show help message about MIME mode."
918 (with-output-to-temp-buffer "*Help*"
919 (princ "MIME editor mode:\n")
920 (princ (documentation 'mime-edit-mode))
921 (print-help-return-message)))
923 (defun mime-edit-insert-text ()
924 "Insert a text message.
925 Charset is automatically obtained from the `charsets-mime-charset-alist'."
927 (let ((ret (mime-edit-insert-tag "text" nil nil)))
930 (if (looking-at mime-edit-single-part-tag-regexp)
932 ;; Make a space between the following message.
936 (if (and (member (second ret) '("enriched" "richtext"))
937 (fboundp 'enriched-mode)
940 (if (boundp 'enriched-mode)
944 (defun mime-edit-insert-file (file &optional verbose)
945 "Insert a message from a file."
946 (interactive "fInsert file as MIME message: \nP")
947 (let* ((guess (mime-find-file-type file))
949 (subtype (nth 1 guess))
950 (parameters (nth 2 guess))
951 (encoding (nth 3 guess))
952 (disposition-type (nth 4 guess))
953 (disposition-params (nth 5 guess))
956 (setq type (mime-prompt-for-type type)
957 subtype (mime-prompt-for-subtype type subtype)
959 (if (or (interactive-p) verbose)
960 (setq encoding (mime-prompt-for-encoding encoding))
962 (if (or (consp parameters) (stringp disposition-type))
963 (let ((rest parameters) cell attribute value)
966 (setq cell (car rest))
967 (setq attribute (car cell))
968 (setq value (cdr cell))
970 (setq value (std11-wrap-as-quoted-string
971 (file-name-nondirectory file)))
973 (setq parameters (concat parameters "; " attribute "=" value))
974 (setq rest (cdr rest))
979 (concat parameters "\n"
980 "Content-Disposition: " disposition-type))
981 (setq rest disposition-params)
983 (setq cell (car rest))
984 (setq attribute (car cell))
985 (setq value (cdr cell))
987 (setq value (std11-wrap-as-quoted-string
988 (file-name-nondirectory file)))
991 (concat parameters "; " attribute "=" value))
992 (setq rest (cdr rest))
996 (mime-edit-insert-tag type subtype parameters)
997 (mime-edit-insert-binary-file file encoding)
1000 (defun mime-edit-insert-external ()
1001 "Insert a reference to external body."
1003 (mime-edit-insert-tag "message" "external-body" nil ";\n\t")
1005 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
1007 (let* ((pritype (mime-prompt-for-type))
1008 (subtype (mime-prompt-for-subtype pritype))
1009 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
1012 (insert "Content-Type: "
1013 pritype "/" subtype (or parameters "") "\n")))
1014 (if (and (not (eobp))
1015 (not (looking-at mime-edit-single-part-tag-regexp)))
1016 (insert (mime-make-text-tag) "\n")))
1018 (defun mime-edit-insert-voice ()
1019 "Insert a voice message."
1023 "What transfer encoding: "
1024 mime-file-encoding-method-alist nil t nil)))
1025 (mime-edit-insert-tag "audio" "basic" nil)
1026 (mime-edit-define-encoding encoding)
1028 (narrow-to-region (1- (point))(point))
1030 (funcall mime-edit-voice-recorder encoding)
1033 (invisible-region (point-min)(point-max))
1034 (goto-char (point-max))
1037 (defun mime-edit-insert-signature (&optional arg)
1038 "Insert a signature file."
1040 (let ((signature-insert-hook
1043 (apply (function mime-edit-insert-tag)
1044 (mime-find-file-type signature-file-name))
1047 (insert-signature arg)
1051 ;; Insert a new tag around a point.
1053 (defun mime-edit-insert-tag (&optional pritype subtype parameters delimiter)
1054 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
1055 If nothing is inserted, return nil."
1058 (mime-edit-goto-tag)
1059 (if (and (re-search-forward mime-edit-tag-regexp nil t)
1060 (< (match-beginning 0) p)
1063 (goto-char (match-beginning 0))
1072 (mime-prompt-for-type)))
1075 (mime-prompt-for-subtype pritype)))
1078 (mime-prompt-for-parameters pritype subtype delimiter)))
1079 ;; Make a new MIME tag.
1080 (setq newtag (mime-make-tag pritype subtype parameters))
1081 ;; Find an current MIME tag.
1084 (if (mime-edit-goto-tag)
1085 (buffer-substring (match-beginning 0) (match-end 0))
1086 ;; Assume content type is 'text/plan'.
1087 (mime-make-tag "text" "plain")
1089 ;; We are only interested in TEXT.
1091 (not (mime-test-content-type
1092 (mime-edit-get-contype oldtag) "text")))
1095 (if (or (not oldtag) ;Not text
1096 (or mime-ignore-same-text-tag
1097 (not (string-equal oldtag newtag))))
1099 ;; Mark the beginning of the tag for convenience.
1100 (push-mark (point) 'nomsg)
1101 (insert newtag "\n")
1102 (list pritype subtype parameters) ;New tag is created.
1104 ;; Restore previous point.
1106 nil ;Nothing is created.
1110 (defun mime-edit-insert-binary-file (file &optional encoding)
1111 "Insert binary FILE at point.
1112 Optional argument ENCODING specifies an encoding method such as base64."
1113 (let* ((tagend (1- (point))) ;End of the tag
1114 (hide-p (and mime-auto-hide-body
1117 (let ((en (downcase encoding)))
1118 (or (string-equal en "7bit")
1119 (string-equal en "8bit")
1120 (string-equal en "binary")
1124 (narrow-to-region tagend (point))
1125 (mime-insert-encoded-file file encoding)
1128 (invisible-region (point-min) (point-max))
1129 (goto-char (point-max))
1131 (goto-char (point-max))
1134 (looking-at mime-edit-tag-regexp)
1135 (= (point)(point-max))
1136 (mime-edit-insert-tag "text" "plain")
1138 ;; Define encoding even if it is 7bit.
1139 (if (stringp encoding)
1141 (goto-char tagend) ; Make sure which line the tag is on.
1142 (mime-edit-define-encoding encoding)
1147 ;; Commands work on a current message flagment.
1149 (defun mime-edit-goto-tag ()
1150 "Search for the beginning of the tagged MIME message."
1151 (let ((current (point)))
1152 (if (looking-at mime-edit-tag-regexp)
1154 ;; At first, go to the end.
1155 (cond ((re-search-forward mime-edit-beginning-tag-regexp nil t)
1156 (goto-char (1- (match-beginning 0))) ;For multiline tag
1159 (goto-char (point-max))
1161 ;; Then search for the beginning.
1162 (re-search-backward mime-edit-end-tag-regexp nil t)
1163 (or (looking-at mime-edit-beginning-tag-regexp)
1164 ;; Restore previous point.
1171 (defun mime-edit-content-beginning ()
1172 "Return the point of the beginning of content."
1174 (let ((beg (save-excursion
1175 (beginning-of-line) (point))))
1176 (if (mime-edit-goto-tag)
1177 (let ((top (point)))
1178 (goto-char (match-end 0))
1179 (if (and (= beg top)
1180 (= (following-char) ?\^M))
1184 ;; Default text/plain tag.
1185 (goto-char (point-min))
1187 (concat "\n" (regexp-quote mail-header-separator)
1188 (if mime-ignore-preceding-spaces
1189 "[ \t\n]*\n" "\n")) nil 'move)
1193 (defun mime-edit-content-end ()
1194 "Return the point of the end of content."
1196 (let ((beg (point)))
1197 (if (mime-edit-goto-tag)
1198 (let ((top (point)))
1199 (goto-char (match-end 0))
1200 (if (invisible-p (point))
1201 (next-visible-point (point))
1202 ;; Move to the end of this text.
1203 (if (re-search-forward mime-edit-tag-regexp nil 'move)
1204 ;; Don't forget a multiline tag.
1205 (goto-char (match-beginning 0))
1209 ;; Assume the message begins with text/plain.
1210 (goto-char (mime-edit-content-beginning))
1211 (if (re-search-forward mime-edit-tag-regexp nil 'move)
1212 ;; Don't forget a multiline tag.
1213 (goto-char (match-beginning 0)))
1217 (defun mime-edit-define-charset (charset)
1218 "Set charset of current tag to CHARSET."
1220 (if (mime-edit-goto-tag)
1221 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1222 (delete-region (match-beginning 0) (match-end 0))
1225 (mime-edit-set-parameter
1226 (mime-edit-get-contype tag)
1227 "charset" (upcase (symbol-name charset)))
1228 (mime-edit-get-encoding tag)))
1231 (defun mime-edit-define-encoding (encoding)
1232 "Set encoding of current tag to ENCODING."
1234 (if (mime-edit-goto-tag)
1235 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1236 (delete-region (match-beginning 0) (match-end 0))
1237 (insert (mime-create-tag (mime-edit-get-contype tag) encoding)))
1240 (defun mime-edit-choose-charset ()
1241 "Choose charset of a text following current point."
1242 (detect-mime-charset-region (point) (mime-edit-content-end))
1245 (defun mime-make-text-tag (&optional subtype)
1246 "Make a tag for a text after current point.
1247 Subtype of text type can be specified by an optional argument SUBTYPE.
1248 Otherwise, it is obtained from mime-content-types."
1249 (let* ((pritype "text")
1250 (subtype (or subtype
1251 (car (car (cdr (assoc pritype mime-content-types)))))))
1252 ;; Charset should be defined later.
1253 (mime-make-tag pritype subtype)))
1256 ;; Tag handling functions
1258 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1259 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1260 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1264 (defun mime-create-tag (contype &optional encoding)
1265 "Make a tag with CONTENT-TYPE and optional ENCODING."
1266 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1269 (defun mime-edit-get-contype (tag)
1270 "Return Content-Type (including parameters) of TAG."
1272 (or (string-match mime-edit-single-part-tag-regexp tag)
1273 (string-match mime-edit-multipart-beginning-regexp tag)
1274 (string-match mime-edit-multipart-end-regexp tag)
1276 (substring tag (match-beginning 1) (match-end 1))
1279 (defun mime-edit-get-encoding (tag)
1280 "Return encoding of TAG."
1282 (string-match mime-edit-single-part-tag-regexp tag)
1284 (not (= (match-beginning 3) (match-end 3)))
1285 (substring tag (match-beginning 3) (match-end 3))))
1287 (defun mime-get-parameter (contype parameter)
1288 "For given CONTYPE return value for PARAMETER.
1289 Nil if no such parameter."
1293 (regexp-quote parameter)
1294 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1296 (substring contype (match-beginning 1) (match-end 1))
1297 nil ;No such parameter
1300 (defun mime-edit-set-parameter (contype parameter value)
1301 "For given CONTYPE set PARAMETER to VALUE."
1302 (let (ctype opt-fields)
1303 (if (string-match "\n[^ \t\n\r]+:" contype)
1304 (setq ctype (substring contype 0 (match-beginning 0))
1305 opt-fields (substring contype (match-beginning 0)))
1306 (setq ctype contype)
1311 (regexp-quote parameter)
1312 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1315 (concat (substring ctype 0 (match-beginning 1))
1317 (substring contype (match-end 1))
1319 (concat ctype "; " parameter "=" value opt-fields)
1322 (defun mime-strip-parameters (contype)
1323 "Return primary content-type and subtype without parameters for CONTYPE."
1324 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1325 (substring contype (match-beginning 1) (match-end 1)) nil))
1327 (defun mime-test-content-type (contype type &optional subtype)
1328 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1329 (and (stringp contype)
1332 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1333 (downcase contype))))
1338 (defun mime-find-file-type (file)
1339 "Guess Content-Type, subtype, and parameters from FILE."
1341 (guesses mime-file-types))
1342 (while (and (not guess) guesses)
1343 (if (string-match (car (car guesses)) file)
1344 (setq guess (cdr (car guesses))))
1345 (setq guesses (cdr guesses)))
1349 (defun mime-prompt-for-type (&optional default)
1350 "Ask for Content-type."
1352 ;; Repeat until primary content type is specified.
1353 (while (string-equal type "")
1355 (completing-read "What content type: "
1358 'require-match ;Type must be specified.
1361 (if (string-equal type "")
1363 (message "Content type is required.")
1370 (defun mime-prompt-for-subtype (type &optional default)
1371 "Ask for subtype of media-type TYPE."
1372 (let ((subtypes (cdr (assoc type mime-content-types))))
1374 (assoc default subtypes))
1375 (setq default (car (car subtypes)))
1381 "What content subtype: (default " default ") ")
1382 "What content subtype: ")
1383 (cdr (assoc type mime-content-types))
1385 'require-match ;Subtype must be specified.
1388 (if (string-equal answer "") default answer)))
1390 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1391 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1392 Optional DELIMITER specifies parameter delimiter (';' by default)."
1393 (let* ((delimiter (or delimiter "; "))
1398 (mime-prompt-for-parameters-1
1400 (cdr (assoc pritype mime-content-types))))))
1403 (if (and (stringp parameters)
1404 (not (string-equal parameters "")))
1405 (concat delimiter parameters)
1406 "" ;"" if no parameters
1409 (defun mime-prompt-for-parameters-1 (optlist)
1410 (apply (function append)
1411 (mapcar (function mime-prompt-for-parameter) optlist)))
1413 (defun mime-prompt-for-parameter (parameter)
1415 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1416 (let* ((prompt (car parameter))
1417 (choices (mapcar (function
1419 (if (consp e) e (list e))))
1421 (default (car (car choices)))
1427 (concat "What " prompt
1429 (if (string-equal default "") "\"\"" default)
1431 choices nil nil ""))
1432 ;; If nothing is selected, use default.
1433 (if (string-equal answer "")
1434 (setq answer default)))
1436 (read-string (concat "What " prompt ": "))))
1437 (cons (if (and answer
1438 (not (string-equal answer "")))
1440 ;; Note: control characters ignored!
1441 (if (string-match mime-tspecials-regexp answer)
1442 (concat "\"" answer "\"") answer)))
1443 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1446 (defun mime-prompt-for-encoding (default)
1447 "Ask for Content-Transfer-Encoding. [mime-edit.el]"
1452 "What transfer encoding: "
1453 mime-file-encoding-method-alist nil t default)
1459 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1462 (defvar mime-edit-translate-buffer-hook
1463 '(mime-edit-pgp-enclose-buffer
1464 mime-edit-translate-body
1465 mime-edit-translate-header))
1467 (defun mime-edit-translate-header ()
1468 "Encode the message header into network representation."
1469 (eword-encode-header 'code-conversion)
1470 (run-hooks 'mime-edit-translate-header-hook)
1473 (defun mime-edit-translate-buffer ()
1474 "Encode the tagged MIME message in current buffer in MIME compliant message."
1476 (if (catch 'mime-edit-error
1478 (run-hooks 'mime-edit-translate-buffer-hook)
1482 (error "Translation error!")
1485 (defun mime-edit-find-inmost ()
1486 (goto-char (point-min))
1487 (if (re-search-forward mime-edit-multipart-beginning-regexp nil t)
1488 (let ((bb (match-beginning 0))
1490 (type (buffer-substring (match-beginning 1)(match-end 1)))
1492 (setq end-exp (format "--}-<<%s>>\n" type))
1494 (if (re-search-forward end-exp nil t)
1496 (setq eb (match-beginning 0))
1497 (setq ee (match-end 0))
1499 (setq eb (point-max))
1500 (setq ee (point-max))
1502 (narrow-to-region be eb)
1504 (if (re-search-forward mime-edit-multipart-beginning-regexp nil t)
1506 (narrow-to-region (match-beginning 0)(point-max))
1507 (mime-edit-find-inmost)
1510 (list type bb be eb)
1513 (defun mime-edit-process-multipart-1 (boundary)
1514 (let ((ret (mime-edit-find-inmost)))
1516 (let ((type (car ret))
1517 (bb (nth 1 ret))(be (nth 2 ret))
1520 (narrow-to-region bb eb)
1521 (delete-region bb be)
1522 (setq bb (point-min))
1523 (setq eb (point-max))
1526 (if (looking-at mime-edit-multipart-end-regexp)
1527 (let ((beg (match-beginning 0))
1530 (delete-region beg end)
1531 (or (looking-at mime-edit-beginning-tag-regexp)
1533 (insert (concat (mime-make-text-tag) "\n"))
1535 (cond ((string-equal type "quote")
1536 (mime-edit-enquote-region bb eb)
1538 ((string-equal type "signed")
1539 (cond ((eq mime-edit-signing-type 'pgp-elkins)
1540 (mime-edit-sign-pgp-elkins bb eb boundary)
1542 ((eq mime-edit-signing-type 'pgp-kazu)
1543 (mime-edit-sign-pgp-kazu bb eb boundary)
1546 ((string-equal type "encrypted")
1547 (cond ((eq mime-edit-encrypting-type 'pgp-elkins)
1548 (mime-edit-encrypt-pgp-elkins bb eb boundary)
1550 ((eq mime-edit-encrypting-type 'pgp-kazu)
1551 (mime-edit-encrypt-pgp-kazu bb eb boundary)
1555 (nth 2 (mime-edit-translate-region bb eb
1559 (format "--[[multipart/%s;
1560 boundary=\"%s\"][7bit]]\n"
1565 (defun mime-edit-enquote-region (beg end)
1568 (narrow-to-region beg end)
1570 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1571 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1572 (replace-match (concat "- " (substring tag 1)))
1575 (defun mime-edit-dequote-region (beg end)
1578 (narrow-to-region beg end)
1580 (while (re-search-forward
1581 mime-edit-quoted-single-part-tag-regexp nil t)
1582 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1583 (replace-match (concat "-" (substring tag 2)))
1586 (defun mime-edit-sign-pgp-elkins (beg end boundary)
1589 (narrow-to-region beg end)
1591 (mime-edit-translate-region beg end boundary))
1593 (encoding (nth 1 ret))
1595 (pgp-boundary (concat "pgp-sign-" boundary))
1598 (insert (format "Content-Type: %s\n" ctype))
1600 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1603 (or (funcall (pgp-function 'mime-sign)
1604 (point-min)(point-max) nil nil pgp-boundary)
1605 (throw 'mime-edit-error 'pgp-error)
1609 (defvar mime-edit-encrypt-recipient-fields-list '("To" "cc"))
1611 (defun mime-edit-make-encrypt-recipient-header ()
1612 (let* ((names mime-edit-encrypt-recipient-fields-list)
1614 (std11-field-bodies (cons "From" names)
1615 nil mail-header-separator))
1618 (setq values (cdr values))))
1619 (header (and (stringp from)
1620 (if (string-equal from "")
1622 (format "From: %s\n" from)
1625 (while (and names values)
1626 (let ((name (car names))
1627 (value (car values))
1629 (and (stringp value)
1630 (or (string-equal value "")
1632 (setq header (concat header name ": " value "\n")
1633 recipients (if recipients
1634 (concat recipients " ," value)
1637 (setq names (cdr names)
1638 values (cdr values))
1640 (vector from recipients header)
1643 (defun mime-edit-encrypt-pgp-elkins (beg end boundary)
1646 (let (from recipients header)
1647 (let ((ret (mime-edit-make-encrypt-recipient-header)))
1648 (setq from (aref ret 0)
1649 recipients (aref ret 1)
1650 header (aref ret 2))
1652 (narrow-to-region beg end)
1654 (mime-edit-translate-region beg end boundary))
1656 (encoding (nth 1 ret))
1658 (pgp-boundary (concat "pgp-" boundary))
1662 (insert (format "Content-Type: %s\n" ctype))
1664 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1667 (or (funcall (pgp-function 'encrypt)
1668 recipients (point-min) (point-max) from)
1669 (throw 'mime-edit-error 'pgp-error)
1672 (insert (format "--[[multipart/encrypted;
1674 protocol=\"application/pgp-encrypted\"][7bit]]
1676 Content-Type: application/pgp-encrypted
1679 Content-Type: application/octet-stream
1680 Content-Transfer-Encoding: 7bit
1682 " pgp-boundary pgp-boundary pgp-boundary))
1683 (goto-char (point-max))
1684 (insert (format "\n--%s--\n" pgp-boundary))
1687 (defun mime-edit-sign-pgp-kazu (beg end boundary)
1690 (narrow-to-region beg end)
1692 (mime-edit-translate-region beg end boundary))
1694 (encoding (nth 1 ret))
1698 (insert (format "Content-Type: %s\n" ctype))
1700 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1703 (or (as-binary-process
1704 (funcall (pgp-function 'traditional-sign)
1706 (throw 'mime-edit-error 'pgp-error)
1710 "--[[application/pgp; format=mime][7bit]]\n")
1714 (defun mime-edit-encrypt-pgp-kazu (beg end boundary)
1716 (let (from recipients header)
1717 (let ((ret (mime-edit-make-encrypt-recipient-header)))
1718 (setq from (aref ret 0)
1719 recipients (aref ret 1)
1720 header (aref ret 2))
1723 (narrow-to-region beg end)
1725 (mime-edit-translate-region beg end boundary))
1727 (encoding (nth 1 ret))
1732 (insert (format "Content-Type: %s\n" ctype))
1734 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1737 (or (as-binary-process
1738 (funcall (pgp-function 'encrypt)
1739 recipients beg (point-max) nil 'maybe)
1741 (throw 'mime-edit-error 'pgp-error)
1745 "--[[application/pgp; format=mime][7bit]]\n")
1749 (defsubst replace-space-with-underline (str)
1750 (mapconcat (function
1758 (defun mime-edit-make-boundary ()
1759 (concat mime-multipart-boundary "_"
1760 (replace-space-with-underline (current-time-string))
1763 (defun mime-edit-translate-body ()
1764 "Encode the tagged MIME body in current buffer in MIME compliant message."
1767 (let ((boundary (mime-edit-make-boundary))
1770 (while (mime-edit-process-multipart-1
1771 (format "%s-%d" boundary i))
1775 ;; We are interested in message body.
1778 (goto-char (point-min))
1780 (concat "\n" (regexp-quote mail-header-separator)
1781 (if mime-ignore-preceding-spaces
1782 "[ \t\n]*\n" "\n")) nil 'move)
1786 (goto-char (point-max))
1787 (and mime-ignore-trailing-spaces
1788 (re-search-backward "[^ \t\n]\n" beg t)
1791 (setq ret (mime-edit-translate-region
1793 (format "%s-%d" boundary i)))
1795 (mime-edit-dequote-region (point-min)(point-max))
1796 (let ((contype (car ret)) ;Content-Type
1797 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1799 ;; Insert X-Emacs field
1800 (and mime-edit-insert-x-emacs-field
1801 (or (mail-position-on-field "X-Emacs")
1802 (insert mime-edit-x-emacs-value)
1804 ;; Make primary MIME headers.
1805 (or (mail-position-on-field "Mime-Version")
1806 (insert mime-edit-mime-version-value))
1807 ;; Remove old Content-Type and other fields.
1809 (goto-char (point-min))
1810 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1811 (narrow-to-region (point-min) (point))
1812 (goto-char (point-min))
1813 (mime-delete-field "Content-Type")
1814 (mime-delete-field "Content-Transfer-Encoding"))
1815 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1816 (mail-position-on-field "Content-Type")
1820 (mail-position-on-field "Content-Transfer-Encoding")
1824 (defun mime-edit-translate-single-part-tag (&optional prefix)
1825 (if (re-search-forward mime-edit-single-part-tag-regexp nil t)
1826 (let* ((beg (match-beginning 0))
1828 (tag (buffer-substring beg end))
1830 (delete-region beg end)
1831 (setq contype (mime-edit-get-contype tag))
1832 (setq encoding (mime-edit-get-encoding tag))
1833 (insert (concat prefix "--" boundary "\n"))
1835 (narrow-to-region (point)(point))
1836 (insert "Content-Type: " contype "\n")
1838 (insert "Content-Transfer-Encoding: " encoding "\n"))
1839 (eword-encode-header)
1843 (defun mime-edit-translate-region (beg end &optional boundary multipart)
1845 (setq boundary (mime-edit-make-boundary))
1849 (narrow-to-region beg end)
1850 (let ((tag nil) ;MIME tag
1851 (contype nil) ;Content-Type
1852 (encoding nil) ;Content-Transfer-Encoding
1853 (nparts 0)) ;Number of body parts
1854 ;; Normalize the body part by inserting appropriate message
1855 ;; tags for every message contents.
1856 (mime-edit-normalize-body)
1857 ;; Counting the number of Content-Type.
1858 (goto-char (point-min))
1859 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1860 (setq nparts (1+ nparts)))
1861 ;; Begin translation.
1863 ((and (<= nparts 1)(not multipart))
1864 ;; It's a singular message.
1865 (goto-char (point-min))
1866 (while (re-search-forward
1867 mime-edit-single-part-tag-regexp nil t)
1869 (buffer-substring (match-beginning 0) (match-end 0)))
1870 (delete-region (match-beginning 0) (1+ (match-end 0)))
1871 (setq contype (mime-edit-get-contype tag))
1872 (setq encoding (mime-edit-get-encoding tag))
1875 ;; It's a multipart message.
1876 (goto-char (point-min))
1877 (and (mime-edit-translate-single-part-tag)
1878 (while (mime-edit-translate-single-part-tag "\n"))
1880 ;; Define Content-Type as "multipart/mixed".
1882 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1883 ;; Content-Transfer-Encoding must be "7bit".
1884 ;; The following encoding can be `nil', but is
1885 ;; specified as is since there is no way that a user
1887 (setq encoding "7bit")
1888 ;; Insert the trailer.
1889 (goto-char (point-max))
1890 (insert "\n--" boundary "--\n")
1892 (list contype encoding boundary nparts)
1895 (defun mime-edit-normalize-body ()
1896 "Normalize the body part by inserting appropriate message tags."
1897 ;; Insert the first MIME tags if necessary.
1898 (goto-char (point-min))
1899 (if (not (looking-at mime-edit-single-part-tag-regexp))
1900 (insert (mime-make-text-tag) "\n"))
1901 ;; Check each tag, and add new tag or correct it if necessary.
1902 (goto-char (point-min))
1903 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1904 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1905 (contype (mime-edit-get-contype tag))
1906 (charset (mime-get-parameter contype "charset"))
1907 (encoding (mime-edit-get-encoding tag)))
1908 ;; Remove extra whitespaces after the tag.
1909 (if (looking-at "[ \t]+$")
1910 (delete-region (match-beginning 0) (match-end 0)))
1912 (end (mime-edit-content-end))
1914 (if (= end (point-max))
1917 (or (looking-at mime-edit-beginning-tag-regexp)
1919 (insert (mime-make-text-tag) "\n")
1921 (visible-region beg end)
1925 ((mime-test-content-type contype "message")
1926 ;; Content-type "message" should be sent as is.
1929 ((mime-test-content-type contype "text")
1930 ;; Define charset for text if necessary.
1931 (setq charset (if charset
1932 (intern (downcase charset))
1933 (mime-edit-choose-charset)))
1934 (mime-edit-define-charset charset)
1935 (cond ((string-equal contype "text/x-rot13-47")
1939 (goto-char (mime-edit-content-end))
1942 ((string-equal contype "text/enriched")
1947 (end (mime-edit-content-end))
1949 ;; Patch for hard newlines
1952 ;; (while (search-forward "\n" end t)
1953 ;; (put-text-property (match-beginning 0)
1956 ;; End patch for hard newlines
1957 (enriched-encode beg end)
1959 (if (search-forward "\n\n")
1960 (delete-region beg (match-end 0))
1963 ;; Point is now on current tag.
1964 ;; Define encoding and encode text if necessary.
1965 (or encoding ;Encoding is not specified.
1969 mime-edit-charset-default-encoding-alist)
1971 (beg (mime-edit-content-beginning))
1973 (encode-mime-charset-region beg (mime-edit-content-end)
1975 (mime-encode-region beg (mime-edit-content-end) encoding)
1976 (mime-edit-define-encoding encoding)
1978 (goto-char (mime-edit-content-end))
1980 ((null encoding) ;Encoding is not specified.
1981 ;; Application, image, audio, video, and any other
1982 ;; unknown content-type without encoding should be
1984 (let* ((encoding "base64") ;Encode in BASE64 by default.
1985 (beg (mime-edit-content-beginning))
1986 (end (mime-edit-content-end))
1987 (body (buffer-substring beg end))
1989 (mime-encode-region beg end encoding)
1990 (mime-edit-define-encoding encoding))
1995 (defun mime-delete-field (field)
1996 "Delete header FIELD."
1997 (let ((regexp (format "^%s:[ \t]*" field)))
1998 (goto-char (point-min))
1999 (while (re-search-forward regexp nil t)
2000 (delete-region (match-beginning 0)
2001 (progn (forward-line 1) (point)))
2006 ;;; Platform dependent functions
2009 ;; Sun implementations
2011 (defun mime-edit-voice-recorder-for-sun (encoding)
2012 "Record voice in a buffer using Sun audio device,
2013 and insert data encoded as ENCODING. [mime-edit.el]"
2014 (message "Start the recording on %s. Type C-g to finish the recording..."
2016 (mime-insert-encoded-file "/dev/audio" encoding)
2020 ;;; @ Other useful commands.
2023 ;; Message forwarding commands as content-type "message/rfc822".
2025 (defun mime-edit-insert-message (&optional message)
2027 (let ((inserter (cdr (assq major-mode mime-edit-message-inserter-alist))))
2028 (if (and inserter (fboundp inserter))
2030 (mime-edit-insert-tag "message" "rfc822")
2031 (funcall inserter message)
2033 (message "Sorry, I don't have message inserter for your MUA.")
2036 (defun mime-edit-insert-mail (&optional message)
2038 (let ((inserter (cdr (assq major-mode mime-edit-mail-inserter-alist))))
2039 (if (and inserter (fboundp inserter))
2041 (mime-edit-insert-tag "message" "rfc822")
2042 (funcall inserter message)
2044 (message "Sorry, I don't have mail inserter for your MUA.")
2047 (defun mime-edit-inserted-message-filter ()
2050 (let ((header-start (point))
2051 (case-fold-search t)
2054 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2055 (if (re-search-forward "^$" (mark t))
2056 (narrow-to-region header-start (match-beginning 0))
2058 (goto-char header-start)
2059 (while (and (re-search-forward
2060 mime-edit-yank-ignored-field-regexp nil t)
2061 (setq beg (match-beginning 0))
2062 (setq end (1+ (std11-field-end)))
2064 (delete-region beg end)
2069 ;;; @ multipart enclosure
2072 (defun mime-edit-enclose-region (type beg end)
2075 (let ((current (point)))
2077 (narrow-to-region beg end)
2078 (insert (format "--<<%s>>-{\n" type))
2079 (goto-char (point-max))
2080 (insert (format "--}-<<%s>>\n" type))
2081 (goto-char (point-max))
2083 (or (looking-at mime-edit-beginning-tag-regexp)
2085 (insert (mime-make-text-tag) "\n")
2089 (defun mime-edit-enclose-quote-region (beg end)
2091 (mime-edit-enclose-region "quote" beg end)
2094 (defun mime-edit-enclose-mixed-region (beg end)
2096 (mime-edit-enclose-region "mixed" beg end)
2099 (defun mime-edit-enclose-parallel-region (beg end)
2101 (mime-edit-enclose-region "parallel" beg end)
2104 (defun mime-edit-enclose-digest-region (beg end)
2106 (mime-edit-enclose-region "digest" beg end)
2109 (defun mime-edit-enclose-alternative-region (beg end)
2111 (mime-edit-enclose-region "alternative" beg end)
2114 (defun mime-edit-enclose-signed-region (beg end)
2116 (if mime-edit-signing-type
2117 (mime-edit-enclose-region "signed" beg end)
2118 (message "Please specify signing type.")
2121 (defun mime-edit-enclose-encrypted-region (beg end)
2123 (if mime-edit-signing-type
2124 (mime-edit-enclose-region "encrypted" beg end)
2125 (message "Please specify encrypting type.")
2128 (defun mime-edit-insert-key (&optional arg)
2129 "Insert a pgp public key."
2131 (mime-edit-insert-tag "application" "pgp-keys")
2132 (mime-edit-define-encoding "7bit")
2133 (funcall (pgp-function 'insert-key))
2140 (defun mime-edit-set-split (arg)
2143 (y-or-n-p "Do you want to enable split?")
2145 (setq mime-edit-split-message arg)
2147 (message "This message is enabled to split.")
2148 (message "This message is not enabled to split.")
2151 (defun mime-edit-toggle-transfer-level (&optional transfer-level)
2152 "Toggle transfer-level is 7bit or 8bit through.
2154 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2156 (if (numberp transfer-level)
2157 (setq mime-transfer-level transfer-level)
2158 (if (< mime-transfer-level 8)
2159 (setq mime-transfer-level 8)
2160 (setq mime-transfer-level 7)
2162 (setq mime-edit-charset-default-encoding-alist
2163 (mime-make-charset-default-encoding-alist mime-transfer-level))
2164 (message (format "Current transfer-level is %d bit"
2165 mime-transfer-level))
2166 (setq mime-transfer-level-string
2167 (mime-encoding-name mime-transfer-level 'not-omit))
2168 (force-mode-line-update)
2171 (defun mime-edit-set-transfer-level-7bit ()
2173 (mime-edit-toggle-transfer-level 7)
2176 (defun mime-edit-set-transfer-level-8bit ()
2178 (mime-edit-toggle-transfer-level 8)
2185 (defun mime-edit-set-sign (arg)
2188 (y-or-n-p "Do you want to sign?")
2191 (if mime-edit-signing-type
2193 (setq mime-edit-pgp-processing 'sign)
2194 (message "This message will be signed.")
2196 (message "Please specify signing type.")
2198 (if (eq mime-edit-pgp-processing 'sign)
2199 (setq mime-edit-pgp-processing nil)
2201 (message "This message will not be signed.")
2204 (defun mime-edit-set-encrypt (arg)
2207 (y-or-n-p "Do you want to encrypt?")
2210 (if mime-edit-encrypting-type
2212 (setq mime-edit-pgp-processing 'encrypt)
2213 (message "This message will be encrypt.")
2215 (message "Please specify encrypting type.")
2217 (if (eq mime-edit-pgp-processing 'encrypt)
2218 (setq mime-edit-pgp-processing nil)
2220 (message "This message will not be encrypt.")
2223 (defvar mime-edit-pgp-processing nil)
2224 (make-variable-buffer-local 'mime-edit-pgp-processing)
2226 (defun mime-edit-pgp-enclose-buffer ()
2227 (let ((beg (save-excursion
2228 (goto-char (point-min))
2229 (if (search-forward (concat "\n" mail-header-separator "\n"))
2235 (cond ((eq mime-edit-pgp-processing 'sign)
2236 (mime-edit-enclose-signed-region beg end)
2238 ((eq mime-edit-pgp-processing 'encrypt)
2239 (mime-edit-enclose-encrypted-region beg end)
2247 (defun mime-edit-insert-partial-header
2248 (fields subject id number total separator)
2250 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2251 (insert (format "Mime-Version: 1.0 (split by %s)\n"
2252 mime-edit-version-name))
2254 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2255 id number total separator))
2258 (defun mime-edit-split-and-send
2259 (&optional cmd lines mime-edit-message-max-length)
2263 (count-lines (point-min) (point-max)))
2265 (or mime-edit-message-max-length
2266 (setq mime-edit-message-max-length
2267 (or (cdr (assq major-mode mime-edit-message-max-lines-alist))
2268 mime-edit-message-default-max-lines))
2270 (let* ((mime-edit-draft-file-name
2271 (or (buffer-file-name)
2273 (expand-file-name "mime-draft" mime-temp-directory))))
2274 (separator mail-header-separator)
2276 (replace-space-with-underline (current-time-string))
2277 "@" (system-name) "\"")))
2278 (run-hooks 'mime-edit-before-split-hook)
2279 (let ((the-buf (current-buffer))
2280 (copy-buf (get-buffer-create " *Original Message*"))
2281 (header (std11-header-string-except
2282 mime-edit-split-ignored-field-regexp separator))
2283 (subject (mail-fetch-field "subject"))
2284 (total (+ (/ lines mime-edit-message-max-length)
2285 (if (> (mod lines mime-edit-message-max-length) 0)
2291 mime-edit-split-message-sender-alist))
2295 (error "Split sender is not specified for `%s'." major-mode)
2298 (mime-edit-partial-number 1)
2301 (set-buffer copy-buf)
2303 (insert-buffer the-buf)
2305 (if (re-search-forward
2306 (concat "^" (regexp-quote separator) "$") nil t)
2307 (let ((he (match-beginning 0)))
2309 (narrow-to-region (point-min) he)
2311 (goto-char (point-min))
2312 (while (re-search-forward mime-edit-split-blind-field-regexp nil t)
2313 (delete-region (match-beginning 0)
2314 (1+ (std11-field-end)))
2316 (while (< mime-edit-partial-number total)
2319 (set-buffer copy-buf)
2320 (setq data (buffer-substring
2323 (goto-line mime-edit-message-max-length)
2326 (delete-region (point-min)(point))
2328 (mime-edit-insert-partial-header
2329 header subject id mime-edit-partial-number total separator)
2332 (message (format "Sending %d/%d..."
2333 mime-edit-partial-number total))
2334 (call-interactively command)
2335 (message (format "Sending %d/%d... done"
2336 mime-edit-partial-number total))
2338 (setq mime-edit-partial-number
2339 (1+ mime-edit-partial-number))
2343 (set-buffer copy-buf)
2344 (setq data (buffer-string))
2347 (mime-edit-insert-partial-header
2348 header subject id mime-edit-partial-number total separator)
2351 (message (format "Sending %d/%d..."
2352 mime-edit-partial-number total))
2353 (message (format "Sending %d/%d... done"
2354 mime-edit-partial-number total))
2358 (defun mime-edit-maybe-split-and-send (&optional cmd)
2360 (run-hooks 'mime-edit-before-send-hook)
2361 (let ((mime-edit-message-max-length
2362 (or (cdr (assq major-mode mime-edit-message-max-lines-alist))
2363 mime-edit-message-default-max-lines))
2364 (lines (count-lines (point-min) (point-max)))
2366 (if (and (> lines mime-edit-message-max-length)
2367 mime-edit-split-message)
2368 (mime-edit-split-and-send cmd lines mime-edit-message-max-length)
2372 ;;; @ preview message
2375 (defvar mime-edit-buffer nil) ; buffer local variable
2377 (defun mime-edit-preview-message ()
2378 "preview editing MIME message. [mime-edit.el]"
2380 (let* ((str (buffer-string))
2381 (separator mail-header-separator)
2382 (the-buf (current-buffer))
2383 (buf-name (buffer-name))
2384 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2385 (buf (get-buffer temp-buf-name))
2389 (switch-to-buffer buf)
2392 (setq buf (get-buffer-create temp-buf-name))
2393 (switch-to-buffer buf)
2396 (setq major-mode 'mime-temp-message-mode)
2397 (make-local-variable 'mail-header-separator)
2398 (setq mail-header-separator separator)
2399 (make-local-variable 'mime-edit-buffer)
2400 (setq mime-edit-buffer the-buf)
2402 (run-hooks 'mime-edit-translate-hook)
2403 (mime-edit-translate-buffer)
2404 (goto-char (point-min))
2405 (if (re-search-forward
2406 (concat "^" (regexp-quote separator) "$"))
2412 (defun mime-edit-quitting-method ()
2413 (let ((temp mime::preview/article-buffer)
2415 (mime-view-kill-buffer)
2417 (setq buf mime-edit-buffer)
2419 (switch-to-buffer buf)
2422 (set-alist 'mime-view-quitting-method-alist
2423 'mime-temp-message-mode
2424 (function mime-edit-quitting-method)
2431 (defvar mime-edit-again-ignored-field-regexp
2432 (concat "^\\(" "Content-.*\\|Mime-Version"
2433 (if mime-edit-insert-x-emacs-field "\\|X-Emacs")
2435 "Regexp for deleted header fields when `mime-edit-again' is called.")
2437 (defun mime-edit-decode-buffer (not-decode-text)
2439 (goto-char (point-min))
2440 (let ((ctl (mime/Content-Type)))
2442 (let ((ctype (car ctl))
2445 (if (string-match "/" ctype)
2447 (setq type (substring ctype 0 (match-beginning 0)))
2448 (setq stype (substring ctype (match-end 0)))
2453 ((string= ctype "application/pgp-signature")
2454 (delete-region (point-min)(point-max))
2456 ((string= type "multipart")
2457 (let* ((boundary (cdr (assoc "boundary" params)))
2459 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2461 (re-search-forward boundary-pat nil t)
2462 (let ((bb (match-beginning 0)) eb tag)
2463 (setq tag (format "\n--<<%s>>-{\n" stype))
2466 (setq bb (+ bb (length tag)))
2468 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2470 (setq eb (match-beginning 0))
2471 (replace-match (format "--}-<<%s>>\n" stype))
2473 (narrow-to-region bb eb)
2474 (goto-char (point-min))
2475 (while (re-search-forward boundary-pat nil t)
2476 (let ((beg (match-beginning 0))
2478 (delete-region beg (match-end 0))
2480 (if (re-search-forward boundary-pat nil t)
2481 (setq end (match-beginning 0))
2482 (setq end (point-max))
2485 (narrow-to-region beg end)
2486 (mime-edit-decode-buffer not-decode-text)
2487 (goto-char (point-max))
2490 (goto-char (point-min))
2491 (or (= (point-min) 1)
2492 (delete-region (point-min)
2493 (if (search-forward "\n\n" nil t)
2501 (let ((bytes (+ 14 (length ctype))))
2502 (mapconcat (function
2504 (if (string-equal (car attr) "charset")
2506 (setq charset (cdr attr))
2514 (setq bytes (+ bytes bs 2))
2517 (setq bytes (+ bs 1))
2525 (if (re-search-forward
2526 "Content-Transfer-Encoding:" nil t)
2527 (let ((beg (match-beginning 0))
2528 (hbeg (match-end 0))
2529 (end (std11-field-end)))
2531 (eliminate-top-spaces
2532 (std11-unfold-string
2533 (buffer-substring hbeg end))))
2534 (if (or charset (string-equal type "text"))
2536 (delete-region beg (1+ end))
2537 (goto-char (point-min))
2538 (if (search-forward "\n\n" nil t)
2541 (match-end 0)(point-max) encoding)
2545 (if (or encoded (not not-decode-text))
2546 (decode-mime-charset-region
2547 (point-min)(point-max)
2548 (or charset default-mime-charset))
2551 (if (re-search-forward "^$" nil t)
2555 (if (= (point-min) 1)
2561 (concat type "/" stype pstr) encoding)))
2563 (delete-region (point-min) he)
2566 (concat type "/" stype pstr) encoding))
2570 (decode-mime-charset-region (point-min) (point-max)
2571 default-mime-charset)
2575 (defun mime-edit-again (&optional not-decode-text no-separator not-turn-on)
2576 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode.
2577 Content-Type and Content-Transfer-Encoding header fields will be
2578 converted to MIME-Edit tags."
2580 (goto-char (point-min))
2582 (concat "\n" (regexp-quote mail-header-separator) "\n")
2584 (replace-match "\n\n")
2586 (mime-edit-decode-buffer not-decode-text)
2587 (goto-char (point-min))
2589 (std11-narrow-to-header)
2590 (goto-char (point-min))
2591 (while (re-search-forward mime-edit-again-ignored-field-regexp nil t)
2592 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2595 (and (re-search-forward "^$")
2596 (replace-match mail-header-separator)
2606 (provide 'mime-edit)
2608 (run-hooks 'mime-edit-load-hook)
2610 ;;; mime-edit.el ends here