tm 7.70.
[elisp/tm.git] / tm-edit.el
index faab4ea..8e7334f 100644 (file)
@@ -8,7 +8,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.62 $
+;;; Version: $Revision: 7.70 $
 ;;; Keywords: mail, news, MIME, multimedia, multilingual
 ;;;
 ;;; This file is part of tm (Tools for MIME).
 ;;;
 
 (defconst mime-editor/RCS-ID
-  "$Id: tm-edit.el,v 7.62 1996/05/19 16:16:42 morioka Exp $")
+  "$Id: tm-edit.el,v 7.70 1996/07/09 13:30:32 morioka Exp $")
 
 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
 
 (defvar mime-prefix "\C-c\C-x"
   "*Keymap prefix for MIME commands.")
 
-;; (defvar mime-signature-file "~/.signature.rtf"
-;;   "*Signature file to be included as a part of a multipart message.")
-
 (defvar mime-ignore-preceding-spaces nil
   "*Ignore preceding white spaces if non-nil.")
 
@@ -337,6 +334,11 @@ To insert a signature file automatically, call the function
      nil
      "attachment"      (("filename" . file))
      )
+    ("\\.patch$"
+     "application" "octet-stream" (("type" . "patch"))
+     nil
+     "attachment"      (("filename" . file))
+     )
     ("\\.signature"
      "text"    "plain"         nil     nil)
     (".*"
@@ -368,7 +370,7 @@ If encoding is nil, it is determined from its contents.")
 ;;;
 
 (defvar mime-editor/yank-ignored-field-list
-  '("Received" "Sender" "Approved" "Path" "Status" "X-VM-.*" "X-UIDL")
+  '("Received" "Approved" "Path" "Replied" "Status" "X-VM-.*" "X-UIDL")
   "Delete these fields from original message when it is inserted
 as message/rfc822 part.
 Each elements are regexp of field-name. [tm-edit.el]")
@@ -399,19 +401,8 @@ Each elements are regexp of field-name. [tm-edit.el]")
 (defvar mime-editor/split-blind-field-regexp
   "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
 
-(defvar mime-editor/message-default-sender-alist
-  '((mail-mode . mail-send-and-exit)
-    (mh-letter-mode . mh-send-letter)
-    (news-reply-mode . gnus-inews-news)
-    ))
-
 (defvar mime-editor/split-message-sender-alist
-  '((mail-mode
-     . (lambda ()
-        (interactive)
-        (sendmail-send-it)
-        ))
-    (mh-letter-mode
+  '((mh-letter-mode
      . (lambda (&optional arg)
         (interactive "P")
         (write-region (point-min) (point-max)
@@ -434,22 +425,6 @@ Each elements are regexp of field-name. [tm-edit.el]")
         ))
     ))
 
-(defvar mime-editor/window-config-alist
-  '((mail-mode       . nil)
-    (mh-letter-mode  . mh-previous-window-config)
-    (news-reply-mode . (cond ((boundp 'gnus-winconf-post-news)
-                             (prog1
-                                 gnus-winconf-post-news
-                               (setq gnus-winconf-post-news nil)
-                               ))
-                            ((boundp 'gnus-prev-winconf)
-                             (prog1
-                                 gnus-prev-winconf
-                               (setq gnus-prev-winconf nil)
-                               ))
-                            ))
-    ))
-
 (defvar mime-editor/news-reply-mode-server-running nil)
 
 
@@ -526,16 +501,15 @@ Tspecials means any character that matches with it in header must be quoted.")
 (defconst mime-editor/mime-map (make-sparse-keymap)
   "Keymap for MIME commands.")
 
+(defconst mime-editor/minor-mime-map nil
+  "Keymap for MIME commands.")
+
 ;;; @ keymap and menu
 ;;;
 
 (defvar mime/editor-mode-flag nil)
 (make-variable-buffer-local 'mime/editor-mode-flag)
 
-(set-alist 'minor-mode-alist
-          'mime/editor-mode-flag
-          '((" MIME-Edit "  mime-editor/transfer-level-string)))
-
 (defun mime-editor/define-keymap (keymap)
   "Add mime-editor commands to KEYMAP."
   (if (not (keymapp keymap))
@@ -563,6 +537,29 @@ Tspecials means any character that matches with it in header must be quoted.")
 
 (mime-editor/define-keymap mime-editor/mime-map)
 
+(if mime-editor/minor-mime-map
+    ()
+  (setq mime-editor/minor-mime-map 
+       (make-sparse-keymap 'mime-editor/minor-mime-map))
+  (define-key mime-editor/minor-mime-map mime-prefix mime-editor/mime-map))
+
+(defun mime-editor/toggle-mode ()
+  (interactive)
+  (if mime/editor-mode-flag
+      (mime-editor/exit 'nomime)
+    (mime/editor-mode)
+    ))
+
+(if running-xemacs
+    (add-minor-mode 'mime/editor-mode-flag
+                   '((" MIME-Edit "  mime-editor/transfer-level-string))
+                   mime-editor/minor-mime-map
+                   nil
+                   'mime-editor/toggle-mode)
+  (set-alist 'minor-mode-alist
+            'mime/editor-mode-flag
+            '((" MIME-Edit "  mime-editor/transfer-level-string))))
+
 (defconst mime-editor/menu-title "MIME-Edit")
 
 (defconst mime-editor/menu-list
@@ -815,10 +812,6 @@ just return to previous mode."
     ;; Restore previous state.
     (setq mime/editor-mode-flag nil)
     (cond (running-xemacs
-          ;; mime-prefix only defined if binding was nil
-          (if (eq (lookup-key (current-local-map) mime-prefix)
-                  mime-editor/mime-map)
-              (define-key (current-local-map) mime-prefix nil))
           (delete-menu-item (list mime-editor/menu-title)))
          (t
           (use-local-map mime/editor-mode-old-local-map)))
@@ -954,7 +947,7 @@ Charset is automatically obtained from the `mime/lc-charset-alist'."
          (function
           (lambda ()
             (apply (function mime-editor/insert-tag)
-                   (mime-find-file-type signature))
+                   (mime-find-file-type signature-file-name))
             )))
         )
     (insert-signature arg)
@@ -1080,7 +1073,8 @@ Optional argument ENCODING specifies an encoding method such as base64."
        (insert-buffer-substring buffer)
        ;; Encode binary message if necessary.
        (if encoding
-           (mime-encode-region encoding start (point-max))))
+           (mime-encode-region start (point-max) encoding)
+         ))
       (if hide-p
          (progn
            (mime-flag-region (point-min) (1- (point-max)) ?\^M)
@@ -1723,13 +1717,7 @@ Content-Transfer-Encoding: 7bit
            (insert (format "Content-Transfer-Encoding: %s\n" encoding))
          )
        (insert "\n")
-       (or (let ((program-coding-system-alist
-                  (cons (cons (cons nil ".*pgp.*")
-                              (cons *noconv* *noconv*))
-                        program-coding-system-alist))
-                 )
-             (mc-pgp-sign-region beg (point-max))
-             )
+       (or (as-binary-process (mc-pgp-sign-region beg (point-max)))
            (throw 'mime-editor/error 'pgp-error)
            )
        (goto-char beg)
@@ -1776,15 +1764,11 @@ Content-Transfer-Encoding: 7bit
              (insert (format "Content-Transfer-Encoding: %s\n" encoding))
            )
          (insert "\n")
-         (or (let ((program-coding-system-alist
-                    (cons (cons (cons nil ".*pgp.*")
-                                (cons *noconv* *noconv*))
-                          program-coding-system-alist))
-                   )
-               (mc-pgp-encrypt-region
-                (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
-                beg (point-max))
-               )
+         (or (as-binary-process
+              (mc-pgp-encrypt-region
+               (mc-split "\\([ \t\n]*,[ \t\n]*\\)+" recipients)
+               beg (point-max))
+              )
              (throw 'mime-editor/error 'pgp-error)
              )
          (goto-char beg)
@@ -1988,7 +1972,7 @@ Content-Transfer-Encoding: 7bit
                   )
              (mime-charset-encode-region beg (mime-editor/content-end)
                                          charset)
-             (mime-encode-region encoding beg (mime-editor/content-end))
+             (mime-encode-region beg (mime-editor/content-end) encoding)
              (mime-editor/define-encoding encoding)
              ))
        (forward-line 1)
@@ -2002,7 +1986,7 @@ Content-Transfer-Encoding: 7bit
               (end (mime-editor/content-end))
               (body (buffer-substring beg end))
               )
-         (mime-encode-region encoding beg end)
+         (mime-encode-region beg end encoding)
          (mime-editor/define-encoding encoding))
        (forward-line 1)
        )
@@ -2318,92 +2302,46 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
              (make-temp-name
               (expand-file-name "tm-draft" mime/tmp-dir))))
         (separator mail-header-separator)
-        (config
-         (eval (cdr (assq major-mode mime-editor/window-config-alist))))
         (id (concat "\""
                     (replace-space-with-underline (current-time-string))
                     "@" (system-name) "\"")))
     (run-hooks 'mime-editor/before-split-hook)
-    (let* ((header (rfc822/get-header-string-except
-                   mime-editor/split-ignored-field-regexp separator))
-          (subject (mail-fetch-field "subject"))
-          (total (+ (/ lines mime-editor/message-max-length)
-                    (if (> (mod lines mime-editor/message-max-length) 0)
-                        1)))
-          (the-buf (current-buffer))
-          (buf (get-buffer "*tmp-send*"))
-          (command
-           (or cmd
-               (cdr
-                (assq major-mode
-                      mime-editor/split-message-sender-alist))
-               (cdr
-                (assq major-mode
-                      mime-editor/message-default-sender-alist))
-               ))
-          data)
-      (goto-char (point-min))
-      (if (re-search-forward (concat "^" (regexp-quote separator) "$")
-                            nil t)
-         (replace-match "")
-       )
-      (if buf
-         (progn
-           (switch-to-buffer buf)
-           (erase-buffer)
-           (switch-to-buffer the-buf)
-           )
-       (setq buf (get-buffer-create "*tmp-send*"))
-       )
-      (switch-to-buffer buf)
-      (make-local-variable 'mail-header-separator)
-      (setq mail-header-separator separator)
-      (switch-to-buffer the-buf)
-      (goto-char (point-min))
-      (re-search-forward "^$" nil t)
-      (let ((mime-editor/partial-number 1))
-       (setq data (buffer-substring
-                   (point-min)
-                   (progn
-                     (goto-line mime-editor/message-max-length)
-                     (point))
-                   ))
-       (delete-region (point-min)(point))
-       (switch-to-buffer buf)
-       (mime-editor/insert-partial-header
-        header subject id mime-editor/partial-number total separator)
-       (insert data)
-       (save-excursion
-         (save-restriction
-           (goto-char (point-min))
-           (search-forward (concat "\n" mail-header-separator "\n"))
-           (narrow-to-region
-            (match-end 0)
-            (if (re-search-forward "^$" nil t)
-                (match-beginning 0)
-              (point-max)
+    (let ((the-buf (current-buffer))
+         (copy-buf (get-buffer-create " *Original Message*"))
+         (header (rfc822/get-header-string-except
+                  mime-editor/split-ignored-field-regexp separator))
+         (subject (mail-fetch-field "subject"))
+         (total (+ (/ lines mime-editor/message-max-length)
+                   (if (> (mod lines mime-editor/message-max-length) 0)
+                       1)))
+         (command
+          (or cmd
+              (cdr
+               (assq major-mode
+                     mime-editor/split-message-sender-alist))
               ))
-           (goto-char (point-min))
-           (while (re-search-forward
-                   mime-editor/split-blind-field-regexp nil t)
-             (delete-region (match-beginning 0)
-                            (let ((e (rfc822/field-end)))
-                              (if (< e (point-max))
-                                  (1+ e)
-                                e)))
-             )
-           ))
-       (save-excursion
-         (message (format "Sending %d/%d..."
-                          mime-editor/partial-number total))
-         (call-interactively command)
-         (message (format "Sending %d/%d... done"
-                          mime-editor/partial-number total))
-         )
+         (mime-editor/partial-number 1)
+         data)
+      (save-excursion
+       (set-buffer copy-buf)
        (erase-buffer)
-       (switch-to-buffer the-buf)
-       (setq mime-editor/partial-number 2)
-       (while (< mime-editor/partial-number total)
+       (insert-buffer the-buf)
+       (save-restriction
+         (if (re-search-forward
+              (concat "^" (regexp-quote separator) "$") nil t)
+             (let ((he (match-beginning 0)))
+               (replace-match "")
+               (narrow-to-region (point-min) he)
+               ))
+         (goto-char (point-min))
+         (while (re-search-forward mime-editor/split-blind-field-regexp nil t)
+           (delete-region (match-beginning 0)
+                          (1+ (rfc822/field-end)))
+           )))
+      (while (< mime-editor/partial-number total)
+       (erase-buffer)
+       (save-excursion
+         (set-buffer copy-buf)
          (setq data (buffer-substring
                      (point-min)
                      (progn
@@ -2411,28 +2349,36 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
                        (point))
                      ))
          (delete-region (point-min)(point))
-         (switch-to-buffer buf)
-         (mime-editor/insert-partial-header
-          header subject id mime-editor/partial-number total separator)
-         (insert data)
-         (save-excursion
-           (message (format "Sending %d/%d..."
-                            mime-editor/partial-number total))
-           (call-interactively command)
-           (message (format "Sending %d/%d... done"
-                            mime-editor/partial-number total))
-           )
-         (erase-buffer)
-         (switch-to-buffer the-buf)
-         (setq mime-editor/partial-number
-               (1+ mime-editor/partial-number))
          )
-       (goto-char (point-min))
        (mime-editor/insert-partial-header
         header subject id mime-editor/partial-number total separator)
+       (insert data)
+       (save-excursion
+         (message (format "Sending %d/%d..."
+                          mime-editor/partial-number total))
+         (call-interactively command)
+         (message (format "Sending %d/%d... done"
+                          mime-editor/partial-number total))
+         )
+       (setq mime-editor/partial-number
+             (1+ mime-editor/partial-number))
+       )
+      (erase-buffer)
+      (save-excursion
+       (set-buffer copy-buf)
+       (setq data (buffer-string))
+       (erase-buffer)
+       )
+      (mime-editor/insert-partial-header
+       header subject id mime-editor/partial-number total separator)
+      (insert data)
+      (save-excursion
        (message (format "Sending %d/%d..."
                         mime-editor/partial-number total))
-       ))))
+       (message (format "Sending %d/%d... done"
+                        mime-editor/partial-number total))
+       )
+      )))
 
 (defun mime-editor/maybe-split-and-send (&optional cmd)
   (interactive)
@@ -2651,7 +2597,7 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
                              (if (search-forward "\n\n" nil t)
                                  (progn
                                    (mime-decode-region
-                                    encoding (match-end 0)(point-max))
+                                    (match-end 0)(point-max) encoding)
                                    (setq encoded t
                                          encoding nil)
                                    )))))))