--- a/mercurial/mail.py Thu Dec 02 03:43:06 2010 +0100
+++ b/mercurial/mail.py Mon Dec 20 16:56:54 2010 +0800
@@ -33,7 +33,17 @@
def _smtp(ui):
'''build an smtp connection and return a function to send mail'''
local_hostname = ui.config('smtp', 'local_hostname')
- s = smtplib.SMTP(local_hostname=local_hostname)
+ tls = ui.config('smtp', 'tls')
+ # backward compatible: when tls = true, we use starttls.
+ starttls = tls == 'starttls' or util.parsebool(tls)
+ smtps = tls == 'smtps'
+ if (starttls or smtps) and not hasattr(socket, 'ssl'):
+ raise util.Abort(_("can't use TLS: Python SSL support not installed"))
+ if smtps:
+ ui.note(_('(using smtps)\n'))
+ s = smtplib.SMTP_SSL(local_hostname=local_hostname)
+ else:
+ s = smtplib.SMTP(local_hostname=local_hostname)
mailhost = ui.config('smtp', 'host')
if not mailhost:
raise util.Abort(_('smtp.host not configured - cannot send mail'))
@@ -41,11 +51,8 @@
ui.note(_('sending mail: smtp host %s, port %s\n') %
(mailhost, mailport))
s.connect(host=mailhost, port=mailport)
- if ui.configbool('smtp', 'tls'):
- if not hasattr(socket, 'ssl'):
- raise util.Abort(_("can't use TLS: Python SSL support "
- "not installed"))
- ui.note(_('(using tls)\n'))
+ if starttls:
+ ui.note(_('(using starttls)\n'))
s.ehlo()
s.starttls()
s.ehlo()