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