There are many MIME types that can be returned, here are a few:
- text/plain: the message body only in plain text
- text/html: the message body only in HTML
- multipart/alternative: will contain two parts that are alternatives for each othe, for example:
- a text/plain part for the message body in plain text
- a text/html part for the message body in html
- multipart/mixed: will contain many unrelated parts which can be:
- multipart/alternative as above, or text/plain or text/html as above
- application/octet-stream, or other application/* for application specific mime types for attachments
- image/png ot other image/* for images, which could be embedded in the message.
The definitive reference for all this is RFC 2046 https://www.ietf.org/rfc/rfc2046.txt (you might want to also see 2044 and 2045)
To answer your question, build a tree of the message, and look either for:
- the first text/plain or text/html part (either in the message body or in a multipart/mixed)
- the first text/plain or text/html inside of a multipart/alternative, which may be part of a multipart mixed.
An example of a complex message:
multipart/mixed
- multipart/alternative
- text/plain <- message body in plain text
- text/html <- message body in HTML
- application/zip <- a zip file attachment
-