tm 7.59.
[elisp/tm.git] / tm-edit.el
index df0383f..be28d3e 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.56 $
+;;; Version: $Revision: 7.59 $
 ;;; 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.56 1996/05/05 16:40:31 morioka Exp $")
+  "$Id: tm-edit.el,v 7.59 1996/05/09 18:40:11 morioka Exp $")
 
 (defconst mime-editor/version (get-version-string mime-editor/RCS-ID))
 
@@ -607,7 +607,7 @@ Tspecials means any character that matches with it in header must be quoted.")
          (reverse mime-editor/menu-list)
          ))
 
-;;; modified by Pekka Marjola <pema@niksula.hut.fi>
+;;; modified by Pekka Marjola <pema@iki.fi>
 ;;;    1995/9/5 (c.f. [tm-en:69])
 (defun mime-editor/define-menu-for-xemacs ()
   "Define menu for Emacs 19."
@@ -776,11 +776,9 @@ User customizable variables (not documented all of them):
     
     ;; Define menu.  Menus for other emacs implementations are
     ;; welcome.
-    ;; modified by Pekka Marjola <pema@niksula.hut.fi>
-    ;;         1995/9/5 (c.f. [tm-eng:69])
     (cond (running-xemacs
           (mime-editor/define-menu-for-xemacs))
-         ((string-match "^19\\." emacs-version)
+         ((>= emacs-major-version 19)
           (mime-editor/define-menu-for-emacs19)
           ))
     ;; end
@@ -1938,77 +1936,82 @@ Content-Transfer-Encoding: 7bit
       ;; Remove extra whitespaces after the tag.
       (if (looking-at "[ \t]+$")
          (delete-region (match-beginning 0) (match-end 0)))
-      (cond ((= (following-char) ?\^M)
-            ;; It must be image, audio or video.
-            (let ((beg (point))
-                  (end (mime-editor/content-end)))
-              ;; Insert explicit MIME tags after hidden messages.
-              (forward-line 1)
-              (if (and (not (eobp))
-                       (not (looking-at mime-editor/single-part-tag-regexp)))
-                  (progn
-                    (insert (mime-make-text-tag) "\n")
-                    (forward-line -1)  ;Process it again as text.
+      (cond
+       ((= (following-char) ?\^M)
+       ;; It must be image, audio or video.
+       (let ((beg (point))
+             (end (mime-editor/content-end)))
+         ;; Insert explicit MIME tags after hidden messages.
+         (forward-line 1)
+         (if (and (not (eobp))
+                  (not (looking-at mime-editor/single-part-tag-regexp)))
+             (progn
+               (insert (mime-make-text-tag) "\n")
+               (forward-line -1)       ;Process it again as text.
+               ))
+         ;; Show a hidden message.  The point is not altered
+         ;; after the conversion.
+         (mime-flag-region beg end ?\n)
+         ))
+       ((mime-test-content-type contype "message")
+       ;; Content-type "message" should be sent as is.
+       (forward-line 1)
+       )
+       ((mime-test-content-type contype "text")
+       ;; Define charset for text if necessary.
+       (setq charset (or charset (mime-editor/choose-charset)))
+       (mime-editor/define-charset charset)
+       (cond ((string-equal contype "text/x-rot13-47")
+              (save-excursion
+                (forward-line)
+                (set-mark (point))
+                (goto-char (mime-editor/content-end))
+                (tm:caesar-region)
+                ))
+             ((string-equal contype "text/enriched")
+              (save-excursion
+                (let ((beg (progn
+                             (forward-line)
+                             (point)))
+                      (end (mime-editor/content-end))
+                      )
+                  (enriched-encode beg end)
+                  (goto-char beg)
+                  (if (search-forward "\n\n")
+                      (delete-region beg (match-end 0))
+                    )
+                  ))))
+       ;; Point is now on current tag.
+       ;; Define encoding and encode text if necessary.
+       (or encoding    ;Encoding is not specified.
+           (let* ((encoding
+                   (cdr
+                    (assoc charset
+                           mime-editor/charset-default-encoding-alist)
                     ))
-              ;; Show a hidden message.  The point is not altered
-              ;; after the conversion.
-              (mime-flag-region beg end ?\n)))
-           ((mime-test-content-type contype "message")
-            ;; Content-type "message" should be sent as is.
-            (forward-line 1))
-           ((mime-test-content-type contype "text")
-            ;; Define charset for text if necessary.
-            (setq charset (or charset (mime-editor/choose-charset)))
-            (mime-editor/define-charset charset)
-            (cond ((string-equal contype "text/x-rot13-47")
-                   (save-excursion
-                     (forward-line)
-                     (set-mark (point))
-                     (goto-char (mime-editor/content-end))
-                     (tm:caesar-region)
-                     ))
-                  ((string-equal contype "text/enriched")
-                   (save-excursion
-                     (let ((beg (progn
-                                  (forward-line)
-                                  (point)))
-                           (end (mime-editor/content-end))
-                           )
-                       (enriched-encode beg end)
-                       (goto-char beg)
-                       (if (search-forward "\n\n")
-                           (delete-region beg (match-end 0))
-                         )
-                       ))))
-            ;; Point is now on current tag.
-            ;; Define encoding and encode text if necessary.
-            (if (null encoding)        ;Encoding is not specified.
-                (let* ((encoding
-                        (cdr
-                         (assoc charset
-                                mime-editor/charset-default-encoding-alist)
-                         ))
-                       (beg (mime-editor/content-beginning))
-                       )
-                  (mime/code-convert-region-from-emacs
-                   beg (mime-editor/content-end) charset)
-                  (mime-encode-region encoding
-                                      beg (mime-editor/content-end))
-                   (mime-editor/define-encoding encoding)))
-            (forward-line 1))
-           ((null encoding)            ;Encoding is not specified.
-            ;; Application, image, audio, video, and any other
-            ;; unknown content-type without encoding should be
-            ;; encoded.
-            (let* ((encoding "base64") ;Encode in BASE64 by default.
-                   (beg (mime-editor/content-beginning))
-                   (end (mime-editor/content-end))
-                   (body (buffer-substring beg end))
-                    )
-              (mime-encode-region encoding beg end)
-               (mime-editor/define-encoding encoding))
-            (forward-line 1))
-           )
+                  (beg (mime-editor/content-beginning))
+                  )
+             (mime-charset-encode-region beg (mime-editor/content-end)
+                                         charset)
+             (mime-encode-region encoding beg (mime-editor/content-end))
+             (mime-editor/define-encoding encoding)
+             ))
+       (forward-line 1)
+       )
+       ((null encoding)                ;Encoding is not specified.
+       ;; Application, image, audio, video, and any other
+       ;; unknown content-type without encoding should be
+       ;; encoded.
+       (let* ((encoding "base64")      ;Encode in BASE64 by default.
+              (beg (mime-editor/content-beginning))
+              (end (mime-editor/content-end))
+              (body (buffer-substring beg end))
+              )
+         (mime-encode-region encoding beg end)
+         (mime-editor/define-encoding encoding))
+       (forward-line 1)
+       )
+       )
       )))
 
 (defun mime-delete-field (field)
@@ -2579,94 +2582,94 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n"
                  )
              (setq type ctype)
              )
