Re: v4 of DB_RETRY_LOCK patches
[notmuch-archives.git] / 8c / cf149fd266f7235fb1492bee4214904f2746e9
1 Return-Path:\r
2  <return-gsfbd9y6t2m24wu4hrg33p5p5n@temporary-address.scs.stanford.edu>\r
3 X-Original-To: notmuch@notmuchmail.org\r
4 Delivered-To: notmuch@notmuchmail.org\r
5 Received: from localhost (localhost [127.0.0.1])\r
6         by olra.theworths.org (Postfix) with ESMTP id 17141431FBF\r
7         for <notmuch@notmuchmail.org>; Tue,  8 Apr 2014 02:20:08 -0700 (PDT)\r
8 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -2.3\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id LWQYCprcxFgU for <notmuch@notmuchmail.org>;\r
17         Tue,  8 Apr 2014 02:19:56 -0700 (PDT)\r
18 Received: from market.scs.stanford.edu (market.scs.stanford.edu [171.66.3.10])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 2B226431FBC\r
22         for <notmuch@notmuchmail.org>; Tue,  8 Apr 2014 02:19:56 -0700 (PDT)\r
23 Received: from market.scs.stanford.edu (localhost.scs.stanford.edu\r
24  [127.0.0.1])   by market.scs.stanford.edu (8.14.7/8.14.7) with ESMTP id\r
25  s389Jlde001749;        Tue, 8 Apr 2014 02:19:47 -0700 (PDT)\r
26 Received: (from dm@localhost)\r
27         by market.scs.stanford.edu (8.14.7/8.14.7/Submit) id s389JkH1002190;\r
28         Tue, 8 Apr 2014 02:19:46 -0700 (PDT)\r
29 X-Authentication-Warning: market.scs.stanford.edu: dm set sender to\r
30         return-gsfbd9y6t2m24wu4hrg33p5p5n@ta.scs.stanford.edu using -f\r
31 From: David Mazieres <dm-list-email-notmuch@scs.stanford.edu>\r
32 To: Ian Kelling <ian@iankelling.org>, notmuch@notmuchmail.org\r
33 Subject: Re: gnus-alias integration bug\r
34 In-Reply-To: <87vbuk8xo5.fsf@treetowl.lan>\r
35 References: <87vbuk8xo5.fsf@treetowl.lan>\r
36 Date: Tue, 08 Apr 2014 11:19:46 +0200\r
37 Message-ID: <8738hogoul.fsf@ta.scs.stanford.edu>\r
38 MIME-Version: 1.0\r
39 Content-Type: text/plain\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 Reply-To: David Mazieres expires 2014-07-07 CEST\r
44         <mazieres-ta6a6dtvd22xr33tw7tutuhifs@temporary-address.scs.stanford.edu>\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Tue, 08 Apr 2014 09:20:08 -0000\r
55 \r
56 Ian Kelling <ian@iankelling.org> writes:\r
57 \r
58 > gnus-alias allows you to set your identity based on the headers in the\r
59 > message you are replying. This is an essential feature in a mail client\r
60 > for me, I want to automatically reply as the person an email was sent to\r
61 > for certain addresses. This does not work in notmuch.\r
62 \r
63 I need this feature, too.  There is some support for the same\r
64 functionality built into notmuch.  The big problem for me is that\r
65 .notmuch-config does not support wildcards (e.g., *@mydomain.com or\r
66 user-*@mydomain.com).  Compounding this issue is that, other than\r
67 notmuch reply's internals, notmuch pretty much suppresses the\r
68 Delivered-To header, which is crucial for knowing in a non-heuristic way\r
69 where an email was actually delivered to.  I want to compute my From:\r
70 header based on the Delivered-To, so I created a\r
71 mail-delivered-to-reply-from alist that maps one to the other.\r
72 \r
73 It's pretty horrifying what I had to do to get this to work, but it\r
74 looks something like the following.  (Apologies for any mistakes, I had\r
75 to strip out additional complexity I have for other things in there, so\r
76 it's not verbatim the code that I'm using, but it's pretty close.)\r
77 \r
78 If someone knows a better way of doing this with stock notmuch, please\r
79 let me know.  I know it's simpler to fix notmuch-reply, but I really\r
80 don't want to start depending on a custom-forked version on the notmuch\r
81 binary, as I read my mail from multiple operating systems and I'm sure\r
82 I'd forget to update one of them.\r
83 \r
84 David\r
85 \r
86 \r
87 ;;; Regular expression matching all of my own email addresses.  Note\r
88 ;;; this is also used by mail-dont-reply-to (which ships with emacs).\r
89 (setq mail-dont-reply-to-names\r
90       (concat "REXEXP MATCHING ALL YOUR EMAIL ALIASES"))\r
91 \r
92 ;;; Alist mapping Delivered-To addresses to the address that should be\r
93 ;;; in the From header of replies.\r
94 (setq mail-delivered-to-reply-from\r
95       '(("delivered-to-\\(.*\\)@address.com"\r
96          . "Name <send-from-\\1@address.com>")\r
97         ;; ...\r
98         ))\r
99 \r
100 (defun compute-from (email)\r
101   (let ((case-fold-search t)\r
102         (subst (assoc-default email mail-delivered-to-reply-from\r
103                               #'string-match)))\r
104     (and subst\r
105          (concat (notmuch-user-name) " <"\r
106                  (replace-match subst t nil email) ">"))))\r
107 \r
108 (defun get-delivered-to-from-path (path)\r
109   (with-temp-buffer\r
110     ; It's weird to use sed, but there's also no reason to read a huge\r
111     ; file into a buffer right here when we reply to messags with\r
112     ; attachments.  (notmuch show doesn't support --body=false in\r
113     ; --format=raw mode, and the other modes all get rid of Delivered-To.)\r
114     (call-process "sed" nil t t "-ne"\r
115                   "/^Delivered-To: */{s///p;q;}; /^$/q" path)\r
116     (goto-char (point-max))\r
117     (or (bobp) (delete-char -1))\r
118     (and (not (bobp)) (buffer-string))))\r
119 \r
120 (defun get-msg-pathnames (query)\r
121   (notmuch-call-notmuch-sexp\r
122    "search" "--format=sexp" "--format-version=1"\r
123    "--output=files" "--" query))\r
124 \r
125 (defun compute-reply-from (pl)\r
126   (let* ((orig (plist-get pl :original))\r
127          (path (plist-get orig :filename))\r
128          (orig-from (plist-get (plist-get orig :headers) :From))\r
129          (addr\r
130           (cond\r
131            ((get-delivered-to-from-path path))\r
132            ;; in case of maildir.synchronize_flags=true, the pathname\r
133            ;; might already be incorrect, so try getting it again\r
134            ((and (setq path (car (get-msg-pathnames query-string)))\r
135                  (get-delivered-to-from-path path)))\r
136            ((string-match mail-dont-reply-to-names\r
137                           (setq orig-from (car (rfc822-addresses orig-from))))\r
138             orig-from)\r
139            )))\r
140     (and addr (compute-from addr))))\r
141 \r
142 ;;; Somehow no plist-del function in emacs\r
143 (defun my-plist-del (plist0 prop)\r
144   (if (eq prop (car plist0))\r
145       (cddr plist0)\r
146     (let ((p (cdr plist0)))\r
147       (while (and p (not (eq prop (cadr p))))\r
148         (setq p (cddr p)))\r
149       (if p (setcdr p (cdddr p)))\r
150       plist0)))\r
151 \r
152 (defun fix-reply-sexp (pl)\r
153   (let* ((rh (plist-get pl :reply-headers))\r
154          (from (compute-reply-from pl))\r
155          h)\r
156     (if from (setq rh (plist-put rh :From from)))\r
157     (and (setq h (plist-get rh :To))\r
158          (setq h (mail-dont-reply-to h))\r
159          (not (equal h ""))\r
160          (setq rh (plist-put rh :To h)))\r
161     (and (setq h (plist-get rh :Cc))\r
162          (setq h (mail-dont-reply-to h))\r
163          (if (equal h "")\r
164              (setq rh (my-plist-del rh :Cc))\r
165            (setq rh (plist-put rh :Cc h))))\r
166     (plist-put pl :reply-headers rh)))\r
167 (defadvice notmuch-call-notmuch-sexp (after fix-reply activate)\r
168   "Fix From/To/CC headers in reply"\r
169   (if (equal (ad-get-arg 0) "reply")\r
170       (setq ad-return-value (fix-reply-sexp ad-return-value))))\r