updated.
[elisp/semi.git] / mime-edit.el
index 024b5a3..17e1088 100644 (file)
@@ -7,7 +7,7 @@
 ;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
 ;; Created: 1994/08/21 renamed from mime.el
 ;;     Renamed: 1997/2/21 from tm-edit.el
-;; Version: $Revision: 0.73 $
+;; Version: $Revision: 0.86 $
 ;; Keywords: MIME, multimedia, multilingual, mail, news
 
 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
 ;;;
 
 (defconst mime-edit-RCS-ID
-  "$Id: mime-edit.el,v 0.73 1997-03-15 20:36:32 morioka Exp $")
+  "$Id: mime-edit.el,v 0.86 1997-07-24 15:59:25 morioka Exp $")
 
-(defconst mime-edit-version (get-version-string mime-edit-RCS-ID))
+(defconst mime-edit-version `,(get-version-string mime-edit-RCS-ID))
 
 (defconst mime-edit-version-name
-  (concat "SEMI MIME-Edit " mime-edit-version))
+  `,(concat "SEMI MIME-Edit " mime-edit-version
+           " \"" semi-version-name "\""))
 
 
 ;;; @ variables
@@ -148,7 +149,7 @@ If non-nil, the text tag is not inserted unless something different.")
 
 (defvar mime-edit-voice-recorder
   (function mime-edit-voice-recorder-for-sun)
-  "*Function to record a voice message and encode it. [mime-edit.el]")
+  "*Function to record a voice message and encode it.")
 
 (defvar mime-edit-mode-hook nil
   "*Hook called when enter MIME mode.")
@@ -180,7 +181,7 @@ To insert a signature file automatically, call the function
      ("html"
       ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8")
       )
