Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 1C07D41A540 for ; Thu, 25 Nov 2010 03:03:26 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RzJRJUdIwra5 for ; Thu, 25 Nov 2010 03:03:24 -0800 (PST) Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com [74.125.82.181]) by olra.theworths.org (Postfix) with ESMTP id 9A4A3431FB6 for ; Thu, 25 Nov 2010 03:03:24 -0800 (PST) Received: by mail-wy0-f181.google.com with SMTP id 22so827352wyf.26 for ; Thu, 25 Nov 2010 03:03:24 -0800 (PST) Received: by 10.216.3.130 with SMTP id 2mr651683weh.3.1290683004054; Thu, 25 Nov 2010 03:03:24 -0800 (PST) Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com [81.149.164.25]) by mx.google.com with ESMTPS id w41sm254090weq.8.2010.11.25.03.03.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 25 Nov 2010 03:03:19 -0800 (PST) Received: by ut.hh.sledj.net (Postfix, from userid 1000) id 9601B59405B; Thu, 25 Nov 2010 10:59:19 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH 2/3] emacs: Fix Fcc generation. Date: Thu, 25 Nov 2010 10:59:09 +0000 Message-Id: <1290682750-30283-2-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1290632444-10046-1-git-send-email-cworth@cworth.org> References: <1290632444-10046-1-git-send-email-cworth@cworth.org> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Nov 2010 11:03:26 -0000 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