]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/rmail.el
Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[gnu-emacs] / lisp / mail / rmail.el
index d2b9890805c21bfbd0dfb5526853c43f157e82b1..a05cd342862544dc27581646311e3a66e60444a9 100644 (file)
@@ -1,7 +1,7 @@
 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs
 
-;; Copyright (C) 1985-1988, 1993-1998, 2000-2012
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1985-1988, 1993-1998, 2000-2013 Free Software
+;; Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: mail
@@ -100,7 +100,9 @@ its character representation and its display representation.")
   "The current header display style choice, one of
 'normal (selected headers) or 'full (all headers).")
 
-;; rmail-spool-directory and rmail-file-name are defined in paths.el.
+(defvar rmail-mime-decoded nil
+  "Non-nil if message has been processed by `rmail-show-mime-function'.")
+(put 'rmail-mime-decoded 'permanent-local t) ; for rmail-edit
 
 (defgroup rmail nil
   "Mail reader for Emacs."
@@ -143,6 +145,40 @@ its character representation and its display representation.")
   :prefix "rmail-edit-"
   :group 'rmail)
 
+;;;###autoload
+(defcustom rmail-file-name (purecopy "~/RMAIL")
+  "Name of user's primary mail file."
+  :type 'string
+  :group 'rmail
+  :version "21.1")
+
+;;;###autoload
+(put 'rmail-spool-directory 'standard-value
+     '((cond ((file-exists-p "/var/mail") "/var/mail/")
+            ((file-exists-p "/var/spool/mail") "/var/spool/mail/")
+            ((memq system-type '(hpux usg-unix-v irix)) "/usr/mail/")
+            (t "/usr/spool/mail/"))))
+
+;;;###autoload
+(defcustom rmail-spool-directory
+  (purecopy
+  (cond ((file-exists-p "/var/mail")
+        ;; SVR4 and recent BSD are said to use this.
+        ;; Rather than trying to know precisely which systems use it,
+        ;; let's assume this dir is never used for anything else.
+        "/var/mail/")
+       ;; Many GNU/Linux systems use this name.
+       ((file-exists-p "/var/spool/mail") "/var/spool/mail/")
+       ((memq system-type '(hpux usg-unix-v irix)) "/usr/mail/")
+       (t "/usr/spool/mail/")))
+  "Name of directory used by system mailer for delivering new mail.
+Its name should end with a slash."
+  :initialize 'custom-initialize-delay
+  :type 'directory
+  :group 'rmail)
+
+;;;###autoload(custom-initialize-delay 'rmail-spool-directory nil)
+
 (defcustom rmail-movemail-program nil
   "If non-nil, the file name of the `movemail' program."
   :group 'rmail-retrieve
@@ -631,6 +667,7 @@ Element N specifies the summary line for message N+1.")
 (defvar rmail-last-regexp nil)
 (put 'rmail-last-regexp 'permanent-local t)
 
+;; Note that rmail-output-read-file-name modifies this.
 (defcustom rmail-default-file "~/xmail"
   "Default file name for \\[rmail-output]."
   :type 'file
@@ -713,19 +750,6 @@ to an appropriate value, and optionally also set
 `rmail-insert-mime-forwarded-message-function', and
 `rmail-insert-mime-resent-message-function'.")
 
-;; FIXME this is unused since 23.1.
-(defvar rmail-decode-mime-charset t
-  "Non-nil means a message is decoded by MIME's charset specification.
-If this variable is nil, or the message has not MIME specification,
-the message is decoded as normal way.
-
-If the variable `rmail-enable-mime' is non-nil, this variable is
-ignored, and all the decoding work is done by a feature specified by
-the variable `rmail-mime-feature'.")
-
-(make-obsolete-variable 'rmail-decode-mime-charset
-                       "it does nothing." "23.1")
-
 (defvar rmail-mime-charset-pattern
   (concat "^content-type:[ \t]*text/plain;"
          "\\(?:[ \t\n]*\\(?:format\\|delsp\\)=\"?[-a-z0-9]+\"?;\\)*"
@@ -2679,6 +2703,27 @@ N defaults to the current message."
   :group 'rmail
   :version "23.1")
 
+;; FIXME?
+;; rmail-show-mime-function does not unquote >From lines.  Should it?
+(defcustom rmail-mbox-format 'mboxrd
+  "The mbox format that your system uses.
+There is no way to determine this, so you should set the appropriate value.
+The formats quote lines containing \"From \" differently.
+The choices are:
+  `mboxo' : lines that start with \"From \" quoted as \">From \"
+  `mboxrd': lines that start with \">*From \" quoted with another \">\"
+The `mboxo' format is ambiguous, in that one cannot know whether
+a line starting with \">From \" originally had a \">\" or not.
+
+It is not critical to set this to the correct value; it only affects
+how Rmail displays lines starting with \">*From \" in non-MIME messages.
+
+See also `unrmail-mbox-format'."
+  :type '(choice (const mboxrd)
+                (const mboxro))
+  :version "24.4"
+  :group 'rmail-files)
+
 (defun rmail-show-message-1 (&optional msg)
   "Show message MSG (default: current message) using `rmail-view-buffer'.
 Return text to display in the minibuffer if MSG is out of
@@ -2727,6 +2772,7 @@ The current mail message becomes the message displayed."
                 (re-search-forward "mime-version: 1.0" nil t))
            (let ((rmail-buffer mbox-buf)
                  (rmail-view-buffer view-buf))
+             (set (make-local-variable 'rmail-mime-decoded) t)
              (funcall rmail-show-mime-function))
          (setq body-start (search-forward "\n\n" nil t))
          (narrow-to-region beg (point))
@@ -2771,11 +2817,15 @@ The current mail message becomes the message displayed."
            ;; Prepare the separator (blank line) before the body.
            (goto-char (point-min))
            (insert "\n")
-           ;; Unquote quoted From lines
-           (while (re-search-forward "^>+From " nil t)
-             (beginning-of-line)
-             (delete-char 1)
-             (forward-line))
+           ;; Unquote quoted From lines.
+           (let ((fromline (if (eq 'mboxrd rmail-mbox-format)
+                               "^>+From "
+                             "^>From "))
+                 case-fold-search)
+             (while (re-search-forward fromline nil t)
+               (beginning-of-line)
+               (delete-char 1)
+               (forward-line)))
            (goto-char (point-min)))
          ;; Copy the headers to the front of the message view buffer.
          (rmail-copy-headers beg end)
@@ -3570,8 +3620,17 @@ If BUFFER is not swapped, yank out of its message viewer buffer."
   (with-current-buffer buffer
     (unless (rmail-buffers-swapped-p)
       (setq buffer rmail-view-buffer)))
-  (insert-buffer buffer))
-
+  (insert-buffer-substring buffer)
+  ;; If they yank the text of BUFFER, the encoding of BUFFER is a
+  ;; better default for the reply message than the default value of
+  ;; buffer-file-coding-system.
+  (and (coding-system-equal (default-value 'buffer-file-coding-system)
+                           buffer-file-coding-system)
+       (setq buffer-file-coding-system
+            (coding-system-change-text-conversion
+             buffer-file-coding-system (coding-system-base
+                                        (with-current-buffer buffer
+                                          buffer-file-coding-system))))))
 
 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
                                   replybuffer sendactions same-window
@@ -3840,6 +3899,7 @@ see the documentation of `rmail-resend'."
          (msgnum rmail-current-message)
          (subject (concat "["
                           (let ((from (or (mail-fetch-field "From")
+                                          ;; FIXME - huh?
                                           (mail-fetch-field ">From"))))
                             (if from
                                 (concat (mail-strip-quoted-names from) ": ")
@@ -4039,6 +4099,13 @@ The variable `rmail-retry-ignored-headers' is a regular expression
 specifying headers which should not be copied into the new message."
   (interactive)
   (require 'mail-utils)
+  (if rmail-enable-mime
+      (with-current-buffer rmail-buffer
+       (if (rmail-mime-message-p)
+           (let ((rmail-mime-mbox-buffer rmail-view-buffer)
+                 (rmail-mime-view-buffer rmail-buffer))
+             (rmail-mime-toggle-raw 'raw)))))
+
   (let ((rmail-this-buffer (current-buffer))
        (msgnum rmail-current-message)
        bounce-start bounce-end bounce-indent resending
@@ -4157,29 +4224,25 @@ This has an effect only if a summary buffer exists."
 
 ;; Put the summary buffer back on the screen, if user wants that.
 (defun rmail-maybe-display-summary ()
-  (let ((selected (selected-window))
-       window)
-    ;; If requested, make sure the summary is displayed.
-    (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
-        rmail-redisplay-summary
-        (if (get-buffer-window rmail-summary-buffer 0)
-            ;; It's already in some frame; show that one.
-            (let ((frame (window-frame
-                          (get-buffer-window rmail-summary-buffer 0))))
-              (make-frame-visible frame)
-              (raise-frame frame))
-          (display-buffer rmail-summary-buffer)))
-    ;; If requested, set the height of the summary window.
-    (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
-        rmail-summary-window-size
-        (setq window (get-buffer-window rmail-summary-buffer))
-        ;; Don't try to change the size if just one window in frame.
-        (not (eq window (frame-root-window (window-frame window))))
-        (unwind-protect
-            (progn
-              (select-window window)
-              (enlarge-window (- rmail-summary-window-size (window-height))))
-          (select-window selected)))))
+  (cond
+   ((or (not rmail-summary-buffer)
+       (not (buffer-name rmail-summary-buffer))))
+   (rmail-redisplay-summary
+    ;; If `rmail-redisplay-summary' is non-nil, make sure the summary
+    ;; buffer is displayed.
+    (display-buffer
+     rmail-summary-buffer
+     `(nil
+       (reusable-frames . 0)
+       ,(when rmail-summary-window-size
+         `(window-height . ,rmail-summary-window-size)))))
+   (rmail-summary-window-size
+    ;; If `rmail-summary-window-size' is non-nil and the summary buffer
+    ;; is displayed, make sure it gets resized.
+    (let ((window (get-buffer-window rmail-summary-buffer 0)))
+      (when window
+       (window-resize-no-error
+        window (- rmail-summary-window-size (window-height window))))))))
 \f
 ;;;; *** Rmail Local Fontification ***
 
@@ -4222,10 +4285,13 @@ This has an effect only if a summary buffer exists."
 ;;; Speedbar support for RMAIL files.
 (eval-when-compile (require 'speedbar))
 
-(defvar rmail-speedbar-match-folder-regexp "^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
-  "This regex is used to match folder names to be displayed in speedbar.
-Enabling this will permit speedbar to display your folders for easy
-browsing, and moving of messages.")
+(defcustom rmail-speedbar-match-folder-regexp "^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
+  "Regexp matching Rmail folder names to be displayed in Speedbar.
+Enabling this permits Speedbar to display your folders for easy
+browsing, and moving of messages."
+  :type 'regexp
+  :group 'rmail
+  :group 'speedbar)
 
 (defvar rmail-speedbar-last-user nil
   "The last user to be displayed in the speedbar.")
@@ -4511,7 +4577,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"
-;;;;;;  "7d558f958574f6003fa474ce2f3c80a8")
+;;;;;;  "0b056146d4775080a1847b8ce7527bc5")
 ;;; Generated autoloads from rmailedit.el
 
 (autoload 'rmail-edit-current-message "rmailedit" "\
@@ -4523,7 +4589,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" "4ae5660d86d49e524f4a6bcbc6d9a984")
+;;;;;;  "rmailkwd.el" "b5337290fd35bbc11888afb25d767195")
 ;;; Generated autoloads from rmailkwd.el
 
 (autoload 'rmail-add-label "rmailkwd" "\
@@ -4566,7 +4632,7 @@ With prefix argument N moves forward N messages with these labels.
 
 ;;;***
 \f
-;;;### (autoloads (rmail-mime) "rmailmm" "rmailmm.el" "be7f4b94a269f840b8707defd515c4f9")
+;;;### (autoloads (rmail-mime) "rmailmm" "rmailmm.el" "1f33964668345a1a1f3119fece148227")
 ;;; Generated autoloads from rmailmm.el
 
 (autoload 'rmail-mime "rmailmm" "\
@@ -4593,7 +4659,7 @@ The arguments ARG and STATE have no effect in this case.
 ;;;***
 \f
 ;;;### (autoloads (set-rmail-inbox-list) "rmailmsc" "rmailmsc.el"
-;;;;;;  "e2212ea15561d60365ffa1f7a5902939")
+;;;;;;  "8a2466563b4a463710531d01766c07a3")
 ;;; Generated autoloads from rmailmsc.el
 
 (autoload 'set-rmail-inbox-list "rmailmsc" "\
@@ -4609,7 +4675,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" "38da5f17d4ed0dcd2b09c158642cef63")
+;;;;;;  rmail-sort-by-date) "rmailsort" "rmailsort.el" "3e3a30326fc95d7f17835906c2ccb19f")
 ;;; Generated autoloads from rmailsort.el
 
 (autoload 'rmail-sort-by-date "rmailsort" "\
@@ -4668,7 +4734,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" "bef21a376bd5bd59792a20dd86e6ec34")
+;;;;;;  rmail-summary) "rmailsum" "rmailsum.el" "341825201e892b8fc875c1ae49ffd560")
 ;;; Generated autoloads from rmailsum.el
 
 (autoload 'rmail-summary "rmailsum" "\
@@ -4716,7 +4782,7 @@ SENDERS is a string of regexps separated by commas.
 ;;;***
 \f
 ;;;### (autoloads (unforward-rmail-message undigestify-rmail-message)
-;;;;;;  "undigest" "undigest.el" "9f270a2571bbbbfabc27498a8d4089c7")
+;;;;;;  "undigest" "undigest.el" "9b273a3e15b5496ab6121b585d8bd3b3")
 ;;; Generated autoloads from undigest.el
 
 (autoload 'undigestify-rmail-message "undigest" "\