Merge lp:~gmb/launchpad/dont-leak-email-addresses-bug-111147 into lp:launchpad

Proposed by Graham Binns
Status: Rejected
Rejected by: Graham Binns
Proposed branch: lp:~gmb/launchpad/dont-leak-email-addresses-bug-111147
Merge into: lp:launchpad
Diff against target: 726 lines (+138/-120)
5 files modified
lib/canonical/launchpad/mailnotification.py (+8/-28)
lib/lp/bugs/doc/bugnotification-email.txt (+14/-37)
lib/lp/bugs/doc/bugnotification-sending.txt (+65/-54)
lib/lp/bugs/scripts/bugnotification.py (+1/-1)
lib/lp/bugs/tests/test_bugnotification.py (+50/-0)
To merge this branch: bzr merge lp:~gmb/launchpad/dont-leak-email-addresses-bug-111147
Reviewer Review Type Date Requested Status
Canonical Launchpad Engineering code Pending
Review via email: mp+27155@code.launchpad.net

Commit message

Bug notification email will now always come from 'Person Name <$<email address hidden>>' instead of spoofing the email of the person who generated the notification.

Description of the change

This branch fixes bug 111147 and bug 31586 by making all bug notification emails come from $<email address hidden> instead of the email address of the Person that triggered the notification.

To compensate for the fact that people will no longer be able to filter bugmail based on the sender's email address, I've added an X-Launchpad-Sender header which contains the LP name of the Person that caused the notification to be sent.

I've made the following changes:

== lib/canonical/launchpad/mailnotification.py ==

 - I've updated the get_bugmail_from_address() function to always return "Name <$<email address hidden>>" instead of returning the Person's email address.
 - I've added a line to BugNotificationBuilder.build() to add an X-Launchpad-Sender header to notification emails.

== lib/lp/bugs/doc/bugnotification-email.txt ==

 - I've updated all tests to account for the changes I've made.

== lib/lp/bugs/doc/bugnotification-sending.txt ==

 - I've updated all tests to account for the changes I've made.

== lib/lp/bugs/scripts/bugnotification.py ==

 - I've updated the call to BugNotificationBuilder.build() to pass the Person who triggered the notification.

== lib/lp/bugs/tests/test_bugnotification.py ==

 - I've added a TestCase to cover BugNotification email headers. We'll eventually refactor our existing tests for headers as unit tests, so this seemed an ideal time to start.
 - I've added a test for the new X-Launchpad-Sender header.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/mailnotification.py'
