Download only certain email headers from sent Gmail items using imap

As for my earlier question about accessing the sent items folder in Gmail, the code provided in the accepted answer downloads all the message headers in the folder using UIDRetrieveAllEnvelopes for this. I filter the headers as soon as they are downloaded.

Is there a way to download only those messages that were sent on the current day (for example, filtering before downloading)?

+4
source share
2 answers

It is not possible to receive only messages of a certain day in a specific folder.

The IMAP method is to cache the message / envelope and receive only the latest / new messages. Take a look at TIdIMAP4.StatusMailbox and TIdIMAP4.RetrieveFlags to check which messages are new to the client and download only those messages / enelopes.

Possible flags

  TIdMessageFlags = ( mfAnswered, //Message has been answered. mfFlagged, //Message is "flagged" for urgent/special attention. mfDeleted, //Message is "deleted" for removal by later EXPUNGE. mfDraft, //Message has not completed composition (marked as a draft). mfSeen, //Message has been read. mfRecent ); //Message is "recently" arrived in this mailbox. 
+2
source

I seem to have found a way

  today:= datetostr (date); with imap do begin Username:= ' whatever@gmail.com '; Password:= ....; Connect; if SelectMailBox('[Gmail]/sent items') then begin i:= MailBox.TotalMsgs; retrieve (i, email); while datetostr (email.date) = today do begin lb.items.add (email.subject + ' ' + datetostr (email.date)); dec (i); retrieve (i, email) end end; Disconnect; end; 
0
source

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


All Articles