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.
See `mu4e-trash-folder'." (mu4e--get-folder 'mu4e-trash-folder msg))
;;; Maildirs
(defun mu4e--guess-maildir (path)
"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)
"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
create it -- we cannot be sure creation succeeded here, since this
is done asynchronously. Otherwise, return nil. NOte, DIR has to be
an absolute path."
(if (and (file-exists-p dir) (not (file-directory-p dir)))
(mu4e-error "File %s exists, but is not a directory" dir)
(cond
((file-directory-p dir) t)
((yes-or-no-p (mu4e-format "%s does not exist yet. Create now?" dir))
(mu4e--server-mkdir dir) t)
(t nil))))
Return t if it already exists or (after asking) an attempt has been
to create it; otherwise return nil."
(let ((seems-to-exist (file-directory-p dir)))
(when (or seems-to-exist
(yes-or-no-p (mu4e-format "%s does not exist yet. Create now?" dir)))
;; even when the maildir already seems to exist,
;; call mkdir for a deeper check. However only get an update
;; when the maildir is totally new.
(mu4e--server-mkdir dir (not seems-to-exist)) t)))
(defun mu4e~get-maildirs-1 (path mdir)
"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 ()
"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: "))
(target (if (string= (substring target 0 1) "/")
target
(concat "/" target)))
(fulltarget (mu4e-join-paths (mu4e-root-maildir) target)))
(when (or (file-directory-p fulltarget)
(and (yes-or-no-p
(format "%s does not exist. Create now?" fulltarget))
(mu4e--server-mkdir fulltarget)))
(when (mu4e-create-maildir-maybe fulltarget)
target)))
(defun mu4e--mark-ask-target (mark)

View File

@ -557,9 +557,12 @@ the directory time stamp."
`(index :cleanup ,(and cleanup t)
:lazy-check ,(and lazy-check t))))
(defun mu4e--server-mkdir (path)
"Create a new maildir-directory at filesystem PATH."
(mu4e--server-call-mu `(mkdir :path ,path)))
(defun mu4e--server-mkdir (path &optional update)
"Create a new maildir-directory at filesystem 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)
"Move message identified by DOCID-OR-MSGID.