1

I am trying to create multiple html files that are associated with an email address. But since the "@" cannot be used in filenames, and in order to avoid confusion, I am trying to replace it with a character that won't normally exist in an email address.

Anything comes in mind?

Thanks!

Emilio
  • 1,314
  • 2
  • 15
  • 39

4 Answers4

2

Comma and semi-colon is not allowed in email address but in filenames on most file systems.

  • Good idea! but still not perfect :/ en.wikipedia.org/wiki/Email_address#Local_part – Emilio Jan 27 '17 at 15:38
  • 1
    I see, but then you get into problems with the double quote. I would do what is suggested in the comment to your question, encode it. Use url encoding, that should make a valid filename is most file systems, and easy to reverse, just url decode it. – Andreas Johansson Jan 27 '17 at 17:59
  • Yeah, I know I should probably do that, but it's too complicated for my purposes! Thanks! – Emilio Jan 27 '17 at 18:28
1

I believe '~' is used for this purpose.

Nicky
  • 83
  • 1
  • 12
  • Good idea! but still not perfect :/ en.wikipedia.org/wiki/Email_address#Local_part – Emilio Jan 27 '17 at 15:39
  • 1
    I can't stop wondering why you would need to create html files. It sounds like a dynamic page would do the trick. though I don't know the context, so I could be wrong. – Nicky Jan 27 '17 at 15:43
  • 1
    oops... I wrote "html" files, what I meant was "jpg" files. But yeah I think I will use the ~, because no character is perfect, and I was just looking for a quick and simple way to associate these files with email addresses. Thanks! – Emilio Jan 27 '17 at 18:24
1

According to the link here almost all ASCII characters are allow in email addresses so long as the special characters aren't at the beginning or the end.

What characters are allowed in an email address?

Community
  • 1
  • 1
  • Sad but true, seems like there is no perfect answer to my question :/ https://en.wikipedia.org/wiki/Email_address#Local_part – Emilio Jan 27 '17 at 15:16
1

Any of , (comma) ; (semi-colon) <> (angle brackets) [] (square brackets) or " (double quote) should work for most cases.

Since these characters are allowed in quoted strings, you could replace the "@" with a sequence that would be invalid such as three double quotes in a row.

According to the RFC

within a quoted string, any ASCII graphic or space is permitted without blackslash-quoting except double-quote and the backslash itself.

You could have an email abc."~~~".def@rst.xyz. But you could not have abc.""".def@rst.xyz; it would have to be abc.""".def@rst.xyz. So you could safely use """ as a substitute for @ in the filename.

However, the RFC also says

While the above definition for Local-part is relatively permissive, for maximum interoperability, a host that expects to receive mail SHOULD avoid defining mailboxes where the Local-part requires (or uses) the Quoted-string form or where the Local-part is case- sensitive.

With SHOULD meaning "...that there may exist valid reasons in particular circumstances when the particular behavior is acceptable or even useful, but the full implications should be understood and the case carefully weighed before implementing..." RFC2119

So, although """ will work, are the chances you will see an email with quotes worth the trouble of designing for it? If not, then use one of the single characters.

Community
  • 1
  • 1
cmerriman
  • 305
  • 1
  • 7
  • Good idea! but still not perfect :/ en.wikipedia.org/wiki/Email_address#Local_part – Emilio Jan 27 '17 at 15:39
  • 1
    The original question was "won't normally exist". And the wikipedia link states "Despite the wide range of special characters which are technically valid; organisations, mail services, mail servers and mail clients in practice often do not accept all of them" – cmerriman Jan 27 '17 at 15:52
  • Ok, then, which character do you think is the best? I was going to use the "~". Is there another character that is better? – Emilio Jan 27 '17 at 18:26
  • 1
    Too long for a comment so added to answer. – cmerriman Jan 27 '17 at 19:12
  • Ok! You definitely have the best answer! :D – Emilio Jan 27 '17 at 20:07