[PATCH fix-default] mail: provide ui to wrapsocket in STARTTLS (issue4713)

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sat Jun 6 16:04:10 CDT 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1433624401 25200
#      Sat Jun 06 14:00:01 2015 -0700
# Node ID 8d53041dc3acf990d6b6fc023384ee65c42775db
# Parent  6fabde6ef4453ee6c2aa964184f6cf2c54483621
mail: provide ui to wrapsocket in STARTTLS (issue4713)

Since 21b536f01eda we need to feed a ui object to wrapsocket. So we now provide
a ui object to STARTTLS to be able to provide it.

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -33,22 +33,23 @@ email.Header.Header.__dict__['__init__']
 class STARTTLS(smtplib.SMTP):
     '''Derived class to verify the peer certificate for STARTTLS.
 
     This class allows to pass any keyword arguments to SSL socket creation.
     '''
-    def __init__(self, sslkwargs, **kwargs):
+    def __init__(self, ui, sslkwargs, **kwargs):
         smtplib.SMTP.__init__(self, **kwargs)
         self._sslkwargs = sslkwargs
+        self.ui = ui
 
     def starttls(self, keyfile=None, certfile=None):
         if not self.has_extn("starttls"):
             msg = "STARTTLS extension not supported by server"
             raise smtplib.SMTPException(msg)
         (resp, reply) = self.docmd("STARTTLS")
         if resp == 220:
             self.sock = sslutil.wrapsocket(self.sock, keyfile, certfile,
-                                           **self._sslkwargs)
+                                           self.ui, **self._sslkwargs)
             if not util.safehasattr(self.sock, "read"):
                 # using httplib.FakeSocket with Python 2.5.x or earlier
                 self.sock.read = self.sock.recv
             self.file = smtplib.SSLFakeFile(self.sock)
             self.helo_resp = None
@@ -107,11 +108,11 @@ def _smtp(ui):
         sslkwargs = {}
     if smtps:
         ui.note(_('(using smtps)\n'))
         s = SMTPS(sslkwargs, local_hostname=local_hostname)
     elif starttls:
-        s = STARTTLS(sslkwargs, local_hostname=local_hostname)
+        s = STARTTLS(ui, sslkwargs, local_hostname=local_hostname)
     else:
         s = smtplib.SMTP(local_hostname=local_hostname)
     if smtps:
         defaultport = 465
     else:
@@ -121,11 +122,11 @@ def _smtp(ui):
             (mailhost, mailport))
     s.connect(host=mailhost, port=mailport)
     if starttls:
         ui.note(_('(using starttls)\n'))
         s.ehlo()
-        s.starttls()
+        s.starttls(ui)
         s.ehlo()
     if (starttls or smtps) and verifycert:
         ui.note(_('(verifying remote certificate)\n'))
         sslutil.validator(ui, mailhost)(s.sock, verifycert == 'strict')
     username = ui.config('smtp', 'username')


More information about the Mercurial-devel mailing list