1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: roundupdb.py,v 1.16 2001-10-30 00:54:45 richard Exp $
18+ # $Id: roundupdb.py,v 1.17 2001-11-12 22:01:06 richard Exp $
1919
2020import re , os , smtplib , socket
2121
@@ -31,6 +31,7 @@ def splitDesignator(designator, dre=re.compile(r'([^\d]+)(\d+)')):
3131 raise DesignatorError , '"%s" not a node designator' % designator
3232 return m .group (1 ), m .group (2 )
3333
34+
3435class Database :
3536 def getuid (self ):
3637 """Return the id of the "user" node associated with the user
@@ -214,6 +215,12 @@ def getprops(self, protected=1):
214215 d ['content' ] = hyperdb .String ()
215216 return d
216217
218+ class MessageSendError (RuntimeError ):
219+ pass
220+
221+ class DetectorError (RuntimeError ):
222+ pass
223+
217224# XXX deviation from spec - was called ItemClass
218225class IssueClass (Class ):
219226 # configuration
@@ -266,17 +273,18 @@ def sendmessage(self, nodeid, msgid):
266273 r = {}
267274 for recipid in recipients :
268275 r [recipid ] = 1
276+ rlen = len (recipients )
269277
270278 # figure the author's id, and indicate they've received the message
271279 authid = self .db .msg .get (msgid , 'author' )
272- r [authid ] = 1
273280
274- sendto = []
275281 # ... but duplicate the message to the author as long as it's not
276282 # the anonymous user
277283 if (self .MESSAGES_TO_AUTHOR == 'yes' and
278284 self .db .user .get (authid , 'username' ) != 'anonymous' ):
279- sendto .append (authid )
285+ if not r .has_key (authid ):
286+ recipients .append (authid )
287+ r [authid ] = 1
280288
281289 # now figure the nosy people who weren't recipients
282290 nosy = self .get (nodeid , 'nosy' )
@@ -286,46 +294,50 @@ def sendmessage(self, nodeid, msgid):
286294 # do...)
287295 if self .db .user .get (nosyid , 'username' ) == 'anonymous' : continue
288296 if not r .has_key (nosyid ):
289- sendto .append (nosyid )
290297 recipients .append (nosyid )
291298
292- if sendto :
293- # update the message's recipients list
294- self .db .msg .set (msgid , recipients = recipients )
295-
296- # send an email to the people who missed out
297- sendto = [self .db .user .get (i , 'address' ) for i in recipients ]
298- cn = self .classname
299- title = self .get (nodeid , 'title' ) or '%s message copy' % cn
300- # figure author information
301- authname = self .db .user .get (authid , 'realname' )
302- if not authname :
303- authname = self .db .user .get (authid , 'username' )
304- authaddr = self .db .user .get (authid , 'address' )
305- if authaddr :
306- authaddr = '<%s> ' % authaddr
307- else :
308- authaddr = ''
309- # TODO attachments
310- m = ['Subject: [%s%s] %s' % (cn , nodeid , title )]
311- m .append ('To: %s' % ', ' .join (sendto ))
312- m .append ('From: %s' % self .ISSUE_TRACKER_EMAIL )
313- m .append ('Reply-To: %s' % self .ISSUE_TRACKER_EMAIL )
314- m .append ('' )
315- # add author information
316- m .append ("%s %sadded the comment:" % (authname , authaddr ))
317- m .append ('' )
318- # add the content
319- m .append (self .db .msg .get (msgid , 'content' ))
320- # "list information" footer
321- m .append (self .email_footer (nodeid , msgid ))
322- try :
323- smtp = smtplib .SMTP (self .MAILHOST )
324- smtp .sendmail (self .ISSUE_TRACKER_EMAIL , sendto , '\n ' .join (m ))
325- except socket .error , value :
326- return "Couldn't send confirmation email: mailhost %s" % value
327- except smtplib .SMTPException , value :
328- return "Couldn't send confirmation email: %s" % value
299+ # no new recipients
300+ if rlen == len (recipients ):
301+ return
302+
303+ # update the message's recipients list
304+ self .db .msg .set (msgid , recipients = recipients )
305+
306+ # send an email to the people who missed out
307+ sendto = [self .db .user .get (i , 'address' ) for i in recipients ]
308+ cn = self .classname
309+ title = self .get (nodeid , 'title' ) or '%s message copy' % cn
310+ # figure author information
311+ authname = self .db .user .get (authid , 'realname' )
312+ if not authname :
313+ authname = self .db .user .get (authid , 'username' )
314+ authaddr = self .db .user .get (authid , 'address' )
315+ if authaddr :
316+ authaddr = '<%s> ' % authaddr
317+ else :
318+ authaddr = ''
319+ # TODO attachments
320+ m = ['Subject: [%s%s] %s' % (cn , nodeid , title )]
321+ m .append ('To: %s' % ', ' .join (sendto ))
322+ m .append ('From: %s' % self .ISSUE_TRACKER_EMAIL )
323+ m .append ('Reply-To: %s' % self .ISSUE_TRACKER_EMAIL )
324+ m .append ('' )
325+ # add author information
326+ m .append ("%s %sadded the comment:" % (authname , authaddr ))
327+ m .append ('' )
328+ # add the content
329+ m .append (self .db .msg .get (msgid , 'content' ))
330+ # "list information" footer
331+ m .append (self .email_footer (nodeid , msgid ))
332+ try :
333+ smtp = smtplib .SMTP (self .MAILHOST )
334+ smtp .sendmail (self .ISSUE_TRACKER_EMAIL , sendto , '\n ' .join (m ))
335+ except socket .error , value :
336+ raise MessageSendError , \
337+ "Couldn't send confirmation email: mailhost %s" % value
338+ except smtplib .SMTPException , value :
339+ raise MessageSendError , \
340+ "Couldn't send confirmation email: %s" % value
329341
330342 def email_footer (self , nodeid , msgid ):
331343 ''' Add a footer to the e-mail with some useful information
@@ -339,6 +351,12 @@ def email_footer(self, nodeid, msgid):
339351
340352#
341353# $Log: not supported by cvs2svn $
354+ # Revision 1.16 2001/10/30 00:54:45 richard
355+ # Features:
356+ # . #467129 ] Lossage when username=e-mail-address
357+ # . #473123 ] Change message generation for author
358+ # . MailGW now moves 'resolved' to 'chatting' on receiving e-mail for an issue.
359+ #
342360# Revision 1.15 2001/10/23 01:00:18 richard
343361# Re-enabled login and registration access after lopping them off via
344362# disabling access for anonymous users.
0 commit comments