##// 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 151 if starttls or smtps:
152 152 ui.note(_(b'(verifying remote certificate)\n'))
153 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 180 username = ui.config(b'smtp', b'username')
155 181 password = ui.config(b'smtp', b'password')
156 182 if username:
@@ -163,21 +189,7 b' def _smtp(ui):'
163 189 if username and password:
164 190 ui.note(_(b'(authenticating to mail server as %s)\n') % username)
165 191 username = encoding.strfromlocal(username)
166 try:
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
192 smtp.login(username, password)
181 193
182 194
183 195 def _sendmail(ui, sender, recipients, msg):
General Comments 0
You need to be logged in to leave comments. Login now