--- /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 8628940DACB\r
+ for <notmuch@notmuchmail.org>; Mon, 8 Nov 2010 07:02:44 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.9\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
+ tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham\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 H7TGDIziQs3y for <notmuch@notmuchmail.org>;\r
+ Mon, 8 Nov 2010 07:02:34 -0800 (PST)\r
+Received: from mail-ew0-f53.google.com (mail-ew0-f53.google.com\r
+ [209.85.215.53])\r
+ by olra.theworths.org (Postfix) with ESMTP id A5A8940DAC8\r
+ for <notmuch@notmuchmail.org>; Mon, 8 Nov 2010 07:02:33 -0800 (PST)\r
+Received: by ewy10 with SMTP id 10so3148158ewy.26\r
+ for <notmuch@notmuchmail.org>; Mon, 08 Nov 2010 07:02:33 -0800 (PST)\r
+Received: by 10.216.27.20 with SMTP id d20mr4990767wea.99.1289228551821;\r
+ Mon, 08 Nov 2010 07:02:31 -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 x3sm3173729wes.22.2010.11.08.07.02.30\r
+ (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
+ Mon, 08 Nov 2010 07:02:30 -0800 (PST)\r
+Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
+ id AA37259405B; Mon, 8 Nov 2010 15:01:26 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: Improve the definition and use of `notmuch-fcc-dirs'.\r
+Date: Mon, 8 Nov 2010 15:01:25 +0000\r
+Message-Id: <1289228485-5505-1-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <87lj5328gl.fsf@ut.hh.sledj.net>\r
+References: <87lj5328gl.fsf@ut.hh.sledj.net>\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: Mon, 08 Nov 2010 15:02:44 -0000\r
+\r
+Re-work the declaration and definition of `notmuch-fcc-dirs'. The\r
+variable now allows three types of values:\r
+\r
+- nil: no Fcc header is added,\r
+\r
+- a string: the value of `notmuch-fcc-dirs' is the name of the\r
+ folder to use,\r
+\r
+- a list: the folder is chosen based on the From address of the\r
+ current message using a list of regular expressions and\r
+ corresponding folders:\r
+\r
+ ((\"Sebastian@SSpaeth.de\" . \"privat\")\r
+ (\"spaetz@sspaeth.de\" . \"OUTBOX.OSS\")\r
+ (\".*\" . \"defaultinbox\"))\r
+\r
+ If none of the regular expressions match the From address, no\r
+ Fcc header will be added.\r
+---\r
+\r
+Fix runtime cl use.\r
+\r
+ emacs/notmuch-maildir-fcc.el | 140 ++++++++++++++++++++++++------------------\r
+ 1 files changed, 81 insertions(+), 59 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el\r
+index 693d8d4..e5e0549 100644\r
+--- a/emacs/notmuch-maildir-fcc.el\r
++++ b/emacs/notmuch-maildir-fcc.el\r
+@@ -16,6 +16,7 @@\r
+ ;; To use this as the fcc handler for message-mode,\r
+ ;; customize the notmuch-fcc-dirs variable\r
+ \r
++(eval-when-compile (require 'cl))\r
+ (require 'message)\r
+ \r
+ (require 'notmuch-lib)\r
+@@ -23,41 +24,40 @@\r
+ (defvar notmuch-maildir-fcc-count 0)\r
+ \r
+ (defcustom notmuch-fcc-dirs "sent"\r
+- "Determines the maildir directory to save outgoing mails in.\r
++ "Determines the maildir directory in which to save outgoing mail.\r
+ \r
+- If set to non-nil, this will cause message mode to file your\r
+- mail in the specified directory (fcc).\r
++Three types of values are permitted:\r
+ \r
+- It is either a string if you only need one fcc directory or a\r
+- list if they depend on your From address (see example).\r
++- nil: no Fcc header is added,\r
+ \r
+- In the former case it is a string such as \"INBOX.Sent\".\r
++- a string: the value of `notmuch-fcc-dirs' is the name of the\r
++ folder to use,\r
+ \r
+- In the fancy setup, where you want different outboxes depending\r
+- on your From address, you supply a list like this:\r
++- a list: the folder is chosen based on the From address of the\r
++ current message using a list of regular expressions and\r
++ corresponding folders:\r
+ \r
+- ((\"defaultinbox\")\r
+- (\"Sebastian Spaeth <Sebastian@SSpaeth.de>\" . \"privat\")\r
+- (\"Sebastian Spaeth <spaetz@sspaeth.de>\" . \"OUTBOX.OSS\")\r
+- )\r
++ ((\"Sebastian@SSpaeth.de\" . \"privat\")\r
++ (\"spaetz@sspaeth.de\" . \"OUTBOX.OSS\")\r
++ (\".*\" . \"defaultinbox\"))\r
+ \r
+- The outbox that matches a key (case insensitive) will be\r
+- used. The first entry is used as a default fallback when nothing\r
+- else matches.\r
++ If none of the regular expressions match the From address, no\r
++ Fcc header will be added.\r
+ \r
+- In all cases, a relative FCC directory will be understood to\r
+- specify a directory within the notmuch mail store, (as set by\r
+- the database.path option in the notmuch configuration file).\r
++In all cases, a relative FCC directory will be understood to\r
++specify a directory within the notmuch mail store, (as set by\r
++the database.path option in the notmuch configuration file).\r
+ \r
+- You will be prompted to create the directory if it does not exist yet when \r
+- sending a mail.\r
+-\r
+- This function will not modify the headers if there is a FCC\r
+- header, but will check that the target directory exists."\r
++You will be prompted to create the directory if it does not exist\r
++yet when sending a mail."\r
+ \r
+ :require 'notmuch-fcc-initialization\r
+ :group 'notmuch\r
+-)\r
++ :type '(choice\r
++ (const :tag "No FCC header" nil)\r
++ (string :tag "A single folder")\r
++ (repeat :tag "A folder based on the From header"\r
++ (cons regexp (string :tag "Folder")))))\r
+ \r
+ (defun notmuch-fcc-initialization ()\r
+ "If notmuch-fcc-directories is set,\r
+@@ -67,44 +67,66 @@\r
+ (setq message-fcc-handler-function\r
+ '(lambda (destdir)\r
+ (notmuch-maildir-fcc-write-buffer-to-maildir destdir t)))\r
+- ;;add a hook to actually insert the Fcc header when sending\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-header-setup ()\r
+- "Adds an appropriate fcc header to the current mail buffer\r
+-\r
+- Can be added to message-send-hook and will set the FCC header\r
+- based on the values of notmuch-fcc-directories (see the\r
+- variable customization there for examples). It uses the first\r
+- entry as default fallback if no From address matches."\r
+- ;; only do something if notmuch-fcc-dirs is set\r
+- (when notmuch-fcc-dirs\r
+- (let (subdir)\r
+- (if (stringp notmuch-fcc-dirs)\r
+- ;; notmuch-fcc-dirs is a string, just use it as subdir\r
+- (setq subdir notmuch-fcc-dirs)\r
+- ;; else: it's a list of alists (("sent") ("name1" . "sent1"))\r
+- (setq subdir (cdr (assoc-string (message-fetch-field "from") notmuch-fcc-dirs t)))\r
+- ;; if we found no hit, use the first entry as default fallback\r
+- (unless subdir (setq subdir (car (car notmuch-fcc-dirs)))))\r
+-\r
+- ;; if there is no fcc header yet, add ours\r
+- (unless (message-fetch-field "fcc")\r
+- (message-add-header (concat "Fcc: "\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 "%s is not a maildir, but you don't have permission to create one." 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 "Not sending message."))))))))\r
++ "Add an Fcc header to the current message buffer.\r
++\r
++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
+ (defun notmuch-maildir-fcc-host-fixer (hostname)\r
+ (replace-regexp-in-string "/\\|:"\r
+-- \r
+1.7.2.3\r
+\r