Question

Trying to get emails from IMAP(gmail) and struggling with the last part.

If I fetch just message headers, for a 85 messages in my inbox, it took 3 seconds:

imap.fetch(message_ids, '(BODY.PEEK[HEADER.FIELDS (FROM TO CC SUBJECT DATE)])')

But if i try to fetch the email body, it takes ~3 minutes:

imap.fetch(message_ids, '(RFC822)')

or

imap.fetch(message_ids, '(BODY.PEEK[TEXT])')

or

imap.fetch(message_ids, 'RFC822.TEXT')

Already tried to set TCP_NODELAY as some thread suggested here. Same problem with imapClient lib and Twisted imap4 module

Any thoughts?

Was it helpful?

Solution

All of those will retrieve the full MIME content of the message, which can be quite large if they include attachments, and will take quite a while.

If you fetch BODYSTRUCTURE, you can parse the format/structure of the message, and get an idea of the size before you download it, and where exactly the main "body" part is.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top