Question

I want to get just email text body from Gmail(imap servers in general) without need to download the entire message.

if I fetch for RC822, I can get everything just fine:

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

But the problem is if I have too many messages and with attachments, it takes a lot of time.

I could get just the headers and text body I need with:

mail_box.fetch(message_ids, '(RFC822.HEADER BODY.PEEK[1])')

But this way I couldn't parse the text body, it has a weird format:

'\r\n------=_NextPart_001_0011_01CB63DF.D39BA1C0\r\nContent-Type: text/plain;\r\n\tcharset="iso-8859-1"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\nRafael, ...other content like html tags and css...------=_NextPart_001_0011_01CB63DF.D39BA1C0--\r\n'

Tried to parse it with email.message_from_string and quopri modules, but no luck so far.

Is it possible? To get messages formatted like RFC822 but without downloading attachments?

No correct solution

OTHER TIPS

The correct way is to request the BODYSTRUCTURE of the message and only fetch the relevant part.

In the comments you are suggesting that you have already fetched the BODYSTRUCTURE and that the part 1 corresponds to a text/plain MIME part. Please show us the whole, unprocessed BODYSTRUCTURE; without it, one cannot tell whether the IMAP server you are using is buggy or whether your understanding of the BODYSTRUCTURE is wrong.

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