2

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).

Community
  • 1
  • 1
grokky
  • 8,537
  • 20
  • 62
  • 96

2 Answers2

1

Where/how will you be storing the string and what will the delimiter be used for?

You could use a non-visible ascii character such as the CR (Ascii 13) or Tab (Ascii 9).

Mat Walker
  • 45
  • 1
  • 7
  • Storing in a database. How did you arrive at those chars? [The spec](https://tools.ietf.org/html/rfc5322#section-3.5) mentions that ascii control chars are "discouraged" for the body, but does not say anything about the headers, So I assume that those are technically allowed in an email address? Doesn't make sense, admittedly, but we need to rely on the formal spec. – grokky May 30 '17 at 07:20
0

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.

grokky
  • 8,537
  • 20
  • 62
  • 96