Why does the TIdMailBox.UnseenMsgs property return 0?

I am trying to get the number of unread messages in my IMAP mailbox using TIdIMAP4 from Indy 10.6.0.4975.

The problem is that the UnseenMsgs property returns 0, even if there are unread messages in the available mailbox. This is the code I'm using:

 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 TIdMailBox.UnseenMsgs property return 0 instead of the correct number?

+6
source share
1 answer

Call the StatusMailBox method before accessing this property. It is referred to in the UnseenMsgs documentation as:

UnseenMsgs is updated when the results of the TIdIMAP4.StatusMailBox method are analyzed.

So do this:

 IdIMAP41.Connect(True); IdIMAP41.SelectMailBox('Inbox'); IdIMAP41.StatusMailBox('Inbox', IdIMAP41.MailBox); UnseenMsgs := IdIMAP41.MailBox.UnseenMsgs; 
+8
source

Source: https://habr.com/ru/post/986750/


All Articles