Patchwork [4,of,6] mail: remove use of sslkwargs

login
register
mail settings
Submitter Gregory Szorc
Date May 26, 2016, 3:03 a.m.
Message ID <5ea31af4040f1d1c5927.1464231833@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/15215/
State Accepted
Headers show

Comments

Gregory Szorc - May 26, 2016, 3:03 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1464231380 25200
#      Wed May 25 19:56:20 2016 -0700
# Node ID 5ea31af4040f1d1c59278b637d15cb13a9403792
# Parent  de1d20a7379deb5289e2d12d73352c16470b0358
mail: remove use of sslkwargs

Patch

diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -43,63 +43,59 @@  def _unifiedheaderinit(self, *args, **kw
 
 setattr(email.header.Header, '__init__', _unifiedheaderinit)
 
 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, ui, sslkwargs, host=None, **kwargs):
+    def __init__(self, ui, host=None, **kwargs):
         smtplib.SMTP.__init__(self, **kwargs)
         self._ui = ui
-        self._sslkwargs = sslkwargs
         self._host = host
 
     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,
                                            ui=self._ui,
-                                           serverhostname=self._host,
-                                           **self._sslkwargs)
+                                           serverhostname=self._host)
             self.file = smtplib.SSLFakeFile(self.sock)
             self.helo_resp = None
             self.ehlo_resp = None
             self.esmtp_features = {}
             self.does_esmtp = 0
         return (resp, reply)
 
 class SMTPS(smtplib.SMTP):
     '''Derived class to verify the peer certificate for SMTPS.
 
     This class allows to pass any keyword arguments to SSL socket creation.
     '''
-    def __init__(self, ui, sslkwargs, keyfile=None, certfile=None, host=None,
+    def __init__(self, ui, 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._ui = ui
-        self._sslkwargs = sslkwargs
 
     def _get_socket(self, host, port, timeout):
         if self.debuglevel > 0:
             print('connect:', (host, port), file=sys.stderr)
         new_socket = socket.create_connection((host, port), timeout)
         new_socket = sslutil.wrapsocket(new_socket,
                                         self.keyfile, self.certfile,
                                         ui=self._ui,
-                                        serverhostname=self._host,
-                                        **self._sslkwargs)
+                                        serverhostname=self._host)
         self.file = smtplib.SSLFakeFile(new_socket)
         return new_socket
 
 def _smtp(ui):
     '''build an smtp connection and return a function to send mail'''
     local_hostname = ui.config('smtp', 'local_hostname')
     tls = ui.config('smtp', 'tls', 'none')
     # backward compatible: when tls = true, we use starttls.
@@ -111,25 +107,22 @@  def _smtp(ui):
     if not mailhost:
         raise error.Abort(_('smtp.host not configured - cannot send mail'))
     verifycert = ui.config('smtp', 'verifycert', 'strict')
     if verifycert not in ['strict', 'loose']:
         if util.parsebool(verifycert) is not False:
             raise error.Abort(_('invalid smtp.verifycert configuration: %s')
                              % (verifycert))
         verifycert = False
-    if (starttls or smtps) and verifycert:
-        sslkwargs = sslutil.sslkwargs(ui, mailhost)
 
     if smtps:
         ui.note(_('(using smtps)\n'))
-        s = SMTPS(ui, sslkwargs, local_hostname=local_hostname, host=mailhost)
+        s = SMTPS(ui, local_hostname=local_hostname, host=mailhost)
     elif starttls:
-        s = STARTTLS(ui, sslkwargs, local_hostname=local_hostname,
-                     host=mailhost)
+        s = STARTTLS(ui, local_hostname=local_hostname, host=mailhost)
     else:
         s = smtplib.SMTP(local_hostname=local_hostname)
     if smtps:
         defaultport = 465
     else:
         defaultport = 25
     mailport = util.getport(ui.config('smtp', 'port', defaultport))
     ui.note(_('sending mail: smtp host %s, port %d\n') %