Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best strategy to avoid to download all readed emails
#1
I can read emails with the idIMAP component with code like this:
    IMAP.SelectMailBox('INBOX');
    IMAP.StatusMailBox('INBOX', IMAP.MailBox);
    if IMAP.MailBox.UnseenMsgs  > 0 then ...

But, because the emails are over 3.000 (that increases about of 100 emails per month) this code:
    IMAP.SelectMailBox('INBOX');
runs for about three minutes and more.

This code read even the email readed even I don't want to do anymore.

I needs to repeat read new email ever 10 minutes but i will lost about 3 minutes every time due to IMAP.SelectMailBox('INBOX'); even I don't have new emails.

What is the best strategy to avoid to lost about 3 minutes every time i do: IMAP.SelectMailBox('INBOX');

Thanks
Reply
#2
(01-05-2022, 04:49 PM)luigisic Wrote: But, because the emails are over 3.000 (that increases about of 100 emails per month) this code:
    IMAP.SelectMailBox('INBOX');
runs for about three minutes and more.

That would make sense if you have the TIdIMAP4.RetrieveOnSelect property set to something other than rsDisabled, which would cause SelectMailBox() to download all headers/bodies in the selected mailbox.

(01-05-2022, 04:49 PM)luigisic Wrote: What is the best strategy to avoid to lost about 3 minutes every time i do: IMAP.SelectMailBox('INBOX');

Make sure RetrieveOnSelect is set to rsDisabled, so you can decide what you want to download and when. You can then use (UID)SearchMailBox() to search for just skUnseen/skNew messages and retrieve their IDs, then you can download the headers/bodies for just those IDs as needed.

Technically, a better solution is to use the IMAP IDLE command to let the IMAP server notify you in real-time whenever new emails arrive, instead of you having to poll for them periodically. However, TIdIMAP4 does not support that command yet (it is on the TODO list), but you could try implementing it yourself, if you want.

Reply
#3
(01-05-2022, 07:01 PM)rlebeau Wrote: Make sure RetrieveOnSelect is set to rsDisabled, so you can decide what you want to download and when.  You can then use (UID)SearchMailBox() to search for just skUnseen/skNew messages and retrieve their IDs, then you can download the headers/bodies for just those IDs as needed.

Ok, now i can read only new emails without wasting time howewer now, all emails I have found are automatically marked as readed but is not what I wont.

I need to read by software all new emails but mark readed only those email that match with some criteria like specific words on the Object of email or email that have specific attachments.

How I can mark as readed some emails and leave others untouched because they need to be read by others?

(01-05-2022, 07:01 PM)rlebeau Wrote: Technically, a better solution is to use the IMAP IDLE command to let the IMAP server notify you in real-time whenever new emails arrive, instead of you having to poll for them periodically.  However, TIdIMAP4 does not support that command yet (it is on the TODO list), but you could try implementing it yourself, if you want.

unfortunately, I don't have the skills Sad



I think I found the solution:

I can use RetrievePeek that not automatically mark the emails as readed and I can use StoreFlags to mark by software the emails that I worked.
Reply
#4
(01-06-2022, 06:39 PM)luigisic Wrote: I can use RetrievePeek that not automatically mark the emails as readed and I can use StoreFlags to mark by software the emails that I worked.

Sounds about right.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)