Where to find body of email depending of mimeType

后端 未结 5 1881
小蘑菇
小蘑菇 2020-12-01 09:53

I am making a request to the User.messages endpoint. All objects returned (the emails) have a mimeType property which I\'m struggling to understand.

More specificall

5条回答
  •  爱一瞬间的悲伤
    2020-12-01 10:28

    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
    • -

提交回复
热议问题