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:
- If the Mailbox starts with
@
, then remove the@
and all characters until you find a:
. Remove the:
. - Find the last
@
. If there is no@
, then STOP. This is not a valid address. - Take the portion of the Mailbox starting with the last
@
and convert all uppercase characters to lowercase. - If the Mailbox does not start with
"
, then STOP. You have a normalized address. - If the character before the final
@
is not a"
, then STOP. This is not a valid address. - Find all
\
characters. If the character after the\
is not either a\
or a"
, then remove the\
. - If the portion between the starting
"
and the"
before the final@
consists of only letters (A
toZ
anda
toz
), digits (0
to9
), 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