Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / df / d6d8fdd39e9e0fa6f552893bff1047db63c50e
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 7E3DA418C3C\r
6         for <notmuch@notmuchmail.org>; Mon, 26 Apr 2010 01:23:28 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.9\r
10 X-Spam-Level: \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 DRGk9hMjB6qt for <notmuch@notmuchmail.org>;\r
16         Mon, 26 Apr 2010 01:23:27 -0700 (PDT)\r
17 Received: from homiemail-a15.g.dreamhost.com (caiajhbdcbef.dreamhost.com\r
18         [208.97.132.145])\r
19         by olra.theworths.org (Postfix) with ESMTP id D32954196F3\r
20         for <notmuch@notmuchmail.org>; Mon, 26 Apr 2010 01:23:26 -0700 (PDT)\r
21 Received: from localhost.localdomain (mtec-hg-docking-1-dhcp-204.ethz.ch\r
22         [129.132.133.204]) (Authenticated sender: sebastian@sspaeth.de)\r
23         by homiemail-a15.g.dreamhost.com (Postfix) with ESMTPA id A30D876C065; \r
24         Mon, 26 Apr 2010 01:23:25 -0700 (PDT)\r
25 From: Sebastian Spaeth <Sebastian@SSpaeth.de>\r
26 To: Notmuch developer list <notmuch@notmuchmail.org>\r
27 Subject: [PATCH v3 4/4] Integrate notmuch-fcc mechansim\r
28 Date: Mon, 26 Apr 2010 10:23:18 +0200\r
29 Message-Id: <1272270198-28357-4-git-send-email-Sebastian@SSpaeth.de>\r
30 X-Mailer: git-send-email 1.7.0.4\r
31 In-Reply-To: <m3bpd8tpjk.fsf@x200.gr8dns.org>\r
32 References: <m3bpd8tpjk.fsf@x200.gr8dns.org>\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.13\r
35 Precedence: list\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: Mon, 26 Apr 2010 08:23:28 -0000\r
46 \r
47 I have gone wild and added a defcustom "notmuch-fcc-dirs".\r
48 Depending on the value of that variable we will not do any\r
49 maildir fcc at all (nil, the default), or it is of the format\r
50 (("defaultsentbox")\r
51  ("full name <email@address>" . "Work/sentbox")\r
52  ("full name2 <email2@address2>" . "Work2/sentbox"))\r
53 \r
54 The outbox name will be concatenated with the message mode\r
55 variable "message-directory" which is "~/Mail/" by default.\r
56 \r
57 Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>\r
58 ---\r
59  emacs/notmuch-maildir-fcc.el |   85 +++++++++++++++++++++++++++++------------\r
60  1 files changed, 60 insertions(+), 25 deletions(-)\r
61 \r
62 diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el\r
63 index 84f4187..cab1d59 100644\r
64 --- a/emacs/notmuch-maildir-fcc.el\r
65 +++ b/emacs/notmuch-maildir-fcc.el\r
66 @@ -12,39 +12,73 @@\r
67  ;; along with GNU Emacs; see the file COPYING.  If not, write to the\r
68  ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\r
69  ;; Boston, MA 02110-1301, USA.\r
70 -\r
71 -;; Commentary:\r
72 -;;\r
73 -;; This is the beginning of a solution for storing sent mail in a\r
74 -;; maildir in emacs message mode, presented because some people might\r
75 -;; find it useful. It is *not* fully tested, it *may* overwrite files,\r
76 -;; and any directories you point this at may no longer be there\r
77 -;; afterwards. Use at your own risk.\r
78 -;;\r
79 -;; To use this as the fcc handler for message-mode, put\r
80 -;; one of the following in your init file:\r
81 -;;\r
82 -;; if you want Fcc'd messages to be marked as read:\r
83  ;;\r
84 -;;     (setq message-fcc-handler-function\r
85 -;;          '(lambda (destdir)\r
86 -;;          (notmuch-maildir-fcc-write-buffer-to-maildir destdir t)))\r
87 -;;\r
88 -;; if you want Fcc'd messages to be marked as new:\r
89 -;;\r
90 -;;     (setq message-fcc-handler-function\r
91 -;;          '(lambda (destdir)\r
92 -;;          (notmuch-maildir-fcc-write-buffer-to-maildir destdir nil)))\r
93 +;; To use this as the fcc handler for message-mode,\r
94 +;; customize the notmuch-fcc-dirs variable\r
95  \r
96 +(require 'message)\r
97  \r
98  (defvar notmuch-maildir-fcc-count 0)\r
99  \r
100 +(defcustom notmuch-fcc-dirs nil\r
101 + "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
102 +\r
103 + The first entry (a list) is used as a default fallback\r
104 + when nothing matches. So in the easiest case notmuch-fcc-dirs is\r
105 + just something like ((\"INBOX.Sent\"))\r
106 +\r
107 + If you need a more fancy setup, where you want different Outboxes depending\r
108 + on your From address, you use something like this:\r
109 +\r
110 +     (   (\"defaultinbox\")\r
111 +         (\"Sebastian Spaeth <Sebastian@SSpaeth.de>\" . \"privat\")\r
112 +         (\"Sebastian Spaeth <SSpaeth@ethz.ch>\" . \"uni\")\r
113 +     )\r
114 +\r
115 + This will constructs a path, concatenating the content of the\r
116 + variable 'message-directory' (a message mode variable\r
117 + customizable via m-x\r
118 + customize-variable<RET>message-directory<RET>) and the second\r
119 + part in the alist."\r
120 + :require 'notmuch-fcc-initialization\r
121 + :group 'notmuch\r
122 +)\r
123 +\r
124 +(defun notmuch-fcc-initialization ()\r
125 +  "If notmuch-fcc-directories is set,\r
126 +   hook them into the message-fcc-handler-function"\r
127 +(if (not (eq notmuch-fcc-dirs nil)) (progn\r
128 +    ;Set up the message-fcc-handler to move mails to the maildir in Fcc\r
129 +    ;The parameter is hardcoded to mark messages as "seen"\r
130 +    (setq message-fcc-handler-function\r
131 +          '(lambda (destdir)\r
132 +             (notmuch-maildir-fcc-write-buffer-to-maildir destdir t)))\r
133 +    ;add a hook to actually insert the Fcc header when sending\r
134 +    ;(preferrably we would use message-header-setup-up, but notmuch-reply\r
135 +    ; munges headers after that is run, so it won't work for replies within\r
136 +    ; notmuch)\r
137 +    (add-hook 'message-send-hook 'notmuch-fcc-header-setup))))\r
138 +\r
139 +(defun notmuch-fcc-header-setup ()\r
140 +  "Can be added to message-send-hook and will set the FCC header\r
141 +      based on the values of notmuch-fcc-directories (see the\r
142 +      variable customization there for examples). It uses the\r
143 +      first entry as default fallback if no From address\r
144 +      matches."\r
145 +  ; only do something if notmuch-fcc-dirs is set\r
146 +  (if notmuch-fcc-dirs\r
147 +   (let ((subdir \r
148 +          (cdr (assoc-string (message-fetch-field "from") notmuch-fcc-dirs t))))\r
149 +     (if (eq subdir nil) (setq subdir (car (car notmuch-fcc-dirs))))\r
150 +     (message-remove-header "Fcc")\r
151 +     (message-add-header (concat "Fcc: " message-directory subdir)))))\r
152 +\r
153  (defun notmuch-maildir-fcc-host-fixer (hostname)\r
154    (replace-regexp-in-string "/\\|:"\r
155                             '(lambda (s)\r
156 -                                (cond ((string-equal s "/") "\\057")\r
157 -                                      ((string-equal s ":") "\\072")\r
158 -                                      (t s)))\r
159 +                               (cond ((string-equal s "/") "\\057")\r
160 +                                     ((string-equal s ":") "\\072")\r
161 +                                     (t s)))\r
162                             hostname\r
163                             t\r
164                             t))\r
165 @@ -114,4 +148,5 @@ return t if successful, and nil otherwise."\r
166           (delete-file (concat destdir "/tmp/" msg-id))))\r
167        t)))\r
168  \r
169 +(notmuch-fcc-initialization)\r
170  (provide 'notmuch-maildir-fcc)\r
171 -- \r
172 1.7.0.4\r
173 \r