From: David Edmondson <dme@dme.org>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/3] emacs: Fix Fcc generation.
Date: Thu, 25 Nov 2010 10:59:09 +0000 [thread overview]
Message-ID: <1290682750-30283-2-git-send-email-dme@dme.org> (raw)
In-Reply-To: <1290632444-10046-1-git-send-email-cworth@cworth.org>
The previous code did not correctly identify an old configuration and,
as a consequence, broke new configurations.
Minor re-arrangement to assist testing.
---
emacs/notmuch-maildir-fcc.el | 107 +++++++++++++++++++++---------------------
1 files changed, 53 insertions(+), 54 deletions(-)
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index e5e0549..349c4d9 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -70,6 +70,31 @@ yet when sending a mail."
;; add a hook to actually insert the Fcc header when sending
(add-hook 'message-header-setup-hook 'notmuch-fcc-header-setup))
+(defun notmuch-fcc-determine-folder (configuration from)
+ "Determine the correct folder to be used for Fcc."
+
+ (cond
+ ((stringp configuration)
+ configuration)
+
+ ((and (listp configuration)
+ (stringp (car configuration)))
+ ;; Old style - no longer works.
+ (error "Invalid Fcc configuration (old style)"))
+
+ ((listp configuration)
+ (let ((match
+ (catch 'first-match
+ (dolist (re-folder configuration)
+ (when (string-match-p (car re-folder) from)
+ (throw 'first-match re-folder))))))
+ (if match
+ (cdr match)
+ nil)))
+
+ (t
+ (error "Invalid Fcc configuration (neither string nor list)"))))
+
(defun notmuch-fcc-header-setup ()
"Add an Fcc header to the current message buffer.
@@ -77,63 +102,37 @@ Can be added to `message-send-hook' and will set the Fcc header
based on the values of `notmuch-fcc-dirs'. An existing Fcc header
will NOT be removed or replaced."
- (let ((subdir
- (cond
- ((or (not notmuch-fcc-dirs)
- (message-fetch-field "Fcc"))
- ;; Nothing set or an existing header.
- nil)
-
- ((stringp notmuch-fcc-dirs)
- notmuch-fcc-dirs)
-
- ((and (listp notmuch-fcc-dirs)
- (= 1 (length (car notmuch-fcc-dirs))))
- ;; Old style - no longer works.
- (error "Invalid `notmuch-fcc-dirs' setting (old style)"))
-
- ((listp notmuch-fcc-dirs)
- (let* ((from (message-fetch-field "From"))
- (match
- (catch 'first-match
- (dolist (re-folder notmuch-fcc-dirs)
- (when (string-match-p (car re-folder) from)
- (throw 'first-match re-folder))))))
- (if match
- (cdr match)
- (message "No Fcc header added.")
- nil)))
-
- (t
- (error "Invalid `notmuch-fcc-dirs' setting (neither string nor list)")))))
-
- (when subdir
- (message-add-header
- (concat "Fcc: "
- ;; 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-fetch-field "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"))))))))
-
+ (when notmuch-fcc-dirs
+ (let* ((from (or (message-fetch-field "From") ""))
+ (subdir (notmuch-fcc-determine-folder notmuch-fcc-dirs from)))
+
+ (when subdir
+ (message-add-header
+ (concat "Fcc: "
+ ;; 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-fetch-field "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")))))))))
+
(defun notmuch-maildir-fcc-host-fixer (hostname)
(replace-regexp-in-string "/\\|:"
'(lambda (s)
- (cond ((string-equal s "/") "\\057")
- ((string-equal s ":") "\\072")
- (t s)))
+ (cond ((string-equal s "/") "\\057")
+ ((string-equal s ":") "\\072")
+ (t s)))
hostname
t
t))
--
1.7.2.3
next prev parent reply other threads:[~2010-11-25 11:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-24 21:00 [PATCH] Workaround broken check for old-style notmuch-fcc-dirs Carl Worth
2010-11-25 10:59 ` [PATCH 1/3] test: Add ERT for emacs testing David Edmondson
2010-11-25 12:02 ` David Edmondson
2010-11-25 14:09 ` [PATCH] test: Add some more emacs tests David Edmondson
2010-11-25 10:59 ` David Edmondson [this message]
2010-11-25 10:59 ` [PATCH 3/3] test: Add ERT tests for Fcc determination David Edmondson
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=1290682750-30283-2-git-send-email-dme@dme.org \
--to=dme@dme.org \
--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).