* [PATCH v2 1/6] emacs: notmuch-check-exit-status bugfix
2016-09-03 22:59 [PATCH v2 0/6] Use notmuch insert for fcc Mark Walters
@ 2016-09-03 22:59 ` Mark Walters
2016-09-04 11:31 ` David Bremner
2016-09-03 22:59 ` [PATCH v2 2/6] emacs: maildir-fcc: prepare for use of notmuch insert Mark Walters
` (4 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: Mark Walters @ 2016-09-03 22:59 UTC (permalink / raw)
To: notmuch
This function prints diagnostic information in the event of an
error. However, one of the callers has an optional :stdin-string
keyword argument. This causes the error printing routine to error
itself.
Rather than reach notmuch-check-exit-status about the possible keyword
arguments (currently only one but could be more in the future) this
commit just tells notmuch-check-exit-status how to print non-string arguments.
---
emacs/notmuch-lib.el | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 1781af4..2f015b0 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -790,9 +790,15 @@ You may need to restart Emacs or upgrade your notmuch package."))
(insert-file-contents err-file)
(unless (eobp)
(buffer-string)))))
+ (command-string
+ (mapconcat (lambda (arg)
+ (shell-quote-argument
+ (cond ((stringp arg) arg)
+ ((symbolp arg) (symbol-name arg))
+ (t "*UNKNOWN ARGUMENT*"))))
+ command " "))
(extra
- (concat
- "command: " (mapconcat #'shell-quote-argument command " ") "\n"
+ (concat "command: " command-string "\n"
(if (integerp exit-status)
(format "exit status: %s\n" exit-status)
(format "exit signal: %s\n" exit-status))
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/6] emacs: maildir-fcc: prepare for use of notmuch insert
2016-09-03 22:59 [PATCH v2 0/6] Use notmuch insert for fcc Mark Walters
2016-09-03 22:59 ` [PATCH v2 1/6] emacs: notmuch-check-exit-status bugfix Mark Walters
@ 2016-09-03 22:59 ` Mark Walters
2016-09-03 22:59 ` [PATCH v2 3/6] emacs: maildir import message-do-fcc Mark Walters
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Mark Walters @ 2016-09-03 22:59 UTC (permalink / raw)
To: notmuch
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 3/6] emacs: maildir import message-do-fcc
2016-09-03 22:59 [PATCH v2 0/6] Use notmuch insert for fcc Mark Walters
2016-09-03 22:59 ` [PATCH v2 1/6] emacs: notmuch-check-exit-status bugfix Mark Walters
2016-09-03 22:59 ` [PATCH v2 2/6] emacs: maildir-fcc: prepare for use of notmuch insert Mark Walters
@ 2016-09-03 22:59 ` Mark Walters
2016-09-03 22:59 ` [PATCH v2 4/6] emacs: simplify our local copy of message-do-fcc Mark Walters
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Mark Walters @ 2016-09-03 22:59 UTC (permalink / raw)
To: notmuch
We will need our own local copy of message-do-fcc so this commit just
copies the code straight from message.el so that it is easier to see
our local changes coming in the next commit.
---
emacs/notmuch-maildir-fcc.el | 64 ++++++++++++++++++++++++++++++++++++++++++++
emacs/notmuch-mua.el | 7 +++--
2 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 835258f..6fed11f 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -120,6 +120,70 @@ by notmuch-mua-mail"
subdir
(concat (notmuch-database-path) "/" subdir))))))
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Functions for saving a message either using notmuch insert or file
+;; fcc. First functions common to the two cases.
+
+(defun notmuch-maildir-message-do-fcc ()
+ "Process Fcc headers in the current buffer.
+
+This is a direct copy from message-mode's message-do-fcc."
+ (let ((case-fold-search t)
+ (buf (current-buffer))
+ list file
+ (mml-externalize-attachments message-fcc-externalize-attachments))
+ (save-excursion
+ (save-restriction
+ (message-narrow-to-headers)
+ (setq file (message-fetch-field "fcc" t)))
+ (when file
+ (set-buffer (get-buffer-create " *message temp*"))
+ (erase-buffer)
+ (insert-buffer-substring buf)
+ (message-encode-message-body)
+ (save-restriction
+ (message-narrow-to-headers)
+ (while (setq file (message-fetch-field "fcc" t))
+ (push file list)
+ (message-remove-header "fcc" nil t))
+ (let ((mail-parse-charset message-default-charset)
+ (rfc2047-header-encoding-alist
+ (cons '("Newsgroups" . default)
+ rfc2047-header-encoding-alist)))
+ (mail-encode-encoded-word-buffer)))
+ (goto-char (point-min))
+ (when (re-search-forward
+ (concat "^" (regexp-quote mail-header-separator) "$")
+ nil t)
+ (replace-match "" t t ))
+ ;; Process FCC operations.
+ (while list
+ (setq file (pop list))
+ (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
+ ;; Pipe the article to the program in question.
+ (call-process-region (point-min) (point-max) shell-file-name
+ nil nil nil shell-command-switch
+ (match-string 1 file))
+ ;; Save the article.
+ (setq file (expand-file-name file))
+ (unless (file-exists-p (file-name-directory file))
+ (make-directory (file-name-directory file) t))
+ (if (and message-fcc-handler-function
+ (not (eq message-fcc-handler-function 'rmail-output)))
+ (funcall message-fcc-handler-function file)
+ ;; FIXME this option, rmail-output (also used if
+ ;; message-fcc-handler-function is nil) is not
+ ;; documented anywhere AFAICS. It should work in Emacs
+ ;; 23; I suspect it does not work in Emacs 22.
+ ;; FIXME I don't see the need for the two different cases here.
+ ;; mail-use-rfc822 makes no difference (in Emacs 23),and
+ ;; the third argument just controls \"Wrote file\" message.
+ (if (and (file-readable-p file) (mail-file-babyl-p file))
+ (rmail-output file 1 nil t)
+ (let ((mail-use-rfc822 t))
+ (rmail-output file 1 t t))))))
+ (kill-buffer (current-buffer))))))
+
(defun notmuch-fcc-handler (fcc-header)
"Store message with file fcc."
(notmuch-maildir-fcc-file-fcc fcc-header))
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index f3a4e5a..61b029b 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -33,6 +33,7 @@
(declare-function notmuch-show-insert-body "notmuch-show" (msg body depth))
(declare-function notmuch-fcc-header-setup "notmuch-maildir-fcc" ())
(declare-function notmuch-fcc-handler "notmuch-maildir-fcc" (destdir))
+(declare-function notmuch-maildir-message-do-fcc "notmuch-maildir-fcc" ())
;;
@@ -491,12 +492,14 @@ will be addressed to all recipients of the source message."
(defun notmuch-mua-send-and-exit (&optional arg)
(interactive "P")
(let ((message-fcc-handler-function #'notmuch-fcc-handler))
- (message-send-and-exit arg)))
+ (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
+ (message-send-and-exit arg))))
(defun notmuch-mua-send (&optional arg)
(interactive "P")
(let ((message-fcc-handler-function #'notmuch-fcc-handler))
- (message-send arg)))
+ (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
+ (message-send arg))))
(defun notmuch-mua-kill-buffer ()
(interactive)
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 4/6] emacs: simplify our local copy of message-do-fcc
2016-09-03 22:59 [PATCH v2 0/6] Use notmuch insert for fcc Mark Walters
` (2 preceding siblings ...)
2016-09-03 22:59 ` [PATCH v2 3/6] emacs: maildir import message-do-fcc Mark Walters
@ 2016-09-03 22:59 ` Mark Walters
2016-09-03 22:59 ` [PATCH v2 5/6] Modify " Mark Walters
2016-09-03 22:59 ` [PATCH v2 6/6] emacs: maildir: add the actual insert code Mark Walters
5 siblings, 0 replies; 8+ messages in thread
From: Mark Walters @ 2016-09-03 22:59 UTC (permalink / raw)
To: notmuch
message-do-fcc has lots of functionality we don't need, so remove it.
---
emacs/notmuch-maildir-fcc.el | 31 +++----------------------------
emacs/notmuch-mua.el | 11 ++++-------
2 files changed, 7 insertions(+), 35 deletions(-)
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index 6fed11f..b01f009 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -127,7 +127,7 @@ by notmuch-mua-mail"
(defun notmuch-maildir-message-do-fcc ()
"Process Fcc headers in the current buffer.
-This is a direct copy from message-mode's message-do-fcc."
+This is a rearranged version of message mode's message-do-fcc."
(let ((case-fold-search t)
(buf (current-buffer))
list file
@@ -146,10 +146,7 @@ This is a direct copy from message-mode's message-do-fcc."
(while (setq file (message-fetch-field "fcc" t))
(push file list)
(message-remove-header "fcc" nil t))
- (let ((mail-parse-charset message-default-charset)
- (rfc2047-header-encoding-alist
- (cons '("Newsgroups" . default)
- rfc2047-header-encoding-alist)))
+ (let ((mail-parse-charset message-default-charset))
(mail-encode-encoded-word-buffer)))
(goto-char (point-min))
(when (re-search-forward
@@ -159,29 +156,7 @@ This is a direct copy from message-mode's message-do-fcc."
;; Process FCC operations.
(while list
(setq file (pop list))
- (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
- ;; Pipe the article to the program in question.
- (call-process-region (point-min) (point-max) shell-file-name
- nil nil nil shell-command-switch
- (match-string 1 file))
- ;; Save the article.
- (setq file (expand-file-name file))
- (unless (file-exists-p (file-name-directory file))
- (make-directory (file-name-directory file) t))
- (if (and message-fcc-handler-function
- (not (eq message-fcc-handler-function 'rmail-output)))
- (funcall message-fcc-handler-function file)
- ;; FIXME this option, rmail-output (also used if
- ;; message-fcc-handler-function is nil) is not
- ;; documented anywhere AFAICS. It should work in Emacs
- ;; 23; I suspect it does not work in Emacs 22.
- ;; FIXME I don't see the need for the two different cases here.
- ;; mail-use-rfc822 makes no difference (in Emacs 23),and
- ;; the third argument just controls \"Wrote file\" message.
- (if (and (file-readable-p file) (mail-file-babyl-p file))
- (rmail-output file 1 nil t)
- (let ((mail-use-rfc822 t))
- (rmail-output file 1 t t))))))
+ (notmuch-fcc-handler file))
(kill-buffer (current-buffer))))))
(defun notmuch-fcc-handler (fcc-header)
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 61b029b..b60ed05 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -32,7 +32,6 @@
(declare-function notmuch-show-insert-body "notmuch-show" (msg body depth))
(declare-function notmuch-fcc-header-setup "notmuch-maildir-fcc" ())
-(declare-function notmuch-fcc-handler "notmuch-maildir-fcc" (destdir))
(declare-function notmuch-maildir-message-do-fcc "notmuch-maildir-fcc" ())
;;
@@ -491,15 +490,13 @@ will be addressed to all recipients of the source message."
(defun notmuch-mua-send-and-exit (&optional arg)
(interactive "P")
- (let ((message-fcc-handler-function #'notmuch-fcc-handler))
- (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
- (message-send-and-exit arg))))
+ (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
+ (message-send-and-exit arg)))
(defun notmuch-mua-send (&optional arg)
(interactive "P")
- (let ((message-fcc-handler-function #'notmuch-fcc-handler))
- (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
- (message-send arg))))
+ (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
+ (message-send arg)))
(defun notmuch-mua-kill-buffer ()
(interactive)
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 5/6] Modify our local copy of message-do-fcc
2016-09-03 22:59 [PATCH v2 0/6] Use notmuch insert for fcc Mark Walters
` (3 preceding siblings ...)
2016-09-03 22:59 ` [PATCH v2 4/6] emacs: simplify our local copy of message-do-fcc Mark Walters
@ 2016-09-03 22:59 ` Mark Walters
2016-09-03 22:59 ` [PATCH v2 6/6] emacs: maildir: add the actual insert code Mark Walters
5 siblings, 0 replies; 8+ messages in thread
From: Mark Walters @ 2016-09-03 22:59 UTC (permalink / raw)
To: notmuch
Since we also need to use this code for the draft handling we split
message-do-fcc into convenient sub-chunks (functions or macros as
appropriate).
---
emacs/notmuch-maildir-fcc.el | 63 ++++++++++++++++++++++++++------------------
1 file changed, 38 insertions(+), 25 deletions(-)
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index b01f009..cda51e7 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -124,40 +124,53 @@ by notmuch-mua-mail"
;; Functions for saving a message either using notmuch insert or file
;; fcc. First functions common to the two cases.
+(defmacro with-temporary-notmuch-message-buffer (&rest body)
+ "Set-up a temporary copy of the current message-mode buffer."
+ `(let ((case-fold-search t)
+ (buf (current-buffer))
+ (mml-externalize-attachments message-fcc-externalize-attachments))
+ (with-current-buffer (get-buffer-create " *message temp*")
+ (erase-buffer)
+ (insert-buffer-substring buf)
+ ,@body)))
+
+(defun notmuch-maildir-setup-message-for-saving ()
+ "Setup message for saving. Should be called on a temporary copy.
+
+This is taken from the function message-do-fcc."
+ (message-encode-message-body)
+ (save-restriction
+ (message-narrow-to-headers)
+ (let ((mail-parse-charset message-default-charset))
+ (mail-encode-encoded-word-buffer)))
+ (goto-char (point-min))
+ (when (re-search-forward
+ (concat "^" (regexp-quote mail-header-separator) "$")
+ nil t)
+ (replace-match "" t t )))
+
(defun notmuch-maildir-message-do-fcc ()
"Process Fcc headers in the current buffer.
This is a rearranged version of message mode's message-do-fcc."
- (let ((case-fold-search t)
- (buf (current-buffer))
- list file
- (mml-externalize-attachments message-fcc-externalize-attachments))
+ (let (list file)
(save-excursion
(save-restriction
(message-narrow-to-headers)
(setq file (message-fetch-field "fcc" t)))
(when file
- (set-buffer (get-buffer-create " *message temp*"))
- (erase-buffer)
- (insert-buffer-substring buf)
- (message-encode-message-body)
- (save-restriction
- (message-narrow-to-headers)
- (while (setq file (message-fetch-field "fcc" t))
- (push file list)
- (message-remove-header "fcc" nil t))
- (let ((mail-parse-charset message-default-charset))
- (mail-encode-encoded-word-buffer)))
- (goto-char (point-min))
- (when (re-search-forward
- (concat "^" (regexp-quote mail-header-separator) "$")
- nil t)
- (replace-match "" t t ))
- ;; Process FCC operations.
- (while list
- (setq file (pop list))
- (notmuch-fcc-handler file))
- (kill-buffer (current-buffer))))))
+ (with-temporary-notmuch-message-buffer
+ (save-restriction
+ (message-narrow-to-headers)
+ (while (setq file (message-fetch-field "fcc" t))
+ (push file list)
+ (message-remove-header "fcc" nil t)))
+ (notmuch-maildir-setup-message-for-saving)
+ ;; Process FCC operations.
+ (while list
+ (setq file (pop list))
+ (notmuch-fcc-handler file))
+ (kill-buffer (current-buffer)))))))
(defun notmuch-fcc-handler (fcc-header)
"Store message with file fcc."
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 6/6] emacs: maildir: add the actual insert code
2016-09-03 22:59 [PATCH v2 0/6] Use notmuch insert for fcc Mark Walters
` (4 preceding siblings ...)
2016-09-03 22:59 ` [PATCH v2 5/6] Modify " Mark Walters
@ 2016-09-03 22:59 ` Mark Walters
5 siblings, 0 replies; 8+ messages in thread
From: Mark Walters @ 2016-09-03 22:59 UTC (permalink / raw)
To: notmuch
With all the preparation it is now simple to add the actual insert
code. Since insert can fail for many reasons we let the user decide
interactively deal with it.
We modify test-lib.el to set file fcc, so that all the old tests and
emacs_fcc_message from test-lib.sh still work
---
emacs/notmuch-maildir-fcc.el | 74 ++++++++++++++++++++++++++++++++++++++++++--
test/test-lib.el | 5 +++
2 files changed, 76 insertions(+), 3 deletions(-)
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index cda51e7..1218c01 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -65,6 +65,12 @@ yet when sending a mail."
:require 'notmuch-fcc-initialization
:group 'notmuch-send)
+(defcustom notmuch-maildir-use-notmuch-insert 't
+ "Should fcc use notmuch insert instead of simple fcc"
+ :type '(choice :tag "Fcc Method"
+ (const :tag "Use notmuch insert" t)
+ (const :tag "Use simple fcc" nil))
+ :group 'notmuch-send)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Functions which set up the fcc header in the message buffer.
@@ -108,7 +114,18 @@ by notmuch-mua-mail"
(error "Invalid `notmuch-fcc-dirs' setting (neither string nor list)")))))
(when subdir
- (notmuch-maildir-add-file-style-fcc-header subdir))))
+ (if notmuch-maildir-use-notmuch-insert
+ (notmuch-maildir-add-notmuch-insert-style-fcc-header subdir)
+ (notmuch-maildir-add-file-style-fcc-header subdir)))))
+
+(defun notmuch-maildir-add-notmuch-insert-style-fcc-header (subdir)
+ ;; Notmuch insert does not accept absolute paths, so check the user
+ ;; really want this header inserted.
+
+ (when (or (not (= (elt subdir 0) ?/))
+ (y-or-n-p (format "Fcc header %s is an absolute path and notmuch insert is requested.\nInsert header anyway? "
+ subdir)))
+ (message-add-header (concat "Fcc: " subdir))))
(defun notmuch-maildir-add-file-style-fcc-header (subdir)
(message-add-header
@@ -173,8 +190,59 @@ This is a rearranged version of message mode's message-do-fcc."
(kill-buffer (current-buffer)))))))
(defun notmuch-fcc-handler (fcc-header)
- "Store message with file fcc."
- (notmuch-maildir-fcc-file-fcc fcc-header))
+ "Store message with notmuch insert or normal (file) fcc.
+
+If `notmuch-maildir-use-notmuch-insert` is set then store the
+message using notmuch insert. Otherwise store the message using
+normal fcc."
+ (if notmuch-maildir-use-notmuch-insert
+ (notmuch-maildir-fcc-with-notmuch-insert fcc-header)
+ (notmuch-maildir-fcc-file-fcc fcc-header)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Functions for saving a message using notmuch insert.
+
+(defun notmuch-maildir-notmuch-insert-current-buffer (folder &optional create tags)
+ "Use notmuch insert to put the current buffer in the database.
+
+This inserts the current buffer as a message into the notmuch
+database in folder FOLDER. If CREATE is non-nil it will supply
+the --create-folder flag to create the folder if necessary. TAGS
+should be a list of tag changes to apply to the inserted message."
+ (let* ((args (append (when create (list "--create-folder"))
+ (list (concat "--folder=" folder))
+ tags)))
+ (apply 'notmuch-call-notmuch-process
+ :stdin-string (buffer-string) "insert" args)))
+
+(defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
+ "Store message with notmuch insert.
+
+The fcc-header should be of the form \"folder +tag1 -tag2\" where
+folder is the folder (relative to the notmuch mailstore) to store
+the message in, and tag1 and tag2 are tag changes to apply to the
+stored message. If CREATE is non-nil then create the folder if
+necessary."
+ (let* ((args (split-string-and-unquote fcc-header))
+ (folder (car args))
+ (tags (cdr args)))
+ (condition-case nil
+ (notmuch-maildir-notmuch-insert-current-buffer folder create tags)
+ ;; Since there are many reasons notmuch insert could fail, e.g.,
+ ;; locked database, non-existent folder (which could be due to a
+ ;; typo, or just the user want a new folder, let the user decide
+ ;; how to deal with it.
+ (error
+ (let ((response (read-char-choice
+ "Insert failed: (r)etry, (c)reate folder, (i)gnore, or (e)dit the header? "
+ '(?r ?c ?i ?e))))
+ (case response
+ (?r (notmuch-maildir-fcc-with-notmuch-insert fcc-header))
+ (?c (notmuch-maildir-fcc-with-notmuch-insert fcc-header 't))
+ (?i 't)
+ (?e (notmuch-maildir-fcc-with-notmuch-insert
+ (read-from-minibuffer "Fcc header: " fcc-header)))))))))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Functions for saving a message using file fcc.
diff --git a/test/test-lib.el b/test/test-lib.el
index 496626f..9946010 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -184,6 +184,11 @@ nothing."
(setq notmuch-tag-deleted-formats
'((".*" nil)))
+;; Also for historical reasons, we set the fcc handler to file not
+;; insert.
+
+(setq notmuch-maildir-use-notmuch-insert nil)
+
;; force a common html renderer, to avoid test variations between
;; environments
--
2.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread