authenticateWithOAuth2 method

Future<GenericImapResult> authenticateWithOAuth2(
  1. String user,
  2. String accessToken
)

Logs in the user with the given user and accessToken via Oauth 2.0.

Note that the capability 'AUTH=XOAUTH2' needs to be present.

Implementation

Future<GenericImapResult> authenticateWithOAuth2(
    String user, String accessToken) async {
  final authText =
      'user=$user\u{0001}auth=Bearer $accessToken\u{0001}\u{0001}';
  final authBase64Text = base64.encode(utf8.encode(authText));
  final cmd = Command('AUTHENTICATE XOAUTH2 $authBase64Text');
  cmd.logText = 'AUTHENTICATE XOAUTH (base64 code scrambled)';
  final response = await sendCommand<GenericImapResult>(
      cmd, GenericParser(this, _selectedMailbox));
  isLoggedIn = true;
  return response;
}