Skip to content

Commit c577ede

Browse files
author
Johannes Gijsbers
committed
Change nosymessage and send_message to accept msgid=None (RFE [SF#707235]).
1 parent bd42a27 commit c577ede

File tree

2 files changed

+77
-86
lines changed

2 files changed

+77
-86
lines changed

CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Feature:
88
- using Zope3's test runner now, allowing GC checks, nicer controls and
99
coverage analysis
1010
- !BETA! added postgresql backend, needs work !BETA!
11-
- all RDMBS backends now have indexes on several columns
11+
- all RDBMS backends now have indexes on several columns
12+
- Change nosymessage and send_message to accept msgid=None (RFE #707235).
1213

1314
Fixed:
1415
- mysql documentation fixed to note requirement of 4.0+ and InnoDB

roundup/roundupdb.py

Lines changed: 75 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: roundupdb.py,v 1.92 2003-10-04 11:21:47 jlgijsbers Exp $
18+
# $Id: roundupdb.py,v 1.93 2003-11-06 19:01:57 jlgijsbers Exp $
1919

2020
__doc__ = """
2121
Extending hyperdb with types specific to issue-tracking.
2222
"""
23+
from __future__ import nested_scopes
2324

2425
import re, os, smtplib, socket, time, random
2526
import cStringIO, base64, quopri, mimetypes
@@ -129,75 +130,56 @@ def nosymessage(self, nodeid, msgid, oldvalues, whichnosy='nosy',
129130
130131
These users are then added to the message's "recipients" list.
131132
133+
If 'msgid' is None, the message gets sent only to the nosy
134+
list, and it's called a 'System Message'.
132135
"""
133-
users = self.db.user
134-
messages = self.db.msg
135-
136-
# figure the recipient ids
136+
authid, recipients = None, []
137+
if msgid:
138+
authid = self.db.msg.get(msgid, 'author')
139+
recipients = self.db.msg.get(msgid, 'recipients')
140+
137141
sendto = []
138-
r = {}
139-
recipients = messages.get(msgid, 'recipients')
140-
for recipid in messages.get(msgid, 'recipients'):
141-
r[recipid] = 1
142-
143-
# figure the author's id, and indicate they've received the message
144-
authid = messages.get(msgid, 'author')
145-
142+
seen_message = dict([(recipient, 1) for recipient in recipients])
143+
144+
def add_recipient(userid):
145+
# make sure they have an address
146+
address = self.db.user.get(userid, 'address')
147+
if address:
148+
sendto.append(address)
149+
recipients.append(userid)
150+
151+
def good_recipient(userid):
152+
# Make sure we don't send mail to either the anonymous
153+
# user or a user who has already seen the message.
154+
return (userid and
155+
self.db.user.get(userid, 'username') != 'anonymous' and
156+
not seen_message.has_key(userid))
157+
146158
# possibly send the message to the author, as long as they aren't
147159
# anonymous
148-
if (users.get(authid, 'username') != 'anonymous' and
149-
not r.has_key(authid)):
150-
if (self.db.config.MESSAGES_TO_AUTHOR == 'yes' or
151-
(self.db.config.MESSAGES_TO_AUTHOR == 'new' and not oldvalues)):
152-
# make sure they have an address
153-
add = users.get(authid, 'address')
154-
if add:
155-
# send it to them
156-
sendto.append(add)
157-
recipients.append(authid)
158-
159-
r[authid] = 1
160-
161-
# now deal with cc people.
162-
for cc_userid in cc :
163-
if r.has_key(cc_userid):
164-
continue
165-
# make sure they have an address
166-
add = users.get(cc_userid, 'address')
167-
if add:
168-
# send it to them
169-
sendto.append(add)
170-
recipients.append(cc_userid)
171-
172-
# now figure the nosy people who weren't recipients
173-
nosy = self.get(nodeid, whichnosy)
174-
for nosyid in nosy:
175-
# Don't send nosy mail to the anonymous user (that user
176-
# shouldn't appear in the nosy list, but just in case they
177-
# do...)
178-
if users.get(nosyid, 'username') == 'anonymous':
179-
continue
180-
# make sure they haven't seen the message already
181-
if not r.has_key(nosyid):
182-
# make sure they have an address
183-
add = users.get(nosyid, 'address')
184-
if add:
185-
# send it to them
186-
sendto.append(add)
187-
recipients.append(nosyid)
188-
189-
# generate a change note
160+
if (good_recipient(authid) and
161+
(self.db.config.MESSAGES_TO_AUTHOR == 'yes' or
162+
(self.db.config.MESSAGES_TO_AUTHOR == 'new' and not oldvalues))):
163+
add_recipient(authid)
164+
165+
if authid:
166+
seen_message[authid] = 1
167+
168+
# now deal with the nosy and cc people who weren't recipients.
169+
for userid in cc + self.get(nodeid, whichnosy):
170+
if good_recipient(userid):
171+
add_recipient(userid)
172+
190173
if oldvalues:
191174
note = self.generateChangeNote(nodeid, oldvalues)
192175
else:
193176
note = self.generateCreateNote(nodeid)
194177

195-
# we have new recipients
178+
# If we have new recipients, update the message's recipients
179+
# and send the mail.
196180
if sendto:
197-
# update the message's recipients list
198-
messages.set(msgid, recipients=recipients)
199-
200-
# send the message
181+
if msgid:
182+
self.db.msg.set(msgid, recipients=recipients)
201183
self.send_message(nodeid, msgid, note, sendto, from_address)
202184

203185
# backwards compatibility - don't remove
@@ -211,31 +193,35 @@ def send_message(self, nodeid, msgid, note, sendto, from_address=None):
211193
messages = self.db.msg
212194
files = self.db.file
213195

214-
# determine the messageid and inreplyto of the message
215-
inreplyto = messages.get(msgid, 'inreplyto')
216-
messageid = messages.get(msgid, 'messageid')
196+
inreplyto, messageid = None, None
197+
if msgid:
198+
inreplyto = messages.get(msgid, 'inreplyto')
199+
messageid = messages.get(msgid, 'messageid')
217200

218-
# make up a messageid if there isn't one (web edit)
219-
if not messageid:
220-
# this is an old message that didn't get a messageid, so
221-
# create one
222-
messageid = "<%s.%s.%s%s@%s>"%(time.time(), random.random(),
223-
self.classname, nodeid, self.db.config.MAIL_DOMAIN)
224-
messages.set(msgid, messageid=messageid)
201+
# make up a messageid if there isn't one (web edit)
202+
if not messageid:
203+
# this is an old message that didn't get a messageid, so
204+
# create one
205+
messageid = "<%s.%s.%s%s@%s>"%(time.time(), random.random(),
206+
self.classname, nodeid,
207+
self.db.config.MAIL_DOMAIN)
208+
messages.set(msgid, messageid=messageid)
225209

226210
# send an email to the people who missed out
227211
cn = self.classname
228212
title = self.get(nodeid, 'title') or '%s message copy'%cn
229-
# figure author information
230-
authid = messages.get(msgid, 'author')
231-
authname = users.get(authid, 'realname')
232-
if not authname:
233-
authname = users.get(authid, 'username')
234-
authaddr = users.get(authid, 'address')
235-
if authaddr:
236-
authaddr = " <%s>" % straddr( ('',authaddr) )
237-
else:
238-
authaddr = ''
213+
214+
authid, authname, authaddr = None, '', ''
215+
if msgid:
216+
authid = messages.get(msgid, 'author')
217+
authname = users.get(authid, 'realname')
218+
if not authname:
219+
authname = users.get(authid, 'username')
220+
authaddr = users.get(authid, 'address')
221+
if authaddr:
222+
authaddr = " <%s>" % straddr( ('',authaddr) )
223+
else:
224+
authaddr = ''
239225

240226
# make the message body
241227
m = ['']
@@ -245,14 +231,18 @@ def send_message(self, nodeid, msgid, note, sendto, from_address=None):
245231
m.append(self.email_signature(nodeid, msgid))
246232

247233
# add author information
248-
if len(self.get(nodeid,'messages')) == 1:
249-
m.append("New submission from %s%s:"%(authname, authaddr))
234+
if authid:
235+
if len(self.get(nodeid,'messages')) == 1:
236+
m.append("New submission from %s%s:"%(authname, authaddr))
237+
else:
238+
m.append("%s%s added the comment:"%(authname, authaddr))
250239
else:
251-
m.append("%s%s added the comment:"%(authname, authaddr))
240+
m.append("System message:")
252241
m.append('')
253242

254243
# add the content
255-
m.append(messages.get(msgid, 'content'))
244+
if msgid:
245+
m.append(messages.get(msgid, 'content'))
256246

257247
# add the change note
258248
if note:
@@ -269,7 +259,7 @@ def send_message(self, nodeid, msgid, note, sendto, from_address=None):
269259
content_encoded = content_encoded.getvalue()
270260

271261
# get the files for this message
272-
message_files = messages.get(msgid, 'files')
262+
message_files = msgid and messages.get(msgid, 'files') or None
273263

274264
# make sure the To line is always the same (for testing mostly)
275265
sendto.sort()

0 commit comments

Comments
 (0)