Getting email body without fetching attachments using ruby mail gem
Asked Answered
C

1

6

I am trying to fetch the body of gmail using IMAP and ruby mail gem. It works perfectly while I fetch RFC822 field as described in another stack overflow answer.. Fiedl has described the approach very nicely to answer similar question.

This approach is great except it requires fetching RFC822 which also fetches all the attachments. Is there any other field or some other approach I can take not to fetch attachments but still use ruby mail gem to get the nicely decoded body?

Cantilever answered 12/6, 2013 at 16:57 Comment(4)
Does this do what you need in PHP? #15024790Angling
@crizCraig, This seems to fetch the body (not sure about php's fetch_body method though), which does not work for multipart emails.Cantilever
What about this (python) #15597929Raji
@jimt, I have already tried BODY[1], it doesn't work for all type of messages.Cantilever
C
0

You have to parse and understand the actual structure of the returned BODYSTRUCTURE response, see RFC 3501, p. 56. Also remember to apply the relevant Content-Transfer-Encoding (like base64 or quoted-printable) and employ proper charset conversion (the charset parameter of the Content-Type header of each body part). All of that information is included in the BODYSTRUCTURE response; consult your library's documentation to see how to get access to that.

Camper answered 14/6, 2013 at 16:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.