comparison roundup/roundupdb.py @ 1360:aa7e4e8b14be

allow additional control over the roundupdb email sending... ...explicit cc addresses, different from address and different nosy list property. (thanks John Rouillard)
author Richard Jones <richard@users.sourceforge.net>
date Sun, 12 Jan 2003 00:41:27 +0000
parents b1f86cc82d33
children 98ec0c4ce7ab
comparison
equal deleted inserted replaced
1359:ebfd8dd1cce7 1360:aa7e4e8b14be
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
18 # $Id: roundupdb.py,v 1.75 2002-12-11 01:52:20 richard Exp $ 18 # $Id: roundupdb.py,v 1.76 2003-01-12 00:41:26 richard Exp $
19 19
20 __doc__ = """ 20 __doc__ = """
21 Extending hyperdb with types specific to issue-tracking. 21 Extending hyperdb with types specific to issue-tracking.
22 """ 22 """
23 23
85 85
86 The given text is saved as the body of the message and the node is 86 The given text is saved as the body of the message and the node is
87 appended to the "messages" field of the specified issue. 87 appended to the "messages" field of the specified issue.
88 """ 88 """
89 89
90 def nosymessage(self, nodeid, msgid, oldvalues): 90 def nosymessage(self, nodeid, msgid, oldvalues, whichnosy='nosy',
91 from_address=[], cc=[], bcc=[]):
91 """Send a message to the members of an issue's nosy list. 92 """Send a message to the members of an issue's nosy list.
92 93
93 The message is sent only to users on the nosy list who are not 94 The message is sent only to users on the nosy list who are not
94 already on the "recipients" list for the message. 95 already on the "recipients" list for the message.
95 96
113 if (self.db.config.MESSAGES_TO_AUTHOR == 'yes' and 114 if (self.db.config.MESSAGES_TO_AUTHOR == 'yes' and
114 users.get(authid, 'username') != 'anonymous'): 115 users.get(authid, 'username') != 'anonymous'):
115 sendto.append(authid) 116 sendto.append(authid)
116 r[authid] = 1 117 r[authid] = 1
117 118
119 # now deal with cc people.
120 for cc_userid in cc :
121 if r.has_key(cc_userid):
122 continue
123 # send it to them
124 sendto.append(cc_userid)
125 recipients.append(cc_userid)
126
118 # now figure the nosy people who weren't recipients 127 # now figure the nosy people who weren't recipients
119 nosy = self.get(nodeid, 'nosy') 128 nosy = self.get(nodeid, whichnosy)
120 for nosyid in nosy: 129 for nosyid in nosy:
121 # Don't send nosy mail to the anonymous user (that user 130 # Don't send nosy mail to the anonymous user (that user
122 # shouldn't appear in the nosy list, but just in case they 131 # shouldn't appear in the nosy list, but just in case they
123 # do...) 132 # do...)
124 if users.get(nosyid, 'username') == 'anonymous': 133 if users.get(nosyid, 'username') == 'anonymous':
142 151
143 # update the message's recipients list 152 # update the message's recipients list
144 messages.set(msgid, recipients=recipients) 153 messages.set(msgid, recipients=recipients)
145 154
146 # send the message 155 # send the message
147 self.send_message(nodeid, msgid, note, sendto) 156 self.send_message(nodeid, msgid, note, sendto, from_address)
148 157
149 # backwards compatibility - don't remove 158 # backwards compatibility - don't remove
150 sendmessage = nosymessage 159 sendmessage = nosymessage
151 160
152 def send_message(self, nodeid, msgid, note, sendto): 161 def send_message(self, nodeid, msgid, note, sendto, from_address=None):
153 '''Actually send the nominated message from this node to the sendto 162 '''Actually send the nominated message from this node to the sendto
154 recipients, with the note appended. 163 recipients, with the note appended.
155 ''' 164 '''
156 users = self.db.user 165 users = self.db.user
157 messages = self.db.msg 166 messages = self.db.msg
218 message_files = messages.get(msgid, 'files') 227 message_files = messages.get(msgid, 'files')
219 228
220 # make sure the To line is always the same (for testing mostly) 229 # make sure the To line is always the same (for testing mostly)
221 sendto.sort() 230 sendto.sort()
222 231
232 # make sure we have a from address
233 if from_address is None:
234 from_address = self.db.config.TRACKER_EMAIL
235
236 # additional bit for after the From: "name"
237 from_tag = getattr(self.db.config, 'EMAIL_FROM_TAG', '')
238 if from_tag:
239 from_tag = ' ' + from_tag
240
223 # create the message 241 # create the message
224 message = cStringIO.StringIO() 242 message = cStringIO.StringIO()
225 writer = MimeWriter.MimeWriter(message) 243 writer = MimeWriter.MimeWriter(message)
226 writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid, title)) 244 writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid, title))
227 writer.addheader('To', ', '.join(sendto)) 245 writer.addheader('To', ', '.join(sendto))
228 writer.addheader('From', straddr( 246 writer.addheader('From', straddr((authname + from_tag, from_address)))
229 (authname, self.db.config.TRACKER_EMAIL) ) ) 247 writer.addheader('Reply-To', straddr((self.db.config.TRACKER_NAME,
230 writer.addheader('Reply-To', straddr( 248 from_address)))
231 (self.db.config.TRACKER_NAME,
232 self.db.config.TRACKER_EMAIL) ) )
233 writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000", 249 writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000",
234 time.gmtime())) 250 time.gmtime()))
235 writer.addheader('MIME-Version', '1.0') 251 writer.addheader('MIME-Version', '1.0')
236 if messageid: 252 if messageid:
237 writer.addheader('Message-Id', messageid) 253 writer.addheader('Message-Id', messageid)
280 body = writer.startbody('text/plain') 296 body = writer.startbody('text/plain')
281 body.write(content_encoded) 297 body.write(content_encoded)
282 298
283 # now try to send the message 299 # now try to send the message
284 if SENDMAILDEBUG: 300 if SENDMAILDEBUG:
285 open(SENDMAILDEBUG, 'w').write('FROM: %s\nTO: %s\n%s\n'%( 301 open(SENDMAILDEBUG, 'a').write('FROM: %s\nTO: %s\n%s\n'%(
286 self.db.config.ADMIN_EMAIL, 302 self.db.config.ADMIN_EMAIL,
287 ', '.join(sendto),message.getvalue())) 303 ', '.join(sendto),message.getvalue()))
288 else: 304 else:
289 try: 305 try:
290 # send the message as admin so bounces are sent there 306 # send the message as admin so bounces are sent there

Roundup Issue Tracker: http://roundup-tracker.org/