使用 Indy 检查未读消息

发布于 2024-10-09 23:54:02 字数 968 浏览 0 评论 0原文

我只是为了好玩而在 Delphi 中做一个未读消息检查器应用程序。我正在使用 Indy 10。我可以连接 Gmail 并检索所有邮件,但我在这里遇到一个问题:我无法判断邮件是否已读。 TidMessage 组件中有一个 flag 属性,可以告诉我消息是否已被读取。 代码如下所示:

procedure TForm1.btTestConnectionClick(Sender: TObject);
var
 i: Integer;
 count: Integer;
 flag: TIdMessageFlags;
begin
 if (pop3Test.Connected) then begin
  pop3Test.Disconnect;
 end;

 pop3Test.Username := edAccount.Text;
 pop3Test.Password := edPassword.Text;
 pop3Test.Host := HOST;
 pop3Test.AuthType := patUserPass;
 pop3Test.Port := PORT;
 pop3Test.Connect;
 Count := 0;
 for i := pop3Test.CheckMessages downto 1 do begin
      pop3Test.Retrieve(i, IdMessage1);
      if (mfSeen in IdMessage1.Flags) then begin
       Count := Count + 1;
      end;
 end;


 ShowMessage(IntToStr(Count));
 pop3Test.Disconnect;
end;

在测试邮箱中,有一封未读邮件,但所有检索到的邮件的 flags 枚举属性均为空,因此结果始终为 0。我是否做错了什么?是 Indy/Gmail 兼容性问题吗?

谢谢。

编辑:我肯定做错了什么,因为使用 Hotmail 帐户进行测试显示了相同的空标志属性问题。

I'm doing just for fun an unread messages checker application in Delphi. I'm using Indy 10. I can connect with Gmail and can retrieve all the messages but I'm facing a problem here: I cannot tell if a message is already read or not. There is a flag property in the TidMessage component that should tell me if the message has been read.
The code looks like this:

procedure TForm1.btTestConnectionClick(Sender: TObject);
var
 i: Integer;
 count: Integer;
 flag: TIdMessageFlags;
begin
 if (pop3Test.Connected) then begin
  pop3Test.Disconnect;
 end;

 pop3Test.Username := edAccount.Text;
 pop3Test.Password := edPassword.Text;
 pop3Test.Host := HOST;
 pop3Test.AuthType := patUserPass;
 pop3Test.Port := PORT;
 pop3Test.Connect;
 Count := 0;
 for i := pop3Test.CheckMessages downto 1 do begin
      pop3Test.Retrieve(i, IdMessage1);
      if (mfSeen in IdMessage1.Flags) then begin
       Count := Count + 1;
      end;
 end;


 ShowMessage(IntToStr(Count));
 pop3Test.Disconnect;
end;

In the test mailbox there is one unread message but all the retrieved messages have the flags enum property empty so the result is always 0. Am I doing something wrong? Is it a problem of Indy/Gmail compatibility?

Thanks.

EDIT: I'm definitely doing something wrong as testing with a Hotmail account shows the same empty-flags property problem.

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

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

发布评论

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

评论(2

千紇 2024-10-16 23:54:02

POP3 协议不支持消息状态信息服务器喜欢读取、回复或删除。尝试改用 IMAP for Gmail

the POP3 protocol does not support Message state information on the server like read, replied to, or deleted . try using IMAP for Gmail instead.

伴我心暖 2024-10-16 23:54:02

找到这个答案的最好(也是最快)的方法是在 Indy 源代码中搜索“mfSeen”,您应该会发现它仅在 idIMAP* 单元中使用。 RRUZ 是正确的 - POP3 不提供这种固有的能力。在 POP3 中,您需要在客户端跟踪这一点。此标志添加到 IdMessage 是为了 IMAP 目的,而不一定是为了 POP3。

TIdMessageFlags 可能应该被命名为 TIdIMAPMessageFlags

The best (and quickest) way to find this answer would be to search the Indy sourcecode for "mfSeen" You should find it only utilized in idIMAP* units. RRUZ is correct - POP3 doesn't offer this inherent ability. In POP3 you need to track this on the client side. This flag was added to IdMessage for IMAP purposes, and not necessarily for POP3.

TIdMessageFlags should likely have been named TIdIMAPMessageFlags

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