diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-03 19:57:30 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-03 19:57:30 -0500 |
| commit | 3e9499f62c4fb621ec234a0cf5cee51eb2cf32c0 (patch) | |
| tree | 1a7384b5204351eefa8135242d24da2a8da8d38d /modules/mail-config.el | |
| parent | 59094e944b4a9e8c5e1a20724c2681ffe9b6155c (diff) | |
| download | dotemacs-3e9499f62c4fb621ec234a0cf5cee51eb2cf32c0.tar.gz dotemacs-3e9499f62c4fb621ec234a0cf5cee51eb2cf32c0.zip | |
fix: validate mail transport executables and default debug off
`mail-config.el` had three related issues. SMTP transport debug was hard-coded to t, which is sensitive since mail bodies and headers land in debug buffers. The use-package `:config` was also setting `sendmail-program` and `mu4e-get-mail-command` directly from `executable-find` results. So a host without msmtp or mbsync silently got `nil` or `(concat nil " -a")` instead of a clear failure mode.
I added `cj/smtpmail-debug-enabled` (default nil) plus `cj/set-smtpmail-debug` and `cj/toggle-smtpmail-debug` for temporary troubleshooting, mirroring the pattern from `auth-config.el`.
I extracted `cj/mail--executable-or-warn` so a missing program emits a one-time `display-warning` and returns nil. `cj/mail-configure-smtpmail` and `cj/mail--mbsync-command` both use it. Missing msmtp now leaves `sendmail-program` nil with a warning. Missing mbsync produces a nil sync command instead of the broken `(concat nil " -a")` string. I also wrapped the mbsync executable path in `shell-quote-argument` so unusual install paths don't fall apart on the `" -a"` concat.
I added `tests/test-mail-config-transport.el` with seven tests across Normal / Boundary / Error: debug-default-off, toggle wiring, msmtp present and missing, mbsync present, mbsync path with spaces, and mbsync missing. The `test-mail-config--with-executables` macro stubs `executable-find` from an alist so each test names its own environment.
Diffstat (limited to 'modules/mail-config.el')
| -rw-r--r-- | modules/mail-config.el | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/modules/mail-config.el b/modules/mail-config.el index a53473b4..f19adf80 100644 --- a/modules/mail-config.el +++ b/modules/mail-config.el @@ -34,6 +34,62 @@ (eval-and-compile (defvar cj/custom-keymap (make-sparse-keymap))) +(defvar smtpmail-debug-info nil) +(defvar sendmail-program nil) +(defvar send-mail-function nil) +(defvar message-send-mail-function nil) +(defvar message-sendmail-envelope-from nil) + +(defcustom cj/smtpmail-debug-enabled nil + "Non-nil means enable verbose SMTP transport debug logging. + +Keep this nil during normal startup. SMTP debug output is useful for +troubleshooting mail delivery problems, but it can expose sensitive mail +transport details in debug buffers." + :type 'boolean + :group 'mail) + +(defun cj/set-smtpmail-debug (enabled) + "Set SMTP transport debug logging according to ENABLED." + (interactive + (list (y-or-n-p "Enable SMTP transport debug logging? "))) + (setq cj/smtpmail-debug-enabled enabled) + (setq smtpmail-debug-info enabled) + (message "SMTP transport debug logging %s" + (if enabled "enabled" "disabled"))) + +(defun cj/toggle-smtpmail-debug () + "Toggle verbose SMTP transport debug logging for troubleshooting." + (interactive) + (cj/set-smtpmail-debug (not smtpmail-debug-info))) + +(defun cj/mail--executable-or-warn (program feature) + "Return PROGRAM's executable path, or warn that FEATURE is unavailable." + (or (executable-find program) + (progn + (display-warning + 'mail-config + (format "%s not found; %s unavailable" program feature) + :warning) + nil))) + +(defun cj/mail--mbsync-command () + "Return the mu4e mail sync command, or nil if mbsync is unavailable." + (when-let ((mbsync (cj/mail--executable-or-warn + "mbsync" "mu4e mail synchronization"))) + (concat (shell-quote-argument mbsync) " -a"))) + +(defun cj/mail-configure-smtpmail () + "Configure SMTP mail transport when msmtp is available." + (setq smtpmail-debug-info cj/smtpmail-debug-enabled) + (if-let ((msmtp (cj/mail--executable-or-warn + "msmtp" "SMTP mail sending"))) + (setq sendmail-program msmtp + send-mail-function 'message-send-mail-with-sendmail + message-send-mail-function 'message-send-mail-with-sendmail + message-sendmail-envelope-from 'header) + (setq sendmail-program nil))) + ;; -------------------- HarfBuzz Crash Fix: Disable Composition --------------- ;; Disable auto-composition in mu4e headers to prevent SIGSEGV from HarfBuzz ;; when shaping emoji characters in email subjects. See Commentary above. @@ -63,11 +119,7 @@ Prompts user for the action when executing." :ensure nil ;; built-in :defer .5 :config - (setq sendmail-program (executable-find "msmtp")) - (setq send-mail-function 'message-send-mail-with-sendmail - message-send-mail-function 'message-send-mail-with-sendmail) - (setq message-sendmail-envelope-from 'header) - (setq smtpmail-debug-info t)) + (cj/mail-configure-smtpmail)) ;; --------------------------------- Mu4e Email -------------------------------- @@ -119,7 +171,7 @@ Prompts user for the action when executing." (setq mu4e-html2text-command 'mu4e-shr2text) ;; email conversion to html via shr2text (setq mu4e-mu-binary (executable-find "mu")) - (setq mu4e-get-mail-command (concat (executable-find "mbsync") " -a")) ;; command to sync mail + (setq mu4e-get-mail-command (cj/mail--mbsync-command)) ;; command to sync mail (setq mu4e-user-mail-address-list '("c@cjennings.net" "craigmartinjennings@gmail.com" "craig.jennings@deepsat.com")) |
