开发者

Creating files in a *nix environment with an email address as its name

PLEASE don't tell me why you think its a bad idea. Just tell me if its a workable idea.

I want to create files in a folder with names like the following:

a开发者_StackOverflow社区sdf@qwerty.com.eml
abc+def@asdf.net.eml
abc_def@sasdf.at.eml

Is there some fundamental incompatibility in the characters allowed in email addresses and those allowed by a unix system?

I will be having a bash script reading the file names, subtracting the ".eml" ending, converting it into the "correct" usable format and sending an email to the address.

A simple test showed that it saved the above as files called

asdf\@qwerty.com.eml
abc+def\@asdf.net.eml
abc_def\@sasdf.at.eml


The only characters not allowed in a *nix filename are \0 and /, neither of which is allowed in an email address anyways. How your shell may handle symbols is another matter.


There are no characters disallowed in UNIX file names except / (directory separator) and ASCII 0 (string terminator), so there is no problem at a fundamental level.

Handling those file names in shell scripts is a different matter; it requires at least quoting every variable reference as "$FILENAME", and forgetting even one quotatino will create a very rare, insidious bug. (Also, many other utilities will fail on strange characters such as | or newline unless you consistently use the -0 option.)

So yes, technically your bad idea is workable :-)


Short answer:

przemek@linux-634b:~/tmp/email> touch john.smith@example.com
przemek@linux-634b:~/tmp/email> ls
john.smith@example.com

Works perfectly;)

Long answer:

It depends on filesystem you're using. See Wikipedia entry which lists allowed characters in file names. Most UNIX file systems support all characters that can be included in e-mail addresses. Non-UNIX filesystems, such as FAT, however, may cause problems.

Note that your problems may come from improper escaping. Check how are you creating your files.


What was your "simple test"?

Typing abc and hitting tab? The bash autocompletion will add a \ before every special character. But this does not mean, it is stored with a \ in its name.

Use ls to see the true name.


There is no problem with such file names on systems which treat file names as blobs and allow all byte sequences, i.e. Linux. But they are not portable to systems which treat file names as Unicode strings and disallow certain characters (Windows) or transform file names (Mac OS X, canonical decomposition).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