1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
Bug Notification Threading
==========================
In order to make the notifications more usable, all notifications
related to a specific bug have their headers set so that they will be
grouped together by an email client that handles threading correctly.
Comments added by the web UI won't be correctly threaded, though, since
you can't know to which comment the new comment was a reply to.
Let's add add change notification and see how it works:
>>> from canonical.database.sqlbase import flush_database_updates
>>> from lp.services.messages.model.message import MessageSet
>>> login('test@canonical.com')
>>> import pytz
>>> from datetime import datetime, timedelta
>>> from lp.services.messages.interfaces.message import IMessageSet
>>> from lp.bugs.interfaces.bug import IBugSet
>>> from lp.bugs.adapters.bugchange import BugVisibilityChange
>>> ten_minutes_ago = (
... datetime.now(pytz.timezone('UTC')) - timedelta(minutes=10))
>>> sample_person = getUtility(ILaunchBag).user
>>> bug_one = getUtility(IBugSet).get(1)
>>> bug_one.addChange(
... BugVisibilityChange(
... ten_minutes_ago, sample_person, "private",
... False, True))
>>> from lp.bugs.interfaces.bugnotification import IBugNotificationSet
>>> from lp.bugs.scripts.bugnotification import (
... get_email_notifications)
>>> notifications = getUtility(
... IBugNotificationSet).getNotificationsToSend()
>>> messages = [emails for notifications, omitted, emails in
... get_email_notifications(notifications)]
>>> len(messages)
1
There are four recipients for this message, so we get:
>>> emails = messages[0]
>>> len(emails)
4
The three emails have identical headers for our purposes, so:
>>> notification = emails[0]
The email has the message id of the change notification, and it
references the bug's initial message, so that it will be threaded in
an email client.
>>> notification['Message-Id'] == notifications[0].message.rfc822msgid
True
>>> notification['References'] == bug_one.initial_message.rfc822msgid
True
If we add a comment, the notification will have the comment's message
id:
>>> comment = getUtility(IMessageSet).fromText(
... 'subject', 'comment', sample_person, datecreated=ten_minutes_ago)
>>> bug_one.addCommentNotification(comment)
>>> bug_one.linkMessage(comment)
<...>
>>> bug_one.addChange(
... BugVisibilityChange(
... ten_minutes_ago, sample_person, "private",
... True, False))
>>> notifications = getUtility(
... IBugNotificationSet).getNotificationsToSend()
>>> messages = [emails for notifications, omitted, emails in
... get_email_notifications(notifications)]
>>> len(messages)
1
>>> emails = messages[0]
>>> len(emails)
4
>>> notification = emails[0]
>>> notification['Message-Id'] == comment.rfc822msgid
True
>>> notification['References'] == bug_one.initial_message.rfc822msgid
True
Refresh the dates, and create a new reply to ensure that the references
are chained together properly:
>>> for notification in notifications:
... notification.date_emailed = datetime.now(pytz.timezone('UTC'))
>>> flush_database_updates()
>>> reply = MessageSet().fromText(
... 'Re: subject', 'reply', sample_person,
... datecreated=ten_minutes_ago)
>>> reply.parent = comment
>>> bug_one.addCommentNotification(reply)
>>> bug_one.linkMessage(reply)
<...>
Grab the notifications:
>>> notifications = getUtility(
... IBugNotificationSet).getNotificationsToSend()
>>> messages = [emails for notifications, omitted, emails in
... get_email_notifications(notifications)]
>>> len(messages)
1
>>> emails = messages[0]
>>> len(emails)
4
>>> notification = emails[0]
>>> notification['Message-Id'] == reply.rfc822msgid
True
>>> references = notification['References'].split()
>>> bug_one.initial_message.rfc822msgid in references
True
>>> comment.rfc822msgid in references
True
|