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.82 $
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.82 1997-05-27 03:26:23 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")))
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 "inline" (("filename" . file))
281 "attachment" (("filename" . file))
286 "attachment" (("filename" . file))
289 "application" "octet-stream" (("type" . "emacs-lisp"))
291 "attachment" (("filename" . file))
294 "application" "octet-stream" (("type" . "common-lisp"))
296 "attachment" (("filename" . file))
299 "application" "octet-stream" (("type" . "tar+gzip"))
301 "attachment" (("filename" . file))
304 "application" "octet-stream" (("type" . "tar+gzip"))
306 "attachment" (("filename" . file))
309 "application" "octet-stream" (("type" . "tar+compress"))
311 "attachment" (("filename" . file))
314 "application" "octet-stream" (("type" . "tar+compress"))
316 "attachment" (("filename" . file))
319 "application" "octet-stream" (("type" . "gzip"))
321 "attachment" (("filename" . file))
324 "application" "octet-stream" (("type" . "compress"))
326 "attachment" (("filename" . file))
329 "application" "octet-stream" (("type" . "lha"))
331 "attachment" (("filename" . file))
334 "application" "zip" nil
336 "attachment" (("filename" . file))
339 "application" "octet-stream" (("type" . "patch"))
341 "attachment" (("filename" . file))
344 "application" "octet-stream" (("type" . "patch"))
346 "attachment" (("filename" . file))
349 "text" "plain" nil nil)
351 "application" "octet-stream" nil
353 "attachment" (("filename" . file))
356 "*Alist of file name, types, parameters, and default encoding.
357 If encoding is nil, it is determined from its contents.")
360 ;;; @@ about charset, encoding and transfer-level
363 (defvar mime-charset-type-list
365 (iso-8859-1 8 "quoted-printable")
366 (iso-8859-2 8 "quoted-printable")
367 (iso-8859-3 8 "quoted-printable")
368 (iso-8859-4 8 "quoted-printable")
369 (iso-8859-5 8 "quoted-printable")
370 (koi8-r 8 "quoted-printable")
371 (iso-8859-7 8 "quoted-printable")
372 (iso-8859-8 8 "quoted-printable")
373 (iso-8859-9 8 "quoted-printable")
374 (iso-2022-jp 7 "base64")
375 (iso-2022-kr 7 "base64")
377 (cn-gb2312 8 "quoted-printable")
379 (gb2312 8 "quoted-printable")
381 (iso-2022-jp-2 7 "base64")
382 (iso-2022-int-1 7 "base64")
385 (defvar mime-transfer-level 7
386 "*A number of network transfer level. It should be bigger than 7.")
387 (make-variable-buffer-local 'mime-transfer-level)
389 (defsubst mime-encoding-name (transfer-level &optional not-omit)
390 (cond ((> transfer-level 8) "binary")
391 ((= transfer-level 8) "8bit")
395 (defvar mime-transfer-level-string
396 (mime-encoding-name mime-transfer-level 'not-omit)
397 "A string formatted version of mime-transfer-level")
398 (make-variable-buffer-local 'mime-transfer-level-string)
400 (defun mime-make-charset-default-encoding-alist (transfer-level)
402 (lambda (charset-type)
403 (let ((charset (car charset-type))
404 (type (nth 1 charset-type))
405 (encoding (nth 2 charset-type))
407 (if (<= type transfer-level)
408 (cons charset (mime-encoding-name type))
409 (cons charset encoding)
411 mime-charset-type-list))
413 (defvar mime-edit-charset-default-encoding-alist
414 (mime-make-charset-default-encoding-alist mime-transfer-level))
415 (make-variable-buffer-local 'mime-edit-charset-default-encoding-alist)
418 ;;; @@ about message inserting
421 (defvar mime-edit-yank-ignored-field-list
422 '("Received" "Approved" "Path" "Replied" "Status"
423 "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
424 "Delete these fields from original message when it is inserted
425 as message/rfc822 part.
426 Each elements are regexp of field-name. [mime-edit.el]")
428 (defvar mime-edit-yank-ignored-field-regexp
430 (apply (function regexp-or) mime-edit-yank-ignored-field-list)
433 (defvar mime-edit-message-inserter-alist nil)
434 (defvar mime-edit-mail-inserter-alist nil)
437 ;;; @@ about message splitting
440 (defvar mime-edit-split-message t
441 "*Split large message if it is non-nil. [mime-edit.el]")
443 (defvar mime-edit-message-default-max-lines 1000
444 "*Default maximum lines of a message. [mime-edit.el]")
446 (defvar mime-edit-message-max-lines-alist
447 '((news-reply-mode . 500))
448 "Alist of major-mode vs maximum lines of a message.
449 If it is not specified for a major-mode,
450 `mime-edit-message-default-max-lines' is used. [mime-edit.el]")
452 (defconst mime-edit-split-ignored-field-regexp
453 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
455 (defvar mime-edit-split-blind-field-regexp
456 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
458 (defvar mime-edit-split-message-sender-alist nil)
460 (defvar mime-edit-news-reply-mode-server-running nil)
466 (defvar mime-edit-signing-type 'pgp-elkins
467 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [mime-edit.el]")
469 (defvar mime-edit-encrypting-type 'pgp-elkins
470 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [mime-edit.el]")
476 (defconst mime-edit-single-part-tag-regexp
477 "--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
478 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
480 (defconst mime-edit-quoted-single-part-tag-regexp
481 (concat "- " (substring mime-edit-single-part-tag-regexp 1)))
483 (defconst mime-edit-multipart-beginning-regexp "--<<\\([^<>]+\\)>>-{\n")
485 (defconst mime-edit-multipart-end-regexp "--}-<<\\([^<>]+\\)>>\n")
487 (defconst mime-edit-beginning-tag-regexp
488 (regexp-or mime-edit-single-part-tag-regexp
489 mime-edit-multipart-beginning-regexp))
491 (defconst mime-edit-end-tag-regexp
492 (regexp-or mime-edit-single-part-tag-regexp
493 mime-edit-multipart-end-regexp))
495 (defconst mime-edit-tag-regexp
496 (regexp-or mime-edit-single-part-tag-regexp
497 mime-edit-multipart-beginning-regexp
498 mime-edit-multipart-end-regexp))
500 (defvar mime-tag-format "--[[%s]]"
501 "*Control-string making a MIME tag.")
503 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
504 "*Control-string making a MIME tag with encoding.")
507 ;;; @@ multipart boundary
510 (defvar mime-multipart-boundary "Multipart"
511 "*Boundary of a multipart message.")
514 ;;; @@ optional header fields
517 (defvar mime-edit-insert-x-emacs-field t
518 "*If non-nil, insert X-Emacs header field.")
520 (defvar mime-edit-x-emacs-value
522 (concat emacs-version
526 (let ((ver (if (string-match "\\.[0-9]+$" emacs-version)
527 (substring emacs-version 0 (match-beginning 0))
530 (concat "Emacs " ver ", MULE " mule-version)
537 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
538 "*Specify MIME tspecials.
539 Tspecials means any character that matches with it in header must be quoted.")
541 (defconst mime-edit-mime-version-value
542 (concat "1.0 (generated by " mime-edit-version-name ")")
543 "MIME version number.")
546 ;;; @ keymap and menu
549 (defvar mime-edit-mode-flag nil)
550 (make-variable-buffer-local 'mime-edit-mode-flag)
552 (defvar mime-edit-mode-map (make-sparse-keymap)
553 "Keymap for MIME-Edit mode commands.")
555 (define-key mime-edit-mode-map
556 "\C-c\C-x\C-t" 'mime-edit-insert-text)
557 (define-key mime-edit-mode-map
558 "\C-c\C-x\C-i" 'mime-edit-insert-file)
559 (define-key mime-edit-mode-map
560 "\C-c\C-x\C-e" 'mime-edit-insert-external)
561 (define-key mime-edit-mode-map
562 "\C-c\C-x\C-v" 'mime-edit-insert-voice)
563 (define-key mime-edit-mode-map
564 "\C-c\C-x\C-y" 'mime-edit-insert-message)
565 (define-key mime-edit-mode-map
566 "\C-c\C-x\C-m" 'mime-edit-insert-mail)
567 (define-key mime-edit-mode-map
568 "\C-c\C-x\C-w" 'mime-edit-insert-signature)
569 (define-key mime-edit-mode-map
570 "\C-c\C-x\C-s" 'mime-edit-insert-signature)
571 (define-key mime-edit-mode-map
572 "\C-c\C-x\C-k" 'mime-edit-insert-key)
573 (define-key mime-edit-mode-map
574 "\C-c\C-xt" 'mime-edit-insert-tag)
576 (define-key mime-edit-mode-map
577 "\C-c\C-m\C-a" 'mime-edit-enclose-alternative-region)
578 (define-key mime-edit-mode-map
579 "\C-c\C-m\C-p" 'mime-edit-enclose-parallel-region)
580 (define-key mime-edit-mode-map
581 "\C-c\C-m\C-m" 'mime-edit-enclose-mixed-region)
582 (define-key mime-edit-mode-map
583 "\C-c\C-m\C-d" 'mime-edit-enclose-digest-region)
584 (define-key mime-edit-mode-map
585 "\C-c\C-m\C-s" 'mime-edit-enclose-signed-region)
586 (define-key mime-edit-mode-map
587 "\C-c\C-m\C-e" 'mime-edit-enclose-encrypted-region)
588 (define-key mime-edit-mode-map
589 "\C-c\C-m\C-q" 'mime-edit-enclose-quote-region)
591 (define-key mime-edit-mode-map
592 "\C-c\C-x7" 'mime-edit-set-transfer-level-7bit)
593 (define-key mime-edit-mode-map
594 "\C-c\C-x8" 'mime-edit-set-transfer-level-8bit)
595 (define-key mime-edit-mode-map
596 "\C-c\C-x/" 'mime-edit-set-split)
597 (define-key mime-edit-mode-map
598 "\C-c\C-xs" 'mime-edit-set-sign)
599 (define-key mime-edit-mode-map
600 "\C-c\C-xv" 'mime-edit-set-sign)
601 (define-key mime-edit-mode-map
602 "\C-c\C-xe" 'mime-edit-set-encrypt)
603 (define-key mime-edit-mode-map
604 "\C-c\C-xh" 'mime-edit-set-encrypt)
605 (define-key mime-edit-mode-map
606 "\C-c\C-x\C-p" 'mime-edit-preview-message)
607 (define-key mime-edit-mode-map
608 "\C-c\C-x\C-z" 'mime-edit-exit)
609 (define-key mime-edit-mode-map
610 "\C-c\C-x?" 'mime-edit-help)
612 (defconst mime-edit-menu-title "MIME-Edit")
614 (defconst mime-edit-menu-list
615 '((mime-help "Describe MIME editor mode" mime-edit-help)
616 (file "Insert File" mime-edit-insert-file)
617 (external "Insert External" mime-edit-insert-external)
618 (voice "Insert Voice" mime-edit-insert-voice)
619 (message "Insert Message" mime-edit-insert-message)
620 (mail "Insert Mail" mime-edit-insert-mail)
621 (signature "Insert Signature" mime-edit-insert-signature)
622 (text "Insert Text" mime-edit-insert-text)
623 (tag "Insert Tag" mime-edit-insert-tag)
624 (alternative "Enclose as alternative"
625 mime-edit-enclose-alternative-region)
626 (parallel "Enclose as parallel" mime-edit-enclose-parallel-region)
627 (mixed "Enclose as serial" mime-edit-enclose-mixed-region)
628 (digest "Enclose as digest" mime-edit-enclose-digest-region)
629 (signed "Enclose as signed" mime-edit-enclose-signed-region)
630 (encrypted "Enclose as encrypted" mime-edit-enclose-encrypted-region)
631 (quote "Verbatim region" mime-edit-enclose-quote-region)
632 (key "Insert Public Key" mime-edit-insert-key)
633 (split "About split" mime-edit-set-split)
634 (sign "About sign" mime-edit-set-sign)
635 (encrypt "About encryption" mime-edit-set-encrypt)
636 (preview "Preview Message" mime-edit-preview-message)
637 (level "Toggle transfer-level" mime-edit-toggle-transfer-level)
639 "MIME-edit menubar entry.")
641 (cond (running-xemacs
642 ;; modified by Pekka Marjola <pema@iki.fi>
643 ;; 1995/9/5 (c.f. [tm-en:69])
644 (defun mime-edit-define-menu-for-xemacs ()
645 "Define menu for Emacs 19."
646 (cond ((featurep 'menubar)
647 (make-local-variable 'current-menubar)
648 (set-buffer-menubar current-menubar)
651 (cons mime-edit-menu-title
654 (vector (nth 1 item)(nth 2 item)
657 mime-edit-menu-list)))
660 ;; modified by Steven L. Baur <steve@miranova.com>
661 ;; 1995/12/6 (c.f. [tm-en:209])
662 (or (boundp 'mime-edit-popup-menu-for-xemacs)
663 (setq mime-edit-popup-menu-for-xemacs
664 (append '("MIME Commands" "---")
665 (mapcar (function (lambda (item)
669 mime-edit-menu-list)))
672 ((>= emacs-major-version 19)
673 (define-key mime-edit-mode-map [menu-bar mime-edit]
674 (cons mime-edit-menu-title
675 (make-sparse-keymap mime-edit-menu-title)))
678 (define-key mime-edit-mode-map
679 (vector 'menu-bar 'mime-edit (car item))
680 (cons (nth 1 item)(nth 2 item))
683 (reverse mime-edit-menu-list)
692 (defun mime-edit-mode ()
693 "MIME minor mode for editing the tagged MIME message.
695 In this mode, basically, the message is composed in the tagged MIME
696 format. The message tag looks like:
698 --[[text/plain; charset=ISO-2022-JP][7bit]]
700 The tag specifies the MIME content type, subtype, optional parameters
701 and transfer encoding of the message following the tag. Messages
702 without any tag are treated as `text/plain' by default. Charset and
703 transfer encoding are automatically defined unless explicitly
704 specified. Binary messages such as audio and image are usually
705 hidden. The messages in the tagged MIME format are automatically
706 translated into a MIME compliant message when exiting this mode.
708 Available charsets depend on Emacs version being used. The following
709 lists the available charsets of each emacs.
711 Without mule: US-ASCII and ISO-8859-1 (or other charset) are available.
712 With mule: US-ASCII, ISO-8859-* (except for ISO-8859-5), KOI8-R,
713 ISO-2022-JP, ISO-2022-JP-2, EUC-KR, CN-GB-2312,
714 CN-BIG5 and ISO-2022-INT-1 are available.
716 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in mule is expected to
717 be used to represent multilingual text in intermixed manner. Any
718 languages that has no registered charset are represented as either
719 ISO-2022-JP-2 or ISO-2022-INT-1 in mule.
721 If you want to use non-ISO-8859-1 charset in Emacs 19 or XEmacs
722 without mule, please set variable `default-mime-charset'. This
723 variable must be symbol of which name is a MIME charset.
725 If you want to add more charsets in mule, please set variable
726 `charsets-mime-charset-alist'. This variable must be alist of which
727 key is list of charset and value is symbol of MIME charset. If name
728 of coding-system is different as MIME charset, please set variable
729 `mime-charset-coding-system-alist'. This variable must be alist of
730 which key is MIME charset and value is coding-system.
732 Following commands are available in addition to major mode commands:
735 \\[mime-edit-insert-text] insert a text message.
736 \\[mime-edit-insert-file] insert a (binary) file.
737 \\[mime-edit-insert-external] insert a reference to external body.
738 \\[mime-edit-insert-voice] insert a voice message.
739 \\[mime-edit-insert-message] insert a mail or news message.
740 \\[mime-edit-insert-mail] insert a mail message.
741 \\[mime-edit-insert-signature] insert a signature file at end.
742 \\[mime-edit-insert-key] insert PGP public key.
743 \\[mime-edit-insert-tag] insert a new MIME tag.
745 \[make enclosure (maybe multipart)\]
746 \\[mime-edit-enclose-alternative-region] enclose as multipart/alternative.
747 \\[mime-edit-enclose-parallel-region] enclose as multipart/parallel.
748 \\[mime-edit-enclose-mixed-region] enclose as multipart/mixed.
749 \\[mime-edit-enclose-digest-region] enclose as multipart/digest.
750 \\[mime-edit-enclose-signed-region] enclose as PGP signed.
751 \\[mime-edit-enclose-encrypted-region] enclose as PGP encrypted.
752 \\[mime-edit-enclose-quote-region] enclose as verbose mode (to avoid to expand tags)
755 \\[mime-edit-set-transfer-level-7bit] set transfer-level as 7.
756 \\[mime-edit-set-transfer-level-8bit] set transfer-level as 8.
757 \\[mime-edit-set-split] set message splitting mode.
758 \\[mime-edit-set-sign] set PGP-sign mode.
759 \\[mime-edit-set-encrypt] set PGP-encryption mode.
760 \\[mime-edit-preview-message] preview editing MIME message.
761 \\[mime-edit-exit] exit and translate into a MIME compliant message.
762 \\[mime-edit-help] show this help.
763 \\[mime-edit-maybe-translate] exit and translate if in MIME mode, then split.
765 Additional commands are available in some major modes:
766 C-c C-c exit, translate and run the original command.
767 C-c C-s exit, translate and run the original command.
769 The following is a message example written in the tagged MIME format.
770 TABs at the beginning of the line are not a part of the message:
772 This is a conventional plain text. It should be translated
775 This is also a plain text. But, it is explicitly specified as
777 --[[text/plain; charset=ISO-8859-1]]
778 This is also a plain text. But charset is specified as
781 ¡Hola! Buenos días. ¿Cómo está usted?
783 This is a <bold>enriched text</bold>.
784 --[[image/gif][base64]]...image encoded in base64 here...
785 --[[audio/basic][base64]]...audio encoded in base64 here...
787 User customizable variables (not documented all of them):
789 Specifies a key prefix for MIME minor mode commands.
791 mime-ignore-preceding-spaces
792 Preceding white spaces in a message body are ignored if non-nil.
794 mime-ignore-trailing-spaces
795 Trailing white spaces in a message body are ignored if non-nil.
798 Hide a non-textual body message encoded in base64 after insertion
802 A number of network transfer level. It should be bigger than 7.
803 If you are in 8bit-through environment, please set 8.
805 mime-edit-voice-recorder
806 Specifies a function to record a voice message and encode it.
807 The function `mime-edit-voice-recorder-for-sun' is for Sun
811 Turning on MIME mode calls the value of mime-edit-mode-hook, if
814 mime-edit-translate-hook
815 The value of mime-edit-translate-hook is called just before translating
816 the tagged MIME format into a MIME compliant message if it is
817 non-nil. If the hook call the function mime-edit-insert-signature,
818 the signature file will be inserted automatically.
821 Turning off MIME mode calls the value of mime-edit-exit-hook, if it is
824 (if mime-edit-mode-flag
826 (if (and (boundp 'mime-edit-touched-flag)
827 mime-edit-touched-flag)
829 (make-local-variable 'mime-edit-touched-flag)
830 (setq mime-edit-touched-flag t)
835 (cond (running-xemacs
836 (add-minor-mode 'mime-edit-mode-flag
837 '((" MIME-Edit " mime-transfer-level-string))
843 (set-alist 'minor-mode-alist
845 '((" MIME-Edit " mime-transfer-level-string)))
846 (set-alist 'minor-mode-map-alist
853 (defun turn-on-mime-edit ()
854 "Unconditionally turn on MIME-Edit mode."
856 (if mime-edit-mode-flag
857 (error "You are already editing a MIME message.")
858 (setq mime-edit-mode-flag t)
860 ;; Set transfer level into mode line
862 (setq mime-transfer-level-string
863 (mime-encoding-name mime-transfer-level 'not-omit))
864 (force-mode-line-update)
866 ;; Define menu for XEmacs.
868 (mime-edit-define-menu-for-xemacs)
873 ;; I don't care about saving these.
874 (setq paragraph-start
875 (regexp-or mime-edit-single-part-tag-regexp
877 (setq paragraph-separate
878 (regexp-or mime-edit-single-part-tag-regexp
880 (run-hooks 'mime-edit-mode-hook)
882 (substitute-command-keys
883 "Type \\[mime-edit-exit] to exit MIME mode, and type \\[mime-edit-help] to get help."))
887 (defalias 'edit-mime 'turn-on-mime-edit) ; for convenience
890 (defun mime-edit-exit (&optional nomime no-error)
891 "Translate the tagged MIME message into a MIME compliant message.
892 With no argument encode a message in the buffer into MIME, otherwise
893 just return to previous mode."
895 (if (not mime-edit-mode-flag)
897 (error "You aren't editing a MIME message.")
901 (run-hooks 'mime-edit-translate-hook)
902 (mime-edit-translate-buffer)))
903 ;; Restore previous state.
904 (setq mime-edit-mode-flag nil)
905 (if (and running-xemacs
907 (delete-menu-item (list mime-edit-menu-title))
910 (set-buffer-modified-p (buffer-modified-p))
911 (run-hooks 'mime-edit-exit-hook)
912 (message "Exit MIME editor mode.")
915 (defun mime-edit-maybe-translate ()
917 (mime-edit-exit nil t)
918 (call-interactively 'mime-edit-maybe-split-and-send)
921 (defun mime-edit-help ()
922 "Show help message about MIME mode."
924 (with-output-to-temp-buffer "*Help*"
925 (princ "MIME editor mode:\n")
926 (princ (documentation 'mime-edit-mode))
927 (print-help-return-message)))
929 (defun mime-edit-insert-text ()
930 "Insert a text message.
931 Charset is automatically obtained from the `charsets-mime-charset-alist'."
933 (let ((ret (mime-edit-insert-tag "text" nil nil)))
936 (if (looking-at mime-edit-single-part-tag-regexp)
938 ;; Make a space between the following message.
942 (if (and (member (second ret) '("enriched" "richtext"))
943 (fboundp 'enriched-mode)
946 (if (boundp 'enriched-mode)
950 (defun mime-edit-insert-file (file &optional verbose)
951 "Insert a message from a file."
952 (interactive "fInsert file as MIME message: \nP")
953 (let* ((guess (mime-find-file-type file))
955 (subtype (nth 1 guess))
956 (parameters (nth 2 guess))
957 (encoding (nth 3 guess))
958 (disposition-type (nth 4 guess))
959 (disposition-params (nth 5 guess))
962 (setq type (mime-prompt-for-type type)
963 subtype (mime-prompt-for-subtype type subtype)
965 (if (or (interactive-p) verbose)
966 (setq encoding (mime-prompt-for-encoding encoding))
968 (if (or (consp parameters) (stringp disposition-type))
969 (let ((rest parameters) cell attribute value)
972 (setq cell (car rest))
973 (setq attribute (car cell))
974 (setq value (cdr cell))
976 (setq value (std11-wrap-as-quoted-string
977 (file-name-nondirectory file)))
979 (setq parameters (concat parameters "; " attribute "=" value))
980 (setq rest (cdr rest))
985 (concat parameters "\n"
986 "Content-Disposition: " disposition-type))
987 (setq rest disposition-params)
989 (setq cell (car rest))
990 (setq attribute (car cell))
991 (setq value (cdr cell))
993 (setq value (std11-wrap-as-quoted-string
994 (file-name-nondirectory file)))
997 (concat parameters "; " attribute "=" value))
998 (setq rest (cdr rest))
1002 (mime-edit-insert-tag type subtype parameters)
1003 (mime-edit-insert-binary-file file encoding)
1006 (defun mime-edit-insert-external ()
1007 "Insert a reference to external body."
1009 (mime-edit-insert-tag "message" "external-body" nil ";\n\t")
1011 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
1013 (let* ((pritype (mime-prompt-for-type))
1014 (subtype (mime-prompt-for-subtype pritype))
1015 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
1018 (insert "Content-Type: "
1019 pritype "/" subtype (or parameters "") "\n")))
1020 (if (and (not (eobp))
1021 (not (looking-at mime-edit-single-part-tag-regexp)))
1022 (insert (mime-make-text-tag) "\n")))
1024 (defun mime-edit-insert-voice ()
1025 "Insert a voice message."
1029 "What transfer encoding: "
1030 mime-file-encoding-method-alist nil t nil)))
1031 (mime-edit-insert-tag "audio" "basic" nil)
1032 (mime-edit-define-encoding encoding)
1034 (narrow-to-region (1- (point))(point))
1036 (funcall mime-edit-voice-recorder encoding)
1039 (invisible-region (point-min)(point-max))
1040 (goto-char (point-max))
1043 (defun mime-edit-insert-signature (&optional arg)
1044 "Insert a signature file."
1046 (let ((signature-insert-hook
1049 (apply (function mime-edit-insert-tag)
1050 (mime-find-file-type signature-file-name))
1053 (insert-signature arg)
1057 ;; Insert a new tag around a point.
1059 (defun mime-edit-insert-tag (&optional pritype subtype parameters delimiter)
1060 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
1061 If nothing is inserted, return nil."
1064 (mime-edit-goto-tag)
1065 (if (and (re-search-forward mime-edit-tag-regexp nil t)
1066 (< (match-beginning 0) p)
1069 (goto-char (match-beginning 0))
1078 (mime-prompt-for-type)))
1081 (mime-prompt-for-subtype pritype)))
1084 (mime-prompt-for-parameters pritype subtype delimiter)))
1085 ;; Make a new MIME tag.
1086 (setq newtag (mime-make-tag pritype subtype parameters))
1087 ;; Find an current MIME tag.
1090 (if (mime-edit-goto-tag)
1091 (buffer-substring (match-beginning 0) (match-end 0))
1092 ;; Assume content type is 'text/plan'.
1093 (mime-make-tag "text" "plain")
1095 ;; We are only interested in TEXT.
1097 (not (mime-test-content-type
1098 (mime-edit-get-contype oldtag) "text")))
1101 (if (or (not oldtag) ;Not text
1102 (or mime-ignore-same-text-tag
1103 (not (string-equal oldtag newtag))))
1105 ;; Mark the beginning of the tag for convenience.
1106 (push-mark (point) 'nomsg)
1107 (insert newtag "\n")
1108 (list pritype subtype parameters) ;New tag is created.
1110 ;; Restore previous point.
1112 nil ;Nothing is created.
1116 (defun mime-edit-insert-binary-file (file &optional encoding)
1117 "Insert binary FILE at point.
1118 Optional argument ENCODING specifies an encoding method such as base64."
1119 (let* ((tagend (1- (point))) ;End of the tag
1120 (hide-p (and mime-auto-hide-body
1123 (let ((en (downcase encoding)))
1124 (or (string-equal en "7bit")
1125 (string-equal en "8bit")
1126 (string-equal en "binary")
1130 (narrow-to-region tagend (point))
1131 (mime-insert-encoded-file file encoding)
1134 (invisible-region (point-min) (point-max))
1135 (goto-char (point-max))
1137 (goto-char (point-max))
1140 (looking-at mime-edit-tag-regexp)
1141 (= (point)(point-max))
1142 (mime-edit-insert-tag "text" "plain")
1144 ;; Define encoding even if it is 7bit.
1145 (if (stringp encoding)
1147 (goto-char tagend) ; Make sure which line the tag is on.
1148 (mime-edit-define-encoding encoding)
1153 ;; Commands work on a current message flagment.
1155 (defun mime-edit-goto-tag ()
1156 "Search for the beginning of the tagged MIME message."
1157 (let ((current (point)))
1158 (if (looking-at mime-edit-tag-regexp)
1160 ;; At first, go to the end.
1161 (cond ((re-search-forward mime-edit-beginning-tag-regexp nil t)
1162 (goto-char (1- (match-beginning 0))) ;For multiline tag
1165 (goto-char (point-max))
1167 ;; Then search for the beginning.
1168 (re-search-backward mime-edit-end-tag-regexp nil t)
1169 (or (looking-at mime-edit-beginning-tag-regexp)
1170 ;; Restore previous point.
1177 (defun mime-edit-content-beginning ()
1178 "Return the point of the beginning of content."
1180 (let ((beg (save-excursion
1181 (beginning-of-line) (point))))
1182 (if (mime-edit-goto-tag)
1183 (let ((top (point)))
1184 (goto-char (match-end 0))
1185 (if (and (= beg top)
1186 (= (following-char) ?\^M))
1190 ;; Default text/plain tag.
1191 (goto-char (point-min))
1193 (concat "\n" (regexp-quote mail-header-separator)
1194 (if mime-ignore-preceding-spaces
1195 "[ \t\n]*\n" "\n")) nil 'move)
1199 (defun mime-edit-content-end ()
1200 "Return the point of the end of content."
1202 (if (mime-edit-goto-tag)
1204 (goto-char (match-end 0))
1205 (if (invisible-p (point))
1206 (next-visible-point (point))
1207 ;; Move to the end of this text.
1208 (if (re-search-forward mime-edit-tag-regexp nil 'move)
1209 ;; Don't forget a multiline tag.
1210 (goto-char (match-beginning 0))
1214 ;; Assume the message begins with text/plain.
1215 (goto-char (mime-edit-content-beginning))
1216 (if (re-search-forward mime-edit-tag-regexp nil 'move)
1217 ;; Don't forget a multiline tag.
1218 (goto-char (match-beginning 0)))
1222 (defun mime-edit-define-charset (charset)
1223 "Set charset of current tag to CHARSET."
1225 (if (mime-edit-goto-tag)
1226 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1227 (delete-region (match-beginning 0) (match-end 0))
1230 (mime-edit-set-parameter
1231 (mime-edit-get-contype tag)
1232 "charset" (upcase (symbol-name charset)))
1233 (mime-edit-get-encoding tag)))
1236 (defun mime-edit-define-encoding (encoding)
1237 "Set encoding of current tag to ENCODING."
1239 (if (mime-edit-goto-tag)
1240 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1241 (delete-region (match-beginning 0) (match-end 0))
1242 (insert (mime-create-tag (mime-edit-get-contype tag) encoding)))
1245 (defun mime-edit-choose-charset ()
1246 "Choose charset of a text following current point."
1247 (detect-mime-charset-region (point) (mime-edit-content-end))
1250 (defun mime-make-text-tag (&optional subtype)
1251 "Make a tag for a text after current point.
1252 Subtype of text type can be specified by an optional argument SUBTYPE.
1253 Otherwise, it is obtained from mime-content-types."
1254 (let* ((pritype "text")
1255 (subtype (or subtype
1256 (car (car (cdr (assoc pritype mime-content-types)))))))
1257 ;; Charset should be defined later.
1258 (mime-make-tag pritype subtype)))
1261 ;; Tag handling functions
1263 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1264 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1265 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1269 (defun mime-create-tag (contype &optional encoding)
1270 "Make a tag with CONTENT-TYPE and optional ENCODING."
1271 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1274 (defun mime-edit-get-contype (tag)
1275 "Return Content-Type (including parameters) of TAG."
1277 (or (string-match mime-edit-single-part-tag-regexp tag)
1278 (string-match mime-edit-multipart-beginning-regexp tag)
1279 (string-match mime-edit-multipart-end-regexp tag)
1281 (substring tag (match-beginning 1) (match-end 1))
1284 (defun mime-edit-get-encoding (tag)
1285 "Return encoding of TAG."
1287 (string-match mime-edit-single-part-tag-regexp tag)
1289 (not (= (match-beginning 3) (match-end 3)))
1290 (substring tag (match-beginning 3) (match-end 3))))
1292 (defun mime-get-parameter (contype parameter)
1293 "For given CONTYPE return value for PARAMETER.
1294 Nil if no such parameter."
1298 (regexp-quote parameter)
1299 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1301 (substring contype (match-beginning 1) (match-end 1))
1302 nil ;No such parameter
1305 (defun mime-edit-set-parameter (contype parameter value)
1306 "For given CONTYPE set PARAMETER to VALUE."
1307 (let (ctype opt-fields)
1308 (if (string-match "\n[^ \t\n\r]+:" contype)
1309 (setq ctype (substring contype 0 (match-beginning 0))
1310 opt-fields (substring contype (match-beginning 0)))
1311 (setq ctype contype)
1316 (regexp-quote parameter)
1317 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1320 (concat (substring ctype 0 (match-beginning 1))
1322 (substring contype (match-end 1))
1324 (concat ctype "; " parameter "=" value opt-fields)
1327 (defun mime-strip-parameters (contype)
1328 "Return primary content-type and subtype without parameters for CONTYPE."
1329 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1330 (substring contype (match-beginning 1) (match-end 1)) nil))
1332 (defun mime-test-content-type (contype type &optional subtype)
1333 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1334 (and (stringp contype)
1337 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1338 (downcase contype))))
1343 (defun mime-find-file-type (file)
1344 "Guess Content-Type, subtype, and parameters from FILE."
1346 (guesses mime-file-types))
1347 (while (and (not guess) guesses)
1348 (if (string-match (car (car guesses)) file)
1349 (setq guess (cdr (car guesses))))
1350 (setq guesses (cdr guesses)))
1354 (defun mime-prompt-for-type (&optional default)
1355 "Ask for Content-type."
1357 ;; Repeat until primary content type is specified.
1358 (while (string-equal type "")
1360 (completing-read "What content type: "
1363 'require-match ;Type must be specified.
1366 (if (string-equal type "")
1368 (message "Content type is required.")
1375 (defun mime-prompt-for-subtype (type &optional default)
1376 "Ask for subtype of media-type TYPE."
1377 (let ((subtypes (cdr (assoc type mime-content-types))))
1379 (assoc default subtypes))
1380 (setq default (car (car subtypes)))
1386 "What content subtype: (default " default ") ")
1387 "What content subtype: ")
1388 (cdr (assoc type mime-content-types))
1390 'require-match ;Subtype must be specified.
1393 (if (string-equal answer "") default answer)))
1395 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1396 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1397 Optional DELIMITER specifies parameter delimiter (';' by default)."
1398 (let* ((delimiter (or delimiter "; "))
1403 (mime-prompt-for-parameters-1
1405 (cdr (assoc pritype mime-content-types))))))
1408 (if (and (stringp parameters)
1409 (not (string-equal parameters "")))
1410 (concat delimiter parameters)
1411 "" ;"" if no parameters
1414 (defun mime-prompt-for-parameters-1 (optlist)
1415 (apply (function append)
1416 (mapcar (function mime-prompt-for-parameter) optlist)))
1418 (defun mime-prompt-for-parameter (parameter)
1420 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1421 (let* ((prompt (car parameter))
1422 (choices (mapcar (function
1424 (if (consp e) e (list e))))
1426 (default (car (car choices)))
1432 (concat "What " prompt
1434 (if (string-equal default "") "\"\"" default)
1436 choices nil nil ""))
1437 ;; If nothing is selected, use default.
1438 (if (string-equal answer "")
1439 (setq answer default)))
1441 (read-string (concat "What " prompt ": "))))
1442 (cons (if (and answer
1443 (not (string-equal answer "")))
1445 ;; Note: control characters ignored!
1446 (if (string-match mime-tspecials-regexp answer)
1447 (concat "\"" answer "\"") answer)))
1448 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1451 (defun mime-prompt-for-encoding (default)
1452 "Ask for Content-Transfer-Encoding. [mime-edit.el]"
1457 "What transfer encoding: "
1458 mime-file-encoding-method-alist nil t default)
1464 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1467 (defvar mime-edit-translate-buffer-hook
1468 '(mime-edit-pgp-enclose-buffer
1469 mime-edit-translate-body
1470 mime-edit-translate-header))
1472 (defun mime-edit-translate-header ()
1473 "Encode the message header into network representation."
1474 (eword-encode-header 'code-conversion)
1475 (run-hooks 'mime-edit-translate-header-hook)
1478 (defun mime-edit-translate-buffer ()
1479 "Encode the tagged MIME message in current buffer in MIME compliant message."
1481 (if (catch 'mime-edit-error
1483 (run-hooks 'mime-edit-translate-buffer-hook)
1487 (error "Translation error!")
1490 (defun mime-edit-find-inmost ()
1491 (goto-char (point-min))
1492 (if (re-search-forward mime-edit-multipart-beginning-regexp nil t)
1493 (let ((bb (match-beginning 0))
1495 (type (buffer-substring (match-beginning 1)(match-end 1)))
1497 (setq end-exp (format "--}-<<%s>>\n" type))
1499 (if (re-search-forward end-exp nil t)
1501 (setq eb (match-beginning 0))
1502 (setq ee (match-end 0))
1504 (setq eb (point-max))
1505 (setq ee (point-max))
1507 (narrow-to-region be eb)
1509 (if (re-search-forward mime-edit-multipart-beginning-regexp nil t)
1511 (narrow-to-region (match-beginning 0)(point-max))
1512 (mime-edit-find-inmost)
1515 (list type bb be eb)
1518 (defun mime-edit-process-multipart-1 (boundary)
1519 (let ((ret (mime-edit-find-inmost)))
1521 (let ((type (car ret))
1522 (bb (nth 1 ret))(be (nth 2 ret))
1525 (narrow-to-region bb eb)
1526 (delete-region bb be)
1527 (setq bb (point-min))
1528 (setq eb (point-max))
1531 (if (looking-at mime-edit-multipart-end-regexp)
1532 (let ((beg (match-beginning 0))
1535 (delete-region beg end)
1536 (or (looking-at mime-edit-beginning-tag-regexp)
1538 (insert (concat (mime-make-text-tag) "\n"))
1540 (cond ((string-equal type "quote")
1541 (mime-edit-enquote-region bb eb)
1543 ((string-equal type "signed")
1544 (cond ((eq mime-edit-signing-type 'pgp-elkins)
1545 (mime-edit-sign-pgp-elkins bb eb boundary)
1547 ((eq mime-edit-signing-type 'pgp-kazu)
1548 (mime-edit-sign-pgp-kazu bb eb boundary)
1551 ((string-equal type "encrypted")
1552 (cond ((eq mime-edit-encrypting-type 'pgp-elkins)
1553 (mime-edit-encrypt-pgp-elkins bb eb boundary)
1555 ((eq mime-edit-encrypting-type 'pgp-kazu)
1556 (mime-edit-encrypt-pgp-kazu bb eb boundary)
1560 (nth 2 (mime-edit-translate-region bb eb
1564 (format "--[[multipart/%s;
1565 boundary=\"%s\"][7bit]]\n"
1570 (defun mime-edit-enquote-region (beg end)
1573 (narrow-to-region beg end)
1575 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1576 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1577 (replace-match (concat "- " (substring tag 1)))
1580 (defun mime-edit-dequote-region (beg end)
1583 (narrow-to-region beg end)
1585 (while (re-search-forward
1586 mime-edit-quoted-single-part-tag-regexp nil t)
1587 (let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
1588 (replace-match (concat "-" (substring tag 2)))
1591 (defun mime-edit-sign-pgp-elkins (beg end boundary)
1594 (narrow-to-region beg end)
1596 (mime-edit-translate-region beg end boundary))
1598 (encoding (nth 1 ret))
1600 (pgp-boundary (concat "pgp-sign-" boundary))
1603 (insert (format "Content-Type: %s\n" ctype))
1605 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1608 (or (as-binary-process
1609 (funcall (pgp-function 'mime-sign)
1610 (point-min)(point-max) nil nil pgp-boundary))
1611 (throw 'mime-edit-error 'pgp-error)
1615 (defvar mime-edit-encrypt-recipient-fields-list '("To" "cc"))
1617 (defun mime-edit-make-encrypt-recipient-header ()
1618 (let* ((names mime-edit-encrypt-recipient-fields-list)
1620 (std11-field-bodies (cons "From" names)
1621 nil mail-header-separator))
1624 (setq values (cdr values))))
1625 (header (and (stringp from)
1626 (if (string-equal from "")
1628 (format "From: %s\n" from)
1631 (while (and names values)
1632 (let ((name (car names))
1633 (value (car values))
1635 (and (stringp value)
1636 (or (string-equal value "")
1638 (setq header (concat header name ": " value "\n")
1639 recipients (if recipients
1640 (concat recipients " ," value)
1643 (setq names (cdr names)
1644 values (cdr values))
1646 (vector from recipients header)
1649 (defun mime-edit-encrypt-pgp-elkins (beg end boundary)
1652 (let (from recipients header)
1653 (let ((ret (mime-edit-make-encrypt-recipient-header)))
1654 (setq from (aref ret 0)
1655 recipients (aref ret 1)
1656 header (aref ret 2))
1658 (narrow-to-region beg end)
1660 (mime-edit-translate-region beg end boundary))
1662 (encoding (nth 1 ret))
1664 (pgp-boundary (concat "pgp-" boundary))
1668 (insert (format "Content-Type: %s\n" ctype))
1670 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1673 (or (funcall (pgp-function 'encrypt)
1674 recipients (point-min) (point-max) from)
1675 (throw 'mime-edit-error 'pgp-error)
1678 (insert (format "--[[multipart/encrypted;
1680 protocol=\"application/pgp-encrypted\"][7bit]]
1682 Content-Type: application/pgp-encrypted
1685 Content-Type: application/octet-stream
1686 Content-Transfer-Encoding: 7bit
1688 " pgp-boundary pgp-boundary pgp-boundary))
1689 (goto-char (point-max))
1690 (insert (format "\n--%s--\n" pgp-boundary))
1693 (defun mime-edit-sign-pgp-kazu (beg end boundary)
1696 (narrow-to-region beg end)
1698 (mime-edit-translate-region beg end boundary))
1700 (encoding (nth 1 ret))
1704 (insert (format "Content-Type: %s\n" ctype))
1706 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1709 (or (as-binary-process
1710 (funcall (pgp-function 'traditional-sign)
1712 (throw 'mime-edit-error 'pgp-error)
1716 "--[[application/pgp; format=mime][7bit]]\n")
1720 (defun mime-edit-encrypt-pgp-kazu (beg end boundary)
1722 (let (from recipients header)
1723 (let ((ret (mime-edit-make-encrypt-recipient-header)))
1724 (setq from (aref ret 0)
1725 recipients (aref ret 1)
1726 header (aref ret 2))
1729 (narrow-to-region beg end)
1731 (mime-edit-translate-region beg end boundary))
1733 (encoding (nth 1 ret))
1738 (insert (format "Content-Type: %s\n" ctype))
1740 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1743 (or (as-binary-process
1744 (funcall (pgp-function 'encrypt)
1745 recipients beg (point-max) nil 'maybe)
1747 (throw 'mime-edit-error 'pgp-error)
1751 "--[[application/pgp; format=mime][7bit]]\n")
1755 (defsubst replace-space-with-underline (str)
1756 (mapconcat (function
1764 (defun mime-edit-make-boundary ()
1765 (concat mime-multipart-boundary "_"
1766 (replace-space-with-underline (current-time-string))
1769 (defun mime-edit-translate-body ()
1770 "Encode the tagged MIME body in current buffer in MIME compliant message."
1773 (let ((boundary (mime-edit-make-boundary))
1776 (while (mime-edit-process-multipart-1
1777 (format "%s-%d" boundary i))
1781 ;; We are interested in message body.
1784 (goto-char (point-min))
1786 (concat "\n" (regexp-quote mail-header-separator)
1787 (if mime-ignore-preceding-spaces
1788 "[ \t\n]*\n" "\n")) nil 'move)
1792 (goto-char (point-max))
1793 (and mime-ignore-trailing-spaces
1794 (re-search-backward "[^ \t\n]\n" beg t)
1797 (setq ret (mime-edit-translate-region
1799 (format "%s-%d" boundary i)))
1801 (mime-edit-dequote-region (point-min)(point-max))
1802 (let ((contype (car ret)) ;Content-Type
1803 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1805 ;; Insert X-Emacs field
1806 (and mime-edit-insert-x-emacs-field
1807 (or (mail-position-on-field "X-Emacs")
1808 (insert mime-edit-x-emacs-value)
1810 ;; Make primary MIME headers.
1811 (or (mail-position-on-field "Mime-Version")
1812 (insert mime-edit-mime-version-value))
1813 ;; Remove old Content-Type and other fields.
1815 (goto-char (point-min))
1816 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1817 (narrow-to-region (point-min) (point))
1818 (goto-char (point-min))
1819 (mime-delete-field "Content-Type")
1820 (mime-delete-field "Content-Transfer-Encoding"))
1821 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1822 (mail-position-on-field "Content-Type")
1826 (mail-position-on-field "Content-Transfer-Encoding")
1830 (defun mime-edit-translate-single-part-tag (&optional prefix)
1831 "Translate single-part-tag to MIME header."
1832 (if (re-search-forward mime-edit-single-part-tag-regexp nil t)
1833 (let* ((beg (match-beginning 0))
1835 (tag (buffer-substring beg end))
1837 (delete-region beg end)
1838 (let ((contype (mime-edit-get-contype tag))
1839 (encoding (mime-edit-get-encoding tag))
1841 (insert (concat prefix "--" boundary "\n"))
1843 (narrow-to-region (point)(point))
1844 (insert "Content-Type: " contype "\n")
1846 (insert "Content-Transfer-Encoding: " encoding "\n"))
1847 (eword-encode-header)
1851 (defun mime-edit-translate-region (beg end &optional boundary multipart)
1853 (setq boundary (mime-edit-make-boundary))
1857 (narrow-to-region beg end)
1858 (let ((tag nil) ;MIME tag
1859 (contype nil) ;Content-Type
1860 (encoding nil) ;Content-Transfer-Encoding
1861 (nparts 0)) ;Number of body parts
1862 ;; Normalize the body part by inserting appropriate message
1863 ;; tags for every message contents.
1864 (mime-edit-normalize-body)
1865 ;; Counting the number of Content-Type.
1866 (goto-char (point-min))
1867 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1868 (setq nparts (1+ nparts)))
1869 ;; Begin translation.
1871 ((and (<= nparts 1)(not multipart))
1872 ;; It's a singular message.
1873 (goto-char (point-min))
1874 (while (re-search-forward
1875 mime-edit-single-part-tag-regexp nil t)
1877 (buffer-substring (match-beginning 0) (match-end 0)))
1878 (delete-region (match-beginning 0) (1+ (match-end 0)))
1879 (setq contype (mime-edit-get-contype tag))
1880 (setq encoding (mime-edit-get-encoding tag))
1883 ;; It's a multipart message.
1884 (goto-char (point-min))
1885 (and (mime-edit-translate-single-part-tag)
1886 (while (mime-edit-translate-single-part-tag "\n"))
1888 ;; Define Content-Type as "multipart/mixed".
1890 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1891 ;; Content-Transfer-Encoding must be "7bit".
1892 ;; The following encoding can be `nil', but is
1893 ;; specified as is since there is no way that a user
1895 (setq encoding "7bit")
1896 ;; Insert the trailer.
1897 (goto-char (point-max))
1898 (insert "\n--" boundary "--\n")
1900 (list contype encoding boundary nparts)
1903 (defun mime-edit-normalize-body ()
1904 "Normalize the body part by inserting appropriate message tags."
1905 ;; Insert the first MIME tags if necessary.
1906 (goto-char (point-min))
1907 (if (not (looking-at mime-edit-single-part-tag-regexp))
1908 (insert (mime-make-text-tag) "\n"))
1909 ;; Check each tag, and add new tag or correct it if necessary.
1910 (goto-char (point-min))
1911 (while (re-search-forward mime-edit-single-part-tag-regexp nil t)
1912 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1913 (contype (mime-edit-get-contype tag))
1914 (charset (mime-get-parameter contype "charset"))
1915 (encoding (mime-edit-get-encoding tag)))
1916 ;; Remove extra whitespaces after the tag.
1917 (if (looking-at "[ \t]+$")
1918 (delete-region (match-beginning 0) (match-end 0)))
1920 (end (mime-edit-content-end))
1922 (if (= end (point-max))
1925 (or (looking-at mime-edit-beginning-tag-regexp)
1927 (insert (mime-make-text-tag) "\n")
1929 (visible-region beg end)
1933 ((mime-test-content-type contype "message")
1934 ;; Content-type "message" should be sent as is.
1937 ((mime-test-content-type contype "text")
1938 ;; Define charset for text if necessary.
1939 (setq charset (if charset
1940 (intern (downcase charset))
1941 (mime-edit-choose-charset)))
1942 (mime-edit-define-charset charset)
1943 (cond ((string-equal contype "text/x-rot13-47-48")
1946 (mule-caesar-region (point) (mime-edit-content-end))
1948 ((string-equal contype "text/enriched")
1953 (end (mime-edit-content-end))
1955 ;; Patch for hard newlines
1958 ;; (while (search-forward "\n" end t)
1959 ;; (put-text-property (match-beginning 0)
1962 ;; End patch for hard newlines
1963 (enriched-encode beg end)
1965 (if (search-forward "\n\n")
1966 (delete-region beg (match-end 0))
1969 ;; Point is now on current tag.
1970 ;; Define encoding and encode text if necessary.
1971 (or encoding ;Encoding is not specified.
1975 mime-edit-charset-default-encoding-alist)
1977 (beg (mime-edit-content-beginning))
1979 (encode-mime-charset-region beg (mime-edit-content-end)
1981 (mime-encode-region beg (mime-edit-content-end) encoding)
1982 (mime-edit-define-encoding encoding)
1984 (goto-char (mime-edit-content-end))
1986 ((null encoding) ;Encoding is not specified.
1987 ;; Application, image, audio, video, and any other
1988 ;; unknown content-type without encoding should be
1990 (let* ((encoding "base64") ;Encode in BASE64 by default.
1991 (beg (mime-edit-content-beginning))
1992 (end (mime-edit-content-end))
1993 (body (buffer-substring beg end))
1995 (mime-encode-region beg end encoding)
1996 (mime-edit-define-encoding encoding))
2001 (defun mime-delete-field (field)
2002 "Delete header FIELD."
2003 (let ((regexp (format "^%s:[ \t]*" field)))
2004 (goto-char (point-min))
2005 (while (re-search-forward regexp nil t)
2006 (delete-region (match-beginning 0)
2007 (progn (forward-line 1) (point)))
2012 ;;; Platform dependent functions
2015 ;; Sun implementations
2017 (defun mime-edit-voice-recorder-for-sun (encoding)
2018 "Record voice in a buffer using Sun audio device,
2019 and insert data encoded as ENCODING. [mime-edit.el]"
2020 (message "Start the recording on %s. Type C-g to finish the recording..."
2022 (mime-insert-encoded-file "/dev/audio" encoding)
2026 ;;; @ Other useful commands.
2029 ;; Message forwarding commands as content-type "message/rfc822".
2031 (defun mime-edit-insert-message (&optional message)
2033 (let ((inserter (cdr (assq major-mode mime-edit-message-inserter-alist))))
2034 (if (and inserter (fboundp inserter))
2036 (mime-edit-insert-tag "message" "rfc822")
2037 (funcall inserter message)
2039 (message "Sorry, I don't have message inserter for your MUA.")
2042 (defun mime-edit-insert-mail (&optional message)
2044 (let ((inserter (cdr (assq major-mode mime-edit-mail-inserter-alist))))
2045 (if (and inserter (fboundp inserter))
2047 (mime-edit-insert-tag "message" "rfc822")
2048 (funcall inserter message)
2050 (message "Sorry, I don't have mail inserter for your MUA.")
2053 (defun mime-edit-inserted-message-filter ()
2056 (let ((header-start (point))
2057 (case-fold-search t)
2060 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2061 (if (re-search-forward "^$" (mark t))
2062 (narrow-to-region header-start (match-beginning 0))
2064 (goto-char header-start)
2065 (while (and (re-search-forward
2066 mime-edit-yank-ignored-field-regexp nil t)
2067 (setq beg (match-beginning 0))
2068 (setq end (1+ (std11-field-end)))
2070 (delete-region beg end)
2075 ;;; @ multipart enclosure
2078 (defun mime-edit-enclose-region (type beg end)
2081 (let ((current (point)))
2083 (narrow-to-region beg end)
2084 (insert (format "--<<%s>>-{\n" type))
2085 (goto-char (point-max))
2086 (insert (format "--}-<<%s>>\n" type))
2087 (goto-char (point-max))
2089 (or (looking-at mime-edit-beginning-tag-regexp)
2091 (insert (mime-make-text-tag) "\n")
2095 (defun mime-edit-enclose-quote-region (beg end)
2097 (mime-edit-enclose-region "quote" beg end)
2100 (defun mime-edit-enclose-mixed-region (beg end)
2102 (mime-edit-enclose-region "mixed" beg end)
2105 (defun mime-edit-enclose-parallel-region (beg end)
2107 (mime-edit-enclose-region "parallel" beg end)
2110 (defun mime-edit-enclose-digest-region (beg end)
2112 (mime-edit-enclose-region "digest" beg end)
2115 (defun mime-edit-enclose-alternative-region (beg end)
2117 (mime-edit-enclose-region "alternative" beg end)
2120 (defun mime-edit-enclose-signed-region (beg end)
2122 (if mime-edit-signing-type
2123 (mime-edit-enclose-region "signed" beg end)
2124 (message "Please specify signing type.")
2127 (defun mime-edit-enclose-encrypted-region (beg end)
2129 (if mime-edit-signing-type
2130 (mime-edit-enclose-region "encrypted" beg end)
2131 (message "Please specify encrypting type.")
2134 (defun mime-edit-insert-key (&optional arg)
2135 "Insert a pgp public key."
2137 (mime-edit-insert-tag "application" "pgp-keys")
2138 (mime-edit-define-encoding "7bit")
2139 (funcall (pgp-function 'insert-key))
2146 (defun mime-edit-set-split (arg)
2149 (y-or-n-p "Do you want to enable split?")
2151 (setq mime-edit-split-message arg)
2153 (message "This message is enabled to split.")
2154 (message "This message is not enabled to split.")
2157 (defun mime-edit-toggle-transfer-level (&optional transfer-level)
2158 "Toggle transfer-level is 7bit or 8bit through.
2160 Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8."
2162 (if (numberp transfer-level)
2163 (setq mime-transfer-level transfer-level)
2164 (if (< mime-transfer-level 8)
2165 (setq mime-transfer-level 8)
2166 (setq mime-transfer-level 7)
2168 (setq mime-edit-charset-default-encoding-alist
2169 (mime-make-charset-default-encoding-alist mime-transfer-level))
2170 (message (format "Current transfer-level is %d bit"
2171 mime-transfer-level))
2172 (setq mime-transfer-level-string
2173 (mime-encoding-name mime-transfer-level 'not-omit))
2174 (force-mode-line-update)
2177 (defun mime-edit-set-transfer-level-7bit ()
2179 (mime-edit-toggle-transfer-level 7)
2182 (defun mime-edit-set-transfer-level-8bit ()
2184 (mime-edit-toggle-transfer-level 8)
2191 (defun mime-edit-set-sign (arg)
2194 (y-or-n-p "Do you want to sign?")
2197 (if mime-edit-signing-type
2199 (setq mime-edit-pgp-processing 'sign)
2200 (message "This message will be signed.")
2202 (message "Please specify signing type.")
2204 (if (eq mime-edit-pgp-processing 'sign)
2205 (setq mime-edit-pgp-processing nil)
2207 (message "This message will not be signed.")
2210 (defun mime-edit-set-encrypt (arg)
2213 (y-or-n-p "Do you want to encrypt?")
2216 (if mime-edit-encrypting-type
2218 (setq mime-edit-pgp-processing 'encrypt)
2219 (message "This message will be encrypt.")
2221 (message "Please specify encrypting type.")
2223 (if (eq mime-edit-pgp-processing 'encrypt)
2224 (setq mime-edit-pgp-processing nil)
2226 (message "This message will not be encrypt.")
2229 (defvar mime-edit-pgp-processing nil)
2230 (make-variable-buffer-local 'mime-edit-pgp-processing)
2232 (defun mime-edit-pgp-enclose-buffer ()
2233 (let ((beg (save-excursion
2234 (goto-char (point-min))
2235 (if (search-forward (concat "\n" mail-header-separator "\n"))
2241 (cond ((eq mime-edit-pgp-processing 'sign)
2242 (mime-edit-enclose-signed-region beg end)
2244 ((eq mime-edit-pgp-processing 'encrypt)
2245 (mime-edit-enclose-encrypted-region beg end)
2253 (defun mime-edit-insert-partial-header
2254 (fields subject id number total separator)
2256 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2257 (insert (format "Mime-Version: 1.0 (split by %s)\n"
2258 mime-edit-version-name))
2260 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2261 id number total separator))
2264 (defun mime-edit-split-and-send
2265 (&optional cmd lines mime-edit-message-max-length)
2269 (count-lines (point-min) (point-max)))
2271 (or mime-edit-message-max-length
2272 (setq mime-edit-message-max-length
2273 (or (cdr (assq major-mode mime-edit-message-max-lines-alist))
2274 mime-edit-message-default-max-lines))
2276 (let* ((mime-edit-draft-file-name
2277 (or (buffer-file-name)
2279 (expand-file-name "mime-draft" mime-temp-directory))))
2280 (separator mail-header-separator)
2282 (replace-space-with-underline (current-time-string))
2283 "@" (system-name) "\"")))
2284 (run-hooks 'mime-edit-before-split-hook)
2285 (let ((the-buf (current-buffer))
2286 (copy-buf (get-buffer-create " *Original Message*"))
2287 (header (std11-header-string-except
2288 mime-edit-split-ignored-field-regexp separator))
2289 (subject (mail-fetch-field "subject"))
2290 (total (+ (/ lines mime-edit-message-max-length)
2291 (if (> (mod lines mime-edit-message-max-length) 0)
2297 mime-edit-split-message-sender-alist))
2301 (error "Split sender is not specified for `%s'." major-mode)
2304 (mime-edit-partial-number 1)
2307 (set-buffer copy-buf)
2309 (insert-buffer the-buf)
2311 (if (re-search-forward
2312 (concat "^" (regexp-quote separator) "$") nil t)
2313 (let ((he (match-beginning 0)))
2315 (narrow-to-region (point-min) he)
2317 (goto-char (point-min))
2318 (while (re-search-forward mime-edit-split-blind-field-regexp nil t)
2319 (delete-region (match-beginning 0)
2320 (1+ (std11-field-end)))
2322 (while (< mime-edit-partial-number total)
2325 (set-buffer copy-buf)
2326 (setq data (buffer-substring
2329 (goto-line mime-edit-message-max-length)
2332 (delete-region (point-min)(point))
2334 (mime-edit-insert-partial-header
2335 header subject id mime-edit-partial-number total separator)
2338 (message (format "Sending %d/%d..."
2339 mime-edit-partial-number total))
2340 (call-interactively command)
2341 (message (format "Sending %d/%d... done"
2342 mime-edit-partial-number total))
2344 (setq mime-edit-partial-number
2345 (1+ mime-edit-partial-number))
2349 (set-buffer copy-buf)
2350 (setq data (buffer-string))
2353 (mime-edit-insert-partial-header
2354 header subject id mime-edit-partial-number total separator)
2357 (message (format "Sending %d/%d..."
2358 mime-edit-partial-number total))
2359 (message (format "Sending %d/%d... done"
2360 mime-edit-partial-number total))
2364 (defun mime-edit-maybe-split-and-send (&optional cmd)
2366 (run-hooks 'mime-edit-before-send-hook)
2367 (let ((mime-edit-message-max-length
2368 (or (cdr (assq major-mode mime-edit-message-max-lines-alist))
2369 mime-edit-message-default-max-lines))
2370 (lines (count-lines (point-min) (point-max)))
2372 (if (and (> lines mime-edit-message-max-length)
2373 mime-edit-split-message)
2374 (mime-edit-split-and-send cmd lines mime-edit-message-max-length)
2378 ;;; @ preview message
2381 (defvar mime-edit-buffer nil) ; buffer local variable
2383 (defun mime-edit-preview-message ()
2384 "preview editing MIME message. [mime-edit.el]"
2386 (let* ((str (buffer-string))
2387 (separator mail-header-separator)
2388 (the-buf (current-buffer))
2389 (buf-name (buffer-name))
2390 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2391 (buf (get-buffer temp-buf-name))
2395 (switch-to-buffer buf)
2398 (setq buf (get-buffer-create temp-buf-name))
2399 (switch-to-buffer buf)
2402 (setq major-mode 'mime-temp-message-mode)
2403 (make-local-variable 'mail-header-separator)
2404 (setq mail-header-separator separator)
2405 (make-local-variable 'mime-edit-buffer)
2406 (setq mime-edit-buffer the-buf)
2408 (run-hooks 'mime-edit-translate-hook)
2409 (mime-edit-translate-buffer)
2410 (goto-char (point-min))
2411 (if (re-search-forward
2412 (concat "^" (regexp-quote separator) "$"))
2418 (defun mime-edit-quitting-method ()
2419 "Quitting method for mime-view."
2420 (let ((temp mime-raw-buffer)
2422 (mime-view-kill-buffer)
2424 (setq buf mime-edit-buffer)
2426 (switch-to-buffer buf)
2429 (set-alist 'mime-view-quitting-method-alist
2430 'mime-temp-message-mode
2431 (function mime-edit-quitting-method)
2438 (defvar mime-edit-again-ignored-field-regexp
2439 (concat "^\\(" "Content-.*\\|Mime-Version"
2440 (if mime-edit-insert-x-emacs-field "\\|X-Emacs")
2442 "Regexp for deleted header fields when `mime-edit-again' is called.")
2444 (defun mime-edit-decode-buffer (not-decode-text)
2446 (goto-char (point-min))
2447 (let ((ctl (mime/Content-Type)))
2449 (let ((ctype (car ctl))
2452 (if (string-match "/" ctype)
2454 (setq type (substring ctype 0 (match-beginning 0)))
2455 (setq stype (substring ctype (match-end 0)))
2460 ((string= ctype "application/pgp-signature")
2461 (delete-region (point-min)(point-max))
2463 ((string= type "multipart")
2464 (let* ((boundary (cdr (assoc "boundary" params)))
2466 (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))
2468 (re-search-forward boundary-pat nil t)
2469 (let ((bb (match-beginning 0)) eb tag)
2470 (setq tag (format "\n--<<%s>>-{\n" stype))
2473 (setq bb (+ bb (length tag)))
2475 (concat "\n--" (regexp-quote boundary) "--[ \t]*\n")
2477 (setq eb (match-beginning 0))
2478 (replace-match (format "--}-<<%s>>\n" stype))
2480 (narrow-to-region bb eb)
2481 (goto-char (point-min))
2482 (while (re-search-forward boundary-pat nil t)
2483 (let ((beg (match-beginning 0))
2485 (delete-region beg (match-end 0))
2487 (if (re-search-forward boundary-pat nil t)
2488 (setq end (match-beginning 0))
2489 (setq end (point-max))
2492 (narrow-to-region beg end)
2493 (mime-edit-decode-buffer not-decode-text)
2494 (goto-char (point-max))
2497 (goto-char (point-min))
2498 (or (= (point-min) 1)
2499 (delete-region (point-min)
2500 (if (search-forward "\n\n" nil t)
2508 (let ((bytes (+ 14 (length ctype))))
2509 (mapconcat (function
2511 (if (string-equal (car attr) "charset")
2513 (setq charset (cdr attr))
2521 (setq bytes (+ bytes bs 2))
2524 (setq bytes (+ bs 1))
2532 (if (re-search-forward
2533 "Content-Transfer-Encoding:" nil t)
2534 (let ((beg (match-beginning 0))
2535 (hbeg (match-end 0))
2536 (end (std11-field-end)))
2538 (eliminate-top-spaces
2539 (std11-unfold-string
2540 (buffer-substring hbeg end))))
2541 (if (or charset (string-equal type "text"))
2543 (delete-region beg (1+ end))
2544 (goto-char (point-min))
2545 (if (search-forward "\n\n" nil t)
2548 (match-end 0)(point-max) encoding)
2552 (if (or encoded (not not-decode-text))
2553 (decode-mime-charset-region
2554 (point-min)(point-max)
2555 (or charset default-mime-charset))
2558 (if (re-search-forward "^$" nil t)
2562 (if (= (point-min) 1)
2568 (concat type "/" stype pstr) encoding)))
2570 (delete-region (point-min) he)
2573 (concat type "/" stype pstr) encoding))
2577 (decode-mime-charset-region (point-min) (point-max)
2578 default-mime-charset)
2582 (defun mime-edit-again (&optional not-decode-text no-separator not-turn-on)
2583 "Convert current buffer to MIME-Edit buffer and turn on MIME-Edit mode.
2584 Content-Type and Content-Transfer-Encoding header fields will be
2585 converted to MIME-Edit tags."
2587 (goto-char (point-min))
2589 (concat "\n" (regexp-quote mail-header-separator) "\n")
2591 (replace-match "\n\n")
2593 (mime-edit-decode-buffer not-decode-text)
2594 (goto-char (point-min))
2596 (std11-narrow-to-header)
2597 (goto-char (point-min))
2598 (while (re-search-forward mime-edit-again-ignored-field-regexp nil t)
2599 (delete-region (match-beginning 0) (1+ (std11-field-end)))
2602 (and (re-search-forward "^$")
2603 (replace-match mail-header-separator)
2613 (provide 'mime-edit)
2615 (run-hooks 'mime-edit-load-hook)
2617 ;;; mime-edit.el ends here