waitForEmailCount method
Wait for and return count number of emails. Hold connection until inbox count matches expected or timeout occurs
If inbox contains count or more emails at time of request then return count worth of emails. If not wait until the count is reached and return those or return an error if timeout is exceeded.
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 that 1
-
int timeout: Max milliseconds to wait
-
bool unreadOnly: Optional filter for unread only
-
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
Implementation
Future<List<EmailPreview>?> waitForEmailCount(String inboxId, int count, { int? timeout, bool? unreadOnly, DateTime? before, DateTime? since, String? sort, int? delay, }) async {
final response = await waitForEmailCountWithHttpInfo(inboxId, count, 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) {
final responseBody = await _decodeBodyBytes(response);
return (await apiClient.deserializeAsync(responseBody, 'List<EmailPreview>') as List)
.cast<EmailPreview>()
.toList();
}
return null;
}