1 Return-Path: <jrollins@servo.finestructure.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 olra.theworths.org (Postfix) with ESMTP id A1D6D429E2D
\r
6 for <notmuch@notmuchmail.org>; Fri, 27 May 2011 03:28:02 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.921 tagged_above=-999 required=5
\r
12 tests=[NO_DNS_FOR_FROM=0.379, RCVD_IN_DNSWL_MED=-2.3]
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id P4fRb3-SFJI0 for <notmuch@notmuchmail.org>;
\r
17 Fri, 27 May 2011 03:28:00 -0700 (PDT)
\r
18 Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu
\r
20 by olra.theworths.org (Postfix) with ESMTP id CB5DB429E4E
\r
21 for <notmuch@notmuchmail.org>; Fri, 27 May 2011 03:27:52 -0700 (PDT)
\r
22 Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1])
\r
23 by fire-doxen-postvirus (Postfix) with ESMTP id 828F7328393;
\r
24 Fri, 27 May 2011 03:21:31 -0700 (PDT)
\r
25 X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new
\r
26 Received: from servo.finestructure.net (cpe-98-149-172-122.socal.res.rr.com
\r
27 [98.149.172.122]) (Authenticated sender: jrollins)
\r
28 by fire-doxen-submit (Postfix) with ESMTP id 61712328395;
\r
29 Fri, 27 May 2011 03:21:24 -0700 (PDT)
\r
30 Received: by servo.finestructure.net (Postfix, from userid 1000)
\r
31 id 24DB5270; Fri, 27 May 2011 03:27:43 -0700 (PDT)
\r
32 From: Jameson Graef Rollins <jrollins@finestructure.net>
\r
33 To: notmuch@notmuchmail.org
\r
34 Subject: [PATCH 2/4] Render all parts of multipart/encrypted when decrypting.
\r
35 Date: Fri, 27 May 2011 03:27:37 -0700
\r
36 Message-Id: <1306492059-7706-3-git-send-email-jrollins@finestructure.net>
\r
37 X-Mailer: git-send-email 1.7.4.4
\r
38 In-Reply-To: <1306492059-7706-2-git-send-email-jrollins@finestructure.net>
\r
39 References: <1306371680-19441-1-git-send-email-jrollins@finestructure.net>
\r
40 <1306492059-7706-1-git-send-email-jrollins@finestructure.net>
\r
41 <1306492059-7706-2-git-send-email-jrollins@finestructure.net>
\r
42 X-BeenThere: notmuch@notmuchmail.org
\r
43 X-Mailman-Version: 2.1.13
\r
45 List-Id: "Use and development of the notmuch mail system."
\r
46 <notmuch.notmuchmail.org>
\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
50 List-Post: <mailto:notmuch@notmuchmail.org>
\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
54 X-List-Received-Date: Fri, 27 May 2011 10:28:02 -0000
\r
56 The primary goal here is to keep the decrypted output as similarly
\r
57 structured as undecrypted output as possible. Now, when decrypting
\r
58 parts, only the original encrypted part is replaced by the it's
\r
59 decrypted content. If this part isn't itself a multipart, then all
\r
60 part numbering should remain consistent during decryption.
\r
62 The only draw back here is that the useless application/pgp-encrypted
\r
63 sub-part of the multipart/encrypted part is also emitted. But this
\r
64 part can be easily ignored by clients.
\r
66 show-message.c | 22 ++++++++++++++++------
\r
67 test/crypto | 39 +++++++++++++++++++++++++++------------
\r
68 2 files changed, 43 insertions(+), 18 deletions(-)
\r
70 diff --git a/show-message.c b/show-message.c
\r
71 index 849c686..7a4bbc2 100644
\r
72 --- a/show-message.c
\r
73 +++ b/show-message.c
\r
74 @@ -34,6 +34,7 @@ show_message_part (GMimeObject *part,
\r
75 notmuch_show_params_t *params,
\r
78 + GMimeObject *decryptedpart = NULL;
\r
80 state->part_count += 1;
\r
82 @@ -67,7 +68,7 @@ show_message_part (GMimeObject *part,
\r
83 g_mime_multipart_get_count (multipart));
\r
85 GMimeMultipartEncrypted *encrypteddata = GMIME_MULTIPART_ENCRYPTED (part);
\r
86 - GMimeObject *decryptedpart = g_mime_multipart_encrypted_decrypt (encrypteddata, params->cryptoctx, &err);
\r
87 + decryptedpart = g_mime_multipart_encrypted_decrypt (encrypteddata, params->cryptoctx, &err);
\r
88 if (decryptedpart) {
\r
89 if ((selected || state->in_zone) && format->part_encstatus)
\r
90 format->part_encstatus (1);
\r
91 @@ -76,8 +77,6 @@ show_message_part (GMimeObject *part,
\r
92 fprintf (stderr, "Failed to verify signed part: %s\n", (err ? err->message : "no error explanation given"));
\r
93 if ((selected || state->in_zone) && format->part_sigstatus)
\r
94 format->part_sigstatus (sigvalidity);
\r
95 - /* swap the part with the decrypted part */
\r
96 - part = decryptedpart;
\r
98 fprintf (stderr, "Failed to decrypt part: %s\n", (err ? err->message : "no error explanation given"));
\r
99 if ((selected || state->in_zone) && format->part_encstatus)
\r
100 @@ -125,9 +124,20 @@ show_message_part (GMimeObject *part,
\r
102 state->in_zone = 1;
\r
104 - for (i = 0; i < g_mime_multipart_get_count (multipart); i++) {
\r
105 - show_message_part (g_mime_multipart_get_part (multipart, i),
\r
106 - state, format, params, i == 0);
\r
107 + if (decryptedpart) {
\r
108 + /* We emit the useless application/pgp-encrypted version
\r
109 + * part here only to keep the emitted output as consistent
\r
110 + * as possible between decrypted output and the
\r
111 + * unprocessed multipart/mime. For some strange reason,
\r
112 + * the actual encrypted data is the second part of the
\r
114 + show_message_part (g_mime_multipart_get_part (multipart, 0), state, format, params, TRUE);
\r
115 + show_message_part (decryptedpart, state, format, params, FALSE);
\r
117 + for (i = 0; i < g_mime_multipart_get_count (multipart); i++) {
\r
118 + show_message_part (g_mime_multipart_get_part (multipart, i),
\r
119 + state, format, params, i == 0);
\r
124 diff --git a/test/crypto b/test/crypto
\r
125 index ef35c55..6ce51d9 100755
\r
128 @@ -160,15 +160,20 @@ To: test_suite@notmuchmail.org
\r
129 Date: 01 Jan 2000 12:00:00 -0000
\r
135 part{ ID: 1, Content-type: multipart/mixed
\r
137 part{ ID: 2, Content-type: text/plain
\r
139 part{ ID: 1, Content-type: multipart/encrypted
\r
141 part{ ID: 2, Content-type: application/pgp-encrypted
\r
142 +Non-text part: application/pgp-encrypted
\r
146 part{ ID: 3, Content-type: multipart/mixed
\r
148 part{ ID: 4, Content-type: text/plain
\r
149 This is a test encrypted message.
\r
153 attachment{ ID: 3, Content-type: application/octet-stream
\r
155 attachment{ ID: 5, Content-type: application/octet-stream
\r
156 Attachment: TESTATTACHMENT (application/octet-stream)
\r
157 Non-text part: application/octet-stream
\r
168 test_expect_equal \
\r
169 @@ -194,33 +199,37 @@ expected='[[[{"id": "XXXXX",
\r
171 "encstatus": [{"status": "good"}],
\r
173 - "content-type": "multipart/mixed",
\r
174 + "content-type": "multipart/encrypted",
\r
175 "content": [{"id": 2,
\r
176 + "content-type": "application/pgp-encrypted"},
\r
178 + "content-type": "multipart/mixed",
\r
179 + "content": [{"id": 4,
\r
180 "content-type": "text/plain",
\r
181 "content": "This is a test encrypted message.\n"},
\r
184 "content-type": "application/octet-stream",
\r
185 - "filename": "TESTATTACHMENT"}]}]},
\r
186 + "filename": "TESTATTACHMENT"}]}]}]},
\r
188 test_expect_equal \
\r
192 -test_begin_subtest "decryption, --format=json, --part=2"
\r
193 -output=$(notmuch show --format=json --part=2 --decrypt subject:"test encrypted message 001" \
\r
194 +test_begin_subtest "decryption, --format=json, --part=4"
\r
195 +output=$(notmuch show --format=json --part=4 --decrypt subject:"test encrypted message 001" \
\r
196 | notmuch_json_show_sanitize \
\r
197 | sed -e 's|"created": [1234567890]*|"created": 946728000|')
\r
198 -expected='{"id": 2,
\r
199 +expected='{"id": 4,
\r
200 "content-type": "text/plain",
\r
201 "content": "This is a test encrypted message.\n"}'
\r
202 test_expect_equal \
\r
206 -test_begin_subtest "decrypt attachment (--part=3 --format=raw)"
\r
207 +test_begin_subtest "decrypt attachment (--part=5 --format=raw)"
\r
213 subject:"test encrypted message 001" >OUTPUT
\r
214 test_expect_equal_file OUTPUT TESTATTACHMENT
\r
215 @@ -283,8 +292,12 @@ expected='[[[{"id": "XXXXX",
\r
216 "fingerprint": "'$FINGERPRINT'",
\r
217 "created": 946728000,
\r
218 "userid": " Notmuch Test Suite <test_suite@notmuchmail.org> (INSECURE!)"}],
\r
219 + "content-type": "multipart/encrypted",
\r
220 + "content": [{"id": 2,
\r
221 + "content-type": "application/pgp-encrypted"},
\r
223 "content-type": "text/plain",
\r
224 - "content": "This is another test encrypted message.\n"}]},
\r
225 + "content": "This is another test encrypted message.\n"}]}]},
\r
227 test_expect_equal \
\r
229 @@ -297,6 +310,8 @@ expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
230 Subject: Re: test encrypted message 002
\r
232 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
\r
233 +Non-text part: multipart/encrypted
\r
234 +Non-text part: application/pgp-encrypted
\r
235 > This is another test encrypted message.'
\r
236 test_expect_equal \
\r