[PATCH v2 00/14] reply refactor, fixes
[notmuch-archives.git] / 99 / 2d9aa7fbedc7eb39a431b695264f8f68119ec2
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 EF9FE6DE1603\r
6  for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 19:40:13 -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.033\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.033 tagged_above=-999 required=5\r
12  tests=[AWL=-0.033] 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 l707XKEmuUEW for <notmuch@notmuchmail.org>;\r
16  Wed,  9 Dec 2015 19:40:12 -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 F3EF46DE1811\r
19  for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 19:40:05 -0800 (PST)\r
20 Received: from fifthhorseman.net (unknown [38.109.115.130])\r
21  by che.mayfirst.org (Postfix) with ESMTPSA id 7A89AF98C\r
22  for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 22:40:04 -0500 (EST)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id C683E212DC; Wed,  9 Dec 2015 22:40:03 -0500 (EST)\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>\r
27 Subject: [PATCH 9/9] add --try-decrypt to notmuch new\r
28 Date: Wed,  9 Dec 2015 22:39:46 -0500\r
29 Message-Id: <1449718786-28000-10-git-send-email-dkg@fifthhorseman.net>\r
30 X-Mailer: git-send-email 2.6.2\r
31 In-Reply-To: <1449718786-28000-1-git-send-email-dkg@fifthhorseman.net>\r
32 References: <1449718786-28000-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: Thu, 10 Dec 2015 03:40:14 -0000\r
46 \r
47 Try to decrypt newly-discovered messages while indexing them.\r
48 \r
49 If ~/.notmuch-config contains crypto.gpg_path, and gpg is needed, it\r
50 will be used to find gpg while indexing.\r
51 ---\r
52  completion/notmuch-completion.bash |  2 +-\r
53  doc/man1/notmuch-new.rst           | 10 ++++++++++\r
54  notmuch-new.c                      | 18 +++++++++++++++++-\r
55  3 files changed, 28 insertions(+), 2 deletions(-)\r
56 \r
57 diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash\r
58 index 4bc9040..214f776 100644\r
59 --- a/completion/notmuch-completion.bash\r
60 +++ b/completion/notmuch-completion.bash\r
61 @@ -247,7 +247,7 @@ _notmuch_new()\r
62  \r
63      case "${cur}" in\r
64         -*)\r
65 -           local options="--no-hooks --quiet ${_notmuch_shared_options}"\r
66 +           local options="--no-hooks --try-decrypt --quiet ${_notmuch_shared_options}"\r
67             compopt -o nospace\r
68             COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )\r
69             ;;\r
70 diff --git a/doc/man1/notmuch-new.rst b/doc/man1/notmuch-new.rst\r
71 index 787ed78..cf08021 100644\r
72 --- a/doc/man1/notmuch-new.rst\r
73 +++ b/doc/man1/notmuch-new.rst\r
74 @@ -43,6 +43,16 @@ Supported options for **new** include\r
75      ``--quiet``\r
76          Do not print progress or results.\r
77  \r
78 +    ``--try-decrypt``\r
79 +\r
80 +        For each message, if it is encrypted, try to decrypt it while\r
81 +        indexing.  If decryption is successful, index the cleartext\r
82 +        itself.  Be aware that the index is likely sufficient to\r
83 +        reconstruct the cleartext of the message itself, so please\r
84 +        ensure that the notmuch message index is adequately\r
85 +        protected. DO NOT USE THIS FLAG without considering the\r
86 +        security of your index.\r
87 +\r
88  SEE ALSO\r
89  ========\r
90  \r
91 diff --git a/notmuch-new.c b/notmuch-new.c\r
92 index d45d0af..e5903b8 100644\r
93 --- a/notmuch-new.c\r
94 +++ b/notmuch-new.c\r
95 @@ -49,6 +49,7 @@ typedef struct {\r
96      size_t new_tags_length;\r
97      const char **new_ignore;\r
98      size_t new_ignore_length;\r
99 +    notmuch_bool_t try_decrypt;\r
100  \r
101      int total_files;\r
102      int processed_files;\r
103 @@ -260,7 +261,10 @@ add_file (notmuch_database_t *notmuch, const char *filename,\r
104      if (status)\r
105         goto DONE;\r
106  \r
107 -    status = notmuch_database_add_message (notmuch, filename, &message);\r
108 +    if (state->try_decrypt)\r
109 +       status = notmuch_database_add_message_try_decrypt (notmuch, filename, &message);\r
110 +    else\r
111 +       status = notmuch_database_add_message (notmuch, filename, &message);\r
112      switch (status) {\r
113      /* Success. */\r
114      case NOTMUCH_STATUS_SUCCESS:\r
115 @@ -930,6 +934,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
116      add_files_state_t add_files_state = {\r
117         .verbosity = VERBOSITY_NORMAL,\r
118         .debug = FALSE,\r
119 +       .try_decrypt = FALSE,\r
120         .output_is_a_tty = isatty (fileno (stdout)),\r
121      };\r
122      struct timeval tv_start;\r
123 @@ -951,6 +956,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
124         { NOTMUCH_OPT_BOOLEAN,  &verbose, "verbose", 'v', 0 },\r
125         { NOTMUCH_OPT_BOOLEAN,  &add_files_state.debug, "debug", 'd', 0 },\r
126         { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },\r
127 +       { NOTMUCH_OPT_BOOLEAN,  &add_files_state.try_decrypt, "try-decrypt", 0, 0 },\r
128         { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
129         { 0, 0, 0, 0, 0 }\r
130      };\r
131 @@ -1068,6 +1074,16 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
132      if (notmuch == NULL)\r
133         return EXIT_FAILURE;\r
134  \r
135 +    if (add_files_state.try_decrypt) {\r
136 +       const char* gpg_path = notmuch_config_get_crypto_gpg_path (config);\r
137 +       status = notmuch_database_set_gpg_path(notmuch, gpg_path);\r
138 +       if (status)\r
139 +           fprintf (stderr, "Warning: failed to set database gpg_path to '%s' (%s)\n",\r
140 +                    gpg_path ? gpg_path : "(NULL)",\r
141 +                    notmuch_status_to_string (status));\r
142 +    }\r
143 +\r
144 +    \r
145      /* Set up our handler for SIGINT. We do this after having\r
146       * potentially done a database upgrade we this interrupt handler\r
147       * won't support. */\r
148 -- \r
149 2.6.2\r
150 \r