电子邮件标签与本地部分和连字符
Email label vs local-part and hyphens
我一直在阅读 RFC、摘要、维基百科等。我对本地部分与标签非常困惑。在我看来,本地部分在@之前。这似乎很简单。标签是由点分隔的域的任何部分。但是在我看来,有些地方也将本地部分称为标签。在允许使用连字符的情况下,这非常令人困惑。那么具体什么是标签呢?
那么,其中哪些是有效的电子邮件地址(如果有)?
-bobross@painting.com
bobross-@painting.com
bobross@-painting.com
bobross@painting-.com
我的理解是标签既不能以连字符结尾也不能以连字符开头,并且不能包含两个连续的连字符。我错过了什么吗?
奖励积分 - 本地部分允许使用许多特殊字符,但我看到的一些消息来源说本地部分必须以字母数字字符结尾,但我实际上没有看到在任何标准中..我是否遗漏了它或者它可以以允许的字符之一结尾?
A domain name (or often just a "domain") consists of one or more
components, separated by dots if more than one appears. In the case
of a top-level domain used by itself in an email address, a single
string is used without any dots. This makes the requirement,
described in more detail below, that only fully-qualified domain
names appear in SMTP transactions on the public Internet,
particularly important where top-level domains are involved. These
components ("labels" in DNS terminology, RFC 1035 [2]) are restricted
for SMTP purposes to consist of a sequence of letters, digits, and
hyphens drawn from the ASCII character set [6]. Domain names are
used as names of hosts and of other entities in the domain name
hierarchy. For example, a domain may refer to an alias (label of a
CNAME RR) or the label of Mail eXchanger records to be used to
deliver mail instead of representing a host name. See RFC 1035 [2]
and Section 5 of this specification.
换句话说,abc.def.xyz
的域由 3 个 组件(又名 标签)组成:abc
、def
和 xyz
。每个 标签 只允许包含字母、数字和连字符。对于更具体的定义,我们必须检查 Command Argument Syntax 部分中的 ABNF 语法,因为我们真正关心的是 MAIL FROM
和 RCPT TO
命令的参数语法(又名“外行术语中的电子邮件地址”令牌)。
“电子邮件地址”在 SMTP 规范中实际上称为 Mailbox
:
Mailbox = Local-part "@" ( Domain / address-literal )
现在看一下 Local-part
令牌的定义:
Local-part = Dot-string / Quoted-string
; MAY be case-sensitive
Dot-string = Atom *("." Atom)
Atom = 1*atext
要获得 atext
的定义,我们需要查看 Internet Message Format. Specifically, we need to look at section 3.2.3:
atext = ALPHA / DIGIT / ; Printable US-ASCII
"!" / "#" / ; characters not including
"$" / "%" / ; specials. Used for atoms.
"&" / "'" /
"*" / "+" /
"-" / "/" /
"=" / "?" /
"^" / "_" /
"`" / "{" /
"|" / "}" /
"~"
(注意:我省略了 Quoted-string
的定义,因为它与您的问题无关。)
现在让我们检查一下 Domain
:
的定义
Domain = sub-domain *("." sub-domain)
sub-domain = Let-dig [Ldh-str]
Let-dig = ALPHA / DIGIT
Ldh-str = *( ALPHA / DIGIT / "-" ) Let-dig
我们在这里看到的是 label 与 sub-domain
标记相同,但在这里我们还看到 labels[= Domain
的 76=](又名 sub-domain
's)不能以连字符开头或结尾。
我们还可以看到 sub-domain
标记实际上是 Atom
中允许字符的子集,因此每个 组件 中允许的字符Local-part
与 Domain
.
的每个 组件 中允许的不同
回答您的其他问题:
And with that, which of these are valid email address (if any)?
-bobross@painting.com [VALID]
bobross-@painting.com [VALID]
bobross@-painting.com [INVALID]
bobross@painting-.com [INVALID]
My understanding is that a label can neither end or begin with a hyphen and it must not contain two consecutive hyphens. Am I missing anything with that?
让我们使用术语 sub-domain
来减少混淆。
是的,没错。
Bonus points - there are a number of special characters allowed in the local-part, but some sources I've seen say that the local-part must end in an alphanumeric character, but I'm not actually seeing that in any standard..am I missing it or can it end with one of the allowed characters?
嗯,根据rfc5322的ABNF语法,一个Local-part
可以同时以和以连字符结尾。
我一直在阅读 RFC、摘要、维基百科等。我对本地部分与标签非常困惑。在我看来,本地部分在@之前。这似乎很简单。标签是由点分隔的域的任何部分。但是在我看来,有些地方也将本地部分称为标签。在允许使用连字符的情况下,这非常令人困惑。那么具体什么是标签呢?
那么,其中哪些是有效的电子邮件地址(如果有)?
-bobross@painting.com
bobross-@painting.com
bobross@-painting.com
bobross@painting-.com
我的理解是标签既不能以连字符结尾也不能以连字符开头,并且不能包含两个连续的连字符。我错过了什么吗?
奖励积分 - 本地部分允许使用许多特殊字符,但我看到的一些消息来源说本地部分必须以字母数字字符结尾,但我实际上没有看到在任何标准中..我是否遗漏了它或者它可以以允许的字符之一结尾?
A domain name (or often just a "domain") consists of one or more
components, separated by dots if more than one appears. In the case
of a top-level domain used by itself in an email address, a single
string is used without any dots. This makes the requirement,
described in more detail below, that only fully-qualified domain
names appear in SMTP transactions on the public Internet,
particularly important where top-level domains are involved. These
components ("labels" in DNS terminology, RFC 1035 [2]) are restricted
for SMTP purposes to consist of a sequence of letters, digits, and
hyphens drawn from the ASCII character set [6]. Domain names are
used as names of hosts and of other entities in the domain name
hierarchy. For example, a domain may refer to an alias (label of a
CNAME RR) or the label of Mail eXchanger records to be used to
deliver mail instead of representing a host name. See RFC 1035 [2]
and Section 5 of this specification.
换句话说,abc.def.xyz
的域由 3 个 组件(又名 标签)组成:abc
、def
和 xyz
。每个 标签 只允许包含字母、数字和连字符。对于更具体的定义,我们必须检查 Command Argument Syntax 部分中的 ABNF 语法,因为我们真正关心的是 MAIL FROM
和 RCPT TO
命令的参数语法(又名“外行术语中的电子邮件地址”令牌)。
“电子邮件地址”在 SMTP 规范中实际上称为 Mailbox
:
Mailbox = Local-part "@" ( Domain / address-literal )
现在看一下 Local-part
令牌的定义:
Local-part = Dot-string / Quoted-string
; MAY be case-sensitive
Dot-string = Atom *("." Atom)
Atom = 1*atext
要获得 atext
的定义,我们需要查看 Internet Message Format. Specifically, we need to look at section 3.2.3:
atext = ALPHA / DIGIT / ; Printable US-ASCII
"!" / "#" / ; characters not including
"$" / "%" / ; specials. Used for atoms.
"&" / "'" /
"*" / "+" /
"-" / "/" /
"=" / "?" /
"^" / "_" /
"`" / "{" /
"|" / "}" /
"~"
(注意:我省略了 Quoted-string
的定义,因为它与您的问题无关。)
现在让我们检查一下 Domain
:
Domain = sub-domain *("." sub-domain)
sub-domain = Let-dig [Ldh-str]
Let-dig = ALPHA / DIGIT
Ldh-str = *( ALPHA / DIGIT / "-" ) Let-dig
我们在这里看到的是 label 与 sub-domain
标记相同,但在这里我们还看到 labels[= Domain
的 76=](又名 sub-domain
's)不能以连字符开头或结尾。
我们还可以看到 sub-domain
标记实际上是 Atom
中允许字符的子集,因此每个 组件 中允许的字符Local-part
与 Domain
.
回答您的其他问题:
And with that, which of these are valid email address (if any)?
-bobross@painting.com [VALID]
bobross-@painting.com [VALID]
bobross@-painting.com [INVALID]
bobross@painting-.com [INVALID]
My understanding is that a label can neither end or begin with a hyphen and it must not contain two consecutive hyphens. Am I missing anything with that?
让我们使用术语 sub-domain
来减少混淆。
是的,没错。
Bonus points - there are a number of special characters allowed in the local-part, but some sources I've seen say that the local-part must end in an alphanumeric character, but I'm not actually seeing that in any standard..am I missing it or can it end with one of the allowed characters?
嗯,根据rfc5322的ABNF语法,一个Local-part
可以同时以和以连字符结尾。