--- /dev/null
+Return-Path: <dme@dme.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1C07D41A540\r
+ for <notmuch@notmuchmail.org>; Thu, 25 Nov 2010 03:03:26 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id RzJRJUdIwra5 for <notmuch@notmuchmail.org>;\r
+ Thu, 25 Nov 2010 03:03:24 -0800 (PST)\r
+Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com\r
+ [74.125.82.181])\r
+ by olra.theworths.org (Postfix) with ESMTP id 9A4A3431FB6\r
+ for <notmuch@notmuchmail.org>; Thu, 25 Nov 2010 03:03:24 -0800 (PST)\r
+Received: by mail-wy0-f181.google.com with SMTP id 22so827352wyf.26\r
+ for <notmuch@notmuchmail.org>; Thu, 25 Nov 2010 03:03:24 -0800 (PST)\r
+Received: by 10.216.3.130 with SMTP id 2mr651683weh.3.1290683004054;\r
+ Thu, 25 Nov 2010 03:03:24 -0800 (PST)\r
+Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com\r
+ [81.149.164.25])\r
+ by mx.google.com with ESMTPS id w41sm254090weq.8.2010.11.25.03.03.18\r
+ (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
+ Thu, 25 Nov 2010 03:03:19 -0800 (PST)\r
+Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
+ id 9601B59405B; Thu, 25 Nov 2010 10:59:19 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/3] emacs: Fix Fcc generation.\r
+Date: Thu, 25 Nov 2010 10:59:09 +0000\r
+Message-Id: <1290682750-30283-2-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <1290632444-10046-1-git-send-email-cworth@cworth.org>\r
+References: <1290632444-10046-1-git-send-email-cworth@cworth.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 25 Nov 2010 11:03:26 -0000\r
+\r
+The previous code did not correctly identify an old configuration and,\r
+as a consequence, broke new configurations.\r
+\r
+Minor re-arrangement to assist testing.\r
+---\r
+ emacs/notmuch-maildir-fcc.el | 107 +++++++++++++++++++++---------------------\r
+ 1 files changed, 53 insertions(+), 54 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el\r
+index e5e0549..349c4d9 100644\r
+--- a/emacs/notmuch-maildir-fcc.el\r
++++ b/emacs/notmuch-maildir-fcc.el\r
+@@ -70,6 +70,31 @@ yet when sending a mail."\r
+ ;; add a hook to actually insert the Fcc header when sending\r
+ (add-hook 'message-header-setup-hook 'notmuch-fcc-header-setup))\r
+ \r
++(defun notmuch-fcc-determine-folder (configuration from)\r
++ "Determine the correct folder to be used for Fcc."\r
++\r
++ (cond\r
++ ((stringp configuration)\r
++ configuration)\r
++\r
++ ((and (listp configuration)\r
++ (stringp (car configuration)))\r
++ ;; Old style - no longer works.\r
++ (error "Invalid Fcc configuration (old style)"))\r
++\r
++ ((listp configuration)\r
++ (let ((match\r
++ (catch 'first-match\r
++ (dolist (re-folder configuration)\r
++ (when (string-match-p (car re-folder) from)\r
++ (throw 'first-match re-folder))))))\r
++ (if match\r
++ (cdr match)\r
++ nil)))\r
++ \r
++ (t\r
++ (error "Invalid Fcc configuration (neither string nor list)"))))\r
++\r
+ (defun notmuch-fcc-header-setup ()\r
+ "Add an Fcc header to the current message buffer.\r
+ \r
+@@ -77,63 +102,37 @@ Can be added to `message-send-hook' and will set the Fcc header\r
+ based on the values of `notmuch-fcc-dirs'. An existing Fcc header\r
+ will NOT be removed or replaced."\r
+ \r
+- (let ((subdir\r
+- (cond\r
+- ((or (not notmuch-fcc-dirs)\r
+- (message-fetch-field "Fcc"))\r
+- ;; Nothing set or an existing header.\r
+- nil)\r
+-\r
+- ((stringp notmuch-fcc-dirs)\r
+- notmuch-fcc-dirs)\r
+-\r
+- ((and (listp notmuch-fcc-dirs)\r
+- (= 1 (length (car notmuch-fcc-dirs))))\r
+- ;; Old style - no longer works.\r
+- (error "Invalid `notmuch-fcc-dirs' setting (old style)"))\r
+-\r
+- ((listp notmuch-fcc-dirs)\r
+- (let* ((from (message-fetch-field "From"))\r
+- (match\r
+- (catch 'first-match\r
+- (dolist (re-folder notmuch-fcc-dirs)\r
+- (when (string-match-p (car re-folder) from)\r
+- (throw 'first-match re-folder))))))\r
+- (if match\r
+- (cdr match)\r
+- (message "No Fcc header added.")\r
+- nil)))\r
+-\r
+- (t\r
+- (error "Invalid `notmuch-fcc-dirs' setting (neither string nor list)")))))\r
+-\r
+- (when subdir\r
+- (message-add-header\r
+- (concat "Fcc: "\r
+- ;; If the resulting directory is not an absolute path,\r
+- ;; prepend the standard notmuch database path.\r
+- (if (= (elt subdir 0) ?/)\r
+- subdir\r
+- (concat (notmuch-database-path) "/" subdir))))\r
+- \r
+- ;; finally test if fcc points to a valid maildir\r
+- (let ((fcc-header (message-fetch-field "Fcc")))\r
+- (unless (notmuch-maildir-fcc-dir-is-maildir-p fcc-header)\r
+- (cond ((not (file-writable-p fcc-header))\r
+- (error (format "No permission to create %s, which does not exist"\r
+- fcc-header)))\r
+- ((y-or-n-p (format "%s is not a maildir. Create it? "\r
+- fcc-header))\r
+- (notmuch-maildir-fcc-create-maildir fcc-header))\r
+- (t\r
+- (error "Message not sent"))))))))\r
+- \r
++ (when notmuch-fcc-dirs\r
++ (let* ((from (or (message-fetch-field "From") ""))\r
++ (subdir (notmuch-fcc-determine-folder notmuch-fcc-dirs from)))\r
++\r
++ (when subdir\r
++ (message-add-header\r
++ (concat "Fcc: "\r
++ ;; If the resulting directory is not an absolute path,\r
++ ;; prepend the standard notmuch database path.\r
++ (if (= (elt subdir 0) ?/)\r
++ subdir\r
++ (concat (notmuch-database-path) "/" subdir))))\r
++ \r
++ ;; finally test if fcc points to a valid maildir\r
++ (let ((fcc-header (message-fetch-field "Fcc")))\r
++ (unless (notmuch-maildir-fcc-dir-is-maildir-p fcc-header)\r
++ (cond ((not (file-writable-p fcc-header))\r
++ (error (format "No permission to create %s, which does not exist"\r
++ fcc-header)))\r
++ ((y-or-n-p (format "%s is not a maildir. Create it? "\r
++ fcc-header))\r
++ (notmuch-maildir-fcc-create-maildir fcc-header))\r
++ (t\r
++ (error "Message not sent")))))))))\r
++ \r
+ (defun notmuch-maildir-fcc-host-fixer (hostname)\r
+ (replace-regexp-in-string "/\\|:"\r
+ '(lambda (s)\r
+- (cond ((string-equal s "/") "\\057")\r
+- ((string-equal s ":") "\\072")\r
+- (t s)))\r
++ (cond ((string-equal s "/") "\\057")\r
++ ((string-equal s ":") "\\072")\r
++ (t s)))\r
+ hostname\r
+ t\r
+ t))\r
+-- \r
+1.7.2.3\r
+\r