Re: [PATCH] emacs/*.el: changed one-char comment prefix ';' to two; ';;'
[notmuch-archives.git] / 6b / 31a7eb71831c102ddf7f17391512c858e89f3f
1 Return-Path: <anarcat@anarcat.ath.cx>\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 DCFB8429E35\r
6         for <notmuch@notmuchmail.org>; Mon, 16 Jan 2012 20:48:35 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 1.274\r
10 X-Spam-Level: *\r
11 X-Spam-Status: No, score=1.274 tagged_above=-999 required=5\r
12         tests=[RDNS_NONE=1.274] 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 fjBhRqWki5iv for <notmuch@notmuchmail.org>;\r
16         Mon, 16 Jan 2012 20:48:35 -0800 (PST)\r
17 Received: from marcos.anarcat.ath.cx (unknown [72.0.72.144])\r
18         by olra.theworths.org (Postfix) with ESMTP id 0BB7B429E2F\r
19         for <notmuch@notmuchmail.org>; Mon, 16 Jan 2012 20:48:35 -0800 (PST)\r
20 Received: by marcos.anarcat.ath.cx (Postfix, from userid 1000)\r
21         id 86B82143139; Mon, 16 Jan 2012 23:48:33 -0500 (EST)\r
22 From: Antoine =?utf-8?Q?Beaupr=C3=A9?= <anarcat@anarcat.ath.cx>\r
23 To: Gregor Zattler <telegraph@gmx.net>, David Edmondson <dme@dme.org>,\r
24         Jameson Graef Rollins <jrollins@finestructure.net>,\r
25         Gregor Zattler <telegraph@gmx.net>, Notmuch Mail <notmuch@notmuchmail.org>\r
26 Subject: Re: Emacs: Crypto: How to get automatic encryption?\r
27 In-Reply-To: <87d3akppoc.fsf@shi.workgroup>\r
28 Message-ID: <87pqejj5nl.fsf@marcos.anarcat.ath.cx>\r
29 MIME-Version: 1.0\r
30 Content-Type: multipart/signed; boundary="==-=-=";\r
31         micalg=pgp-sha256; protocol="application/pgp-signature"\r
32 X-Mailman-Approved-At: Thu, 02 Feb 2012 08:56:31 -0800\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 Date: Tue, 17 Jan 2012 04:48:36 -0000\r
46 X-Original-Date: Mon, 16 Jan 2012 23:48:30 -0500\r
47 X-List-Received-Date: Tue, 17 Jan 2012 04:48:36 -0000\r
48 \r
49 --==-=-=\r
50 Content-Type: multipart/mixed; boundary="=-=-="\r
51 \r
52 --=-=-=\r
53 Content-Type: text/plain; charset=utf-8\r
54 Content-Transfer-Encoding: quoted-printable\r
55 \r
56 Jumping in here, I have modified the previously posted code here to\r
57 provide me with a more complete solution.\r
58 \r
59 With the attach code, I can:\r
60 \r
61  * automatically encrypt mails if all recipients have a *valid* public\r
62    key. The previous patch allowed encryption if a key existed but was\r
63    revoked, which cause a weird UX issue where the user would be\r
64    bothered with "No public key for..."\r
65 \r
66  * not have specify if i want to encrypt the mail or not: it is\r
67    encrypted if possible\r
68 \r
69  * try to autodetect (by running the function directly) if the mail will\r
70    be crypted and signed or just signed before sending\r
71 \r
72  * explicitely request the mail to be encrypted or just signed, if I\r
73    want to, using the usual keybindings (ie. the existing #secure tags\r
74    are respected)\r
75 \r
76 So basically, this replaces the common hook:\r
77 \r
78 (add-hook 'message-setup-hook 'mml-secure-sign-pgpmime)\r
79 \r
80 with this:\r
81 \r
82 (add-hook 'message-send-hook 'anarcat/message-set-encryption)\r
83 \r
84 The rationale behind this technique is that the setup-hook runs when\r
85 recipients are not yet defined so it will always set the mail to be only\r
86 signed, even though your final recipients should be crypted.=20\r
87 \r
88 An alternative would be for notmuch to prompt the To: header before\r
89 setting up the buffer ("=C3=A0 la" Mutt), but I didn't feel like going that\r
90 way.\r
91 \r
92 Code is attached. Obviously, those function names would change if they\r
93 would be to integrate into notmuch. ;)\r
94 \r
95 \r
96 --=-=-=\r
97 Content-Type: application/emacs-lisp\r
98 Content-Disposition: inline; filename=notmuch-opportunistic.el\r
99 Content-Transfer-Encoding: quoted-printable\r
100 \r
101 ;; -*- mode: emacs-lisp; -*-\r
102 \r
103 (require 'notmuch)\r
104 \r
105 (add-hook 'message-send-hook 'anarcat/message-set-encryption)\r
106 \r
107 (defun anarcat/message-set-encryption (&optional force)\r
108   "Automatically set the encryption depending on the recipients.\r
109 \r
110 If ran interactively, will overwrite settings, otherwise it will\r
111 not touch existing settings, so that this can safely be ran in\r
112 `message-send-hook'."\r
113   (interactive "p")\r
114   (message-goto-body)\r
115   ;; clear existing settings\r
116   (if (and force (re-search-forward "<#secure [^>]*>\n" nil t))\r
117       (replace-match "" nil nil))\r
118   ;; If we can encrypt, do so, else just sign.\r
119   (if (or force (not (re-search-forward "<#secure [^>]*>\n" nil t)))\r
120       (if (anarcat/message-guess-encryption)\r
121           (insert "<#secure method=3Dpgpmime mode=3Dsignencrypt>\n")\r
122         (insert "<#secure method=3Dpgpmime mode=3Dsign>\n"))\r
123     )\r
124 )\r
125 \r
126 ;; http://notmuchmail.org/pipermail/notmuch/2012/007340.html\r
127 (defun anarcat/message-guess-encryption ()\r
128   "Return `t' if we have gpg public keys for all recipients of this message=\r
129 ."\r
130   (require 'epa-mail)\r
131   (if (and (not (message-news-p))  ; No encryption for news,=20\r
132            (or (message-fetch-field "to") (message-fetch-field "cc"))) ; we=\r
133  have to have one address at least\r
134       (catch :exit\r
135         (mapc\r
136          (lambda (addr)\r
137            ;; check for a usable key - taken from epa-mail.el\r
138            (if (not (epa-mail--find-usable-key\r
139                      (epg-list-keys\r
140                       (epg-make-context epa-protocol)\r
141                       (downcase (mail-strip-quoted-names addr)))\r
142                      'encrypt))\r
143                (throw :exit nil)))\r
144          (message-tokenize-header (concat\r
145                                    (message-fetch-field "to")\r
146                                    ","\r
147                                    (message-fetch-field "cc"))))\r
148         t)\r
149     nil))\r
150 \r
151 --=-=-=\r
152 Content-Transfer-Encoding: quoted-printable\r
153 \r
154 \r
155 Opportunistic encryption, here we go.\r
156 \r
157 a.\r
158 \r
159 =2D-=20\r
160 Evil exists to glorify the good. Evil is negative good.\r
161 It is a relative term. Evil can be transmuted into good.\r
162 What is evil to one at one time,\r
163 becomes good at another time to somebody else.\r
164                         - Sivananda\r
165 \r
166 --=-=-=--\r
167 \r
168 --==-=-=\r
169 Content-Type: application/pgp-signature\r
170 \r
171 -----BEGIN PGP SIGNATURE-----\r
172 Version: GnuPG v1.4.11 (GNU/Linux)\r
173 \r
174 iQIcBAEBCAAGBQJPFP2eAAoJEHkhUlJ7dZIeZFgP/3O94zqpj/E7S0JHnugNJ8cj\r
175 YKT3fdLZI8iy6Zw0SjxQE7RTF5ykT52gQXpojagOSxLQ1+N5LPhiHA+qWcrdBX8n\r
176 VE+UtFUJbTaU7iARGQ/jBw7Ogb2AGM9uKWDuoV3oe28y3RzeeYCTD9xPWtn2RTXy\r
177 aZd6d3bhbrx7ENG8TR7EBFj6wLfVqt0DlgWTPR5v8uAEHrP/BepNsWKVYOnWSteo\r
178 qN0WQZ5uWMoAX73hOc/xYYwH8LIIZwAjJB29c/lWI8O5ZKG12noa1zqRQZNoFdj8\r
179 7L6K/5ZKgEit0piedj69rbx7kxQrp9NJt60dl2h2xuWPP883lAIt+uHJwPnOUBe2\r
180 ZBPU4piFTmn/4+tVzBK69VmogWRUWP/3KjJ2nfX8IhWfAJfvwXZCCctTHSOJ29Lj\r
181 oImWFS4/5wxJB72RH0XUSRdr8Uq9iB+GHt2mckeiTfoAVgLObwDT2LjrBMl8JxTB\r
182 8uRP0/GTfKuhH5HBf8nZ2iTfydX2c+hZ/LT+HG8GLc31lifW+9Wf1+ninQUnloYa\r
183 BZDAiBGTqsv6oQ6Bpc23kUU6cxYc4R0xxOmjX+R/KGJE1w+i73SYCVNHrTQj+OOW\r
184 blrLCkgVG+eJpDiPjF2mXw15DMLJauf7Kq5fUjubGQfrNY5JEcdW/Tp8gdlKJUYy\r
185 DnRoI1rC/t/eJhGPD8OU\r
186 =Bxam\r
187 -----END PGP SIGNATURE-----\r
188 --==-=-=--\r