tm 7.90.
[elisp/tm.git] / tm-edit.el
index f62b31c..9498829 100644 (file)
@@ -6,7 +6,7 @@
 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
 ;; Created: 1994/08/21 renamed from mime.el
-;; Version: $Revision: 7.86 $
+;; Version: $Revision: 7.90 $
 ;; Keywords: mail, news, MIME, multimedia, multilingual
 
 ;; This file is part of tm (Tools for MIME).
@@ -22,8 +22,8 @@
 ;; General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with this program; see the file COPYING.  If not, write to
-;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 ;;;
 
 (defconst mime-editor/RCS-ID
-  "$Id: tm-edit.el,v 7.86 1996/09/21 14:33:25 morioka Exp $")
+  "$Id: tm-edit.el,v 7.90 1996/10/07 14:30:50 shuhei-k Exp $")
 
 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
 
@@ -148,9 +148,9 @@ If non-nil, the text tag is not inserted unless something different.")
 (defvar mime-auto-hide-body t
   "*Hide non-textual body encoded in base64 after insertion if non-nil.")
 
-(defvar mime-voice-recorder
-  (function mime-voice-recorder-for-sun)
-  "*Function to record a voice message and return a buffer that contains it.")
+(defvar mime-editor/voice-recorder
+  (function mime-editor/voice-recorder-for-sun)
+  "*Function to record a voice message and encode it. [tm-edit.el]")
 
 (defvar mime/editor-mode-hook nil
   "*Hook called when enter MIME mode.")
@@ -385,7 +385,8 @@ If encoding is nil, it is determined from its contents.")
 ;;;
 
 (defvar mime-editor/yank-ignored-field-list
-  '("Received" "Approved" "Path" "Replied" "Status" "X-VM-.*" "X-UIDL")
+  '("Received" "Approved" "Path" "Replied" "Status"
+    "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*")
   "Delete these fields from original message when it is inserted
 as message/rfc822 part.
 Each elements are regexp of field-name. [tm-edit.el]")
@@ -745,10 +746,10 @@ User customizable variables (not documented all of them):
     Hide a non-textual body message encoded in base64 after insertion
     if non-nil.
 
- mime-voice-recorder
-    Specifies a function to record a voice message and return a buffer
-    that contains it.  The function mime-voice-recorder-for-sun is for
-    Sun SparcStations.
+ mime-editor/voice-recorder
+    Specifies a function to record a voice message and encode it.
+    The function `mime-editor/voice-recorder-for-sun' is for Sun
+    SparcStations.
 
  mime/editor-mode-hook
     Turning on MIME mode calls the value of mime/editor-mode-hook, if
@@ -857,13 +858,22 @@ just return to previous mode."
   "Insert a text message.
 Charset is automatically obtained from the `mime/lc-charset-alist'."
   (interactive)
