waitForMatchingFirstEmail method

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

Wait for or return the first email that matches provided MatchOptions array

Perform a search of emails in an inbox with the given patterns. If a result if found then return or else retry the search until a result is found or timeout is reached. Match options allow simple CONTAINS or EQUALS filtering on SUBJECT, TO, BCC, CC, and FROM. See the MatchOptions object for options. An example payload is { matches: [{field: 'SUBJECT',should:'CONTAIN',value:'needle'}] }. You can use an array of matches and they will be applied sequentially to filter out emails. If you want to perform matches and extractions of content using Regex patterns see the EmailController getEmailContentMatch method.

Parameters:

  • String inboxId (required): Id of the inbox we are matching an email for

  • MatchOptions matchOptions (required):

  • int timeout: Max milliseconds to wait

  • 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?> waitForMatchingFirstEmail(String inboxId, MatchOptions matchOptions, { int? timeout, bool? unreadOnly, DateTime? since, DateTime? before, String? sort, int? delay, }) async {
  final response = await waitForMatchingFirstEmailWithHttpInfo(inboxId, matchOptions,  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;
}