Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
メールアドレスを深堀りする
Search
Hiroto Fukui
June 20, 2019
Programming
1.2k
2
Share
メールアドレスを深堀りする
Diving deep into the world of Email Address format
Hiroto Fukui
June 20, 2019
More Decks by Hiroto Fukui
See All by Hiroto Fukui
Deploy from slack
bary822
0
70
kiba ETLで小さく始めるデータ分析基盤構築
bary822
3
280
AR_migrationの例外.pdf
bary822
0
66
GraphQLを_Rubyで気軽に試す.pdf
bary822
0
340
Other Decks in Programming
See All in Programming
Rethinking API Platform Filters
vinceamstoutz
0
5.1k
Symfonyの特性(設計思想)を手軽に活かす特性(trait)
ickx
0
110
Laravel Nightwatchの裏側 - Laravel公式Observabilityツールを支える設計と実装
avosalmon
1
300
Java 21/25 Virtual Threads 소개
debop
0
320
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
310
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
220
Coding at the Speed of Thought: The New Era of Symfony Docker
dunglas
0
4.1k
実践ハーネスエンジニアリング #MOSHTech
kajitack
7
5.3k
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
4
1.5k
Linux Kernelの1文字のミスで 権限昇格ができた話
rqda
0
2.2k
それはエンジニアリングの糧である:AI開発のためにAIのOSSを開発する現場より / It serves as fuel for engineering: insights from the field of developing open-source AI for AI development.
nrslib
1
820
Coding as Prompting Since 2025
ragingwind
0
630
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
880
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
300
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
130
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
170
Balancing Empowerment & Direction
lara
5
1k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2.6k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
200
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.2k
Facilitating Awesome Meetings
lara
57
6.8k
Transcript
メールアドレスを 深堀りする Hiroto Fukui @bary822
self self.name => Hiroto Fukui self.sns => @bary822 self.titles =>
[‘app engineer’, ‘data engineer’] self.companies => [‘rakuten’, ‘grooves’] self.likes => [‘dog’, ‘camping’, ‘ruby’]
Osaka Tokyo
None
メールアドレス
[email protected]
[email protected]
ローカル部 (ユーザー名) ドメイン
[email protected]
とは 「example.comという(メール)サーバーに 登録されているhogeというユーザー」
RFC 5322 (Internet Message Format)
ローカル部 - ASCII - アルファベット(A-Z a-z) - 数字(0-9) - 記号(!
# $ % & ' * + - / = ? ^ _ ` { | } ~) - ドット(.) - ただし先頭、末尾以外 - 2個以上連続してはならない - “”で囲まれた特殊な記号 - ( ) < > [ ] : ; @ , - ドット(.) - 制限を受けない - スペース - \を付けた時のみ、\と”が単体で使える - h\\o\”
[email protected]
- いわゆるエスケープ
-
[email protected]
-
[email protected]
- user+mailbox/
[email protected]
- !#$%&'*+-/=?^_`.{|}
[email protected]
- "Abc@def"@example.com
- "Fred\ Bloggs"@example.com - "Joe.\\Blow"@example.com -
[email protected]
-
[email protected]
- hoge”
[email protected]
-
[email protected]
-
[email protected]
- user+mailbox/
[email protected]
- !#$%&'*+-/=?^_`.{|}
[email protected]
- "Abc@def"@example.com
- FredBloggs(a.k.a superman)@example.com - "Joe.\\Blow"@example.com -
[email protected]
-
[email protected]
- hoge”
[email protected]
ドメイン - アルファベット(A-Z a-z)、数字(0-9)またはハイフン(-)をドット(.)で繋いだ文字列 -
[email protected]
- [ ]で囲まれたIPアドレス -
hoge@[192.168.0.12] - 先頭と末尾はアルファベットか数字に限る
-
[email protected]
-
[email protected]
-
[email protected]
-
[email protected]
-
[email protected]
-
[email protected]
-
[email protected]
- hoge@com - hoge@exampl(e).com -
[email protected]
-
[email protected]
-
[email protected]
-
[email protected]
-
[email protected]
-
[email protected]
-
[email protected]
-
[email protected]
-
[email protected]
- hoge@com - hoge@exampl(e).com -
[email protected]
-
[email protected]
本当か?
None
None
None
なぜか
結局のところアプリ側のvalidationが統一されてない - RFCに準拠しているアプリのほうが珍しい - オレオレvalidationの横行 - みんな何となくでやってる
ネットワークレベルの独自仕様 ref: https://www.nttdocomo.co.jp/info/spam_mail/spmode/change_add/index.html
Railsでのプラクティス
自前実装 - Regexpで頑張る - /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i とかする - メンテが大変 - lib/validatorsに追加する
- EmailValidator#validate_each みたいなのを実装する
URI::MailTo::EMAIL_REGEXP を使う URI::MailTo::EMAIL_REGEXP => /\A[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61} [a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z/ - Rubyのstdlib - なかなか厳しい制約
-
[email protected]
は通ってしまう "
[email protected]
".match? URI::MailTo::EMAIL_REGEXP => true
Devise#email_regexp を使う Devise.email_regexp => /\A[^@\s]+@[^@\s]+\z/ - (デフォルトは)メチャメチャ緩い - 使うならカスタムして、アプリ全体で統一させると良さそう
専用gemを使う balexand/email_validator
gemを使う balexand/email_validator
v2.0.0 の衝撃
v2.0.0 の衝撃 @をスペース以外の文字列で挟めばOK
v2.0.0 の衝撃
v2.0.0 の衝撃
とはいえやっぱり validationしたい
None
real_world_email_validator (ほとんど)全てのメールシステムで動作することを目指す - 基本はRFC 5322に準拠 - プラスでいくつかの制限 - ローカル部 -
スペースは禁止 - バックスラッシュ(/)は禁止 - コメントは禁止 - ho(comment)
[email protected]
- ドメイン - トップレベルドメインのみは禁止 - hoge@com - コメントは禁止 - hoge@exam(comment)ple.com
Pull Request お待ちしています
まとめ - 「正しいメールアドレス」を定義するのは難しい - RFCが正だと思うのは危険 - validationする時は一旦立ち止まって考えよう