Release 2.8.1 (emergency release).
[elisp/wanderlust.git] / elmo / elmo-mime.el
index 74cd30f..46a4881 100644 (file)
@@ -1,4 +1,4 @@
-;;; elmo-mime.el -- MIME module for ELMO.
+;;; elmo-mime.el --- MIME module for ELMO.
 
 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
 
 ;;
 
 ;;; Commentary:
-;; 
+;;
 
 ;;; Code:
-;; 
+;;
 (require 'elmo-vars)
 (require 'mmbuffer)
 (require 'mmimap)
@@ -53,6 +53,12 @@ value is used."
                 (function :tag "Function"))
   :group 'elmo)
 
+(defcustom elmo-mime-display-as-is-coding-system (if (boundp 'MULE)
+                                                    '*autoconv* 'undecided)
+  "*Coding system used when message is displayed as is."
+  :type 'symbol
+  :group 'elmo)
+
 (luna-define-method initialize-instance :after ((entity mime-elmo-buffer-entity)
                                                &rest init-args)
   entity)
@@ -71,7 +77,7 @@ value is used."
        (mode-obj (mime-find-field-presentation-method 'wide))
        field-decoder
        f-b p f-e field-name field field-body
-        vf-alist (sl sort-fields))
+       vf-alist (sl sort-fields))
     (save-excursion
       (set-buffer buffer)
       (save-restriction
@@ -89,42 +95,42 @@ value is used."
                  field-body (buffer-substring p f-e)
                  field-decoder (inline (mime-find-field-decoder-internal
                                         field mode-obj)))
-            (setq vf-alist (append (list
-                                    (cons field-name
-                                          (list field-body field-decoder)))
-                                   vf-alist))))
-        (and vf-alist
-             (setq vf-alist
-                   (sort vf-alist
-                         (function (lambda (s d)
-                                     (let ((n 0) re
-                                           (sf (car s))
-                                           (df (car d)))
-                                       (catch 'done
-                                         (while (setq re (nth n sl))
-                                           (setq n (1+ n))
-                                           (and (string-match re sf)
-                                                (throw 'done t))
-                                           (and (string-match re df)
-                                                (throw 'done nil)))
-                                         t)))))))
-        (with-current-buffer the-buf
-          (while vf-alist
-            (let* ((vf (car vf-alist))
-                   (field-name (car vf))
-                   (field-body (car (cdr vf)))
-                   (field-decoder (car (cdr (cdr vf)))))
-              (insert field-name)
+           (setq vf-alist (append (list
+                                   (cons field-name
+                                         (list field-body field-decoder)))
+                                  vf-alist))))
+       (and vf-alist
+            (setq vf-alist
+                  (sort vf-alist
+                        (function (lambda (s d)
+                                    (let ((n 0) re
+                                          (sf (car s))
+                                          (df (car d)))
+                                      (catch 'done
+                                        (while (setq re (nth n sl))
+                                          (setq n (1+ n))
+                                          (and (string-match re sf)
+                                               (throw 'done t))
+                                          (and (string-match re df)
+                                               (throw 'done nil)))
+                                        t)))))))
+       (with-current-buffer the-buf
+         (while vf-alist
+           (let* ((vf (car vf-alist))
+                  (field-name (car vf))
+                  (field-body (car (cdr vf)))
+                  (field-decoder (car (cdr (cdr vf)))))
+             (insert field-name)
              (insert (if field-decoder
                          (funcall field-decoder field-body
-                                   (string-width field-name)
+                                  (string-width field-name)
                                   (if (functionp elmo-mime-header-max-column)
                                       (funcall elmo-mime-header-max-column)
                                     elmo-mime-header-max-column))
                        ;; Don't decode
                        field-body))
-              (insert "\n"))
-            (setq vf-alist (cdr vf-alist)))
+             (insert "\n"))
+           (setq vf-alist (cdr vf-alist)))
          (run-hooks 'mmelmo-header-inserted-hook))))))
 
 (luna-define-generic elmo-mime-insert-sorted-header (entity
@@ -158,7 +164,9 @@ value is used."
            p-max (point-max))
       (set-buffer the-buf)
       (elmo-mime-insert-header-from-buffer buf p-min p-max
-                                          invisible-fields visible-fields))))
+                                          invisible-fields
+                                          visible-fields
+                                          sorted-fields))))
 
 (luna-define-method mime-insert-text-content :around
   ((entity mime-elmo-buffer-entity))
@@ -178,13 +186,13 @@ value is used."
    elmo-message-sorted-field-list)
   (run-hooks 'elmo-message-header-inserted-hook))
 
-(defun elmo-make-mime-message-location (folder number strategy rawbuf unseen)
+(defun elmo-make-mime-message-location (folder number strategy rawbuf unread)
 ;; Return the MIME message location structure.
 ;; FOLDER is the ELMO folder structure.
 ;; NUMBER is the number of the message in the FOLDER.
 ;; STRATEGY is the message fetching strategy.
 ;; RAWBUF is the output buffer for original message.
-;; If second optional argument UNSEEN is non-nil, message is not marked
+;; If second optional argument UNREAD is non-nil, message is not marked
 ;; as read.
   (if (and strategy
           (eq (elmo-fetch-strategy-entireness strategy) 'section))
@@ -200,21 +208,24 @@ value is used."
        (if strategy
            (elmo-message-fetch folder number strategy
                                nil (current-buffer)
-                               unseen))))
+                               unread))))
     rawbuf))
 
 (defun elmo-mime-message-display (folder number viewbuf rawbuf original-mode
-                                        &optional ignore-cache)
+                                        &optional ignore-cache unread keymap)
   "Display MIME message. 
 A message in the FOLDER with NUMBER is displayed on the VIEWBUF using RAWBUF.
 VIEWBUF is a view buffer and RAWBUF is a raw buffer.
 ORIGINAL is the major mode of RAWBUF.
 If optional argument IGNORE-CACHE is specified, existing cache is ignored.
+If second optional argument UNREAD is specified, message is displayed but
+keep it as unread.
 Return non-nil if not entire message was fetched."
   (let (mime-display-header-hook ; Do nothing.
+       (elmo-message-displaying t)
        entity strategy)
     (setq entity (elmo-msgdb-overview-get-entity number
-                                                (elmo-folder-msgdb-internal
+                                                (elmo-folder-msgdb
                                                  folder)))
     (setq strategy (elmo-find-fetch-strategy folder entity
                                             ignore-cache))
@@ -225,24 +236,26 @@ Return non-nil if not entire message was fetched."
          'elmo-imap
        'elmo-buffer)
       (elmo-make-mime-message-location
-       folder number strategy rawbuf nil))
-     viewbuf nil nil original-mode)
+       folder number strategy rawbuf unread))
+     viewbuf nil keymap
+     original-mode)
     (if strategy
        (or (elmo-fetch-strategy-use-cache strategy)
            (eq (elmo-fetch-strategy-entireness strategy)
                'section)))))
 
 (defun elmo-mime-display-as-is (folder number viewbuf rawbuf original-mode
-                                        &optional ignore-cache)
+                                      &optional ignore-cache unread keymap)
   "Display MIME message. 
 A message in the FOLDER with NUMBER is displayed on the VIEWBUF using RAWBUF.
 VIEWBUF is a view buffer and RAWBUF is a raw buffer.
 ORIGINAL is the major mode of RAWBUF.
 If optional argument IGNORE-CACHE is specified, existing cache is ignored.
+If second optional argument UNREAD is specified, message is displayed but
+keep it as unread.
 Return non-nil if cache is used."
   (let ((entity (elmo-msgdb-overview-get-entity number
-                                               (elmo-folder-msgdb-internal
-                                                folder)))
+                                               (elmo-folder-msgdb folder)))
        mime-display-header-hook ; Do nothing.
        cache-file strategy use-cache)
     (setq cache-file (elmo-file-cache-get
@@ -256,8 +269,8 @@ Return non-nil if cache is used."
      (mime-open-entity
       'elmo-buffer
       (elmo-make-mime-message-location
-       folder number strategy rawbuf nil))
-     viewbuf nil nil original-mode)
+       folder number strategy rawbuf unread))
+     viewbuf nil keymap original-mode)
     (elmo-fetch-strategy-use-cache strategy)))
 
 ;; Replacement of mime-display-message.
@@ -282,21 +295,19 @@ Return non-nil if cache is used."
       (setq major-mode 'mime-view-mode)
       (setq mode-name "MIME-View")
 
+      ;; Humm...
+      (set-buffer-multibyte nil)
       (mime-insert-entity message)
-      ;(insert (mime-entity-body message))
-      ;(insert (mime-entity-body message))
-
-      (decode-coding-region (point-min) (point-max) 'undecided)
-
+      (set-buffer-multibyte t)
+      (decode-coding-region (point-min) (point-max)
+                           elmo-mime-display-as-is-coding-system)
       (save-restriction
        (std11-narrow-to-header)
        (run-hooks 'elmo-message-header-inserted-hook))
-;      (mime-display-entity message nil
-;                         `((entity-button . invisible)
-;                           (header . visible)
-;                           (major-mode . ,original-major-mode))
-;                         preview-buffer)
-
+      ;; set original major mode for mime-preview-quit
+      (put-text-property (point-min) (point-max)
+                        'mime-view-situation
+                        `((major-mode . ,original-major-mode)))
       (use-local-map
        (or keymap
           (if default-keymap-or-function
@@ -316,4 +327,4 @@ Return non-nil if cache is used."
 (require 'product)
 (product-provide (provide 'elmo-mime) (require 'elmo-version))
 
-;; elmo-mime.el ends here
\ No newline at end of file
+;; elmo-mime.el ends here