ehlo method Null safety

Future<SmtpResponse> ehlo()

Issues the enhanced helo command to find out the capabilities of the SMTP server

EHLO or HELO always needs to be the first command that is sent to the SMTP server.

Implementation

Future<SmtpResponse> ehlo() async {
  final result = await sendCommand(SmtpEhloCommand(_clientDomain));
  for (final line in result.responseLines) {
    if (line.code == 250) {
      serverInfo.capabilities.add(line.message!);
      if (line.message!.startsWith('AUTH ')) {
        if (line.message!.contains('PLAIN')) {
          serverInfo.authMechanisms.add(AuthMechanism.plain);
        }
        if (line.message!.contains('LOGIN')) {
          serverInfo.authMechanisms.add(AuthMechanism.login);
        }
        if (line.message!.contains('CRAM-MD5')) {
          serverInfo.authMechanisms.add(AuthMechanism.cramMd5);
        }
        if (line.message!.contains('XOAUTH2')) {
          serverInfo.authMechanisms.add(AuthMechanism.xoauth2);
        }
      } else {
        serverInfo.capabilities.add(line.message!);
        if (line.message!.startsWith('SIZE ')) {
          final maxSizeText = line.message!.substring('SIZE '.length);
          serverInfo.maxMessageSize = int.tryParse(maxSizeText);
        }
      }
    }
  }
  return result;
}