(What's tm?): Don't use section number.
[elisp/tm.git] / tm-edit.el
index f7c1bbf..12cd4b9 100644 (file)
@@ -6,7 +6,6 @@
 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
 ;; Created: 1994/08/21 renamed from mime.el
-;; Version: $Revision: 7.103 $
 ;; Keywords: mail, news, MIME, multimedia, multilingual
 
 ;; This file is part of tm (Tools for MIME).
 (require 'mel)
 (require 'tl-list)
 (require 'tm-view)
-(require 'tm-ew-e)
+(require 'eword-encode)
 (require 'signature)
 
 
 ;;; @ version
 ;;;
 
-(defconst mime-editor/RCS-ID
-  "$Id: tm-edit.el,v 7.103 1997/01/31 14:21:10 morioka Exp $")
-
-(defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
+(defconst mime-editor/version "8.8 (Time Passed Me By)")
 
 (defconst mime-editor/version-name
   (concat "tm-edit " mime-editor/version))
@@ -210,6 +206,7 @@ To insert a signature file automatically, call the function
     ("image"
      ("gif")
      ("jpeg")
+     ("png")
      ("tiff")
      ("x-pic")
      ("x-mag")
@@ -226,7 +223,7 @@ To insert a signature file automatically, call the function
      "text"    "richtext"      nil
      nil
      nil               nil)
-    ("\\.html$"
+    ("\\.\\(html\\|htm\\)$"
      "text"    "html"          nil
      nil
      nil               nil)
@@ -235,7 +232,7 @@ To insert a signature file automatically, call the function
      "quoted-printable"
      "attachment"      (("filename" . file))
      )
-    ("\\.jpg$"
+    ("\\.\\(jpeg\\|jpg\\)$"
      "image"   "jpeg"          nil
      "base64"
      "inline"          (("filename" . file))
@@ -245,7 +242,12 @@ To insert a signature file automatically, call the function
      "base64"
      "inline"          (("filename" . file))
      )
-    ("\\.tiff$"
+    ("\\.png$"
+     "image"   "png"           nil
+     "base64"
+     "inline"          (("filename" . file))
+     )
+    ("\\.\\(tiff\\|tif\\)$"
      "image"   "tiff"          nil
      "base64"
      "inline"          (("filename" . file))
@@ -280,9 +282,14 @@ To insert a signature file automatically, call the function
      "base64"
      "attachment"      (("filename" . file))
      )
+    ("\\.txt$"
+     "text"    "plain"         nil
+     nil
+     "attachment"      (("filename" . file))
+     )
     ("\\.el$"
      "application" "octet-stream" (("type" . "emacs-lisp"))
-     "7bit"
+     nil
      "attachment"      (("filename" . file))
      )
     ("\\.lsp$"
@@ -330,7 +337,7 @@ To insert a signature file automatically, call the function
      "base64"
      "attachment"      (("filename" . file))
      )
-    ("\\.diff$"
+    ("\\.diffs?$"
      "application" "octet-stream" (("type" . "patch"))
      nil
      "attachment"      (("filename" . file))
@@ -433,16 +440,6 @@ If it is not specified for a major-mode,
 (defvar mime-editor/encrypting-type 'pgp-elkins
   "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [tm-edit.el]")
 
-(defvar mime-editor/pgp-sign-function 'tm:mc-pgp-sign-region)
-(defvar mime-editor/pgp-encrypt-function 'tm:mc-pgp-encrypt-region)
-(defvar mime-editor/traditional-pgp-sign-function 'mc-pgp-sign-region)
-(defvar mime-editor/pgp-insert-public-key-function 'mc-insert-public-key)
-
-(autoload mime-editor/pgp-sign-function "tm-edit-mc")
-(autoload mime-editor/pgp-encrypt-function "tm-edit-mc")
-(autoload mime-editor/traditional-pgp-sign-function "mc-pgp")
-(autoload mime-editor/pgp-insert-public-key-function "mc-toplev")
-
 
 ;;; @@ about tag
 ;;;
@@ -577,6 +574,7 @@ Tspecials means any character that matches with it in header must be quoted.")
 (defconst mime-editor/menu-list
   '((mime-help "Describe MIME editor mode" mime-editor/help)
     (file      "Insert File"           mime-editor/insert-file)
+    (file      "Insert File (verbose)" mime-editor/insert-file-verbose)
     (external  "Insert External"       mime-editor/insert-external)
     (voice     "Insert Voice"          mime-editor/insert-voice)
     (message   "Insert Message"        mime-editor/insert-message)
@@ -621,16 +619,24 @@ Tspecials means any character that matches with it in header must be quoted.")
 (defun mime-editor/define-menu-for-xemacs ()
   "Define menu for Emacs 19."
   (cond ((featurep 'menubar)
-        (make-local-variable 'current-menubar)
-        (set-buffer-menubar current-menubar)
-        (add-submenu nil
-                     (cons mime-editor/menu-title
-                           (mapcar (function
-                                    (lambda (item)
-                                      (vector (nth 1 item)(nth 2 item)
-                                              mime/editor-mode-flag)
-                                      ))
-                                   mime-editor/menu-list)))
+         ;; (make-local-variable 'current-menubar)
+         ;; (set-buffer-menubar current-menubar)
+         ;; (add-submenu nil
+         ;;              (cons mime-editor/menu-title
+         ;;                    (mapcar (function
+         ;;                             (lambda (item)
+         ;;                               (vector (nth 1 item)(nth 2 item)
+         ;;                                       mime/editor-mode-flag)
+         ;;                               ))
+         ;;                            mime-editor/menu-list)))
+        (easy-menu-add
+         (cons mime-editor/menu-title
+               (mapcar (function
+                        (lambda (item)
+                          (vector (nth 1 item)(nth 2 item)
+                                  mime/editor-mode-flag)
+                          ))
+                       mime-editor/menu-list)))
         )))
 
 ;;; modified by Steven L. Baur <steve@miranova.com>
@@ -701,6 +707,8 @@ Following commands are available in addition to major mode commands:
 \[make single part\]
 \\[mime-editor/insert-text]    insert a text message.
 \\[mime-editor/insert-file]    insert a (binary) file.
+\\[mime-editor/insert-file-verbose]    insert a (binary) file, with verbose
+                               MIME prompting.
 \\[mime-editor/insert-external]        insert a reference to external body.
 \\[mime-editor/insert-voice]   insert a voice message.
 \\[mime-editor/insert-message] insert a mail or news message.
@@ -880,7 +888,7 @@ just return to previous mode."
 
 (defun mime-editor/insert-text ()
   "Insert a text message.
-Charset is automatically obtained from the `mime/lc-charset-alist'."
+Charset is automatically obtained from the `charsets-mime-charset-alist'."
   (interactive)
   (let ((ret (mime-editor/insert-tag "text" nil nil)))
   (if ret
@@ -914,7 +922,7 @@ Charset is automatically obtained from the `mime/lc-charset-alist'."
        (setq type    (mime-prompt-for-type type)
              subtype (mime-prompt-for-subtype type subtype)
              ))
-    (if (or (interactive-p) verbose)
+    (if (or (interactive-p) verbose (null encoding))
        (setq encoding (mime-prompt-for-encoding encoding))
       )
     (if (or (consp parameters) (stringp disposition-type))
@@ -955,6 +963,16 @@ Charset is automatically obtained from the `mime/lc-charset-alist'."
     (mime-editor/insert-binary-file file encoding)
     ))
 
+;;
+;; mime-editor/insert-file-verbose exists so that users can access verbose
+;; functionality from menu picks, and not just key sequences.
+;;
+(defun mime-editor/insert-file-verbose (file)
+  "Insert a message from a file, with verbose MIME prompting"
+  (interactive "fInsert file as MIME message: \n")
+  (mime-editor/insert-file file t)
+  )
+
 (defun mime-editor/insert-external ()
   "Insert a reference to external body."
   (interactive)
@@ -979,7 +997,7 @@ Charset is automatically obtained from the `mime/lc-charset-alist'."
   (let ((encoding
         (completing-read
          "What transfer encoding: "
-         mime-file-encoding-method-alist nil t nil)))
+          (mime-encoding-alist) nil t nil)))
     (mime-editor/insert-tag "audio" "basic" nil)
     (mime-editor/define-encoding encoding)
     (save-restriction
@@ -1296,7 +1314,8 @@ Nil if no such parameter."
 (defun mime-find-file-type (file)
   "Guess Content-Type, subtype, and parameters from FILE."
   (let ((guess nil)
-       (guesses mime-file-types))
+       (guesses mime-file-types)
+       (case-fold-search t))
     (while (and (not guess) guesses)
       (if (string-match (car (car guesses)) file)
          (setq guess (cdr (car guesses))))
@@ -1408,7 +1427,7 @@ Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
            (setq encoding
                  (completing-read
                   "What transfer encoding: "
-                  mime-file-encoding-method-alist nil t default)
+                   (mime-encoding-alist) nil t default)
                  )
            ""))
     encoding))
@@ -1424,7 +1443,7 @@ Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
 
 (defun mime-editor/translate-header ()
   "Encode the message header into network representation."
-  (mime/encode-message-header 'code-conversion)
+  (eword-encode-header 'code-conversion)
   (run-hooks 'mime-editor/translate-header-hook)
   )
 
@@ -1558,8 +1577,9 @@ Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
            (insert (format "Content-Transfer-Encoding: %s\n" encoding))
          )
        (insert "\n")
-       (or (funcall mime-editor/pgp-sign-function
-                    (point-min)(point-max) nil nil pgp-boundary)
+       (or (as-binary-process
+            (funcall (pgp-function 'mime-sign)
+                     (point-min)(point-max) nil nil pgp-boundary))
            (throw 'mime-editor/error 'pgp-error)
            )
        ))))
@@ -1622,7 +1642,7 @@ Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
              (insert (format "Content-Transfer-Encoding: %s\n" encoding))
            )
          (insert "\n")
-         (or (funcall mime-editor/pgp-encrypt-function
+         (or (funcall (pgp-function 'encrypt)
                       recipients (point-min) (point-max) from)
              (throw 'mime-editor/error 'pgp-error)
              )
@@ -1659,7 +1679,7 @@ Content-Transfer-Encoding: 7bit
          )
        (insert "\n")
        (or (as-binary-process
-            (funcall mime-editor/traditional-pgp-sign-function
+            (funcall (pgp-function 'traditional-sign)
                      beg (point-max)))
            (throw 'mime-editor/error 'pgp-error)
            )
@@ -1693,7 +1713,7 @@ Content-Transfer-Encoding: 7bit
            )
          (insert "\n")
          (or (as-binary-process
-              (funcall mime-editor/pgp-encrypt-function
+              (funcall (pgp-function 'encrypt)
                        recipients beg (point-max) nil 'maybe)
               )
              (throw 'mime-editor/error 'pgp-error)
@@ -1770,16 +1790,17 @@ Content-Transfer-Encoding: 7bit
             (tag (buffer-substring beg end))
             )
        (delete-region beg end)
-       (setq contype (mime-editor/get-contype tag))
-       (setq encoding (mime-editor/get-encoding tag))
-       (insert (concat prefix "--" boundary "\n"))
-       (save-restriction
-         (narrow-to-region (point)(point))
-         (insert "Content-Type: " contype "\n")
-         (if encoding
-             (insert "Content-Transfer-Encoding: " encoding "\n"))
-         (mime/encode-message-header)
-         )
+       (let ((contype (mime-editor/get-contype tag))
+             (encoding (mime-editor/get-encoding tag))
+             )
+         (insert (concat prefix "--" boundary "\n"))
+         (save-restriction
+           (narrow-to-region (point)(point))
+           (insert "Content-Type: " contype "\n")
+           (if encoding
+               (insert "Content-Transfer-Encoding: " encoding "\n"))
+           (eword-encode-header)
+           ))
        t)))
 
 (defun mime-editor/translate-region (beg end &optional boundary multipart)
@@ -1916,7 +1937,8 @@ Content-Transfer-Encoding: 7bit
                   )
              (encode-mime-charset-region beg (mime-editor/content-end)
                                          charset)
-             (mime-encode-region beg (mime-editor/content-end) encoding)
+             (if encoding
+                 (mime-encode-region beg (mime-editor/content-end) encoding))
              (mime-editor/define-encoding encoding)
              ))
        (goto-char (mime-editor/content-end))
@@ -2074,7 +2096,7 @@ and insert data encoded as ENCODING. [tm-edit.el]"
   (interactive "P")
   (mime-editor/insert-tag "application" "pgp-keys")
   (mime-editor/define-encoding "7bit")
-  (funcall mime-editor/pgp-insert-public-key-function)
+  (funcall (pgp-function 'insert-key))
   )
 
 
@@ -2444,7 +2466,10 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
              (setq type ctype)
              )
            (cond
-            ((string-equal type "multipart")
+            ((string= ctype "application/pgp-signature")
+             (delete-region (point-min)(point-max))
+             )
+            ((string= type "multipart")
              (let* ((boundary (assoc-value "boundary" params))
                     (boundary-pat
                      (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))