mercurial/mail.py
changeset 39025 569d662816de
parent 39024 eabdf3c25b8b
child 39026 a5e70c14214a
equal deleted inserted replaced
39024:eabdf3c25b8b 39025:569d662816de
    80                                         ui=self._ui,
    80                                         ui=self._ui,
    81                                         serverhostname=self._host)
    81                                         serverhostname=self._host)
    82         self.file = smtplib.SSLFakeFile(new_socket)
    82         self.file = smtplib.SSLFakeFile(new_socket)
    83         return new_socket
    83         return new_socket
    84 
    84 
       
    85 def _pyhastls():
       
    86     """Returns true iff Python has TLS support, false otherwise."""
       
    87     try:
       
    88         import ssl
       
    89         getattr(ssl, 'HAS_TLS', False)
       
    90         return True
       
    91     except ImportError:
       
    92         return False
       
    93 
    85 def _smtp(ui):
    94 def _smtp(ui):
    86     '''build an smtp connection and return a function to send mail'''
    95     '''build an smtp connection and return a function to send mail'''
    87     local_hostname = ui.config('smtp', 'local_hostname')
    96     local_hostname = ui.config('smtp', 'local_hostname')
    88     tls = ui.config('smtp', 'tls')
    97     tls = ui.config('smtp', 'tls')
    89     # backward compatible: when tls = true, we use starttls.
    98     # backward compatible: when tls = true, we use starttls.
    90     starttls = tls == 'starttls' or stringutil.parsebool(tls)
    99     starttls = tls == 'starttls' or stringutil.parsebool(tls)
    91     smtps = tls == 'smtps'
   100     smtps = tls == 'smtps'
    92     if (starttls or smtps) and not util.safehasattr(socket, 'ssl'):
   101     if (starttls or smtps) and not _pyhastls():
    93         raise error.Abort(_("can't use TLS: Python SSL support not installed"))
   102         raise error.Abort(_("can't use TLS: Python SSL support not installed"))
    94     mailhost = ui.config('smtp', 'host')
   103     mailhost = ui.config('smtp', 'host')
    95     if not mailhost:
   104     if not mailhost:
    96         raise error.Abort(_('smtp.host not configured - cannot send mail'))
   105         raise error.Abort(_('smtp.host not configured - cannot send mail'))
    97     if smtps:
   106     if smtps: