Adobe Air javascript imap ssl - 无法发出“列表”命令 - 错误的未知命令

发布于 2024-12-28 00:02:05 字数 764 浏览 2 评论 0原文

我正在 Adob​​e Air 中编写一个应用程序来从 Gmail 获取电子邮件。我能够使用 SSL 连接并成功登录,但随后我无法继续提取电子邮件。我认为这是因为未维护 SSL 会话。每次我发出命令时,会话都会丢失。

要获取电子邮件,我必须发送登录请求,然后发送 LIST "" "*" 命令。但由于登录后连接中断,当我发送 LIST 命令时,它会作为一个新连接启动,并认为我尚未登录,并给出错误消息 a001 BAD Unknown command gf9if3619638pbc .89

代码如下。有什么想法可以实现这一点,或者这是否可能?

var socket;
function login() {
    socket = new air.SecureSocket();
    socket.connect('imap.gmail.com', 993);
    socket.writeUTFBytes("\n"+"a001 LOGIN username password");
    socket.addEventListener(air.ProgressEvent.SOCKET_DATA, socketDataHandler);
}

function fetchEmail() {
    socket = new air.SecureSocket();
    socket.connect(server, port);
    socket.writeUTFBytes("\n"+'a001 LIST "" "*"');
}

I am writing an application in Adobe Air to fetch emails from Gmail. I am able to connect with SSL and successfully login, but then I'm unable to proceed further in fetching emails. I think this is because the SSL session is not maintained. Each time i issue a command, the session is lost.

To fetch email, I have to send a login request and then a LIST "" "*" command. But since the connection breaks after login, when i send that LIST command, it starts as a new connection and thinks I haven't logged in, and give the error message a001 BAD Unknown command gf9if3619638pbc.89

The code is below. Any idea to implement this, or is this even possible?

var socket;
function login() {
    socket = new air.SecureSocket();
    socket.connect('imap.gmail.com', 993);
    socket.writeUTFBytes("\n"+"a001 LOGIN username password");
    socket.addEventListener(air.ProgressEvent.SOCKET_DATA, socketDataHandler);
}

function fetchEmail() {
    socket = new air.SecureSocket();
    socket.connect(server, port);
    socket.writeUTFBytes("\n"+'a001 LIST "" "*"');
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹤仙姿 2025-01-04 00:02:05

这并非特定于 SSL/TLS。在这里,当您想要记录时,您将创建一个新连接;当您想要获取电子邮件时,您将创建另一个新连接。就服务器而言,这是两个完全不同的连接。删除 fetchEmail() 中的这些行应该是一个开始:

socket = new air.SecureSocket();
socket.connect(server, port);

此外,您需要确保在 LOGIN 命令(或任何其他命令实际上),然后再继续执行下一个命令。

This is not specific to SSL/TLS. Here, you're creating a new connection when you want to log and another new connection when you want to fetch the e-mails. As far as the server is concerned, these are two completely distinct connections. Removing these lines in fetchEmail() should be a start:

socket = new air.SecureSocket();
socket.connect(server, port);

In addition, you'll need to make sure you get the appropriate response code after the LOGIN command (or any other command in fact) before proceeding to the next command.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文