我一直在阅读RFC,摘要,维基百科等。我对本地部分与标签非常混淆。在我看来,本地部分在@之前。这看起来很简单。标签是由点分隔的域的任何部分。但在我看来,有些地方也将本地部分称为标签。在允许连字符的情况下,这是非常混乱的。那么具体什么是标签?
有了这些,哪些是有效的电子邮件地址(如果有的话)?
-bobross@painting.com
bobross-@painting.com
bobross@-painting.com
bobross@painting-.com
我的理解是标签既不能以连字符结尾也不能以连字符开头,并且不能包含两个连续的连字符。我错过了什么吗?
奖励积分 - 本地部分允许有许多特殊字符,但我见过的一些来源说本地部分必须以字母数字字符结尾,但我实际上并没有看到standard..am我错过了它还是以允许的字符之一结束?
答案 0 :(得分:2)
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
,{{1} }和def
。这些标签中的每一个都只允许包含字母,数字和连字符。对于更具体的定义,我们必须检查Command Argument Syntax部分中的ABNF语法,因为我们真正关心的是xyz
和MAIL FROM
命令的参数语法(也就是& #34;电子邮件地址"外行人的标记)。
"电子邮件地址"实际上在SMTP规范中称为RCPT TO
:
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
的定义,我们需要查看Internet Message Format。具体来说,我们需要查看section 3.2.3:
atext
(注意:我已经忽略了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
令牌相同,但在这里我们也看到标签(又名{{1 sub-domain
的{{1}}无法以连字符开头或结尾。
我们还可以看到sub-domain
令牌实际上是Domain
中允许字符的子集,因此每个组件中允许的字符为{{1}与sub-domain
的每个组件中允许的内容不同。
回答您的其他问题:
有了这些,哪些是有效的电子邮件地址(如果有的话)?
Atom
我的理解是标签既不能以连字符结尾也不能以连字符开头,并且不能包含两个连续的连字符。我错过了什么吗?
让我们使用术语Local-part
来减少混乱。
是的,这是正确的。
奖励积分 - 本地部分允许使用一些特殊字符,但我见过的一些消息来说,本地部分必须以字母数字字符结尾,但我实际上并不是在任何标准中看到它...我错过了它还是以允许的字符之一结束?
嗯,根据rfc5322的ABNF语法,Domain
可以用连字符开始和结束。