开发者

Check unread messages with Indy

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 开发者_JAVA技巧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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