@api.multi
def connect(self):
user = self.env['res.users']
aouth_id = self.env['auth.oauth.provider'].search([('enabled', '=', True)])
user_ids = user.search([('id', '=', 800),('oauth_access_token', '!=', False)])
for user in user_ids:
partner_ids = self.search([('user_id', '=', user.id)])
for partner in partner_ids:
server = 'imap.gmail.com'
port = IMAP4_SSL_PORT
print port, "llllllll"
connection = IMAP4_SSL(server)
username = partner.user_id.login
print partner.user_id.oauth_access_token
print(oauth2.GeneratePermissionUrl(aouth_id.client_id))
oauth2String = oauth2.GenerateOAuth2String(username,partner.user_id.oauth_access_token,base64_encode=False)
print oauth2String, "---------===-----"
connection.authenticate('XOAUTH2', lambda x: oauth2String)
print "-----", connection
# connection.login(username, partner.user_id.oauth_access_token)
return connection