X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=emacs%2Fnotmuch-maildir-fcc.el;h=d9a8f9b6c258d2ca3db3c37a85a31fb9bf8d988c;hb=b749bd5390ce8b478de202495574c441dd875edf;hp=91c174c7a0afcf9ae644e3180a642f6e9bf7d5d2;hpb=4b34effca5a7dcde66737ab62f64d9d76213209a;p=notmuch diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el index 91c174c7..d9a8f9b6 100644 --- a/emacs/notmuch-maildir-fcc.el +++ b/emacs/notmuch-maildir-fcc.el @@ -47,7 +47,6 @@ (defun notmuch-fcc-initialization () "If notmuch-fcc-directories is set, hook them into the message-fcc-handler-function" -(if (not (eq notmuch-fcc-dirs nil)) (progn ;Set up the message-fcc-handler to move mails to the maildir in Fcc ;The parameter is hardcoded to mark messages as "seen" (setq message-fcc-handler-function @@ -57,7 +56,7 @@ ;(preferrably we would use message-header-setup-up, but notmuch-reply ; munges headers after that is run, so it won't work for replies within ; notmuch) - (add-hook 'message-send-hook 'notmuch-fcc-header-setup)))) + (add-hook 'message-send-hook 'notmuch-fcc-header-setup)) (defun notmuch-fcc-header-setup () "Can be added to message-send-hook and will set the FCC header @@ -70,8 +69,19 @@ (let ((subdir (cdr (assoc-string (message-fetch-field "from") notmuch-fcc-dirs t)))) (if (eq subdir nil) (setq subdir (car (car notmuch-fcc-dirs)))) - (message-remove-header "Fcc") - (message-add-header (concat "Fcc: " message-directory subdir))))) + (unless (message-fetch-field "fcc") + (message-add-header (concat "Fcc: " + (file-name-as-directory message-directory) + subdir))) + (let ((fcc-header (message-fetch-field "fcc"))) + (unless (notmuch-maildir-fcc-dir-is-maildir-p fcc-header) + (cond ((not (file-writable-p fcc-header)) + (error (format "%s is not a maildir, but you don't have permission to create one." fcc-header))) + ((y-or-n-p (format "%s is not a maildir. Create it? " + fcc-header)) + (notmuch-maildir-fcc-create-maildir fcc-header)) + (t + (error "Not sending message.")))))))) (defun notmuch-maildir-fcc-host-fixer (hostname) (replace-regexp-in-string "/\\|:" @@ -101,6 +111,16 @@ (file-exists-p (concat dir "/new/")) (file-exists-p (concat dir "/tmp/")))) +(defun notmuch-maildir-fcc-create-maildir (path) + (cond ((or (not (file-exists-p path)) (file-directory-p path)) + (make-directory (concat path "/cur/") t) + (make-directory (concat path "/new/") t) + (make-directory (concat path "/tmp/") t)) + ((file-regular-p path) + (error "%s is a file. Can't creat maildir." path)) + (t + (error "I don't know how to create a maildir here")))) + (defun notmuch-maildir-fcc-save-buffer-to-tmp (destdir) "Returns the msg id of the message written to the temp directory if successful, nil if not." @@ -111,8 +131,8 @@ if successful, nil if not." (write-file (concat destdir "/tmp/" msg-id)) msg-id) (t - (message (format "Can't write to %s. Not a maildir." - destdir)) + (error (format "Can't write to %s. Not a maildir." + destdir)) nil)))) (defun notmuch-maildir-fcc-move-tmp-to-new (destdir msg-id)