Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / b6 / d295b0e6ddd5f8582de0f36a6c0e0bea92770e
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.921\r
10 X-Spam-Level: \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
13         autolearn=disabled\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
19         [131.215.239.19])\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
44 Precedence: list\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
55 \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
61 \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
65 ---\r
66  show-message.c |   22 ++++++++++++++++------\r
67  test/crypto    |   39 +++++++++++++++++++++++++++------------\r
68  2 files changed, 43 insertions(+), 18 deletions(-)\r
69 \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
76                    int first)\r
77  {\r
78 +    GMimeObject *decryptedpart = NULL;\r
79      int selected;\r
80      state->part_count += 1;\r
81  \r
82 @@ -67,7 +68,7 @@ show_message_part (GMimeObject *part,\r
83                          g_mime_multipart_get_count (multipart));\r
84             } else {\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
97                 } else {\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
101         if (selected)\r
102             state->in_zone = 1;\r
103  \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
113 +            * multipart. */\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
116 +       } else {\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
120 +           }\r
121         }\r
122  \r
123         if (selected)\r
124 diff --git a/test/crypto b/test/crypto\r
125 index ef35c55..6ce51d9 100755\r
126 --- a/test/crypto\r
127 +++ b/test/crypto\r
128 @@ -160,15 +160,20 @@ To: test_suite@notmuchmail.org\r
129  Date: 01 Jan 2000 12:00:00 -0000\r
130  \f\r
131 header}\r
132  \f\r
133 body{\r
134 -\f\r
135 part{ ID: 1, Content-type: multipart/mixed\r
136 -\f\r
137 part{ ID: 2, Content-type: text/plain\r
138 +\f\r
139 part{ ID: 1, Content-type: multipart/encrypted\r
140 +\f\r
141 part{ ID: 2, Content-type: application/pgp-encrypted\r
142 +Non-text part: application/pgp-encrypted\r
143 +\f\r
144 part}\r
145 +\f\r
146 part{ ID: 3, Content-type: multipart/mixed\r
147 +\f\r
148 part{ ID: 4, Content-type: text/plain\r
149  This is a test encrypted message.\r
150  \f\r
151 part}\r
152 -\f\r
153 attachment{ ID: 3, Content-type: application/octet-stream\r
154 +\f\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
158  \f\r
159 attachment}\r
160  \f\r
161 part}\r
162 +\f\r
163 part}\r
164  \f\r
165 body}\r
166  \f\r
167 message}'\r
168  test_expect_equal \\r
169 @@ -194,33 +199,37 @@ expected='[[[{"id": "XXXXX",\r
170   "body": [{"id": 1,\r
171   "encstatus": [{"status": "good"}],\r
172   "sigstatus": [],\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
177 + {"id": 3,\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
182 - {"id": 3,\r
183 + {"id": 5,\r
184   "content-type": "application/octet-stream",\r
185 - "filename": "TESTATTACHMENT"}]}]},\r
186 + "filename": "TESTATTACHMENT"}]}]}]},\r
187   []]]]'\r
188  test_expect_equal \\r
189      "$output" \\r
190      "$expected"\r
191  \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
203      "$output" \\r
204      "$expected"\r
205  \r
206 -test_begin_subtest "decrypt attachment (--part=3 --format=raw)"\r
207 +test_begin_subtest "decrypt attachment (--part=5 --format=raw)"\r
208  notmuch show \\r
209      --format=raw \\r
210 -    --part=3 \\r
211 +    --part=5 \\r
212      --decrypt \\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
222 + {"id": 3,\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
226   []]]]'\r
227  test_expect_equal \\r
228      "$output" \\r
229 @@ -297,6 +310,8 @@ expected='From: Notmuch Test Suite <test_suite@notmuchmail.org>\r
230  Subject: Re: test encrypted message 002\r
231  \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
237      "$output" \\r
238 -- \r
239 1.7.4.4\r
240 \r