waitForNthEmail method

Future<Email?> waitForNthEmail({
  1. String? inboxId,
  2. int? index,
  3. int? timeout,
  4. bool? unreadOnly,
  5. DateTime? since,
  6. DateTime? before,
  7. String? sort,
  8. int? delay,
})

Wait for or fetch the email with a given index in the inbox specified. If index doesn't exist waits for it to exist or timeout to occur.

If nth email is already present in inbox then return it. If not hold the connection open until timeout expires or the nth email is received and returned.

Parameters:

  • String inboxId: Id of the inbox you are fetching emails from

  • int index: Zero based index of the email to wait for. If an inbox has 1 email already and you want to wait for the 2nd email pass index=1

  • int timeout: Max milliseconds to wait for the nth email if not already present

  • bool unreadOnly: Optional filter for unread only

  • DateTime since: Filter for emails that were received after the given timestamp

  • DateTime before: Filter for emails that were received before the given timestamp

  • String sort: Sort direction

  • int delay: Max milliseconds delay between calls

Implementation

Future<Email?> waitForNthEmail({ String? inboxId, int? index, int? timeout, bool? unreadOnly, DateTime? since, DateTime? before, String? sort, int? delay, }) async {
  final response = await waitForNthEmailWithHttpInfo( inboxId: inboxId, index: index, timeout: timeout, unreadOnly: unreadOnly, since: since, before: before, sort: sort, delay: delay, );
  if (response.statusCode >= HttpStatus.badRequest) {
    throw ApiException(response.statusCode, await _decodeBodyBytes(response));
  }
  // When a remote server returns no body with a status of 204, we shall not decode it.
  // At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
  // FormatException when trying to decode an empty string.
  if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) {
    return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'Email',) as Email;

  }
  return null;
}