2001-08-08 15:00:00 ShengHuo ZHU <zsh@cs.rochester.edu>
[gnus] / lisp / message.el
index f66ea77..0e3ccfe 100644 (file)
@@ -32,7 +32,7 @@
 
 (eval-when-compile
   (require 'cl)
-  (defvar gnus-list-identifiers))      ; gnus-sum is required where necessary
+  (defvar gnus-list-identifiers)) ; gnus-sum is required where necessary
 (require 'mailheader)
 (require 'nnheader)
 ;; This is apparently necessary even though things are autoloaded:
@@ -169,7 +169,7 @@ Checks include `subject-cmsg', `multiple-headers', `sendsys',
 `new-text', `quoting-style', `redirected-followup', `signature',
 `approved', `sender', `empty', `empty-headers', `message-id', `from',
 `subject', `shorten-followup-to', `existing-newsgroups',
-`buffer-file-name', `unchanged', `newsgroups'."
+`buffer-file-name', `unchanged', `newsgroups', `reply-to'."
   :group 'message-news
   :type '(repeat sexp))                        ; Fixme: improve this
 
@@ -401,7 +401,7 @@ and respond with new To and Cc headers."
   :group 'message-interface
   :type '(choice function (const nil)))
 
-(defcustom message-use-followup-to t
+(defcustom message-use-followup-to 'ask
   "*Specifies what to do with Followup-To header.
 If nil, always ignore the header.  If it is t, use its value, but
 query before using the \"poster\" value.  If it is the symbol `ask',
@@ -413,6 +413,16 @@ always query the user whether to use the value.  If it is the symbol
                 (const use)
                 (const ask)))
 
+(defcustom message-use-mail-followup-to 'use
+  "*Specifies what to do with Mail-Followup-To header.
+If nil, always ignore the header.  If it is the symbol `ask', always
+query the user whether to use the value.  If it is the symbol `use',
+always use the value."
+  :group 'message-interface
+  :type '(choice (const :tag "ignore" nil)
+                (const use)
+                (const ask)))
+
 (defcustom message-sendmail-f-is-evil nil
   "*Non-nil means don't add \"-f username\" to the sendmail command line.
 Doing so would be even more evil than leaving it out."
@@ -512,14 +522,27 @@ the signature is inserted."
 
 ;;;###autoload
 (defcustom message-citation-line-function 'message-insert-citation-line
-  "*Function called to insert the \"Whomever writes:\" line."
+  "*Function called to insert the \"Whomever writes:\" line.
+
+Note that Gnus provides a feature where the reader can click on
+`writes:' to hide the cited text.  If you change this line too much,
+people who read your message will have to change their Gnus
+configuration.  See the variable `gnus-cite-attribution-suffix'."
   :type 'function
   :group 'message-insertion)
 
 ;;;###autoload
 (defcustom message-yank-prefix "> "
   "*Prefix inserted on the lines of yanked messages.
-Fix `message-cite-prefix-regexp' if it is set to an abnormal value."
+Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
+See also `message-yank-cited-prefix'."
+  :type 'string
+  :group 'message-insertion)
+
+(defcustom message-yank-cited-prefix ">"
+  "*Prefix inserted on cited or empty lines of yanked messages.
+Fix `message-cite-prefix-regexp' if it is set to an abnormal value.
+See also `message-yank-prefix'."
   :type 'string
   :group 'message-insertion)
 
@@ -748,10 +771,6 @@ candidates:
     table)
   "Syntax table used while in Message mode.")
 
-(defvar message-mode-abbrev-table text-mode-abbrev-table
-  "Abbrev table used in Message mode buffers.
-Defaults to `text-mode-abbrev-table'.")
-
 (defface message-header-to-face
   '((((class color)
       (background dark))
@@ -980,6 +999,16 @@ Except if it is nil, use Gnus native MUA; if it is t, use
   :version "21.1"
   :group 'message)
 
+(defcustom message-wide-reply-confirm-recipients nil
+  "Whether to confirm a wide reply to multiple email recipients.
+If this variable is nil, don't ask whether to reply to all recipients.
+If this variable is non-nil, pose the question \"Reply to all
+recipients?\" before a wide reply to multiple recipients.  If the user
+answers yes, reply to all recipients as usual.  If the user answers
+no, only reply back to the author."
+  :group 'message-headers
+  :type 'boolean)
+
 ;;; Internal variables.
 
 (defvar message-sending-message "Sending...")
@@ -1082,6 +1111,9 @@ Except if it is nil, use Gnus native MUA; if it is t, use
 (defvar        message-options nil
   "Some saved answers when sending message.")
 
+(defvar message-send-mail-real-function nil
+  "Internal send mail function.")
+
 (eval-and-compile
   (autoload 'message-setup-toolbar "messagexmas")
   (autoload 'mh-new-draft-name "mh-comp")
@@ -1118,11 +1150,11 @@ Except if it is nil, use Gnus native MUA; if it is t, use
 (defun message-unquote-tokens (elems)
   "Remove double quotes (\") from strings in list ELEMS."
   (mapcar (lambda (item)
-            (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
-              (setq item (concat (match-string 1 item)
-                                 (match-string 2 item))))
-            item)
-          elems))
+           (while (string-match "^\\(.*\\)\"\\(.*\\)$" item)
+             (setq item (concat (match-string 1 item)
+                                (match-string 2 item))))
+           item)
+         elems))
 
 (defun message-tokenize-header (header &optional separator)
   "Split HEADER into a list of header elements.
@@ -1157,7 +1189,7 @@ is used by default."
                ((and (eq (char-after) ?\))
                      (not quoted))
                 (setq paren nil))))
-        (nreverse elems)))))
+       (nreverse elems)))))
 
 (defun message-mail-file-mbox-p (file)
   "Say whether FILE looks like a Unix mbox file."
@@ -1241,7 +1273,7 @@ is used by default."
                    gnus-list-identifiers
                  (mapconcat 'identity gnus-list-identifiers " *\\|"))))
     (if (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
-                               " *\\)\\)+\\(Re: +\\)?\\)") subject)
+                             " *\\)\\)+\\(Re: +\\)?\\)") subject)
        (concat (substring subject 0 (match-beginning 1))
                (or (match-string 3 subject)
                    (match-string 5 subject))
@@ -1464,53 +1496,53 @@ Point is left at the beginning of the narrowed-to region."
   (define-key message-mode-map "\M-;" 'comment-region))
 
 (easy-menu-define
- message-mode-menu message-mode-map "Message Menu."
- `("Message"
-   ["Sort Headers" message-sort-headers t]
-   ["Yank Original" message-yank-original t]
-   ["Fill Yanked Message" message-fill-yanked-message t]
-   ["Insert Signature" message-insert-signature t]
-   ["Caesar (rot13) Message" message-caesar-buffer-body t]
-   ["Caesar (rot13) Region" message-caesar-region (mark t)]
-   ["Elide Region" message-elide-region (mark t)]
-   ["Delete Outside Region" message-delete-not-region (mark t)]
-   ["Kill To Signature" message-kill-to-signature t]
-   ["Newline and Reformat" message-newline-and-reformat t]
-   ["Rename buffer" message-rename-buffer t]
-   ["Spellcheck" ispell-message
-    ,@(if (featurep 'xemacs) '(t)
-       '(:help "Spellcheck this message"))]
-   ["Attach file as MIME" mml-attach-file
-    ,@(if (featurep 'xemacs) '(t)
-       '(:help "Attach a file at point"))]
-   "----"
-   ["Send Message" message-send-and-exit
-    ,@(if (featurep 'xemacs) '(t)
-       '(:help "Send this message"))]
-   ["Abort Message" message-dont-send
-    ,@(if (featurep 'xemacs) '(t)
-       '(:help "File this draft message and exit"))]
-   ["Kill Message" message-kill-buffer
-    ,@(if (featurep 'xemacs) '(t)
-       '(:help "Delete this message without sending"))]))
 message-mode-menu message-mode-map "Message Menu."
 `("Message"
+    ["Sort Headers" message-sort-headers t]
+    ["Yank Original" message-yank-original t]
+    ["Fill Yanked Message" message-fill-yanked-message t]
+    ["Insert Signature" message-insert-signature t]
+    ["Caesar (rot13) Message" message-caesar-buffer-body t]
+    ["Caesar (rot13) Region" message-caesar-region (mark t)]
+    ["Elide Region" message-elide-region (mark t)]
+    ["Delete Outside Region" message-delete-not-region (mark t)]
+    ["Kill To Signature" message-kill-to-signature t]
+    ["Newline and Reformat" message-newline-and-reformat t]
+    ["Rename buffer" message-rename-buffer t]
+    ["Spellcheck" ispell-message
+     ,@(if (featurep 'xemacs) '(t)
+        '(:help "Spellcheck this message"))]
+    ["Attach file as MIME" mml-attach-file
+     ,@(if (featurep 'xemacs) '(t)
+        '(:help "Attach a file at point"))]
+    "----"
+    ["Send Message" message-send-and-exit
+     ,@(if (featurep 'xemacs) '(t)
+        '(:help "Send this message"))]
+    ["Abort Message" message-dont-send
+     ,@(if (featurep 'xemacs) '(t)
+        '(:help "File this draft message and exit"))]
+    ["Kill Message" message-kill-buffer
+     ,@(if (featurep 'xemacs) '(t)
+        '(:help "Delete this message without sending"))]))
 
 (easy-menu-define
- message-mode-field-menu message-mode-map ""
- '("Field"
-   ["Fetch To" message-insert-to t]
-   ["Fetch Newsgroups" message-insert-newsgroups t]
-   "----"
-   ["To" message-goto-to t]
-   ["Subject" message-goto-subject t]
-   ["Cc" message-goto-cc t]
-   ["Reply-To" message-goto-reply-to t]
-   ["Summary" message-goto-summary t]
-   ["Keywords" message-goto-keywords t]
-   ["Newsgroups" message-goto-newsgroups t]
-   ["Followup-To" message-goto-followup-to t]
-   ["Distribution" message-goto-distribution t]
-   ["Body" message-goto-body t]
-   ["Signature" message-goto-signature t]))
 message-mode-field-menu message-mode-map ""
 '("Field"
+    ["Fetch To" message-insert-to t]
+    ["Fetch Newsgroups" message-insert-newsgroups t]
+    "----"
+    ["To" message-goto-to t]
+    ["Subject" message-goto-subject t]
+    ["Cc" message-goto-cc t]
+    ["Reply-To" message-goto-reply-to t]
+    ["Summary" message-goto-summary t]
+    ["Keywords" message-goto-keywords t]
+    ["Newsgroups" message-goto-newsgroups t]
+    ["Followup-To" message-goto-followup-to t]
+    ["Distribution" message-goto-distribution t]
+    ["Body" message-goto-body t]
+    ["Signature" message-goto-signature t]))
 
 (defvar message-tool-bar-map nil)
 
@@ -1519,7 +1551,7 @@ Point is left at the beginning of the narrowed-to region."
   (defvar facemenu-remove-face-function))
 
 ;;;###autoload
-(defun message-mode ()
+(define-derived-mode message-mode text-mode "Message"
   "Major mode for editing mail and news to be sent.
 Like Text Mode but with these additional commands:\\<message-mode-map>
 C-c C-s  `message-send' (send the message)  C-c C-c  `message-send-and-exit'
@@ -1544,35 +1576,22 @@ C-c C-z  `message-kill-to-signature' (kill the text up to the signature).
 C-c C-r  `message-caesar-buffer-body' (rot13 the message body).
 C-c C-a  `mml-attach-file' (attach a file as MIME).
 M-RET    `message-newline-and-reformat' (break the line and reformat)."
-  (interactive)
-  (if (local-variable-p 'mml-buffer-list (current-buffer))
-      (mml-destroy-buffers))
-  (kill-all-local-variables)
   (set (make-local-variable 'message-reply-buffer) nil)
   (make-local-variable 'message-send-actions)
   (make-local-variable 'message-exit-actions)
   (make-local-variable 'message-kill-actions)
   (make-local-variable 'message-postpone-actions)
   (make-local-variable 'message-draft-article)
-  (make-local-hook 'kill-buffer-hook)
-  (set-syntax-table message-mode-syntax-table)
-  (use-local-map message-mode-map)
-  (setq local-abbrev-table message-mode-abbrev-table)
-  (setq major-mode 'message-mode)
-  (setq mode-name "Message")
   (setq buffer-offer-save t)
-  (make-local-variable 'facemenu-add-face-function)
-  (make-local-variable 'facemenu-remove-face-function)
-  (setq facemenu-add-face-function
-       (lambda (face end)
-         (let ((face-fun (cdr (assq face message-face-alist))))
-           (if face-fun
-               (funcall face-fun (point) end)
-             (error "Face %s not configured for %s mode" face mode-name)))
-         "")
-       facemenu-remove-face-function t)
-  (make-local-variable 'message-reply-headers)
-  (setq message-reply-headers nil)
+  (set (make-local-variable 'facemenu-add-face-function)
+       (lambda (face end)
+        (let ((face-fun (cdr (assq face message-face-alist))))
+          (if face-fun
+              (funcall face-fun (point) end)
+            (error "Face %s not configured for %s mode" face mode-name)))
+        ""))
+  (set (make-local-variable 'facemenu-remove-face-function) t)
+  (set (make-local-variable 'message-reply-headers) nil)
   (make-local-variable 'message-newsreader)
   (make-local-variable 'message-mailer)
   (make-local-variable 'message-post-method)
@@ -1597,10 +1616,9 @@ M-RET    `message-newline-and-reformat' (break the line and reformat)."
       (mail-aliases-setup)))
   (message-set-auto-save-file-name)
   (mm-enable-multibyte)
-  (make-local-variable 'indent-tabs-mode) ;Turn off tabs for indentation.
-  (setq indent-tabs-mode nil)
-  (mml-mode)
-  (run-hooks 'text-mode-hook 'message-mode-hook))
+  (set (make-local-variable 'indent-line-function) 'indent-relative)
+  (set (make-local-variable 'indent-tabs-mode) nil) ;No tabs for indentation.
+  (mml-mode))
 
 (defun message-setup-fill-variables ()
   "Setup message fill variables."
@@ -1616,22 +1634,22 @@ M-RET    `message-newline-and-reformat' (break the line and reformat)."
   (let ((quote-prefix-regexp
         ;; User should change message-cite-prefix-regexp if
         ;; message-yank-prefix is set to an abnormal value.
-         (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
+        (concat "\\(" message-cite-prefix-regexp "\\)[ \t]*")))
     (setq paragraph-start
-          (concat
-           (regexp-quote mail-header-separator) "$\\|"
-           "[ \t]*$\\|"                 ; blank lines
-           "-- $\\|"                    ; signature delimiter
-           "---+$\\|"                   ; delimiters for forwarded messages
-           page-delimiter "$\\|"        ; spoiler warnings
-           ".*wrote:$\\|"               ; attribution lines
-           quote-prefix-regexp "$"))    ; empty lines in quoted text
+         (concat
+          (regexp-quote mail-header-separator) "$\\|"
+          "[ \t]*$\\|"                 ; blank lines
+          "-- $\\|"                    ; signature delimiter
+          "---+$\\|"              ; delimiters for forwarded messages
+          page-delimiter "$\\|"        ; spoiler warnings
+          ".*wrote:$\\|"               ; attribution lines
+          quote-prefix-regexp "$"))    ; empty lines in quoted text
     (setq paragraph-separate paragraph-start)
     (setq adaptive-fill-regexp
-          (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
+         (concat quote-prefix-regexp "\\|" adaptive-fill-regexp))
     (setq adaptive-fill-first-line-regexp
-          (concat quote-prefix-regexp "\\|"
-                  adaptive-fill-first-line-regexp))
+         (concat quote-prefix-regexp "\\|"
+                 adaptive-fill-first-line-regexp))
     (setq auto-fill-inhibit-regexp "^[A-Z][^: \n\t]+:")))
 
 \f
@@ -1705,7 +1723,7 @@ M-RET    `message-newline-and-reformat' (break the line and reformat)."
     (expand-abbrev))
   (goto-char (point-min))
   (or (search-forward (concat "\n" mail-header-separator "\n") nil t)
-      (search-forward "\n\n" nil t)))
+      (search-forward-regexp "[^:]+:\\([^\n]\\|\n[ \t]\\)+\n\n" nil t)))
 
 (defun message-goto-eoh ()
   "Move point to the end of the headers."
@@ -1780,17 +1798,25 @@ With the prefix argument FORCE, insert the header anyway."
 (defun message-delete-not-region (beg end)
   "Delete everything in the body of the current message outside of the region."
   (interactive "r")
-  (save-excursion
-    (goto-char end)
-    (delete-region (point) (if (not (message-goto-signature))
-                              (point)
-                            (forward-line -2)
-                            (point)))
-    (insert "\n")
-    (goto-char beg)
-    (delete-region beg (progn (message-goto-body)
-                             (forward-line 2)
-                             (point))))
+  (let (citeprefix)
+    (save-excursion
+      (goto-char beg)
+      ;; snarf citation prefix, if appropriate
+      (unless (eq (point) (progn (beginning-of-line) (point)))
+       (when (looking-at message-cite-prefix-regexp)
+         (setq citeprefix (match-string 0))))
+      (goto-char end)
+      (delete-region (point) (if (not (message-goto-signature))
+                                (point)
+                              (forward-line -2)
+                              (point)))
+      (insert "\n")
+      (goto-char beg)
+      (delete-region beg (progn (message-goto-body)
+                               (forward-line 2)
+                               (point)))
+      (when citeprefix
+       (insert citeprefix))))
   (when (message-goto-signature)
     (forward-line -2)))
 
@@ -1818,7 +1844,7 @@ Prefix arg means justify as well."
     (if not-break
        (while (and (not (eobp))
                    (not (looking-at message-cite-prefix-regexp))
-               (looking-at paragraph-start))
+                   (looking-at paragraph-start))
          (forward-line 1)))
     ;; Find the prefix
     (when (looking-at message-cite-prefix-regexp)
@@ -1881,7 +1907,7 @@ Prefix arg means justify as well."
          (insert quoted leading-space)))
       (if quoted
          (let* ((adaptive-fill-regexp
-                (regexp-quote (concat quoted leading-space)))
+                 (regexp-quote (concat quoted leading-space)))
                 (adaptive-fill-first-line-regexp
                  adaptive-fill-regexp ))
            (fill-paragraph arg))
@@ -1891,8 +1917,10 @@ Prefix arg means justify as well."
 (defun message-fill-paragraph (&optional arg)
   "Like `fill-paragraph'."
   (interactive (list (if current-prefix-arg 'full)))
-  (message-newline-and-reformat arg t)
-  t)
+  (if (and (boundp 'filladapt-mode) filladapt-mode)
+      nil
+    (message-newline-and-reformat arg t)
+    t))
 
 (defun message-insert-signature (&optional force)
   "Insert a signature.  See documentation for variable `message-signature'."
@@ -1951,7 +1979,7 @@ text was killed."
       (prefix-numeric-value current-prefix-arg))))
 
   (setq n (if (numberp n) (mod n 26) 13)) ;canonize N
-  (unless (or (zerop n)                        ; no action needed for a rot of 0
+  (unless (or (zerop n)                        ; no action needed for a rot of 0
              (= b e))                  ; no region to rotate
     ;; We build the table, if necessary.
     (when (or (not message-caesar-translation-table)
@@ -1994,7 +2022,7 @@ Mail and USENET news headers are not rotated."
   (save-excursion
     (save-restriction
       (when (message-goto-body)
-        (narrow-to-region (point) (point-max)))
+       (narrow-to-region (point) (point-max)))
       (shell-command-on-region
        (point-min) (point-max) program nil t))))
 
@@ -2073,9 +2101,31 @@ However, if `message-yank-prefix' is non-nil, insert that prefix on each line."
        (indent-rigidly start (mark t) message-indentation-spaces)
       (save-excursion
        (goto-char start)
-       (while (< (point) (mark t))
-         (insert message-yank-prefix)
-         (forward-line 1))))
+       (let (last-line)
+         ;; `last-line' describes the contents of the last line
+         ;; encountered in the loop below. nil means "empty line",
+         ;; spaces "line consisting entirely of whitespace",
+         ;; right-angle "line starts with >", quoted "quote character
+         ;; at the beginning of the line", text "the remaining cases".
+         (while (< (point) (mark t))
+           (cond
+            ((eolp) 
+             (insert message-yank-cited-prefix)
+             (setq last-line nil))
+            ((looking-at ">")
+             (if (memq last-line '(nil spaces right-angle quoted))
+                 (progn
+                   (insert message-yank-cited-prefix)
+                   (setq last-line 'quoted))
+               (insert message-yank-prefix)
+               (setq last-line 'right-angle)))
+            ((looking-at "\\s-+$")
+             (insert message-yank-prefix)
+             (setq last-line 'spaces))
+            (t
+             (insert message-yank-prefix)
+             (setq last-line 'text)))
+           (forward-line 1)))))
     (goto-char start)))
 
 (defun message-yank-original (&optional arg)
@@ -2151,7 +2201,7 @@ prefix, and don't delete any headers."
        (insert "\n"))
       (funcall message-citation-line-function))))
 
-(eval-when-compile (defvar mail-citation-hook))                ;Compiler directive
+(eval-when-compile (defvar mail-citation-hook))        ;Compiler directive
 (defun message-cite-original ()
   "Cite function in the standard Message manner."
   (if (and (boundp 'mail-citation-hook)
@@ -2310,7 +2360,7 @@ It should typically alter the sending method in some way or other."
                            (format
                             "Already sent message via %s; resend? "
                             (car elem)))
-                        (error "Denied posting -- multiple copies.")))
+                        (error "Denied posting -- multiple copies")))
                   (setq success (funcall (caddr elem) arg)))
          (setq sent t))))
     (unless (or sent (not success))
@@ -2448,7 +2498,8 @@ It should typically alter the sending method in some way or other."
              (insert "\n")
              (widen)
              (mm-with-unibyte-current-buffer
-               (funcall message-send-mail-function)))
+               (funcall (or message-send-mail-real-function
+                            message-send-mail-function))))
            (setq n (+ n 1))
            (setq p (pop plist))
            (erase-buffer)))
@@ -2514,7 +2565,8 @@ It should typically alter the sending method in some way or other."
                  (not (y-or-n-p "Message exceeds message-send-mail-partially-limit, send in parts? ")))
              (mm-with-unibyte-current-buffer
                (message "Sending via mail...")
-               (funcall message-send-mail-function))
+               (funcall (or message-send-mail-real-function
+                            message-send-mail-function)))
            (message-send-mail-partially)))
       (kill-buffer tembuf))
     (set-buffer mailbuf)
@@ -2622,7 +2674,7 @@ to find out how to use this."
     ;; qmail-inject doesn't say anything on it's stdout/stderr,
     ;; we have to look at the retval instead
     (0 nil)
-    (1   (error "qmail-inject reported permanent failure"))
+    (100 (error "qmail-inject reported permanent failure"))
     (111 (error "qmail-inject reported transient failure"))
     ;; should never happen
     (t   (error "qmail-inject reported unknown failure"))))
@@ -2682,7 +2734,8 @@ to find out how to use this."
              (cons '(valid-newsgroups . disabled)
                    message-syntax-checks)))
       (message-cleanup-headers)
-      (if (not (message-check-news-syntax))
+      (if (not (let ((message-post-method method))
+                (message-check-news-syntax)))
          nil
        (unwind-protect
            (save-excursion
@@ -2858,17 +2911,22 @@ to find out how to use this."
                     (if followup-to
                         (concat newsgroups "," followup-to)
                       newsgroups)))
-           (hashtb (and (boundp 'gnus-active-hashtb)
-                        gnus-active-hashtb))
+           (known-groups
+            (mapcar (lambda (n) (gnus-group-real-name n))
+                    (gnus-groups-from-server
+                     (if (message-functionp message-post-method)
+                         (funcall message-post-method)
+                       message-post-method))))
            errors)
        (while groups
-        (when (and (not (boundp (intern (car groups) hashtb)))
-                   (not (equal (car groups) "poster")))
+        (unless (or (equal (car groups) "poster")
+                    (member (car groups) known-groups))
           (push (car groups) errors))
         (pop groups))
        (cond
        ;; Gnus is not running.
-       ((or (not hashtb)
+       ((or (not (and (boundp 'gnus-active-hashtb)
+                      gnus-active-hashtb))
             (not (boundp 'gnus-read-active-file)))
         t)
        ;; We don't have all the group names.
@@ -2892,69 +2950,95 @@ to find out how to use this."
           (if (= (length errors) 1) "this" "these")
           (if (= (length errors) 1) "" "s")
           (mapconcat 'identity errors ", ")))))))
-     ;; Check the Newsgroups & Followup-To headers for syntax errors.
-     (message-check 'valid-newsgroups
-       (let ((case-fold-search t)
-            (headers '("Newsgroups" "Followup-To"))
-            header error)
-        (while (and headers (not error))
-          (when (setq header (mail-fetch-field (car headers)))
-            (if (or
-                 (not
-                  (string-match
-                   "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
-                   header))
-                 (memq
-                  nil (mapcar
-                       (lambda (g)
-                         (not (string-match "\\.\\'\\|\\.\\." g)))
-                       (message-tokenize-header header ","))))
-                (setq error t)))
-          (unless error
-            (pop headers)))
-        (if (not error)
-            t
-          (y-or-n-p
-           (format "The %s header looks odd: \"%s\".  Really post? "
-                   (car headers) header)))))
-     (message-check 'repeated-newsgroups
-       (let ((case-fold-search t)
-            (headers '("Newsgroups" "Followup-To"))
-            header error groups group)
-        (while (and headers
-                    (not error))
-          (when (setq header (mail-fetch-field (pop headers)))
-            (setq groups (message-tokenize-header header ","))
-            (while (setq group (pop groups))
-              (when (member group groups)
-                (setq error group
-                      groups nil)))))
-        (if (not error)
-            t
-          (y-or-n-p
-           (format "Group %s is repeated in headers.  Really post? " error)))))
-     ;; Check the From header.
-     (message-check 'from
-       (let* ((case-fold-search t)
-             (from (message-fetch-field "from"))
-             ad)
-        (cond
-         ((not from)
-          (message "There is no From line.  Posting is denied.")
-          nil)
-         ((or (not (string-match
-                    "@[^\\.]*\\."
-                    (setq ad (nth 1 (mail-extract-address-components
-                                     from))))) ;larsi@ifi
-              (string-match "\\.\\." ad) ;larsi@ifi..uio
-              (string-match "@\\." ad) ;larsi@.ifi.uio
-              (string-match "\\.$" ad) ;larsi@ifi.uio.
-              (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
-              (string-match "(.*).*(.*)" from)) ;(lars) (lars)
-          (message
-           "Denied posting -- the From looks strange: \"%s\"." from)
-          nil)
-         (t t))))))
+   ;; Check the Newsgroups & Followup-To headers for syntax errors.
+   (message-check 'valid-newsgroups
+     (let ((case-fold-search t)
+          (headers '("Newsgroups" "Followup-To"))
+          header error)
+       (while (and headers (not error))
+        (when (setq header (mail-fetch-field (car headers)))
+          (if (or
+               (not
+                (string-match
+                 "\\`\\([-+_&.a-zA-Z0-9]+\\)?\\(,[-+_&.a-zA-Z0-9]+\\)*\\'"
+                 header))
+               (memq
+                nil (mapcar
+                     (lambda (g)
+                       (not (string-match "\\.\\'\\|\\.\\." g)))
+                     (message-tokenize-header header ","))))
+              (setq error t)))
+        (unless error
+          (pop headers)))
+       (if (not error)
+          t
+        (y-or-n-p
+         (format "The %s header looks odd: \"%s\".  Really post? "
+                 (car headers) header)))))
+   (message-check 'repeated-newsgroups
+     (let ((case-fold-search t)
+          (headers '("Newsgroups" "Followup-To"))
+          header error groups group)
+       (while (and headers
+                  (not error))
+        (when (setq header (mail-fetch-field (pop headers)))
+          (setq groups (message-tokenize-header header ","))
+          (while (setq group (pop groups))
+            (when (member group groups)
+              (setq error group
+                    groups nil)))))
+       (if (not error)
+          t
+        (y-or-n-p
+         (format "Group %s is repeated in headers.  Really post? " error)))))
+   ;; Check the From header.
+   (message-check 'from
+     (let* ((case-fold-search t)
+           (from (message-fetch-field "from"))
+           ad)
+       (cond
+       ((not from)
+        (message "There is no From line.  Posting is denied.")
+        nil)
+       ((or (not (string-match
+                  "@[^\\.]*\\."
+                  (setq ad (nth 1 (mail-extract-address-components
+                                   from))))) ;larsi@ifi
+            (string-match "\\.\\." ad) ;larsi@ifi..uio
+            (string-match "@\\." ad)   ;larsi@.ifi.uio
+            (string-match "\\.$" ad)   ;larsi@ifi.uio.
+            (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
+            (string-match "(.*).*(.*)" from)) ;(lars) (lars)
+        (message
+         "Denied posting -- the From looks strange: \"%s\"." from)
+        nil)
+       (t t))))
+   ;; Check the Reply-To header.
+   (message-check 'reply-to
+     (let* ((case-fold-search t)
+           (reply-to (message-fetch-field "reply-to"))
+           ad)
+       (cond
+       ((not reply-to)
+        t)
+       ((string-match "," reply-to)
+        (y-or-n-p
+         (format "Multiple Reply-To addresses: \"%s\". Really post? "
+                 reply-to)))
+       ((or (not (string-match
+                  "@[^\\.]*\\."
+                  (setq ad (nth 1 (mail-extract-address-components
+                                   reply-to))))) ;larsi@ifi
+            (string-match "\\.\\." ad) ;larsi@ifi..uio
+            (string-match "@\\." ad)   ;larsi@.ifi.uio
+            (string-match "\\.$" ad)   ;larsi@ifi.uio.
+            (not (string-match "^[^@]+@[^@]+$" ad)) ;larsi.ifi.uio
+            (string-match "(.*).*(.*)" reply-to)) ;(lars) (lars)
+        (y-or-n-p
+         (format
+          "The Reply-To looks strange: \"%s\". Really post? "
+          reply-to)))
+       (t t))))))
 
 (defun message-check-news-body-syntax ()
   (and
@@ -3050,8 +3134,8 @@ to find out how to use this."
        (concat "^" (regexp-quote mail-header-separator) "$"))
       (while (not (eobp))
        (when (not (looking-at "[ \t\n]"))
-         (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
-                           (char-after))))
+         (setq sum (logxor (ash sum 1) (if (natnump sum) 0 1)
+                           (char-after))))
        (forward-char 1)))
     sum))
 
@@ -3061,47 +3145,49 @@ to find out how to use this."
        (buf (current-buffer))
        list file)
     (save-excursion
-      (set-buffer (get-buffer-create " *message temp*"))
-      (erase-buffer)
-      (insert-buffer-substring buf)
-      (save-restriction
-       (message-narrow-to-headers)
-       (while (setq file (message-fetch-field "fcc"))
-         (push file list)
-         (message-remove-header "fcc" nil t)))
-      (message-encode-message-body)
       (save-restriction
        (message-narrow-to-headers)
-       (let ((mail-parse-charset message-default-charset)
-             (rfc2047-header-encoding-alist
-              (cons '("Newsgroups" . default)
-                    rfc2047-header-encoding-alist)))
-         (mail-encode-encoded-word-buffer)))
-      (goto-char (point-min))
-      (when (re-search-forward
-            (concat "^" (regexp-quote mail-header-separator) "$")
-            nil t)
-       (replace-match "" t t ))
-      ;; Process FCC operations.
-      (while list
-       (setq file (pop list))
-       (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
-           ;; Pipe the article to the program in question.
-           (call-process-region (point-min) (point-max) shell-file-name
-                                nil nil nil shell-command-switch
-                                (match-string 1 file))
-         ;; Save the article.
-         (setq file (expand-file-name file))
-         (unless (file-exists-p (file-name-directory file))
-           (make-directory (file-name-directory file) t))
-         (if (and message-fcc-handler-function
-                  (not (eq message-fcc-handler-function 'rmail-output)))
-             (funcall message-fcc-handler-function file)
-           (if (and (file-readable-p file) (mail-file-babyl-p file))
-               (rmail-output file 1 nil t)
-             (let ((mail-use-rfc822 t))
-               (rmail-output file 1 t t))))))
-      (kill-buffer (current-buffer)))))
+       (setq file (message-fetch-field "fcc" t)))
+      (when file
+       (set-buffer (get-buffer-create " *message temp*"))
+       (erase-buffer)
+       (insert-buffer-substring buf)
+       (message-encode-message-body)
+       (save-restriction
+         (message-narrow-to-headers)
+         (while (setq file (message-fetch-field "fcc" t))
+           (push file list)
+           (message-remove-header "fcc" nil t))
+         (let ((mail-parse-charset message-default-charset)
+               (rfc2047-header-encoding-alist
+                (cons '("Newsgroups" . default)
+                      rfc2047-header-encoding-alist)))
+           (mail-encode-encoded-word-buffer)))
+       (goto-char (point-min))
+       (when (re-search-forward
+              (concat "^" (regexp-quote mail-header-separator) "$")
+              nil t)
+         (replace-match "" t t ))
+       ;; Process FCC operations.
+       (while list
+         (setq file (pop list))
+         (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
+             ;; Pipe the article to the program in question.
+             (call-process-region (point-min) (point-max) shell-file-name
+                                  nil nil nil shell-command-switch
+                                  (match-string 1 file))
+           ;; Save the article.
+           (setq file (expand-file-name file))
+           (unless (file-exists-p (file-name-directory file))
+             (make-directory (file-name-directory file) t))
+           (if (and message-fcc-handler-function
+                    (not (eq message-fcc-handler-function 'rmail-output)))
+               (funcall message-fcc-handler-function file)
+             (if (and (file-readable-p file) (mail-file-babyl-p file))
+                 (rmail-output file 1 nil t)
+               (let ((mail-use-rfc822 t))
+                 (rmail-output file 1 t t))))))
+       (kill-buffer (current-buffer))))))
 
 (defun message-output (filename)
   "Append this article to Unix/babyl mail file FILENAME."
@@ -3133,7 +3219,7 @@ to find out how to use this."
           (point)))
        (goto-char (point-min))
        (while (re-search-forward "\n[ \t]+" nil t)
-         (replace-match " " t t))      ;No line breaks (too confusing)
+         (replace-match " " t t))     ;No line breaks (too confusing)
        (goto-char (point-min))
        (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t)
          (replace-match "," t t))
@@ -3152,6 +3238,9 @@ If NOW, use that time instead."
       (setq sign "-")
       (setq zone (- zone)))
     (concat
+     ;; The day name of the %a spec is locale-specific.  Pfff.
+     (format "%s, " (capitalize (car (rassoc (nth 6 (decode-time now))
+                                            parse-time-weekdays))))
      (format-time-string "%d" now)
      ;; The month name of the %b spec is locale-specific.  Pfff.
      (format " %s "
@@ -3613,12 +3702,12 @@ Headers already prepared in the buffer are not modified."
          (nthcdr (+ (- cut 2) surplus 1) list)))
 
 (defun message-shorten-references (header references)
-  "Trim REFERENCES to be less than 31 Message-ID long, and fold them.
+  "Trim REFERENCES to be 21 Message-ID long or less, and fold them.
 If folding is disallowed, also check that the REFERENCES are less
 than 988 characters long, and if they are not, trim them until they are."
-  (let ((maxcount 31)
+  (let ((maxcount 21)
        (count 0)
-       (cut 6)
+       (cut 2)
        refs)
     (with-temp-buffer
       (insert references)
@@ -3737,7 +3826,7 @@ than 988 characters long, and if they are not, trim them until they are."
   ;; list of buffers.
   (setq message-buffer-list (delq (current-buffer) message-buffer-list))
   (while (and message-max-buffers
-              message-buffer-list
+             message-buffer-list
              (>= (length message-buffer-list) message-max-buffers))
     ;; Kill the oldest buffer -- unless it has been changed.
     (let ((buffer (pop message-buffer-list)))
@@ -3757,8 +3846,10 @@ than 988 characters long, and if they are not, trim them until they are."
                     (string-equal name "mail")
                     (string-equal name "news")))
            (setq name (concat "*sent " name "*"))
+         (message-narrow-to-headers)
          (setq to (message-fetch-field "to"))
          (setq group (message-fetch-field "newsgroups"))
+         (widen)
          (setq name
                (cond
                 (to (concat "*sent mail to "
@@ -3881,7 +3972,10 @@ than 988 characters long, and if they are not, trim them until they are."
        (setq message-draft-article
              (nndraft-request-associate-buffer "drafts"))
       (setq buffer-file-name (expand-file-name
-                             (if (eq system-type 'windows-nt)
+                             (if (memq system-type 
+                                       '(ms-dos ms-windows windows-nt 
+                                                cygwin32 win32 w32 
+                                                mswindows))
                                  "message"
                                "*message*")
                              message-auto-save-directory))
@@ -3958,8 +4052,8 @@ OTHER-HEADERS is an alist of header/value pairs."
          mct (message-fetch-field "mail-copies-to")
          reply-to (message-fetch-field "reply-to")
          mrt (message-fetch-field "mail-reply-to")
-         mft (and message-use-followup-to
-                   (message-fetch-field "mail-followup-to")))
+         mft (and message-use-mail-followup-to
+                  (message-fetch-field "mail-followup-to")))
 
     ;; Handle special values of Mail-Copies-To.
     (when mct
@@ -3972,8 +4066,8 @@ OTHER-HEADERS is an alist of header/value pairs."
             (setq mct (or mrt reply-to from)))))
 
     (if (and (not mft)
-             (or (not wide)
-                 to-address))
+            (or (not wide)
+                to-address))
        (progn
          (setq follow-to (list (cons 'To (or to-address mrt reply-to from))))
          (when (and (and wide mct)
@@ -3982,29 +4076,32 @@ OTHER-HEADERS is an alist of header/value pairs."
       (let (ccalist)
        (save-excursion
          (message-set-work-buffer)
-          (if (and mft
-                   message-use-followup-to
-                   wide
-                   (or (not (eq message-use-followup-to 'ask))
-                       (message-y-or-n-p
-                       (concat "Obey Mail-Followup-To? ") t "\
+         (if (and mft
+                  wide
+                  (or (not (eq message-use-mail-followup-to 'ask))
+                      (message-y-or-n-p
+                       (concat "Obey Mail-Followup-To? ") t "\
 You should normally obey the Mail-Followup-To: header.  In this
 article, it has the value of
 
 " mft "
 
 which directs your response to " (if (string-match "," mft)
-                              "the specified addresses"
-                            "that address only") ".
+                                    "the specified addresses"
+                                  "that address only") ".
+
+Most commonly, Mail-Followup-To is used by a mailing list poster to
+express that responses should be sent to just the list, and not the
+poster as well.
 
-If a message is posted to several mailing lists, Mail-Followup-To is
-often used to direct the following discussion to one list only,
+If a message is posted to several mailing lists, Mail-Followup-To may
+also be used to direct the following discussion to one list only,
 because discussions that are spread over several lists tend to be
 fragmented and very difficult to follow.
 
 Also, some source/announcement lists are not intended for discussion;
 responses here are directed to other addresses.")))
-              (insert mft)
+             (insert mft)
            (unless never-mct
              (insert (or mrt reply-to from "")))
            (insert (if to (concat (if (bolp) "" ", ") to "") ""))
@@ -4035,7 +4132,12 @@ responses here are directed to other addresses.")))
                                (lambda (addr) (cdr addr)) ccalist ", "))))
            (when (string-match "^ +" (cdr ccs))
              (setcdr ccs (substring (cdr ccs) (match-end 0))))
-           (push ccs follow-to)))))
+           (push ccs follow-to)))
+       ;; Allow the user to be asked whether or not to reply to all
+       ;; recipients in a wide reply.
+       (if (and ccalist wide message-wide-reply-confirm-recipients
+                (not (y-or-n-p "Reply to all recipients?")))
+           (setq follow-to (delq (assoc 'Cc follow-to) follow-to)))))
     follow-to))
 
 
@@ -4068,16 +4170,16 @@ responses here are directed to other addresses.")))
            date (message-fetch-field "date")
            from (message-fetch-field "from")
            subject (or (message-fetch-field "subject") "none"))
-    (when gnus-list-identifiers
-      (setq subject (message-strip-list-identifiers subject)))
-    (setq subject (concat "Re: " (message-strip-subject-re subject)))
+      (when gnus-list-identifiers
+       (setq subject (message-strip-list-identifiers subject)))
+      (setq subject (concat "Re: " (message-strip-subject-re subject)))
 
-    (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
-              (string-match "<[^>]+>" gnus-warning))
-      (setq message-id (match-string 0 gnus-warning)))
+      (when (and (setq gnus-warning (message-fetch-field "gnus-warning"))
+                (string-match "<[^>]+>" gnus-warning))
+       (setq message-id (match-string 0 gnus-warning)))
 
-    (unless follow-to
-      (setq follow-to (message-get-reply-headers wide to-address))))
+      (unless follow-to
+       (setq follow-to (message-get-reply-headers wide to-address))))
 
     (unless (message-mail-user-agent)
       (message-pop-to-buffer
@@ -4369,13 +4471,13 @@ The form is: [Source] Subject, where if the original message was mail,
 Source is the sender, and if the original message was news, Source is
 the list of newsgroups is was posted to."
   (concat "["
-          (let ((prefix
-                 (or (message-fetch-field
-                      (if (message-news-p) "newsgroups" "from"))
-                     "(nowhere)")))
-            (if message-forward-decoded-p
-                prefix
-              (mail-decode-encoded-word-string prefix)))
+         (let ((prefix
+                (or (message-fetch-field
+                     (if (message-news-p) "newsgroups" "from"))
+                    "(nowhere)")))
+           (if message-forward-decoded-p
+               prefix
+             (mail-decode-encoded-word-string prefix)))
          "] " subject))
 
 (defun message-forward-subject-fwd (subject)
@@ -4423,7 +4525,7 @@ Optional DIGEST will use digest to forward."
   (let* ((cur (current-buffer))
         (message-forward-decoded-p
          (if (local-variable-p 'gnus-article-decoded-p (current-buffer))
-             gnus-article-decoded-p  ;; In an article buffer.
+             gnus-article-decoded-p ;; In an article buffer.
            message-forward-decoded-p))
         (subject (message-make-forward-subject))
         art-beg)
@@ -4433,7 +4535,7 @@ Optional DIGEST will use digest to forward."
     ;; Put point where we want it before inserting the forwarded
     ;; message.
     (if message-forward-before-signature
-        (message-goto-body)
+       (message-goto-body)
       (goto-char (point-max)))
     (if message-forward-as-mime
        (if digest
@@ -4563,15 +4665,17 @@ you."
       (undo-boundary)
       (goto-char (point-min))
       (search-forward "\n\n" nil t)
-      (or (and (re-search-forward message-unsent-separator nil t)
-              (forward-line 1))
-         (re-search-forward "^Return-Path:.*\n" nil t))
-      ;; We remove everything before the bounced mail.
-      (delete-region
-       (point-min)
-       (if (re-search-forward "^[^ \n\t]+:" nil t)
-          (match-beginning 0)
-        (point))))
+      (if (or (and (re-search-forward message-unsent-separator nil t)
+                  (forward-line 1))
+             (re-search-forward "^Return-Path:.*\n" nil t))
+         ;; We remove everything before the bounced mail.
+         (delete-region
+          (point-min)
+          (if (re-search-forward "^[^ \n\t]+:" nil t)
+              (match-beginning 0)
+            (point)))
+       (when (re-search-backward "^.?From .*\n" nil t)
+         (delete-region (match-beginning 0) (match-end 0)))))
     (mm-enable-multibyte)
     (mime-to-mml)
     (save-restriction
@@ -4714,14 +4818,21 @@ which specify the range to operate on."
   "^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):"
   "Regexp that match headers that lists groups.")
 
+(defvar message-completion-alist
+  (list (cons message-newgroups-header-regexp 'message-expand-group)
+       '("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . message-expand-name))
+  "Alist of (RE . FUN).  Use FUN for completion on header lines matching RE.")
+
 (defun message-tab ()
-  "Expand group names in Newsgroups and Followup-To headers.
-Do a `tab-to-tab-stop' if not in those headers."
+  "Complete names according to `message-completion-alist'.
+Do an `indent-line-function' if not in those headers."
   (interactive)
-  (if (let ((mail-abbrev-mode-regexp message-newgroups-header-regexp))
-       (mail-abbrev-in-expansion-header-p))
-      (message-expand-group)
-    (tab-to-tab-stop)))
+  (let ((alist message-completion-alist))
+    (while (and alist
+               (let ((mail-abbrev-mode-regexp (caar alist)))
+                 (not (mail-abbrev-in-expansion-header-p))))
+      (setq alist (cdr alist)))
+    (funcall (or (cdar alist) indent-line-function))))
 
 (defun message-expand-group ()
   "Expand the group name under point."
@@ -4765,6 +4876,11 @@ Do a `tab-to-tab-stop' if not in those headers."
            (goto-char (point-min))
            (delete-region (point) (progn (forward-line 3) (point))))))))))
 
+(defun message-expand-name ()
+  (if (fboundp 'bbdb-complete-name)
+      (bbdb-complete-name)
+    (expand-abbrev)))
+
 ;;; Help stuff.
 
 (defun message-talkative-question (ask question show &rest text)
@@ -4927,10 +5043,15 @@ regexp varstr."
                          (message-fetch-field "from")))
     (message-options-set 'message-recipients
                         (mail-strip-quoted-names
-                         (concat
-                          (or (message-fetch-field "to") "") ", "
-                          (or (message-fetch-field "cc") "") ", "
-                          (or (message-fetch-field "bcc") ""))))))
+                         (let ((to (message-fetch-field "to"))
+                               (cc (message-fetch-field "cc"))
+                               (bcc (message-fetch-field "bcc")))
+                           (concat
+                            (or to "")
+                            (if (and to cc) ", ")
+                            (or cc "")
+                            (if (and (or to cc) bcc) ", ")
+                            (or bcc "")))))))
 
 (when (featurep 'xemacs)
   (require 'messagexmas)