##// END OF EJS Templates
mail: split out the SMTP login to allow the keyring extension to wrap it...
Matt Harbison -
r47753:83c0d144 default
parent child Browse files
Show More
@@ -151,6 +151,32 b' def _smtp(ui):'
151 if starttls or smtps:
151 if starttls or smtps:
152 ui.note(_(b'(verifying remote certificate)\n'))
152 ui.note(_(b'(verifying remote certificate)\n'))
153 sslutil.validatesocket(s.sock)
153 sslutil.validatesocket(s.sock)
154
155 try:
156 _smtp_login(ui, s, mailhost, mailport)
157 except smtplib.SMTPException as inst:
158 raise error.Abort(stringutil.forcebytestr(inst))
159
160 def send(sender, recipients, msg):
161 try:
162 return s.sendmail(sender, recipients, msg)
163 except smtplib.SMTPRecipientsRefused as inst:
164 recipients = [r[1] for r in inst.recipients.values()]
165 raise error.Abort(b'\n' + b'\n'.join(recipients))
166 except smtplib.SMTPException as inst:
167 raise error.Abort(inst)
168
169 return send
170
171
172 def _smtp_login(ui, smtp, mailhost, mailport):
173 """A hook for the keyring extension to perform the actual SMTP login.
174
175 An already connected SMTP object of the proper type is provided, based on
176 the current configuration. The host and port to which the connection was
177 established are provided for accessibility, since the SMTP object doesn't
178 provide an accessor. ``smtplib.SMTPException`` is raised on error.
179 """
154 username = ui.config(b'smtp', b'username')
180 username = ui.config(b'smtp', b'username')
155 password = ui.config(b'smtp', b'password')
181 password = ui.config(b'smtp', b'password')
156 if username:
182 if username:
@@ -163,21 +189,7 b' def _smtp(ui):'
163 if username and password:
189 if username and password:
164 ui.note(_(b'(authenticating to mail server as %s)\n') % username)
190 ui.note(_(b'(authenticating to mail server as %s)\n') % username)
165 username = encoding.strfromlocal(username)
191 username = encoding.strfromlocal(username)
166 try:
192 smtp.login(username, password)
167 s.login(username, password)
168 except smtplib.SMTPException as inst:
169 raise error.Abort(stringutil.forcebytestr(inst))
170
171 def send(sender, recipients, msg):
172 try:
173 return s.sendmail(sender, recipients, msg)
174 except smtplib.SMTPRecipientsRefused as inst:
175 recipients = [r[1] for r in inst.recipients.values()]
176 raise error.Abort(b'\n' + b'\n'.join(recipients))
177 except smtplib.SMTPException as inst:
178 raise error.Abort(inst)
179
180 return send
181
193
182
194
183 def _sendmail(ui, sender, recipients, msg):
195 def _sendmail(ui, sender, recipients, msg):
General Comments 0
You need to be logged in to leave comments. Login now