resume method

Future<void> resume({
  1. bool startPollingWhenError = true,
})

Resumes the mail client after a some inactivity.

Reconnects the mail client in the background, if necessary. Set the startPollingWhenError to false in case polling should not be started again when an error occurred.

Implementation

Future<void> resume({bool startPollingWhenError = true}) async {
  await _incomingLock.synchronized(() async {
    _incomingMailClient.log('resume mail client');
    try {
      await _incomingMailClient.stopPolling();
      await _incomingMailClient.startPolling(defaultPollingDuration);
    } catch (e, s) {
      _incomingMailClient.log('error while resuming: $e $s');
      // re-connect explicitly:
      try {
        await _incomingMailClient.reconnect();
        if (startPollingWhenError && !_incomingMailClient.isPolling()) {
          await _incomingMailClient.startPolling(defaultPollingDuration);
        }
      } catch (e2, s2) {
        _incomingMailClient.log(
          'error while trying to reconnect in resume: $e2 $s2',
        );
      }
    }
  });
}