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?
------=_NextPart_001_0011_01CB63DF.D39BA1C0
hints on the message being a multipart message with a header fieldContent-Type: multipart/....; boundary=----=_NextPart...
. Maybe you have to pass theContent-Type
header to the function that decodes the body so it knows what to do with the NextPart-thing. some additional info: en.wikipedia.org/wiki/MIME#Multipart_messages – User