2--- lib/canonical/launchpad/mailnotification.py 2010-05-20 01:11:41 +0000
3+++ lib/canonical/launchpad/mailnotification.py 2010-06-09 13:50:46 +0000
4@@ -251,7 +251,7 @@
5 ('X-Launchpad-Bug-Commenters', ' '.join(sorted(commenters))))
6
7 def build(self, from_address, to_address, body, subject, email_date,
8- rationale=None, references=None, message_id=None):
9+ sender, rationale=None, references=None, message_id=None):
10 """Construct the notification.
11
12 :param from_address: The From address of the notification.
13@@ -260,6 +260,7 @@
14 :type body: unicode
15 :param subject: The Subject of the notification.
16 :param email_date: The Date for the notification.
17+ :param sender: The Launchpad Person sending the notification.
18 :param rationale: The rationale for why the recipient is
19 receiving this notification.
20 :param references: A value for the References header.
21@@ -292,6 +293,8 @@
22 if rationale is not None:
23 message.add_header('X-Launchpad-Message-Rationale', rationale)
24
25+ message.add_header('X-Launchpad-Sender', sender.name)
26+
27 return message
28
29
30@@ -368,34 +371,11 @@
31
32 def get_bugmail_from_address(person, bug):
33 """Returns the right From: address to use for a bug notification."""
34+ bug_address = "%s@%s" % (bug.id, config.launchpad.bugs_domain)
35 if person == getUtility(ILaunchpadCelebrities).janitor:
36- return format_address(
37- 'Launchpad Bug Tracker',
38- "%s@%s" % (bug.id, config.launchpad.bugs_domain))
39-
40- if person.preferredemail is not None:
41- return format_address(person.displayname, person.preferredemail.email)
42-
43- # XXX: Bjorn Tillenius 2006-04-05:
44- # The person doesn't have a preferred email set, but he
45- # added a comment (either via the email UI, or because he was
46- # imported as a deaf reporter). It shouldn't be possible to use the
47- # email UI if you don't have a preferred email set, but work around
48- # it for now by trying hard to find the right email address to use.
49- email_addresses = shortlist(
50- getUtility(IEmailAddressSet).getByPerson(person))
51- if not email_addresses:
52- # XXX: Bjorn Tillenius 2006-05-21 bug=33427:
53- # A user should always have at least one email address,
54- # but due to bug #33427, this isn't always the case.
55- return format_address(person.displayname,
56- "%s@%s" % (bug.id, config.launchpad.bugs_domain))
57-
58- # At this point we have no validated emails to use: if any of the
59- # person's emails had been validated the preferredemail would be
60- # set. Since we have no idea of which email address is best to use,
61- # we choose the first one.
62- return format_address(person.displayname, email_addresses[0].email)
63+ return format_address('Launchpad Bug Tracker', bug_address)
64+ else:
65+ return format_address(person.displayname, bug_address)
66
67
68 def get_bugmail_replyto_address(bug):
69
70=== modified file 'lib/lp/bugs/doc/bugnotification-email.txt'
71--- lib/lp/bugs/doc/bugnotification-email.txt 2010-04-14 12:55:44 +0000
72+++ lib/lp/bugs/doc/bugnotification-email.txt 2010-06-09 13:50:46 +0000
73@@ -31,7 +31,7 @@
74
75 >>> from zope.component import getUtility
76 >>> from canonical.launchpad.interfaces import (
77- ... IBugDelta, IBugSet, IEmailAddressSet, IPersonSet)
78+ ... IBugDelta, IBugSet, IPersonSet)
79 >>> from lp.bugs.adapters.bugdelta import BugDelta
80
81 = Filing a bug =
82@@ -432,41 +432,16 @@
83 >>> get_bugmail_replyto_address(bug_four)
84 u'Bug 4 <4@bugs.launchpad.net>'
85
86-The From address generator handles a few special cases. The trivial case
87-is, well, trivial. Stuart has four email addresses:
88+The From address generator uses the Person's full name but the bug's
89+email address. This avoids private addresses being leaked.
90
91 >>> stub = getUtility(IPersonSet).getByName("stub")
92- >>> [(email.email, email.status.name) for email
93- ... in getUtility(IEmailAddressSet).getByPerson(stub)]
94- [(u'stuart.bishop@canonical.com', 'PREFERRED'),
95- (u'stuart@stuartbishop.net', 'VALIDATED'),
96- (u'stub@fastmail.fm', 'NEW'),
97- (u'zen@shangri-la.dropbear.id.au', 'OLD')]
98-
99-But we use his preferred one:
100-
101 >>> get_bugmail_from_address(stub, bug_four)
102- 'Stuart Bishop <stuart.bishop@canonical.com>'
103-
104-Now, mpo doesn't have a validated email address, but we pick out the
105-first address we find:
106-
107- >>> mpo = getUtility(IPersonSet).getByName("mpo")
108- >>> get_bugmail_from_address(mpo, bug_four)
109- '=?utf-8?b?TWF0dGkgUMO2bGzDpA==?= <mpo@iki.fi>'
110-
111-(As you can see in the above example, get_bugmail_from_address() takes
112-care of encoding the person's displayname correctly.)
113-
114-The team janitor doesn't have an email address at all!
115-
116- >>> janitor = getUtility(IPersonSet).getByName("team-membership-janitor")
117- >>> get_bugmail_from_address(janitor, bug_four)
118- 'Team Membership Janitor <4@bugs.launchpad.net>'
119+ 'Stuart Bishop <4@bugs.launchpad.net>'
120
121 The Launchpad Janitor celebrity isn't a real user, and shouldn't be
122-sending mail. Notifications from the janitor are sent with the address
123-of the bug itself.
124+sending mail. Notifications from the janitor are sent as though from the
125+bug tracker itself.
126
127 >>> from canonical.launchpad.interfaces import ILaunchpadCelebrities
128 >>> lp_janitor = getUtility(ILaunchpadCelebrities).janitor
129@@ -498,8 +473,9 @@
130
131 The build() method of a builder accepts a number of parameters and
132 returns an instance of email.MIMEText. The most basic invokation of
133-this method requires a from address, a to address, a body, a subject
134-and a sending date for the mail.
135+this method requires a from address, a to address, a body, a subject,
136+a sending date for the mail and the Person object representing the
137+sender.
138
139 >>> from datetime import datetime
140 >>> import pytz
141@@ -510,7 +486,7 @@
142
143 >>> notification_email = bug_four_notification_builder.build(
144 ... from_address, 'foo.bar@canonical.com',
145- ... "A test body.", "A test subject.", sending_date)
146+ ... "A test body.", "A test subject.", sending_date, lp_janitor)
147
148 The fields of the generated notification email will be set according
149 to the parameters that were used to instantiate BugNotificationBuilder
150@@ -536,7 +512,7 @@
151
152 >>> notification_email = bug_four_notification_builder.build(
153 ... from_address, 'foo.bar@canonical.com',
154- ... "A test body.", "A test subject.", sending_date,
155+ ... "A test body.", "A test subject.", sending_date, lp_janitor,
156 ... rationale='Because-I-said-so',
157 ... references=['<12345@launchpad.net>'],
158 ... message_id='<67890@launchpad.net>')
159@@ -562,7 +538,8 @@
160
161 >>> notification_email = bug_four_notification_builder.build(
162 ... from_address, 'foo.bar@canonical.com',
163- ... "A test body.", "Yet another message", sending_date)
164+ ... "A test body.", "Yet another message", sending_date,
165+ ... lp_janitor)
166
167 >>> print notification_email['Subject']
168 [Bug 4] Yet another message
169@@ -572,7 +549,7 @@
170
171 >>> notification_email = bug_four_notification_builder.build(
172 ... from_address, 'foo.bar@canonical.com',
173- ... "A test body.", None, sending_date)
174+ ... "A test body.", None, sending_date, lp_janitor)
175
176 >>> print notification_email['Subject']
177 [Bug 4]
178
179=== modified file 'lib/lp/bugs/doc/bugnotification-sending.txt'
180--- lib/lp/bugs/doc/bugnotification-sending.txt 2010-06-03 12:32:45 +0000
181+++ lib/lp/bugs/doc/bugnotification-sending.txt 2010-06-09 13:50:46 +0000
182@@ -60,7 +60,7 @@
183 ... for message in messages:
184 ... print_notification(message)
185 To: foo.bar@canonical.com
186- From: Sample Person <test@canonical.com>
187+ From: Sample Person <1@bugs.launchpad.net>
188 Subject: [Bug 1] subject
189 X-Launchpad-Message-Rationale: Subscriber (mozilla-firefox in ubuntu)
190 <BLANKLINE>
191@@ -74,7 +74,7 @@
192 <BLANKLINE>
193 ----------------------------------------------------------------------
194 To: mark@example.com
195- From: Sample Person <test@canonical.com>
196+ From: Sample Person <1@bugs.launchpad.net>
197 Subject: [Bug 1] subject
198 X-Launchpad-Message-Rationale: Assignee
199 <BLANKLINE>
200@@ -87,7 +87,7 @@
201 <BLANKLINE>
202 ----------------------------------------------------------------------
203 To: support@ubuntu.com
204- From: Sample Person <test@canonical.com>
205+ From: Sample Person <1@bugs.launchpad.net>
206 Subject: [Bug 1] subject
207 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
208 <BLANKLINE>
209@@ -101,7 +101,7 @@
210 <BLANKLINE>
211 ----------------------------------------------------------------------
212 To: test@canonical.com
213- From: Sample Person <test@canonical.com>
214+ From: Sample Person <1@bugs.launchpad.net>
215 Subject: [Bug 1] subject
216 X-Launchpad-Message-Rationale: Subscriber
217 <BLANKLINE>
218@@ -172,7 +172,7 @@
219 To: mark@example.com
220 ...
221 To: support@ubuntu.com
222- From: Sample Person <test@canonical.com>
223+ From: Sample Person <1@bugs.launchpad.net>
224 Subject: Re: [Bug 1] subject
225 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
226 <BLANKLINE>
227@@ -212,7 +212,7 @@
228 To: mark@example.com
229 ...
230 To: support@ubuntu.com
231- From: Sample Person <test@canonical.com>
232+ From: Sample Person <1@bugs.launchpad.net>
233 Subject: [Bug 1] Re: Firefox does not support SVG
234 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
235 <BLANKLINE>
236@@ -260,7 +260,7 @@
237 To: mark@example.com
238 ...
239 To: support@ubuntu.com
240- From: Sample Person <test@canonical.com>
241+ From: Sample Person <1@bugs.launchpad.net>
242 Subject: [Bug 1] Re: Firefox does not support SVG
243 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
244 <BLANKLINE>
245@@ -303,7 +303,7 @@
246 To: mark@example.com
247 ...
248 To: support@ubuntu.com
249- From: Sample Person <test@canonical.com>
250+ From: Sample Person <1@bugs.launchpad.net>
251 Subject: [Bug 1] Re: Firefox does not support SVG
252 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
253 <BLANKLINE>
254@@ -331,7 +331,7 @@
255 To: mark@example.com
256 ...
257 To: support@ubuntu.com
258- From: Sample Person <test@canonical.com>
259+ From: Sample Person <1@bugs.launchpad.net>
260 Subject: [Bug 1] subject
261 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
262 <BLANKLINE>
263@@ -377,7 +377,7 @@
264 To: mark@example.com
265 ...
266 To: support@ubuntu.com
267- From: Sample Person <test@canonical.com>
268+ From: Sample Person <1@bugs.launchpad.net>
269 Subject: [Bug 1] subject
270 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
271 <BLANKLINE>
272@@ -397,7 +397,7 @@
273 To: mark@example.com
274 ...
275 To: support@ubuntu.com
276- From: Sample Person <test@canonical.com>
277+ From: Sample Person <1@bugs.launchpad.net>
278 Subject: [Bug 1] subject
279 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
280 <BLANKLINE>
281@@ -417,7 +417,7 @@
282 To: mark@example.com
283 ...
284 To: support@ubuntu.com
285- From: Sample Person <test@canonical.com>
286+ From: Sample Person <1@bugs.launchpad.net>
287 Subject: [Bug 1] subject
288 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
289 <BLANKLINE>
290@@ -465,7 +465,7 @@
291 To: mark@example.com
292 ...
293 To: support@ubuntu.com
294- From: Sample Person <test@canonical.com>
295+ From: Sample Person <1@bugs.launchpad.net>
296 Subject: [Bug 1] subject
297 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
298 <BLANKLINE>
299@@ -485,7 +485,7 @@
300 To: mark@example.com
301 ...
302 To: support@ubuntu.com
303- From: Foo Bar <foo.bar@canonical.com>
304+ From: Foo Bar <1@bugs.launchpad.net>
305 Subject: [Bug 1] Re: Firefox does not support SVG
306 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
307 <BLANKLINE>
308@@ -505,7 +505,7 @@
309 To: mark@example.com
310 ...
311 To: support@ubuntu.com
312- From: Sample Person <test@canonical.com>
313+ From: Sample Person <1@bugs.launchpad.net>
314 Subject: [Bug 1] Re: Firefox does not support SVG
315 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
316 <BLANKLINE>
317@@ -603,72 +603,72 @@
318 ... print_notification_headers(message)
319 ... print
320 To: mark@example.com
321- From: Sample Person <test@canonical.com>
322+ From: Sample Person <2@bugs.launchpad.net>
323 Subject: [Bug 2] Re: Blackhole Trash folder
324 X-Launchpad-Message-Rationale: Registrant (Debian)
325 <BLANKLINE>
326 To: support@ubuntu.com
327- From: Sample Person <test@canonical.com>
328+ From: Sample Person <2@bugs.launchpad.net>
329 Subject: [Bug 2] Re: Blackhole Trash folder
330 X-Launchpad-Message-Rationale: Registrant (Tomcat) @ubuntu-team
331 <BLANKLINE>
332 To: test@canonical.com
333- From: Sample Person <test@canonical.com>
334+ From: Sample Person <2@bugs.launchpad.net>
335 Subject: [Bug 2] Re: Blackhole Trash folder
336 X-Launchpad-Message-Rationale: Assignee
337 <BLANKLINE>
338 To: mark@example.com
339- From: Foo Bar <foo.bar@canonical.com>
340+ From: Foo Bar <2@bugs.launchpad.net>
341 Subject: [Bug 2] Re: Blackhole Trash folder
342 X-Launchpad-Message-Rationale: Registrant (Debian)
343 <BLANKLINE>
344 To: support@ubuntu.com
345- From: Foo Bar <foo.bar@canonical.com>
346+ From: Foo Bar <2@bugs.launchpad.net>
347 Subject: [Bug 2] Re: Blackhole Trash folder
348 X-Launchpad-Message-Rationale: Registrant (Tomcat) @ubuntu-team
349 <BLANKLINE>
350 To: test@canonical.com
351- From: Foo Bar <foo.bar@canonical.com>
352+ From: Foo Bar <2@bugs.launchpad.net>
353 Subject: [Bug 2] Re: Blackhole Trash folder
354 X-Launchpad-Message-Rationale: Assignee
355 <BLANKLINE>
356 To: foo.bar@canonical.com
357- From: Sample Person <test@canonical.com>
358+ From: Sample Person <1@bugs.launchpad.net>
359 Subject: [Bug 1] Re: Firefox does not support SVG
360 X-Launchpad-Message-Rationale: Subscriber (mozilla-firefox in ubuntu)
361 <BLANKLINE>
362 To: mark@example.com
363- From: Sample Person <test@canonical.com>
364+ From: Sample Person <1@bugs.launchpad.net>
365 Subject: [Bug 1] Re: Firefox does not support SVG
366 X-Launchpad-Message-Rationale: Assignee
367 <BLANKLINE>
368 To: support@ubuntu.com
369- From: Sample Person <test@canonical.com>
370+ From: Sample Person <1@bugs.launchpad.net>
371 Subject: [Bug 1] Re: Firefox does not support SVG
372 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
373 <BLANKLINE>
374 To: test@canonical.com
375- From: Sample Person <test@canonical.com>
376+ From: Sample Person <1@bugs.launchpad.net>
377 Subject: [Bug 1] Re: Firefox does not support SVG
378 X-Launchpad-Message-Rationale: Subscriber
379 <BLANKLINE>
380 To: foo.bar@canonical.com
381- From: Foo Bar <foo.bar@canonical.com>
382+ From: Foo Bar <1@bugs.launchpad.net>
383 Subject: [Bug 1] Re: Firefox does not support SVG
384 X-Launchpad-Message-Rationale: Subscriber (mozilla-firefox in ubuntu)
385 <BLANKLINE>
386 To: mark@example.com
387- From: Foo Bar <foo.bar@canonical.com>
388+ From: Foo Bar <1@bugs.launchpad.net>
389 Subject: [Bug 1] Re: Firefox does not support SVG
390 X-Launchpad-Message-Rationale: Assignee
391 <BLANKLINE>
392 To: support@ubuntu.com
393- From: Foo Bar <foo.bar@canonical.com>
394+ From: Foo Bar <1@bugs.launchpad.net>
395 Subject: [Bug 1] Re: Firefox does not support SVG
396 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
397 <BLANKLINE>
398 To: test@canonical.com
399- From: Foo Bar <foo.bar@canonical.com>
400+ From: Foo Bar <1@bugs.launchpad.net>
401 Subject: [Bug 1] Re: Firefox does not support SVG
402 X-Launchpad-Message-Rationale: Subscriber
403 <BLANKLINE>
404@@ -729,7 +729,8 @@
405 >>> flush_notifications()
406
407
408-== Duplicates ==
409+Duplicates
410+----------
411
412 We will need some helper functions.
413
414@@ -779,7 +780,7 @@
415 ... for message in messages:
416 ... print_notification(message)
417 To: support@ubuntu.com
418- From: Sample Person <test@canonical.com>
419+ From: Sample Person <16@bugs.launchpad.net>
420 Subject: [Bug 16] subject
421 X-Launchpad-Message-Rationale: Registrant (Ubuntu) @ubuntu-team
422 <BLANKLINE>
423@@ -796,7 +797,7 @@
424 <BLANKLINE>
425 ----------------------------------------------------------------------
426 To: test@canonical.com
427- From: Sample Person <test@canonical.com>
428+ From: Sample Person <16@bugs.launchpad.net>
429 Subject: [Bug 16] subject
430 X-Launchpad-Message-Rationale: Subscriber
431 <BLANKLINE>
432@@ -816,7 +817,8 @@
433 >>> flush_notifications()
434
435
436-== Security Vulnerabilities ==
437+Security Vulnerabilities
438+------------------------
439
440 When a new security related bug is filed, a small notification is
441 inserted at the top of the message body.
442@@ -844,7 +846,7 @@
443 ... for message in messages:
444 ... print_notification(message)
445 To: support@ubuntu.com
446- From: Sample Person <test@canonical.com>
447+ From: Sample Person <...@bugs.launchpad.net>
448 Subject: [Bug ...] [NEW] Zero-day on Frobulator
449 X-Launchpad-Message-Rationale: Subscriber @ubuntu-team
450 <BLANKLINE>
451@@ -868,7 +870,7 @@
452 ... for message in messages:
453 ... print_notification(message)
454 To: support@ubuntu.com
455- From: Sample Person <test@canonical.com>
456+ From: Sample Person <...@bugs.launchpad.net>
457 Subject: [Bug ...] subject
458 X-Launchpad-Message-Rationale: Subscriber @ubuntu-team
459 <BLANKLINE>
460@@ -879,7 +881,8 @@
461 >>> flush_notifications()
462
463
464-== The cronscript ==
465+The cronscript
466+--------------
467
468 There's a cronsript which does the sending of the email. Let's add a
469 few notifications to show that it works.
470@@ -937,7 +940,7 @@
471 ...
472 INFO Notifying test@canonical.com about bug 2.
473 ...
474- From: Sample Person <test@canonical.com>
475+ From: Sample Person <2@bugs.launchpad.net>
476 To: test@canonical.com
477 Reply-To: Bug 2 <2@bugs.launchpad.net>
478 ...
479@@ -947,7 +950,7 @@
480 ...
481 INFO Notifying foo.bar@canonical.com about bug 1.
482 ...
483- From: Sample Person <test@canonical.com>
484+ From: Sample Person <1@bugs.launchpad.net>
485 To: foo.bar@canonical.com
486 Reply-To: Bug 1 <1@bugs.launchpad.net>
487 ...
488@@ -965,13 +968,14 @@
489 ...
490 INFO Notifying foo.bar@canonical.com about bug 1.
491 ...
492- From: Sample Person <test@canonical.com>
493+ From: Sample Person <1@bugs.launchpad.net>
494 To: foo.bar@canonical.com
495 Reply-To: Bug 1 <1@bugs.launchpad.net>
496 ...
497 References: sdsdfsfd
498 ...
499 X-Launchpad-Message-Rationale: Subscriber (mozilla-firefox in ubuntu)
500+ X-Launchpad-Sender: name12
501 Errors-To: bounces@canonical.com
502 Return-Path: bounces@canonical.com
503 Precedence: bulk
504@@ -1000,7 +1004,8 @@
505 >>> flush_notifications()
506
507
508-== The X-Launchpad-Bug header ==
509+The X-Launchpad-Bug header
510+--------------------------
511
512 When a notification is sent out about a bug, the X-Launchpad-Bug header is
513 filled with data about that bug:
514@@ -1038,7 +1043,8 @@
515 False
516
517
518-== The X-Launchpad-Bug-Tags header ==
519+The X-Launchpad-Bug-Tags header
520+-------------------------------
521
522 First, a helper function that triggers notifications by adding a
523 comment to a given bug, another that returns a sorted list of new
524@@ -1103,7 +1109,8 @@
525 ... message.get_all('X-Launchpad-Bug-Tags')
526
527
528-== The X-Launchpad-Bug-Private header ==
529+The X-Launchpad-Bug-Private header
530+----------------------------------
531
532 When a notification is sent out about a bug, the
533 X-Launchpad-Bug-Private header shows if the bug is marked as
534@@ -1128,7 +1135,8 @@
535 mark@example.com ['yes']
536
537
538-== The X-Launchpad-Bug-Security-Vulnerability header ==
539+The X-Launchpad-Bug-Security-Vulnerability header
540+-------------------------------------------------
541
542 When a notification is sent out about a bug, the
543 X-Launchpad-Bug-Security-Vulnerability header records if the bug is a
544@@ -1156,7 +1164,8 @@
545 mark@example.com ['yes']
546
547
548-== The X-Launchpad-Bug-Commenters header ==
549+The X-Launchpad-Bug-Commenters header
550+-------------------------------------
551
552 The X-Launchpad-Bug-Recipient-Commented header lists all user IDs of
553 people who have ever commented on the bug. It's a space-separated
554@@ -1187,7 +1196,8 @@
555 name12 name16
556
557
558-== Verbose bug notifications ==
559+Verbose bug notifications
560+-------------------------
561
562 It is possible for users to have all the bug notifications which they
563 receive include the bug description and status. This helps in those
564@@ -1301,7 +1311,7 @@
565
566 >>> print_notification(collated_messages['concise@example.com'][0])
567 To: concise@example.com
568- From: Verbose Person <verbose@example.com>
569+ From: Verbose Person <...@bugs.launchpad.net>
570 Subject: [Bug ...] subject
571 X-Launchpad-Message-Rationale: Subscriber
572 <BLANKLINE>
573@@ -1320,7 +1330,7 @@
574
575 >>> print_notification(collated_messages['verboseteam@example.com'][0])
576 To: verboseteam@example.com
577- From: Verbose Person <verbose@example.com>
578+ From: Verbose Person <...@bugs.launchpad.net>
579 Subject: [Bug ...] subject
580 X-Launchpad-Message-Rationale: Subscriber @verboseteam
581 <BLANKLINE>
582@@ -1338,7 +1348,7 @@
583
584 >>> print_notification(collated_messages['verbose@example.com'][0])
585 To: verbose@example.com
586- From: Verbose Person <verbose@example.com>
587+ From: Verbose Person <...@bugs.launchpad.net>
588 Subject: [Bug ...] subject
589 X-Launchpad-Message-Rationale: Subscriber
590 <BLANKLINE>
591@@ -1364,7 +1374,7 @@
592
593 >>> print_notification(collated_messages['conciseteam@example.com'][0])
594 To: conciseteam@example.com
595- From: Verbose Person <verbose@example.com>
596+ From: Verbose Person <...@bugs.launchpad.net>
597 Subject: [Bug ...] subject
598 X-Launchpad-Message-Rationale: Subscriber @conciseteam
599 <BLANKLINE>
600@@ -1383,7 +1393,8 @@
601 <BLANKLINE>
602 ----------------------------------------------------------------------
603
604-== Notification Recipients ==
605+Notification Recipients
606+-----------------------
607
608 Bug notifications are sent to direct subscribers of a bug as well as to
609 structural subscribers. Structural subcribers can select the
610@@ -1437,7 +1448,7 @@
611 <BLANKLINE>
612 ----------------------------------------------------------------------
613 To: no-priv@canonical.com
614- From: Sample Person <test@canonical.com>
615+ From: Sample Person <1@bugs.launchpad.net>
616 Subject: [Bug 1] subject
617 X-Launchpad-Message-Rationale: Subscriber (Mozilla Firefox)
618 <BLANKLINE>
619@@ -1489,7 +1500,7 @@
620 <BLANKLINE>
621 ----------------------------------------------------------------------
622 To: marilize@hbd.com
623- From: Sample Person <test@canonical.com>
624+ From: Sample Person <1@bugs.launchpad.net>
625 Subject: [Bug 1] subject
626 X-Launchpad-Message-Rationale: Subscriber @shipit-admins
627 <BLANKLINE>
628@@ -1551,7 +1562,7 @@
629 <BLANKLINE>
630 ----------------------------------------------------------------------
631 To: no-priv@canonical.com
632- From: Sample Person <test@canonical.com>
633+ From: Sample Person <1@bugs.launchpad.net>
634 Subject: [Bug 1] subject
635 X-Launchpad-Message-Rationale: Subscriber (Mozilla Firefox)
636 <BLANKLINE>
637@@ -1603,7 +1614,7 @@
638 <BLANKLINE>
639 ----------------------------------------------------------------------
640 To: marilize@hbd.com
641- From: Sample Person <test@canonical.com>
642+ From: Sample Person <1@bugs.launchpad.net>
643 Subject: [Bug 1] Re: Firefox does not support SVG
644 X-Launchpad-Message-Rationale: Subscriber @shipit-admins
645 <BLANKLINE>
646
647=== modified file 'lib/lp/bugs/scripts/bugnotification.py'
648--- lib/lp/bugs/scripts/bugnotification.py 2009-11-17 17:33:28 +0000
649+++ lib/lp/bugs/scripts/bugnotification.py 2010-06-09 13:50:46 +0000
650@@ -155,7 +155,7 @@
651
652 body = get_email_template(email_template) % body_data
653 msg = bug_notification_builder.build(
654- from_address, address, body, subject, email_date,
655+ from_address, address, body, subject, email_date, person,
656 rationale, references, msgid)
657 messages.append(msg)
658
659
660=== modified file 'lib/lp/bugs/tests/test_bugnotification.py'
661--- lib/lp/bugs/tests/test_bugnotification.py 2010-06-03 13:53:29 +0000
662+++ lib/lp/bugs/tests/test_bugnotification.py 2010-06-09 13:50:46 +0000
663@@ -16,6 +16,8 @@
664 from canonical.config import config
665 from canonical.launchpad.database.message import MessageSet
666 from canonical.launchpad.ftests import login
667+from canonical.launchpad.mailnotification import (
668+ BugNotificationBuilder, get_bugmail_from_address)
669 from lp.bugs.interfaces.bugtask import BugTaskStatus, IUpstreamBugTask
670 from lp.bugs.model.bugnotification import BugNotification, BugNotificationSet
671 from lp.testing import TestCaseWithFactory
672@@ -200,6 +202,54 @@
673 self.assertEqual(self.dupe_subscribers, recipients)
674
675
676+class TestBugNotificationEmailHeaders(TestCaseWithFactory):
677+ """Tests for X-Launchpad bugnotification headers."""
678+
679+ layer = DatabaseFunctionalLayer
680+
681+ def setUp(self):
682+ super(TestBugNotificationEmailHeaders, self).setUp(
683+ user='test@canonical.com')
684+ self.bug = self.factory.makeBug()
685+
686+ def _buildBugNotificationEmail(self, bug_notification, rationale=None,
687+ references=None, message_id=None):
688+ """Build a notification email based on a BugNotification instance."""
689+ from_address = get_bugmail_from_address(
690+ bug_notification.message.owner, bug_notification.bug)
691+ to_address = 'test@canonical.com'
692+ body = bug_notification.message.text_contents
693+ subject = bug_notification.message.subject
694+ email_date = bug_notification.message.datecreated
695+ sender = bug_notification.message.owner
696+
697+ builder = BugNotificationBuilder(bug_notification.bug)
698+ return builder.build(
699+ from_address, to_address, body, subject, email_date, sender,
700+ rationale, references, message_id)
701+
702+ def test_x_launchpad_sender(self):
703+ # Bug notifications include a header, X-Launchpad-Sender, which
704+ # is set to the name of the Person who triggered the
705+ # notification.
706+ self.bug.newMessage(
707+ self.bug.owner, subject='subject', content='content')
708+
709+ latest_notification = BugNotification.selectFirst(orderBy='-id')
710+ notification_email = self._buildBugNotificationEmail(
711+ latest_notification)
712+
713+ self.assertTrue(
714+ 'X-Launchpad-Sender' in notification_email,
715+ "Notification email does not include an X-Launchpad-Sender "
716+ "header")
717+ self.assertEqual(
718+ self.bug.owner.name, notification_email['X-Launchpad-Sender'],
719+ "X-Launchpad-Sender does not match expected value. Expected "
720+ "'%s', found '%s'" %
721+ (self.bug.owner.name, notification_email['X-Launchpad-Sender']))
722+
723+
724 def test_suite():
725 """Return the test suite for the tests in this module."""
726 return unittest.TestLoader().loadTestsFromName(__name__)