(consumer, access_token, user, proto,
                         xoauth_requestor_id, nonce, timestamp)
return preencoded
Generates an IMAP XOAUTH authentication string.

  Args:
    consumer: An OAuthEntity representing the consumer.
    access_token: An OAuthEntity representing the access token.
    user: The Google Mail username (full email address)
    proto: "imap" or "smtp", for example.
    xoauth_requestor_id: xoauth_requestor_id URL parameter for 2-legged OAuth
    nonce: optional supplied nonce
    timestamp: optional supplied timestamp

  Returns:
    A string that can be passed as the argument to an IMAP
    "AUTHENTICATE XOAUTH" command after being base64-encoded.
Generates an IMAP XOAUTH authentication string.
Generates an IMAP XOAUTH authentication string .
def GenerateXOauthString(consumer, access_token, user, proto,
                         xoauth_requestor_id, nonce, timestamp):
  """Generates an IMAP XOAUTH authentication string.

  Args:
    consumer: An OAuthEntity representing the consumer.
    access_token: An OAuthEntity representing the access token.
    user: The Google Mail username (full email address)
    proto: "imap" or "smtp", for example.
    xoauth_requestor_id: xoauth_requestor_id URL parameter for 2-legged OAuth
    nonce: optional supplied nonce
    timestamp: optional supplied timestamp

  Returns:
    A string that can be passed as the argument to an IMAP
    "AUTHENTICATE XOAUTH" command after being base64-encoded.
  """
  method = 'GET'
  url_params = {}
  if xoauth_requestor_id:
    url_params['xoauth_requestor_id'] = xoauth_requestor_id
  oauth_params = {}
  FillInCommonOauthParams(oauth_params, consumer, nonce, timestamp)
  if access_token.key:
    oauth_params['oauth_token'] = access_token.key
  signed_params = oauth_params.copy()
  signed_params.update(url_params)
  request_url_base = (
      'https://mail.google.com/mail/b/%s/%s/' % (user, proto))
  base_string = GenerateSignatureBaseString(
      method,
      request_url_base,
      signed_params)
  print 'signature base string:\n' + base_string + '\n'
  signature = GenerateOauthSignature(base_string, consumer.secret,
                                     access_token.secret)
  oauth_params['oauth_signature'] = signature

  formatted_params = []
  for k, v in sorted(oauth_params.iteritems()):
    formatted_params.append('%s="%s"' % (k, UrlEscape(v)))
  param_list = ','.join(formatted_params)
  if url_params:
    request_url = '%s?%s' % (request_url_base,
                             FormatUrlParams(url_params))
  else:
    request_url = request_url_base
  preencoded = '%s %s %s' % (method, request_url, param_list)
  print 'xoauth string (before base64-encoding):\n' + preencoded + '\n'
  return preencoded
def GenerateXOauthString ( consumer , access_token , user , proto , xoauth_requestor_id , nonce , timestamp ) : method = 'GET' url_params = { } if xoauth_requestor_id : url_params [ 'xoauth_requestor_id' ] = xoauth_requestor_id oauth_params = { } FillInCommonOauthParams ( oauth_params , consumer , nonce , timestamp ) if access_token . key : oauth_params [ 'oauth_token' ] = access_token . key signed_params = oauth_params . copy ( ) signed_params . update ( url_params ) request_url_base = ( 'https://mail.google.com/mail/b/%s/%s/' % ( user , proto ) ) base_string = GenerateSignatureBaseString ( method , request_url_base , signed_params ) print 'signature base string:\n' + base_string + '\n' signature = GenerateOauthSignature ( base_string , consumer . secret , access_token . secret ) oauth_params [ 'oauth_signature' ] = signature formatted_params = [ ] for k , v in sorted ( oauth_params . iteritems ( ) ) : formatted_params . append ( '%s="%s"' % ( k , UrlEscape ( v ) ) ) param_list = ',' . join ( formatted_params ) if url_params : request_url = '%s?%s' % ( request_url_base , FormatUrlParams ( url_params ) ) else : request_url = request_url_base preencoded = '%s %s %s' % ( method , request_url , param_list ) print 'xoauth string (before base64-encoding):\n' + preencoded + '\n' return preencoded