##// END OF EJS Templates
smtp: add the class to verify the certificate of the SMTP server for STARTTLS...
FUJIWARA Katsunori -
r18885:cf1304fb default
parent child Browse files
Show More
@@ -6,7 +6,7 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from i18n import _
9 import util, encoding
9 import util, encoding, sslutil
10 10 import os, smtplib, socket, quopri, time
11 11 import email.Header, email.MIMEText, email.Utils
12 12
@@ -30,6 +30,33 b' def _unifiedheaderinit(self, *args, **kw'
30 30
31 31 email.Header.Header.__dict__['__init__'] = _unifiedheaderinit
32 32
33 class STARTTLS(smtplib.SMTP):
34 '''Derived class to verify the peer certificate for STARTTLS.
35
36 This class allows to pass any keyword arguments to SSL socket creation.
37 '''
38 def __init__(self, sslkwargs, **kwargs):
39 smtplib.SMTP.__init__(self, **kwargs)
40 self._sslkwargs = sslkwargs
41
42 def starttls(self, keyfile=None, certfile=None):
43 if not self.has_extn("starttls"):
44 msg = "STARTTLS extension not supported by server"
45 raise smtplib.SMTPException(msg)
46 (resp, reply) = self.docmd("STARTTLS")
47 if resp == 220:
48 self.sock = sslutil.ssl_wrap_socket(self.sock, keyfile, certfile,
49 **self._sslkwargs)
50 if not util.safehasattr(self.sock, "read"):
51 # using httplib.FakeSocket with Python 2.5.x or earlier
52 self.sock.read = self.sock.recv
53 self.file = smtplib.SSLFakeFile(self.sock)
54 self.helo_resp = None
55 self.ehlo_resp = None
56 self.esmtp_features = {}
57 self.does_esmtp = 0
58 return (resp, reply)
59
33 60 def _smtp(ui):
34 61 '''build an smtp connection and return a function to send mail'''
35 62 local_hostname = ui.config('smtp', 'local_hostname')
General Comments 0
You need to be logged in to leave comments. Login now