Check unread messages with Indy
Asked Answered
J

2

5

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.

Jennefer answered 29/12, 2010 at 22:17 Comment(0)
D
13

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

Dilisio answered 29/12, 2010 at 22:29 Comment(1)
I have same problem with IMAP.Volitive
J
3

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

Jeans answered 30/12, 2010 at 5:32 Comment(1)
Renaming the flags type to an IMAP-specific name would mean creating an IMAP-specific version of TIdMessage, which is not ideal. We don't want to limit how coders use the flags. Just because POP3 does not support message flags in the protocol does not mean a coder does not. For instance, imagine a scenario where a list of TIdMessage objects are downloaded and then displayed. The coder could use the flags manually to indicate which messages in memory have been seen by the user., etcOlsewski

© 2022 - 2024 — McMap. All rights reserved.