diff roundup/mailgw.py @ 1612:e109d59f232d

SMTP login and TLS support added ([SF#710853] with extras ;)
author Richard Jones <richard@users.sourceforge.net>
date Thu, 24 Apr 2003 07:20:00 +0000
parents f2bdf6b07c2a
children 12637989ca4b
line wrap: on
line diff
--- a/roundup/mailgw.py	Thu Apr 24 07:19:02 2003 +0000
+++ b/roundup/mailgw.py	Thu Apr 24 07:20:00 2003 +0000
@@ -73,7 +73,7 @@
 an exception, the original message is bounced back to the sender with the
 explanatory message given in the exception. 
 
-$Id: mailgw.py,v 1.117 2003-04-23 12:09:20 richard Exp $
+$Id: mailgw.py,v 1.118 2003-04-24 07:19:58 richard Exp $
 '''
 
 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -132,6 +132,35 @@
                 return rfc822.unquote(f[i+1:].strip())
     return None
 
+def openSMTPConnection(config):
+    ''' Open an SMTP connection to the mailhost specified in the config
+    '''
+    smtp = smtplib.SMTP(config.MAILHOST)
+
+    # use TLS?
+    use_tls = getattr(config, 'MAILHOST_TLS', 'no')
+    if use_tls == 'yes'
+        # do we have key files too?
+        keyfile = getattr(config, 'MAILHOST_TLS_KEYFILE', None)
+        if keyfile is not None:
+            certfile = getattr(config, 'MAILHOST_TLS_CERTFILE', None)
+            if certfile is not None:
+                args = (keyfile, certfile)
+            else:
+                args = (keyfile, )
+        else:
+            args = ()
+        # start the TLS
+        smtp.starttls(*args)
+
+    # ok, now do we also need to log in?
+    mailuser = getattr(config, 'MAILUSER', None)
+    if mailuser:
+        smtp.login(*config.MAILUSER)
+
+    # that's it, a fully-configured SMTP connection ready to go
+    return smtp
+
 class Message(mimetools.Message):
     ''' subclass mimetools.Message so we can retrieve the parts of the
         message...
@@ -345,7 +374,7 @@
                     m.getvalue()))
         else:
             try:
-                smtp = smtplib.SMTP(self.instance.config.MAILHOST)
+                smtp = openSMTPConnection(self.instance.config)
                 smtp.sendmail(self.instance.config.ADMIN_EMAIL, sendto,
                     m.getvalue())
             except socket.error, value:
@@ -820,12 +849,12 @@
         # attach the files to the issue
         if nodeid:
             # extend the existing files list
-            fileprop = cl.get(nodeid, 'file')
+            fileprop = cl.get(nodeid, 'files')
             fileprop.extend(files)
             props['files'] = fileprop
         else:
             # pre-load the files list
-            props['files'] = fileprop
+            props['files'] = files
 
 
         # 

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