Mercurial > p > roundup > code
comparison roundup/mailer.py @ 3467:8fcee705ebdb maint-0.8
merge from HEAD
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 13 Jan 2006 03:34:34 +0000 |
| parents | e49e6c7b14fb |
| children | 5603e08ac6fc |
comparison
equal
deleted
inserted
replaced
| 3462:639a3d1014e9 | 3467:8fcee705ebdb |
|---|---|
| 1 """Sending Roundup-specific mail over SMTP. | 1 """Sending Roundup-specific mail over SMTP. |
| 2 """ | 2 """ |
| 3 __docformat__ = 'restructuredtext' | 3 __docformat__ = 'restructuredtext' |
| 4 # $Id: mailer.py,v 1.10 2004-07-25 15:25:44 a1s Exp $ | 4 # $Id: mailer.py,v 1.10.2.1 2006-01-13 03:34:34 richard Exp $ |
| 5 | 5 |
| 6 import time, quopri, os, socket, smtplib, re | 6 import time, quopri, os, socket, smtplib, re |
| 7 | 7 |
| 8 from cStringIO import StringIO | 8 from cStringIO import StringIO |
| 9 from MimeWriter import MimeWriter | 9 from MimeWriter import MimeWriter |
| 10 | 10 |
| 11 from roundup.rfc2822 import encode_header | 11 from roundup.rfc2822 import encode_header |
| 12 from roundup import __version__ | 12 from roundup import __version__ |
| 13 | |
| 14 try: | |
| 15 from email.Utils import formatdate | |
| 16 except ImportError: | |
| 17 def formatdate(timeval): | |
| 18 return time.strftime("%a, %d %b %Y %H:%M:%S +0000", timeval) | |
| 13 | 19 |
| 14 class MessageSendError(RuntimeError): | 20 class MessageSendError(RuntimeError): |
| 15 pass | 21 pass |
| 16 | 22 |
| 17 class Mailer: | 23 class Mailer: |
| 52 message = StringIO() | 58 message = StringIO() |
| 53 writer = MimeWriter(message) | 59 writer = MimeWriter(message) |
| 54 writer.addheader('Subject', encode_header(subject, charset)) | 60 writer.addheader('Subject', encode_header(subject, charset)) |
| 55 writer.addheader('To', ', '.join(to)) | 61 writer.addheader('To', ', '.join(to)) |
| 56 writer.addheader('From', author) | 62 writer.addheader('From', author) |
| 57 writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000", | 63 writer.addheader('Date', formatdate(time.gmtime())) |
| 58 time.gmtime())) | |
| 59 | 64 |
| 60 # Add a unique Roundup header to help filtering | 65 # Add a unique Roundup header to help filtering |
| 61 writer.addheader('X-Roundup-Name', encode_header(tracker_name, | 66 writer.addheader('X-Roundup-Name', encode_header(tracker_name, |
| 62 charset)) | 67 charset)) |
| 63 # and another one to avoid loops | 68 # and another one to avoid loops |
