onCommandResult method

void onCommandResult(
  1. ImapResponse imapResponse
)

Implementation

void onCommandResult(ImapResponse imapResponse) {
  final line = imapResponse.parseText;
  final spaceIndex = line.indexOf(' ');
  if (spaceIndex != -1) {
    final commandId = line.substring(0, spaceIndex);
    final task = _tasks[commandId];
    if (task != null) {
      if (task == _currentCommandTask) {
        _currentCommandTask = null;
      }
      imapResponse.parseText = line.substring(spaceIndex + 1);
      final response = task.parse(imapResponse);
      if (response.isOkStatus) {
        task.completer.complete(response.result);
      } else if (!task.completer.isCompleted) {
        task.completer.completeError(ImapException(this, response.details));
      }
    } else {
      log('ERROR: no task found for command [$commandId]');
    }
  } else {
    log('unexpected SERVER response: [$imapResponse]');
  }
}