-     ("x-rot13-47")
+     ("x-rot13-47-48")
      )
     ("message"
      ("external-body"
@@ -209,6 +210,7 @@ To insert a signature file automatically, call the function
     ("image"
      ("gif")
      ("jpeg")
+     ("png")
      ("tiff")
      ("x-pic")
      ("x-mag")
@@ -244,6 +246,11 @@ To insert a signature file automatically, call the function
      "base64"
      "inline"          (("filename" . file))
      )
+    ("\\.png$"
+     "image"   "png"           nil
+     "base64"
+     "inline"          (("filename" . file))
+     )
     ("\\.tiff$"
      "image"   "tiff"          nil
      "base64"
@@ -417,7 +424,7 @@ If encoding is nil, it is determined from its contents.")
     "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. [mime-edit.el]")
+Each elements are regexp of field-name.")
 
 (defvar mime-edit-yank-ignored-field-regexp
   (concat "^"
@@ -432,16 +439,16 @@ Each elements are regexp of field-name. [mime-edit.el]")
 ;;;
 
 (defvar mime-edit-split-message t
-  "*Split large message if it is non-nil. [mime-edit.el]")
+  "*Split large message if it is non-nil.")
 
 (defvar mime-edit-message-default-max-lines 1000
-  "*Default maximum lines of a message. [mime-edit.el]")
+  "*Default maximum lines of a message.")
 
 (defvar mime-edit-message-max-lines-alist
   '((news-reply-mode . 500))
   "Alist of major-mode vs maximum lines of a message.
 If it is not specified for a major-mode,
-`mime-edit-message-default-max-lines' is used. [mime-edit.el]")
+`mime-edit-message-default-max-lines' is used.")
 
 (defconst mime-edit-split-ignored-field-regexp
   "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)")
@@ -458,10 +465,10 @@ If it is not specified for a major-mode,
 ;;;
 
 (defvar mime-edit-signing-type 'pgp-elkins
-  "*PGP signing type (pgp-elkins, pgp-kazu or nil). [mime-edit.el]")
+  "*PGP signing type (pgp-elkins, pgp-kazu or nil).")
 
 (defvar mime-edit-encrypting-type 'pgp-elkins
-  "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [mime-edit.el]")
+  "*PGP encrypting type (pgp-elkins, pgp-kazu or nil).")
 
 
 ;;; @@ about tag
@@ -1193,26 +1200,25 @@ Optional argument ENCODING specifies an encoding method such as base64."
 (defun mime-edit-content-end ()
   "Return the point of the end of content."
   (save-excursion
-    (let ((beg (point)))
-      (if (mime-edit-goto-tag)
-         (let ((top (point)))
-           (goto-char (match-end 0))
-           (if (invisible-p (point))
-               (next-visible-point (point))
-             ;; Move to the end of this text.
-             (if (re-search-forward mime-edit-tag-regexp nil 'move)
-                 ;; Don't forget a multiline tag.
-                 (goto-char (match-beginning 0))
-               )
-             (point)
-             ))
-       ;; Assume the message begins with text/plain.
-       (goto-char (mime-edit-content-beginning))
-       (if (re-search-forward mime-edit-tag-regexp nil 'move)
-           ;; Don't forget a multiline tag.
-           (goto-char (match-beginning 0)))
-       (point))
-      )))
+    (if (mime-edit-goto-tag)
+       (progn
+         (goto-char (match-end 0))
+         (if (invisible-p (point))
+             (next-visible-point (point))
+           ;; Move to the end of this text.
+           (if (re-search-forward mime-edit-tag-regexp nil 'move)
+               ;; Don't forget a multiline tag.
+               (goto-char (match-beginning 0))
+             )
+           (point)
+           ))
+      ;; Assume the message begins with text/plain.
+      (goto-char (mime-edit-content-beginning))
+      (if (re-search-forward mime-edit-tag-regexp nil 'move)
+         ;; Don't forget a multiline tag.
+         (goto-char (match-beginning 0)))
+      (point))
+    ))
 
 (defun mime-edit-define-charset (charset)
   "Set charset of current tag to CHARSET."
@@ -1444,7 +1450,7 @@ Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
     ))
 
 (defun mime-prompt-for-encoding (default)
-  "Ask for Content-Transfer-Encoding. [mime-edit.el]"
+  "Ask for Content-Transfer-Encoding."
   (let (encoding)
     (while (string=
            (setq encoding
@@ -1600,8 +1606,9 @@ Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))."
            (insert (format "Content-Transfer-Encoding: %s\n" encoding))
          )
        (insert "\n")
-       (or (funcall (pgp-function 'mime-sign)
-                    (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-edit-error 'pgp-error)
            )
        ))))
@@ -1822,22 +1829,24 @@ Content-Transfer-Encoding: 7bit
        ))))
 
 (defun mime-edit-translate-single-part-tag (&optional prefix)
+  "Translate single-part-tag to MIME header."
   (if (re-search-forward mime-edit-single-part-tag-regexp nil t)
       (let* ((beg (match-beginning 0))
             (end (match-end 0))
             (tag (buffer-substring beg end))
             )
        (delete-region beg end)
-       (setq contype (mime-edit-get-contype tag))
-       (setq encoding (mime-edit-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)
-         )
+       (let ((contype (mime-edit-get-contype tag))
+             (encoding (mime-edit-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-edit-translate-region (beg end &optional boundary multipart)
@@ -1932,12 +1941,10 @@ Content-Transfer-Encoding: 7bit
                          (intern (downcase charset))
                        (mime-edit-choose-charset)))
        (mime-edit-define-charset charset)
-       (cond ((string-equal contype "text/x-rot13-47")
+       (cond ((string-equal contype "text/x-rot13-47-48")
               (save-excursion
                 (forward-line)
-                (set-mark (point))
-                (goto-char (mime-edit-content-end))
-                (tm:caesar-region)
+                (mule-caesar-region (point) (mime-edit-content-end))
                 ))
              ((string-equal contype "text/enriched")
               (save-excursion
@@ -1972,6 +1979,33 @@ Content-Transfer-Encoding: 7bit
                   )
              (encode-mime-charset-region beg (mime-edit-content-end)
                                          charset)
+             ;; Protect "From " in beginning of line
+             (save-restriction
+               (narrow-to-region beg (mime-edit-content-end))
+               (goto-char beg)
+               (if (re-search-forward "^From " nil t)
+                   (unless encoding
+                     (if (memq charset '(iso-2022-jp
+                                         iso-2022-jp-2
+                                         iso-2022-int-1
+                                         x-ctext))
+                         (while (progn
+                                  (replace-match "\e(BFrom ")
+                                  (re-search-forward "^From " nil t)
+                                  ))
+                       (setq encoding "quoted-printable")
+                       ))))
+             ;; canonicalize line break code
+             (or (member encoding '(nil "7bit" "8bit" "quoted-printable"))
+                 (save-restriction
+                   (narrow-to-region beg (mime-edit-content-end))
+                   (goto-char beg)
+                   (while (re-search-forward "\\([^\r]\\)\n" nil t)
+                     (replace-match
+                      (concat (buffer-substring (match-beginning 0)
+                                                (match-end 1)) "\r\n"))
+                     )))
+             (goto-char beg)
              (mime-encode-region beg (mime-edit-content-end) encoding)
              (mime-edit-define-encoding encoding)
              ))
@@ -2010,7 +2044,7 @@ Content-Transfer-Encoding: 7bit
 
 (defun mime-edit-voice-recorder-for-sun (encoding)
   "Record voice in a buffer using Sun audio device,
-and insert data encoded as ENCODING. [mime-edit.el]"
+and insert data encoded as ENCODING."
   (message "Start the recording on %s.  Type C-g to finish the recording..."
           (system-name))
   (mime-insert-encoded-file "/dev/audio" encoding)
@@ -2375,7 +2409,7 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
 (defvar mime-edit-buffer nil) ; buffer local variable
 
 (defun mime-edit-preview-message ()
-  "preview editing MIME message. [mime-edit.el]"
+  "preview editing MIME message."
   (interactive)
   (let* ((str (buffer-string))
         (separator mail-header-separator)
@@ -2410,7 +2444,8 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
     ))
 
 (defun mime-edit-quitting-method ()
-  (let ((temp mime::preview/article-buffer)
+  "Quitting method for mime-view."
+  (let ((temp mime-raw-buffer)
        buf)
     (mime-view-kill-buffer)
     (set-buffer temp)