Auto-commit of loaddefs files.
[bpt/emacs.git] / lisp / mail / sendmail.el
index dedb571..e86229a 100644 (file)
@@ -1,7 +1,7 @@
-;;; sendmail.el --- mail sending commands for Emacs.  -*- byte-compile-dynamic: t -*-
+;;; sendmail.el --- mail sending commands for Emacs
 
-;; Copyright (C) 1985-1986, 1992-1996, 1998, 2000-2011
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1985-1986, 1992-1996, 1998, 2000-2013 Free Software
+;; Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: mail
@@ -140,7 +140,11 @@ Otherwise, let mailer send back a message to report errors."
 
 ;; Useful to set in site-init.el
 ;;;###autoload
-(defcustom send-mail-function 'sendmail-query-once
+(defcustom send-mail-function
+  ;; Assume smtpmail is the preferred choice if it's already configured.
+  (if (and (boundp 'smtpmail-smtp-server)
+           smtpmail-smtp-server)
+      'smtpmail-send-it 'sendmail-query-once)
   "Function to call to send the current buffer as mail.
 The headers should be delimited by a line which is
 not a valid RFC822 header or continuation line,
@@ -239,15 +243,14 @@ Used by `mail-yank-original' via `mail-indent-citation'."
   :type 'integer
   :group 'sendmail)
 
-;; FIXME make it really obsolete.
 (defvar mail-yank-hooks nil
   "Obsolete hook for modifying a citation just inserted in the mail buffer.
 Each hook function can find the citation between (point) and (mark t).
 And each hook function should leave point and mark around the citation
 text as modified.
-
 This is a normal hook, misnamed for historical reasons.
-It is semi-obsolete and mail agents should no longer use it.")
+It is obsolete and mail agents should no longer use it.")
+(make-obsolete-variable 'mail-yank-hooks 'mail-citation-hook "19.34")
 
 ;;;###autoload
 (defcustom mail-citation-hook nil
@@ -300,7 +303,7 @@ The default value matches citations like `foo-bar>' plus whitespace."
     (define-key map "\C-c\C-w" 'mail-signature)
     (define-key map "\C-c\C-c" 'mail-send-and-exit)
     (define-key map "\C-c\C-s" 'mail-send)
-    (define-key map "\C-c\C-i" 'mail-attach-file)
+    (define-key map "\C-c\C-i" 'mail-insert-file)
     ;; FIXME add this? "b" = bury buffer.  It's in the menu-bar.
 ;;;    (define-key map "\C-c\C-b" 'mail-dont-send)
 
@@ -505,46 +508,55 @@ by Emacs.)")
 (defun sendmail-query-once ()
   "Query for `send-mail-function' and send mail with it.
 This also saves the value of `send-mail-function' via Customize."
-  (let* ((mail-buffer (current-buffer))
-        ;; Compute default mail sender, preferring smtpmail if it's
-        ;; already configured.
-        (default (cond
-                  ((and (boundp 'smtpmail-smtp-server)
-                        smtpmail-smtp-server)
-                   'smtpmail-send-it)
-                  ((or (and window-system (eq system-type 'darwin))
-                       (eq system-type 'windows-nt))
-                   'mailclient-send-it)
-                  ((and sendmail-program
-                        (executable-find sendmail-program))
-                   'sendmail-send-it)))
-        (send-function (if (eq default 'smtpmail-send-it)
-                           'smtpmail-send-it)))
-    (unless send-function
-      ;; Query the user.
-      (with-temp-buffer
-       (rename-buffer "*Mail Help*" t)
-       (erase-buffer)
-       (insert "Emacs has not been set up for sending mail.\n
-Type `y' to configure and use Emacs as a mail client,
-or `n' to use your system's default mailer.\n
-To change your decision later, customize `send-mail-function'.\n")
-       (goto-char (point-min))
-       (display-buffer (current-buffer))
-       (if (y-or-n-p "Set up Emacs for sending SMTP mail? ")
-           ;; FIXME: We should check and correct the From: field too.
-           (setq send-function 'smtpmail-send-it)
-         (setq send-function default))))
-    (when send-function
-      (customize-save-variable 'send-mail-function send-function)
-      ;; HACK: Message mode stupidly has `message-send-mail-function',
-      ;; so we must update it too or sending again in the current
-      ;; Emacs session will still call `sendmail-query-once'.
-      (and (boundp 'message-send-mail-function)
-          (eq message-send-mail-function 'sendmail-query-once)
-          (customize-set-variable 'message-send-mail-function
-                                  send-function))
-      (funcall send-function))))
+  ;; If send-mail-function is already setup, we're incorrectly called
+  ;; a second time, probably because someone's using an old value
+  ;; of send-mail-function.
+  (when (eq send-mail-function 'sendmail-query-once)
+    (sendmail-query-user-about-smtp))
+  (funcall send-mail-function))
+
+(defun sendmail-query-user-about-smtp ()
+  (let* ((options `(("mail client" . mailclient-send-it)
+                   ,@(when (and sendmail-program
+                                (executable-find sendmail-program))
+                       '(("transport" . sendmail-send-it)))
+                   ("smtp" . smtpmail-send-it)))
+        (choice
+         ;; Query the user.
+         (with-temp-buffer
+           (rename-buffer "*Emacs Mail Setup Help*" t)
+           (insert "\
+ Emacs is about to send an email message, but it has not been
+ configured for sending email.  To tell Emacs how to send email:
+
+ - Type `"
+                   (propertize "mail client" 'face 'bold)
+                   "' to start your default email client and
+   pass it the message text.\n\n")
+           (and sendmail-program
+                (executable-find sendmail-program)
+                (insert "\
+ - Type `"
+                        (propertize "transport" 'face 'bold)
+                        "' to invoke the system's mail transport agent
+   (the `"
+                        sendmail-program
+                        "' program).\n\n"))
+           (insert "\
+ - Type `"
+                   (propertize "smtp" 'face 'bold)
+                   "' to send mail directly to an \"outgoing mail\" server.
+   (Emacs may prompt you for SMTP settings).
+
+ Emacs will record your selection and will use it thereafter.
+ To change it later, customize the option `send-mail-function'.\n")
+           (goto-char (point-min))
+           (display-buffer (current-buffer))
+           (let ((completion-ignore-case t))
+             (completing-read "Send mail via: "
+                              options nil 'require-match)))))
+    (customize-save-variable 'send-mail-function
+                            (cdr (assoc-string choice options t)))))
 \f
 (defun sendmail-sync-aliases ()
   (when mail-personal-alias-file
@@ -603,7 +615,7 @@ To change your decision later, customize `send-mail-function'.\n")
   ;; (kill-local-variable 'enable-multibyte-characters)
   (set-buffer-multibyte (default-value 'enable-multibyte-characters))
   (if current-input-method
-      (inactivate-input-method))
+      (deactivate-input-method))
 
   ;; Local variables for Mail mode.
   (setq mail-send-actions actions)
@@ -720,6 +732,7 @@ Turning on Mail mode runs the normal hooks `text-mode-hook' and
       (set (make-local-variable 'comment-start-skip)
           (concat "^" (regexp-quote mail-yank-prefix) "[ \t]*")))
   (make-local-variable 'adaptive-fill-regexp)
+  ;; Also update the paragraph-separate entry if you change this.
   (setq adaptive-fill-regexp
        (concat "[ \t]*[-[:alnum:]]+>+[ \t]*\\|"
                adaptive-fill-regexp))
@@ -733,11 +746,14 @@ Turning on Mail mode runs the normal hooks `text-mode-hook' and
   ;; lines that delimit forwarded messages.
   ;; Lines containing just >= 3 dashes, perhaps after whitespace,
   ;; are also sometimes used and should be separators.
-  (setq paragraph-separate (concat (regexp-quote mail-header-separator)
-                               "$\\|\t*\\([-|#;>* ]\\|(?[0-9]+[.)]\\)+$"
-                               "\\|[ \t]*[[:alnum:]]*>+[ \t]*$\\|[ \t]*$\\|"
-                               "--\\( \\|-+\\)$\\|"
-                               page-delimiter)))
+  (setq paragraph-separate
+       (concat (regexp-quote mail-header-separator)
+               ;; This is based on adaptive-fill-regexp (presumably
+               ;; the idea is to allow navigation etc of cited paragraphs).
+               "$\\|\t*[-–!|#%;>*·•‣⁃◦ ]+$"
+               "\\|[ \t]*[-[:alnum:]]*>+[ \t]*$\\|[ \t]*$\\|"
+               "--\\( \\|-+\\)$\\|"
+               page-delimiter)))
 
 
 (defun mail-header-end ()
@@ -839,15 +855,17 @@ Prefix arg means don't delete this window."
 (defun mail-bury (&optional arg)
   "Bury this mail buffer."
   (let ((newbuf (other-buffer (current-buffer)))
-       (return-action mail-return-action)
-       some-rmail)
+       (return-action mail-return-action))
     (bury-buffer (current-buffer))
     ;; If there is an Rmail buffer, return to it nicely
     ;; even if this message was not started by an Rmail command.
     (unless return-action
       (dolist (buffer (buffer-list))
-       (if (eq (buffer-local-value 'major-mode buffer) 'rmail-mode)
-           (setq return-action `(rmail-mail-return ,newbuf)))))
+       (if (and (eq (buffer-local-value 'major-mode buffer) 'rmail-mode)
+                (null return-action)
+                ;; Don't match message-viewer buffer.
+                (not (string-match "\\` " (buffer-name buffer))))
+           (setq return-action `(rmail-mail-return ,buffer)))))
     (if (and (null arg) return-action)
        (apply (car return-action) (cdr return-action))
       (switch-to-buffer newbuf))))
@@ -972,7 +990,7 @@ This function uses `mail-envelope-from'."
 
 ;;;###autoload
 (defvar sendmail-coding-system nil
-  "*Coding system for encoding the outgoing mail.
+  "Coding system for encoding the outgoing mail.
 This has higher priority than the default `buffer-file-coding-system'
 and `default-sendmail-coding-system',
 but lower priority than the local value of `buffer-file-coding-system'.
@@ -1068,6 +1086,9 @@ Return non-nil if and only if some part of the header is encoded."
                (cons selected mm-coding-system-priorities)
              mm-coding-system-priorities))
           (tick (buffer-chars-modified-tick))
+          ;; Many mailers, including Gnus, passes a message of which
+          ;; the header is already encoded, so this is necessary to
+          ;; prevent it from being encoded again.
           (rfc2047-encode-encoded-words nil))
       (rfc2047-encode-message-header)
       (= tick (buffer-chars-modified-tick)))))
@@ -1392,6 +1413,7 @@ just append to the file, in Babyl format if necessary."
 
 (defun mail-sent-via ()
   "Make a Sent-via header line from each To or CC header line."
+  (declare (obsolete "nobody can remember what it is for." "24.1"))
   (interactive)
   (save-excursion
     ;; put a marker at the end of the header
@@ -1411,9 +1433,6 @@ just append to the file, in Babyl format if necessary."
                                   (point)))))
          ;; Insert a copy, with altered header field name.
          (insert-before-markers "Sent-via:" to-line))))))
-
-(make-obsolete 'mail-sent-via "nobody can remember what it is for." "24.1")
-
 \f
 (defun mail-to ()
   "Move point to end of To field, creating it if necessary."
@@ -1656,7 +1675,8 @@ Just \\[universal-argument] as argument means don't indent, insert no prefix,
 and don't delete any header fields."
   (interactive "P")
   (and (consp mail-reply-action)
-       (eq (car mail-reply-action) 'insert-buffer)
+       (memq (car mail-reply-action)
+            '(rmail-yank-current-message insert-buffer))
        (with-current-buffer (nth 1 mail-reply-action)
         (or (mark t)
             (error "No mark set: %S" (current-buffer))))
@@ -1976,4 +1996,9 @@ you can move to one of them and type C-c C-c to recover that one."
 
 (provide 'sendmail)
 
+;; Local Variables:
+;; byte-compile-dynamic: t
+;; coding: utf-8
+;; End:
+
 ;;; sendmail.el ends here