如何正确使用AUTHENTICATE PLAIN连接IMAP?

时间:2011-08-25 14:28:18

标签: imap

我正在使用OpenSSL连接到邮件服务器。

POP3工作正常,但我的IMAP有问题。基于CAPABILITY命令服务器支持PLAIN,NTLM和GSS-API身份验证方法。

我想使用PLAIN,因为它比其他人更容易。 我已经读过它需要使用<NUL>

我已经运行了下一个版本,但没有成功:

? login user pass
? login <nul>user<nul>pass
? <nul>login <nul>user<nul>pass

我做错了什么?

3 个答案:

答案 0 :(得分:28)

以前的答案都没有实际说如何使用PLAIN身份验证,所以我做了一些挖掘。事实证明,在base64中预计会出现身份验证信息。通过示例解释可能最容易。假设用户名为“bob”,密码为“munchkin”。

我们首先需要在base64中编码。在Linux-ish系统上,它是这样的:

echo -en "\0bob\0munchkin" | base64

这根据需要包含空字符,并且还执行base64编码。我们得到了这个字符串:AGJvYgBtdW5jaGtpbg==

现在,我们可以进行实际身份验证(S =服务器,C =客户端):

S: * OK The Microsoft Exchange IMAP4 service is ready.
C: D0 CAPABILITY
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN CHILDREN IDLE NAMESPACE LITERAL+
S: D0 OK CAPABILITY completed.
C: D1 AUTHENTICATE PLAIN
S: +
C: AGJvYgBtdW5jaGtpbg==
S: D1 OK AUTHENTICATE completed

你已经完成了!

答案 1 :(得分:3)

May be this will help

/* RFC 4616.2. PLAIN SASL Mechanism.                
The mechanism consists of a single message, a string of [UTF-8]
encoded [Unicode] characters, from the client to the server.  The
client presents the authorization identity (identity to act as),
followed by a NUL (U+0000) character, followed by the authentication
identity (identity whose password will be used), followed by a NUL
(U+0000) character, followed by the clear-text password.  As with
other SASL mechanisms, the client does not provide an authorization
identity when it wishes the server to derive an identity from the
credentials and use that as the authorization identity.

message = [authzid] UTF8NUL authcid UTF8NUL passwd

Example:
C: a002 AUTHENTICATE "PLAIN"
S: + ""
C: {21}
C: <NUL>tim<NUL>tanstaaftanstaaf
S: a002 OK "Authenticated"
*/


IMAP not easy to code, literal string and xxx response formats ... .
It's easier to use some free IMAP client.

答案 2 :(得分:-1)

?登录mymailbox@box.zone mypassword \ r \ n

通常服务器不需要“@ box.zone”部分,您只需输入login

即可