"BAD无法解析命令"如果邮箱名称包含非英语符号,则返回 [英] "BAD Could not parse command" is returned if mailbox name contains non-English symbols
问题描述
我正在使用Chilkat.IMAP组件从IMAP服务器获取电子邮件.如果邮箱名称包含非英语符号,则返回"BAD无法解析命令":
I'm using Chilkat.IMAP components to get emails from IMAP servers. If a mailbox name contains non-English symbols, "BAD Could not parse command" is returned:
----IMAP REQUEST----
aaai LIST "[Gmail]/" "%"
----IMAP RESPONSE----
* LIST (\All \HasNoChildren) "/" "[Gmail]/All Mail"
* LIST (\HasChildren \Trash) "/" "[Gmail]/Bin"
* LIST (\Drafts \HasNoChildren) "/" "[Gmail]/Drafts"
* LIST (\HasNoChildren \Important) "/" "[Gmail]/Important"
* LIST (\HasNoChildren \Sent) "/" "[Gmail]/Sent Mail"
* LIST (\HasNoChildren \Junk) "/" "[Gmail]/Spam"
* LIST (\HasNoChildren) "/" "[Gmail]/&BB8EMAQ,BDoEMA-"
aaai OK Success
----IMAP REQUEST----
aaaj LIST "[Gmail]/All Mail/" "%"
----IMAP RESPONSE----
aaaj OK Success
----IMAP REQUEST----
aaap LIST "[Gmail]/Папка/" "%"
----IMAP RESPONSE----
aaap BAD Could not parse command
推荐答案
默认情况下,IMAP不会发送8位字符,并且原始协议将非英语ASCII字符的邮箱定义为UTF-7编码(进行了一些修改)).这是您看到的& BB8EMAQ,BDoEMA-
.
IMAP by default does not send 8-bit characters, and the original protocol defines mailboxes with non-English ASCII characters to be UTF-7 encoded (with some modifications). This is the &BB8EMAQ,BDoEMA-
you're seeing.
您可以将UTF-7编码/解码添加到应用程序中,或者,如果服务器足够新,则可以使用 ENABLE
UTF-8模式.注意:启用UTF-8可能会在您不希望看到的地方获得Unicode.Gmail确实支持此扩展程序.
You can either add UTF-7 encoding/decoding to your application, or, if your server is new enough, ENABLE
UTF-8 mode. Note: enabling UTF-8 may get you Unicode in places you do not expect. Gmail does support this extension.
> a LIST "" *
< ...
< * LIST (\HasChildren) "/" "&AOk-cole"
> b ENABLE UTF8=ACCEPT
< ...
< * LIST (\HasChildren) "/" "école"
这是UTF-7字符串分解的方式:
Here's how that UTF-7 string breaks down:
[Gmail]/&BB8EMAQ,BDoEMA-
&--移入和移出解码模式,所以看起来像
& and - shift in and out of decoding mode, so this looks like
"[Gmail]/" + mUTF7decode("BB8EMAQ,BDoEMA")
这是一个python 3 one liner对其进行解码.添加"==="以满足base64填充要求,并且 altchars
指定base64编码的最后两个字符:
And here's a python 3 one liner that decodes that. With "===" added to meet the base64 padding requirements, and the altchars
specifying the last two characters of the base64 encoding:
>>> import base64; base64.b64decode("BB8EMAQ,BDoEMA===", altchars="+,").decode("utf-16be")
'Папка'
这篇关于"BAD无法解析命令"如果邮箱名称包含非英语符号,则返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!