Reputation: 2251
I am using ImapX lib to recieve email from Gmail.
I get many type of Content-Type and Content-Encoding-Trafering of Body of email. How to decode it?
Upvotes: 1
Views: 576
Reputation: 189397
The MIME standards are documented in RFCs 2045 through 2048. You probably don't want to read all of them, but you certainly should have a basic understanding of MIME before you attempt to process it. http://en.wikipedia.org/wiki/MIME is a good starting point.
The Content-Transfer-Encoding
can have one of five distinct values; out of those, 7bit
, 8bit
, and binary
do not need any decoding (they differ in what you can assume about character sets and line lengths; the difference between 8bit
and binary
is that 8bit
is guaranteed to have lines of limited length; although you certainly see this violated in the wild sometimes).
For quoted-printable
and base64
you need decoding; but any reasonably modern programming language already has library functions for this.
The Content-Type
hierarchy is basically unlimited. There is a limited number of top-level types (text
, image
, audio
, application
, etc) and a standard set of subtypes (text/plain
, text/html
, etc) but more are being registered, and the standard doesn't require a type to be registered. Anyway, these do not typically need decoding; they declare the type of the content, so that the recipient knows what to do with them. The generic catch-all is application/octet-stream
which basically means "here is a blob of data; hopefully the human recipient knows what to do with this" and for many types, there is no sensible default action other than to download to the local disk. All general-purpose email clients will display text/plain
directly to the user, unless the Content-Disposition
requires otherwise, and most modern clients will display text/html
and several other types inline. But what you want to do with the content is first and foremost dictated by what kind of application you are coding.
Upvotes: 1