MIME RFC"Content-Type"参数混淆?不清楚RFC规范

Bas*_*Ben 17 mime specifications rfc rfc822

我正在尝试为multipart/relatedC++/Qt 实现一个基本的MIME解析器.

到目前为止,我一直在为头文件编写一些基本的解析器代码,我正在阅读RFC以了解如何尽可能接近规范来完成所有操作.不幸的是,RFC中有一部分让我感到困惑:

来自RFC882第3.1.1节:

每个标题字段可以被视为ASCII字符的单个逻辑行,包括字段名称和字段主体.为方便起见,该概念实体的场体部分可以分成多线表示; 这被称为"折叠".一般规则是,只要存在线性白空间(不仅仅是LWSP-chars),就可以替换地插入紧接着一个LWSP-char的CRLF.因此,单行

好吧,所以我简单地解析一个头字段,如果一个CRLF跟随线性空格,我只是以有用的方式连接它们以产生一个标题行.我们继续......

来自RFC2045第5.1节:

在RFC 822的Augmented BNF表示法中,Content-Type头字段值定义如下:

 content := "Content-Type" ":" type "/" subtype
            *(";" parameter)
            ; Matching of media type and subtype
            ; is ALWAYS case-insensitive.
Run Code Online (Sandbox Code Playgroud)

[...]

 parameter := attribute "=" value

 attribute := token
              ; Matching of attributes
              ; is ALWAYS case-insensitive.

 value := token / quoted-string

 token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
             or tspecials>
Run Code Online (Sandbox Code Playgroud)

好的.所以,如果您想要指定Content-Type带参数的标头,只需这样做:

Content-Type: multipart/related; foo=bar; something=else
Run Code Online (Sandbox Code Playgroud)

...并且相同标题的折叠版本看起来像这样:

Content-Type: multipart/related;
    foo=bar;
    something=else
Run Code Online (Sandbox Code Playgroud)

正确?好.在我不断阅读RFC时,我在RFC2387第5.1节(示例)中遇到了以下内容:

 Content-Type: Multipart/Related; boundary=example-1
         start="<950120.aaCC@XIson.com>";
         type="Application/X-FixedRecord"
         start-info="-o ps"

 --example-1
 Content-Type: Application/X-FixedRecord
 Content-ID: <950120.aaCC@XIson.com>

 [data]
 --example-1
 Content-Type: Application/octet-stream
 Content-Description: The fixed length records
 Content-Transfer-Encoding: base64
 Content-ID: <950120.aaCB@XIson.com>

 [data]

 --example-1--
Run Code Online (Sandbox Code Playgroud)

嗯,这很奇怪.你看到Content-Type头了吗?它有许多参数,但不是都有";" 作为参数分隔符.

也许我只是没有正确地读取RFC,但如果我的解析器严格按照规范定义的那样工作,那么typestart-info参数会导致单个字符串或更糟糕的解析器错误.

伙计们,你对此有何看法?只是RFC中的拼写错误?还是我错过了什么?

谢谢!

Rem*_*eau 16

这是一个错误的例子.参数必须始终用分号分隔,即使折叠也是如此.折叠并不意味着改变标题的语义,只是为了允许可读性并考虑具有行长度限制的系统.

  • 绝对是一个错字.这是BNF:`content:="Content-Type"":"type"/"subtype*(";"参数)`.http://tools.ietf.org/html/rfc2045#section-5.1. (2认同)