10

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.

10

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)
2
  • Great, I tested this and it works. Thanks.
    – Gregor
    Apr 23 '18 at 18:05
  • @Gregor Updated to call message-field-value instead of message-fetch-field, which generally worked but could lead to problems.
    – Basil
    Apr 25 '18 at 7:57
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.

1
  • 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 8 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.