Zhigang Wang
2010-12-10 08:00:37 UTC
doc/hgrc.5.txt | 3 +++
mercurial/mail.py | 17 +++++++++++------
2 files changed, 14 insertions(+), 6 deletions(-)
# HG changeset patch
# User Zhigang Wang <***@oracle.com>
# Date 1291967692 -28800
# Node ID d44d0475a776eaffb8d8b34107e357dd43cfbbd3
# Parent 5dac0d04b838d599acdc5db9ee0b7de51de15537
smtp tls: fix for server doesn't support STARTTLS extension.
Currently we only support enabling TLS by using SMTP STARTTLS extension. But
not all the servers support it.
With this patch, user can choose which way to use to enable TLS:
* Default:
tls = false
starttls = false
port = 25
* To use tls:
tls = true
port = 465
* To use starttls:
starttls = true
port = 465
Signed-off-by: Zhigang Wang <***@gmail.com>
diff -r 5dac0d04b838 -r d44d0475a776 doc/hgrc.5.txt
--- a/doc/hgrc.5.txt Wed Dec 08 13:12:12 2010 -0600
+++ b/doc/hgrc.5.txt Fri Dec 10 15:54:52 2010 +0800
@@ -711,6 +711,9 @@
``tls``
Optional. Whether to connect to mail server using TLS. True or
False. Default: False.
+``starttls``
+ Optional. Whether to enable TLS using STARTTLS extension. True or
+ False. Default: False.
``username``
Optional. User name for authenticating with the SMTP server.
Default: none.
diff -r 5dac0d04b838 -r d44d0475a776 mercurial/mail.py
--- a/mercurial/mail.py Wed Dec 08 13:12:12 2010 -0600
+++ b/mercurial/mail.py Fri Dec 10 15:54:52 2010 +0800
@@ -33,7 +33,15 @@
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)
+ if ui.configbool('smtp', 'tls') or ui.configbool('smtp', 'starttls'):
+ if not hasattr(socket, 'ssl'):
+ raise util.Abort(_("can't use TLS: Python SSL support "
+ "not installed"))
+ if ui.configbool('smtp', 'tls') and not ui.configbool('smtp', 'starttls'):
+ ui.note(_('(using tls)\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 +49,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 ui.configbool('smtp', 'starttls'):
+ ui.note(_('(using starttls)\n'))
s.ehlo()
s.starttls()
s.ehlo()
mercurial/mail.py | 17 +++++++++++------
2 files changed, 14 insertions(+), 6 deletions(-)
# HG changeset patch
# User Zhigang Wang <***@oracle.com>
# Date 1291967692 -28800
# Node ID d44d0475a776eaffb8d8b34107e357dd43cfbbd3
# Parent 5dac0d04b838d599acdc5db9ee0b7de51de15537
smtp tls: fix for server doesn't support STARTTLS extension.
Currently we only support enabling TLS by using SMTP STARTTLS extension. But
not all the servers support it.
With this patch, user can choose which way to use to enable TLS:
* Default:
tls = false
starttls = false
port = 25
* To use tls:
tls = true
port = 465
* To use starttls:
starttls = true
port = 465
Signed-off-by: Zhigang Wang <***@gmail.com>
diff -r 5dac0d04b838 -r d44d0475a776 doc/hgrc.5.txt
--- a/doc/hgrc.5.txt Wed Dec 08 13:12:12 2010 -0600
+++ b/doc/hgrc.5.txt Fri Dec 10 15:54:52 2010 +0800
@@ -711,6 +711,9 @@
``tls``
Optional. Whether to connect to mail server using TLS. True or
False. Default: False.
+``starttls``
+ Optional. Whether to enable TLS using STARTTLS extension. True or
+ False. Default: False.
``username``
Optional. User name for authenticating with the SMTP server.
Default: none.
diff -r 5dac0d04b838 -r d44d0475a776 mercurial/mail.py
--- a/mercurial/mail.py Wed Dec 08 13:12:12 2010 -0600
+++ b/mercurial/mail.py Fri Dec 10 15:54:52 2010 +0800
@@ -33,7 +33,15 @@
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)
+ if ui.configbool('smtp', 'tls') or ui.configbool('smtp', 'starttls'):
+ if not hasattr(socket, 'ssl'):
+ raise util.Abort(_("can't use TLS: Python SSL support "
+ "not installed"))
+ if ui.configbool('smtp', 'tls') and not ui.configbool('smtp', 'starttls'):
+ ui.note(_('(using tls)\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 +49,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 ui.configbool('smtp', 'starttls'):
+ ui.note(_('(using starttls)\n'))
s.ehlo()
s.starttls()
s.ehlo()