SearchQueryBuilder.from constructor
SearchQueryBuilder.from(
- String query,
- SearchQueryType queryType, {
- SearchMessageType? messageType,
- DateTime? since,
- DateTime? before,
- DateTime? sentSince,
- DateTime? sentBefore,
Creates a common search query.
query contains the search text, define where to search
with the queryType.
Optionally you can also define what kind of messages to search
with the messageType,
the internal date since a message has been received with since,
the internal date before a message has been received with before,
the internal date since a message has been sent with sentSince,
the internal date before a message has been sent with sentBefore,
Implementation
SearchQueryBuilder.from(
String query,
SearchQueryType queryType, {
SearchMessageType? messageType,
DateTime? since,
DateTime? before,
DateTime? sentSince,
DateTime? sentBefore,
}) {
if (query.isNotEmpty) {
if (_TextSearchTerm.containsNonAsciiCharacters(query)) {
add(const SearchTermCharsetUf8());
}
switch (queryType) {
case SearchQueryType.subject:
add(SearchTermSubject(query));
break;
case SearchQueryType.from:
add(SearchTermFrom(query));
break;
case SearchQueryType.to:
add(SearchTermTo(query));
break;
case SearchQueryType.allTextHeaders:
add(SearchTermText(query));
break;
case SearchQueryType.body:
add(SearchTermBody(query));
break;
case SearchQueryType.fromOrSubject:
add(SearchTermOr(SearchTermFrom(query), SearchTermSubject(query)));
break;
case SearchQueryType.toOrSubject:
add(SearchTermOr(SearchTermTo(query), SearchTermSubject(query)));
break;
case SearchQueryType.fromOrTo:
add(SearchTermOr(SearchTermFrom(query), SearchTermTo(query)));
break;
}
}
if (messageType != null) {
switch (messageType) {
case SearchMessageType.all:
// ignore
break;
case SearchMessageType.flagged:
add(const SearchTermFlagged());
break;
case SearchMessageType.unflagged:
add(const SearchTermUnflagged());
break;
case SearchMessageType.seen:
add(const SearchTermSeen());
break;
case SearchMessageType.unseen:
add(const SearchTermUnseen());
break;
case SearchMessageType.deleted:
add(const SearchTermDeleted());
break;
case SearchMessageType.undeleted:
add(const SearchTermUndeleted());
break;
case SearchMessageType.draft:
add(const SearchTermDraft());
break;
case SearchMessageType.undraft:
add(const SearchTermUndraft());
break;
}
}
if (before != null) {
add(SearchTermBefore(before));
}
if (since != null) {
add(SearchTermSince(since));
}
if (sentBefore != null) {
add(SearchTermSentBefore(sentBefore));
}
if (sentSince != null) {
add(SearchTermSentSince(sentSince));
}
}