Show More
@@ -540,7 +540,13 b' def patchbomb(ui, repo, *revs, **opts):' | |||||
540 | fp.close() |
|
540 | fp.close() | |
541 | else: |
|
541 | else: | |
542 | if not sendmail: |
|
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 | ui.status(_('sending '), subj, ' ...\n') |
|
550 | ui.status(_('sending '), subj, ' ...\n') | |
545 | ui.progress(_('sending'), i, item=subj, total=len(msgs)) |
|
551 | ui.progress(_('sending'), i, item=subj, total=len(msgs)) | |
546 | if not mbox: |
|
552 | if not mbox: |
@@ -1052,6 +1052,16 b' Configuration for extensions that need t' | |||||
1052 | Optional. Method to enable TLS when connecting to mail server: starttls, |
|
1052 | Optional. Method to enable TLS when connecting to mail server: starttls, | |
1053 | smtps or none. Default: none. |
|
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 | ``username`` |
|
1065 | ``username`` | |
1056 | Optional. User name for authenticating with the SMTP server. |
|
1066 | Optional. User name for authenticating with the SMTP server. | |
1057 | Default: none. |
|
1067 | Default: none. |
@@ -92,14 +92,25 b' def _smtp(ui):' | |||||
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)) | |
@@ -109,6 +120,9 b' def _smtp(ui):' | |||||
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: |
General Comments 0
You need to be logged in to leave comments.
Login now