startTls method

Upgrades the current insure connection to SSL.

Opportunistic TLS (Transport Layer Security) refers to extensions in plain text communication protocols, which offer a way to upgrade a plain text connection to an encrypted (TLS or SSL) connection instead of using a separate port for encrypted communication.

Implementation

Future<GenericImapResult> startTls() async {
  final cmd = Command(
    'STARTTLS',
    writeTimeout: defaultWriteTimeout,
    responseTimeout: defaultResponseTimeout,
  );
  final response = await sendCommand<GenericImapResult>(
    cmd,
    GenericParser(this, _selectedMailbox),
  );
  log('STARTTLS: upgrading socket to secure one...', initial: 'A');
  await upgradeToSslSocket();
  // RFC 3501 section 6.2.1: the capabilities received before the upgrade
  // came over an unprotected connection and must be discarded.
  serverInfo.clearCapabilities();
  await capability();

  return response;
}