encodedAddress property

String get encodedAddress

Returns the mail address with the domain encoded using IDNA (Punycode).

This properly handles internationalized domain names by:

  1. Normalizing Unicode to NFC
  2. Converting the domain to Punycode using emailToAscii

The local-part (before @) is not modified by emailToAscii.

Implementation

String get encodedAddress {
  try {
    if (!mailAddress.contains('@')) {
      return mailAddress;
    }

    // Normalize to NFC before encoding
    final normalized = unorm.nfc(mailAddress);

    return emailToAscii(normalized);
  } catch (_) {
    return mailAddress;
  }
}