Reputation: 4501
I am writing an email client using IMAPClient. My goal now is to render the list of messages in my INBOX. The number of messages amount to around 4 thousand. The problem is that it takes ages to fetch these letters like this:
server = IMAPClient(HOST, use_uid=True, ssl=True)
server.login(USERNAME, PASSWORD)
server.select_folder('INBOX')
messages = server.search(['NOT DELETED'])
response = server.fetch(messages, ['RFC822', 'BODY[TEXT]']) # TAKES AGES TO FINISH
It seem intuitive that I should ask for, say, the first 20 messages, and then if the user scrolls down, ask for the next chunk of 20 messages (sorted by date when the letter has been received). In other words, I should somehow paginate the fetch
command, or make it lazy. But IMAPClient seems to be silent on this , though it seems like a major issue. Any ideas ?
Upvotes: 0
Views: 1250
Reputation: 2254
Your best bet is to break up messages
into chunks and just request the messages you need at the time.
In order to quickly build a message list for display to the user, you might want to consider requesting ENVELOPE
for all messages first. IMAP servers are generally optimised for this and the ENVELOPE
response is much smaller than the RFC822
or BODY[TEXT]
responses.
Upvotes: 1