I connect to the mailbox via IMAP, everything is fine, I get the number of letters in the Inbox ("INBOX"), I can read them. But there is a problem - the Retrieve method does not mark the letters as read, and the next time I read the mail, I see these letters as unread again - respectively, and they are loaded along with the new ones. On the Internet I found a description of the method, it is written that Retrieve marks the letters after downloading as read (so that the letters are not marked as read there is a RetrievePeek method).

Here is the procedure code:

procedure TForm1.FormCreate(Sender: TObject); var MsgCnt, i: integer; msg: TIdMessage; begin try msg := TIdMessage.Create(nil); msg.CharSet := 'windows-1251'; msg.ContentType := 'text/plain; charset="windows-1251"'; IdIMAP41.Host := 'imap.gmail.com'; IdIMAP41.Port := 993; IdIMAP41.Username := '***@gmail.com'; IdIMAP41.Password := '*****'; IdIMAP41.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(IdIMAP41); IdIMAP41.UseTLS := utUseImplicitTLS; IdIMAP41.Connect; IdIMAP41.SelectMailBox('INBOX'); MsgCnt := IdIMAP41.MailBox.TotalMsgs; ShowMessage('Кол-Π²ΠΎ писСм Π² ящикС: ' + IntToStr(MsgCnt)); for i := 1 to MsgCnt do begin IdIMAP41.Retrieve(i, msg); if msg.Subject = 'Need' then begin Memo1.Lines.Add(msg.Subject); Memo1.Lines.AddStrings(msg.Body); end; end; IdIMAP41.Disconnect; IdIMAP41.IOHandler.Free; except on e: Exception do ShowMessage('ошибка чтСния писСм!'); end; end; 

I hope someone faced with Indy IMAP and tell you what to do.

    3 answers 3

    The author and all who have such a mistake, pay attention to the Indy version. I have indie 10 on Delphi 7-ke. Everything works - the code is viable and messages are marked as read. Test mail.ru passed. and for i: = 1 to MsgCnt do will look at letters starting with the old ones. and for i: = MsgCnt downto 1 do will look from the last received and to the older ones.

      For some reason I can not write a comment, I will write in response. Try a box on another mail server mail.ru, hotmail.com, etc. Google may have its own troubles, the opera's mail client is always buggy with their drawers.

      • When the problem appeared, immediately tried with yandex mail - the same thing. Letters are all new every time. - xinferum

      It is necessary to use not
      IdIMAP41.MailBox.TotalMsgs
      but
      IdIMAP41.MailBox.RecentMsgs .
      Then shows the number of last sent letters.