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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
74
kiba ETLで小さく始めるデータ分析基盤構築
bary822
3
280
AR_migrationの例外.pdf
bary822
0
67
GraphQLを_Rubyで気軽に試す.pdf
bary822
0
340
Other Decks in Programming
See All in Programming
開発とはなにか、Essenceカーネルで見えるもの
ukin0k0
0
160
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
150
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
1.2k
属人化しないコード品質の作り方_2026.04.07.pdf
muraaano
0
350
🦞OpenClaw works with AWS
licux
1
350
20260514 - build with ai 2026 - build LINE Bot with Gemini CLI
line_developers_tw
PRO
0
430
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
270
実用!Hono RPC2026
yodaka
2
310
Building on Bluesky's AT Protocol with Ruby
mackuba
0
120
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
420
空間オーディオの活用
objectiveaudio
0
150
From Formal Specification to Property Based Test
ohbarye
0
2.5k
Featured
See All Featured
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
180
The Invisible Side of Design
smashingmag
302
52k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1k
Crafting Experiences
bethany
1
140
How to train your dragon (web standard)
notwaldorf
97
6.6k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.9k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.9k
Docker and Python
trallard
47
3.8k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
360
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Scaling GitHub
holman
464
140k
The agentic SEO stack - context over prompts
schlessera
0
780
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する時は一旦立ち止まって考えよう