11

If I hit C-c C-c in message-mode (I use notmuch) in order to send an email I've composed, I want to be warned if the Subject: header is empty. E.g. "Really send without Subject? (yes or no)"

When composing new email I fill in the Subject after I have written the body because only then I know exactly what Subject: matches this emails contents best. Sadly I often forget to actually set the Subject and with message-mode the email is sent without Subject:.

I searched online, but I'm astonished that this does not seem to be a recurring topic let alone an already answered FAQ.

Basil
  • 12,019
  • 43
  • 69
Gregor
  • 197
  • 7

2 Answers2

11

One way is to hook into message-send-hook:

message-send-hook is a variable defined in ‘message.el’.
Its value is nil

  This variable may be risky if used as a file-local variable.

Documentation:
Hook run before sending messages.
This hook is run quite early when sending.

For example:

(defun my-confirm-empty-subject ()
  "Allow user to quit when current message subject is empty."
  (or (message-field-value "Subject")
      (yes-or-no-p "Really send without Subject? ")
      (keyboard-quit)))

(add-hook 'message-send-hook #'my-confirm-empty-subject)
Basil
  • 12,019
  • 43
  • 69
0

Instead of adding the function to message-send-hook, as suggested by Basil, I ended up adding the very same function to message-send-mail-hook instead. For some reason (or none?) message-send-hook was always invoked twice for me (and it would ask me twice to confirm). message-send-mail-hook is called once only.

  • Are you sure it's the "Subject" question being asked twice, and not a different question each time? Do you by any chance use queued/deferred message sending? Because that's the only other place I see `message-send-hook` called. If you can reliably reproduce the issue, I suggest reporting it via `M-x report-emacs-bug`. – Basil Oct 08 '21 at 08:11