From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/6] emacs: maildir-fcc: prepare for use of notmuch insert
Date: Sat, 11 Jun 2016 00:02:48 +0100 [thread overview]
Message-ID: <1465599772-10297-3-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1465599772-10297-1-git-send-email-markwalters1009@gmail.com>
We move some code around in preparation for the use of notmuch
insert. In particular, we move the check for a valid maildir for the
fcc to when the message is sent rather than when the fcc header is
inserted. The main motivation is consistency with the insert version
(coming later) where we cannot check the validity until send.
We allow the user some chance to correct the header; the choice here
is intended to be consistent with the insert version to come.
---
emacs/notmuch-maildir-fcc.el | 69 ++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 25 deletions(-)
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index bbf6132..835258f 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -65,11 +65,9 @@ yet when sending a mail."
:require 'notmuch-fcc-initialization
:group 'notmuch-send)
-(defun notmuch-fcc-handler (destdir)
- "Write buffer to `destdir', marking it as sent
-Intended to be dynamically bound to `message-fcc-handler-function'"
- (notmuch-maildir-fcc-write-buffer-to-maildir destdir t))
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Functions which set up the fcc header in the message buffer.
(defun notmuch-fcc-header-setup ()
"Add an Fcc header to the current message buffer.
@@ -110,27 +108,25 @@ by notmuch-mua-mail"
(error "Invalid `notmuch-fcc-dirs' setting (neither string nor list)")))))
(when subdir
- (message-add-header
- (concat "Fcc: "
- (file-truename
- ;; If the resulting directory is not an absolute path,
- ;; prepend the standard notmuch database path.
- (if (= (elt subdir 0) ?/)
- subdir
- (concat (notmuch-database-path) "/" subdir)))))
-
- ;; finally test if fcc points to a valid maildir
- (let ((fcc-header (message-field-value "Fcc")))
- (unless (notmuch-maildir-fcc-dir-is-maildir-p fcc-header)
- (cond ((not (file-writable-p fcc-header))
- (error (format "No permission to create %s, which does not exist"
- 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 "Message not sent"))))))))
-
+ (notmuch-maildir-add-file-style-fcc-header subdir))))
+
+(defun notmuch-maildir-add-file-style-fcc-header (subdir)
+ (message-add-header
+ (concat "Fcc: "
+ (file-truename
+ ;; If the resulting directory is not an absolute path,
+ ;; prepend the standard notmuch database path.
+ (if (= (elt subdir 0) ?/)
+ subdir
+ (concat (notmuch-database-path) "/" subdir))))))
+
+(defun notmuch-fcc-handler (fcc-header)
+ "Store message with file fcc."
+ (notmuch-maildir-fcc-file-fcc fcc-header))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Functions for saving a message using file fcc.
+
(defun notmuch-maildir-fcc-host-fixer (hostname)
(replace-regexp-in-string "/\\|:"
(lambda (s)
@@ -192,6 +188,29 @@ if successful, nil if not."
(concat destdir "/tmp/" msg-id)
(concat destdir "/cur/" msg-id ":2," (when mark-seen "S"))))
+(defun notmuch-maildir-fcc-file-fcc (fcc-header)
+ "Write the message to the file specified by FCC-HEADER.
+
+It offers the user a chance to correct the header, or filesystem,
+if needed."
+ (if (notmuch-maildir-fcc-dir-is-maildir-p fcc-header)
+ (notmuch-maildir-fcc-write-buffer-to-maildir fcc-header 't)
+ ;; The fcc-header is not a valid maildir see if the user wants to
+ ;; fix it in some way.
+ (let* ((prompt (format "Fcc %s is not a maildir: (r)etry, (c)reate folder, (i)gnore, or (e)dit the header? "
+ fcc-header))
+ (response (read-char-choice prompt '(?r ?c ?i ?e))))
+ (case response
+ (?r (notmuch-maildir-fcc-file-fcc fcc-header))
+ (?c (if (file-writable-p fcc-header)
+ (notmuch-maildir-fcc-create-maildir fcc-header)
+ (message "No permission to create %s." fcc-header)
+ (sit-for 2))
+ (notmuch-maildir-fcc-file-fcc fcc-header))
+ (?i 't)
+ (?e (notmuch-maildir-fcc-file-fcc
+ (read-from-minibuffer "Fcc header: " fcc-header)))))))
+
(defun notmuch-maildir-fcc-write-buffer-to-maildir (destdir &optional mark-seen)
"Writes the current buffer to maildir destdir. If mark-seen is
non-nil, it will write it to cur/, and mark it as read. It should
--
2.1.4
next prev parent reply other threads:[~2016-06-10 23:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-10 23:02 [PATCH 0/6] Use notmuch insert for fcc Mark Walters
2016-06-10 23:02 ` [PATCH 1/6] emacs: notmuch-check-exit-status bugfix Mark Walters
2016-06-10 23:02 ` Mark Walters [this message]
2016-06-10 23:02 ` [PATCH 3/6] emacs: maildir import message-do-fcc Mark Walters
2016-06-10 23:02 ` [PATCH 4/6] emacs: simplify our local copy of message-do-fcc Mark Walters
2016-09-03 20:20 ` David Bremner
2016-09-03 21:42 ` Mark Walters
2016-09-03 22:36 ` David Bremner
2016-06-10 23:02 ` [PATCH 5/6] Modify " Mark Walters
2016-09-03 20:33 ` David Bremner
2016-09-03 21:39 ` Mark Walters
2016-09-03 22:37 ` David Bremner
2016-06-10 23:02 ` [PATCH 6/6] emacs: maildir: add the actual insert code Mark Walters
2016-09-03 20:43 ` [PATCH 0/6] Use notmuch insert for fcc David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1465599772-10297-3-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).