11"""Sending Roundup-specific mail over SMTP.
22"""
33__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 $
55
66import time , quopri , os , socket , smtplib , re
77
@@ -21,7 +21,8 @@ def __init__(self, config):
2121
2222 # set to indicate to roundup not to actually _send_ email
2323 # 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" ]
2526
2627 def get_standard_message (self , to , subject , author = None ):
2728 '''Form a standard email message from Roundup.
@@ -64,8 +65,8 @@ def get_standard_message(self, to, subject, author=None):
6465 # finally, an aid to debugging problems
6566 writer .addheader ('X-Roundup-Version' , __version__ )
6667
67- writer .addheader ('MIME-Version' , '1.0' )
68-
68+ writer .addheader ('MIME-Version' , '1.0' )
69+
6970 return message , writer
7071
7172 def standard_message (self , to , subject , content , author = None ):
@@ -136,7 +137,7 @@ def bounce_message(self, bounced_message, to, error,
136137 writer .lastpart ()
137138
138139 self .smtp_send (to , message )
139-
140+
140141 def smtp_send (self , to , message ):
141142 """Send a message over SMTP, using roundup's config.
142143
@@ -168,29 +169,18 @@ class SMTPConnection(smtplib.SMTP):
168169 ''' Open an SMTP connection to the mailhost specified in the config
169170 '''
170171 def __init__ (self , config ):
171-
172+
172173 smtplib .SMTP .__init__ (self , config .MAILHOST )
173174
174- # use TLS?
175- use_tls = getattr (config , 'MAILHOST_TLS' , 'no' )
176- if use_tls == 'yes' :
177- # do we have key files too?
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 )
175+ # start the TLS if requested
176+ if config ["MAIL_TLS" ]:
177+ self .starttls (config ["MAIL_TLS_KEYFILE" ],
178+ config ["MAIL_TLS_CERFILE" ])
189179
190180 # ok, now do we also need to log in?
191- mailuser = getattr ( config , 'MAILUSER' , None )
181+ mailuser = config [ "MAIL_USERNAME" ]
192182 if mailuser :
193- self .login (* config . MAILUSER )
183+ self .login (mailuser , config [ "MAIL_PASSWORD" ] )
194184
195185# use the 'email' module, either imported, or our copied version
196186try :
@@ -207,3 +197,5 @@ def straddr(pair, specialsre = re.compile(r'[][\()<>@,:;".]'),
207197 name = escapesre .sub (r'\\\g<0>' , name )
208198 return '%s%s%s <%s>' % (quotes , name , quotes , address )
209199 return address
200+
201+ # vim: set et sts=4 sw=4 :
0 commit comments