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 {
  _incomingMailClient.log('resume mail client');
  try {
    await _incomingLock.synchronized(() async {
      await _incomingMailClient.stopPolling();
      await _incomingMailClient.startPolling(defaultPollingDuration);
    });
  } catch (e, s) {
    _incomingMailClient.log('error while resuming: $e $s');
    // re-connect explicitly, compare [reconnect] for why this must not
    // happen under the incoming lock:
    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',
      );
    }
  }
}