Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 01 / 1a4483c6b0232807c48e6b8b80efeaaa21adab
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 1B5C16DE0FF1\r
6  for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 19:40:09 -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.035\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.035 tagged_above=-999 required=5\r
12  tests=[AWL=-0.035] 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 5UbXq0YuG3Ap for <notmuch@notmuchmail.org>;\r
16  Wed,  9 Dec 2015 19:40:05 -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 D46A36DE005F\r
19  for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 19:40:04 -0800 (PST)\r
20 Received: from fifthhorseman.net (unknown [38.109.115.130])\r
21  by che.mayfirst.org (Postfix) with ESMTPSA id 09188F985\r
22  for <notmuch@notmuchmail.org>; Wed,  9 Dec 2015 22:40:03 -0500 (EST)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id AC13120CF1; 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 3/9] index encrypted parts when the message is flagged\r
28  appropriately\r
29 Date: Wed,  9 Dec 2015 22:39:40 -0500\r
30 Message-Id: <1449718786-28000-4-git-send-email-dkg@fifthhorseman.net>\r
31 X-Mailer: git-send-email 2.6.2\r
32 In-Reply-To: <1449718786-28000-1-git-send-email-dkg@fifthhorseman.net>\r
33 References: <1449718786-28000-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: Thu, 10 Dec 2015 03:40:09 -0000\r
47 \r
48 We add a new message flag that indicates desire for indexing the\r
49 cleartext of a given message.\r
50 \r
51 If that flag is set while indexing, we'll try to descend into it.\r
52 \r
53 If we can decrypt, we tag the message with index-decrypted.\r
54 \r
55 If we can't decrypt (or recognize the encrypted type of mail), we tag\r
56 with decryption-failed.\r
57 \r
58 Note that a single message may be tagged with "encrypted" and\r
59 "index-decrypted" and "decryption-failed".  For example, consider a\r
60 message that includes multiple layers of encryption.  It is\r
61 automatically tagged with "encrypted".  If we decrypt the outer layer\r
62 ("index-decrypted"), but fail on the inner layer\r
63 ("decryption-failed").\r
64 ---\r
65  lib/index.cc  | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-\r
66  lib/notmuch.h |  5 +++++\r
67  2 files changed, 56 insertions(+), 1 deletion(-)\r
68 \r
69 diff --git a/lib/index.cc b/lib/index.cc\r
70 index 2fa6616..bd028cb 100644\r
71 --- a/lib/index.cc\r
72 +++ b/lib/index.cc\r
73 @@ -300,6 +300,10 @@ _index_address_list (notmuch_message_t *message,\r
74      }\r
75  }\r
76  \r
77 +static void\r
78 +_index_encrypted_mime_part (notmuch_message_t *message, GMimeContentType *content_type,\r
79 +                           GMimeMultipartEncrypted *part);\r
80 +\r
81  /* Callback to generate terms for each mime part of a message. */\r
82  static void\r
83  _index_mime_part (notmuch_message_t *message,\r
84 @@ -346,7 +350,10 @@ _index_mime_part (notmuch_message_t *message,\r
85                 _notmuch_database_log (_notmuch_message_database (message),\r
86                                        "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n");\r
87         } else if (GMIME_IS_MULTIPART_ENCRYPTED (multipart)) {\r
88 -           /* Don't index encrypted parts */\r
89 +           _notmuch_message_add_term (message, "tag", "encrypted");\r
90 +           if (notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_INDEX_DECRYPTED)) {\r
91 +               _index_encrypted_mime_part(message, content_type, GMIME_MULTIPART_ENCRYPTED (part));\r
92 +           }\r
93         } else {\r
94             for (i = 0; i < g_mime_multipart_get_count (multipart); i++) {\r
95                 _index_mime_part (message,\r
96 @@ -431,6 +438,49 @@ _index_mime_part (notmuch_message_t *message,\r
97      }\r
98  }\r
99  \r
100 +/* descend (if possible) into the cleartext part of an encrypted MIME\r
101 + * part while indexing. */\r
102 +static void\r
103 +_index_encrypted_mime_part (notmuch_message_t *message,\r
104 +                           GMimeContentType *content_type,\r
105 +                           GMimeMultipartEncrypted *encrypted_data)\r
106 +{\r
107 +    notmuch_private_status_t status;\r
108 +    GMimeCryptoContext* crypto_ctx = NULL;\r
109 +    const char *protocol = g_mime_content_type_get_parameter (content_type, "protocol");\r
110 +    GError *err = NULL;\r
111 +    notmuch_database_t * notmuch = _notmuch_message_database (message);\r
112 +    GMimeObject *clear = NULL;\r
113 +    \r
114 +    status = _notmuch_database_get_crypto_for_protocol (notmuch, protocol,\r
115 +                                                       &crypto_ctx);\r
116 +    if (status) {\r
117 +       _notmuch_database_log (notmuch, "Warning: setup failed for decrypting "\r
118 +                              "during indexing. (%d)\n", status);\r
119 +       _notmuch_message_add_term (message, "tag", "index-decryption-failed");\r
120 +       return;\r
121 +    }\r
122 +\r
123 +    /* we don't need the GMimeDecryptResult, because we're not looking\r
124 +     * at validating signatures, and we don't care about indexing who\r
125 +     * the message was ostensibly encrypted to.\r
126 +     */\r
127 +    clear = g_mime_multipart_encrypted_decrypt(encrypted_data, crypto_ctx,\r
128 +                                              NULL, &err);\r
129 +    if (err) {\r
130 +       _notmuch_database_log (notmuch, "Failed to decrypt during indexing. (%d:%d) [%s]\n",\r
131 +                              err->domain, err->code, err->message);\r
132 +       g_error_free(err);\r
133 +       /* Indicate that we failed to decrypt during indexing */\r
134 +       _notmuch_message_add_term (message, "tag", "index-decryption-failed");\r
135 +       return;\r
136 +    }\r
137 +    _index_mime_part (message, clear);\r
138 +    g_object_unref (clear);\r
139 +    \r
140 +    _notmuch_message_add_term (message, "tag", "index-decrypted");\r
141 +}\r
142 +\r
143  notmuch_status_t\r
144  _notmuch_message_index_file (notmuch_message_t *message,\r
145                              notmuch_message_file_t *message_file)\r
146 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
147 index 310a8b8..e7085b7 100644\r
148 --- a/lib/notmuch.h\r
149 +++ b/lib/notmuch.h\r
150 @@ -1357,6 +1357,11 @@ typedef enum _notmuch_message_flag {\r
151       * thread ID.\r
152       */\r
153      NOTMUCH_MESSAGE_FLAG_GHOST,\r
154 +    \r
155 +    /* Some part(s) of this message is encrypted, but the message is\r
156 +     * indexed in the clear.\r
157 +     */\r
158 +    NOTMUCH_MESSAGE_FLAG_INDEX_DECRYPTED\r
159  } notmuch_message_flag_t;\r
160  \r
161  /**\r
162 -- \r
163 2.6.2\r
164 \r