waitForLatestEmail method

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

Fetch inbox's latest email or if empty wait for an email to arrive

Will return either the last received email or wait for an email to arrive and return that. If you need to wait for an email for a non-empty inbox set unreadOnly=true or see the other receive methods such as waitForNthEmail or waitForEmailCount.

Parameters:

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

  • int timeout: Max milliseconds to wait

  • bool unreadOnly: Optional filter for unread only.

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

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

  • String sort: Sort direction

  • int delay: Max milliseconds delay between calls

Implementation

Future<Email?> waitForLatestEmail({ String? inboxId, int? timeout, bool? unreadOnly, DateTime? before, DateTime? since, String? sort, int? delay, }) async {
  final response = await waitForLatestEmailWithHttpInfo( inboxId: inboxId, timeout: timeout, unreadOnly: unreadOnly, before: before, since: since, 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;
}