Closed7
メールアドレスの大文字・小文字は区別すべきか
![mythosil](https://res.cloudinary.com/zenn/image/fetch/s--xtCl9wdx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/0889f0c998.jpeg)
小文字に正規化すべき、という認識でいる。
ただ、その認識が本当に正しいのかちゃんと調査したことがない。
![mythosil](https://res.cloudinary.com/zenn/image/fetch/s--xtCl9wdx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/0889f0c998.jpeg)
RFC 5321では、Local-partは大文字・小文字を区別することもあるとされている。
Local-part = Dot-string / Quoted-string
; MAY be case-sensitive
![mythosil](https://res.cloudinary.com/zenn/image/fetch/s--xtCl9wdx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/0889f0c998.jpeg)
RFC 5321 2.4. General Syntax Principles and Transaction Modelから抜粋。
Therefore, SMTP implementations MUST take care to preserve the case
of mailbox local-parts. In particular, for some hosts, the user
"smith" is different from the user "Smith". However, exploiting the
case sensitivity of mailbox local-parts impedes interoperability and
is discouraged.
![mythosil](https://res.cloudinary.com/zenn/image/fetch/s--xtCl9wdx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/0889f0c998.jpeg)
現実的には大文字・小文字を区別しない実装がほとんど。
それらとの相互運用性を考えると、やはり大文字・小文字を区別しないのが望ましい。
このStackoverflowのスレッドで色々な意見が書かれていて参考になる。
![mythosil](https://res.cloudinary.com/zenn/image/fetch/s--xtCl9wdx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/0889f0c998.jpeg)
Firebase Authenticationでユーザーを作成してみた。Local-partを大文字で入力しても小文字で登録される。
![mythosil](https://res.cloudinary.com/zenn/image/fetch/s--xtCl9wdx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/0889f0c998.jpeg)
Microsoftアカウントを作成してみた。
メアドは大文字含んだまま登録された。 UPPERxxxxxx@outlook.com
みたいな感じ。
upperxxxxx@outlook.com
宛にメールを送信しても問題なく届く。
![mythosil](https://res.cloudinary.com/zenn/image/fetch/s--xtCl9wdx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_70/https://storage.googleapis.com/zenn-user-upload/avatar/0889f0c998.jpeg)
メアドの入力を受け付けるサービスの開発をする際には、入力されたメアドは小文字に正規化してしまうのが良さそう。
.
や +
など他にも考慮すべきものがあり、これらの扱い方は要件次第。
このスクラップは2022/11/02にクローズされました