comparison roundup/roundupdb.py @ 2058:e7191f6d8db6 maint-0.6

more complete fix for email charset
author Richard Jones <richard@users.sourceforge.net>
date Sat, 28 Feb 2004 22:53:16 +0000
parents 1d86402ce5e8
children f4550f7f93cb
comparison
equal deleted inserted replaced
2057:d26e577f8a85 2058:e7191f6d8db6
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.86.2.2 2004-02-23 05:37:11 richard Exp $ 18 # $Id: roundupdb.py,v 1.86.2.3 2004-02-28 22:53:16 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
207 # create one 207 # create one
208 messageid = "<%s.%s.%s%s@%s>"%(time.time(), random.random(), 208 messageid = "<%s.%s.%s%s@%s>"%(time.time(), random.random(),
209 self.classname, nodeid, self.db.config.MAIL_DOMAIN) 209 self.classname, nodeid, self.db.config.MAIL_DOMAIN)
210 messages.set(msgid, messageid=messageid) 210 messages.set(msgid, messageid=messageid)
211 211
212 # send an email to the people who missed out 212 # character set to encode the email with
213 charset = getattr(self.db.config, 'EMAIL_CHARSET', 'utf-8')
214
215 # title for the message
213 cn = self.classname 216 cn = self.classname
214 title = self.get(nodeid, 'title') or '%s message copy'%cn 217 title = self.get(nodeid, 'title') or '%s message copy'%cn
218 if charset != 'utf-8':
219 title = unicode(title, 'utf-8').encode(charset)
220
215 # figure author information 221 # figure author information
216 authid = messages.get(msgid, 'author') 222 authid = messages.get(msgid, 'author')
217 authname = users.get(authid, 'realname') 223 authname = users.get(authid, 'realname')
218 if not authname: 224 if not authname:
219 authname = users.get(authid, 'username') 225 authname = users.get(authid, 'username')
247 # put in roundup's signature 253 # put in roundup's signature
248 if self.db.config.EMAIL_SIGNATURE_POSITION == 'bottom': 254 if self.db.config.EMAIL_SIGNATURE_POSITION == 'bottom':
249 m.append(self.email_signature(nodeid, msgid)) 255 m.append(self.email_signature(nodeid, msgid))
250 256
251 # encode the content as quoted-printable 257 # encode the content as quoted-printable
252 content = cStringIO.StringIO('\n'.join(m)) 258 m = '\n'.join(m)
259 if charset != 'utf-8':
260 m = unicode(m, 'utf-8').encode(charset)
261 content = cStringIO.StringIO(m)
253 content_encoded = cStringIO.StringIO() 262 content_encoded = cStringIO.StringIO()
254 quopri.encode(content, content_encoded, 0) 263 quopri.encode(content, content_encoded, 0)
255 content_encoded = content_encoded.getvalue() 264 content_encoded = content_encoded.getvalue()
256 265
257 # get the files for this message 266 # get the files for this message
271 280
272 # create the message 281 # create the message
273 message = cStringIO.StringIO() 282 message = cStringIO.StringIO()
274 writer = MimeWriter.MimeWriter(message) 283 writer = MimeWriter.MimeWriter(message)
275 writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid, 284 writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid,
276 encode_header(title, self.db.config.EMAIL_CHARSET))) 285 encode_header(title, charset)))
277 writer.addheader('To', ', '.join(sendto)) 286 writer.addheader('To', ', '.join(sendto))
278 writer.addheader('From', straddr((encode_header(authname, 287 writer.addheader('From', straddr((encode_header(authname, charset)
279 self.db.config.EMAIL_CHARSET) + from_tag, from_address))) 288 + from_tag, from_address)))
280 tracker_name = encode_header(self.db.config.TRACKER_NAME, 289 tracker_name = encode_header(self.db.config.TRACKER_NAME, charset)
281 self.db.config.EMAIL_CHARSET)
282 writer.addheader('Reply-To', straddr((tracker_name, from_address))) 290 writer.addheader('Reply-To', straddr((tracker_name, from_address)))
283 writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000", 291 writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000",
284 time.gmtime())) 292 time.gmtime()))
285 writer.addheader('MIME-Version', '1.0') 293 writer.addheader('MIME-Version', '1.0')
286 if messageid: 294 if messageid:
297 # attach files 305 # attach files
298 if message_files: 306 if message_files:
299 part = writer.startmultipartbody('mixed') 307 part = writer.startmultipartbody('mixed')
300 part = writer.nextpart() 308 part = writer.nextpart()
301 part.addheader('Content-Transfer-Encoding', 'quoted-printable') 309 part.addheader('Content-Transfer-Encoding', 'quoted-printable')
302 body = part.startbody('text/plain; charset=utf-8') 310 body = part.startbody('text/plain; charset=%s'%charset)
303 body.write(content_encoded) 311 body.write(content_encoded)
304 for fileid in message_files: 312 for fileid in message_files:
305 name = files.get(fileid, 'name') 313 name = files.get(fileid, 'name')
306 mime_type = files.get(fileid, 'type') 314 mime_type = files.get(fileid, 'type')
307 content = files.get(fileid, 'content') 315 content = files.get(fileid, 'content')
325 body = part.startbody(mime_type) 333 body = part.startbody(mime_type)
326 body.write(base64.encodestring(content)) 334 body.write(base64.encodestring(content))
327 writer.lastpart() 335 writer.lastpart()
328 else: 336 else:
329 writer.addheader('Content-Transfer-Encoding', 'quoted-printable') 337 writer.addheader('Content-Transfer-Encoding', 'quoted-printable')
330 body = writer.startbody('text/plain; charset=utf-8') 338 body = writer.startbody('text/plain; charset=%s'%charset)
331 body.write(content_encoded) 339 body.write(content_encoded)
332 340
333 # now try to send the message 341 # now try to send the message
334 if SENDMAILDEBUG: 342 if SENDMAILDEBUG:
335 open(SENDMAILDEBUG, 'a').write('FROM: %s\nTO: %s\n%s\n'%( 343 open(SENDMAILDEBUG, 'a').write('FROM: %s\nTO: %s\n%s\n'%(

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