Mercurial > hg
changeset 28935:a4c5c23de1d3
mail: retain hostname for sslutil.wrapsocket (issue5203)
SMTPS + STARTTLS need to provide serverhostname,
and we can't store it in sslkwargs because that breaks
something involving the https protocol.
author | timeless <timeless@mozdev.org> |
---|---|
date | Fri, 15 Apr 2016 17:43:47 +0000 |
parents | c4040a35b5d9 |
children | 44bd37af54e5 |
files | mercurial/mail.py |
diffstat | 1 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/mail.py Sat Apr 16 04:06:24 2016 +0530 +++ b/mercurial/mail.py Fri Apr 15 17:43:47 2016 +0000 @@ -48,9 +48,10 @@ This class allows to pass any keyword arguments to SSL socket creation. ''' - def __init__(self, sslkwargs, **kwargs): + def __init__(self, sslkwargs, host=None, **kwargs): smtplib.SMTP.__init__(self, **kwargs) self._sslkwargs = sslkwargs + self._host = host def starttls(self, keyfile=None, certfile=None): if not self.has_extn("starttls"): @@ -59,6 +60,7 @@ (resp, reply) = self.docmd("STARTTLS") if resp == 220: self.sock = sslutil.wrapsocket(self.sock, keyfile, certfile, + serverhostname=self._host, **self._sslkwargs) self.file = smtplib.SSLFakeFile(self.sock) self.helo_resp = None @@ -72,10 +74,12 @@ This class allows to pass any keyword arguments to SSL socket creation. ''' - def __init__(self, sslkwargs, keyfile=None, certfile=None, **kwargs): + def __init__(self, sslkwargs, keyfile=None, certfile=None, host=None, + **kwargs): self.keyfile = keyfile self.certfile = certfile smtplib.SMTP.__init__(self, **kwargs) + self._host = host self.default_port = smtplib.SMTP_SSL_PORT self._sslkwargs = sslkwargs @@ -85,6 +89,7 @@ new_socket = socket.create_connection((host, port), timeout) new_socket = sslutil.wrapsocket(new_socket, self.keyfile, self.certfile, + serverhostname=self._host, **self._sslkwargs) self.file = smtplib.SSLFakeFile(new_socket) return new_socket @@ -114,9 +119,9 @@ sslkwargs = {'ui': ui} if smtps: ui.note(_('(using smtps)\n')) - s = SMTPS(sslkwargs, local_hostname=local_hostname) + s = SMTPS(sslkwargs, local_hostname=local_hostname, host=mailhost) elif starttls: - s = STARTTLS(sslkwargs, local_hostname=local_hostname) + s = STARTTLS(sslkwargs, local_hostname=local_hostname, host=mailhost) else: s = smtplib.SMTP(local_hostname=local_hostname) if smtps: