Normalizing addresses - pzb/aws-ses GitHub Wiki

The syntax for addresses allows for a number of different ways to represent the same address. I strong recommend that you normalized all address before passing them to SES.

The following is one possible algorithm to normalize a Mailbox:

  1. If the Mailbox starts with @, then remove the @ and all characters until you find a :. Remove the :.
  2. Find the last @. If there is no @, then STOP. This is not a valid address.
  3. Take the portion of the Mailbox starting with the last @ and convert all uppercase characters to lowercase.
  4. If the Mailbox does not start with ", then STOP. You have a normalized address.
  5. If the character before the final @ is not a ", then STOP. This is not a valid address.
  6. Find all \ characters. If the character after the \ is not either a \ or a ", then remove the \.
  7. If the portion between the starting " and the " before the final @ consists of only letters (A to Z and a to z), digits (0 to 9), and the following characters !#$%&'*+-./=?^_`{|}~, then remove the " characters. You have a normalized addresses.

Examples

Original: [email protected] Normalized: [email protected]

Original: @bob,@sam:"sally.williams"@example.NET Normalized: [email protected]

Original: "sam:brown"@example.org Normalized: "sam:brown"@example.org