Search code examples
emailmimeemail-validationemail-address

Safe delimiter for dsv of email addresses


I need to use/store a delimiter separated value string (not csv) of email addresses. I need to choose a delimiter that is safe.

E.g. bar@foo.com,baz@foo.com, - comma in this e.g. is unsafe as it's valid within an email address.

It seems that almost anything is allowed in an email address, especially now with internationalized email addresses.

What is a safe delimiter to use without jumping through hoops because of corner cases? I can't find a character in the RFC which which is expressly invalid (but there are lots of email related related RFCs, so I'm not sure which to consult).


Solution

  • I originally used \ because that is an escape character, however it is allowed if escaped. @MatWalker's answer recommends stuff like CR or LF etc, but those are allowed too, if they are escaped.

    Escaping and replacing and unescaping got a bit complicated. So right now I'm using control character STX (i.e. "Start of Text", decimal 2).

    Although the RFC doesn't mention (from what I've seen) whether control charactes are valid/invalid, there doesn't seem to be anything that makes it a bad choice. It does say that control chars are "discouraged", but not prohibited for header fields.