]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/rmailsum.el
Merge from mainline.
[gnu-emacs] / lisp / mail / rmailsum.el
index 3c9d3e547099e8a63bdc158c78bf1e1e243d30e6..8e28201e31f8324bb418d299951e694ba322f2f2 100644 (file)
@@ -1,10 +1,10 @@
 ;;; rmailsum.el --- make summary buffers for the mail reader
 
-;; Copyright (C) 1985, 1993, 1994, 1995, 1996, 2000, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1993-1996, 2000-2011 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: mail
+;; Package: rmail
 
 ;; This file is part of GNU Emacs.
 
@@ -31,6 +31,7 @@
 
 ;; For rmail-select-summary.
 (require 'rmail)
+(require 'rfc2047)
 
 (defcustom rmail-summary-scroll-between-messages t
   "Non-nil means Rmail summary scroll commands move between messages.
@@ -63,7 +64,196 @@ Setting this option to nil might speed up the generation of summaries."
   "Overlay used to highlight the current message in the Rmail summary.")
 (put 'rmail-summary-overlay 'permanent-local t)
 
-(defvar rmail-summary-mode-map nil
+(defvar rmail-summary-mode-map
+  (let ((map (make-keymap)))
+    (suppress-keymap map)
+    (define-key map [mouse-2] 'rmail-summary-mouse-goto-message)
+    (define-key map "a"      'rmail-summary-add-label)
+    (define-key map "b"      'rmail-summary-bury)
+    (define-key map "c"      'rmail-summary-continue)
+    (define-key map "d"      'rmail-summary-delete-forward)
+    (define-key map "\C-d"   'rmail-summary-delete-backward)
+    (define-key map "e"      'rmail-summary-edit-current-message)
+    (define-key map "f"      'rmail-summary-forward)
+    (define-key map "g"      'rmail-summary-get-new-mail)
+    (define-key map "h"      'rmail-summary)
+    (define-key map "i"      'rmail-summary-input)
+    (define-key map "j"      'rmail-summary-goto-msg)
+    (define-key map "\C-m"   'rmail-summary-goto-msg)
+    (define-key map "k"      'rmail-summary-kill-label)
+    (define-key map "l"      'rmail-summary-by-labels)
+    (define-key map "\e\C-h" 'rmail-summary)
+    (define-key map "\e\C-l" 'rmail-summary-by-labels)
+    (define-key map "\e\C-r" 'rmail-summary-by-recipients)
+    (define-key map "\e\C-s" 'rmail-summary-by-regexp)
+    ;; `f' for "from".
+    (define-key map "\e\C-f" 'rmail-summary-by-senders)
+    (define-key map "\e\C-t" 'rmail-summary-by-topic)
+    (define-key map "m"      'rmail-summary-mail)
+    (define-key map "\M-m"   'rmail-summary-retry-failure)
+    (define-key map "n"      'rmail-summary-next-msg)
+    (define-key map "\en"    'rmail-summary-next-all)
+    (define-key map "\e\C-n" 'rmail-summary-next-labeled-message)
+    (define-key map "o"      'rmail-summary-output)
+    (define-key map "\C-o"   'rmail-summary-output-as-seen)
+    (define-key map "p"      'rmail-summary-previous-msg)
+    (define-key map "\ep"    'rmail-summary-previous-all)
+    (define-key map "\e\C-p" 'rmail-summary-previous-labeled-message)
+    (define-key map "q"      'rmail-summary-quit)
+    (define-key map "Q"      'rmail-summary-wipe)
+    (define-key map "r"      'rmail-summary-reply)
+    (define-key map "s"      'rmail-summary-expunge-and-save)
+    ;; See rms's comment in rmail.el
+    ;; (define-key map "\er"    'rmail-summary-search-backward)
+    (define-key map "\es"    'rmail-summary-search)
+    (define-key map "t"      'rmail-summary-toggle-header)
+    (define-key map "u"      'rmail-summary-undelete)
+    (define-key map "\M-u"   'rmail-summary-undelete-many)
+    (define-key map "x"      'rmail-summary-expunge)
+    (define-key map "w"      'rmail-summary-output-body)
+    (define-key map "v"      'rmail-mime)
+    (define-key map "."      'rmail-summary-beginning-of-message)
+    (define-key map "/"      'rmail-summary-end-of-message)
+    (define-key map "<"      'rmail-summary-first-message)
+    (define-key map ">"      'rmail-summary-last-message)
+    (define-key map " "      'rmail-summary-scroll-msg-up)
+    (define-key map "\177"   'rmail-summary-scroll-msg-down)
+    (define-key map "?"      'describe-mode)
+    (define-key map "\C-c\C-n" 'rmail-summary-next-same-subject)
+    (define-key map "\C-c\C-p" 'rmail-summary-previous-same-subject)
+    (define-key map "\C-c\C-s\C-d" 'rmail-summary-sort-by-date)
+    (define-key map "\C-c\C-s\C-s" 'rmail-summary-sort-by-subject)
+    (define-key map "\C-c\C-s\C-a" 'rmail-summary-sort-by-author)
+    (define-key map "\C-c\C-s\C-r" 'rmail-summary-sort-by-recipient)
+    (define-key map "\C-c\C-s\C-c" 'rmail-summary-sort-by-correspondent)
+    (define-key map "\C-c\C-s\C-l" 'rmail-summary-sort-by-lines)
+    (define-key map "\C-c\C-s\C-k" 'rmail-summary-sort-by-labels)
+    (define-key map "\C-x\C-s" 'rmail-summary-save-buffer)
+
+    ;; Menu bar bindings.
+
+    (define-key map [menu-bar] (make-sparse-keymap))
+
+    (define-key map [menu-bar classify]
+      (cons "Classify" (make-sparse-keymap "Classify")))
+
+    (define-key map [menu-bar classify output-menu]
+      '("Output (Rmail Menu)..." . rmail-summary-output-menu))
+
+    (define-key map [menu-bar classify input-menu]
+      '("Input Rmail File (menu)..." . rmail-input-menu))
+
+    (define-key map [menu-bar classify input-menu]
+      '(nil))
+
+    (define-key map [menu-bar classify output-menu]
+      '(nil))
+
+    (define-key map [menu-bar classify output-body]
+      '("Output body..." . rmail-summary-output-body))
+
+    (define-key map [menu-bar classify output-inbox]
+      '("Output..." . rmail-summary-output))
+
+    (define-key map [menu-bar classify output]
+      '("Output as seen..." . rmail-summary-output-as-seen))
+
+    (define-key map [menu-bar classify kill-label]
+      '("Kill Label..." . rmail-summary-kill-label))
+
+    (define-key map [menu-bar classify add-label]
+      '("Add Label..." . rmail-summary-add-label))
+
+    (define-key map [menu-bar summary]
+      (cons "Summary" (make-sparse-keymap "Summary")))
+
+    (define-key map [menu-bar summary senders]
+      '("By Senders..." . rmail-summary-by-senders))
+
+    (define-key map [menu-bar summary labels]
+      '("By Labels..." . rmail-summary-by-labels))
+
+    (define-key map [menu-bar summary recipients]
+      '("By Recipients..." . rmail-summary-by-recipients))
+
+    (define-key map [menu-bar summary topic]
+      '("By Topic..." . rmail-summary-by-topic))
+
+    (define-key map [menu-bar summary regexp]
+      '("By Regexp..." . rmail-summary-by-regexp))
+
+    (define-key map [menu-bar summary all]
+      '("All" . rmail-summary))
+
+    (define-key map [menu-bar mail]
+      (cons "Mail" (make-sparse-keymap "Mail")))
+
+    (define-key map [menu-bar mail rmail-summary-get-new-mail]
+      '("Get New Mail" . rmail-summary-get-new-mail))
+
+    (define-key map [menu-bar mail lambda]
+      '("----"))
+
+    (define-key map [menu-bar mail continue]
+      '("Continue" . rmail-summary-continue))
+
+    (define-key map [menu-bar mail resend]
+      '("Re-send..." . rmail-summary-resend))
+
+    (define-key map [menu-bar mail forward]
+      '("Forward" . rmail-summary-forward))
+
+    (define-key map [menu-bar mail retry]
+      '("Retry" . rmail-summary-retry-failure))
+
+    (define-key map [menu-bar mail reply]
+      '("Reply" . rmail-summary-reply))
+
+    (define-key map [menu-bar mail mail]
+      '("Mail" . rmail-summary-mail))
+
+    (define-key map [menu-bar delete]
+      (cons "Delete" (make-sparse-keymap "Delete")))
+
+    (define-key map [menu-bar delete expunge/save]
+      '("Expunge/Save" . rmail-summary-expunge-and-save))
+
+    (define-key map [menu-bar delete expunge]
+      '("Expunge" . rmail-summary-expunge))
+
+    (define-key map [menu-bar delete undelete]
+      '("Undelete" . rmail-summary-undelete))
+
+    (define-key map [menu-bar delete delete]
+      '("Delete" . rmail-summary-delete-forward))
+
+    (define-key map [menu-bar move]
+      (cons "Move" (make-sparse-keymap "Move")))
+
+    (define-key map [menu-bar move search-back]
+      '("Search Back..." . rmail-summary-search-backward))
+
+    (define-key map [menu-bar move search]
+      '("Search..." . rmail-summary-search))
+
+    (define-key map [menu-bar move previous]
+      '("Previous Nondeleted" . rmail-summary-previous-msg))
+
+    (define-key map [menu-bar move next]
+      '("Next Nondeleted" . rmail-summary-next-msg))
+
+    (define-key map [menu-bar move last]
+      '("Last" . rmail-summary-last-message))
+
+    (define-key map [menu-bar move first]
+      '("First" . rmail-summary-first-message))
+
+    (define-key map [menu-bar move previous]
+      '("Previous" . rmail-summary-previous-all))
+
+    (define-key map [menu-bar move next]
+      '("Next" . rmail-summary-next-all))
+    map)
   "Keymap used in Rmail summary mode.")
 
 ;; Entry points for making a summary buffer.
@@ -230,13 +420,13 @@ nil for FUNCTION means all messages."
          (progn
            (split-window (selected-window) rmail-summary-window-size)
            (select-window (next-window (frame-first-window)))
-           (pop-to-buffer rmail-summary-buffer)
+           (rmail-pop-to-buffer rmail-summary-buffer)
            ;; If pop-to-buffer did not use that window, delete that
            ;; window.  (This can happen if it uses another frame.)
            (if (not (eq rmail-summary-buffer
                         (window-buffer (frame-first-window))))
                (delete-other-windows)))
-       (pop-to-buffer rmail-summary-buffer))
+       (rmail-pop-to-buffer rmail-summary-buffer))
       (set-buffer rmail-buffer)
       ;; This is how rmail makes the summary buffer reappear.
       ;; We do this here to make the window the proper size.
@@ -291,7 +481,8 @@ message."
                                    summary-msgs))))
                  (setq msgnum (1+ msgnum))
                  ;; Provide a periodic User progress message.
-                 (if (zerop (% rmail-new-summary-line-count 10))
+                 (if (and (not (zerop rmail-new-summary-line-count))
+                          (zerop (% rmail-new-summary-line-count 10)))
                      (message "Computing summary lines...%d"
                               rmail-new-summary-line-count)))
                (setq summary-msgs (nreverse summary-msgs)))
@@ -362,13 +553,15 @@ The current buffer contains the unrestricted message collection."
       (aset rmail-summary-vector (1- msgnum) line))
     line))
 
-(defcustom rmail-summary-line-decoder (function identity)
+(defcustom rmail-summary-line-decoder (function rfc2047-decode-string)
   "Function to decode a Rmail summary line.
 It receives the summary line for one message as a string
 and should return the decoded string.
 
-By default, it is `identity', which returns the string unaltered."
+By default, it is `rfc2047-decode-string', which decodes MIME-encoded
+subject."
   :type 'function
+  :version "23.3"
   :group 'rmail-summary)
 
 (defun rmail-create-summary-line (msgnum)
@@ -487,25 +680,6 @@ LINES is the number of lines in the message (if we should display that)
             (concat prefix basic-start linecount-string " "
                     labels basic-end))))
 
-;; FIXME move to rmail.el?
-;;;###autoload
-(defcustom rmail-user-mail-address-regexp nil
-  "Regexp matching user mail addresses.
-If non-nil, this variable is used to identify the correspondent
-when receiving new mail.  If it matches the address of the sender,
-the recipient is taken as correspondent of a mail.
-If nil \(default value\), your `user-login-name' and `user-mail-address'
-are used to exclude yourself as correspondent.
-
-Usually you don't have to set this variable, except if you collect mails
-sent by you under different user names.
-Then it should be a regexp matching your mail addresses.
-
-Setting this variable has an effect only before reading a mail."
-  :type '(choice (const :tag "None" nil) regexp)
-  :group 'rmail-retrieve
-  :version "21.1")
-
 (defun rmail-header-summary ()
   "Return a message summary based on the message headers.
 The value is a list of two strings, the first and second parts of the summary.
@@ -517,16 +691,19 @@ the message being processed."
    (concat (save-excursion
             (if (not (re-search-forward "^Date:" nil t))
                 "      "
-              (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
-                      (line-end-position) t)
+              ;; Match month names case-insensitively
+              (cond ((let ((case-fold-search t))
+                       (re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
+                                          (line-end-position) t))
                      (format "%2d-%3s"
                              (string-to-number (buffer-substring
                                                 (match-beginning 2)
                                                 (match-end 2)))
                              (buffer-substring
                               (match-beginning 4) (match-end 4))))
-                    ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
-                      (line-end-position) t)
+                    ((let ((case-fold-search t))
+                       (re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
+                                          (line-end-position) t))
                      (format "%2d-%3s"
                              (string-to-number (buffer-substring
                                                 (match-beginning 4)
@@ -603,10 +780,17 @@ the message being processed."
                                                     (t (- mch 14))))
                                      (min len (+ lo 25)))))))))
    (concat (if (re-search-forward "^Subject:" nil t)
-              (progn (skip-chars-forward " \t")
-                     (buffer-substring (point)
-                                       (progn (end-of-line)
-                                              (point))))
+              (let (pos str)
+                (skip-chars-forward " \t")
+                (setq pos (point))
+                (forward-line 1)
+                (setq str (buffer-substring pos (1- (point))))
+                (while (looking-at "\\s ")
+                  (setq str (concat str " " 
+                                    (buffer-substring (match-end 0)
+                                                      (line-end-position))))
+                  (forward-line 1))
+                str)
             (re-search-forward "[\n][\n]+" nil t)
             (buffer-substring (point) (progn (end-of-line) (point))))
           "\n")))
@@ -658,8 +842,7 @@ non-deleted messages."
 With prefix argument N moves forward N messages with these labels."
   (interactive "p\nsMove to next msg with labels: ")
   (let (msg)
-    (save-excursion
-      (set-buffer rmail-buffer)
+    (with-current-buffer rmail-buffer
       (rmail-next-labeled-message n labels)
       (setq msg rmail-current-message))
     (rmail-summary-goto-msg msg)))
@@ -669,8 +852,7 @@ With prefix argument N moves forward N messages with these labels."
 With prefix argument N moves backward N messages with these labels."
   (interactive "p\nsMove to previous msg with labels: ")
   (let (msg)
-    (save-excursion
-      (set-buffer rmail-buffer)
+    (with-current-buffer rmail-buffer
       (rmail-previous-labeled-message n labels)
       (setq msg rmail-current-message))
     (rmail-summary-goto-msg msg)))
@@ -813,19 +995,18 @@ Optional prefix ARG means undelete ARG previous messages."
             (rmail-summary-goto-msg)
             (if rmail-enable-mime
                 (set-buffer rmail-buffer)
-              (pop-to-buffer rmail-buffer))
+              (rmail-pop-to-buffer rmail-buffer))
             (and (rmail-message-deleted-p rmail-current-message)
                  (rmail-undelete-previous-message))
             (if rmail-enable-mime
-                (pop-to-buffer rmail-buffer))
-            (pop-to-buffer rmail-summary-buffer))
+                (rmail-pop-to-buffer rmail-buffer))
+            (rmail-pop-to-buffer rmail-summary-buffer))
            (t (goto-char opoint))))))
 
 (defun rmail-summary-undelete-many (&optional n)
   "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
   (interactive "P")
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (let* ((init-msg (if n rmail-current-message rmail-total-messages))
           (rmail-current-message init-msg)
           (n (or n rmail-total-messages))
@@ -982,9 +1163,13 @@ Search, the `unseen' attribute is restored.")
                        (rmail-show-message msg-num t))
                    (select-window owin))
                (if (buffer-name rmail-buffer)
-                   (save-excursion
-                     (set-buffer rmail-buffer)
-                     (rmail-show-message msg-num t))))))
+                   (with-current-buffer rmail-buffer
+                     (rmail-show-message msg-num t))))
+             ;; In linum mode, the message buffer must be specially
+             ;; updated (Bug#4878).
+             (and (fboundp 'linum-update)
+                  (buffer-name rmail-buffer)
+                  (linum-update rmail-buffer))))
        (rmail-summary-update-highlight nil)))))
 
 (defun rmail-summary-save-buffer ()
@@ -994,207 +1179,6 @@ Search, the `unseen' attribute is restored.")
     (save-excursion
       (switch-to-buffer rmail-buffer)
       (save-buffer))))
-
-\f
-(if rmail-summary-mode-map
-    nil
-  (setq rmail-summary-mode-map (make-keymap))
-  (suppress-keymap rmail-summary-mode-map)
-
-  (define-key rmail-summary-mode-map [mouse-2] 'rmail-summary-mouse-goto-message)
-  (define-key rmail-summary-mode-map "a"      'rmail-summary-add-label)
-  (define-key rmail-summary-mode-map "b"      'rmail-summary-bury)
-  (define-key rmail-summary-mode-map "c"      'rmail-summary-continue)
-  (define-key rmail-summary-mode-map "d"      'rmail-summary-delete-forward)
-  (define-key rmail-summary-mode-map "\C-d"   'rmail-summary-delete-backward)
-  (define-key rmail-summary-mode-map "e"      'rmail-summary-edit-current-message)
-  (define-key rmail-summary-mode-map "f"      'rmail-summary-forward)
-  (define-key rmail-summary-mode-map "g"      'rmail-summary-get-new-mail)
-  (define-key rmail-summary-mode-map "h"      'rmail-summary)
-  (define-key rmail-summary-mode-map "i"      'rmail-summary-input)
-  (define-key rmail-summary-mode-map "j"      'rmail-summary-goto-msg)
-  (define-key rmail-summary-mode-map "\C-m"   'rmail-summary-goto-msg)
-  (define-key rmail-summary-mode-map "k"      'rmail-summary-kill-label)
-  (define-key rmail-summary-mode-map "l"      'rmail-summary-by-labels)
-  (define-key rmail-summary-mode-map "\e\C-h" 'rmail-summary)
-  (define-key rmail-summary-mode-map "\e\C-l" 'rmail-summary-by-labels)
-  (define-key rmail-summary-mode-map "\e\C-r" 'rmail-summary-by-recipients)
-  (define-key rmail-summary-mode-map "\e\C-s" 'rmail-summary-by-regexp)
-  ;; `f' for "from".
-  (define-key rmail-summary-mode-map "\e\C-f" 'rmail-summary-by-senders)
-  (define-key rmail-summary-mode-map "\e\C-t" 'rmail-summary-by-topic)
-  (define-key rmail-summary-mode-map "m"      'rmail-summary-mail)
-  (define-key rmail-summary-mode-map "\M-m"   'rmail-summary-retry-failure)
-  (define-key rmail-summary-mode-map "n"      'rmail-summary-next-msg)
-  (define-key rmail-summary-mode-map "\en"    'rmail-summary-next-all)
-  (define-key rmail-summary-mode-map "\e\C-n" 'rmail-summary-next-labeled-message)
-  (define-key rmail-summary-mode-map "o"      'rmail-summary-output)
-  (define-key rmail-summary-mode-map "\C-o"   'rmail-summary-output-as-seen)
-  (define-key rmail-summary-mode-map "p"      'rmail-summary-previous-msg)
-  (define-key rmail-summary-mode-map "\ep"    'rmail-summary-previous-all)
-  (define-key rmail-summary-mode-map "\e\C-p" 'rmail-summary-previous-labeled-message)
-  (define-key rmail-summary-mode-map "q"      'rmail-summary-quit)
-  (define-key rmail-summary-mode-map "Q"      'rmail-summary-wipe)
-  (define-key rmail-summary-mode-map "r"      'rmail-summary-reply)
-  (define-key rmail-summary-mode-map "s"      'rmail-summary-expunge-and-save)
-  ;; See rms's comment in rmail.el
-;;;  (define-key rmail-summary-mode-map "\er"    'rmail-summary-search-backward)
-  (define-key rmail-summary-mode-map "\es"    'rmail-summary-search)
-  (define-key rmail-summary-mode-map "t"      'rmail-summary-toggle-header)
-  (define-key rmail-summary-mode-map "u"      'rmail-summary-undelete)
-  (define-key rmail-summary-mode-map "\M-u"   'rmail-summary-undelete-many)
-  (define-key rmail-summary-mode-map "x"      'rmail-summary-expunge)
-  (define-key rmail-summary-mode-map "w"      'rmail-summary-output-body)
-  (define-key rmail-summary-mode-map "v"      'rmail-mime)
-  (define-key rmail-summary-mode-map "."      'rmail-summary-beginning-of-message)
-  (define-key rmail-summary-mode-map "/"      'rmail-summary-end-of-message)
-  (define-key rmail-summary-mode-map "<"      'rmail-summary-first-message)
-  (define-key rmail-summary-mode-map ">"      'rmail-summary-last-message)
-  (define-key rmail-summary-mode-map " "      'rmail-summary-scroll-msg-up)
-  (define-key rmail-summary-mode-map "\177"   'rmail-summary-scroll-msg-down)
-  (define-key rmail-summary-mode-map "?"      'describe-mode)
-  (define-key rmail-summary-mode-map "\C-c\C-n" 'rmail-summary-next-same-subject)
-  (define-key rmail-summary-mode-map "\C-c\C-p" 'rmail-summary-previous-same-subject)
-  (define-key rmail-summary-mode-map "\C-c\C-s\C-d"
-    'rmail-summary-sort-by-date)
-  (define-key rmail-summary-mode-map "\C-c\C-s\C-s"
-    'rmail-summary-sort-by-subject)
-  (define-key rmail-summary-mode-map "\C-c\C-s\C-a"
-    'rmail-summary-sort-by-author)
-  (define-key rmail-summary-mode-map "\C-c\C-s\C-r"
-    'rmail-summary-sort-by-recipient)
-  (define-key rmail-summary-mode-map "\C-c\C-s\C-c"
-    'rmail-summary-sort-by-correspondent)
-  (define-key rmail-summary-mode-map "\C-c\C-s\C-l"
-    'rmail-summary-sort-by-lines)
-  (define-key rmail-summary-mode-map "\C-c\C-s\C-k"
-    'rmail-summary-sort-by-labels)
-  (define-key rmail-summary-mode-map "\C-x\C-s" 'rmail-summary-save-buffer)
-  )
-\f
-;;; Menu bar bindings.
-
-(define-key rmail-summary-mode-map [menu-bar] (make-sparse-keymap))
-
-(define-key rmail-summary-mode-map [menu-bar classify]
-  (cons "Classify" (make-sparse-keymap "Classify")))
-
-(define-key rmail-summary-mode-map [menu-bar classify output-menu]
-  '("Output (Rmail Menu)..." . rmail-summary-output-menu))
-
-(define-key rmail-summary-mode-map [menu-bar classify input-menu]
-  '("Input Rmail File (menu)..." . rmail-input-menu))
-
-(define-key rmail-summary-mode-map [menu-bar classify input-menu]
-  '(nil))
-
-(define-key rmail-summary-mode-map [menu-bar classify output-menu]
-  '(nil))
-
-(define-key rmail-summary-mode-map [menu-bar classify output-body]
-  '("Output body..." . rmail-summary-output-body))
-
-(define-key rmail-summary-mode-map [menu-bar classify output-inbox]
-  '("Output..." . rmail-summary-output))
-
-(define-key rmail-summary-mode-map [menu-bar classify output]
-  '("Output as seen..." . rmail-summary-output-as-seen))
-
-(define-key rmail-summary-mode-map [menu-bar classify kill-label]
-  '("Kill Label..." . rmail-summary-kill-label))
-
-(define-key rmail-summary-mode-map [menu-bar classify add-label]
-  '("Add Label..." . rmail-summary-add-label))
-
-(define-key rmail-summary-mode-map [menu-bar summary]
-  (cons "Summary" (make-sparse-keymap "Summary")))
-
-(define-key rmail-summary-mode-map [menu-bar summary senders]
-  '("By Senders..." . rmail-summary-by-senders))
-
-(define-key rmail-summary-mode-map [menu-bar summary labels]
-  '("By Labels..." . rmail-summary-by-labels))
-
-(define-key rmail-summary-mode-map [menu-bar summary recipients]
-  '("By Recipients..." . rmail-summary-by-recipients))
-
-(define-key rmail-summary-mode-map [menu-bar summary topic]
-  '("By Topic..." . rmail-summary-by-topic))
-
-(define-key rmail-summary-mode-map [menu-bar summary regexp]
-  '("By Regexp..." . rmail-summary-by-regexp))
-
-(define-key rmail-summary-mode-map [menu-bar summary all]
-  '("All" . rmail-summary))
-
-(define-key rmail-summary-mode-map [menu-bar mail]
-  (cons "Mail" (make-sparse-keymap "Mail")))
-
-(define-key rmail-summary-mode-map [menu-bar mail rmail-summary-get-new-mail]
-  '("Get New Mail" . rmail-summary-get-new-mail))
-
-(define-key rmail-summary-mode-map [menu-bar mail lambda]
-  '("----"))
-
-(define-key rmail-summary-mode-map [menu-bar mail continue]
-  '("Continue" . rmail-summary-continue))
-
-(define-key rmail-summary-mode-map [menu-bar mail resend]
-  '("Re-send..." . rmail-summary-resend))
-
-(define-key rmail-summary-mode-map [menu-bar mail forward]
-  '("Forward" . rmail-summary-forward))
-
-(define-key rmail-summary-mode-map [menu-bar mail retry]
-  '("Retry" . rmail-summary-retry-failure))
-
-(define-key rmail-summary-mode-map [menu-bar mail reply]
-  '("Reply" . rmail-summary-reply))
-
-(define-key rmail-summary-mode-map [menu-bar mail mail]
-  '("Mail" . rmail-summary-mail))
-
-(define-key rmail-summary-mode-map [menu-bar delete]
-  (cons "Delete" (make-sparse-keymap "Delete")))
-
-(define-key rmail-summary-mode-map [menu-bar delete expunge/save]
-  '("Expunge/Save" . rmail-summary-expunge-and-save))
-
-(define-key rmail-summary-mode-map [menu-bar delete expunge]
-  '("Expunge" . rmail-summary-expunge))
-
-(define-key rmail-summary-mode-map [menu-bar delete undelete]
-  '("Undelete" . rmail-summary-undelete))
-
-(define-key rmail-summary-mode-map [menu-bar delete delete]
-  '("Delete" . rmail-summary-delete-forward))
-
-(define-key rmail-summary-mode-map [menu-bar move]
-  (cons "Move" (make-sparse-keymap "Move")))
-
-(define-key rmail-summary-mode-map [menu-bar move search-back]
-  '("Search Back..." . rmail-summary-search-backward))
-
-(define-key rmail-summary-mode-map [menu-bar move search]
-  '("Search..." . rmail-summary-search))
-
-(define-key rmail-summary-mode-map [menu-bar move previous]
-  '("Previous Nondeleted" . rmail-summary-previous-msg))
-
-(define-key rmail-summary-mode-map [menu-bar move next]
-  '("Next Nondeleted" . rmail-summary-next-msg))
-
-(define-key rmail-summary-mode-map [menu-bar move last]
-  '("Last" . rmail-summary-last-message))
-
-(define-key rmail-summary-mode-map [menu-bar move first]
-  '("First" . rmail-summary-first-message))
-
-(define-key rmail-summary-mode-map [menu-bar move previous]
-  '("Previous" . rmail-summary-previous-all))
-
-(define-key rmail-summary-mode-map [menu-bar move next]
-  '("Next" . rmail-summary-next-all))
 \f
 (defun rmail-summary-mouse-goto-message (event)
   "Select the message whose summary line you click on."
@@ -1221,7 +1205,7 @@ Returns non-nil if message N was found."
         (curmsg (string-to-number
                  (buffer-substring (point)
                                    (min (point-max) (+ 6 (point))))))
-        (total (save-excursion (set-buffer buf) rmail-total-messages)))
+        (total (with-current-buffer buf rmail-total-messages)))
     ;; If message number N was specified, find that message's line
     ;; or set message-not-found.
     ;; If N wasn't specified or that message can't be found.
@@ -1248,7 +1232,7 @@ Returns non-nil if message N was found."
     (unless skip-rmail
       (let ((selwin (selected-window)))
        (unwind-protect
-           (progn (pop-to-buffer buf)
+           (progn (rmail-pop-to-buffer buf)
                   (rmail-show-message n))
          (select-window selwin)
          ;; The actions above can alter the current buffer.  Preserve it.
@@ -1347,12 +1331,12 @@ Position it according to WHERE which can be BEG or END"
       (let ((buffer rmail-buffer))
        (split-window (selected-window) rmail-summary-window-size)
        (select-window (frame-first-window))
-       (pop-to-buffer rmail-buffer)
+       (rmail-pop-to-buffer rmail-buffer)
        ;; If pop-to-buffer did not use that window, delete that
        ;; window.  (This can happen if it uses another frame.)
        (or (eq buffer (window-buffer (next-window (frame-first-window))))
            (delete-other-windows)))
-    (pop-to-buffer rmail-buffer))
+    (rmail-pop-to-buffer rmail-buffer))
   (cond
    ((eq where 'BEG)
        (goto-char (point-min))
@@ -1361,7 +1345,7 @@ Position it according to WHERE which can be BEG or END"
        (goto-char (point-max))
        (recenter (1- (window-height))))
    )
-  (pop-to-buffer rmail-summary-buffer))
+  (rmail-pop-to-buffer rmail-summary-buffer))
 
 (defun rmail-summary-bury ()
   "Bury the Rmail buffer and the Rmail summary buffer."
@@ -1383,20 +1367,19 @@ Position it according to WHERE which can be BEG or END"
 (defun rmail-summary-wipe ()
   "Kill and wipe away Rmail summary, remaining within Rmail."
   (interactive)
-  (save-excursion (set-buffer rmail-buffer) (setq rmail-summary-buffer nil))
+  (with-current-buffer rmail-buffer (setq rmail-summary-buffer nil))
   (let ((local-rmail-buffer rmail-buffer))
     (kill-buffer (current-buffer))
     ;; Delete window if not only one.
     (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
        (delete-window))
     ;; Switch windows to the rmail buffer, or switch to it in this window.
-    (pop-to-buffer local-rmail-buffer)))
+    (rmail-pop-to-buffer local-rmail-buffer)))
 
 (defun rmail-summary-expunge ()
   "Actually erase all deleted messages and recompute summary headers."
   (interactive)
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (when (rmail-expunge-confirmed)
       (rmail-only-expunge)))
   (rmail-update-summary))
@@ -1420,8 +1403,7 @@ argument says to read a file name and use that file as the inbox."
    (list (if current-prefix-arg
             (read-file-name "Get new mail from file: "))))
   (let (msg)
-    (save-excursion
-      (set-buffer rmail-buffer)
+    (with-current-buffer rmail-buffer
       (rmail-get-new-mail file-name)
       ;; Get the proper new message number.
       (setq msg rmail-current-message))
@@ -1433,7 +1415,7 @@ argument says to read a file name and use that file as the inbox."
   "Run Rmail on file FILENAME."
   (interactive "FRun rmail on RMAIL file: ")
   ;; We switch windows here, then display the other Rmail file there.
-  (pop-to-buffer rmail-buffer)
+  (rmail-pop-to-buffer rmail-buffer)
   (rmail filename))
 
 (defun rmail-summary-first-message ()
@@ -1466,7 +1448,7 @@ argument says to read a file name and use that file as the inbox."
 (defun rmail-summary-edit-current-message ()
   "Edit the contents of this message."
   (interactive)
-  (pop-to-buffer rmail-buffer)
+  (rmail-pop-to-buffer rmail-buffer)
   (rmail-edit-current-message)
   (use-local-map rmail-summary-edit-map))
 
@@ -1474,14 +1456,14 @@ argument says to read a file name and use that file as the inbox."
   "Finish editing message, then go back to Rmail summary buffer."
   (interactive)
   (rmail-cease-edit)
-  (pop-to-buffer rmail-summary-buffer))
+  (rmail-pop-to-buffer rmail-summary-buffer))
 
 (defun rmail-summary-abort-edit ()
   "Abort edit of current message; restore original contents.
 Go back to summary buffer."
   (interactive)
   (rmail-abort-edit)
-  (pop-to-buffer rmail-summary-buffer))
+  (rmail-pop-to-buffer rmail-summary-buffer))
 
 (defun rmail-summary-search-backward (regexp &optional n)
   "Show message containing next match for REGEXP.
@@ -1508,12 +1490,8 @@ Interactively, empty argument means use same regexp used last time."
            (prefix-numeric-value current-prefix-arg))))
   ;; Don't use save-excursion because that prevents point from moving
   ;; properly in the summary buffer.
-  (let ((buffer (current-buffer)))
-    (unwind-protect
-       (progn
-         (set-buffer rmail-buffer)
-         (rmail-search regexp (- n)))
-      (set-buffer buffer))))
+  (with-current-buffer rmail-buffer
+    (rmail-search regexp (- n))))
 
 (defun rmail-summary-search (regexp &optional n)
   "Show message containing next match for REGEXP.
@@ -1544,7 +1522,7 @@ Interactively, empty argument means use same regexp used last time."
        (selwin (selected-window)))
     (unwind-protect
        (progn
-         (pop-to-buffer rmail-buffer)
+         (rmail-pop-to-buffer rmail-buffer)
          (rmail-search regexp n))
       (select-window selwin)
       (set-buffer buffer))))
@@ -1571,21 +1549,17 @@ Interactively, empty argument means use same regexp used last time."
 (defun rmail-summary-add-label (label)
   "Add LABEL to labels associated with current Rmail message.
 Completion is performed over known labels when reading."
-  (interactive (list (save-excursion
-                      (set-buffer rmail-buffer)
+  (interactive (list (with-current-buffer rmail-buffer
                       (rmail-read-label "Add label"))))
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (rmail-add-label label)))
 
 (defun rmail-summary-kill-label (label)
   "Remove LABEL from labels associated with current Rmail message.
 Completion is performed over known labels when reading."
-  (interactive (list (save-excursion
-                      (set-buffer rmail-buffer)
+  (interactive (list (with-current-buffer rmail-buffer
                       (rmail-read-label "Kill label"))))
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (rmail-set-label label nil)))
 \f
 ;;;; *** Rmail Summary Mailing Commands ***
@@ -1752,8 +1726,7 @@ Also set the default for subsequent \\[rmail-output-to-babyl-file] commands.
 The variables `rmail-secondary-file-directory' and
 `rmail-secondary-file-regexp' control which files are offered in the menu."
   (interactive)
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (let ((rmail-delete-after-output nil))
       (call-interactively 'rmail-output-menu)))
   (if rmail-delete-after-output
@@ -1782,8 +1755,7 @@ The variables `rmail-secondary-file-directory' and
   "Write this message body to the file FILE-NAME.
 FILE-NAME defaults, interactively, from the Subject field of the message."
   (interactive)
-  (save-excursion
-    (set-buffer rmail-buffer)
+  (with-current-buffer rmail-buffer
     (let ((rmail-delete-after-output nil))
       (if file-name
          (rmail-output-body-to-file file-name)
@@ -1824,7 +1796,7 @@ If prefix argument REVERSE is non-nil, sorts in reverse order."
   "Sort messages of current Rmail summary by other correspondent.
 This uses either the \"From\", \"Sender\", \"To\", or
 \"Apparently-To\" header, downcased.  Uses the first header not
-excluded by `rmail-dont-reply-to-names'.  If prefix argument
+excluded by `mail-dont-reply-to-names'.  If prefix argument
 REVERSE is non-nil, sorts in reverse order."
   (interactive "P")
   (rmail-sort-from-summary (function rmail-sort-by-correspondent) reverse))
@@ -1852,11 +1824,14 @@ the summary is only showing a subset of messages."
   (require 'rmailsort)
   (let ((selwin (selected-window)))
     (unwind-protect
-       (progn (pop-to-buffer rmail-buffer)
+       (progn (rmail-pop-to-buffer rmail-buffer)
               (funcall sortfun reverse))
       (select-window selwin))))
 
 (provide 'rmailsum)
 
-;; arch-tag: 80b0a27a-a50d-4f37-9466-83d32d1e0ca8
+;; Local Variables:
+;; generated-autoload-file: "rmail.el"
+;; End:
+
 ;;; rmailsum.el ends here