equal
deleted
inserted
replaced
21 encoding, |
21 encoding, |
22 error, |
22 error, |
23 pycompat, |
23 pycompat, |
24 sslutil, |
24 sslutil, |
25 util, |
25 util, |
|
26 ) |
|
27 from .utils import ( |
|
28 stringutil, |
26 ) |
29 ) |
27 |
30 |
28 class STARTTLS(smtplib.SMTP): |
31 class STARTTLS(smtplib.SMTP): |
29 '''Derived class to verify the peer certificate for STARTTLS. |
32 '''Derived class to verify the peer certificate for STARTTLS. |
30 |
33 |
79 def _smtp(ui): |
82 def _smtp(ui): |
80 '''build an smtp connection and return a function to send mail''' |
83 '''build an smtp connection and return a function to send mail''' |
81 local_hostname = ui.config('smtp', 'local_hostname') |
84 local_hostname = ui.config('smtp', 'local_hostname') |
82 tls = ui.config('smtp', 'tls') |
85 tls = ui.config('smtp', 'tls') |
83 # backward compatible: when tls = true, we use starttls. |
86 # backward compatible: when tls = true, we use starttls. |
84 starttls = tls == 'starttls' or util.parsebool(tls) |
87 starttls = tls == 'starttls' or stringutil.parsebool(tls) |
85 smtps = tls == 'smtps' |
88 smtps = tls == 'smtps' |
86 if (starttls or smtps) and not util.safehasattr(socket, 'ssl'): |
89 if (starttls or smtps) and not util.safehasattr(socket, 'ssl'): |
87 raise error.Abort(_("can't use TLS: Python SSL support not installed")) |
90 raise error.Abort(_("can't use TLS: Python SSL support not installed")) |
88 mailhost = ui.config('smtp', 'host') |
91 mailhost = ui.config('smtp', 'host') |
89 if not mailhost: |
92 if not mailhost: |
135 return send |
138 return send |
136 |
139 |
137 def _sendmail(ui, sender, recipients, msg): |
140 def _sendmail(ui, sender, recipients, msg): |
138 '''send mail using sendmail.''' |
141 '''send mail using sendmail.''' |
139 program = ui.config('email', 'method') |
142 program = ui.config('email', 'method') |
140 cmdline = '%s -f %s %s' % (program, util.email(sender), |
143 cmdline = '%s -f %s %s' % (program, stringutil.email(sender), |
141 ' '.join(map(util.email, recipients))) |
144 ' '.join(map(stringutil.email, recipients))) |
142 ui.note(_('sending mail: %s\n') % cmdline) |
145 ui.note(_('sending mail: %s\n') % cmdline) |
143 fp = util.popen(cmdline, 'w') |
146 fp = util.popen(cmdline, 'w') |
144 fp.write(msg) |
147 fp.write(msg) |
145 ret = fp.close() |
148 ret = fp.close() |
146 if ret: |
149 if ret: |