##// END OF EJS Templates
#46 Fix Incompatible smtp.tls setting with hg.
diryboy -
r146:e1635e84 default
parent child Browse files
Show More
@@ -37,13 +37,14 b' command line). This extension uses and w'
37 library.
37 library.
38 '''
38 '''
39
39
40 from mercurial import util
40 from mercurial import util, sslutil
41 from mercurial.i18n import _
41 from mercurial.i18n import _
42 try:
42 try:
43 from mercurial.url import passwordmgr
43 from mercurial.url import passwordmgr
44 except:
44 except:
45 from mercurial.httprepo import passwordmgr
45 from mercurial.httprepo import passwordmgr
46 from mercurial import mail
46 from mercurial import mail
47 from mercurial.mail import SMTPS, STARTTLS
47 from mercurial import encoding
48 from mercurial import encoding
48 from urllib2 import AbstractBasicAuthHandler, AbstractDigestAuthHandler
49 from urllib2 import AbstractBasicAuthHandler, AbstractDigestAuthHandler
49
50
@@ -464,22 +465,48 b' def keyring_supported_smtp(ui, username)'
464 marked with #>>>>> and #<<<<< markers
465 marked with #>>>>> and #<<<<< markers
465 """
466 """
466 local_hostname = ui.config('smtp', 'local_hostname')
467 local_hostname = ui.config('smtp', 'local_hostname')
467 s = smtplib.SMTP(local_hostname=local_hostname)
468 tls = ui.config('smtp', 'tls', 'none')
469 # backward compatible: when tls = true, we use starttls.
470 starttls = tls == 'starttls' or util.parsebool(tls)
471 smtps = tls == 'smtps'
472 if (starttls or smtps) and not util.safehasattr(socket, 'ssl'):
473 raise util.Abort(_("can't use TLS: Python SSL support not installed"))
468 mailhost = ui.config('smtp', 'host')
474 mailhost = ui.config('smtp', 'host')
469 if not mailhost:
475 if not mailhost:
470 raise util.Abort(_('no [smtp]host in hgrc - cannot send mail'))
476 raise util.Abort(_('smtp.host not configured - cannot send mail'))
471 mailport = int(ui.config('smtp', 'port', 25))
477 verifycert = ui.config('smtp', 'verifycert', 'strict')
478 if verifycert not in ['strict', 'loose']:
479 if util.parsebool(verifycert) is not False:
480 raise util.Abort(_('invalid smtp.verifycert configuration: %s')
481 % (verifycert))
482 verifycert = False
483 if (starttls or smtps) and verifycert:
484 sslkwargs = sslutil.sslkwargs(ui, mailhost)
485 else:
486 sslkwargs = {}
487 if smtps:
488 ui.note(_('(using smtps)\n'))
489 s = SMTPS(sslkwargs, local_hostname=local_hostname)
490 elif starttls:
491 s = STARTTLS(sslkwargs, local_hostname=local_hostname)
492 else:
493 s = smtplib.SMTP(local_hostname=local_hostname)
494 if smtps:
495 defaultport = 465
496 else:
497 defaultport = 25
498 mailport = util.getport(ui.config('smtp', 'port', defaultport))
472 ui.note(_('sending mail: smtp host %s, port %s\n') %
499 ui.note(_('sending mail: smtp host %s, port %s\n') %
473 (mailhost, mailport))
500 (mailhost, mailport))
474 s.connect(host=mailhost, port=mailport)
501 s.connect(host=mailhost, port=mailport)
475 if ui.configbool('smtp', 'tls'):
502 if starttls:
476 if not hasattr(socket, 'ssl'):
503 ui.note(_('(using starttls)\n'))
477 raise util.Abort(_("can't use TLS: Python SSL support "
478 "not installed"))
479 ui.note(_('(using tls)\n'))
480 s.ehlo()
504 s.ehlo()
481 s.starttls()
505 s.starttls()
482 s.ehlo()
506 s.ehlo()
507 if (starttls or smtps) and verifycert:
508 ui.note(_('(verifying remote certificate)\n'))
509 sslutil.validator(ui, mailhost)(s.sock, verifycert == 'strict')
483
510
484 #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
511 #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
485 stored = password = password_store.get_smtp_password(
512 stored = password = password_store.get_smtp_password(
General Comments 0
You need to be logged in to leave comments. Login now