Search code examples
mime-typesmime

What is the specification for "attribute/value notation" mentioned in RFC 2046?


I'm looking for the rules on how to correctly parse MIME type strings. Note that this is required for use outside of email (in this case AMQP).

In RFC 2046 it refers to "attribute/value notation":

After the media type and subtype names, the remainder of the header field is simply a set of parameters, specified in an attribute=value notation.

I'm not sure if I'm missing something obvious in RFC 2046 or this is specified elsewhere, but I can't seem to find any syntax rules for this.

For example, can values be quoted? If so, which quotes are valid (' or ")? Also what white space is valid and how much?

Most things like this in RFCs usually have some BNF defining them, but I just don't see it for MIME type parameters.


Solution

  • The attribute=value part is actually defined in the RFC 2045 - 5.1. Syntax of the Content-Type Header Field as mentioned in the introduction of RFC 2046. There you see a detailed description of how attribute and value are defined:

     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>
    

    Where quoted-string is defined in RFC 882:

     quoted-string = <"> *(qtext/quoted-pair) <">; Regular qtext or
                                                 ;   quoted chars.