From 54ec919e8f478e60308eba4513d5845f4c0e688c Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 5 Jul 2025 10:57:36 +0300 Subject: [PATCH] mu4e: allow mu4e-get-mail-command to be a function For making it easier to influence the behavior. --- mu4e/mu4e-helpers.el | 5 +++++ mu4e/mu4e-update.el | 17 +++++++++++------ mu4e/mu4e.texi | 18 +++++++++--------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/mu4e/mu4e-helpers.el b/mu4e/mu4e-helpers.el index 17412182..26488083 100644 --- a/mu4e/mu4e-helpers.el +++ b/mu4e/mu4e-helpers.el @@ -559,7 +559,12 @@ BUFNAME is the name of the buffer, and DATA is lisp-data, if any." "Set VAR to VAL if VAR is nil." `(unless ,var (setq ,var ,val))) + ;;; Misc +(defun mu4e--fun-val (val) + "If var is a function, return (funcall VAL), otherwise return VAL." + (if (functionp val) (funcall val) val)) + (defun mu4e-join-paths (directory &rest components) "Append COMPONENTS to DIRECTORY and return the resulting string. diff --git a/mu4e/mu4e-update.el b/mu4e/mu4e-update.el index a8aa0dfd..7c52d232 100644 --- a/mu4e/mu4e-update.el +++ b/mu4e/mu4e-update.el @@ -33,15 +33,20 @@ ;;; Customization (defcustom mu4e-get-mail-command "true" - "Shell command for retrieving new mail. + "Shell command for retrieving new mail or a function. + Common values are \"offlineimap\", \"fetchmail\" or \"mbsync\", but -arbitrary shell-commands can be used. +arbitrary shell-commands can be used. If it is a function, it should +return a string specifying the same. When set to the literal string \"true\" (the default), the command simply finishes successfully (running the \"true\" command) without retrieving any mail. This can be useful when mail is already retrieved in another way, such as a local MDA." :type 'string + :type '(choice + (string :tag "Shell command") + (function :tag "Function that returns a string (shell command)")) :group 'mu4e :safe 'stringp) @@ -105,8 +110,8 @@ running." (defvar mu4e-update-pre-hook nil "Hook run just *before* the mail-retrieval / database updating process starts. -You can use this hook for example to `mu4e-get-mail-command' with -some specific setting.") +You can use this hook for example to update +`mu4e-get-mail-command' with some specific setting.") (defcustom mu4e-hide-index-messages nil "Whether to hide the \"Indexing...\" and contacts messages." @@ -271,9 +276,9 @@ If RUN-IN-BACKGROUND is non-nil (or called with prefix-argument), run in the background; otherwise, pop up a window." (let* ((process-connection-type t) + (cmd (mu4e--fun-val mu4e-get-mail-command)) (proc (start-process-shell-command - mu4e--update-name mu4e--update-name - mu4e-get-mail-command)) + mu4e--update-name mu4e--update-name cmd)) (buf (process-buffer proc)) (win (or run-in-background (mu4e--temp-window buf mu4e--update-buffer-height)))) diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index 061fdfcb..5ebbd1cf 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -521,11 +521,12 @@ Emacs/@t{mu4e}. However, you can also do it from within @subsection Basics To set up mail-retrieval from within @t{mu4e}, set the variable -@code{mu4e-get-mail-command} to the program or shell command you want to -use for retrieving mail. You can then get your e-mail using @kbd{M-x -mu4e-update-mail-and-index}, or @kbd{C-S-u} in all @t{mu4e}-views; -alternatively, you can use @kbd{C-c C-u}, which may be more convenient -if you use emacs in a terminal. +@code{mu4e-get-mail-command} to a shell command you want to use for retrieving +mail. It can also be a function which returns such a shell-command. + +You can then get your e-mail using @kbd{M-x mu4e-update-mail-and-index}, or +@kbd{C-S-u} in all @t{mu4e}-views; alternatively, you can use @kbd{C-c C-u}, +which may be more convenient if you use emacs in a terminal. You can kill the (foreground) update process with @kbd{q}. @@ -608,10 +609,9 @@ A simple setup could look something like: mu4e-update-interval 300) ;; update every 5 minutes @end lisp -A hook @code{mu4e-update-pre-hook} is available which is run right -before starting the process. That can be useful, for example, to -influence, @code{mu4e-get-mail-command} based on the the current -situation (location, time of day, ...). +To influence the details, a hook @code{mu4e-update-pre-hook} is available, which +is called right before starting the process. It is also possible to set +@code{mu4e-get-mail-command} to a function which returns a command. It is possible to get notifications when the indexing process does any updates --- for example when receiving new mail. See