Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 5f / f80fe0628c0006d12c5842c4efadb91acf3682
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 2A7DF6DE1557\r
6  for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 18:53:25 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.023\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.023 tagged_above=-999 required=5\r
12  tests=[AWL=-0.023] 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 gBp_lTlYlBql for <notmuch@notmuchmail.org>;\r
16  Tue, 19 Jan 2016 18:53:23 -0800 (PST)\r
17 Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
18  by arlo.cworth.org (Postfix) with ESMTP id 613F26DE15D4\r
19  for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 18:53:16 -0800 (PST)\r
20 Received: from fifthhorseman.net (unknown [38.109.115.130])\r
21  by che.mayfirst.org (Postfix) with ESMTPSA id 27E22F99B\r
22  for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 21:53:14 -0500 (EST)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id F3C7720676; Tue, 19 Jan 2016 18:53:10 -0800 (PST)\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>\r
27 Subject: [PATCH v2 11/16] add --try-decrypt to notmuch insert\r
28 Date: Tue, 19 Jan 2016 21:52:44 -0500\r
29 Message-Id: <1453258369-7366-12-git-send-email-dkg@fifthhorseman.net>\r
30 X-Mailer: git-send-email 2.7.0.rc3\r
31 In-Reply-To: <1453258369-7366-1-git-send-email-dkg@fifthhorseman.net>\r
32 References: <1453258369-7366-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: Wed, 20 Jan 2016 02:53:25 -0000\r
46 \r
47 allow an incoming message to be delivered while indexing the\r
48 cleartext.\r
49 \r
50 This requires the secret keys for the message to be available.  For\r
51 the moment, the most functional approach is to ensure that gpg-agent\r
52 is running and knows about any secret keys that might be useful to\r
53 decrypt incoming mail.\r
54 \r
55 Any additional recommendations for how to phrase the caveat for this\r
56 option are welcome.\r
57 \r
58 If ~/.notmuch-config contains crypto.gpg_path, and gpg is needed for\r
59 indexing, the configuration option will be used to find gpg.\r
60 ---\r
61  completion/notmuch-completion.bash |  2 +-\r
62  doc/man1/notmuch-insert.rst        | 11 +++++++++++\r
63  notmuch-insert.c                   | 32 +++++++++++++++++++++++++++++---\r
64  3 files changed, 41 insertions(+), 4 deletions(-)\r
65 \r
66 diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash\r
67 index cc58392..4bc9040 100644\r
68 --- a/completion/notmuch-completion.bash\r
69 +++ b/completion/notmuch-completion.bash\r
70 @@ -224,7 +224,7 @@ _notmuch_insert()\r
71      ! $split &&\r
72      case "${cur}" in\r
73         --*)\r
74 -           local options="--create-folder --folder= --keep --no-hooks ${_notmuch_shared_options}"\r
75 +           local options="--create-folder --folder= --keep --no-hooks --try-decrypt ${_notmuch_shared_options}"\r
76             compopt -o nospace\r
77             COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
78             return\r
79 diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst\r
80 index 2c9c0d0..9c76b30 100644\r
81 --- a/doc/man1/notmuch-insert.rst\r
82 +++ b/doc/man1/notmuch-insert.rst\r
83 @@ -50,6 +50,17 @@ Supported options for **insert** include\r
84      ``--no-hooks``\r
85          Prevent hooks from being run.\r
86  \r
87 +    ``--try-decrypt``\r
88 +\r
89 +        If the message is encrypted, try to decrypt the message while\r
90 +        indexing.  If decryption is successful, index the cleartext\r
91 +        itself.  The message is stored to disk in its original form\r
92 +        (ciphertext).  Be aware that the index is likely sufficient to\r
93 +        reconstruct the cleartext of the message itself, so please\r
94 +        ensure that the notmuch message index is adequately\r
95 +        protected. DO NOT USE THIS FLAG without considering the\r
96 +        security of your index.\r
97 +\r
98  EXIT STATUS\r
99  ===========\r
100  \r
101 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
102 index 5205c17..eae1ec5 100644\r
103 --- a/notmuch-insert.c\r
104 +++ b/notmuch-insert.c\r
105 @@ -378,12 +378,13 @@ FAIL:\r
106   */\r
107  static notmuch_status_t\r
108  add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops,\r
109 -         notmuch_bool_t synchronize_flags, notmuch_bool_t keep)\r
110 +         notmuch_bool_t synchronize_flags, notmuch_bool_t keep,\r
111 +         notmuch_indexopts_t *indexopts)\r
112  {\r
113      notmuch_message_t *message;\r
114      notmuch_status_t status;\r
115  \r
116 -    status = notmuch_database_add_message (notmuch, path, &message);\r
117 +    status = notmuch_database_add_message_with_indexopts (notmuch, path, indexopts, &message);\r
118      if (status == NOTMUCH_STATUS_SUCCESS) {\r
119         status = tag_op_list_apply (message, tag_ops, 0);\r
120         if (status) {\r
121 @@ -455,17 +456,20 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
122      notmuch_bool_t create_folder = FALSE;\r
123      notmuch_bool_t keep = FALSE;\r
124      notmuch_bool_t no_hooks = FALSE;\r
125 +    notmuch_bool_t try_decrypt = FALSE;\r
126      notmuch_bool_t synchronize_flags;\r
127      const char *maildir;\r
128      char *newpath;\r
129      int opt_index;\r
130      unsigned int i;\r
131 +    notmuch_indexopts_t *indexopts;\r
132  \r
133      notmuch_opt_desc_t options[] = {\r
134         { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },\r
135         { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },\r
136         { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 },\r
137         { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },\r
138 +       { NOTMUCH_OPT_BOOLEAN,  &try_decrypt, "try-decrypt", 0, 0 },\r
139         { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
140         { NOTMUCH_OPT_END, 0, 0, 0, 0 }\r
141      };\r
142 @@ -545,8 +549,29 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
143         return EXIT_FAILURE;\r
144      }\r
145  \r
146 +    indexopts = notmuch_indexopts_create ();\r
147 +    if (!indexopts) {\r
148 +       fprintf (stderr, "Error: could not create index options.\n");\r
149 +       return EXIT_FAILURE;\r
150 +    }\r
151 +    status = notmuch_indexopts_set_try_decrypt (indexopts, try_decrypt);\r
152 +    if (status != NOTMUCH_STATUS_SUCCESS) {\r
153 +       fprintf (stderr, "Error: Failed to set try_decrypt to %s. (%s)\n",\r
154 +                try_decrypt ? "True" : "False", notmuch_status_to_string (status));\r
155 +       notmuch_indexopts_destroy (indexopts);\r
156 +       return EXIT_FAILURE;\r
157 +    }\r
158 +    if (try_decrypt) {\r
159 +       const char* gpg_path = notmuch_config_get_crypto_gpg_path (config);\r
160 +       status = notmuch_indexopts_set_gpg_path (indexopts, gpg_path);\r
161 +       if (status)\r
162 +           fprintf (stderr, "Warning: failed to set database gpg_path to '%s' (%s)\n",\r
163 +                    gpg_path ? gpg_path : "(NULL)",\r
164 +                    notmuch_status_to_string (status));\r
165 +    }\r
166 +\r
167      /* Index the message. */\r
168 -    status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep);\r
169 +    status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts);\r
170  \r
171      /* Commit changes. */\r
172      close_status = notmuch_database_destroy (notmuch);\r
173 @@ -577,5 +602,6 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
174         notmuch_run_hook (db_path, "post-insert");\r
175      }\r
176  \r
177 +    notmuch_indexopts_destroy (indexopts);\r
178      return status ? EXIT_FAILURE : EXIT_SUCCESS;\r
179  }\r
180 -- \r
181 2.7.0.rc3\r
182 \r