Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the TIdMailBox.UnseenMsgs property return 0 value?

I'm trying to get the number of unread messages of my IMAP mailbox by using TIdIMAP4 from Indy 10.6.0.4975.

The problem is that the UnseenMsgs property returns 0 even when there are some unread messages in the accessed mailbox. This is the code I use:

procedure TForm1.FormClick(Sender: TObject);
var
  TotalMsgs: Integer;
  UnseenMsgs: Integer;
begin
  IdIMAP41.Connect(True);
  IdIMAP41.SelectMailBox('Inbox');

  TotalMsgs := IdIMAP41.MailBox.TotalMsgs; // returns correct value
  UnseenMsgs := IdIMAP41.MailBox.UnseenMsgs; // <- returns always 0

  IdIMAP41.Disconnect(False);
end;

Why does the TIdMailBox.UnseenMsgs property return 0 instead of proper number?

like image 243
JO SeongGng Avatar asked May 07 '15 14:05

JO SeongGng


1 Answers

Call the StatusMailBox method before you access that property. It is mentioned in the UnseenMsgs property documentation as:

UnseenMsgs is updated when the results from the TIdIMAP4.StatusMailBox method are parsed.

So do it like:

IdIMAP41.Connect(True);
IdIMAP41.SelectMailBox('Inbox');
IdIMAP41.StatusMailBox('Inbox', IdIMAP41.MailBox);

UnseenMsgs := IdIMAP41.MailBox.UnseenMsgs;
like image 128
TLama Avatar answered Oct 14 '22 01:10

TLama