diff --git a/mu4e/mu4e-helpers.el b/mu4e/mu4e-helpers.el index d7f6c241..ae1d7b60 100644 --- a/mu4e/mu4e-helpers.el +++ b/mu4e/mu4e-helpers.el @@ -148,6 +148,63 @@ Function will return the cdr of the list element." (mu4e-warn "Unknown shortcut '%c'" response)))) + +;;; Server properties +(defvar mu4e--server-props nil + "Metadata we receive from the mu4e server.") + +(defun mu4e-server-properties () + "Get the server metadata plist." + mu4e--server-props) + +(defun mu4e-root-maildir() + "Get the root maildir." + (or (and mu4e--server-props + (plist-get mu4e--server-props :root-maildir)) + (mu4e-error "Root maildir unknown; did you start mu4e?"))) + +(defun mu4e-database-path() + "Get the root maildir." + (or (and mu4e--server-props + (plist-get mu4e--server-props :database-path)) + (mu4e-error "Root maildir unknown; did you start mu4e?"))) + +(defun mu4e-server-version() + "Get the root maildir." + (or (and mu4e--server-props + (plist-get mu4e--server-props :version)) + (mu4e-error "Version unknown; did you start mu4e?"))) + +(defun mu4e-personal-addresses(&optional no-regexp) + "Get the list user's personal addresses, as passed to mu init. +The address are either plain e-mail address or /regular + expressions/. When NO-REGEXP is non-nil, do not include regexp + address patterns (if any)." + (seq-remove + (lambda(addr) (and no-regexp (string-match-p "^/.*/" addr))) + (when mu4e--server-props + (plist-get mu4e--server-props :personal-addresses)))) + +(defun mu4e-last-query-results () + "Get the results (counts) of the last cached queries. + +The cached queries are the bookmark / maildir queries that are +used to populated the read/unread counts in the main view. They +are refreshed when calling `(mu4e)', i.e., when going to the main +view. + +The results are a list of elements of the form + (:query \"query string\" + :count + :unread )" + (plist-get mu4e--server-props :queries)) + +(defun mu4e-last-query-result (query) + "Get the last result for some QUERY or nil if not found." + (seq-find + (lambda (elm) (string= (plist-get elm :query) query)) + (mu4e-last-query-results))) + ;;; Logging / debugging diff --git a/mu4e/mu4e-proc.el b/mu4e/mu4e-proc.el index b7224104..97acb5a6 100644 --- a/mu4e/mu4e-proc.el +++ b/mu4e/mu4e-proc.el @@ -24,7 +24,7 @@ ;;; Code: -(require 'mu4e-vars) +(require 'mu4e-helpers) (require 'mu4e-utils) (require 'mu4e-meta) @@ -177,6 +177,7 @@ The server output is as follows: ;; received a pong message ((plist-get sexp :pong) + (setq mu4e--server-props (plist-get sexp :props)) (funcall mu4e-pong-func sexp)) ;; received a contacts message @@ -243,7 +244,8 @@ backslashes and double-quotes." "Cannot find mu, please set `mu4e-mu-binary' to the mu executable path")) ;; sanity-check 2 - (let ((version (let ((s (shell-command-to-string (concat mu4e-mu-binary " --version")))) + (let ((version (let ((s (shell-command-to-string + (concat mu4e-mu-binary " --version")))) (and (string-match "version \\([.0-9]+\\)" s) (match-string 1 s))))) (unless (string= version mu4e-mu-version) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index f5f3363a..0e6a83fc 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -175,8 +175,9 @@ see its docstring)." (expand-file-name dir) (mu4e-error "mu4e-attachment-dir evaluates to nil")))) -;;; Maildir (1/2) + +;;; Maildirs (defun mu4e~guess-maildir (path) "Guess the maildir for some path, or nil if cannot find it." (let ((idx (string-match (mu4e-root-maildir) path))) @@ -201,8 +202,6 @@ an absolute path." (mu4e~proc-mkdir dir) t) (t nil))) -;;; Maildir (1/2) - (defun mu4e~get-maildirs-1 (path mdir) "Get maildirs under path, recursively, as a list of relative paths." (let ((dirs) @@ -289,6 +288,7 @@ and offer to create it if it does not exist yet." (mu4e~proc-mkdir fullpath))) mdir)) + ;;; Bookmarks (defun mu4e-ask-bookmark (prompt) "Ask the user for a bookmark (using PROMPT) as defined in @@ -551,7 +551,7 @@ completion; for testing/debugging." "Check for the settings required for running mu4e." (unless (>= emacs-major-version 25) (mu4e-error "Emacs >= 25.x is required for mu4e")) - (when mu4e~server-props + (when mu4e--server-props (unless (string= (mu4e-server-version) mu4e-mu-version) (mu4e-error "mu server has version %s, but we need %s" (mu4e-server-version) mu4e-mu-version))) @@ -602,8 +602,7 @@ nothing." (defun mu4e~pong-handler (data func) "Handle 'pong' responses from the mu server." - (setq mu4e~server-props (plist-get data :props)) ;; save info from the server - (let ((doccount (plist-get mu4e~server-props :doccount))) + (let ((doccount (plist-get mu4e--server-props :doccount))) (mu4e~check-requirements) (when func (funcall func)) (when (zerop doccount) @@ -615,29 +614,6 @@ nothing." (lambda () (mu4e-update-mail-and-index mu4e-index-update-in-background))))))) -(defun mu4e-last-query-results () - "Get the results (counts) of the last cached queries. - -The cached queries are the bookmark / maildir queries that are -used to populated the read/unread counts in the main view. They -are refreshed when calling `(mu4e)', i.e., when going to the main -view. - -The results are a list of elements of the form - (:query \"query string\" - :count - :unread )" - (plist-get mu4e~server-props :queries)) - - -(defun mu4e-last-query-result (query) - "Get the last result for some cached query, as per - `mu4e-bookmark-query-results' or nil if not found." - (cl-find-if - (lambda (elm) (string= (plist-get elm :query) query)) - (mu4e-last-query-results))) - - (defun mu4e~start (&optional func) "If `mu4e-contexts' have been defined, but we don't have a context yet, switch to the matching one, or none matches, the @@ -670,7 +646,7 @@ When successful, call FUNC (if non-nil) afterwards." mu4e~contacts-tstamp "0")) (defun mu4e~stop () - "Stop the mu4e session." + "Stop the mu4e se ssion." (when mu4e~update-timer (cancel-timer mu4e~update-timer) (setq mu4e~update-timer nil)) @@ -715,6 +691,8 @@ This is meant to be the exact same data structure as (mu4e~maildirs-with-query)) maximize (string-width (plist-get b :name)))) + + ;;; Indexing & Updating @@ -772,8 +750,6 @@ if you otherwise want to use `mu4e-index-lazy-check'." (let ((mu4e-index-cleanup t) (mu4e-index-lazy-check nil)) (mu4e-update-index))) - - (defvar mu4e~update-buffer nil "Internal, store the buffer of the update process when updating.") diff --git a/mu4e/mu4e-vars.el b/mu4e/mu4e-vars.el index 3d903ea8..f7869fa0 100644 --- a/mu4e/mu4e-vars.el +++ b/mu4e/mu4e-vars.el @@ -35,31 +35,6 @@ "mu4e - mu for emacs" :group 'mail) -(defcustom mu4e-mu-home nil - "Location of an alternate mu home dir. If not set, use the -defaults, based on the XDG Base Directory Specification." - :group 'mu4e - :type '(choice (const :tag "Default location" nil) - (directory :tag "Specify location")) - :safe 'stringp) - -(defcustom mu4e-mu-binary (executable-find "mu") - "Name of the mu-binary to use. -If it cannot be found in your PATH, you can specify the full -path." - :type 'file - :group 'mu4e - :safe 'stringp) - -(defcustom mu4e-mu-debug nil - "Whether to run the mu binary in debug-mode. -Setting this to t increases the amount of information in the log." - :type 'boolean - :group 'mu4e) - -(make-obsolete-variable 'mu4e-maildir - "determined by server; see `mu4e-root-maildir'." "1.3.8") - (defcustom mu4e-org-support t "Support org-mode links." :type 'boolean @@ -1063,41 +1038,6 @@ We need to keep this information around to quickly re-sort subsets of the contacts in the completions function in mu4e-compose.") -(defvar mu4e~server-props nil - "Information we receive from the mu4e server process \(in the 'pong-handler').") - -(defun mu4e-root-maildir() - "Get the root maildir." - (let ((root-maildir (and mu4e~server-props - (plist-get mu4e~server-props :root-maildir)))) - (unless root-maildir - (mu4e-error "root maildir unknown; did you start mu4e?")) - root-maildir)) - -(defun mu4e-database-path() - "Get the mu4e database path" - (let ((path (and mu4e~server-props - (plist-get mu4e~server-props :database-path)))) - (unless path - (mu4e-error "database-path unknown; did you start mu4e?")) - path)) - -(defun mu4e-personal-addresses(&optional no-regexp) - "Get the list user's personal addresses, as passed to `mu init --my-address=...'. - The address are either plain e-mail address or /regular - expressions/. When NO_REGEXP is non-nil, do not include regexp - address patterns (if any)." - (seq-remove - (lambda(addr) (and no-regexp (string-match-p "^/.*/" addr))) - (when mu4e~server-props (plist-get mu4e~server-props :personal-addresses)))) - -(defun mu4e-server-version() - "Get the server version, which should match mu4e's." - (let ((version (and mu4e~server-props (plist-get mu4e~server-props :version)))) - (unless version - (mu4e-error "version unknown; did you start mu4e?")) - version)) - ;;; Handler functions ;;