我是RESTful API的新手,也是处理MIME内容的新手。我正在尝试编写一个应用程序,以便从Gmail邮箱中检索邮件,以便进一步处理。
我使用Google Developers API参考作为工具来熟悉API。使用"试试"以下GMail API参考中的功能
https://developers.google.com/gmail/api/v1/reference/users/messages/get
我检索一条简单的测试消息,该消息只有2行文本。第一行包含简单的ASCII,而第二行包含一些Unicode文本。
This the first line of body text in English only
This is second line, 中文睇到嗎 , could you see those Chinese
并获得以下回复
"parts": [
{
"partId": "0",
"mimeType": "text/plain",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 120,
"data": "VGhpcyB0aGUgZmlyc3QgbGluZSBvZiBib2R5IHRleHQgaW4gRW5nbGlzaCBvbmx5DQoNClRoaXMgaXMgc2Vjb25kIGxpbmUsIOS4reaWh-edh-WIsOWXjiAsIGNvdWxkIHlvdSBzZWUgdGhvc2UgQ2hpbmVzZQ0K"
}
},
{
"partId": "1",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/html; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 354,
"data": "PGRpdiBkaXI9Imx0ciI-PGRpdiBjbGFzcz0iZ21haWxfZGVmYXVsdCIgc3R5bGU9ImZvbnQtZmFtaWx5OnRhaG9tYSxzYW5zLXNlcmlmIj5UaGlzIHRoZSBmaXJzdCBsaW5lIG9mIGJvZHkgdGV4dCBpbiBFbmdsaXNoIG9ubHk8L2Rpdj48ZGl2IGNsYXNzPSJnbWFpbF9kZWZhdWx0IiBzdHlsZT0iZm9udC1mYW1pbHk6dGFob21hLHNhbnMtc2VyaWYiPjxicj48L2Rpdj48ZGl2IGNsYXNzPSJnbWFpbF9kZWZhdWx0IiBzdHlsZT0iZm9udC1mYW1pbHk6dGFob21hLHNhbnMtc2VyaWYiPlRoaXMgaXMgc2Vjb25kIGxpbmUsIOS4reaWh-edh-WIsOWXjiAsIGNvdWxkIHlvdSBzZWUgdGhvc2UgQ2hpbmVzZTwvZGl2PjwvZGl2Pg0K"
}
}
]
正如你所看到的那样," content-transfer-encoding"被指定为" quoted-printable"返回的实际数据是base64url编码。
当我使用我的测试脚本通过GMail RESTful API检索消息时,我获得了相同的64baseurl编码响应。
所以我的问题是为什么"内容转移编码"之间存在分歧。在标题中反对实际的编码响应?我是否忽略了某些内容或者有其他参数/要求使其正确无误?
由于
编辑:根据@EricDeFriez的评论
如果我base64url解码'数据'字段
"VGhpcyB0aGUgZmlyc3QgbGluZSBvZiBib2R5IHRleHQgaW4gRW5nbGlzaCBvbmx5DQoNClRoaXMgaXMgc2Vjb25kIGxpbmUsIOS4reaWh-edh-WIsOWXjiAsIGNvdWxkIHlvdSBzZWUgdGhvc2UgQ2hpbmVzZQ0K"
似乎结果已经是原始的utf8编码文本:
This the first line of body text in English only
This is second line, 中文睇到嗎 , could you see those Chinese
如果它是引用可打印的'编码后,base64url解码的结果应如下所示:
This the first line of body text in English only
This is second line, =E4=B8=AD=E6=96=87=E7=9D=87=E5=88=B0=E5=97=8E , could =
you see those Chinese
似乎引用了可打印的' JSON响应中的CTE标头不正确。无论CTE标题中指定了什么,数据字段始终是base64url编码。
你知道原因吗?
答案 0 :(得分:1)
“数据”字段对于通过JSON原生传输不一定安全,因此它始终是base64url编码的。一旦你64位解码“数据”,它应该与CTE标题匹配。