authenticate method Null safety

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

Implementation

@override
Future<void> authenticate(ServerConfig serverConfig,
    {ImapClient? imap, PopClient? pop, SmtpClient? smtp}) async {
  final name = userName!;
  final pwd = password!;
  switch (serverConfig.type) {
    case ServerType.imap:
      await imap!.login(name, pwd);
      break;
    case ServerType.pop:
      await pop!.login(name, pwd);
      break;
    case ServerType.smtp:
      final authMechanism = smtp!.serverInfo.supportsAuth(AuthMechanism.plain)
          ? AuthMechanism.plain
          : smtp.serverInfo.supportsAuth(AuthMechanism.login)
              ? AuthMechanism.login
              : AuthMechanism.cramMd5;
      await smtp.authenticate(name, pwd, authMechanism);
      break;
    default:
      throw StateError('Unknown server type ${serverConfig.typeName}');
  }
}