Merge from emacs-23
[bpt/emacs.git] / lisp / mail / rmail.el
index 919c756..ee839d4 100644 (file)
@@ -3441,30 +3441,62 @@ does not pop any summary buffer."
 ;;;; *** Rmail Mailing Commands ***
 
 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
-                                  replybuffer sendactions same-window others)
-  (let (yank-action)
+                                  replybuffer sendactions same-window
+                                  other-headers)
+  (let ((switch-function
+        (cond (same-window nil)
+              (rmail-mail-new-frame 'switch-to-buffer-other-frame)
+              (t 'switch-to-buffer-other-window)))
+       yank-action)
     (if replybuffer
        ;; The function used here must behave like insert-buffer wrt
        ;; point and mark (see doc of sc-cite-original).
        (setq yank-action (list 'insert-buffer replybuffer)))
-    (setq others (cons (cons "cc" cc) others))
-    (setq others (cons (cons "in-reply-to" in-reply-to) others))
-    (if same-window
-       (compose-mail to subject others
-                     noerase nil
-                     yank-action sendactions)
-      (if rmail-mail-new-frame
-         (prog1
-             (compose-mail to subject others
-                           noerase 'switch-to-buffer-other-frame
-                           yank-action sendactions)
-           ;; This is not a standard frame parameter;
-           ;; nothing except sendmail.el looks at it.
-           (modify-frame-parameters (selected-frame)
-                                    '((mail-dedicated-frame . t))))
-       (compose-mail to subject others
-                     noerase 'switch-to-buffer-other-window
-                     yank-action sendactions)))))
+    (push (cons "cc" cc) other-headers)
+    (push (cons "in-reply-to" in-reply-to) other-headers)
+    (prog1
+       (compose-mail to subject other-headers noerase
+                     switch-function yank-action sendactions
+                     '(rmail-mail-return))
+      (if (eq switch-function 'switch-to-buffer-other-frame)
+         ;; This is not a standard frame parameter; nothing except
+         ;; sendmail.el looks at it.
+         (modify-frame-parameters (selected-frame)
+                                  '((mail-dedicated-frame . t)))))))
+
+(defun rmail-mail-return ()
+  (cond
+   ;; If there is only one visible frame with no special handling,
+   ;; consider deleting the mail window to return to Rmail.
+   ((or (null (delq (selected-frame) (visible-frame-list)))
+       (not (or (window-dedicated-p (frame-selected-window))
+                (and pop-up-frames (one-window-p))
+                (cdr (assq 'mail-dedicated-frame
+                           (frame-parameters))))))
+    (let (rmail-flag summary-buffer)
+      (and (not (one-window-p))
+          (with-current-buffer
+              (window-buffer (next-window (selected-window) 'not))
+            (setq rmail-flag (eq major-mode 'rmail-mode))
+            (setq summary-buffer
+                  (and (boundp 'mail-bury-selects-summary)
+                       mail-bury-selects-summary
+                       (boundp 'rmail-summary-buffer)
+                       rmail-summary-buffer
+                       (buffer-name rmail-summary-buffer)
+                       (not (get-buffer-window rmail-summary-buffer))
+                       rmail-summary-buffer))))
+      (if rmail-flag
+         ;; If the Rmail buffer has a summary, show that.
+         (if summary-buffer (switch-to-buffer summary-buffer)
+           (delete-window)))))
+   ;; If the frame was probably made for this buffer, the user
+   ;; probably wants to delete it now.
+   ((display-multi-frame-p)
+    (delete-frame (selected-frame)))
+   ;; The previous frame is where normally they have the Rmail buffer
+   ;; displayed.
+   (t (other-frame -1))))
 
 (defun rmail-mail ()
   "Send mail in another window.
@@ -3831,9 +3863,7 @@ The message should be narrowed to just the headers."
                           (1- (point))
                         (point-max)))))))
 
-(declare-function mail-sendmail-delimit-header "sendmail" ())
-(declare-function mail-header-end "sendmail" ())
-(declare-function mail-position-on-field "sendmail" (field &optional soft))
+(autoload 'mail-position-on-field "sendmail")
 
 (defun rmail-retry-failure ()
   "Edit a mail message which is based on the contents of the current message.
@@ -3919,18 +3949,19 @@ specifying headers which should not be copied into the new message."
          ;; Insert original text as initial text of new draft message.
          ;; Bind inhibit-read-only since the header delimiter
          ;; of the previous message was probably read-only.
-         (let ((inhibit-read-only t))
+         (let ((inhibit-read-only t)
+               eoh)
            (erase-buffer)
            (insert-buffer-substring rmail-this-buffer
                                     bounce-start bounce-end)
            (goto-char (point-min))
            (if bounce-indent
                (indent-rigidly (point-min) (point-max) bounce-indent))
-           ;; FIXME better to replace sendmail functions.
-           (require 'sendmail)
-           (mail-sendmail-delimit-header)
+           (rfc822-goto-eoh)
+           (setq eoh (point))
+           (insert mail-header-separator)
            (save-restriction
-             (narrow-to-region (point-min) (mail-header-end))
+             (narrow-to-region (point-min) eoh)
              (rmail-delete-headers rmail-retry-ignored-headers)
              (rmail-delete-headers "^\\(sender\\|return-path\\|received\\):")
              (setq resending (mail-fetch-field "resent-to"))
@@ -4232,7 +4263,7 @@ encoded string (and the same mask) will decode the string."
 ;;; Start of automatically extracted autoloads.
 \f
 ;;;### (autoloads (rmail-edit-current-message) "rmailedit" "rmailedit.el"
-;;;;;;  "60db8013bf16d7999914a16cda435287")
+;;;;;;  "4bf8a5cdfc921b9e30680ee71b7f9ca6")
 ;;; Generated autoloads from rmailedit.el
 
 (autoload 'rmail-edit-current-message "rmailedit" "\
@@ -4244,7 +4275,7 @@ Edit the contents of this message.
 \f
 ;;;### (autoloads (rmail-next-labeled-message rmail-previous-labeled-message
 ;;;;;;  rmail-read-label rmail-kill-label rmail-add-label) "rmailkwd"
-;;;;;;  "rmailkwd.el" "7027ce1ac922c0dd51262b641e4d42c1")
+;;;;;;  "rmailkwd.el" "112240cbb53c402294013cc49987771a")
 ;;; Generated autoloads from rmailkwd.el
 
 (autoload 'rmail-add-label "rmailkwd" "\
@@ -4287,7 +4318,7 @@ With prefix argument N moves forward N messages with these labels.
 
 ;;;***
 \f
-;;;### (autoloads (rmail-mime) "rmailmm" "rmailmm.el" "6c12c2d0563ae855f1069d7a80b8244a")
+;;;### (autoloads (rmail-mime) "rmailmm" "rmailmm.el" "3735f9bfe6ff3e612091857cc6b401b6")
 ;;; Generated autoloads from rmailmm.el
 
 (autoload 'rmail-mime "rmailmm" "\
@@ -4313,7 +4344,7 @@ attachments as specfied by `rmail-mime-attachment-dirs-alist'.
 ;;;***
 \f
 ;;;### (autoloads (set-rmail-inbox-list) "rmailmsc" "rmailmsc.el"
-;;;;;;  "b2a72d4e370f2d2b31b6f8f0794820e4")
+;;;;;;  "c3575020691d5769bcf08ecc932304c3")
 ;;; Generated autoloads from rmailmsc.el
 
 (autoload 'set-rmail-inbox-list "rmailmsc" "\
@@ -4329,7 +4360,7 @@ This applies only to the current session.
 \f
 ;;;### (autoloads (rmail-sort-by-labels rmail-sort-by-lines rmail-sort-by-correspondent
 ;;;;;;  rmail-sort-by-recipient rmail-sort-by-author rmail-sort-by-subject
-;;;;;;  rmail-sort-by-date) "rmailsort" "rmailsort.el" "5a3b5ee477d2fbf79d0c566d776a7fd4")
+;;;;;;  rmail-sort-by-date) "rmailsort" "rmailsort.el" "b96e85edd736f23f1e9d54a299268d1e")
 ;;; Generated autoloads from rmailsort.el
 
 (autoload 'rmail-sort-by-date "rmailsort" "\
@@ -4388,7 +4419,7 @@ If prefix argument REVERSE is non-nil, sorts in reverse order.
 \f
 ;;;### (autoloads (rmail-summary-by-senders rmail-summary-by-topic
 ;;;;;;  rmail-summary-by-regexp rmail-summary-by-recipients rmail-summary-by-labels
-;;;;;;  rmail-summary) "rmailsum" "rmailsum.el" "d855683972baef7111d4508dffbb54b6")
+;;;;;;  rmail-summary) "rmailsum" "rmailsum.el" "666a5db1021cdcba6e68a18a553d65f1")
 ;;; Generated autoloads from rmailsum.el
 
 (autoload 'rmail-summary "rmailsum" "\
@@ -4459,5 +4490,4 @@ following the containing message.
 
 (provide 'rmail)
 
-;; arch-tag: 65d257d3-c281-4a65-9c38-e61af95af2f0
 ;;; rmail.el ends here