comparison 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
comparison
equal deleted inserted replaced
1611:db8545f10476 1612:e109d59f232d
71 set() method to add the message to the item's spool; in the second case we 71 set() method to add the message to the item's spool; in the second case we
72 are calling the create() method to create a new node). If an auditor raises 72 are calling the create() method to create a new node). If an auditor raises
73 an exception, the original message is bounced back to the sender with the 73 an exception, the original message is bounced back to the sender with the
74 explanatory message given in the exception. 74 explanatory message given in the exception.
75 75
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 $
77 ''' 77 '''
78 78
79 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri 79 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
80 import time, random, sys 80 import time, random, sys
81 import traceback, MimeWriter, rfc822 81 import traceback, MimeWriter, rfc822
129 if '=' in f: 129 if '=' in f:
130 i = f.index('=') 130 i = f.index('=')
131 if f[:i].strip().lower() == param: 131 if f[:i].strip().lower() == param:
132 return rfc822.unquote(f[i+1:].strip()) 132 return rfc822.unquote(f[i+1:].strip())
133 return None 133 return None
134
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
134 163
135 class Message(mimetools.Message): 164 class Message(mimetools.Message):
136 ''' subclass mimetools.Message so we can retrieve the parts of the 165 ''' subclass mimetools.Message so we can retrieve the parts of the
137 message... 166 message...
138 ''' 167 '''
343 open(SENDMAILDEBUG, 'a').write('From: %s\nTo: %s\n%s\n'%( 372 open(SENDMAILDEBUG, 'a').write('From: %s\nTo: %s\n%s\n'%(
344 self.instance.config.ADMIN_EMAIL, ', '.join(sendto), 373 self.instance.config.ADMIN_EMAIL, ', '.join(sendto),
345 m.getvalue())) 374 m.getvalue()))
346 else: 375 else:
347 try: 376 try:
348 smtp = smtplib.SMTP(self.instance.config.MAILHOST) 377 smtp = openSMTPConnection(self.instance.config)
349 smtp.sendmail(self.instance.config.ADMIN_EMAIL, sendto, 378 smtp.sendmail(self.instance.config.ADMIN_EMAIL, sendto,
350 m.getvalue()) 379 m.getvalue())
351 except socket.error, value: 380 except socket.error, value:
352 raise MailGWError, "Couldn't send error email: "\ 381 raise MailGWError, "Couldn't send error email: "\
353 "mailhost %s"%value 382 "mailhost %s"%value
818 files.append(self.db.file.create(type=mime_type, name=name, 847 files.append(self.db.file.create(type=mime_type, name=name,
819 content=data, **file_props)) 848 content=data, **file_props))
820 # attach the files to the issue 849 # attach the files to the issue
821 if nodeid: 850 if nodeid:
822 # extend the existing files list 851 # extend the existing files list
823 fileprop = cl.get(nodeid, 'file') 852 fileprop = cl.get(nodeid, 'files')
824 fileprop.extend(files) 853 fileprop.extend(files)
825 props['files'] = fileprop 854 props['files'] = fileprop
826 else: 855 else:
827 # pre-load the files list 856 # pre-load the files list
828 props['files'] = fileprop 857 props['files'] = files
829 858
830 859
831 # 860 #
832 # create the message if there's a message body (content) 861 # create the message if there's a message body (content)
833 # 862 #

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