mu4e: integrate mkdir better into mu4e

When moving to a non-existent folder, offer to create it and proceed from
there (that _almost_ worked earlier).

Fixes #628
Fixes #477
This commit is contained in:
Dirk-Jan C. Binnema
2023-02-12 11:17:59 +02:00
parent 76fedf4d64
commit 88cb22d178
3 changed files with 16 additions and 21 deletions

View File

@ -195,7 +195,6 @@ See `mu4e-sent-folder'." (mu4e--get-folder 'mu4e-sent-folder msg))
"Get the trash folder, optionallly based on MSG. "Get the trash folder, optionallly based on MSG.
See `mu4e-trash-folder'." (mu4e--get-folder 'mu4e-trash-folder msg)) See `mu4e-trash-folder'." (mu4e--get-folder 'mu4e-trash-folder msg))
;;; Maildirs ;;; Maildirs
(defun mu4e--guess-maildir (path) (defun mu4e--guess-maildir (path)
"Guess the maildir for PATH, or nil if cannot find it." "Guess the maildir for PATH, or nil if cannot find it."
@ -209,17 +208,15 @@ See `mu4e-trash-folder'." (mu4e--get-folder 'mu4e-trash-folder msg))
(defun mu4e-create-maildir-maybe (dir) (defun mu4e-create-maildir-maybe (dir)
"Offer to create maildir DIR if it does not exist yet. "Offer to create maildir DIR if it does not exist yet.
Return t if the dir already existed, or an attempt has been made to Return t if it already exists or (after asking) an attempt has been
create it -- we cannot be sure creation succeeded here, since this to create it; otherwise return nil."
is done asynchronously. Otherwise, return nil. NOte, DIR has to be (let ((seems-to-exist (file-directory-p dir)))
an absolute path." (when (or seems-to-exist
(if (and (file-exists-p dir) (not (file-directory-p dir))) (yes-or-no-p (mu4e-format "%s does not exist yet. Create now?" dir)))
(mu4e-error "File %s exists, but is not a directory" dir) ;; even when the maildir already seems to exist,
(cond ;; call mkdir for a deeper check. However only get an update
((file-directory-p dir) t) ;; when the maildir is totally new.
((yes-or-no-p (mu4e-format "%s does not exist yet. Create now?" dir)) (mu4e--server-mkdir dir (not seems-to-exist)) t)))
(mu4e--server-mkdir dir) t)
(t nil))))
(defun mu4e~get-maildirs-1 (path mdir) (defun mu4e~get-maildirs-1 (path mdir)
"Get maildirs for MDIR under PATH. "Get maildirs for MDIR under PATH.

View File

@ -280,17 +280,12 @@ The following marks are available, and the corresponding props:
(defun mu4e--mark-get-move-target () (defun mu4e--mark-get-move-target ()
"Ask for a move target, and propose to create it if it does not exist." "Ask for a move target, and propose to create it if it does not exist."
(interactive)
;; (mu4e-message-at-point) ;; raises error if there is none
(let* ((target (mu4e-ask-maildir "Move message to: ")) (let* ((target (mu4e-ask-maildir "Move message to: "))
(target (if (string= (substring target 0 1) "/") (target (if (string= (substring target 0 1) "/")
target target
(concat "/" target))) (concat "/" target)))
(fulltarget (mu4e-join-paths (mu4e-root-maildir) target))) (fulltarget (mu4e-join-paths (mu4e-root-maildir) target)))
(when (or (file-directory-p fulltarget) (when (mu4e-create-maildir-maybe fulltarget)
(and (yes-or-no-p
(format "%s does not exist. Create now?" fulltarget))
(mu4e--server-mkdir fulltarget)))
target))) target)))
(defun mu4e--mark-ask-target (mark) (defun mu4e--mark-ask-target (mark)

View File

@ -557,9 +557,12 @@ the directory time stamp."
`(index :cleanup ,(and cleanup t) `(index :cleanup ,(and cleanup t)
:lazy-check ,(and lazy-check t)))) :lazy-check ,(and lazy-check t))))
(defun mu4e--server-mkdir (path) (defun mu4e--server-mkdir (path &optional update)
"Create a new maildir-directory at filesystem PATH." "Create a new maildir-directory at filesystem PATH.
(mu4e--server-call-mu `(mkdir :path ,path))) When UPDATE is non-nil, send a update when completed."
(mu4e--server-call-mu `(mkdir
:path ,path
:update ,(or update nil))))
(defun mu4e--server-move (docid-or-msgid &optional maildir flags no-view) (defun mu4e--server-move (docid-or-msgid &optional maildir flags no-view)
"Move message identified by DOCID-OR-MSGID. "Move message identified by DOCID-OR-MSGID.