waitForMatchingEmails method

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

Wait or return list of emails that match simple matching patterns

Perform a search of emails in an inbox with the given patterns. If results match expected count then return or else retry the search until results are 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 fetching emails from

  • int count (required): Number of emails to wait for. Must be greater or equal to 1

  • MatchOptions matchOptions (required):

  • DateTime before: Filter for emails that were received before 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

  • int timeout: Max milliseconds to wait

  • bool unreadOnly: Optional filter for unread only

Implementation

Future<List<EmailPreview>?> waitForMatchingEmails(String inboxId, int count, MatchOptions matchOptions, { DateTime? before, DateTime? since, String? sort, int? delay, int? timeout, bool? unreadOnly, }) async {
  final response = await waitForMatchingEmailsWithHttpInfo(inboxId, count, matchOptions,  before: before, since: since, sort: sort, delay: delay, timeout: timeout, unreadOnly: unreadOnly, );
  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) {
    final responseBody = await _decodeBodyBytes(response);
    return (await apiClient.deserializeAsync(responseBody, 'List<EmailPreview>') as List)
      .cast<EmailPreview>()
      .toList();

  }
  return null;
}