Mercurial > p > roundup > code
comparison roundup/roundupdb.py @ 1383:f19dde90e473
applied unicode patch
| author | Andrey Lebedev <kedder@users.sourceforge.net> |
|---|---|
| date | Wed, 15 Jan 2003 22:17:20 +0000 |
| parents | 98ec0c4ce7ab |
| children | 27586da5557c |
comparison
equal
deleted
inserted
replaced
| 1382:87143c3d7156 | 1383:f19dde90e473 |
|---|---|
| 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.77 2003-01-14 22:19:27 richard Exp $ | 18 # $Id: roundupdb.py,v 1.78 2003-01-15 22:17:19 kedder 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 |
| 24 import re, os, smtplib, socket, time, random | 24 import re, os, smtplib, socket, time, random |
| 25 import MimeWriter, cStringIO | 25 import MimeWriter, cStringIO |
| 26 import base64, quopri, mimetypes | 26 import base64, quopri, mimetypes |
| 27 | |
| 28 from rfc2822 import encode_header | |
| 29 | |
| 27 # if available, use the 'email' module, otherwise fallback to 'rfc822' | 30 # if available, use the 'email' module, otherwise fallback to 'rfc822' |
| 28 try : | 31 try : |
| 29 from email.Utils import formataddr as straddr | 32 from email.Utils import formataddr as straddr |
| 30 except ImportError : | 33 except ImportError : |
| 31 # code taken from the email package 2.4.3 | 34 # code taken from the email package 2.4.3 |
| 241 from_tag = ' ' + from_tag | 244 from_tag = ' ' + from_tag |
| 242 | 245 |
| 243 # create the message | 246 # create the message |
| 244 message = cStringIO.StringIO() | 247 message = cStringIO.StringIO() |
| 245 writer = MimeWriter.MimeWriter(message) | 248 writer = MimeWriter.MimeWriter(message) |
| 246 writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid, title)) | 249 writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid, encode_header(title))) |
| 247 writer.addheader('To', ', '.join(sendto)) | 250 writer.addheader('To', ', '.join(sendto)) |
| 248 writer.addheader('From', straddr((authname + from_tag, from_address))) | 251 writer.addheader('From', straddr((encode_header(authname) + |
| 252 from_tag, from_address))) | |
| 249 writer.addheader('Reply-To', straddr((self.db.config.TRACKER_NAME, | 253 writer.addheader('Reply-To', straddr((self.db.config.TRACKER_NAME, |
| 250 from_address))) | 254 from_address))) |
| 251 writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000", | 255 writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000", |
| 252 time.gmtime())) | 256 time.gmtime())) |
| 253 writer.addheader('MIME-Version', '1.0') | 257 writer.addheader('MIME-Version', '1.0') |
| 265 # attach files | 269 # attach files |
| 266 if message_files: | 270 if message_files: |
| 267 part = writer.startmultipartbody('mixed') | 271 part = writer.startmultipartbody('mixed') |
| 268 part = writer.nextpart() | 272 part = writer.nextpart() |
| 269 part.addheader('Content-Transfer-Encoding', 'quoted-printable') | 273 part.addheader('Content-Transfer-Encoding', 'quoted-printable') |
| 270 body = part.startbody('text/plain') | 274 body = part.startbody('text/plain; charset=utf-8') |
| 271 body.write(content_encoded) | 275 body.write(content_encoded) |
| 272 for fileid in message_files: | 276 for fileid in message_files: |
| 273 name = files.get(fileid, 'name') | 277 name = files.get(fileid, 'name') |
| 274 mime_type = files.get(fileid, 'type') | 278 mime_type = files.get(fileid, 'type') |
| 275 content = files.get(fileid, 'content') | 279 content = files.get(fileid, 'content') |
| 293 body = part.startbody(mime_type) | 297 body = part.startbody(mime_type) |
| 294 body.write(base64.encodestring(content)) | 298 body.write(base64.encodestring(content)) |
| 295 writer.lastpart() | 299 writer.lastpart() |
| 296 else: | 300 else: |
| 297 writer.addheader('Content-Transfer-Encoding', 'quoted-printable') | 301 writer.addheader('Content-Transfer-Encoding', 'quoted-printable') |
| 298 body = writer.startbody('text/plain') | 302 body = writer.startbody('text/plain; charset=utf-8') |
| 299 body.write(content_encoded) | 303 body.write(content_encoded) |
| 300 | 304 |
| 301 # now try to send the message | 305 # now try to send the message |
| 302 if SENDMAILDEBUG: | 306 if SENDMAILDEBUG: |
| 303 open(SENDMAILDEBUG, 'a').write('FROM: %s\nTO: %s\n%s\n'%( | 307 open(SENDMAILDEBUG, 'a').write('FROM: %s\nTO: %s\n%s\n'%( |
