Subject: bug#43386: 27.1; Regression in `report-emacs-bug'

From: Eli Zaretskii <[email-masked]>
Date: Mon, 14 Sep 2020 17:58:27 +0300

> From: Lars Ingebrigtsen <[email-masked]>
> Date: Mon, 14 Sep 2020 02:18:23 +0200
> Cc: [email-masked]
> 
> > In any case, in Emacs 26.3 (and prior), even
> > though the From has that crazy text, when I use
> > C-c C-c and tell Emacs to use my mail client,
> > the mail client window pops up perfectly, and
> > yes, my mail client knows what my email address
> > is.  The buffer *sent mail to [email-masked]*
> > still has the crazy From text, but Emacs doesn't
> > bother me.
> 
> Emacs now requires that the From address is valid, as you've
> discovered.  (Sending bug reports from an "emacs -Q" is a pretty strange
> choice anyway, but that's up to you.)
> 
> Things seem to be working as designed, so I'm closing this bug report.

I think Drew is right here: we have a bug on our hands.

Look at the code:

  ;; 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 (or (and (derived-mode-p 'message-mode)
		 (eq message-send-mail-function 'sendmail-query-once))
	    (and (not (derived-mode-p 'message-mode))
		 (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")))
	(when (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-message "Is `%s' really your email address? "
                                         from))))

As you see, we _know_ that mailclient.el doesn't care about the faux
>From address, and we have some logic to detect when this is the case.
But that logic doesn't work, because the conditions fail to match:

  (when (or (and (derived-mode-p 'message-mode)
		 (eq message-send-mail-function 'sendmail-query-once))
	    (and (not (derived-mode-p 'message-mode))
		 (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))))

The call to sendmail-query-user-about-smtp is the one that asks about
how to send, and allows to select mailclient.  But the conditions to
call it are false, and the rest is history.

I think this breakage is somehow related to our attempt to clean up
the sendmail.el/message.el mess.  So I suggest to look at how things
are supposed to work when message-mode is used by default, and see why
we miss the question about mailclient before asking about the From
address.