电子邮件中有多少种Content-Type和Content-Encoding-Trafing以及如何解码?

发布于 2024-10-29 20:35:17 字数 83 浏览 4 评论 0原文

我正在使用 ImapX lib 接收来自 Gmail 的电子邮件。

我收到电子邮件正文的多种类型的内容类型和内容编码传输。 如何解码呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮坠入山谷 2024-11-05 20:35:17

MIME 标准记录在 RFC 2045 到 2048 中。您可能不想阅读所有这些标准,但在尝试处理 MIME 之前,您当然应该对 MIME 有基本的了解。 http://en.wikipedia.org/wiki/MIME 是一个很好的起点。

Content-Transfer-Encoding 可以具有五个不同值之一;其中,7bit8bitbinary 不需要任何解码(它们的不同之处在于您可以假设的字符集和行长度; 8bitbinary 之间的区别是 8bit 保证具有有限长度的行,尽管有时您确实会看到这种情况被违反; )。

对于 quoted-printablebase64 您需要解码;但任何相当现代的编程语言都已经有这方面的库函数。

Content-Type 层次结构基本上是无限的。顶级类型的数量有限(textimageaudioapplication 等)一组标准的子类型(text/plaintext/html 等),但正在注册更多子类型,并且标准不要求注册类型。无论如何,这些通常不需要解码;它们声明内容的类型,以便接收者知道如何处理它们。通用的包罗万象的是application/octet-stream,它基本上意味着“这里有一个数据块;希望人类接收者知道如何处理它”,并且对于许多类型来说,没有合理的默认值下载到本地磁盘以外的操作。所有通用电子邮件客户端都会直接向用户显示 text/plain,除非 Content-Disposition 另有要求,并且大多数现代客户端都会显示 text/html 和其他几种内联类型。但您想要对内容执行的操作首先取决于您正在编写的应用程序类型。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文