-           (cond ((string-equal type "multipart")
-                  (let ((boundary (assoc-value "boundary" params)))
-                    (re-search-forward (concat "\n--" boundary) nil t)
-                    (let ((bb (match-beginning 0)) eb tag)
-                      (setq tag (format "\n--<<%s>>-{" stype))
-                      (goto-char bb)
-                      (insert tag)
-                      (setq bb (+ bb (length tag)))
-                      (re-search-forward (concat "\n--" boundary "--") nil t)
-                      (setq eb (match-beginning 0))
-                      (replace-match (format "\n--}-<<%s>>" stype))
-                      (save-restriction
-                        (narrow-to-region bb eb)
-                        (goto-char (point-min))
-                        (while (re-search-forward
-                                (concat "\n--" boundary "\n") nil t)
-                          (let ((beg (match-beginning 0))
-                                end)
-                            (delete-region beg (match-end 0))
-                            (save-excursion
-                              (if (re-search-forward
-                                   (concat "\n--" boundary) nil t)
-                                  (setq end (match-beginning 0))
-                                (setq end (point-max))
-                                )
-                              (save-restriction
-                                (narrow-to-region beg end)
-                                (mime-editor::edit-again code-conversion)
-                                (goto-char (point-max))
-                                ))))
-                        ))
-                    (goto-char (point-min))
-                    (or (= (point-min) 1)
-                        (delete-region (point-min)
-                                       (if (re-search-forward "^$" nil t)
-                                           (match-end 0)
-                                         (point-min)
-                                         )))
-                    ))
-                 (t
-                  (let* ((str (rfc822/get-header-string-except
-                               "^Content-Type" ""))
-                         charset
-                         (pstr
-                          (mapconcat (function
-                                      (lambda (attr)
-                                        (if (string-equal (car attr)
-                                                          "charset")
-                                            (progn
-                                              (setq charset (cdr attr))
-                                              "")
-                                          (concat ";" (car attr)
-                                                  "=" (cdr attr))
-                                          )
-                                        ))
-                                     params ""))
-                         )
-                    (if code-conversion
-                        (if charset
-                            (mime/code-convert-region-to-emacs
-                             (point-min) (point-max) charset)
-                          (decode-coding-region
-                           (point-min) (point-max)
-                           mime/default-coding-system)
-                          ))
-                    (and str
-                         (setq pstr (concat pstr "\n" str))
-                         )
-                    (let ((he
-                           (if (re-search-forward "^$" nil t)
-                               (match-end 0)
-                             (point-min)
-                             )))
-                      (if (= (point-min) 1)
-                          (progn
-                            (goto-char he)
-                            (insert
-                             (concat
-                              "\n"
-                              (mime-create-tag (concat type "/" stype))
-                              ))
-                            )
-                        (delete-region (point-min) he)
-                        (insert
-                         (concat "\n" (mime-create-tag
-                                       (concat type "/" stype pstr))))
-                        ))
-                    ))))
+           (cond
+            ((string-equal type "multipart")
+             (let ((boundary (assoc-value "boundary" params)))
+               (re-search-forward (concat "\n--" boundary) nil t)
+               (let ((bb (match-beginning 0)) eb tag)
+                 (setq tag (format "\n--<<%s>>-{" stype))
+                 (goto-char bb)
+                 (insert tag)
+                 (setq bb (+ bb (length tag)))
+                 (re-search-forward (concat "\n--" boundary "--") nil t)
+                 (setq eb (match-beginning 0))
+                 (replace-match (format "\n--}-<<%s>>" stype))
+                 (save-restriction
+                   (narrow-to-region bb eb)
+                   (goto-char (point-min))
+                   (while (re-search-forward
+                           (concat "\n--" boundary "\n") nil t)
+                     (let ((beg (match-beginning 0))
+                           end)
+                       (delete-region beg (match-end 0))
+                       (save-excursion
+                         (if (re-search-forward
+                              (concat "\n--" boundary) nil t)
+                             (setq end (match-beginning 0))
+                           (setq end (point-max))
+                           )
+                         (save-restriction
+                           (narrow-to-region beg end)
+                           (mime-editor::edit-again code-conversion)
+                           (goto-char (point-max))
+                           ))))
+                   ))
+               (goto-char (point-min))
+               (or (= (point-min) 1)
+                   (delete-region (point-min)
+                                  (if (re-search-forward "^$" nil t)
+                                      (match-end 0)
+                                    (point-min)
+                                    )))
+               ))
+            (t
+             (let* ((str (rfc822/get-header-string-except
+                          "^Content-Type" ""))
+                    charset
+                    (pstr
+                     (mapconcat (function
+                                 (lambda (attr)
+                                   (if (string-equal (car attr)
+                                                     "charset")
+                                       (progn
+                                         (setq charset (cdr attr))
+                                         "")
+                                     (concat ";" (car attr)
+                                             "=" (cdr attr))
+                                     )
+                                   ))
+                                params ""))
+                    )
+               (if code-conversion
+                   (if charset
+                       (mime-charset-decode-region (point-min)(point-max)
+                                                   charset)
+                     (character-decode-region (point-min)(point-max)
+                                              mime/default-coding-system)
+                     ))
+               (and str
+                    (setq pstr (concat pstr "\n" str))
+                    )
+               (let ((he
+                      (if (re-search-forward "^$" nil t)
+                          (match-end 0)
+                        (point-min)
+                        )))
+                 (if (= (point-min) 1)
+                     (progn
+                       (goto-char he)
+                       (insert
+                        (concat
+                         "\n"
+                         (mime-create-tag (concat type "/" stype))
+                         ))
+                       )
+                   (delete-region (point-min) he)
+                   (insert
+                    (concat "\n" (mime-create-tag
+                                  (concat type "/" stype pstr))))
+                   ))
+               ))))
        (if code-conversion
            (decode-coding-region (point-min) (point-max)
                                  mime/default-coding-system)