Re: Avoiding the "huge INBOX of death"
[notmuch-archives.git] / ef / 098faa0a665e810e85536e3c9dbe7243580552
1 Return-Path: <dme@dme.org>\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 D3069431FD0\r
6         for <notmuch@notmuchmail.org>; Mon, 12 May 2014 05:29:53 -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: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\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 2W7vIhcP3GC1 for <notmuch@notmuchmail.org>;\r
16         Mon, 12 May 2014 05:29:49 -0700 (PDT)\r
17 Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com\r
18         [209.85.212.176]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 999F3431FDA\r
21         for <notmuch@notmuchmail.org>; Mon, 12 May 2014 05:29:35 -0700 (PDT)\r
22 Received: by mail-wi0-f176.google.com with SMTP id n15so4354394wiw.9\r
23         for <notmuch@notmuchmail.org>; Mon, 12 May 2014 05:29:34 -0700 (PDT)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=1e100.net; s=20130820;\r
26         h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to\r
27         :references;\r
28         bh=/aQI20AsLdN5n9SeuaGD0ctiKhRr1Kp0qlguVsyliB8=;\r
29         b=VtqR+c6e5CJZispBqbRwQWzhWiii9c0lVsPHWNYGzK6MctT9U6fseI7pUbYZ4wYpgY\r
30         auCFzw8jp3/xOpSR3mdn0UwbUzMfmVHUM6nDE+w/hwsTLZyzqOg+RcoMcvpE/nuYd8V9\r
31         hv+1dB85wnBwH2LV9K6AOftksyFbQjCnG9vUQhqmzYCv5qT13VFfHlaoR9hMWMXULCEL\r
32         R+x2prRBOJfvjWDIO0yil6/8rWebETcpZYeTdczdtcxF6/I9eMEndzjseb1iIdzJ8+3D\r
33         s9MvVDJ1NXIRP1gLM5Y6FHGHo1e+xrI5qqWKCjVVq6/0OFKW/NIhtOeXVEIlJuUkJvPP\r
34         5eTQ==\r
35 X-Gm-Message-State:\r
36  ALoCoQkmHGZ9MS9L5jla3XNA4Q9Veb2b3WX1XHBZlxuKLiiMBV8g2keKC/Som1QcG1iPb7TyIHt9\r
37 X-Received: by 10.180.100.41 with SMTP id ev9mr15439102wib.22.1399897774439;\r
38         Mon, 12 May 2014 05:29:34 -0700 (PDT)\r
39 Received: from hotblack-desiato.hh.sledj.net (disaster-area.hh.sledj.net.\r
40         [81.149.164.25]) by mx.google.com with ESMTPSA id\r
41         dn4sm15869601wib.18.2014.05.12.05.29.32 for <notmuch@notmuchmail.org>\r
42         (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
43         Mon, 12 May 2014 05:29:32 -0700 (PDT)\r
44 Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
45         id 4B31410B330; Mon, 12 May 2014 13:29:29 +0100 (BST)\r
46 From: David Edmondson <dme@dme.org>\r
47 To: notmuch@notmuchmail.org\r
48 Subject: [PATCH v3 8/9] emacs/mua: Insert part headers depending on the\r
49  message\r
50 Date: Mon, 12 May 2014 13:29:28 +0100\r
51 Message-Id: <1399897769-26809-9-git-send-email-dme@dme.org>\r
52 X-Mailer: git-send-email 2.0.0.rc0\r
53 In-Reply-To: <1399897769-26809-1-git-send-email-dme@dme.org>\r
54 References: <87sixdujkv.fsf@qmul.ac.uk>\r
55         <1399897769-26809-1-git-send-email-dme@dme.org>\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Mon, 12 May 2014 12:29:54 -0000\r
69 \r
70 Whether to insert part headers should depend on the details of the\r
71 message being cited.\r
72 ---\r
73  emacs/notmuch-mua.el | 45 +++++++++++++++++++++++++++++++++++++++++++--\r
74  1 file changed, 43 insertions(+), 2 deletions(-)\r
75 \r
76 diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
77 index c800c38..239cc1a 100644\r
78 --- a/emacs/notmuch-mua.el\r
79 +++ b/emacs/notmuch-mua.el\r
80 @@ -132,6 +132,47 @@ list."\r
81    (funcall original-func header references)\r
82    (unless (bolp) (insert "\n")))\r
83  \r
84 +(defun notmuch-mua-reply-determine-part-function (message)\r
85 +  "Determine the part header rendering function to use when\r
86 +citing MESSAGE."\r
87 +\r
88 +  (let* ((body (plist-get message :body))\r
89 +        (first-part (car body)))\r
90 +    (cond\r
91 +     ;; If there are multiple top-level parts, we need the\r
92 +     ;; headers. Will this ever happen?\r
93 +     ((> (length body) 1)\r
94 +      #'notmuch-show-insert-header-p-always)\r
95 +     \r
96 +     ;; If the type of the part is multipart/mixed, we need to see the\r
97 +     ;; part headers.\r
98 +     ((notmuch-match-content-type (plist-get first-part :content-type) "multipart/mixed")\r
99 +      #'notmuch-show-insert-header-p-always)\r
100 +\r
101 +     ;; If it is multipart/alternative the renderer will choose a\r
102 +     ;; default part and render it. There's no need to show the\r
103 +     ;; alternative part buttons, as they are not active.\r
104 +     ((notmuch-match-content-type (plist-get first-part :content-type) "multipart/alternative")\r
105 +      #'notmuch-show-insert-header-p-never)\r
106 +\r
107 +     ;; If it's a multipart/signed with a single text/* part and a\r
108 +     ;; signature, we don't need to see the headers.\r
109 +     ((let ((inner-content (plist-get first-part :content)))\r
110 +       (and (notmuch-match-content-type (plist-get first-part :content-type) "multipart/signed")\r
111 +            (eq (length inner-content) 2)\r
112 +            (notmuch-match-content-type (plist-get (nth 0 inner-content) :content-type) "text/*")\r
113 +            (notmuch-match-content-type (plist-get (nth 1 inner-content) :content-type) "application/pgp-signature")))\r
114 +      #'notmuch-show-insert-header-p-never)\r
115 +\r
116 +     ;; If the type of the part is text/*, we don't need to see the\r
117 +     ;; part headers.\r
118 +     ((notmuch-match-content-type (plist-get first-part :content-type) "text/*")\r
119 +      #'notmuch-show-insert-header-p-never)\r
120 +     \r
121 +     ;; Otherwise insert the part headers.\r
122 +     (t\r
123 +      #'notmuch-show-insert-header-p-always))))\r
124 +\r
125  (defun notmuch-mua-reply (query-string &optional sender reply-all)\r
126    (let ((args '("reply" "--format=sexp" "--format-version=1"))\r
127         (process-crypto notmuch-show-process-crypto)\r
128 @@ -206,8 +247,8 @@ list."\r
129                       ;; citations, etc. in the original message before\r
130                       ;; quoting.\r
131                       ((notmuch-show-insert-text/plain-hook nil)\r
132 -                      ;; Don't insert part buttons.\r
133 -                      (notmuch-show-insert-header-p-function #'notmuch-show-insert-header-p-never))\r
134 +                      ;; Determine how to insert part headers.\r
135 +                      (notmuch-show-insert-header-p-function (notmuch-mua-reply-determine-part-function original)))\r
136                     (notmuch-show-insert-body original (plist-get original :body) 0)\r
137                     (buffer-substring-no-properties (point-min) (point-max)))))\r
138  \r
139 -- \r
140 2.0.0.rc0\r
141 \r