authenticate method

  1. @override
Future<void> authenticate(
  1. ServerConfig serverConfig, {
  2. ImapClient? imap,
  3. PopClient? pop,
  4. SmtpClient? smtp,
})
override

Authenticates with the specified mail service

Implementation

@override
Future<void> authenticate(
  ServerConfig serverConfig, {
  ImapClient? imap,
  PopClient? pop,
  SmtpClient? smtp,
}) async {
  final userName = this.userName;
  final accessToken = token.accessToken;
  switch (serverConfig.type) {
    case ServerType.imap:
      await imap
          .toValueOrThrow('no [ImapClient] found')
          .authenticateWithOAuth2(userName, accessToken);
      break;
    case ServerType.pop:
      await pop
          .toValueOrThrow('no [PopClient] found')
          .login(userName, accessToken);
      break;
    case ServerType.smtp:
      await smtp
          .toValueOrThrow('no [SmtpClient] found')
          .authenticate(userName, accessToken, AuthMechanism.xoauth2);
      break;
    default:
      throw InvalidArgumentException(
        'Unknown server type ${serverConfig.typeName}',
      );
  }
}