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
2
1.2k
メールアドレスを深堀りする
Diving deep into the world of Email Address format
Hiroto Fukui
June 20, 2019
Tweet
Share
More Decks by Hiroto Fukui
See All by Hiroto Fukui
Deploy from slack
bary822
0
67
kiba ETLで小さく始めるデータ分析基盤構築
bary822
3
280
AR_migrationの例外.pdf
bary822
0
62
GraphQLを_Rubyで気軽に試す.pdf
bary822
0
330
Other Decks in Programming
See All in Programming
Gemini for developers
meteatamel
0
120
Ruby x Terminal
a_matsuda
2
170
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
1.1k
AIコーディングの理想と現実 2026 | AI Coding: Expectations vs. Reality 2026
tomohisa
0
550
NetBSD+Raspberry Piで 本物のPSGを鳴らすデモを OSC駆動の7日間で作った話 / OSC2026Osaka
tsutsui
1
120
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
22
8k
あなたはユーザーではない #PdENight
kajitack
4
270
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.5k
AIに仕事を丸投げしたら、本当に楽になれるのか
dip_tech
PRO
0
160
Head of Engineeringが現場で回した生産性向上施策 2025→2026
gessy0129
PRO
0
190
要求定義・仕様記述・設計・検証の手引き - 理論から学ぶ明確で統一された成果物定義
orgachem
PRO
1
390
Railsの気持ちを考えながらコントローラとビューを整頓する/tidying-rails-controllers-and-views-as-rails-think
moro
4
340
Featured
See All Featured
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
130
Believing is Seeing
oripsolob
1
67
A Modern Web Designer's Workflow
chriscoyier
698
190k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.7k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
230
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
190
Designing Experiences People Love
moore
144
24k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
Color Theory Basics | Prateek | Gurzu
gurzu
0
210
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
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する時は一旦立ち止まって考えよう