This commit was generated by cvs2svn to compensate for changes in r524,
[elisp/tm.git] / mh-e / tm-mh-e.el
index 559388e..c3f2b14 100644 (file)
@@ -1,33 +1,54 @@
-;;;
-;;; tm-mh-e.el --- MIME extender for mh-e
-;;;
-;;; Copyright (C) 1995 Free Software Foundation, Inc.
-;;; Copyright (C) 1993,1994,1995 MORIOKA Tomohiko
-;;;
-;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
-;;;         OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
-;;; Keywords: mail, MH, MIME, multimedia, encoded-word, multilingual
-;;;
-;;; This file is part of tm (Tools for MIME).
-;;;
+;;; tm-mh-e.el --- MIME extension for mh-e
 
-;;; @ require modules
-;;;
+;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
+
+;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;;         OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
+;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;; Created: 1993/11/21 (obsolete mh-e-mime.el)
+;; Version: $Revision: 7.68 $
+;; Keywords: mail, MH, MIME, multimedia, encoded-word, multilingual
+
+;; This file is part of tm (Tools for MIME).
+
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2, or (at
+;; your option) any later version.
+
+;; This program is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with This program; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Code:
 
 (require 'tl-str)
 (require 'tl-misc)
 (require 'mh-e)
-(if (not (boundp 'mh-e-version))
+(or (featurep 'mh-utils)
     (require 'tm-mh-e3)
-  )
+    )
 (require 'tm-view)
 
+(or (fboundp 'mh-get-header-field)
+    (defalias 'mh-get-header-field 'mh-get-field)
+    )
+(or (boundp 'mh-temp-buffer)
+    (defconst mh-temp-buffer " *mh-temp*")
+    )
+
 
 ;;; @ version
 ;;;
 
 (defconst tm-mh-e/RCS-ID
-  "$Id: tm-mh-e.el,v 7.20 1995/11/15 12:45:44 morioka Exp $")
+  "$Id: tm-mh-e.el,v 7.68 1996/08/31 15:15:12 morioka Exp $")
 
 (defconst tm-mh-e/version (get-version-string tm-mh-e/RCS-ID))
 
 ;;;
 
 (defvar tm-mh-e/automatic-mime-preview t
-  "If non-nil, show MIME processed message.")
+  "*If non-nil, show MIME processed message.")
 
 (defvar tm-mh-e/decode-encoded-word t
-  "If non-nil, decode encoded-word when it is not MIME preview mode.")
+  "*If non-nil, decode encoded-word when it is not MIME preview mode.")
 
 
 ;;; @ functions
 ;;;
 
-(if (not (fboundp 'tm-mh-e/original-mh-display-msg))
-    (fset 'tm-mh-e/original-mh-display-msg
-         (symbol-function 'mh-display-msg))
-  )
+;; (if (not (fboundp 'tm-mh-e/original-mh-display-msg))
+;;     (fset 'tm-mh-e/original-mh-display-msg
+;;           (symbol-function 'mh-display-msg))
+;;   )
 
 (defun mh-display-msg (msg-num folder &optional show-buffer mode)
   (or mode
                   )
                 (set-buffer-modified-p nil)
                 (setq buffer-read-only t)
+                (setq buffer-file-name msg-filename)
                 (mh-show-mode)
                 (mime/viewer-mode nil nil nil
                                   aname (concat "show-" folder))
                 )
               (set-buffer-modified-p nil)
               (setq buffer-read-only t)
+              (setq buffer-file-name msg-filename)
               (mh-show-mode)
               ))
           (or (eq buffer-undo-list t)  ;don't save undo info for prev msgs
               (setq buffer-undo-list nil))
+;;; Added by itokon (02/19/96)
           (setq buffer-file-name msg-filename)
+;;;
           (set-mark nil)
           (setq mode-line-buffer-identification
                 (list (format mh-show-buffer-mode-line-buffer-id
@@ -183,7 +208,7 @@ With arg, turn MIME processing on if arg is positive."
 (defun tm-mh-e/header-display ()
   (interactive)
   (mh-invalidate-show-buffer)
-  (let (mime-viewer/ignored-field-list
+  (let ((mime-viewer/ignored-field-regexp "^:$")
        tm-mh-e/decode-encoded-word)
     (mh-header-display)
     ))
@@ -196,33 +221,52 @@ With arg, turn MIME processing on if arg is positive."
     (mh-header-display)
     ))
 
+(defun tm-mh-e/scroll-up-msg (&optional arg)
+  (interactive)
+  (mh-page-msg (or arg 1))
+  )
+
+(defun tm-mh-e/scroll-down-msg (&optional arg)
+  (interactive)
+  (mh-page-msg (- (or arg 1)))
+  )
+
+(defun tm-mh-e/burst-multipart/digest ()
+  "Burst apart the current message, which should be a multipart/digest.
+The message is replaced by its table of contents and the letters from the
+digest are inserted into the folder after that message."
+  (interactive)
+  (let ((digest (mh-get-msg-num t)))
+    (mh-process-or-undo-commands mh-current-folder)
+    (mh-set-folder-modified-p t)               ; lock folder while bursting
+    (message "Bursting digest...")
+    (mh-exec-cmd "mhn" "-store" mh-current-folder digest)
+    (mh-scan-folder mh-current-folder (format "%d-last" mh-first-msg-num))
+    (message "Bursting digest...done")
+    ))
+
 
 ;;; @ for tm-view
 ;;;
 
-(fset 'tm-mh-e/code-convert-region-to-emacs
-      (symbol-function 'mime/code-convert-region-to-emacs))
+(fset 'tm-mh-e/decode-charset-buffer
+      (symbol-function 'mime-charset/decode-buffer))
+
+(set-alist 'mime-viewer/code-converter-alist
+          'mh-show-mode
+          (function tm-mh-e/decode-charset-buffer))
 
 (defun tm-mh-e/content-header-filter ()
   (goto-char (point-min))
-  (while (and (re-search-forward mime-viewer/ignored-field-regexp nil t)
-             (progn
-               (delete-region
-                (match-beginning 0)
-                (save-excursion
-                  (and
-                   (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
-                   (match-beginning 0)
-                   )))
-               t)))
-  (tm-mh-e/code-convert-region-to-emacs (point-min)(point-max)
-                                       mime/default-coding-system)
+  (mime-preview/cut-header)
+  (tm-mh-e/decode-charset-buffer default-mime-charset)
   (mime/decode-message-header)
-  (if (featurep 'hilit19)
-      (hilit-rehighlight-buffer-quietly)
-    )
   )
 
+(set-alist 'mime-viewer/content-header-filter-alist
+          'mh-show-mode
+          (function tm-mh-e/content-header-filter))
+
 (defun tm-mh-e/quitting-method ()
   (let ((win (get-buffer-window
              mime/output-buffer-name))
@@ -241,8 +285,33 @@ With arg, turn MIME processing on if arg is positive."
     (mh-show (mh-get-msg-num t))
     ))
 
+(set-alist 'mime-viewer/quitting-method-alist
+          'mh-show-mode
+          (function tm-mh-e/quitting-method))
+(set-alist 'mime-viewer/show-summary-method
+          'mh-show-mode
+          (function tm-mh-e/quitting-method))
 
-;;; @ for tm-partial
+(defun tm-mh-e/following-method (buf)
+  (save-excursion
+    (set-buffer buf)
+    (goto-char (point-max))
+    (setq mh-show-buffer buf)
+    (apply (function mh-send)
+          (std11-field-bodies '("To" "cc" "Subject") ""))
+    (setq mh-sent-from-folder buf)
+    (setq mh-sent-from-msg 1)
+    (let ((last (point)))
+      (mh-yank-cur-msg)
+      (goto-char last)
+      )))
+
+(set-alist 'mime-viewer/following-method-alist
+          'mh-show-mode
+          (function tm-mh-e/following-method))
+
+
+;;; @@ for tm-partial
 ;;;
 
 (call-after-loaded
@@ -270,174 +339,6 @@ With arg, turn MIME processing on if arg is positive."
     )))
 
 
-;;; @ for tm-edit
-;;;
-
-(defun tm-mh-e::make-message (folder number)
-  (vector folder number)
-  )
-
-(defun tm-mh-e::message/folder (message)
-  (elt message 0)
-  )
-
-(defun tm-mh-e::message/number (message)
-  (elt message 1)
-  )
-
-(defun tm-mh-e::message/file-name (message)
-  (expand-file-name
-   (tm-mh-e::message/number message)
-   (mh-expand-file-name (tm-mh-e::message/folder message))
-   ))
-
-;;; modified by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
-;;;    1995/11/14 (c.f. [tm ML:1096])
-(defun tm-mh-e/prompt-for-message (prompt folder &optional default)
-  (let* ((files
-         (directory-files (mh-expand-file-name folder) nil "^[0-9]+$")
-         )
-        (folder-buf (get-buffer folder))
-        (default
-          (if folder-buf
-              (save-excursion
-                (set-buffer folder-buf)
-                (let ((show-buffer (get-buffer mh-show-buffer)))
-                  (if show-buffer
-                      (file-name-nondirectory
-                       (buffer-file-name show-buffer))
-                    ))))))
-    (if (or (null default)
-           (not (string-match "^[0-9]+$" default)))
-       (setq default
-             (if (string= folder mh-sent-from-folder)
-                 (int-to-string mh-sent-from-msg)
-               (car files)
-               )))
-    (completing-read prompt
-                    (let ((i 0))
-                      (mapcar (function
-                               (lambda (file)
-                                 (setq i (+ i 1))
-                                 (list file i)
-                                 ))
-                              files)
-                      ) nil nil default)
-    ))
-
-(defun tm-mh-e/query-message ()
-  (let* ((folder (mh-prompt-for-folder
-                 "Message from" (or mh-sent-from-folder "+inbox") nil))
-        (number (tm-mh-e/prompt-for-message "Message number: " folder))
-        )
-    (tm-mh-e::make-message folder number)
-    ))
-;;; end
-
-;;; by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
-;;;    1995/11/14 (c.f. [tm ML:1099])
-(defun tm-mh-e/forward (to cc &optional msg-or-seq)
-  "Forward a message or message sequence as MIME multipart/digest.
-Defaults to displayed message. If optional prefix argument provided,
-then prompt for the message sequence. See also documentation for
-`\\[mh-send]' function."
-  (interactive (list (mh-read-address "To: ")
-                    (mh-read-address "Cc: ")
-                    (if current-prefix-arg
-                        (mh-read-seq-default "Forward" t)
-                        (mh-get-msg-num t))))
-  (or msg-or-seq
-      (setq msg-or-seq (mh-get-msg-num t)))
-  (if (numberp msg-or-seq)
-      (setq msg-or-seq (int-to-string msg-or-seq)))
-  (let* ((folder mh-current-folder)
-        (config (current-window-configuration))
-        ;; use "draft" for compatibility with forw.
-        ;; forw always leaves file in "draft" since it doesn't have -draft
-        (draft-name (expand-file-name "draft" mh-user-path))
-        (draft (cond ((or (not (file-exists-p draft-name))
-                          (y-or-n-p "The file 'draft' exists.  Discard it? "))
-                      (mh-exec-cmd "comp"
-                                   "-noedit" "-nowhatnowproc"
-                                   "-nodraftfolder")
-                      (prog1
-                          (mh-read-draft "" draft-name t)
-                        (mh-insert-fields "To:" to "Cc:" cc)
-                        (set-buffer-modified-p nil)))
-                     (t
-                      (mh-read-draft "" draft-name nil)))))
-    (let (orig-from
-         orig-subject)
-      (goto-char (point-min))
-      (save-excursion
-       (save-restriction
-         (re-search-forward "^-*\n")
-         (insert "--<<digest>>-{\n")
-         (mh-exec-cmd-output "pick" nil folder msg-or-seq)
-         (narrow-to-region (point) (mark t))
-         (while (re-search-forward "^\\([0-9]+\\)\n" nil t)
-           (let ((forw-msg
-                  (buffer-substring (match-beginning 1) (match-end 1))))
-             (replace-match "--[[message/rfc822]]\n" nil nil)
-             (insert-file (mh-expand-file-name
-                           forw-msg (mh-expand-file-name folder)))
-             (if (not (bolp)) (insert "\n"))
-             (mime-editor/inserted-message-filter))
-           (goto-char (mark t)))
-         (insert-string "--}-<<digest>>")))
-      (re-search-forward "^--\\[\\[message/rfc822\\]")
-      (forward-line 1)
-      (save-restriction
-       (narrow-to-region (point) (point-max))
-       (setq orig-from (mh-get-header-field "From:"))
-       (setq orig-subject (mh-get-header-field "Subject:")))
-      (let ((forw-subject
-            (mh-forwarded-letter-subject orig-from orig-subject)))
-       (mh-insert-fields "Subject:" forw-subject)
-       (goto-char (point-min))
-       (re-search-forward "^--\\[\\[message/rfc822\\]")
-       (forward-line -1)
-       (delete-other-windows)
-       (if (numberp msg-or-seq)
-           (mh-add-msgs-to-seq msg-or-seq 'forwarded t)
-         (mh-add-msgs-to-seq (mh-seq-to-msgs msg-or-seq) 'forwarded t))
-       (mh-compose-and-send-mail draft "" folder msg-or-seq
-                                 to forw-subject cc
-                                 mh-note-forw "Forwarded:"
-                                 config)))))
-;;; end
-
-(defun tm-mh-e/insert-message (&optional message)
-  (if (null message)
-      (setq message (tm-mh-e/query-message))
-    )
-  (insert-file (tm-mh-e::message/file-name message))
-  (mime-editor/inserted-message-filter)
-  )
-
-(call-after-loaded
- 'tm-edit
- (function
-  (lambda ()
-    (set-alist
-     'mime-editor/message-inserter-alist
-     'mh-letter-mode (function tm-mh-e/insert-message))
-    (set-alist
-     'mime-editor/mail-inserter-alist
-     'mh-letter-mode (function tm-mh-e/insert-message))
-    (set-alist
-     'mime-editor/mail-inserter-alist
-     'news-reply-mode (function tm-mh-e/insert-message))
-    )))
-
-(call-after-loaded
- 'mime-setup
- (lambda ()
-   (substitute-key-definition
-    'mh-forward 'tm-mh-e/forward mh-folder-mode-map)
-   ))
-
-
 ;;; @ set up
 ;;;
 
@@ -446,16 +347,10 @@ then prompt for the message sequence. See also documentation for
 (define-key mh-folder-mode-map "." (function tm-mh-e/show))
 (define-key mh-folder-mode-map "," (function tm-mh-e/header-display))
 (define-key mh-folder-mode-map "\e," (function tm-mh-e/raw-display))
-(define-key mh-folder-mode-map "\r"
-  (function (lambda ()
-             (interactive)
-             (scroll-other-window 1)
-             )))
-(define-key mh-folder-mode-map "\e\r"
-  (function (lambda ()
-             (interactive)
-             (scroll-other-window -1)
-             )))
+(define-key mh-folder-mode-map "\r" (function tm-mh-e/scroll-up-msg))
+(define-key mh-folder-mode-map "\e\r" (function tm-mh-e/scroll-down-msg))
+(define-key mh-folder-mode-map "\C-c\C-b"
+  (function tm-mh-e/burst-multipart/digest))
 
 (defun tm-mh-e/summary-before-quit ()
   (let ((buf (get-buffer mh-show-buffer)))
@@ -475,17 +370,48 @@ then prompt for the message sequence. See also documentation for
 
 (add-hook 'mh-before-quit-hook (function tm-mh-e/summary-before-quit))
             
-(set-alist 'mime-viewer/quitting-method-alist
-          'mh-show-mode
-          (function tm-mh-e/quitting-method))
 
-(set-alist 'mime-viewer/content-header-filter-alist
-          'mh-show-mode
-          (function tm-mh-e/content-header-filter))
+;;; @@ for tmh-comp.el
+;;;
 
-(set-alist 'mime-viewer/code-converter-alist
-          'mh-show-mode
-          (function tm-mh-e/code-convert-region-to-emacs))
+(autoload 'tm-mh-e/edit-again "tmh-comp"
+  "Clean-up a draft or a message previously sent and make it resendable." t)
+(autoload 'tm-mh-e/extract-rejected-mail "tmh-comp"
+  "Extract a letter returned by the mail system and make it re-editable." t)
+(autoload 'tm-mh-e/forward "tmh-comp"
+  "Forward a message or message sequence by MIME style." t)
+
+(call-after-loaded
+ 'mime-setup
+ (function
+  (lambda ()
+    (substitute-key-definition
+     'mh-edit-again 'tm-mh-e/edit-again mh-folder-mode-map)
+    (substitute-key-definition
+     'mh-extract-rejected-mail 'tm-mh-e/extract-rejected-mail
+     mh-folder-mode-map)
+    (substitute-key-definition
+     'mh-forward 'tm-mh-e/forward mh-folder-mode-map)
+
+    (call-after-loaded
+     'mh-comp
+     (function
+      (lambda ()
+       (require 'tmh-comp)
+       ))
+     'mh-letter-mode-hook)
+    )))
+
+
+;;; @ for BBDB
+;;;
+
+(call-after-loaded
+ 'bbdb
+ (function
+  (lambda ()
+    (require 'tm-bbdb)
+    )))
 
 
 ;;; @ end
@@ -494,3 +420,5 @@ then prompt for the message sequence. See also documentation for
 (provide 'tm-mh-e)
 
 (run-hooks 'tm-mh-e-load-hook)
+
+;;; tm-mh-e.el ends here