Prompt in a more logical fashion when sending bug reports

* gnus/message.el (message-default-send-mail-function): Made into own
function for reuse by emacsbug.el.

* mail/emacsbug.el (report-emacs-bug-hook): Query the user first
about SMTP before checking the From header.

* mail/sendmail.el (sendmail-query-user-about-smtp): Refacored out
into own function for reuse by emacsbug.el.
This commit is contained in:
Lars Ingebrigtsen 2012-02-10 19:16:19 +01:00
parent 3647f557cf
commit cc26d239af
5 changed files with 81 additions and 54 deletions

View file

@ -1,3 +1,11 @@
2012-02-10 Lars Ingebrigtsen <larsi@gnus.org>
* mail/emacsbug.el (report-emacs-bug-hook): Query the user first
about SMTP before checking the From header.
* mail/sendmail.el (sendmail-query-user-about-smtp): Refacored out
into own function for reuse by emacsbug.el.
2012-02-10 Leo Liu <sdl.web@gmail.com> 2012-02-10 Leo Liu <sdl.web@gmail.com>
* subr.el (condition-case-unless-debug): Rename from * subr.el (condition-case-unless-debug): Rename from

View file

@ -1,3 +1,8 @@
2012-02-10 Lars Ingebrigtsen <larsi@gnus.org>
* message.el (message-default-send-mail-function): Made into own
function for reuse by emacsbug.el.
2012-02-09 Juanma Barranquero <lekktu@gmail.com> 2012-02-09 Juanma Barranquero <lekktu@gmail.com>
* gnus.el (gnus-method-ephemeral-p): Move after declaration of defsubst * gnus.el (gnus-method-ephemeral-p): Move after declaration of defsubst

View file

@ -655,14 +655,16 @@ Done before generating the new subject of a forward."
(t (t
(error "Don't know how to send mail. Please customize `message-send-mail-function'")))) (error "Don't know how to send mail. Please customize `message-send-mail-function'"))))
;; Useful to set in site-init.el (defun message-default-send-mail-function ()
(defcustom message-send-mail-function
(cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it) (cond ((eq send-mail-function 'smtpmail-send-it) 'message-smtpmail-send-it)
((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it) ((eq send-mail-function 'feedmail-send-it) 'feedmail-send-it)
((eq send-mail-function 'sendmail-query-once) 'sendmail-query-once) ((eq send-mail-function 'sendmail-query-once) 'sendmail-query-once)
((eq send-mail-function 'mailclient-send-it) ((eq send-mail-function 'mailclient-send-it)
'message-send-mail-with-mailclient) 'message-send-mail-with-mailclient)
(t (message-send-mail-function))) (t (message-send-mail-function))))
;; Useful to set in site-init.el
(defcustom message-send-mail-function (message-default-send-mail-function)
"Function to call to send the current buffer as mail. "Function to call to send the current buffer as mail.
The headers should be delimited by a line whose contents match the The headers should be delimited by a line whose contents match the
variable `mail-header-separator'. variable `mail-header-separator'.

View file

@ -32,6 +32,9 @@
;;; Code: ;;; Code:
(require 'sendmail)
(require 'message)
(defgroup emacsbug nil (defgroup emacsbug nil
"Sending Emacs bug reports." "Sending Emacs bug reports."
:group 'maint :group 'maint
@ -365,26 +368,7 @@ usually do not have translators for other languages.\n\n")))
(string-equal (buffer-substring-no-properties (point-min) (point)) (string-equal (buffer-substring-no-properties (point-min) (point))
report-emacs-bug-orig-text) report-emacs-bug-orig-text)
(error "No text entered in bug report")) (error "No text entered in bug report"))
(or report-emacs-bug-no-confirmation ;; Warning for novice users.
;; mailclient.el does not handle From (at present).
(if (derived-mode-p 'message-mode)
(eq message-send-mail-function 'message-send-mail-with-mailclient)
(eq send-mail-function 'mailclient-send-it))
;; Not narrowing to the headers, but that's OK.
(let ((from (mail-fetch-field "From")))
(and (or (not from)
(message-bogus-recipient-p from)
;; This is the default user-mail-address. On today's
;; systems, it seems more likely to be wrong than right,
;; since most people don't run their own mail server.
(string-match (format "\\<%s@%s\\>"
(regexp-quote (user-login-name))
(regexp-quote (system-name)))
from))
(not (yes-or-no-p
(format "Is `%s' really your email address? " from)))
(error "Please edit the From address and try again"))))
;; The last warning for novice users.
(unless (or report-emacs-bug-no-confirmation (unless (or report-emacs-bug-no-confirmation
(yes-or-no-p (yes-or-no-p
"Send this bug report to the Emacs maintainers? ")) "Send this bug report to the Emacs maintainers? "))
@ -407,7 +391,32 @@ and send the mail again%s."
report-emacs-bug-send-command) report-emacs-bug-send-command)
""))))) "")))))
(error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer")) (error "M-x report-emacs-bug was cancelled, please read *Bug Help* buffer"))
;; Query the user for the SMTP method, so that we can skip
;; questions about From header validity if the user is going to
;; use mailclient, anyway.
(when (eq send-mail-function 'sendmail-query-once)
(sendmail-query-user-about-smtp)
(when (derived-mode-p 'message-mode)
(setq message-send-mail-function (message-default-send-mail-function))))
(or report-emacs-bug-no-confirmation
;; mailclient.el does not need a valid From
(if (derived-mode-p 'message-mode)
(eq message-send-mail-function 'message-send-mail-with-mailclient)
(eq send-mail-function 'mailclient-send-it))
;; Not narrowing to the headers, but that's OK.
(let ((from (mail-fetch-field "From")))
(and (or (not from)
(message-bogus-recipient-p from)
;; This is the default user-mail-address. On today's
;; systems, it seems more likely to be wrong than right,
;; since most people don't run their own mail server.
(string-match (format "\\<%s@%s\\>"
(regexp-quote (user-login-name))
(regexp-quote (system-name)))
from))
(not (yes-or-no-p
(format "Is `%s' really your email address? " from)))
(error "Please edit the From address and try again"))))
;; Delete the uninteresting text that was just to help fill out the report. ;; Delete the uninteresting text that was just to help fill out the report.
(rfc822-goto-eoh) (rfc822-goto-eoh)
(forward-line 1) (forward-line 1)

View file

@ -513,6 +513,10 @@ This also saves the value of `send-mail-function' via Customize."
;; a second time, probably because someone's using an old value ;; a second time, probably because someone's using an old value
;; of send-mail-function. ;; of send-mail-function.
(when (eq send-mail-function 'sendmail-query-once) (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) (let* ((options `(("mail client" . mailclient-send-it)
,@(when (and sendmail-program ,@(when (and sendmail-program
(executable-find sendmail-program)) (executable-find sendmail-program))
@ -554,7 +558,6 @@ This also saves the value of `send-mail-function' via Customize."
options nil 'require-match))))) options nil 'require-match)))))
(customize-save-variable 'send-mail-function (customize-save-variable 'send-mail-function
(cdr (assoc-string choice options t))))) (cdr (assoc-string choice options t)))))
(funcall send-mail-function))
(defun sendmail-sync-aliases () (defun sendmail-sync-aliases ()
(when mail-personal-alias-file (when mail-personal-alias-file