문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top