1 Return-Path: <Sebastian@SSpaeth.de>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 77ADF4196F0
\r
6 for <notmuch@notmuchmail.org>; Wed, 28 Apr 2010 07:31:09 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9] autolearn=ham
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id wBksDg1b2zME for <notmuch@notmuchmail.org>;
\r
16 Wed, 28 Apr 2010 07:31:08 -0700 (PDT)
\r
17 Received: from homiemail-a11.g.dreamhost.com (caiajhbdcagg.dreamhost.com
\r
19 by olra.theworths.org (Postfix) with ESMTP id 39D60431FC1
\r
20 for <notmuch@notmuchmail.org>; Wed, 28 Apr 2010 07:31:08 -0700 (PDT)
\r
21 Received: from localhost.localdomain (unknown [195.190.188.219])
\r
22 (Authenticated sender: sebastian@sspaeth.de)
\r
23 by homiemail-a11.g.dreamhost.com (Postfix) with ESMTPA id 6FB74194083;
\r
24 Wed, 28 Apr 2010 07:31:06 -0700 (PDT)
\r
25 From: Sebastian Spaeth <Sebastian@SSpaeth.de>
\r
26 To: Notmuch developer list <notmuch@notmuchmail.org>
\r
27 Subject: [PATCH 1/2] Easier way to define a fcc directory
\r
28 Date: Wed, 28 Apr 2010 16:30:59 +0200
\r
29 Message-Id: <1272465060-15541-1-git-send-email-Sebastian@SSpaeth.de>
\r
30 X-Mailer: git-send-email 1.7.0.4
\r
31 In-Reply-To: <87ljc77iqn.fsf@SSpaeth.de>
\r
32 References: <87ljc77iqn.fsf@SSpaeth.de>
\r
33 X-BeenThere: notmuch@notmuchmail.org
\r
34 X-Mailman-Version: 2.1.13
\r
36 List-Id: "Use and development of the notmuch mail system."
\r
37 <notmuch.notmuchmail.org>
\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
41 List-Post: <mailto:notmuch@notmuchmail.org>
\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
45 X-List-Received-Date: Wed, 28 Apr 2010 14:31:09 -0000
\r
47 In the common case that a user only has one FCC (save outgoing mail in
\r
48 the Mail directory, it is now possible to simply configure a string
\r
49 such as "Sent" in the notmuch-fcc-dirs variable. More complex options,
\r
50 depending on a users email address, are possible and described in the
\r
51 variable customization help text.
\r
53 The whole function notmuch-fcc-header-setup has been cleaned up a
\r
54 little while working on that.
\r
56 Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
\r
58 emacs/notmuch-maildir-fcc.el | 110 +++++++++++++++++++++++++-----------------
\r
59 1 files changed, 66 insertions(+), 44 deletions(-)
\r
61 diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
\r
62 index d9a8f9b..8bb41a8 100644
\r
63 --- a/emacs/notmuch-maildir-fcc.el
\r
64 +++ b/emacs/notmuch-maildir-fcc.el
\r
66 (defvar notmuch-maildir-fcc-count 0)
\r
68 (defcustom notmuch-fcc-dirs nil
\r
69 - "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
70 + "Determines the maildir directory to save outgoing mails in.
\r
72 - The first entry (a list) is used as a default fallback
\r
73 - when nothing matches. So in the easiest case notmuch-fcc-dirs is
\r
74 - just something like ((\"INBOX.Sent\"))
\r
75 + If set to non-nil, this will cause message mode to file your
\r
76 + mail in the specified directory (fcc).
\r
78 - If you need a more fancy setup, where you want different Outboxes depending
\r
79 - on your From address, you use something like this:
\r
80 + It is either a string if you only need one fcc directory or a
\r
81 + list if they depend on your From address (see example).
\r
83 - ( (\"defaultinbox\")
\r
84 - (\"Sebastian Spaeth <Sebastian@SSpaeth.de>\" . \"privat\")
\r
85 - (\"Sebastian Spaeth <SSpaeth@ethz.ch>\" . \"uni\")
\r
86 + In the former case it is a string such as \"INBOX.Sent\".
\r
88 + In the fancy setup, where you want different outboxes depending
\r
89 + on your From address, you supply a list like this:
\r
91 + ((\"defaultinbox\")
\r
92 + (\"Sebastian Spaeth <Sebastian@SSpaeth.de>\" . \"privat\")
\r
93 + (\"Sebastian Spaeth <spaetz@sspaeth.de>\" . \"OUTBOX.OSS\")
\r
96 - This will constructs a path, concatenating the content of the
\r
97 - variable 'message-directory' (a message mode variable
\r
98 - customizable via m-x
\r
99 - customize-variable<RET>message-directory<RET>) and the second
\r
100 - part in the alist."
\r
101 + The outbox that matches a key (case insensitive) will be
\r
102 + used. The first entry is used as a default fallback when nothing
\r
105 + In all cases, the complete FCC directory will be constructed by
\r
106 + concatenating the content of the variable 'message-directory'
\r
107 + ('~/Mail/' by default and customizable via M-x
\r
108 + customize-variable<RET>message-directory<RET>) and this value.
\r
110 + You will be prompted to create the directory if it does not exist yet when
\r
113 + This function will not modify the headers if there is a FCC
\r
114 + header, but will check that the target directory exists."
\r
116 :require 'notmuch-fcc-initialization
\r
119 @@ -47,42 +61,49 @@
\r
120 (defun notmuch-fcc-initialization ()
\r
121 "If notmuch-fcc-directories is set,
\r
122 hook them into the message-fcc-handler-function"
\r
123 - ;Set up the message-fcc-handler to move mails to the maildir in Fcc
\r
124 - ;The parameter is hardcoded to mark messages as "seen"
\r
125 + ;; Set up the message-fcc-handler to move mails to the maildir in Fcc
\r
126 + ;; The parameter is set to mark messages as "seen"
\r
127 (setq message-fcc-handler-function
\r
129 (notmuch-maildir-fcc-write-buffer-to-maildir destdir t)))
\r
130 - ;add a hook to actually insert the Fcc header when sending
\r
131 - ;(preferrably we would use message-header-setup-up, but notmuch-reply
\r
132 - ; munges headers after that is run, so it won't work for replies within
\r
134 + ;;add a hook to actually insert the Fcc header when sending
\r
135 (add-hook 'message-send-hook 'notmuch-fcc-header-setup))
\r
137 (defun notmuch-fcc-header-setup ()
\r
138 - "Can be added to message-send-hook and will set the FCC header
\r
139 - based on the values of notmuch-fcc-directories (see the
\r
140 - variable customization there for examples). It uses the
\r
141 - first entry as default fallback if no From address
\r
143 - ; only do something if notmuch-fcc-dirs is set
\r
144 - (if notmuch-fcc-dirs
\r
146 - (cdr (assoc-string (message-fetch-field "from") notmuch-fcc-dirs t))))
\r
147 - (if (eq subdir nil) (setq subdir (car (car notmuch-fcc-dirs))))
\r
148 - (unless (message-fetch-field "fcc")
\r
149 - (message-add-header (concat "Fcc: "
\r
150 - (file-name-as-directory message-directory)
\r
152 - (let ((fcc-header (message-fetch-field "fcc")))
\r
153 - (unless (notmuch-maildir-fcc-dir-is-maildir-p fcc-header)
\r
154 - (cond ((not (file-writable-p fcc-header))
\r
155 - (error (format "%s is not a maildir, but you don't have permission to create one." fcc-header)))
\r
156 - ((y-or-n-p (format "%s is not a maildir. Create it? "
\r
158 - (notmuch-maildir-fcc-create-maildir fcc-header))
\r
160 - (error "Not sending message."))))))))
\r
162 + "Adds an appropriate fcc header to the current mail buffer
\r
164 + Can be added to message-send-hook and will set the FCC header
\r
165 + based on the values of notmuch-fcc-directories (see the
\r
166 + variable customization there for examples). It uses the first
\r
167 + entry as default fallback if no From address matches."
\r
168 + ;; only do something if notmuch-fcc-dirs is set
\r
169 + (when notmuch-fcc-dirs
\r
171 + (if (stringp notmuch-fcc-dirs)
\r
172 + ;; notmuch-fcc-dirs is a string, just use it as subdir
\r
173 + (setq subdir notmuch-fcc-dirs)
\r
174 + ;; else: it's a list of alists (("sent") ("name1" . "sent1"))
\r
175 + (setq subdir (cdr (assoc-string (message-fetch-field "from") notmuch-fcc-dirs t)))
\r
176 + ;; if we found no hit, use the first entry as default fallback
\r
177 + (unless subdir (setq subdir (car (car notmuch-fcc-dirs)))))
\r
179 + ;; if there is no fcc header yet, add ours
\r
180 + (unless (message-fetch-field "fcc")
\r
181 + (message-add-header (concat "Fcc: "
\r
182 + (file-name-as-directory message-directory)
\r
185 + ;; finally test if fcc points to a valid maildir
\r
186 + (let ((fcc-header (message-fetch-field "fcc")))
\r
187 + (unless (notmuch-maildir-fcc-dir-is-maildir-p fcc-header)
\r
188 + (cond ((not (file-writable-p fcc-header))
\r
189 + (error (format "%s is not a maildir, but you don't have permission to create one." fcc-header)))
\r
190 + ((y-or-n-p (format "%s is not a maildir. Create it? "
\r
192 + (notmuch-maildir-fcc-create-maildir fcc-header))
\r
194 + (error "Not sending message."))))))))
\r
196 (defun notmuch-maildir-fcc-host-fixer (hostname)
\r
197 (replace-regexp-in-string "/\\|:"
\r
199 @@ -170,3 +191,4 @@ return t if successful, and nil otherwise."
\r
201 (notmuch-fcc-initialization)
\r
202 (provide 'notmuch-maildir-fcc)
\r