mirror of https://github.com/djcb/mu.git
mu4e: get maildirs from server
We were determining the list of maildirs using, but his is rather *slow*. So instead, get it from the server, through a "data" call.
This commit is contained in:
parent
a16d288c70
commit
c554e5194a
|
@ -244,47 +244,8 @@ to create it; otherwise return nil."
|
|||
(setq mu4e-maildir-list nil) ;; clear cache
|
||||
t)))
|
||||
|
||||
(defun mu4e--get-maildirs-1 (path mdir)
|
||||
"Get maildirs for MDIR under PATH.
|
||||
Do so recursively and produce a list of relative paths."
|
||||
(let ((dirs)
|
||||
(dentries
|
||||
(ignore-errors
|
||||
(directory-files-and-attributes
|
||||
(mu4e-join-paths path mdir) nil
|
||||
"^[^.]\\|\\.[^.][^.]" t))))
|
||||
(dolist (dentry dentries)
|
||||
(when (or (and (booleanp (cadr dentry)) (cadr dentry))
|
||||
(file-directory-p (mu4e-join-paths path (car dentry))))
|
||||
(if (file-accessible-directory-p
|
||||
(mu4e-join-paths (mu4e-root-maildir) mdir (car dentry) "cur"))
|
||||
(setq dirs
|
||||
(cons (mu4e-join-paths mdir (car dentry)) dirs)))
|
||||
(unless (member (car dentry) '("cur" "new" "tmp"))
|
||||
(setq dirs
|
||||
(append dirs
|
||||
(mu4e--get-maildirs-1
|
||||
path (mu4e-join-paths mdir (car dentry))))))))
|
||||
dirs))
|
||||
|
||||
(defun mu4e-get-maildirs ()
|
||||
"Get maildirs under `mu4e-maildir'.
|
||||
Do so recursively, and produce a list of relative paths (ie.,
|
||||
/archive, /sent etc.). Most of the work is done in
|
||||
`mu4e--get-maildirs-1'. Note, these results are /cached/ if
|
||||
`mu4e-cache-maildir-list' is customized to non-nil. In that case,
|
||||
the list of maildirs will not change until you restart mu4e."
|
||||
(unless (and mu4e-maildir-list mu4e-cache-maildir-list)
|
||||
(setq mu4e-maildir-list
|
||||
(sort
|
||||
(append
|
||||
(when (file-accessible-directory-p
|
||||
(mu4e-join-paths
|
||||
(mu4e-root-maildir) "cur"))
|
||||
'("/"))
|
||||
(mu4e--get-maildirs-1 (mu4e-root-maildir) "/"))
|
||||
(lambda (s1 s2)
|
||||
(string< (downcase s1) (downcase s2))))))
|
||||
"Get maildirs under `mu4e-maildir'."
|
||||
mu4e-maildir-list)
|
||||
|
||||
(defun mu4e-ask-maildir (prompt)
|
||||
|
|
|
@ -226,9 +226,9 @@ the search."
|
|||
|
||||
|
||||
(defun mu4e-search-maildir (maildir &optional edit)
|
||||
"Search the messages in maildir.
|
||||
The user is prompted to ask what maildir. If prefix arg EDIT is
|
||||
given, offer to edit the search query before executing it."
|
||||
"Search the messages in MAILDIR.
|
||||
The user is prompted to ask what maildir. If prefix-argument EDIT
|
||||
is given, offer to edit the search query before executing it."
|
||||
(interactive
|
||||
(let ((maildir (mu4e-ask-maildir "Jump to maildir: ")))
|
||||
(list maildir current-prefix-arg)))
|
||||
|
|
|
@ -88,6 +88,10 @@ to take effect, you need to stop/start mu4e."
|
|||
:group 'mu4e
|
||||
:safe 'booleanp)
|
||||
|
||||
|
||||
;; Cached data
|
||||
(defvar mu4e-maildir-list)
|
||||
|
||||
|
||||
;; Handlers are not strictly internal, but are not meant
|
||||
;; for overriding outside mu4e. The are mainly for breaking
|
||||
|
@ -398,6 +402,12 @@ The server output is as follows:
|
|||
((plist-get sexp :info)
|
||||
(funcall mu4e-info-func sexp))
|
||||
|
||||
;; get some data
|
||||
((plist-get sexp :data)
|
||||
(pcase (plist-get sexp :data)
|
||||
('maildirs (setq mu4e-maildir-list (plist-get sexp :value)))
|
||||
(_ (mu4e-warn "unknown data kind"))))
|
||||
|
||||
;; receive an error
|
||||
((plist-get sexp :error)
|
||||
(funcall mu4e-error-func
|
||||
|
@ -577,6 +587,12 @@ get at most MAX contacts."
|
|||
:tstamp ,(or tstamp nil)
|
||||
:maxnum ,(or maxnum nil))))
|
||||
|
||||
(defun mu4e--server-data (kind)
|
||||
"Request data of some KIND.
|
||||
KIND is a symbol. Currently supported kinds: maildirs."
|
||||
(mu4e--server-call-mu
|
||||
`(data :kind ,kind)))
|
||||
|
||||
(defun mu4e--server-find (query threads sortfield sortdir maxnum skip-dups
|
||||
include-related)
|
||||
"Run QUERY with THREADS SORTFIELD SORTDIR MAXNUM SKIP-DUPS INCLUDE-RELATED.
|
||||
|
|
|
@ -148,8 +148,10 @@ Otherwise, check requirements, then start mu4e. When successful, invoke
|
|||
(add-hook 'mu4e-query-items-updated-hook #'mu4e--main-redraw)
|
||||
(mu4e--query-items-refresh 'reset-baseline)
|
||||
(mu4e--server-ping)
|
||||
;; ask for the maildir-list
|
||||
(mu4e--server-data 'maildirs)
|
||||
;; maybe request the list of contacts, automatically refreshed after
|
||||
;; reindexing
|
||||
;; re-indexing
|
||||
(unless mu4e--contacts-set
|
||||
(mu4e--request-contacts-maybe)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue