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.