mercurial/mail.py
changeset 18888 19d489404d79
parent 18886 14a60a0f7122
child 18916 6edb0e18b83c
equal deleted inserted replaced
18887:2d7fac049d3a 18888:19d489404d79
    90     # backward compatible: when tls = true, we use starttls.
    90     # backward compatible: when tls = true, we use starttls.
    91     starttls = tls == 'starttls' or util.parsebool(tls)
    91     starttls = tls == 'starttls' or util.parsebool(tls)
    92     smtps = tls == 'smtps'
    92     smtps = tls == 'smtps'
    93     if (starttls or smtps) and not util.safehasattr(socket, 'ssl'):
    93     if (starttls or smtps) and not util.safehasattr(socket, 'ssl'):
    94         raise util.Abort(_("can't use TLS: Python SSL support not installed"))
    94         raise util.Abort(_("can't use TLS: Python SSL support not installed"))
    95     if smtps:
       
    96         ui.note(_('(using smtps)\n'))
       
    97         s = smtplib.SMTP_SSL(local_hostname=local_hostname)
       
    98     else:
       
    99         s = smtplib.SMTP(local_hostname=local_hostname)
       
   100     mailhost = ui.config('smtp', 'host')
    95     mailhost = ui.config('smtp', 'host')
   101     if not mailhost:
    96     if not mailhost:
   102         raise util.Abort(_('smtp.host not configured - cannot send mail'))
    97         raise util.Abort(_('smtp.host not configured - cannot send mail'))
       
    98     verifycert = ui.config('smtp', 'verifycert', 'strict')
       
    99     if verifycert not in ['strict', 'loose']:
       
   100         if util.parsebool(verifycert) is not False:
       
   101             raise util.Abort(_('invalid smtp.verifycert configuration: %s')
       
   102                              % (verifycert))
       
   103     if (starttls or smtps) and verifycert:
       
   104         sslkwargs = sslutil.sslkwargs(ui, mailhost)
       
   105     else:
       
   106         sslkwargs = {}
       
   107     if smtps:
       
   108         ui.note(_('(using smtps)\n'))
       
   109         s = SMTPS(sslkwargs, local_hostname=local_hostname)
       
   110     elif starttls:
       
   111         s = STARTTLS(sslkwargs, local_hostname=local_hostname)
       
   112     else:
       
   113         s = smtplib.SMTP(local_hostname=local_hostname)
   103     mailport = util.getport(ui.config('smtp', 'port', 25))
   114     mailport = util.getport(ui.config('smtp', 'port', 25))
   104     ui.note(_('sending mail: smtp host %s, port %s\n') %
   115     ui.note(_('sending mail: smtp host %s, port %s\n') %
   105             (mailhost, mailport))
   116             (mailhost, mailport))
   106     s.connect(host=mailhost, port=mailport)
   117     s.connect(host=mailhost, port=mailport)
   107     if starttls:
   118     if starttls:
   108         ui.note(_('(using starttls)\n'))
   119         ui.note(_('(using starttls)\n'))
   109         s.ehlo()
   120         s.ehlo()
   110         s.starttls()
   121         s.starttls()
   111         s.ehlo()
   122         s.ehlo()
       
   123     if (starttls or smtps) and verifycert:
       
   124         ui.note(_('(verifying remote certificate)\n'))
       
   125         sslutil.validator(ui, mailhost)(s.sock, verifycert == 'strict')
   112     username = ui.config('smtp', 'username')
   126     username = ui.config('smtp', 'username')
   113     password = ui.config('smtp', 'password')
   127     password = ui.config('smtp', 'password')
   114     if username and not password:
   128     if username and not password:
   115         password = ui.getpass()
   129         password = ui.getpass()
   116     if username and password:
   130     if username and password: