Subject: 24.4; sendmail-query-user-about-smtp allows nil function

From: [email-masked]
Date: Sat, 25 Feb 2017 10:20:42 -0800

If you hit Enter at the "Send mail via" prompt, Emacs will misconfigure
itself so it is impossible to send mail.

RECIPE TO REPEAT

1. Start a new mail message using C-x 4 m

2. After composing, hit C-c C-c to send

3. Emacs will prompt "Send mail via: "

   (This is sendmail.el:sendmail-query-user-about-smtp asking how you
   would like to send mail. Valid responses are: "mail client",
   "transport", or "smtp")

4. Hit the Enter key, assuming Emacs will pick a reasonable default

5. Be surprised when you get a mysterious error message:

   "Symbol's function definition is void: nil"

6. Hit C-c C-c to try to send the message again, assuming Emacs will
   again prompt and you can give a different response.

7. Be even more surprised that instead of asking "Send message via" a
   second time, Emacs has memorized that you want to use the function
   "nil" to send messages and will simply give the same error message
   every time.

One simple fix would be to have the function sendmail-query-once check
if the value of send-mail-function is nil. It is not perfect as it
will still show the user the error message (seen in step 5), but at
least the user can try again. Here is a patch which implements that
fix:
----------------------------------------------------------------------

--- sendmail.el.orig	2014-10-21 14:45:42.000000000 -0700
+++ sendmail.el	2017-02-18 05:58:20.085685326 -0800
@@ -507,15 +507,16 @@
 ;;;###autoload
 (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."
   ;; 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)
+  (when (or (not (fboundp send-mail-function))
+	    (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))

----------------------------------------------------------------------

In GNU Emacs 24.4.1 (x86_64-pc-linux-gnu, GTK+ Version 3.14.5)
 of 2015-03-07 on trouble, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11604000
System Description:	Debian GNU/Linux 8.7 (jessie)

Configured using:
 `configure --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.4/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.4/site-lisp:/usr/share/emacs/site-lisp
 --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
 --libexecdir=/usr/lib --localstatedir=/var/lib
 --infodir=/usr/share/info --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.4/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.4/site-lisp:/usr/share/emacs/site-lisp
 --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
 'CFLAGS=-g -O2 -fstack-protector-strong -Wformat
 -Werror=format-security -Wall' CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-z,relro'