Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / db / 848d19aee8f947494f4b3f431ec42f75315dbd
1 Return-Path: <dkg@fifthhorseman.net>\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 arlo.cworth.org (Postfix) with ESMTP id 4D4AE6DE09E2\r
6  for <notmuch@notmuchmail.org>; Fri,  8 Jul 2016 03:14:03 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.045\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.045 tagged_above=-999 required=5 tests=[AWL=0.045]\r
12  autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id dGcy_W3zhuYE for <notmuch@notmuchmail.org>;\r
16  Fri,  8 Jul 2016 03:13:55 -0700 (PDT)\r
17 Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118])\r
18  by arlo.cworth.org (Postfix) with ESMTP id 8A35F6DE0362\r
19  for <notmuch@notmuchmail.org>; Fri,  8 Jul 2016 03:13:12 -0700 (PDT)\r
20 Received: from fifthhorseman.net (unknown [88.128.80.54])\r
21  by che.mayfirst.org (Postfix) with ESMTPSA id C572CF99C\r
22  for <notmuch@notmuchmail.org>; Fri,  8 Jul 2016 06:13:11 -0400 (EDT)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id 9174A20FAE; Fri,  8 Jul 2016 11:27:34 +0200 (CEST)\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>\r
27 Subject: [PATCH v4 04/16] Provide _notmuch_crypto_{set,get}_gpg_path\r
28 Date: Fri,  8 Jul 2016 11:27:15 +0200\r
29 Message-Id: <1467970047-8013-5-git-send-email-dkg@fifthhorseman.net>\r
30 X-Mailer: git-send-email 2.8.1\r
31 In-Reply-To: <1467970047-8013-1-git-send-email-dkg@fifthhorseman.net>\r
32 References: <1467970047-8013-1-git-send-email-dkg@fifthhorseman.net>\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.20\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: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
44  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
45 X-List-Received-Date: Fri, 08 Jul 2016 10:14:03 -0000\r
46 \r
47 Use functions to access the gpg_path for a _notmuch_crypto_t object.\r
48 This lets us return sensible defaults based on the state of the user's\r
49 machine.\r
50 \r
51 If the passed-in _notmuch_crypto_t is NULL, then just return the\r
52 system's default choice of gpg.\r
53 ---\r
54  notmuch-reply.c | 13 ++++++++++---\r
55  notmuch-show.c  | 12 ++++++++++--\r
56  util/crypto.c   | 50 +++++++++++++++++++++++++++++++++++++++++++++++---\r
57  util/crypto.h   |  8 +++++++-\r
58  4 files changed, 74 insertions(+), 9 deletions(-)\r
59 \r
60 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
61 index 42aef47..d0b4a0d 100644\r
62 --- a/notmuch-reply.c\r
63 +++ b/notmuch-reply.c\r
64 @@ -790,13 +790,15 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])\r
65         .crypto = {\r
66             .verify = FALSE,\r
67             .decrypt = FALSE,\r
68 -           .gpgpath = NULL\r
69 +           .gpg_path = NULL\r
70         }\r
71      };\r
72      int format = FORMAT_DEFAULT;\r
73      int reply_all = TRUE;\r
74      struct sprinter *sp = NULL;\r
75 -\r
76 +    notmuch_status_t status;\r
77 +    const char *gpg_path = NULL;\r
78 +    \r
79      notmuch_opt_desc_t options[] = {\r
80         { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',\r
81           (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },\r
82 @@ -845,7 +847,12 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])\r
83         return EXIT_FAILURE;\r
84      }\r
85  \r
86 -    params.crypto.gpgpath = notmuch_config_get_crypto_gpg_path (config);\r
87 +    gpg_path = notmuch_config_get_crypto_gpg_path (config);\r
88 +    status = _notmuch_crypto_set_gpg_path (&(params.crypto), gpg_path);\r
89 +    if (status != NOTMUCH_STATUS_SUCCESS) {\r
90 +       fprintf (stderr, "Error: could not set gpg_path to '%s'.\n", gpg_path);\r
91 +       return EXIT_FAILURE;\r
92 +    }\r
93  \r
94      if (notmuch_database_open (notmuch_config_get_database_path (config),\r
95                                NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
96 diff --git a/notmuch-show.c b/notmuch-show.c\r
97 index 8ebf4ff..60411d0 100644\r
98 --- a/notmuch-show.c\r
99 +++ b/notmuch-show.c\r
100 @@ -1006,13 +1006,15 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
101         .crypto = {\r
102             .verify = FALSE,\r
103             .decrypt = FALSE,\r
104 -           .gpgpath = NULL\r
105 +           .gpg_path = NULL\r
106         },\r
107         .include_html = FALSE\r
108      };\r
109      int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;\r
110      int exclude = EXCLUDE_TRUE;\r
111      int entire_thread = ENTIRE_THREAD_DEFAULT;\r
112 +    notmuch_status_t status;\r
113 +    const char *gpg_path = NULL;\r
114  \r
115      notmuch_opt_desc_t options[] = {\r
116         { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',\r
117 @@ -1130,7 +1132,13 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
118         return EXIT_FAILURE;\r
119      }\r
120  \r
121 -    params.crypto.gpgpath = notmuch_config_get_crypto_gpg_path (config);\r
122 +\r
123 +    gpg_path = notmuch_config_get_crypto_gpg_path (config);\r
124 +    status = _notmuch_crypto_set_gpg_path (&(params.crypto), gpg_path);\r
125 +    if (status != NOTMUCH_STATUS_SUCCESS) {\r
126 +       fprintf (stderr, "Error: could not set gpg_path to '%s'.\n", gpg_path);\r
127 +       return EXIT_FAILURE;\r
128 +    }\r
129  \r
130      if (notmuch_database_open (notmuch_config_get_database_path (config),\r
131                                NOTMUCH_DATABASE_MODE_READ_ONLY, &notmuch))\r
132 diff --git a/util/crypto.c b/util/crypto.c\r
133 index cce5cbc..9766c2c 100644\r
134 --- a/util/crypto.c\r
135 +++ b/util/crypto.c\r
136 @@ -21,7 +21,9 @@\r
137  \r
138  #include "notmuch.h"\r
139  #include "crypto.h"\r
140 +#include "search-path.h"\r
141  #include <string.h>\r
142 +#include <talloc.h>\r
143  \r
144  #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))\r
145  \r
146 @@ -38,7 +40,7 @@ get_gpg_context (_notmuch_crypto_t *crypto, GMimeCryptoContext **ctx)\r
147      }\r
148  \r
149      /* TODO: GMimePasswordRequestFunc */\r
150 -    crypto->gpgctx = g_mime_gpg_context_new (NULL, crypto->gpgpath ? crypto->gpgpath : "gpg");\r
151 +    crypto->gpgctx = g_mime_gpg_context_new (NULL, _notmuch_crypto_get_gpg_path (crypto));\r
152      if (! crypto->gpgctx) {\r
153         return NOTMUCH_STATUS_FAILED_CRYPTO_CONTEXT_CREATION;\r
154      }\r
155 @@ -51,7 +53,7 @@ get_gpg_context (_notmuch_crypto_t *crypto, GMimeCryptoContext **ctx)\r
156  }\r
157  \r
158  /* Create or pass on a PKCS7 context (GMime 2.6) */\r
159 -static notmuch_status_t \r
160 +static notmuch_status_t\r
161  get_pkcs7_context (_notmuch_crypto_t *crypto, GMimeCryptoContext **ctx)\r
162  {\r
163      if (ctx == NULL || crypto == NULL)\r
164 @@ -76,7 +78,7 @@ get_pkcs7_context (_notmuch_crypto_t *crypto, GMimeCryptoContext **ctx)\r
165  }\r
166  static const struct {\r
167      const char *protocol;\r
168 -    notmuch_status_t (*get_context) (_notmuch_crypto_t *crypto, GMimeCryptoContext **ctx);\r
169 +    notmuch_status_t (*get_context)(_notmuch_crypto_t *crypto, GMimeCryptoContext **ctx);\r
170  } protocols[] = {\r
171      {\r
172         .protocol = "application/pgp-signature",\r
173 @@ -120,6 +122,45 @@ _notmuch_crypto_get_gmime_ctx_for_protocol (_notmuch_crypto_t *crypto,\r
174      return NOTMUCH_STATUS_UNKNOWN_CRYPTO_PROTOCOL;\r
175  }\r
176  \r
177 +const char *\r
178 +_notmuch_crypto_get_gpg_path (const _notmuch_crypto_t *crypto)\r
179 +{\r
180 +    if (crypto && crypto->gpg_path)\r
181 +       return crypto->gpg_path;\r
182 +\r
183 +    if (test_for_executable ("gpg2")) return "gpg2";\r
184 +    if (test_for_executable ("gpg")) return "gpg";\r
185 +    return NULL;\r
186 +}\r
187 +\r
188 +notmuch_status_t\r
189 +_notmuch_crypto_set_gpg_path (_notmuch_crypto_t *crypto, const char *gpg_path)\r
190 +{\r
191 +    /* return success if this matches what is already configured */\r
192 +    if ((! gpg_path && ! crypto->gpg_path) ||\r
193 +       (gpg_path && crypto->gpg_path && 0 == strcmp (gpg_path, crypto->gpg_path)))\r
194 +       return NOTMUCH_STATUS_SUCCESS;\r
195 +\r
196 +    if (! gpg_path && ! test_for_executable (gpg_path))\r
197 +       return NOTMUCH_STATUS_FILE_ERROR;\r
198 +\r
199 +    /* clear any existing gpgctx, since things are changing */\r
200 +    if (crypto->gpgctx) {\r
201 +       g_object_unref (crypto->gpgctx);\r
202 +       crypto->gpgctx = NULL;\r
203 +    }\r
204 +\r
205 +    if (crypto->gpg_path) {\r
206 +       talloc_free (crypto->gpg_path);\r
207 +       crypto->gpg_path = NULL;\r
208 +    }\r
209 +\r
210 +    if (gpg_path)\r
211 +       crypto->gpg_path = talloc_strdup (NULL, gpg_path);\r
212 +\r
213 +    return NOTMUCH_STATUS_SUCCESS;\r
214 +}\r
215 +\r
216  void\r
217  _notmuch_crypto_cleanup (_notmuch_crypto_t *crypto)\r
218  {\r
219 @@ -132,4 +173,7 @@ _notmuch_crypto_cleanup (_notmuch_crypto_t *crypto)\r
220         g_object_unref (crypto->pkcs7ctx);\r
221         crypto->pkcs7ctx = NULL;\r
222      }\r
223 +\r
224 +    talloc_free (crypto->gpg_path);\r
225 +    crypto->gpg_path = NULL;\r
226  }\r
227 diff --git a/util/crypto.h b/util/crypto.h\r
228 index 7cb0a39..70fc8ef 100644\r
229 --- a/util/crypto.h\r
230 +++ b/util/crypto.h\r
231 @@ -11,7 +11,7 @@ typedef struct _notmuch_crypto {\r
232      GMimeCryptoContext* pkcs7ctx;\r
233      notmuch_bool_t verify;\r
234      notmuch_bool_t decrypt;\r
235 -    const char *gpgpath;\r
236 +    char *gpg_path;\r
237  } _notmuch_crypto_t;\r
238  \r
239  \r
240 @@ -20,6 +20,12 @@ _notmuch_crypto_get_gmime_ctx_for_protocol (_notmuch_crypto_t *crypto,\r
241                                             const char *protocol,\r
242                                             GMimeCryptoContext **ctx);\r
243  \r
244 +notmuch_status_t\r
245 +_notmuch_crypto_set_gpg_path (_notmuch_crypto_t *crypto, const char *gpg_path);\r
246 +\r
247 +const char *\r
248 +_notmuch_crypto_get_gpg_path (const _notmuch_crypto_t *crypto);\r
249 +\r
250  void\r
251  _notmuch_crypto_cleanup (_notmuch_crypto_t *crypto);\r
252  \r
253 -- \r
254 2.8.1\r
255 \r