emailToAscii function
Converts the domain part of an email address to Punycode-encoded ASCII.
Only the domain part (after the '@') is transformed. The local part is preserved as-is.
Implementation
String emailToAscii(String email, {bool validate = true}) {
final parts = email.split('@');
if (parts.length != 2) {
throw FormatException('Invalid email format: $email');
}
final localPart = parts[0];
final domainPart = parts[1];
return '$localPart@${domainToAscii(domainPart, validate: validate)}';
}