@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373an exception, the original message is bounced back to the sender with the
7474explanatory message given in the exception.
7575
76- $Id: mailgw.py,v 1.117 2003-04-23 12:09:20 richard Exp $
76+ $Id: mailgw.py,v 1.118 2003-04-24 07:19:58 richard Exp $
7777'''
7878
7979import string , re , os , mimetools , cStringIO , smtplib , socket , binascii , quopri
@@ -132,6 +132,35 @@ def getparam(str, param):
132132 return rfc822 .unquote (f [i + 1 :].strip ())
133133 return None
134134
135+ def openSMTPConnection (config ):
136+ ''' Open an SMTP connection to the mailhost specified in the config
137+ '''
138+ smtp = smtplib .SMTP (config .MAILHOST )
139+
140+ # use TLS?
141+ use_tls = getattr (config , 'MAILHOST_TLS' , 'no' )
142+ if use_tls == 'yes'
143+ # do we have key files too?
144+ keyfile = getattr (config , 'MAILHOST_TLS_KEYFILE' , None )
145+ if keyfile is not None :
146+ certfile = getattr (config , 'MAILHOST_TLS_CERTFILE' , None )
147+ if certfile is not None :
148+ args = (keyfile , certfile )
149+ else :
150+ args = (keyfile , )
151+ else :
152+ args = ()
153+ # start the TLS
154+ smtp .starttls (* args )
155+
156+ # ok, now do we also need to log in?
157+ mailuser = getattr (config , 'MAILUSER' , None )
158+ if mailuser :
159+ smtp .login (* config .MAILUSER )
160+
161+ # that's it, a fully-configured SMTP connection ready to go
162+ return smtp
163+
135164class Message (mimetools .Message ):
136165 ''' subclass mimetools.Message so we can retrieve the parts of the
137166 message...
@@ -345,7 +374,7 @@ def handle_Message(self, message):
345374 m .getvalue ()))
346375 else :
347376 try :
348- smtp = smtplib . SMTP (self .instance .config . MAILHOST )
377+ smtp = openSMTPConnection (self .instance .config )
349378 smtp .sendmail (self .instance .config .ADMIN_EMAIL , sendto ,
350379 m .getvalue ())
351380 except socket .error , value :
@@ -820,12 +849,12 @@ def handle_message(self, message):
820849 # attach the files to the issue
821850 if nodeid :
822851 # extend the existing files list
823- fileprop = cl .get (nodeid , 'file ' )
852+ fileprop = cl .get (nodeid , 'files ' )
824853 fileprop .extend (files )
825854 props ['files' ] = fileprop
826855 else :
827856 # pre-load the files list
828- props ['files' ] = fileprop
857+ props ['files' ] = files
829858
830859
831860 #
0 commit comments