4

With regard to my earlier question about accessing the 'sent items' folder in Gmail, the code presented in the accepted answer downloads all the message headers in the folder, using UIDRetrieveAllEnvelopes to do so. I filter the headers once they have all been downloaded.

Is there a way of downloading only the messages which have been sent in the current day (ie filtering before downloading)?

Community
  • 1
  • 1
No'am Newman
  • 6,395
  • 5
  • 38
  • 50

2 Answers2

2

There is no way to retrieve only the messages of a certain day in a certain folder.

The IMAP way is to cache the message/envelope and only retrieve the recent/new messages. Have a look at TIdIMAP4.StatusMailbox and TIdIMAP4.RetrieveFlags to examine, what messages are new to the client and download only those messages/enelopes.

Possible Flags are

  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.
Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
  • 1
    I would prefer to use a [`mailbox search`](http://stackoverflow.com/q/13612968/960757). Just instead of `skBody` search key with `Text` field I'd use the `skSentSince` key passing today's date to the `TIdIMAP4SearchRec.Date` field. – TLama Jun 29 '13 at 10:26
  • @TLama +1 - but AFAIK this is not limited to a special folder – Sir Rufo Jun 29 '13 at 10:46
  • 2
    @TLama: A search is the correct answer. A search is confined to the currently selected mailbox. So simply select the "sent items" mailbox and then perform a search. – Remy Lebeau Jun 29 '13 at 20:22
  • Some IMAP backends do support this directly via the IMAP `SEARCH UID` command. – tripleee Jun 30 '13 at 12:07
0

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; 
No'am Newman
  • 6,395
  • 5
  • 38
  • 50