[PATCH 7/7] Integrate notmuch-fcc mechansim
authorSebastian Spaeth <Sebastian@SSpaeth.de>
Fri, 23 Apr 2010 09:38:57 +0000 (11:38 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:49 +0000 (09:36 -0800)
27/82ba18522b855041508a9c1cdbc9750bf443ad [new file with mode: 0644]

diff --git a/27/82ba18522b855041508a9c1cdbc9750bf443ad b/27/82ba18522b855041508a9c1cdbc9750bf443ad
new file mode 100644 (file)
index 0000000..8047993
--- /dev/null
@@ -0,0 +1,179 @@
+Return-Path: <Sebastian@SSpaeth.de>\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 6D3174196F2\r
+       for <notmuch@notmuchmail.org>; Fri, 23 Apr 2010 02:39:08 -0700 (PDT)\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] 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 YkapA4kDNb6V for <notmuch@notmuchmail.org>;\r
+       Fri, 23 Apr 2010 02:39:07 -0700 (PDT)\r
+Received: from homiemail-a22.g.dreamhost.com (caiajhbdcahe.dreamhost.com\r
+       [208.97.132.74])\r
+       by olra.theworths.org (Postfix) with ESMTP id E84FB431FC1\r
+       for <notmuch@notmuchmail.org>; Fri, 23 Apr 2010 02:39:06 -0700 (PDT)\r
+Received: from localhost.localdomain (mtec-hg-docking-1-dhcp-204.ethz.ch\r
+       [129.132.133.204]) (Authenticated sender: sebastian@sspaeth.de)\r
+       by homiemail-a22.g.dreamhost.com (Postfix) with ESMTPA id 94AE61A8061; \r
+       Fri, 23 Apr 2010 02:39:02 -0700 (PDT)\r
+From: Sebastian Spaeth <Sebastian@SSpaeth.de>\r
+To: Notmuch developer list <notmuch@notmuchmail.org>\r
+Subject: [PATCH 7/7] Integrate notmuch-fcc mechansim\r
+Date: Fri, 23 Apr 2010 11:38:57 +0200\r
+Message-Id: <1272015537-13225-1-git-send-email-Sebastian@SSpaeth.de>\r
+X-Mailer: git-send-email 1.7.0.4\r
+In-Reply-To: <87ochbx3er.fsf@SSpaeth.de>\r
+References: <87ochbx3er.fsf@SSpaeth.de>\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: Fri, 23 Apr 2010 09:39:08 -0000\r
+\r
+I have gone wild and added a defcustom "notmuch-fcc-dirs".\r
+Depending on the value of that variable we will not do any\r
+maildir fcc at all (nil, the default), or it is of the format\r
+(("defaultsentbox")\r
+ ("full name <email@address>" . "Work/sentbox")\r
+ ("full name2 <email2@address2>" . "Work2/sentbox"))\r
+\r
+The outbox name will be concatenated with the message mode\r
+variable "message-directory" which is "~/Mail/" by default.\r
+\r
+With this solution, no customization of a user's .emacs file\r
+is needed at all.\r
+\r
+Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>\r
+---\r
+I went wild and did a proper notmuch integration including customizations.\r
+Maildir FCC is turned off by default and can be turned on to some universal\r
+SENTBOX or to Dirk's sepcial use case with multiple outboxes depending on \r
+the from address. Some testing would be appreciated before it is merged.\r
+It seems to work nicely here. And be lenient, remember I am an elisp noob.\r
+\r
+ emacs/notmuch-maildir-fcc.el |   86 ++++++++++++++++++++++++++++--------------\r
+ 1 files changed, 57 insertions(+), 29 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el\r
+index b7e1fb3..9f54dfb 100644\r
+--- a/emacs/notmuch-maildir-fcc.el\r
++++ b/emacs/notmuch-maildir-fcc.el\r
+@@ -12,39 +12,66 @@\r
+ ;; along with GNU Emacs; see the file COPYING.  If not, write to the\r
+ ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\r
+ ;; Boston, MA 02110-1301, USA.\r
+-\r
+-;; Commentary:\r
+-;;\r
+-;; This is the beginning of a solution for storing sent mail in a\r
+-;; maildir in emacs message mode, presented because some people might\r
+-;; find it useful. It is *not* fully tested, it *may* overwrite files,\r
+-;; and any directories you point this at may no longer be there\r
+-;; afterwards. Use at your own risk.\r
+-;;\r
+-;; To use this as the fcc handler for message-mode, put\r
+-;; one of the following in your init file:\r
+-;;\r
+-;; if you want Fcc'd messages to be marked as read:\r
+-;;\r
+-;;     (setq message-fcc-handler-function\r
+-;;          '(lambda (destdir)\r
+-;;         (notmuch-maildir-fcc-write-buffer-to-maildir destdir t)))\r
+-;;\r
+-;; if you want Fcc'd messages to be marked as new:\r
+-;;\r
+-;;     (setq message-fcc-handler-function\r
+-;;          '(lambda (destdir)\r
+-;;         (notmuch-maildir-fcc-write-buffer-to-maildir destdir nil)))\r
+-;;\r
+-;; It will then honor the Fcc header that you set in your mail. They can\r
+-;; be set up automatically via:\r
+ ;;\r
+-;;     (add-hook 'message-send-hook\r
+-;;          '(lambda ()\r
+-;;             (message-add-header "Fcc: ~/mail/INBOX.Sent")))\r
++;; To use this as the fcc handler for message-mode,\r
++;; customize the notmuch-fcc-dirs variable\r
++\r
++(require 'message)\r
\r
+ (defvar notmuch-maildir-fcc-count 0)\r
\r
++(defcustom notmuch-fcc-dirs nil\r
++ "If set to non-nil, this will cause message mode to file (fcc) your mail in the specified directory, depending on your From address.\r
++\r
++ The first entry (a list) is used as a default fallback\r
++ when nothing matches. So in the easiest case notmuch-fcc-dirs is\r
++ just something like ((\"INBOX.Sent\"))\r
++\r
++ If you need a more fancy setup, where you want different Outboxes depending\r
++ on your From address, you use something like this:\r
++\r
++     (   (\"defaultinbox\")\r
++         (\"Sebastian Spaeth <Sebastian@SSpaeth.de>\" . \"privat\")\r
++         (\"Sebastian Spaeth <SSpaeth@ethz.ch>\" . \"uni\")\r
++     )\r
++ \r
++ This will constructs a path, concatenating the content of the\r
++ variable 'message-directory' (a message mode variable\r
++ customizable via m-x\r
++ customize-variable<RET>message-directory<RET>) and the second\r
++ part in the alist."\r
++ :require 'notmuch-fcc-initialization\r
++ :group 'notmuch\r
++)\r
++\r
++(defun notmuch-fcc-initialization ()\r
++  "If notmuch-fcc-directories is set, \r
++   hook them into the message-fcc-handler-function"\r
++(if (not (eq notmuch-fcc-dirs nil)) (progn\r
++    ;Set up the message-fcc-handler to move mails to the maildir in Fcc\r
++    ;The parameter is hardcoded to mark messages as "seen"\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
++    ;(preferrably we would use message-header-setup-up, but notmuch-reply \r
++    ; munges headers after that is run, so it won't work for replies within\r
++    ; notmuch)\r
++    (add-hook 'message-send-hook 'notmuch-fcc-header-setup))))\r
++\r
++(defun notmuch-fcc-header-setup ()\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\r
++      first entry as default fallback if no From address\r
++      matches."\r
++  ; only do something if notmuch-fcc-dirs is set\r
++  (if notmuch-fcc-dirs\r
++   (let ((subdir (cdr (assoc (message-fetch-field "from") notmuch-fcc-dirs))))\r
++     (if (eq subdir nil) (setq subdir (car (car notmuch-fcc-dirs))))\r
++     (message-remove-header "Fcc")\r
++     (message-add-header (concat "Fcc: " message-directory subdir)))))\r
++\r
+ (defun notmuch-maildir-fcc-host-fixer (hostname)\r
+   (replace-regexp-in-string "/\\|:"\r
+                           '(lambda (s)\r
+@@ -120,4 +147,5 @@ return t if successful, and nil otherwise."\r
+         (delete-file (concat destdir "/tmp/" msg-id))))\r
+       t)))\r
\r
++(notmuch-fcc-initialization)\r
+ (provide 'notmuch-maildir-fcc)\r
+-- \r
+1.7.0.4\r
+\r