XOAUTH2 handler: urlopen with proxied socket

Signed-off-by: Ray Song <i@maskray.me>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Ray Song 2016-02-15 16:16:26 +08:00 committed by Nicolas Sebrecht
parent 015ec2ada4
commit b670bb2022

View File

@ -227,7 +227,13 @@ class IMAPServer:
self.ui.debug('imap', 'xoauth2handler: url "%s"' % self.oauth2_request_url) self.ui.debug('imap', 'xoauth2handler: url "%s"' % self.oauth2_request_url)
self.ui.debug('imap', 'xoauth2handler: params "%s"' % params) self.ui.debug('imap', 'xoauth2handler: params "%s"' % params)
response = urllib.urlopen(self.oauth2_request_url, urllib.urlencode(params)).read() original_socket = socket.socket
socket.socket = self.proxied_socket
try:
response = urllib.urlopen(self.oauth2_request_url, urllib.urlencode(params)).read()
finally:
socket.socket = original_socket
resp = json.loads(response) resp = json.loads(response)
self.ui.debug('imap', 'xoauth2handler: response "%s"' % resp) self.ui.debug('imap', 'xoauth2handler: response "%s"' % resp)
self.oauth2_access_token = resp['access_token'] self.oauth2_access_token = resp['access_token']