Importing Gnus v5.8.7.
[elisp/gnus.git-] / lisp / mm-uu.el
index c08d009..61cae2d 100644 (file)
@@ -1,10 +1,10 @@
 ;;; mm-uu.el -- Return uu stuffs as mm handles
-;; Copyright (c) 1998,99 by Shenghuo Zhu
+;; Copyright (c) 1998, 1999, 2000 Free Software Foundation, Inc.
 
 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
-;; Keywords: postscript uudecode binhex shar forward
+;; Keywords: postscript uudecode binhex shar forward news
 
-;; This file is part of pgnus.
+;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -26,8 +26,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl))
 (require 'mail-parse)
-(require 'message)
 (require 'nnheader)
 (require 'mm-decode)
 (require 'mailcap)
@@ -131,31 +131,19 @@ To disable dissecting shar codes, for instance, add
 
 (defun mm-uu-dissect ()
   "Dissect the current buffer and return a list of uu handles."
-  (let (ct ctl cte charset text-start start-char end-char
-          type file-name end-line result text-plain-type 
-          start-char-1 end-char-1
-          (case-fold-search t))
+  (let (text-start start-char end-char
+                  type file-name end-line result text-plain-type 
+                  start-char-1 end-char-1
+                  (case-fold-search t))
     (save-excursion
       (save-restriction
        (mail-narrow-to-head)
-       (when (and (mail-fetch-field "mime-version")
-                  (setq ct (mail-fetch-field "content-type")))
-         (setq cte (message-fetch-field "content-transfer-encoding" t)
-               ctl (ignore-errors (mail-header-parse-content-type ct))
-               charset (and ctl (mail-content-type-get ctl 'charset)))
-         (if (stringp cte)
-             (setq cte (intern (downcase (mail-header-remove-whitespace
-                                          (mail-header-remove-comments
-                                           cte))))))
-         (if (memq cte '(base64 quoted-printable))
-             (setq charset 'gnus-encoded ;; a fake charset
-                   cte nil)))
        (goto-char (point-max)))
       (forward-line)
+      ;;; gnus-decoded is a fake charset, which means no further
+      ;;; decoding.
       (setq text-start (point)
-           text-plain-type (cons "text/plain"
-                                 (if charset
-                                     (list (cons 'charset charset)))))
+           text-plain-type '("text/plain"  (charset . gnus-decoded)))
       (while (re-search-forward mm-uu-begin-line nil t)
        (setq start-char (match-beginning 0))
        (setq type (cdr (assq (aref (match-string 0) 0)
@@ -167,67 +155,71 @@ To disable dissecting shar codes, for instance, add
                       (let ((nnheader-file-name-translation-alist
                              '((?/ . ?,) (? . ?_) (?* . ?_) (?$ . ?_))))
                         (nnheader-translate-file-chars (match-string 1))))))
-       (forward-line) ;; in case of failure
+       (forward-line);; in case of failure
        (setq start-char-1 (point))
        (setq end-line (symbol-value
                        (intern (concat "mm-uu-" (symbol-name type)
                                        "-end-line"))))
        (when (and (re-search-forward end-line nil t)
-                  (not (eq (match-beginning 0) (match-end 0)))
-                  ;; Do not dissect base64 forward. 
-                  (not (and (eq charset 'gnus-encoded) (eq type 'forward))))
+                  (not (eq (match-beginning 0) (match-end 0))))
          (setq end-char-1 (match-beginning 0))
          (forward-line)
          (setq end-char (point))
-         (when (or (not (eq type 'binhex))
-                   (setq file-name
-                         (ignore-errors
-                           (binhex-decode-region start-char end-char t))))
+         (when (cond 
+                ((eq type 'binhex)
+                 (setq file-name
+                       (ignore-errors
+                         (binhex-decode-region start-char end-char t))))
+                ((eq type 'forward)
+                 (save-excursion
+                   (goto-char start-char-1)
+                   (looking-at "[\r\n]*[a-zA-Z][a-zA-Z0-9-]*:")))
+                (t t))
            (if (> start-char text-start)
                (push
                 (mm-make-handle (mm-uu-copy-to-buffer text-start start-char)
-                      text-plain-type cte)
+                                text-plain-type)
                 result))
            (push
             (cond
              ((eq type 'postscript)
               (mm-make-handle (mm-uu-copy-to-buffer start-char end-char)
-                    '("application/postscript")))
+                              '("application/postscript")))
              ((eq type 'forward)
               (mm-make-handle (mm-uu-copy-to-buffer start-char-1 end-char-1)
-                    '("message/rfc822")))
+                              '("message/rfc822" (charset . gnus-decoded))))
              ((eq type 'uu)
               (mm-make-handle (mm-uu-copy-to-buffer start-char end-char)
-                    (list (or (and file-name
-                                   (string-match "\\.[^\\.]+$" file-name)
-                                   (mailcap-extension-to-mime
-                                    (match-string 0 file-name)))
-                              "application/octet-stream"))
-                    'x-uuencode nil
-                    (if (and file-name (not (equal file-name "")))
-                        (list mm-dissect-disposition
-                              (cons 'filename file-name)))))
+                              (list (or (and file-name
+                                             (string-match "\\.[^\\.]+$" file-name)
+                                             (mailcap-extension-to-mime
+                                              (match-string 0 file-name)))
+                                        "application/octet-stream"))
+                              'x-uuencode nil
+                              (if (and file-name (not (equal file-name "")))
+                                  (list mm-dissect-disposition
+                                        (cons 'filename file-name)))))
              ((eq type 'binhex)
               (mm-make-handle (mm-uu-copy-to-buffer start-char end-char)
-                    (list (or (and file-name
-                                   (string-match "\\.[^\\.]+$" file-name)
-                                   (mailcap-extension-to-mime
-                                    (match-string 0 file-name)))
-                              "application/octet-stream"))
-                    'x-binhex nil
-                    (if (and file-name (not (equal file-name "")))
-                        (list mm-dissect-disposition
-                              (cons 'filename file-name)))))
+                              (list (or (and file-name
+                                             (string-match "\\.[^\\.]+$" file-name)
+                                             (mailcap-extension-to-mime
+                                              (match-string 0 file-name)))
+                                        "application/octet-stream"))
+                              'x-binhex nil
+                              (if (and file-name (not (equal file-name "")))
+                                  (list mm-dissect-disposition
+                                        (cons 'filename file-name)))))
              ((eq type 'shar)
               (mm-make-handle (mm-uu-copy-to-buffer start-char end-char)
-                    '("application/x-shar"))))
+                              '("application/x-shar"))))
             result)
            (setq text-start end-char))))
       (when result
        (if (> (point-max) (1+ text-start))
            (push
             (mm-make-handle (mm-uu-copy-to-buffer text-start (point-max))
-                  text-plain-type cte)
+                            text-plain-type)
             result))
        (setq result (cons "multipart/mixed" (nreverse result))))
       result)))
@@ -236,10 +228,7 @@ To disable dissecting shar codes, for instance, add
 (defun mm-uu-test ()
   "Check whether the current buffer contains uu stuffs."
   (save-excursion
-    (save-restriction
-      (mail-narrow-to-head)
-      (goto-char (point-max)))
-    (forward-line)
+    (goto-char (point-min))
     (let (type end-line result
               (case-fold-search t))
       (while (and mm-uu-begin-line