comparison roundup/mailer.py @ 2626:e49e6c7b14fb

fix incompatibilities with new configuration; added MAIL_DEBUG config option; added vim modeline
author Alexander Smishlajev <a1s@users.sourceforge.net>
date Sun, 25 Jul 2004 15:25:44 +0000
parents 6deda7ff3b2a
children 75b4c2c32cf3 8fcee705ebdb
comparison
equal deleted inserted replaced
2625:8e4c7a3217d6 2626:e49e6c7b14fb
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.9 2004-03-25 22:53:26 richard Exp $ 4 # $Id: mailer.py,v 1.10 2004-07-25 15:25:44 a1s 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
19 def __init__(self, config): 19 def __init__(self, config):
20 self.config = config 20 self.config = config
21 21
22 # set to indicate to roundup not to actually _send_ email 22 # set to indicate to roundup not to actually _send_ email
23 # this var must contain a file to write the mail to 23 # this var must contain a file to write the mail to
24 self.debug = os.environ.get('SENDMAILDEBUG', '') 24 self.debug = os.environ.get('SENDMAILDEBUG', '') \
25 or config["MAIL_DEBUG"]
25 26
26 def get_standard_message(self, to, subject, author=None): 27 def get_standard_message(self, to, subject, author=None):
27 '''Form a standard email message from Roundup. 28 '''Form a standard email message from Roundup.
28 29
29 "to" - recipients list 30 "to" - recipients list
62 # and another one to avoid loops 63 # and another one to avoid loops
63 writer.addheader('X-Roundup-Loop', 'hello') 64 writer.addheader('X-Roundup-Loop', 'hello')
64 # finally, an aid to debugging problems 65 # finally, an aid to debugging problems
65 writer.addheader('X-Roundup-Version', __version__) 66 writer.addheader('X-Roundup-Version', __version__)
66 67
67 writer.addheader('MIME-Version', '1.0') 68 writer.addheader('MIME-Version', '1.0')
68 69
69 return message, writer 70 return message, writer
70 71
71 def standard_message(self, to, subject, content, author=None): 72 def standard_message(self, to, subject, content, author=None):
72 """Send a standard message. 73 """Send a standard message.
73 74
134 body.write(bounced_message.fp.read()) 135 body.write(bounced_message.fp.read())
135 136
136 writer.lastpart() 137 writer.lastpart()
137 138
138 self.smtp_send(to, message) 139 self.smtp_send(to, message)
139 140
140 def smtp_send(self, to, message): 141 def smtp_send(self, to, message):
141 """Send a message over SMTP, using roundup's config. 142 """Send a message over SMTP, using roundup's config.
142 143
143 Arguments: 144 Arguments:
144 - to: a list of addresses usable by rfc822.parseaddr(). 145 - to: a list of addresses usable by rfc822.parseaddr().
166 167
167 class SMTPConnection(smtplib.SMTP): 168 class SMTPConnection(smtplib.SMTP):
168 ''' Open an SMTP connection to the mailhost specified in the config 169 ''' Open an SMTP connection to the mailhost specified in the config
169 ''' 170 '''
170 def __init__(self, config): 171 def __init__(self, config):
171 172
172 smtplib.SMTP.__init__(self, config.MAILHOST) 173 smtplib.SMTP.__init__(self, config.MAILHOST)
173 174
174 # use TLS? 175 # start the TLS if requested
175 use_tls = getattr(config, 'MAILHOST_TLS', 'no') 176 if config["MAIL_TLS"]:
176 if use_tls == 'yes': 177 self.starttls(config["MAIL_TLS_KEYFILE"],
177 # do we have key files too? 178 config["MAIL_TLS_CERFILE"])
178 keyfile = getattr(config, 'MAILHOST_TLS_KEYFILE', '')
179 if keyfile:
180 certfile = getattr(config, 'MAILHOST_TLS_CERTFILE', '')
181 if certfile:
182 args = (keyfile, certfile)
183 else:
184 args = (keyfile, )
185 else:
186 args = ()
187 # start the TLS
188 self.starttls(*args)
189 179
190 # ok, now do we also need to log in? 180 # ok, now do we also need to log in?
191 mailuser = getattr(config, 'MAILUSER', None) 181 mailuser = config["MAIL_USERNAME"]
192 if mailuser: 182 if mailuser:
193 self.login(*config.MAILUSER) 183 self.login(mailuser, config["MAIL_PASSWORD"])
194 184
195 # use the 'email' module, either imported, or our copied version 185 # use the 'email' module, either imported, or our copied version
196 try : 186 try :
197 from email.Utils import formataddr as straddr 187 from email.Utils import formataddr as straddr
198 except ImportError : 188 except ImportError :
205 if specialsre.search(name): 195 if specialsre.search(name):
206 quotes = '"' 196 quotes = '"'
207 name = escapesre.sub(r'\\\g<0>', name) 197 name = escapesre.sub(r'\\\g<0>', name)
208 return '%s%s%s <%s>' % (quotes, name, quotes, address) 198 return '%s%s%s <%s>' % (quotes, name, quotes, address)
209 return address 199 return address
200
201 # vim: set et sts=4 sw=4 :

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