-  (if (and (mime-editor/insert-tag "text" nil nil)
-          (looking-at mime-editor/single-part-tag-regexp))
+  (let ((ret (mime-editor/insert-tag "text" nil nil)))
+  (if ret
       (progn
-       ;; Make a space between the following message.
-       (insert "\n")
-       (forward-char -1)
-       )))
+       (if (looking-at mime-editor/single-part-tag-regexp)
+           (progn
+             ;; Make a space between the following message.
+             (insert "\n")
+             (forward-char -1)
+             ))
+       (if (and (member (second ret) '("enriched" "richtext"))
+                (fboundp 'enriched-mode)
+                )
+           (enriched-mode t)
+         (if (boundp 'enriched-mode)
+             (enriched-mode nil)
+           ))))))
 
 (defun mime-editor/insert-file (file)
   "Insert a message from a file."
@@ -888,7 +898,7 @@ Charset is automatically obtained from the `mime/lc-charset-alist'."
                                  ")"
                                  ))
                      ": ")
-             mime-encoding-method-alist nil t nil))))
+             mime-file-encoding-method-alist nil t nil))))
     (if (string-equal encoding "")
        (setq encoding default))
     (if (or (consp parameters) (stringp disposition-type))
@@ -950,12 +960,21 @@ Charset is automatically obtained from the `mime/lc-charset-alist'."
 (defun mime-editor/insert-voice ()
   "Insert a voice message."
   (interactive)
-  (mime-editor/insert-tag "audio" "basic" nil)
-  (let ((buffer (funcall mime-voice-recorder)))
-    (unwind-protect
-       (mime-editor/insert-binary-buffer buffer "base64")
-      (kill-buffer buffer)
-      )))
+  (let ((encoding
+        (completing-read
+         "What transfer encoding: "
+         mime-file-encoding-method-alist nil t nil)))
+    (mime-editor/insert-tag "audio" "basic" nil)
+    (mime-editor/define-encoding encoding)
+    (save-restriction
+      (narrow-to-region (1- (point))(point))
+      (unwind-protect
+         (funcall mime-editor/voice-recorder encoding)
+       (progn
+         (insert "\n")
+         (invisible-region (point-min)(point-max))
+         (goto-char (point-max))
+         )))))
 
 (defun mime-editor/insert-signature (&optional arg)
   "Insert a signature file."
@@ -977,6 +996,15 @@ Charset is automatically obtained from the `mime/lc-charset-alist'."
   "Insert new MIME tag and return a list of PRITYPE, SUBTYPE, and PARAMETERS.
 If nothing is inserted, return nil."
   (interactive)
+  (let ((p (point)))
+    (mime-editor/goto-tag)
+    (if (and (re-search-forward mime-editor/tag-regexp nil t)
+            (< (match-beginning 0) p)
+            (< p (match-end 0))
+            )
+       (goto-char (match-beginning 0))
+      (goto-char p)
+      ))
   (let ((oldtag nil)
        (newtag nil)
        (current (point))
@@ -1021,66 +1049,40 @@ If nothing is inserted, return nil."
       )
     ))
 
-;; Insert the binary content after MIME tag.
-;;     modified by MORITA Masahiro <hiro@isl.ntt.JP>
-;;     for x-uue
 (defun mime-editor/insert-binary-file (file &optional encoding)
   "Insert binary FILE at point.
 Optional argument ENCODING specifies an encoding method such as base64."
-  (let ((tmpbuf (get-buffer-create " *MIME insert*")))
-    (save-excursion
-      (set-buffer tmpbuf)
-      (erase-buffer)
-      (as-binary-input-file (insert-file-contents file))
-      )
-    (prog1
-       (if (and (stringp encoding)
-                (string-equal (downcase encoding) "x-uue"))
-           (progn
-             (require 'mel-u)
-             (let ((uuencode-external-encoder
-                    (cons (car uuencode-external-encoder)
-                          (list (file-name-nondirectory file))
-                          )))
-               (mime-editor/insert-binary-buffer tmpbuf encoding)
-               ))
-         (mime-editor/insert-binary-buffer tmpbuf encoding))
-      (kill-buffer tmpbuf))))
-
-;; Insert the binary content after MIME tag.
-;;     modified by MORITA Masahiro <hiro@isl.ntt.JP>
-;;     for x-uue
-(defun mime-editor/insert-binary-buffer (buffer &optional encoding)
-  "Insert binary BUFFER at point.
-Optional argument ENCODING specifies an encoding method such as base64."
   (let* ((tagend (1- (point)))         ;End of the tag
         (hide-p (and mime-auto-hide-body
                      (stringp encoding)
-                     (let ((en (downcase encoding)))
-                       (or (string-equal en "base64")
-                           (string-equal en "x-uue")
-                           ))))
+                     (not
+                      (let ((en (downcase encoding)))
+                        (or (string-equal en "7bit")
+                            (string-equal en "8bit")
+                            (string-equal en "binary")
+                            )))))
         )
     (save-restriction
-      (narrow-to-region (1- (point)) (point))
-      (let ((start (point))
-           (emx-binary-mode t))        ;Stop LF to CRLF conversion in OS/2
-       (insert-buffer-substring buffer)
-       ;; Encode binary message if necessary.
-       (if encoding
-           (mime-encode-region start (point-max) encoding)
-         ))
+      (narrow-to-region tagend (point))
+      (mime-insert-encoded-file file encoding)
       (if hide-p
          (progn
            (invisible-region (point-min) (point-max))
            (goto-char (point-max))
            )
+       (goto-char (point-max))
        ))
+    (or hide-p
+       (looking-at mime-editor/tag-regexp)
+       (= (point)(point-max))
+       (mime-editor/insert-tag "text" "plain")
+       )
     ;; Define encoding even if it is 7bit.
     (if (stringp encoding)
        (save-excursion
-         (goto-char tagend)            ;Make sure which line the tag is on.
-         (mime-editor/define-encoding encoding)))
+         (goto-char tagend) ; Make sure which line the tag is on.
+         (mime-editor/define-encoding encoding)
+         ))
     ))
 
 \f
@@ -1995,6 +1997,14 @@ Content-Transfer-Encoding: 7bit
                              (point)))
                       (end (mime-editor/content-end))
                       )
+                  ;; Patch for hard newlines
+                   ;; (save-excursion
+                   ;;   (goto-char beg)
+                   ;;   (while (search-forward "\n" end t)
+                   ;;     (put-text-property (match-beginning 0)
+                   ;;                        (point)
+                   ;;                        'hard t)))
+                  ;; End patch for hard newlines
                   (enriched-encode beg end)
                   (goto-char beg)
                   (if (search-forward "\n\n")
@@ -2049,46 +2059,13 @@ Content-Transfer-Encoding: 7bit
 
 ;; Sun implementations
 
-(defun mime-voice-recorder-for-sun ()
-  "Record voice in a buffer using Sun audio device, and return the buffer.
-If the environment variable AUDIOHOST is defined, its value is used as
-a recording host instead of local host."
-  (let ((buffer (get-buffer-create " *MIME audio*"))
-       (host (getenv "AUDIOHOST")))
-    (message "Start the recording on %s.  Type C-g to finish the recording..."
-            (or host (system-name)))
-    (save-excursion
-      (set-buffer buffer)
-      (erase-buffer)
-      (condition-case errorcode
-         (let ((selective-display nil) ;Disable ^M to nl translation.
-               (mc-flag nil)           ;Mule
-               (kanji-flag nil))       ;NEmacs
-           ;; If AUDIOHOST is defined, use the value as recording host.
-           (cond ((not (null host))
-                  ;; Disable automatic conversion of coding system if Mule.
-                  (if (featurep 'mule)
-                      (define-program-coding-system nil "rsh" *noconv*))
-                  (call-process "rsh"
-                                nil
-                                buffer
-                                nil
-                                host
-                                "cat"
-                                "/dev/audio"
-                                ))
-                 (t
-                  ;; Disable automatic conversion of coding system if Mule.
-                  (if (featurep 'mule)
-                      (define-program-coding-system nil "cat" *noconv*))
-                  (call-process "cat"
-                                "/dev/audio"
-                                buffer
-                                nil
-                                ))))
-       (quit (message "Type C-g to finish recording... done.")
-             buffer                    ;Return the buffer
-             )))))
+(defun mime-editor/voice-recorder-for-sun (encoding)
+  "Record voice in a buffer using Sun audio device,
+and insert data encoded as ENCODING. [tm-edit.el]"
+  (message "Start the recording on %s.  Type C-g to finish the recording..."
+          (system-name))
+  (mime-insert-encoded-file "/dev/audio" encoding)
+  )
 
 \f
 ;;; @ Other useful commands.