[PHP-users 12217] Re: メール送信時の改行コードに関して

UNO Shintaro php-users@php.gr.jp
Thu, 12 Dec 2002 16:38:32 +0900


>> 私の経験則では、漢字コード (エンコードというべき?) や
>> 改行コードはフォームのそれと一致するというのが、
>> 一般的なブラウザの挙動のようです。
>
>一般的な話じゃないかも知れないのですが,Netscape/Mozilla で電子証明書
>関係で使う keygen タグってのがあるのですが,それでサーバ側に SPKAC 形
>式の CSR を送ります.
>
>その時,Linux 上で Netscape 4 だと "\n" が送られていたのですが,
>Netscape 6,7/Mozilla だと "\r\n"で送られていたというのがありました.


#とりあえず改行の話に限定してのご返事です。

クライアントの実装によって、 entity-body 内の改行コードは本当いろいろ
揺れますよねえ。
友人のサイトでは、同じサイトの同じフォームに送られてくる改行コードが
WindowsのブラウザとMacのブラウザで違うということが起きていました。

私はRFC2616(HTTP/1.1)の下記引用部分を根拠に、「\r\n」「\r」「\n」を
処理できれば十分(他はクライアント側のバグで基本的にはサーバ側対処の
範囲外)と考えてます。
「せっかくメッセージ系プロトコルの header/body 形式を踏襲してるんだか
ら、 text media の entity-body は改行コードを \r\n に揃えた方が良かっ
たんじゃないのか」と思ったりもしますけど(いまさら無理だろうなあ)。

>3.7.1 Canonicalization and Text Defaults
>
>   Internet media types are registered with a canonical form. An
>   entity-body transferred via HTTP messages MUST be represented in the
>   appropriate canonical form prior to its transmission except for
>   "text" types, as defined in the next paragraph.
>
>   When in canonical form, media subtypes of the "text" type use CRLF as
>   the text line break. HTTP relaxes this requirement and allows the
>   transport of text media with plain CR or LF alone representing a line
>   break when it is done consistently for an entire entity-body. HTTP
>   applications MUST accept CRLF, bare CR, and bare LF as being
>   representative of a line break in text media received via HTTP. In
>   addition, if the text is represented in a character set that does not
>   use octets 13 and 10 for CR and LF respectively, as is the case for
>   some multi-byte character sets, HTTP allows the use of whatever octet
>   sequences are defined by that character set to represent the
>   equivalent of CR and LF for line breaks. This flexibility regarding
>   line breaks applies only to text media in the entity-body; a bare CR
>   or LF MUST NOT be substituted for CRLF within any of the HTTP control
>   structures (such as header fields and multipart boundaries).

-- 
UNO Shintaro, 宇野 信太郎
mailto:uno@venus.dti.ne.jp
http://www.venus.dti.ne.jp/~uno/