2 ;;; tm-edit.el --- Simple MIME Composer for GNU Emacs
5 ;; Copyright (C) 1993 UMEDA Masanobu
6 ;; Copyright (C) 1994,1995 MORIOKA Tomohiko
8 ;; Author: UMEDA Masanobu <umerin@mse.kyutech.ac.jp>
9 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
10 ;; Version: $Revision: 7.35 $
11 ;; Keywords: mail, news, MIME, multimedia, multilingual
13 ;; This file is not part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU 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
27 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 ;; This is an Emacs minor mode for editing Internet multimedia
32 ;; messages formatted in MIME (RFC 1521 and RFC 1522). All messages in
33 ;; this mode are composed in the tagged MIME format, that are
34 ;; described in the following examples. The messages composed in the
35 ;; tagged MIME format are automatically translated into a MIME
36 ;; compliant message when exiting the mode.
38 ;; Mule (a multilingual extension to Emacs 18 and 19) has a capability
39 ;; of handling multilingual text in limited ISO-2022 manner that is
40 ;; based on early experiences in Japanese Internet community and
41 ;; resulted in RFC 1468 (ISO-2022-JP charset for MIME). In order to
42 ;; enable multilingual capability in single text message in MIME,
43 ;; charset of multilingual text written in Mule is declared as either
44 ;; `ISO-2022-JP-2' [RFC 1554] or `ISO-2022-INT-1'. Mule is required
45 ;; for reading the such messages.
47 ;; This MIME composer can work with Mail mode, mh-e letter Mode, and
48 ;; News mode. First of all, you need the following autoload
49 ;; definition to load mime/editor-mode automatically:
51 ;; (autoload 'mime/editor-mode "tm-edit"
52 ;; "Minor mode for editing MIME message." t)
54 ;; In case of Mail mode (includes VM mode), you need the following
57 ;; (add-hook 'mail-mode-hook 'mime/editor-mode)
58 ;; (add-hook 'mail-send-hook 'mime-editor/maybe-translate)
60 ;; In case of MH-E, you need the following hook definition:
62 ;; (add-hook 'mh-letter-mode-hook
66 ;; (make-local-variable 'mail-header-separator)
67 ;; (setq mail-header-separator "--------")
69 ;; (add-hook 'mh-before-send-letter-hook 'mime-editor/maybe-translate)
71 ;; In case of News mode, you need the following hook definition:
73 ;; (add-hook 'news-reply-mode-hook 'mime/editor-mode)
74 ;; (add-hook 'news-inews-hook 'mime-editor/maybe-translate)
76 ;; In case of Emacs 19, it is possible to emphasize the message tags
77 ;; using font-lock mode as follows:
79 ;; (add-hook 'mime/editor-mode-hook
83 ;; (setq font-lock-keywords (list mime-editor/tag-regexp))
86 ;; The message tag looks like:
88 ;; --[[TYPE/SUBTYPE;PARAMETERS][ENCODING]]
90 ;; The tagged MIME message examples:
92 ;; This is a conventional plain text. It should be translated into
96 ;; This is also a plain text. But, it is explicitly specified as is.
98 ;;--[[text/plain; charset=ISO-2022-JP]]
99 ;;
\e$B$3$l$O
\e(B charset
\e$B$r
\e(B ISO-2022-JP
\e$B$K;XDj$7$?F|K\8l$N
\e(B plain
\e$B%F%-%9%H$G$9
\e(B.
101 ;;--[[text/richtext]]
102 ;; <center>This is a richtext.</center>
104 ;;--[[image/gif][base64]]^M...image encoded in base64 comes here...
106 ;;--[[audio/basic][base64]]^M...audio encoded in base64 comes here...
108 ;; LCD Archive Entry:
109 ;; mime|Masanobu UMEDA|umerin@mse.kyutech.ac.jp|
110 ;; Simple MIME Composer|
111 ;; $Date: 1995/12/15 15:02:14 $|$Revision: 7.35 $|~/misc/mime.el.Z|
116 (require 'mail-utils)
128 (defconst mime-editor/RCS-ID
129 "$Id: tm-edit.el,v 7.35 1995/12/15 15:02:14 morioka Exp $")
131 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
137 (defvar mime-prefix "\C-c\C-x"
138 "*Keymap prefix for MIME commands.")
140 (defvar mime-signature-file "~/.signature.rtf"
141 "*Signature file to be included as a part of a multipart message.")
143 (defvar mime-ignore-preceding-spaces nil
144 "*Ignore preceding white spaces if non-nil.")
146 (defvar mime-ignore-trailing-spaces nil
147 "*Ignore trailing white spaces if non-nil.")
149 (defvar mime-ignore-same-text-tag t
150 "*Ignore preceding text content-type tag that is same with new one.
151 If non-nil, the text tag is not inserted unless something different.")
153 (defvar mime-auto-hide-body t
154 "*Hide non-textual body encoded in base64 after insertion if non-nil.")
156 (defvar mime-body-charset-chooser
157 (cond ((boundp 'NEMACS)
158 (function mime-body-charset-chooser-for-nemacs))
160 (function mime-body-charset-chooser-for-mule))
161 ((string-match "^19\\." emacs-version)
162 (function mime-body-charset-chooser-for-emacs19))
164 (function mime-body-charset-chooser-for-emacs18)))
165 "*Function to identify charset and encoding of a text in a given region.
166 The value is a form of (CHARSET . ENCODING), where ENCODING must be a
167 full name, such as base64.")
169 (defvar mime-string-encoder
170 (cond ((boundp 'NEMACS)
171 (function mime-string-encoder-for-nemacs))
173 (function mime-string-encoder-for-mule))
174 ((string-match "^19\\." emacs-version)
175 (function mime-string-encoder-for-emacs19))
177 (function mime-string-encoder-for-emacs18)))
178 "*Function to encode a string for given encoding method.
179 The method is a form of (CHARSET . ENCODING).")
181 (defvar mime-voice-recorder
182 (function mime-voice-recorder-for-sun)
183 "*Function to record a voice message and return a buffer that contains it.")
185 (defvar mime/editor-mode-hook nil
186 "*Hook called when enter MIME mode.")
188 (defvar mime-editor/translate-hook nil
189 "*Hook called before translating into a MIME compliant message.
190 To insert a signature file specified by mime-signature-file
191 (`.signature.rtf' by default) automatically, call the function
192 `mime-editor/insert-signature' from this hook.")
194 (defvar mime-editor/exit-hook nil
195 "*Hook called when exit MIME mode.")
197 (defvar mime-content-types
199 ;; Charset parameter need not to be specified, since it is
200 ;; defined automatically while translation.
202 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
205 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
208 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
211 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
214 ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
222 ("site" "ftp.jaist.ac.jp" "wnoc-fuk.wide.ad.jp" "nic.karrn.ad.jp")
223 ("directory" "/pub/GNU/elisp/mime")
225 ("mode" "image" "ascii" "local8"))
230 ("mode" "image" "ascii" "local8"))
231 ("tftp" ("site") ("name"))
232 ("afs" ("site") ("name"))
233 ("local-file" ("site") ("name"))
234 ("mail-server" ("server" "ftpmail@nic.karrn.ad.jp"))
241 ("type" "" "tar" "shar")
244 ("x-kiss" ("x-cnf")))
256 "*Alist of content-type, subtype, parameters and its values.")
258 (defvar mime-file-types
260 "text" "richtext" nil nil)
262 "text" "html" nil nil)
264 "application" "postscript" nil "quoted-printable")
266 "image" "gif" nil "base64"
267 (("Content-Description" . file))
270 "image" "jpeg" nil "base64")
272 "image" "x-xwd" nil "base64")
274 "image" "x-xbm" nil "base64")
276 "image" "x-pic" nil "base64"
277 (("Content-Description" . file))
280 "image" "tiff" nil "base64")
282 "audio" "basic" nil "base64")
284 "video" "mpeg" nil "base64")
286 "application" "octet-stream" (("name" . file)
287 ("type" . "emacs-lisp")) "7bit")
289 "application" "octet-stream" (("name" . file)
290 ("type" . "common-lisp")) "7bit")
292 "application" "octet-stream" (("name" . file)
294 ("conversions" . "gzip")) nil)
296 "application" "octet-stream" (("name" . file)
297 ("type" . "patch")) nil)
299 "text" "plain" nil nil)
300 (".*" nil nil nil nil)
302 "*Alist of file name, types, parameters, and default encoding.
303 If encoding is nil, it is determined from its contents.")
305 ;;; @@ about message inserting
308 (defvar mime-editor/yank-ignored-field-list
309 '("Received" "Sender" "Approved" "Path" "Status" "X-VM-.*" "X-UIDL")
310 "Delete these fields from original message when it is inserted
311 as message/rfc822 part.
312 Each elements are regexp of field-name. [tm-edit.el]")
314 (defvar mime-editor/yank-ignored-field-regexp
316 (apply (function regexp-or) mime-editor/yank-ignored-field-list)
319 (defvar mime-editor/message-inserter-alist nil)
320 (defvar mime-editor/mail-inserter-alist nil)
322 ;;; @@ about message splitting
325 (defvar mime-editor/split-message t
326 "*Split large message if it is non-nil. [tm-edit.el]")
328 (defvar mime-editor/message-default-max-length 1000
329 "*Default maximum size of a message. [tm-edit.el]")
331 (defvar mime-editor/message-max-length-alist
332 '((news-reply-mode . 500)))
334 (defconst mime-editor/split-ignored-field-regexp
335 "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
337 (defvar mime-editor/split-blind-field-regexp
338 "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
340 (defvar mime-editor/message-default-sender-alist
341 '((mail-mode . mail-send-and-exit)
342 (mh-letter-mode . mh-send-letter)
343 (news-reply-mode . gnus-inews-news)
346 (defvar mime-editor/split-message-sender-alist
353 . (lambda (&optional arg)
355 (write-region (point-min) (point-max)
356 mime-editor/draft-file-name nil 'no-message)
358 (pop-to-buffer "MH mail delivery")
360 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
362 mh-send-args mime-editor/draft-file-name)
363 (goto-char (point-max)) ; show the interesting part
367 (apply 'mh-exec-cmd-quiet t mh-send-prog
369 (list "-nopush" "-nodraftfolder"
370 "-noverbose" "-nowatch"
371 mh-send-args mime-editor/draft-file-name)))))
375 (defvar mime-editor/window-config-alist
377 (mh-letter-mode . mh-previous-window-config)
378 (news-reply-mode . (cond ((boundp 'gnus-winconf-post-news)
380 gnus-winconf-post-news
381 (setq gnus-winconf-post-news nil)
383 ((boundp 'gnus-prev-winconf)
386 (setq gnus-prev-winconf nil)
391 (defvar mime-editor/news-reply-mode-server-running nil)
397 (defvar mime-editor/signing-type nil
398 "*PGP signing type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
400 (defvar mime-editor/encrypting-type nil
401 "*PGP encrypting type (pgp-elkins, pgp-kazu or nil).
402 Sorry `pgp-elkins' is not supported yet. [tm-edit.el]")
404 (if (or mime-editor/signing-type mime-editor/encrypting-type)
412 (defconst mime-editor/single-part-tag-regexp
413 "^--[[][[]\\([^]]*\\)]\\([[]\\([^]]*\\)]\\|\\)]"
414 "*Regexp of MIME tag in the form of [[CONTENT-TYPE][ENCODING]].")
416 (defconst mime-editor/multipart-beginning-regexp "^--<<\\([^<>]+\\)>>-{\n")
418 (defconst mime-editor/multipart-end-regexp "^--}-<<\\([^<>]+\\)>>\n")
420 (defconst mime-editor/beginning-tag-regexp
421 (regexp-or mime-editor/single-part-tag-regexp
422 mime-editor/multipart-beginning-regexp))
424 (defconst mime-editor/end-tag-regexp
425 (regexp-or mime-editor/single-part-tag-regexp
426 mime-editor/multipart-end-regexp))
428 (defconst mime-editor/tag-regexp
429 (regexp-or mime-editor/single-part-tag-regexp
430 mime-editor/multipart-beginning-regexp
431 mime-editor/multipart-end-regexp))
433 (defvar mime-tag-format "--[[%s]]"
434 "*Control-string making a MIME tag.")
436 (defvar mime-tag-format-with-encoding "--[[%s][%s]]"
437 "*Control-string making a MIME tag with encoding.")
439 ;;; @@ multipart boundary
442 (defvar mime-multipart-boundary "Multipart"
443 "*Boundary of a multipart message.")
446 ;;; @@ buffer local variables
449 (defvar mime/editor-mode-old-local-map nil)
450 (defvar mime/editor-mode-old-selective-display nil)
451 (defvar mime/editing-buffer nil)
457 (defconst mime-tspecials-regexp "[][()<>@,;:\\\"/?.= \t]"
458 "*Specify MIME tspecials.
459 Tspecials means any character that matches with it in header must be quoted.")
461 (defconst mime-editor/mime-version-value
462 (format "1.0 (generated by tm-edit %s)" mime-editor/version)
463 "MIME version number.")
466 ;;; @ keymap and menu
469 (defvar mime/editor-mode-flag nil)
470 (make-variable-buffer-local 'mime/editor-mode-flag)
472 (set-alist 'minor-mode-alist 'mime/editor-mode-flag '(" MIME-Edit"))
474 (defun mime-editor/define-keymap (keymap)
475 "Add mime-editor commands to KEYMAP."
476 (if (not (keymapp keymap))
478 (define-key keymap "\C-t" 'mime-editor/insert-text)
479 (define-key keymap "\C-i" 'mime-editor/insert-file)
480 (define-key keymap "\C-e" 'mime-editor/insert-external)
481 (define-key keymap "\C-v" 'mime-editor/insert-voice)
482 (define-key keymap "\C-y" 'mime-editor/insert-message)
483 (define-key keymap "\C-m" 'mime-editor/insert-mail)
484 (define-key keymap "\C-w" 'mime-editor/insert-signature)
485 (define-key keymap "\C-s" 'mime-editor/insert-signature)
486 (define-key keymap "\C-k" 'mime-editor/insert-key)
487 (define-key keymap "t" 'mime-editor/insert-tag)
488 (define-key keymap "a" 'mime-editor/enclose-alternative-region)
489 (define-key keymap "p" 'mime-editor/enclose-parallel-region)
490 (define-key keymap "m" 'mime-editor/enclose-mixed-region)
491 (define-key keymap "d" 'mime-editor/enclose-digest-region)
492 (define-key keymap "s" 'mime-editor/enclose-signed-region)
493 (define-key keymap "e" 'mime-editor/enclose-encrypted-region)
494 (define-key keymap "\C-p" 'mime-editor/preview-message)
495 (define-key keymap "\C-z" 'mime-editor/exit)
496 (define-key keymap "?" 'mime-editor/help)
499 (defconst mime-editor/menu-title "MIME-Edit")
501 (defconst mime-editor/menu-list
503 '((mime-help "Describe MIME editor mode" mime-editor/help)
504 (file "Insert File" mime-editor/insert-file)
505 (external "Insert External" mime-editor/insert-external)
506 (voice "Insert Voice" mime-editor/insert-voice)
507 (message "Insert Message" mime-editor/insert-message)
508 (mail "Insert Mail" mime-editor/insert-mail)
509 (signature "Insert Signature" mime-editor/insert-signature)
510 (text "Insert Text" mime-editor/insert-text)
511 (tag "Insert Tag" mime-editor/insert-tag)
512 (alternative "Enclose as alternative"
513 mime-editor/enclose-alternative-region)
514 (parallel "Enclose as parallel" mime-editor/enclose-parallel-region)
515 (mixed "Enclose as serial" mime-editor/enclose-mixed-region)
516 (digest "Enclose as digest" mime-editor/enclose-digest-region)
517 (signed "Enclose as signed" mime-editor/enclose-signed-region)
518 (encrypted "Enclose as encrypted" mime-editor/enclose-encrypted-region)
519 (key "Insert Public Key" mime-editor/insert-key)
520 (split "About split" mime-editor/set-split)
522 (if (and (featurep 'mailcrypt)
523 (not (or mime-editor/signing-type mime-editor/encrypting-type)))
524 '((sign "About sign" mime-editor/set-sign)
525 (encrypt "About encryption" mime-editor/set-encrypt)
527 '((preview "Preview Message" mime-editor/preview-message))
529 "MIME-edit menubar entry.")
531 (defun mime-editor/define-menu-for-emacs19 ()
532 "Define menu for Emacs 19."
533 (define-key (current-local-map) [menu-bar mime-edit]
534 (cons mime-editor/menu-title
535 (make-sparse-keymap mime-editor/menu-title)))
538 (define-key (current-local-map)
539 (vector 'menu-bar 'mime-edit (car item))
540 (cons (nth 1 item)(nth 2 item))
543 (reverse mime-editor/menu-list)
546 ;;; modified by Pekka Marjola <pema@niksula.hut.fi>
547 ;;; 1995/9/5 (c.f. [tm-en:69])
548 (defun mime-editor/define-menu-for-xemacs ()
549 "Define menu for Emacs 19."
550 (cond ((featurep 'menubar)
551 (make-local-variable 'current-menubar)
552 (set-buffer-menubar current-menubar)
554 (cons mime-editor/menu-title
557 (vector (nth 1 item)(nth 2 item)
558 mime/editor-mode-flag)
560 mime-editor/menu-list)))
563 ;;; modified by Steven L. Baur <steve@miranova.com>
564 ;;; 1995/12/6 (c.f. [tm-en:209])
565 (if (and (string-match "XEmacs\\|Lucid" emacs-version)
566 (not (boundp 'mime-editor/popup-menu-for-xemacs)))
567 (setq mime-editor/popup-menu-for-xemacs
568 (append '("MIME Commands" "---")
569 (mapcar (function (lambda (item)
573 mime-editor/menu-list)))
582 (defun mime/editor-mode ()
583 "MIME minor mode for editing the tagged MIME message.
585 In this mode, basically, the message is composed in the tagged MIME
586 format. The message tag looks like:
588 `--[[text/plain; charset=ISO-2022-JP][7bit]]'.
590 The tag specifies the MIME content type, subtype, optional parameters
591 and transfer encoding of the message following the tag. Messages
592 without any tag are treated as `text/plain' by default. Charset and
593 transfer encoding are automatically defined unless explicitly
594 specified. Binary messages such as audio and image are usually hidden
595 using selective-display facility. The messages in the tagged MIME
596 format are automatically translated into a MIME compliant message when
599 Available charsets depend on Emacs version being used. The following
600 lists the available charsets of each emacs.
602 Emacs18: US-ASCII is only available.
603 NEmacs: US-ASCII and ISO-2022-JP are available.
604 Emacs19: US-ASCII and ISO-8859-1 are available.
605 Mule: US-ASCII, ISO-8859-* (except for ISO-8859-6),
606 ISO-2022-JP, ISO-2022-JP-2 and ISO-2022-INT-1 are available.
608 ISO-2022-JP-2 and ISO-2022-INT-1 charsets used in Mule is expected to
609 be used to represent multilingual text in intermixed manner. Any
610 languages that has no registered charset are represented as either
611 ISO-2022-JP-2 or ISO-2022-INT-1 in Mule.
613 Following commands are available in addition to major mode commands:
614 \\[mime-editor/insert-text] insert a text message.
615 \\[mime-editor/insert-file] insert a (binary) file.
616 \\[mime-editor/insert-external] insert a reference to external body.
617 \\[mime-editor/insert-voice] insert a voice message.
618 \\[mime-editor/insert-message] insert a mail or news message.
619 \\[mime-editor/insert-mail] insert a mail message.
620 \\[mime-editor/insert-signature] insert a signature file at end.
621 \\[mime-editor/insert-tag] insert a new MIME tag.
622 \\[mime-editor/enclose-alternative-region] enclose as multipart/alternative.
623 \\[mime-editor/enclose-parallel-region] enclose as multipart/parallel.
624 \\[mime-editor/enclose-mixed-region] enclose as multipart/mixed.
625 \\[mime-editor/enclose-digest-region] enclose as multipart/digest.
626 \\[mime-editor/enclose-signed-region] enclose as PGP signed.
627 \\[mime-editor/enclose-encrypted-region] enclose as PGP encrypted.
628 \\[mime-editor/insert-key] insert PGP public key.
629 \\[mime-editor/preview-message] preview editing MIME message.
630 \\[mime-editor/exit] exit and translate into a MIME compliant message.
631 \\[mime-editor/maybe-translate] exit, translate and run the original command.
632 \\[mime-editor/help] show this help.
634 Additional commands are available in some major modes:
635 C-c C-c exit, translate and run the original command.
636 C-c C-s exit, translate and run the original command.
638 The following is a message example written in the tagged MIME format.
639 TABs at the beginning of the line are not a part of the message:
641 This is a conventional plain text. It should be translated
644 This is also a plain text. But, it is explicitly specified as
646 --[[text/plain; charset=ISO-2022-JP]]
647 \e$B$3$l$O
\e(B charset
\e$B$r
\e(B ISO-2022-JP
\e$B$K;XDj$7$?F|K\8l$N
\e(B plain
\e$B%F%-%9
\e(B
650 <center>This is a richtext.</center>
651 --[[image/gif][base64]]^M...image encoded in base64 here...
652 --[[audio/basic][base64]]^M...audio encoded in base64 here...
654 User customizable variables (not documented all of them):
656 Specifies a key prefix for MIME minor mode commands.
659 Specifies a signature file to be included as part of a multipart
662 mime-ignore-preceding-spaces
663 Preceding white spaces in a message body are ignored if non-nil.
665 mime-ignore-trailing-spaces
666 Trailing white spaces in a message body are ignored if non-nil.
668 mime-auto-fill-header
669 Fill header fields that contain encoded-words if non-nil.
672 Hide a non-textual body message encoded in base64 after insertion
675 mime-body-charset-chooser
676 Specifies a function to identify charset and encoding of a text in
677 a given region. The value is a form of (CHARSET . ENCODING),
678 where ENCODING must be a full name, such as base64.
681 Specifies a function to encode a string for given encoding method.
682 The method is a form of (CHARSET . ENCODING).
685 Specifies a function to record a voice message and return a buffer
686 that contains it. The function mime-voice-recorder-for-sun is for
689 mime/editor-mode-hook
690 Turning on MIME mode calls the value of mime/editor-mode-hook, if
693 mime-editor/translate-hook
694 The value of mime-editor/translate-hook is called just before translating
695 the tagged MIME format into a MIME compliant message if it is
696 non-nil. If the hook call the function mime-editor/insert-signature,
697 the signature file will be inserted automatically.
699 mime-editor/exit-hook
700 Turning off MIME mode calls the value of mime-editor/exit-hook, if it is
703 (if mime/editor-mode-flag
704 (error "You are already editing a MIME message.")
705 (setq mime/editor-mode-flag t)
706 ;; Remember old key bindings.
707 (make-local-variable 'mime/editor-mode-old-local-map)
708 (setq mime/editor-mode-old-local-map (current-local-map))
709 ;; Add MIME commands to current local map.
710 (use-local-map (copy-keymap (current-local-map)))
711 (if (not (lookup-key (current-local-map) mime-prefix))
712 (define-key (current-local-map) mime-prefix (make-sparse-keymap)))
713 (mime-editor/define-keymap (lookup-key (current-local-map) mime-prefix))
715 ;; Define menu. Menus for other emacs implementations are
717 ;; modified by Pekka Marjola <pema@niksula.hut.fi>
718 ;; 1995/9/5 (c.f. [tm-eng:69])
719 (cond ((string-match "XEmacs\\|Lucid" emacs-version)
720 (mime-editor/define-menu-for-xemacs))
721 ((string-match "^19\\." emacs-version)
722 (mime-editor/define-menu-for-emacs19)
726 ;; Remember old selective-display.
727 (make-local-variable 'mime/editor-mode-old-selective-display)
728 (setq mime/editor-mode-old-selective-display selective-display)
729 (setq selective-display t)
730 ;; I don't care about saving these.
731 (setq paragraph-start
732 (concat mime-editor/single-part-tag-regexp "\\|" paragraph-start))
733 (setq paragraph-separate
734 (concat mime-editor/single-part-tag-regexp "\\|" paragraph-separate))
735 (run-hooks 'mime/editor-mode-hook)
737 (substitute-command-keys
738 "Type \\[mime-editor/exit] to exit MIME mode, and type \\[mime-editor/help] to get help."))
742 (defalias 'edit-mime 'mime/editor-mode) ; for convenience
743 (defalias 'mime-mode 'mime/editor-mode) ; for convenience
745 (defun mime-editor/exit (&optional nomime no-error)
746 "Translate the tagged MIME message into a MIME compliant message.
747 With no argument encode a message in the buffer into MIME, otherwise
748 just return to previous mode."
750 (if (not mime/editor-mode-flag)
752 (error "You aren't editing a MIME message.")
756 (run-hooks 'mime-editor/translate-hook)
757 (mime-editor/translate-buffer)))
758 ;; Restore previous state.
759 (setq mime/editor-mode-flag nil)
760 (use-local-map mime/editor-mode-old-local-map)
762 ;; modified by Pekka Marjola <pema@niksula.hut.fi>
763 ;; 1995/9/5 (c.f. [tm-eng:69])
764 (if (string-match "XEmacs\\|Lucid" emacs-version)
766 (delete-menu-item (list mime-editor/menu-title))
767 ; should rather be const
768 ;; (while mime-editor/xemacs-old-bindings
769 ;; (eval (pop mime-editor/xemacs-old-bindings)))
770 (local-unset-key mime-prefix)))
773 (setq selective-display mime/editor-mode-old-selective-display)
774 (set-buffer-modified-p (buffer-modified-p))
775 (run-hooks 'mime-editor/exit-hook)
776 (message "Exit MIME editor mode.")
779 (defun mime-editor/maybe-translate ()
781 (mime-editor/exit nil t)
782 (call-interactively 'mime-editor/maybe-split-and-send)
785 (defun mime-editor/help ()
786 "Show help message about MIME mode."
788 (with-output-to-temp-buffer "*Help*"
789 (princ "MIME editor mode:\n")
790 (princ (documentation 'mime/editor-mode))
791 (print-help-return-message)))
793 (defun mime-editor/insert-text ()
794 "Insert a text message.
795 Charset is automatically obtained from the mime-body-charset-chooser."
797 (if (and (mime-editor/insert-tag "text" nil nil)
798 (looking-at mime-editor/single-part-tag-regexp))
800 ;; Make a space between the following message.
805 (defun mime-editor/insert-file (file)
806 "Insert a message from a file."
807 (interactive "fInsert file as MIME message: ")
808 (let* ((guess (mime-find-file-type file))
809 (pritype (nth 0 guess))
810 (subtype (nth 1 guess))
811 (parameters (nth 2 guess))
812 (default (nth 3 guess)) ;Guess encoding from its file name.
813 (fields (nth 4 guess))
815 (if (not (interactive-p))
818 (concat "What transfer encoding"
821 (if (string-equal default "")
827 mime-encoding-method-alist nil t nil))))
828 (if (string-equal encoding "")
829 (setq encoding default))
830 (if (or (consp parameters) (consp fields))
831 (let ((rest parameters) cell attribute value)
834 (setq cell (car rest))
835 (setq attribute (car cell))
836 (setq value (cdr cell))
838 (setq value (file-name-nondirectory file))
840 (setq parameters (concat parameters "; " attribute "=" value))
841 (setq rest (cdr rest))
845 (setq cell (car rest))
846 (setq attribute (car cell))
847 (setq value (cdr cell))
849 (setq value (file-name-nondirectory file))
851 (setq parameters (concat parameters "\n" attribute ": " value))
852 (setq rest (cdr rest))
855 (mime-editor/insert-tag pritype subtype parameters)
856 (mime-editor/insert-binary-file file encoding)
859 (defun mime-editor/insert-external ()
860 "Insert a reference to external body."
862 (mime-editor/insert-tag "message" "external-body" nil ";\n\t")
864 ;;(insert "Content-Description: " (read-string "Content-Description: ") "\n")
866 (let* ((pritype (mime-prompt-for-type))
867 (subtype (mime-prompt-for-subtype pritype))
868 (parameters (mime-prompt-for-parameters pritype subtype ";\n\t")))
871 (insert "Content-Type: "
872 pritype "/" subtype (or parameters "") "\n")))
873 (if (and (not (eobp))
874 (not (looking-at mime-editor/single-part-tag-regexp)))
875 (insert (mime-make-text-tag) "\n")))
877 (defun mime-editor/insert-voice ()
878 "Insert a voice message."
880 (mime-editor/insert-tag "audio" "basic" nil)
881 (let ((buffer (funcall mime-voice-recorder)))
883 (mime-editor/insert-binary-buffer buffer "base64")
887 (defun mime-editor/insert-signature (&optional arg)
888 "Insert a signature file specified by mime-signature-file."
893 (read-file-name "Insert your signature: "
894 (concat signature-file-name "-")
897 (signature/get-signature-file-name))))
899 (if signature-insert-at-eof
900 (goto-char (point-max))
902 (apply (function mime-editor/insert-tag)
903 (mime-find-file-type signature))
904 (if (file-readable-p signature)
906 (goto-char (point-max))
910 (insert-file-contents signature)
911 (set-buffer-modified-p (buffer-modified-p))
912 ; force mode line update
916 ;; Insert a new tag around a point.
918 (defun mime-editor/insert-tag (&optional pritype subtype parameters delimiter)
919 "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
920 If nothing is inserted, return nil."
925 exist-prev-tag exist-next-tag)
928 (mime-prompt-for-type)))
931 (mime-prompt-for-subtype pritype)))
934 (mime-prompt-for-parameters pritype subtype delimiter)))
935 ;; Make a new MIME tag.
936 (setq newtag (mime-make-tag pritype subtype parameters))
937 ;; Find an current MIME tag.
940 (if (mime-editor/goto-tag)
942 (if (eq current (match-beginning 0))
943 (setq exist-next-tag t)
944 (setq exist-prev-tag t)
946 (buffer-substring (match-beginning 0) (match-end 0))
948 ;; Assume content type is 'text/plan'.
949 (mime-make-tag "text" "plain")
951 ;; We are only interested in TEXT.
953 (not (mime-test-content-type
954 (mime-editor/get-contype oldtag) "text")))
956 (cond (exist-prev-tag (insert "\n"))
957 (exist-next-tag (save-excursion
960 ;; (beginning-of-line)
961 ;; (cond ((and oldtag ;Text
965 ;; (looking-at mime-editor/beginning-tag-regexp)
967 ;; (or mime-ignore-same-text-tag
968 ;; (not (string-equal oldtag newtag))))
969 ;; ;; If point is at the next of current tag, move to the
970 ;; ;; beginning of the tag to disable insertion of extra tag.
971 ;; (forward-line -1))
972 ;; ((and oldtag ;Text
974 ;; (not (looking-at mime-editor/tag-regexp))
975 ;; (or mime-ignore-same-text-tag
976 ;; (not (string-equal oldtag newtag))))
977 ;; ;; Copy current tag to break a text into two.
979 ;; (insert oldtag "\n")))
980 ;; ((and (null oldtag) ;Not text
981 ;; (not (looking-at mime-editor/tag-regexp)))
982 ;; ;; Adjust insertion point. In the middle of text, it is
983 ;; ;; okay to break the text into two. However, it should not
984 ;; ;; be broken into two, if otherwise.
985 ;; (goto-char (mime-editor/content-end))
997 (if (or (not oldtag) ;Not text
998 (or mime-ignore-same-text-tag
999 (not (string-equal oldtag newtag))))
1001 ;; Mark the beginning of the tag for convenience.
1002 (push-mark (point) 'nomsg)
1003 (insert newtag "\n")
1004 (list pritype subtype parameters) ;New tag is created.
1006 ;; Restore previous point.
1008 nil ;Nothing is created.
1012 ;; Insert the binary content after MIME tag.
1013 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1015 (defun mime-editor/insert-binary-file (file &optional encoding)
1016 "Insert binary FILE at point.
1017 Optional argument ENCODING specifies an encoding method such as base64."
1018 (let ((tmpbuf (get-buffer-create " *MIME insert*")))
1022 (let ((mc-flag nil) ;Mule
1023 (file-coding-system-for-read
1024 (if (featurep 'mule) *noconv*))
1025 (kanji-flag nil) ;NEmacs
1026 (emx-binary-mode t) ;Stop CRLF to LF conversion in OS/2
1028 (let (jka-compr-compression-info-list
1029 jam-zcat-filename-list)
1030 (insert-file-contents file))))
1032 (if (and (stringp encoding)
1033 (string-equal (downcase encoding) "x-uue"))
1036 (let ((uuencode-external-encoder
1037 (cons (car uuencode-external-encoder)
1038 (list (file-name-nondirectory file))
1040 (mime-editor/insert-binary-buffer tmpbuf encoding)
1042 (mime-editor/insert-binary-buffer tmpbuf encoding))
1043 (kill-buffer tmpbuf))))
1045 ;; Insert the binary content after MIME tag.
1046 ;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
1048 (defun mime-editor/insert-binary-buffer (buffer &optional encoding)
1049 "Insert binary BUFFER at point.
1050 Optional argument ENCODING specifies an encoding method such as base64."
1051 (let* ((tagend (1- (point))) ;End of the tag
1052 (hide-p (and mime-auto-hide-body
1054 (let ((en (downcase encoding)))
1055 (or (string-equal en "base64")
1056 (string-equal en "x-uue")
1060 (narrow-to-region (1- (point)) (point))
1061 (let ((start (point))
1062 (emx-binary-mode t)) ;Stop LF to CRLF conversion in OS/2
1063 (insert-buffer-substring buffer)
1064 ;; Encode binary message if necessary.
1066 (mime-encode-region encoding start (point-max))))
1069 (mime-flag-region (point-min) (1- (point-max)) ?\^M)
1070 (goto-char (point-max)))
1072 ;; Define encoding even if it is 7bit.
1073 (if (stringp encoding)
1075 (goto-char tagend) ;Make sure which line the tag is on.
1076 (mime-editor/define-encoding encoding)))
1080 ;; Commands work on a current message flagment.
1082 (defun mime-editor/goto-tag ()
1083 "Search for the beginning of the tagged MIME message."
1084 (let ((current (point)) multipart)
1085 (if (looking-at mime-editor/tag-regexp)
1087 ;; At first, go to the end.
1088 (cond ((re-search-forward mime-editor/beginning-tag-regexp nil t)
1089 (goto-char (match-beginning 0)) ;For multiline tag
1094 (goto-char (point-max))
1096 ;; Then search for the beginning.
1097 (re-search-backward mime-editor/end-tag-regexp nil t)
1099 (or (looking-at mime-editor/beginning-tag-regexp)
1100 ;; Restore previous point.
1107 (defun mime-editor/content-beginning ()
1108 "Return the point of the beginning of content."
1110 (let ((beg (save-excursion
1111 (beginning-of-line) (point))))
1112 (if (mime-editor/goto-tag)
1113 (let ((top (point)))
1114 (goto-char (match-end 0))
1115 (if (and (= beg top)
1116 (= (following-char) ?\^M))
1120 ;; Default text/plain tag.
1121 (goto-char (point-min))
1123 (concat "\n" (regexp-quote mail-header-separator)
1124 (if mime-ignore-preceding-spaces
1125 "[ \t\n]*\n" "\n")) nil 'move)
1129 (defun mime-editor/content-end ()
1130 "Return the point of the end of content."
1132 (let ((beg (save-excursion
1133 (beginning-of-line) (point))))
1134 (if (mime-editor/goto-tag)
1135 (let ((top (point)))
1136 (goto-char (match-end 0))
1137 (if (and (= beg top) ;Must be on the same line.
1138 (= (following-char) ?\^M))
1142 ;; Move to the end of this text.
1143 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1144 ;; Don't forget a multiline tag.
1145 (goto-char (match-beginning 0)))
1148 ;; Assume the message begins with text/plain.
1149 (goto-char (mime-editor/content-beginning))
1150 (if (re-search-forward mime-editor/tag-regexp nil 'move)
1151 ;; Don't forget a multiline tag.
1152 (goto-char (match-beginning 0)))
1156 (defun mime-editor/define-charset (charset)
1157 "Set charset of current tag to CHARSET."
1159 (if (mime-editor/goto-tag)
1160 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1161 (delete-region (match-beginning 0) (match-end 0))
1163 (mime-create-tag (mime-set-parameter
1164 (mime-editor/get-contype tag) "charset" charset)
1165 (mime-editor/get-encoding tag))))
1168 (defun mime-editor/define-encoding (encoding)
1169 "Set encoding of current tag to ENCODING."
1171 (if (mime-editor/goto-tag)
1172 (let ((tag (buffer-substring (match-beginning 0) (match-end 0))))
1173 (delete-region (match-beginning 0) (match-end 0))
1174 (insert (mime-create-tag (mime-editor/get-contype tag) encoding)))
1177 (defun mime-editor/choose-charset ()
1178 "Choose charset of a text following current point."
1180 (let* ((beg (point))
1181 (end (mime-editor/content-end)))
1182 (car (funcall mime-body-charset-chooser beg end)))))
1184 (defun mime-editor/choose-encoding ()
1185 "Choose encoding of a text following current point."
1187 (let* ((beg (point))
1188 (end (mime-editor/content-end)))
1189 (cdr (funcall mime-body-charset-chooser beg end)))))
1191 (defun mime-make-text-tag (&optional subtype)
1192 "Make a tag for a text after current point.
1193 Subtype of text type can be specified by an optional argument SUBTYPE.
1194 Otherwise, it is obtained from mime-content-types."
1195 (let* ((pritype "text")
1196 (subtype (or subtype
1197 (car (car (cdr (assoc pritype mime-content-types)))))))
1198 ;; Charset should be defined later.
1199 (mime-make-tag pritype subtype)))
1202 ;; Tag handling functions
1204 (defun mime-make-tag (pritype subtype &optional parameters encoding)
1205 "Make a tag of MIME message of PRITYPE, SUBTYPE and optional PARAMETERS."
1206 (mime-create-tag (concat (or pritype "") "/" (or subtype "")
1210 (defun mime-create-tag (contype &optional encoding)
1211 "Make a tag with CONTENT-TYPE and optional ENCODING."
1212 (format (if encoding mime-tag-format-with-encoding mime-tag-format)
1215 (defun mime-editor/get-contype (tag)
1216 "Return Content-Type (including parameters) of TAG."
1218 (or (string-match mime-editor/single-part-tag-regexp tag)
1219 (string-match mime-editor/multipart-beginning-regexp tag)
1220 (string-match mime-editor/multipart-end-regexp tag)
1222 (substring tag (match-beginning 1) (match-end 1))
1225 (defun mime-editor/get-encoding (tag)
1226 "Return encoding of TAG."
1228 (string-match mime-editor/single-part-tag-regexp tag)
1230 (not (= (match-beginning 3) (match-end 3)))
1231 (substring tag (match-beginning 3) (match-end 3))))
1233 (defun mime-get-parameter (contype parameter)
1234 "For given CONTYPE return value for PARAMETER.
1235 Nil if no such parameter."
1239 (regexp-quote parameter)
1240 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\([ \t\n]*;\\|$\\)")
1242 (substring contype (match-beginning 1) (match-end 1))
1243 nil ;No such parameter
1246 (defun mime-set-parameter (contype parameter value)
1247 "For given CONTYPE set PARAMETER to VALUE."
1251 (regexp-quote parameter)
1252 "[ \t\n]*=[ \t\n]*\\([^\" \t\n;]*\\|\"[^\"]*\"\\)\\)[ \t\n]*\\(;\\|$\\)")
1255 (concat (substring contype 0 (match-beginning 1))
1257 (substring contype (match-end 1)))
1258 (concat contype "; " parameter "=" value)))
1260 (defun mime-strip-parameters (contype)
1261 "Return primary content-type and subtype without parameters for CONTYPE."
1262 (if (string-match "^[ \t]*\\([^; \t\n]*\\)" contype)
1263 (substring contype (match-beginning 1) (match-end 1)) nil))
1265 (defun mime-test-content-type (contype type &optional subtype)
1266 "Test if CONTYPE is a TYPE and an optional SUBTYPE."
1267 (and (stringp contype)
1270 (concat "^[ \t]*" (downcase type) "/" (downcase (or subtype "")))
1271 (downcase contype))))
1276 (defun mime-find-file-type (file)
1277 "Guess Content-Type, subtype, and parameters from FILE."
1279 (guesses mime-file-types))
1280 (while (and (not guess) guesses)
1281 (if (string-match (car (car guesses)) file)
1282 (setq guess (cdr (car guesses))))
1283 (setq guesses (cdr guesses)))
1287 (defun mime-prompt-for-type ()
1288 "Ask for Content-type."
1290 ;; Repeat until primary content type is specified.
1291 (while (string-equal type "")
1293 (completing-read "What content type: "
1296 'require-match ;Type must be specified.
1299 (if (string-equal type "")
1301 (message "Content type is required.")
1309 (defun mime-prompt-for-subtype (pritype)
1310 "Ask for Content-type subtype of Content-Type PRITYPE."
1311 (let* ((default (car (car (cdr (assoc pritype mime-content-types)))))
1316 "What content subtype: (default " default ") ")
1317 "What content subtype: ")
1318 (cdr (assoc pritype mime-content-types))
1320 'require-match ;Subtype must be specified.
1323 (if (string-equal answer "") default answer)))
1325 (defun mime-prompt-for-parameters (pritype subtype &optional delimiter)
1326 "Ask for Content-type parameters of Content-Type PRITYPE and SUBTYPE.
1327 Optional DELIMITER specifies parameter delimiter (';' by default)."
1328 (let* ((delimiter (or delimiter "; "))
1333 (mime-prompt-for-parameters-1
1335 (cdr (assoc pritype mime-content-types))))))
1338 (if (and (stringp parameters)
1339 (not (string-equal parameters "")))
1340 (concat delimiter parameters)
1341 "" ;"" if no parameters
1344 (defun mime-prompt-for-parameters-1 (optlist)
1345 (apply (function append)
1346 (mapcar (function mime-prompt-for-parameter) optlist)))
1348 (defun mime-prompt-for-parameter (parameter)
1350 Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
1351 (let* ((prompt (car parameter))
1352 (choices (mapcar (function
1354 (if (consp e) e (list e))))
1356 (default (car (car choices)))
1362 (concat "What " prompt
1364 (if (string-equal default "") "\"\"" default)
1366 choices nil nil ""))
1367 ;; If nothing is selected, use default.
1368 (if (string-equal answer "")
1369 (setq answer default)))
1371 (read-string (concat "What " prompt ": "))))
1372 (cons (if (and answer
1373 (not (string-equal answer "")))
1375 ;; Note: control characters ignored!
1376 (if (string-match mime-tspecials-regexp answer)
1377 (concat "\"" answer "\"") answer)))
1378 (mime-prompt-for-parameters-1 (cdr (assoc answer (cdr parameter)))))
1381 (defun mime-encode-string (encoding string)
1382 "Using ENCODING encode a STRING.
1383 If the STRING is too long, the encoded string may be broken into
1386 (set-buffer (get-buffer-create " *MIME encoding*"))
1389 (mime-encode-region encoding (point-min) (point-max))
1391 (buffer-substring (point-min) (point-max))
1392 (kill-buffer (current-buffer)))))
1394 (defun mime-decode-string (encoding string)
1395 "Using ENCODING decode a STRING."
1397 (set-buffer (get-buffer-create " *MIME decoding*"))
1400 (mime-decode-region encoding (point-min) (point-max))
1402 (buffer-substring (point-min) (point-max))
1403 (kill-buffer (current-buffer)))))
1405 (defun mime-flag-region (from to flag)
1406 "Hides or shows lines from FROM to TO, according to FLAG.
1407 If FLAG is `\\n' (newline character) then text is shown,
1408 while if FLAG is `\\^M' (control-M) the text is hidden."
1409 (let ((buffer-read-only nil) ;Okay even if write protected.
1410 (modp (buffer-modified-p)))
1412 (subst-char-in-region from to
1413 (if (= flag ?\n) ?\^M ?\n)
1415 (set-buffer-modified-p modp))))
1418 ;;; @ Translate the tagged MIME messages into a MIME compliant message.
1421 (defun mime-editor/translate-buffer ()
1422 "Encode the tagged MIME message in current buffer in MIME compliant message."
1424 (if (catch 'mime-editor/error
1426 (mime/encode-message-header)
1427 (mime-editor/translate-body)
1428 (mime-editor/pgp-processing)
1432 (error "Translation error!")
1435 (defun mime-editor/find-inmost ()
1436 (goto-char (point-min))
1437 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1438 (let ((bb (match-beginning 0))
1440 (type (buffer-substring (match-beginning 1)(match-end 1)))
1442 (setq end-exp (format "^--}-<<%s>>\n" type))
1444 (if (re-search-forward end-exp nil t)
1446 (setq eb (match-beginning 0))
1447 (setq ee (match-end 0))
1449 (setq eb (point-max))
1450 (setq ee (point-max))
1452 (narrow-to-region be eb)
1454 (if (re-search-forward mime-editor/multipart-beginning-regexp nil t)
1456 (narrow-to-region (match-beginning 0)(point-max))
1457 (mime-editor/find-inmost)
1460 ;;(delete-region eb ee)
1461 (list type bb be eb)
1464 (defun mime-editor/process-multipart-1 (boundary)
1465 (let ((ret (mime-editor/find-inmost)))
1467 (let ((type (car ret))
1468 (bb (nth 1 ret))(be (nth 2 ret))
1471 (narrow-to-region bb eb)
1472 (delete-region bb be)
1473 (setq bb (point-min))
1474 (setq eb (point-max))
1477 (if (looking-at mime-editor/multipart-end-regexp)
1478 (let ((beg (match-beginning 0))
1481 (delete-region beg end)
1482 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
1484 (insert (concat (mime-make-text-tag) "\n"))
1486 (cond ((string= type "signed")
1487 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1488 (mime-editor/sign-pgp-elkins bb eb boundary)
1490 ((eq mime-editor/signing-type 'pgp-kazu)
1491 (mime-editor/process-pgp-kazu 'mc-sign
1495 ((string= type "encrypted")
1496 (cond ((eq mime-editor/signing-type 'pgp-elkins)
1497 (message "Sorry, it is not supported yet")
1499 ((eq mime-editor/signing-type 'pgp-kazu)
1500 (mime-editor/process-pgp-kazu 'mc-encrypt
1505 (nth 2 (mime-editor/translate-region bb eb
1509 (format "--[[multipart/%s;
1510 boundary=\"%s\"][7bit]]\n"
1515 (defun mc-tmpgp-generic-parser (result)
1516 (if (or (not (eq result 0))
1517 (mc-message "^\aError: +Bad pass phrase\\.$" (current-buffer))
1520 (mc-deactivate-passwd t)
1524 (defvar mc-tmpgp-path "tmpgp")
1526 (defun tm:mc-pgp-sign-region (start end &optional id unclear boundary)
1527 (if (not (boundp 'mc-pgp-user-id))
1530 (let ((process-environment process-environment)
1531 (buffer (get-buffer-create mc-buffer-name))
1532 passwd args key parser pgp-path
1534 (setq key (mc-pgp-lookup-key (or id mc-pgp-user-id)))
1538 (format "PGP passphrase for %s (%s): " (car key) (cdr key))))
1539 (setenv "PGPPASSFD" "0")
1541 (list "+verbose=1" "+language=en"
1542 (format "+clearsig=%s" (if unclear "off" "on"))
1543 "+batchmode" "-u" (cdr key)))
1546 (setq parser 'mc-tmpgp-generic-parser
1547 pgp-path mc-tmpgp-path
1548 signature-file (make-temp-name
1549 (expand-file-name "tm-sign" mime/tmp-dir))
1550 args (cons "-fbst" args))
1552 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1554 (setq args (cons signature-file args))
1556 (setq parser 'mc-pgp-generic-parser
1557 pgp-path mc-pgp-path
1558 args (cons "-fast" args)
1561 (setq args (cons (format "+comment=%s" mc-pgp-comment) args))
1564 (message "Signing as %s ..." (car key))
1565 (if (mc-process-region start end passwd pgp-path args parser buffer)
1569 (goto-char (point-min))
1572 --[[multipart/signed; protocol=\"application/pgp-signature\";
1573 boundary=\"%s\"; micalg=pgp-md5][7bit]]
1574 --%s\n" boundary boundary))
1575 (goto-char (point-max))
1576 (insert (format "\n--%s\n" boundary))
1577 (insert "Content-Type: application/pgp-signature
1578 Content-Transfer-Encoding: base64
1581 (insert-file-contents signature-file)
1582 (goto-char (point-max))
1583 (insert (format "\n--%s--\n" boundary))
1585 (delete-file signature-file)
1586 (message "Signing as %s ... Done." (car key))
1590 (defun mime-editor/sign-pgp-elkins (beg end boundary)
1593 (narrow-to-region beg end)
1595 (mime-editor/translate-region beg end boundary))
1597 (encoding (nth 1 ret))
1599 (pgp-boundary (concat "pgp-sign-" boundary))
1602 (insert (format "Content-Type: %s\n" ctype))
1604 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1607 (or (tm:mc-pgp-sign-region (point-min)(point-max)
1608 nil nil pgp-boundary)
1609 (throw 'mime-editor/error 'pgp-error)
1613 (defun mime-editor/process-pgp-kazu (type beg end boundary)
1616 (narrow-to-region beg end)
1618 (mime-editor/translate-region beg end boundary))
1620 (encoding (nth 1 ret))
1624 (insert (format "Content-Type: %s\n" ctype))
1626 (insert (format "Content-Transfer-Encoding: %s\n" encoding))
1634 (let ((mail-header-separator "="))
1635 (call-interactively type)
1638 (and (search-forward "=\n")
1641 (throw 'mime-editor/error 'pgp-error)
1645 "--[[application/pgp; format=mime][7bit]]\n")
1649 (defun mime-editor/translate-body ()
1650 "Encode the tagged MIME body in current buffer in MIME compliant message."
1654 (concat mime-multipart-boundary " " (current-time-string)))
1656 (time (current-time-string))
1658 (while (mime-editor/process-multipart-1
1659 (format "%s %s-%d" mime-multipart-boundary time i))
1663 ;; We are interested in message body.
1666 (goto-char (point-min))
1668 (concat "\n" (regexp-quote mail-header-separator)
1669 (if mime-ignore-preceding-spaces
1670 "[ \t\n]*\n" "\n")) nil 'move)
1674 (goto-char (point-max))
1675 (and mime-ignore-trailing-spaces
1676 (re-search-backward "[^ \t\n]\n" beg t)
1679 (setq ret (mime-editor/translate-region
1681 (format "%s %s-%d" mime-multipart-boundary time i)))
1683 (let ((contype (car ret)) ;Content-Type
1684 (encoding (nth 1 ret)) ;Content-Transfer-Encoding
1686 ;; Make primary MIME headers.
1687 (or (mail-position-on-field "Mime-Version")
1688 (insert mime-editor/mime-version-value))
1689 ;; Remove old Content-Type and other fields.
1691 (goto-char (point-min))
1692 (search-forward (concat "\n" mail-header-separator "\n") nil t)
1693 (narrow-to-region (point-min) (point))
1694 (goto-char (point-min))
1695 (mime-delete-field "Content-Type")
1696 (mime-delete-field "Content-Transfer-Encoding"))
1697 ;; Then, insert Content-Type and Content-Transfer-Encoding fields.
1698 (mail-position-on-field "Content-Type")
1702 (mail-position-on-field "Content-Transfer-Encoding")
1706 (defun mime-editor/translate-region (beg end &optional boundary multipart)
1709 (concat mime-multipart-boundary " " (current-time-string)))
1713 (narrow-to-region beg end)
1714 (let ((tag nil) ;MIME tag
1715 (contype nil) ;Content-Type
1716 (encoding nil) ;Content-Transfer-Encoding
1717 (nparts 0)) ;Number of body parts
1718 ;; Normalize the body part by inserting appropriate message
1719 ;; tags for every message contents.
1720 (mime-editor/normalize-body)
1721 ;; Counting the number of Content-Type.
1722 (goto-char (point-min))
1723 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1724 (setq nparts (1+ nparts)))
1725 ;; Begin translation.
1726 (cond ((and (<= nparts 1)(not multipart))
1727 ;; It's a singular message.
1728 (goto-char (point-min))
1729 (while (re-search-forward
1730 mime-editor/single-part-tag-regexp nil t)
1732 (buffer-substring (match-beginning 0) (match-end 0)))
1733 (delete-region (match-beginning 0) (1+ (match-end 0)))
1734 (setq contype (mime-editor/get-contype tag))
1735 (setq encoding (mime-editor/get-encoding tag))
1738 ;; It's a multipart message.
1739 (goto-char (point-min))
1740 (while (re-search-forward
1741 mime-editor/single-part-tag-regexp nil t)
1743 (buffer-substring (match-beginning 0) (match-end 0)))
1744 (delete-region (match-beginning 0) (match-end 0))
1745 (setq contype (mime-editor/get-contype tag))
1746 (setq encoding (mime-editor/get-encoding tag))
1747 (insert "--" boundary "\n")
1748 (insert "Content-Type: " contype "\n")
1750 (insert "Content-Transfer-Encoding: " encoding "\n"))
1752 ;; Define Content-Type as "multipart/mixed".
1754 (concat "multipart/mixed;\n boundary=\"" boundary "\""))
1755 ;; Content-Transfer-Encoding must be "7bit".
1756 ;; The following encoding can be `nil', but is
1757 ;; specified as is since there is no way that a user
1759 (setq encoding "7bit")
1760 ;; Insert the trailer.
1761 (goto-char (point-max))
1763 (insert "--" boundary "--\n")
1764 (insert "\n--" boundary "--\n")
1766 (list contype encoding boundary nparts)
1769 (defun mime-editor/normalize-body ()
1770 "Normalize the body part by inserting appropriate message tags."
1771 ;; Insert the first MIME tags if necessary.
1772 (goto-char (point-min))
1773 (if (not (looking-at mime-editor/single-part-tag-regexp))
1774 (insert (mime-make-text-tag) "\n"))
1775 ;; Check each tag, and add new tag or correct it if necessary.
1776 (goto-char (point-min))
1777 (while (re-search-forward mime-editor/single-part-tag-regexp nil t)
1778 (let* ((tag (buffer-substring (match-beginning 0) (match-end 0)))
1779 (contype (mime-editor/get-contype tag))
1780 (charset (mime-get-parameter contype "charset"))
1781 (encoding (mime-editor/get-encoding tag)))
1782 ;; Remove extra whitespaces after the tag.
1783 (if (looking-at "[ \t]+$")
1784 (delete-region (match-beginning 0) (match-end 0)))
1785 (cond ((= (following-char) ?\^M)
1786 ;; It must be image, audio or video.
1788 (end (mime-editor/content-end)))
1789 ;; Insert explicit MIME tags after hidden messages.
1791 (if (and (not (eobp))
1792 (not (looking-at mime-editor/single-part-tag-regexp)))
1794 (insert (mime-make-text-tag) "\n")
1795 (forward-line -1) ;Process it again as text.
1797 ;; Show a hidden message. The point is not altered
1798 ;; after the conversion.
1799 (mime-flag-region beg end ?\n)))
1800 ((mime-test-content-type contype "message")
1801 ;; Content-type "message" should be sent as is.
1803 ((mime-test-content-type contype "text")
1804 ;; Define charset for text if necessary.
1805 (setq charset (or charset (mime-editor/choose-charset)))
1806 (mime-editor/define-charset charset)
1807 (if (string-equal contype "text/x-rot13-47")
1811 (goto-char (mime-editor/content-end))
1814 ;; Point is now on current tag.
1815 ;; Define encoding and encode text if necessary.
1816 (if (null encoding) ;Encoding is not specified.
1817 (let* ((encoding (mime-editor/choose-encoding))
1818 (beg (mime-editor/content-beginning))
1819 (end (mime-editor/content-end))
1820 (body (buffer-substring beg end))
1821 (encoded (funcall mime-string-encoder
1822 (cons charset encoding) body)))
1823 (if (not (string-equal body encoded))
1826 (delete-region beg end)
1829 (mime-editor/define-encoding encoding)))
1831 ((null encoding) ;Encoding is not specified.
1832 ;; Application, image, audio, video, and any other
1833 ;; unknown content-type without encoding should be
1835 (let* ((encoding "base64") ;Encode in BASE64 by default.
1836 (beg (mime-editor/content-beginning))
1837 (end (mime-editor/content-end))
1838 (body (buffer-substring beg end))
1839 (encoded (funcall mime-string-encoder
1840 (cons nil encoding) body)))
1841 (if (not (string-equal body encoded))
1844 (delete-region beg end)
1847 (mime-editor/define-encoding encoding))
1852 (defun mime-delete-field (field)
1853 "Delete header FIELD."
1854 (let ((regexp (format "^%s:[ \t]*" field)))
1855 (goto-char (point-min))
1856 (while (re-search-forward regexp nil t)
1857 (delete-region (match-beginning 0)
1858 (progn (forward-line 1) (point)))
1863 ;;; Platform dependent functions
1866 ;; Emacs 18 implementations
1868 (defun mime-body-charset-chooser-for-emacs18 (begin end)
1869 "Return a cons of charset and encoding of a message in a given region.
1870 Encoding name must be a canonical name, such as `base64'."
1871 '("US-ASCII" . nil) ;Default charset of MIME.
1874 (defun mime-string-encoder-for-emacs18 (method string)
1875 "For given METHOD that is a cons of charset and encoding, encode a STRING."
1876 (let ((charset (car method))
1877 (encoding (cdr method)))
1878 (cond ((stringp encoding)
1879 (mime-encode-string encoding string))
1880 ;; Return string without any encoding.
1885 ;; Emacs 19 implementations
1887 (defun mime-body-charset-chooser-for-emacs19 (begin end)
1888 "Return a cons of charset and encoding of a message in a given region.
1889 Encoding name must be a canonical name, such as `base64'.
1890 US-ASCII and ISO-8859-1 are supported on Emacs 19."
1891 (cond ((save-excursion
1893 (re-search-forward "[\200-\377]" end t))
1894 '("ISO-8859-1" . "quoted-printable"))
1896 '("US-ASCII" . nil)) ;Default charset of MIME.
1899 (defun mime-string-encoder-for-emacs19 (method string)
1900 "For given METHOD that is a cons of charset and encoding, encode a STRING."
1901 (let ((charset (car method))
1902 (encoding (cdr method)))
1903 (cond ((stringp encoding)
1904 (mime-encode-string encoding string))
1905 ;; Return string without any encoding.
1910 ;; NEmacs implementations
1912 (defun mime-body-charset-chooser-for-nemacs (begin end)
1913 "Return a cons of charset and encoding of a message in a given region.
1914 Encoding name must be a canonical name, such as `base64'.
1915 US-ASCII and ISO-2022-JP are supported on NEmacs."
1916 (cond ((check-region-kanji-code begin end)
1917 ;; The following are safe encoding methods for use in
1918 ;; USENET News systems that strip off all ESCs.
1919 ;; '("ISO-2022-JP" . "quoted-printable")
1920 ;; '("ISO-2022-JP" . "base64")
1921 ;; The following expects transport systems are all MIME
1922 ;; compliants. For instance, ESCs are never stripped off.
1923 '("ISO-2022-JP" . nil))
1925 '("US-ASCII" . nil)) ;Default charset of MIME.
1928 (defun mime-string-encoder-for-nemacs (method string)
1929 "For given METHOD that is a cons of charset and encoding, encode a STRING.
1930 US-ASCII and ISO-2022-JP are supported on NEmacs."
1931 (let ((charset (car method))
1932 (encoding (cdr method)))
1933 (cond ((stringp encoding)
1934 (mime-encode-string encoding
1935 ;; Convert internal (EUC) to JIS code.
1936 (convert-string-kanji-code string 3 2)
1938 ;; NEmacs can convert into ISO-2022-JP automatically,
1939 ;; but can do it myself as follows:
1940 ;;(t (convert-string-kanji-code string 3 2))
1942 ;; Return string without any encoding.
1947 ;; Mule implementations
1948 ;; Thanks to contributions by wkenji@flab.fujitsu.co.jp (Kenji
1949 ;; WAKAMIYA) and handa@etl.go.jp (Kenichi Handa).
1951 (defun mime-body-charset-chooser-for-mule (begin end)
1952 "Return a cons of charset and encoding of a message in a given
1953 region. Encoding name must be a canonical name, such as `base64'.
1954 US-ASCII, ISO-8859-* (except for ISO-8859-6), ISO-2022-JP,
1955 ISO-2022-JP-2 and ISO-2022-INT-1 are supported on Mule. Either of
1956 charset ISO-2022-JP-2 or ISO-2022-INT-1 is used for multilingual text
1958 (let ((lclist (find-charset-region begin end)))
1959 (cond ((null lclist)
1960 '("US-ASCII" . nil)) ;Default charset of MIME.
1961 ;; Multilingual capability requred.
1962 ((and (> (length lclist) 1)
1963 (boundp '*iso-2022-int-1*))
1964 '("ISO-2022-INT-1" . nil))
1965 ((> (length lclist) 1)
1966 '("ISO-2022-JP-2" . nil))
1968 ((memq lc-ltn1 lclist)
1969 '("ISO-8859-1" . "quoted-printable"))
1970 ((memq lc-ltn2 lclist)
1971 '("ISO-8859-2" . "quoted-printable"))
1972 ((memq lc-ltn3 lclist)
1973 '("ISO-8859-3" . "quoted-printable"))
1974 ((memq lc-ltn4 lclist)
1975 '("ISO-8859-4" . "quoted-printable"))
1976 ((memq lc-crl lclist)
1977 '("ISO-8859-5" . "quoted-printable"))
1978 ;;((memq lc-arb lclist)
1979 ;; '("ISO-8859-6" . "quoted-printable"))
1980 ((memq lc-grk lclist)
1981 '("ISO-8859-7" . "quoted-printable"))
1982 ((memq lc-hbw lclist)
1983 '("ISO-8859-8" . "quoted-printable"))
1984 ((memq lc-ltn5 lclist)
1985 '("ISO-8859-9" . "quoted-printable"))
1986 ((memq lc-jp lclist)
1987 '("ISO-2022-JP" . nil))
1988 ((memq lc-kr lclist)
1989 '("ISO-2022-KR" . nil))
1991 ((boundp '*iso-2022-int-1*)
1992 '("ISO-2022-INT-1" . nil))
1994 '("ISO-2022-JP-2" . nil))
1997 (defun mime-string-encoder-for-mule (method string)
1998 "For given METHOD that is a cons of charset and encoding, encode a
1999 STRING. US-ASCII, ISO-8859-* (except for ISO-8859-6), ISO-2022-JP,
2000 ISO-2022-JP-2 and ISO-2022-INT-1 are supported on Mule. Either of
2001 charset ISO-2022-JP-2 or ISO-2022-INT-1 is used for multilingual
2003 (let* ((charset (car method))
2004 (encoding (cdr method))
2006 (cdr (assoc (and (stringp charset) (upcase charset))
2007 '(("ISO-8859-1" . *ctext*)
2008 ("ISO-8859-2" . *iso-8859-2*)
2009 ("ISO-8859-3" . *iso-8859-3*)
2010 ("ISO-8859-4" . *iso-8859-4*)
2011 ("ISO-8859-5" . *iso-8859-5*)
2012 ;;("ISO-8859-6" . *iso-8859-6*)
2013 ("ISO-8859-7" . *iso-8859-7*)
2014 ("ISO-8859-8" . *iso-8859-8*)
2015 ("ISO-8859-9" . *iso-8859-9*)
2016 ("ISO-2022-JP" . *junet*)
2017 ("ISO-2022-JP-2" . *iso-2022-ss2-7*)
2018 ("ISO-2022-KR" . *korean-mail*)
2019 ("ISO-2022-INT-1" . *iso-2022-int-1*)
2021 ;; In bilingual environment it may be unnecessary to convert the
2022 ;; coding system of the string unless transfer encoding is
2023 ;; required since such conversion may be performed by mule
2025 (if (not (null coding-system))
2026 (setq string (code-convert-string string *internal* coding-system)))
2027 (if (stringp encoding)
2028 (setq string (mime-encode-string encoding string)))
2033 ;; Sun implementations
2035 (defun mime-voice-recorder-for-sun ()
2036 "Record voice in a buffer using Sun audio device, and return the buffer.
2037 If the environment variable AUDIOHOST is defined, its value is used as
2038 a recording host instead of local host."
2039 (let ((buffer (get-buffer-create " *MIME audio*"))
2040 (host (getenv "AUDIOHOST")))
2041 (message "Start the recording on %s. Type C-g to finish the recording..."
2042 (or host (system-name)))
2046 (condition-case errorcode
2047 (let ((selective-display nil) ;Disable ^M to nl translation.
2049 (kanji-flag nil)) ;NEmacs
2050 ;; If AUDIOHOST is defined, use the value as recording host.
2051 (cond ((not (null host))
2052 ;; Disable automatic conversion of coding system if Mule.
2053 (if (featurep 'mule)
2054 (define-program-coding-system nil "rsh" *noconv*))
2064 ;; Disable automatic conversion of coding system if Mule.
2065 (if (featurep 'mule)
2066 (define-program-coding-system nil "cat" *noconv*))
2072 (quit (message "Type C-g to finish recording... done.")
2073 buffer ;Return the buffer
2077 ;;; @ Other useful commands.
2080 ;; Message forwarding commands as content-type "message/rfc822".
2082 (defun mime-editor/insert-message (&optional message)
2084 (let ((inserter (assoc-value major-mode mime-editor/message-inserter-alist)))
2085 (if (and inserter (fboundp inserter))
2087 (mime-editor/insert-tag "message" "rfc822")
2088 (funcall inserter message)
2090 (message "Sorry, I don't have message inserter for your MUA.")
2093 (defun mime-editor/insert-mail (&optional message)
2095 (let ((inserter (assoc-value major-mode mime-editor/mail-inserter-alist)))
2096 (if (and inserter (fboundp inserter))
2098 (mime-editor/insert-tag "message" "rfc822")
2099 (funcall inserter message)
2101 (message "Sorry, I don't have mail inserter for your MUA.")
2104 (defun mime-editor/inserted-message-filter ()
2107 (let ((header-start (point))
2108 (case-fold-search t)
2111 ;; (if (re-search-forward "^$" (marker-position (mark-marker)))
2112 (if (re-search-forward "^$" (mark t))
2113 (narrow-to-region header-start (match-beginning 0))
2115 (goto-char header-start)
2116 (while (and (re-search-forward
2117 mime-editor/yank-ignored-field-regexp nil t)
2118 (setq beg (match-beginning 0))
2119 (setq end (1+ (rfc822/field-end)))
2121 (delete-region beg end)
2126 ;;; @ multipart enclosure
2129 (defun mime-editor/enclose-region (type beg end)
2132 (let ((current (point))
2135 (if (mime-editor/goto-tag)
2136 (or (eq current (match-beginning 0))
2137 (setq exist-prev-tag t)
2140 (narrow-to-region beg end)
2145 (insert (format "--<<%s>>-{\n" type))
2146 (goto-char (point-max))
2147 (insert (format "\n--}-<<%s>>\n" type))
2148 (goto-char (point-max))
2150 (if (and (not (looking-at mime-editor/single-part-tag-regexp))
2152 (insert (mime-make-text-tag) "\n")
2156 (defun mime-editor/enclose-mixed-region (beg end)
2158 (mime-editor/enclose-region "mixed" beg end)
2161 (defun mime-editor/enclose-parallel-region (beg end)
2163 (mime-editor/enclose-region "parallel" beg end)
2166 (defun mime-editor/enclose-digest-region (beg end)
2168 (mime-editor/enclose-region "digest" beg end)
2171 (defun mime-editor/enclose-alternative-region (beg end)
2173 (mime-editor/enclose-region "alternative" beg end)
2176 (defun mime-editor/enclose-signed-region (beg end)
2178 (if mime-editor/signing-type
2179 (mime-editor/enclose-region "signed" beg end)
2180 (message "Please specify signing type.")
2183 (defun mime-editor/enclose-encrypted-region (beg end)
2185 (if mime-editor/signing-type
2186 (mime-editor/enclose-region "encrypted" beg end)
2187 (message "Please specify encrypting type.")
2190 (defun mime-editor/insert-key (&optional arg)
2191 "Insert a pgp public key."
2193 (mime-editor/insert-tag "application" "pgp-keys")
2194 (mime-editor/define-encoding "7bit")
2195 (mc-insert-public-key)
2202 (defun mime-editor/set-split (arg)
2205 (y-or-n-p "Do you want to enable split?")
2207 (setq mime-editor/split-message arg)
2209 (message "This message is enabled to split.")
2210 (message "This message is not enabled to split.")
2217 (defun mime-editor/set-sign (arg)
2220 (y-or-n-p "Do you want to sign?")
2224 (setq mime-editor/pgp-processing 'sign)
2225 (message "This message will be signed.")
2227 (if (eq mime-editor/pgp-processing 'sign)
2228 (setq mime-editor/pgp-processing nil)
2230 (message "This message will not be signed.")
2233 (defun mime-editor/set-encrypt (arg)
2236 (y-or-n-p "Do you want to encrypt?")
2240 (setq mime-editor/pgp-processing 'encrypt)
2241 (message "This message will be encrypt.")
2243 (if (eq mime-editor/pgp-processing 'encrypt)
2244 (setq mime-editor/pgp-processing nil)
2246 (message "This message will not be encrypt.")
2249 (defvar mime-editor/pgp-processing nil)
2250 (make-variable-buffer-local 'mime-editor/pgp-processing)
2252 (defun mime-editor/call-mc (command)
2253 (let* ((header (rfc822/get-header-string-except
2254 "^Content-Type:" mail-header-separator)))
2255 (goto-char (point-min))
2256 (if (search-forward mail-header-separator)
2259 (goto-char (point-min))
2261 (insert "Content-Type: application/pgp; format=mime\n")
2262 (insert mail-header-separator)
2264 (if (null (call-interactively command))
2265 (throw 'mime-editor/error 'pgp-error)
2269 (defun mime-editor/pgp-processing ()
2271 (cdr (assq mime-editor/pgp-processing
2273 (encrypt . mc-encrypt)
2276 (mime-editor/call-mc command)
2283 (defun mime-editor/insert-partial-header
2284 (fields subject id number total separator)
2286 (insert (format "Subject: %s (%d/%d)\n" subject number total))
2287 (insert (format "Mime-Version: 1.0 (split by tm-edit %s)\n"
2288 mime-editor/version))
2290 Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
2291 id number total separator))
2294 (defun mime-editor/split-and-send
2295 (&optional cmd lines mime-editor/message-max-length)
2299 (count-lines (point-min) (point-max)))
2301 (or mime-editor/message-max-length
2302 (setq mime-editor/message-max-length
2303 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2304 mime-editor/message-default-max-length))
2306 (let* ((mime-editor/draft-file-name
2307 (or (buffer-file-name)
2309 (expand-file-name "tm-draft" mime/tmp-dir))))
2310 (separator mail-header-separator)
2312 (eval (cdr (assq major-mode mime-editor/window-config-alist))))
2314 (replace-space-with-underline (current-time-string))
2315 "@" (system-name) "\"")))
2316 (run-hooks 'mime-editor/before-split-hook)
2317 (let* ((header (rfc822/get-header-string-except
2318 mime-editor/split-ignored-field-regexp separator))
2319 (subject (mail-fetch-field "subject"))
2320 (total (+ (/ lines mime-editor/message-max-length)
2321 (if (> (mod lines mime-editor/message-max-length) 0)
2323 (the-buf (current-buffer))
2324 (buf (get-buffer "*tmp-send*"))
2329 mime-editor/split-message-sender-alist))
2332 mime-editor/message-default-sender-alist))
2335 (goto-char (point-min))
2336 (if (re-search-forward (concat "^" (regexp-quote separator) "$")
2342 (switch-to-buffer buf)
2344 (switch-to-buffer the-buf)
2346 (setq buf (get-buffer-create "*tmp-send*"))
2348 (switch-to-buffer buf)
2349 (make-local-variable 'mail-header-separator)
2350 (setq mail-header-separator separator)
2351 (switch-to-buffer the-buf)
2352 (goto-char (point-min))
2353 (re-search-forward "^$" nil t)
2354 (let ((mime-editor/partial-number 1))
2355 (setq data (buffer-substring
2358 (goto-line mime-editor/message-max-length)
2361 (delete-region (point-min)(point))
2362 (switch-to-buffer buf)
2363 (mime-editor/insert-partial-header
2364 header subject id mime-editor/partial-number total separator)
2368 (goto-char (point-min))
2369 (search-forward (concat "\n" mail-header-separator "\n"))
2372 (if (re-search-forward "^$" nil t)
2376 (goto-char (point-min))
2377 (while (re-search-forward
2378 mime-editor/split-blind-field-regexp nil t)
2379 (delete-region (match-beginning 0)
2380 (let ((e (rfc822/field-end)))
2381 (if (< e (point-max))
2387 (message (format "Sending %d/%d..."
2388 mime-editor/partial-number total))
2389 (call-interactively command)
2390 (message (format "Sending %d/%d... done"
2391 mime-editor/partial-number total))
2394 (switch-to-buffer the-buf)
2395 (setq mime-editor/partial-number 2)
2396 (while (< mime-editor/partial-number total)
2397 (setq data (buffer-substring
2400 (goto-line mime-editor/message-max-length)
2403 (delete-region (point-min)(point))
2404 (switch-to-buffer buf)
2405 (mime-editor/insert-partial-header
2406 header subject id mime-editor/partial-number total separator)
2409 (message (format "Sending %d/%d..."
2410 mime-editor/partial-number total))
2411 (call-interactively command)
2412 (message (format "Sending %d/%d... done"
2413 mime-editor/partial-number total))
2416 (switch-to-buffer the-buf)
2417 (setq mime-editor/partial-number
2418 (1+ mime-editor/partial-number))
2420 (goto-char (point-min))
2421 (mime-editor/insert-partial-header
2422 header subject id mime-editor/partial-number total separator)
2423 (message (format "Sending %d/%d..."
2424 mime-editor/partial-number total))
2427 (defun mime-editor/maybe-split-and-send (&optional cmd)
2429 (run-hooks 'mime-editor/before-send-hook)
2430 (let ((mime-editor/message-max-length
2431 (or (cdr (assq major-mode mime-editor/message-max-length-alist))
2432 mime-editor/message-default-max-length))
2433 (lines (count-lines (point-min) (point-max)))
2435 (if (and (> lines mime-editor/message-max-length)
2436 mime-editor/split-message)
2437 (mime-editor/split-and-send cmd lines mime-editor/message-max-length)
2441 ;;; @ preview message
2444 (defun mime-editor/preview-message ()
2445 "preview editing MIME message. [tm-edit.el]"
2447 (let* ((str (buffer-string))
2448 (separator mail-header-separator)
2449 (the-buf (current-buffer))
2450 (buf-name (buffer-name))
2451 (temp-buf-name (concat "*temp-article:" buf-name "*"))
2452 (buf (get-buffer temp-buf-name))
2456 (switch-to-buffer buf)
2459 (setq buf (get-buffer-create temp-buf-name))
2460 (switch-to-buffer buf)
2463 (setq major-mode 'mime/temporary-message-mode)
2464 (make-local-variable 'mail-header-separator)
2465 (setq mail-header-separator separator)
2466 (make-local-variable 'mime/editing-buffer)
2467 (setq mime/editing-buffer the-buf)
2469 (run-hooks 'mime-editor/translate-hook)
2470 (mime-editor/translate-buffer)
2471 (goto-char (point-min))
2472 (if (re-search-forward
2473 (concat "^" (regexp-quote separator) "$"))
2479 (defun mime-editor/quitting-method ()
2480 (let ((temp mime::preview/article-buffer)
2482 (mime-viewer/kill-buffer)
2484 (setq buf mime/editing-buffer)
2486 (switch-to-buffer buf)
2489 (set-alist 'mime-viewer/quitting-method-alist
2490 'mime/temporary-message-mode
2491 (function mime-editor/quitting-method)
2497 ;; by "OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
2498 ;; Mon, 10 Apr 1995 20:03:07 +0900
2500 (defvar mime-editor/draft-header-separator-alist
2501 '((news-reply-mode . mail-header-separator)
2502 (mh-letter-mode . mail-header-separator)
2505 (defvar mime::article/draft-header-separator nil)
2507 (defun mime-editor/draft-preview ()
2509 (let ((sep (cdr (assq major-mode mime-editor/draft-header-separator-alist))))
2510 (or (stringp sep) (setq sep (eval sep)))
2511 (make-variable-buffer-local 'mime::article/draft-header-separator)
2512 (goto-char (point-min))
2514 (concat "^\\(" (regexp-quote sep) "\\)?$"))
2515 (setq mime::article/draft-header-separator
2516 (buffer-substring (match-beginning 0) (match-end 0)))
2518 (mime/viewer-mode (current-buffer))
2519 (pop-to-buffer (current-buffer))
2522 (defun mime-viewer::quitting-method/draft-preview ()
2523 (let ((mother mime::preview/mother-buffer))
2525 (switch-to-buffer mother)
2526 (goto-char (point-min))
2530 (regexp-quote mime::article/draft-header-separator)
2534 (insert mime::article/draft-header-separator)
2535 (set-buffer-modified-p (buffer-modified-p))
2537 (mime-viewer/kill-buffer)
2538 (pop-to-buffer mother)
2541 (set-alist 'mime-viewer/quitting-method-alist
2543 (function mime-viewer::quitting-method/draft-preview)
2546 (set-alist 'mime-viewer/quitting-method-alist
2548 (function mime-viewer::quitting-method/draft-preview)
2555 (defun replace-space-with-underline (str)
2556 (mapconcat (function
2570 (run-hooks 'tm-edit-load-hook)
2572 ;;; tm-edit.el ends here