* mu4e-get-maildirs: make it work recursively

This commit is contained in:
djcb 2012-04-17 20:35:32 +03:00
parent a04a1ea449
commit 443a5a4fea
1 changed files with 36 additions and 17 deletions

View File

@ -109,25 +109,44 @@ Function returns the CHAR typed."
(setq okchar (member response optionkars))) (setq okchar (member response optionkars)))
response)) response))
(defun mu4e--get-maildirs-1 (path &optional mdir)
"Get maildirs under path, recursively, as a list of relative
paths."
;; first, we get a list of all directory paths under PATH that have a
;; directory 'cur' as leaf; then we we remove from that list all of those that
;; don't have tmp, new sister dirs. And there we're done!
(defun mu4e-get-maildirs (parentdir) ;; 1. get all proper subdirs of the current dir
"List the maildirs under PARENTDIR." ;; TODO: recursive? (let* ((subdirs
(let* ((files (directory-files parentdir))
(maildirs ;;
(remove-if (remove-if
(lambda (file) (lambda (de)
(let ((path (concat parentdir "/" file))) (or (not (file-directory-p (concat path mdir "/" de)))
(cond (string-match "\\.\\{1,2\\}$" de)))
((string-match "^\\.\\{1,2\\}$" file) t) ;; remove '..' and '.' (directory-files (concat path mdir))))
((not (file-directory-p path)) t) ;; remove non-dirs ;; 2. get the list of dirs with a /cur leaf dir
((not ;; remove non-maildirs (maildirs))
(and (file-directory-p (concat path "/cur")) (dolist (dir subdirs)
(file-directory-p (concat path "/new")) (if (string= dir "cur")
(file-directory-p (concat path "/tmp")))) t) ;; be pedantic, and insist on there being a new/tmp as well
(t nil) ;; otherwise, it's probably maildir (when (and (file-directory-p (concat path mdir "/new" ))
))) (file-directory-p (concat path mdir "/tmp")))
files))) (add-to-list 'maildirs mdir t))
(map 'list (lambda(dir) (concat "/" dir)) maildirs))) (setq maildirs (append maildirs
(mu4e--get-maildirs-1 path (concat mdir "/" dir))))))
maildirs))
(defun mu4e-get-maildirs (path)
"Get maildirs under path, recursively, as a list of relative
paths (ie., /archive, /sent etc.). Most of the work is done in `mu4e-get-maildirs-1,
but we handle the special-case of the top-level Maildir here."
(append
(when (and (file-directory-p (concat path "/cur"))
(file-directory-p (concat path "/tmp"))
(file-directory-p (concat path "/new")))
'("/"))
(mu4e--get-maildirs-1 path)))
(defun mu4e-ask-maildir (prompt) (defun mu4e-ask-maildir (prompt)
"Ask the user for a shortcut (using PROMPT) as defined in "Ask the user for a shortcut (using PROMPT) as defined in