This commit was generated by cvs2svn to compensate for changes in r491,
[elisp/tm.git] / tm-comp.el
index 1ae12f0..8ff815c 100644 (file)
@@ -1,19 +1,24 @@
 ;;;
-;;; tm-comp.el: attachment for MIME composer
+;;; tm-comp.el --- attachment for MIME composer
 ;;;
-;;; by  MORIOKA Tomohiko <morioka@jaist.ac.jp>
-;;; and   OKABE Yasuo    <okabe@kudpc.kyoto-u.ac.jp>
-;;; modified by MORITA Masahiro <hiro@isl.ntt.JP>
-;;;             MORIOKA Tomohiko,
-;;;      Kazushi (Jam) MARUKAWA <kazusi-m@is.aist-nara.ac.jp>,
-;;;             OKABE Yasuo,
-;;;            KOBAYASHI Shuhei <shuhei@cmpt01.phys.tohoku.ac.jp>,
-;;;         and YAMAOKA Katsumi <yamaoka@ga.sony.co.jp>
+;;; Copyright (C) 1995 Free Software Foundation, Inc.
+;;; Copyright (C) 1994,1995 MORIOKA Tomohiko
+;;; Copyright (C) 1994,1995 OKABE Yasuo
+;;;
+;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>,
+;;;         OKABE Yasuo      <okabe@kudpc.kyoto-u.ac.jp>
+;;;    modified by MORITA Masahiro <hiro@isl.ntt.JP>
+;;;                 Kazushi (Jam) MARUKAWA <kazusi-m@is.aist-nara.ac.jp>,
+;;;                 KOBAYASHI Shuhei <shuhei@cmpt01.phys.tohoku.ac.jp>,
+;;;                 YAMAOKA Katsumi <yamaoka@ga.sony.co.jp>,
+;;;             and Richard Stanton <stanton@haas.berkeley.edu>
+;;; Keywords: mail, news, MIME, multimedia
+;;;
+;;; This file is part of tm (Tools for MIME).
 ;;;
 
-(require 'tm-misc)
 (require 'tm-view)
-(require 'tl-header)
+(require 'tl-822)
 (require 'tl-list)
 (require 'mail-utils)
 
@@ -22,7 +27,7 @@
 ;;;
 
 (defconst mime/composer-RCS-ID
-  "$Id: tm-comp.el,v 6.8 1995/08/30 00:40:26 morioka Exp $")
+  "$Id: tm-comp.el,v 7.2 1995/10/08 09:31:05 morioka Exp $")
 
 (defconst mime/composer-version (get-version-string mime/composer-RCS-ID))
 
@@ -36,9 +41,8 @@
   '((news-reply-mode . 500)))
 
 (defconst mime/message-nuke-headers
-  "\\(^[Cc]ontent-\\|^[Ss]ubject:\\|^[Mm][Ii][Mm][Ee]-[Vv]ersion:\\)")
-(defvar mime/message-blind-headers
-  "\\(^[BDFbdf][Cc][Cc]:\\|^[Cc][Cc]:[ \t]*$\\)")
+  "\\(^Content-\\|^Subject:\\|^MIME-Version:\\)")
+(defvar mime/message-blind-headers "\\(^[BDFbdf]cc:\\|^cc:[ \t]*$\\)")
 
 (defvar mime/message-default-sender-alist
   '((mail-mode . mail-send-and-exit)
 ;;; @ edit
 ;;;
 
+(defun tm-comp::mime-insert-file (file)
+  "Insert a message from a file."
+  (interactive "fInsert file as MIME message: ")
+  (let*  ((guess (mime-find-file-type file))
+         (pritype (nth 0 guess))
+         (subtype (nth 1 guess))
+         (parameters (nth 2 guess))
+         (default (nth 3 guess))       ;Guess encoding from its file name.
+         (encoding
+          (if (not (interactive-p))
+              default
+            (completing-read
+             (concat "What transfer encoding"
+                     (if default
+                         (concat " (default "
+                                 (if (string-equal default "") "\"\"" default)
+                                 ")"
+                                 ))
+                     ": ")
+             mime-transfer-encoders nil t nil))))
+    (if (string-equal encoding "")
+       (setq encoding default))
+    (if (consp parameters)
+       (let ((rest parameters) cell attribute value)
+         (setq parameters "")
+         (while rest
+           (setq cell (car rest))
+           (setq attribute (car cell))
+           (setq value (cdr cell))
+           (if (eq value 'file)
+               (setq value (file-name-nondirectory file))
+             )
+           (setq parameters (concat parameters "; " attribute "=" value))
+           (setq rest (cdr rest))
+           )))
+    (mime-insert-tag pritype subtype parameters)
+    (mime-insert-binary-file file encoding)
+    ))
+
 ;; Insert the binary content after MIME tag.
 ;;     modified by MORITA Masahiro <hiro@isl.ntt.JP>
 ;;     for x-uue
@@ -128,7 +171,9 @@ Optional argument ENCODING specifies an encoding method such as base64."
       (let ((mc-flag nil)              ;Mule
            (file-coding-system-for-read
             (if (featurep 'mule) *noconv*))
-           (kanji-flag nil))           ;NEmacs
+           (kanji-flag nil)            ;NEmacs
+           (emx-binary-mode t)         ;Stop CRLF to LF conversion in OS/2
+           )
        (let (jka-compr-compression-info-list
              jam-zcat-filename-list)
          (insert-file-contents file))))
@@ -159,7 +204,8 @@ Optional argument ENCODING specifies an encoding method such as base64."
         )
     (save-restriction
       (narrow-to-region (1- (point)) (point))
-      (let ((start (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
@@ -214,9 +260,9 @@ Optional argument ENCODING specifies an encoding method such as base64."
        (let ((hook (cdr (assq major-mode
                               mime/message-before-send-hook-alist))))
          (run-hooks hook))
-       (let* ((header (message/get-header-string-except
-                     mime/message-nuke-headers separator))
-              (orig-header (message/get-header-string-except
+       (let* ((header (rfc822/get-header-string-except
+                       mime/message-nuke-headers separator))
+              (orig-header (rfc822/get-header-string-except
                             mime/message-blind-headers separator))
               (subject (mail-fetch-field "subject"))
               (total (+ (/ lines mime/message-max-length)
@@ -304,6 +350,12 @@ Optional argument ENCODING specifies an encoding method such as base64."
 (add-hook 'mime-mode-hook
          (function
           (lambda ()
+            (if (not (fboundp 'original::mime-insert-file))
+                (progn
+                  (fset 'original::mime-insert-file
+                        (symbol-function 'mime-insert-file))
+                  (fset 'mime-insert-file 'tm-comp::mime-insert-file)
+                  ))
             (if (not (fboundp 'original::mime-insert-binary-file))
                 (progn
                   (fset 'original::mime-insert-binary-file
@@ -390,27 +442,28 @@ Optional argument ENCODING specifies an encoding method such as base64."
 ;;; @ etc
 ;;;
 
-(defun message/get-header-string-except (pat boundary)
-  (save-excursion
-    (save-restriction
-      (narrow-to-region (goto-char (point-min))
-                       (progn
-                         (re-search-forward
-                          (concat "^\\(" (regexp-quote boundary) "\\)?$")
-                          nil t)
-                         (match-beginning 0)
-                         ))
-      (goto-char (point-min))
-      (let (field header)
-       (while (re-search-forward message/field-regexp nil t)
-         (setq field (buffer-substring (match-beginning 0)
-                                       (match-end 0)
-                                       ))
-         (if (not (string-match pat field))
-             (setq header (concat header field "\n"))
-           ))
-       header)
-      )))
+(defun rfc822/get-header-string-except (pat boundary)
+  (let ((case-fold-search t))
+    (save-excursion
+      (save-restriction
+       (narrow-to-region (goto-char (point-min))
+                         (progn
+                           (re-search-forward
+                            (concat "^\\(" (regexp-quote boundary) "\\)?$")
+                            nil t)
+                           (match-beginning 0)
+                           ))
+       (goto-char (point-min))
+       (let (field header)
+         (while (re-search-forward rfc822/field-top-regexp nil t)
+           (setq field (buffer-substring (match-beginning 0)
+                                         (rfc822/field-end)
+                                         ))
+           (if (not (string-match pat field))
+               (setq header (concat header field "\n"))
+             ))
+         header)
+       ))))
 
 (defun replace-space-with-underline (str)
   (mapconcat (function
@@ -422,6 +475,9 @@ Optional argument ENCODING specifies an encoding method such as base64."
   )
 
 
-(run-hooks 'tm-comp-load-hook)
+;;; @ end
+;;;
 
 (provide 'tm-comp)
+
+(run-hooks 'tm-comp-load-hook)