##// END OF EJS Templates
smtp: verify the certificate of the SMTP server for STARTTLS/SMTPS...
FUJIWARA Katsunori -
r18888:19d48940 default
parent child Browse files
Show More
@@ -540,7 +540,13 b' def patchbomb(ui, repo, *revs, **opts):'
540 540 fp.close()
541 541 else:
542 542 if not sendmail:
543 sendmail = mail.connect(ui, mbox=mbox)
543 verifycert = ui.config('smtp', 'verifycert')
544 if opts.get('insecure'):
545 ui.setconfig('smtp', 'verifycert', 'loose')
546 try:
547 sendmail = mail.connect(ui, mbox=mbox)
548 finally:
549 ui.setconfig('smtp', 'verifycert', verifycert)
544 550 ui.status(_('sending '), subj, ' ...\n')
545 551 ui.progress(_('sending'), i, item=subj, total=len(msgs))
546 552 if not mbox:
@@ -1052,6 +1052,16 b' Configuration for extensions that need t'
1052 1052 Optional. Method to enable TLS when connecting to mail server: starttls,
1053 1053 smtps or none. Default: none.
1054 1054
1055 ``verifycert``
1056 Optional. Verification for the certificate of mail server, when
1057 ``tls`` is starttls or smtps. "strict", "loose" or False. For
1058 "strict" or "loose", the certificate is verified as same as the
1059 verification for HTTPS connections (see ``[hostfingerprints]`` and
1060 ``[web] cacerts`` also). For "strict", sending email is also
1061 aborted, if there is no configuration for mail server in
1062 ``[hostfingerprints]`` and ``[web] cacerts``. --insecure for
1063 :hg:`email` overwrites this as "loose". Default: "strict".
1064
1055 1065 ``username``
1056 1066 Optional. User name for authenticating with the SMTP server.
1057 1067 Default: none.
@@ -92,14 +92,25 b' def _smtp(ui):'
92 92 smtps = tls == 'smtps'
93 93 if (starttls or smtps) and not util.safehasattr(socket, 'ssl'):
94 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 95 mailhost = ui.config('smtp', 'host')
101 96 if not mailhost:
102 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 114 mailport = util.getport(ui.config('smtp', 'port', 25))
104 115 ui.note(_('sending mail: smtp host %s, port %s\n') %
105 116 (mailhost, mailport))
@@ -109,6 +120,9 b' def _smtp(ui):'
109 120 s.ehlo()
110 121 s.starttls()
111 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 126 username = ui.config('smtp', 'username')
113 127 password = ui.config('smtp', 'password')
114 128 if username and not password:
General Comments 0
You need to be logged in to leave comments. Login now