Gmail API not respecting UTF encoding in subject

前端 未结 3 796
不思量自难忘°
不思量自难忘° 2021-01-18 19:29

In an app I\'m helping develop we\'ve added in the ability for a user to invite other users and personalize the invitation email, and then send it via Gmail\'s APIs. I\'m en

3条回答
  •  不要未来只要你来
    2021-01-18 20:00

    By the RFC Standard, Email subject MUST be in US ASCII (7-bit).

    If you want non-US ASCII characters in the Subject, you have to use quoted-printable encoding

    So your

    Subject: Нык ан мюндй конвынёры
    

    must become

    Subject: =?iso-8859-1?Q?=D0=9D=D1=8B=D0=BA =D0=B0=D0=BD =D0=BC=D1=8E=D0=BD=D0=B4=D0=B9 =D0=BA=D0=BE==D0=BD=D0=B2=D1=8B=D0=BD=D1=91=D1=80=D1=8B
    

    Edit Updated in response to the comment:

    RFC 822/RFC2822 (https://www.ietf.org/rfc/rfc0822.txt) Section 2.2 Header Fields says:

    Header fields are lines composed of a field name, followed by a colon (":"), followed by a field body, and terminated by CRLF. A field name MUST be composed of printable US-ASCII characters (i.e., characters that have values between 33 and 126, inclusive), except colon. A field body may be composed of any US-ASCII characters, except for CR and LF. However, a field body may contain CRLF when used in header "folding" and "unfolding" as described in section 2.2.3. All field bodies MUST conform to the syntax described in sections 3 and 4 of this standard.

    US-ASCII is referred to the original 7-bit ASCII encoding (0-127).

提交回复
热议问题