getMatch static method
MailAddress?
getMatch(
- List<
MailAddress> searchForList, - List<
MailAddress> ? searchInList, { - bool handlePlusAliases = false,
- bool removeMatch = false,
- bool useMatchPersonalName = false,
Searches the searchForList
addresses in the searchInList
list.
Set handlePlusAliases
to true
in case plus aliases should be checked, too.
Set removeMatch
to true
in case the matching address should be removed from the searchInList
list.
Set useMatchPersonalName
to true
to return the personal name from the searchInList
in the returned match. By default the personal name is retrieved from the matching entry in searchForList
.
Implementation
static MailAddress? getMatch(
List<MailAddress> searchForList, List<MailAddress>? searchInList,
{bool handlePlusAliases = false,
bool removeMatch = false,
bool useMatchPersonalName = false}) {
for (final searchFor in searchForList) {
final searchForEmailAddress = searchFor.email.toLowerCase();
if (searchInList?.isNotEmpty ?? false) {
MailAddress match;
for (var i = 0; i < searchInList!.length; i++) {
final potentialMatch = searchInList[i];
final matchAddress = getMatchingEmail(
searchForEmailAddress, potentialMatch.email.toLowerCase(),
allowPlusAlias: handlePlusAliases);
if (matchAddress != null) {
match = useMatchPersonalName
? potentialMatch
: MailAddress(searchFor.personalName, matchAddress);
if (removeMatch) {
searchInList.removeAt(i);
}
return match;
}
}
}
}
return null;
}