IMAP 正文命令。如何只获取正文的文本或 html 部分?

发布于 12-07 16:28 字数 1487 浏览 0 评论 0原文

我对 FETCH...BODY[...] 命令有疑问。

获取正文的文本或 html 部分的最佳方法是什么?我认为 BODY[TEXT] 命令可以执行此操作,但它也会返回附件等,这严重影响性能。

目前,这就是我所做的(C# 代码):

        if (contentType != null)
        {
            switch (contentType.ToLower())
            {
                case "multipart/alternative":
                case "text/plain":
                case "text/html":
                    body = " BODY[1]";
                    break;
                case "multipart/related":
                case "multipart/signed":
                    body = " BODY[1.1]";
                    break;
                case "multipart/report":
                    body = " BODY[1]";
                    break;
                case "multipart/mixed":
                    if (mail.MailBody.TextBodyPartCount == 1)
                        body = " BODY[1]";
                    else if (mail.MailBody.TextBodyPartCount == 2)
                    {
                        if (bodyType == BodyType.Plain)
                            body = " BODY[1.1]";
                        else
                            body = " BODY[1.2]";
                    }
                    else
                        body = " BODY[1]";
                    break;
                default:
                    body = " BODY[1]";
                    break;
            }
        }
        else
        {
            body = " BODY[1]";
        }

这在大多数情况下都有效,但在某些情况下它会返回 NIL。抱歉,如果我遗漏了任何详细信息,请务必询问!

谢谢。

I have a query regarding the FETCH...BODY[...] command.

What is the best way to just obtain the text or html part of the body? I thought that the BODY[TEXT] command would do this but it is also returning attachments etc which is severely affecting performance.

Currently, this is what I do (C# code):

        if (contentType != null)
        {
            switch (contentType.ToLower())
            {
                case "multipart/alternative":
                case "text/plain":
                case "text/html":
                    body = " BODY[1]";
                    break;
                case "multipart/related":
                case "multipart/signed":
                    body = " BODY[1.1]";
                    break;
                case "multipart/report":
                    body = " BODY[1]";
                    break;
                case "multipart/mixed":
                    if (mail.MailBody.TextBodyPartCount == 1)
                        body = " BODY[1]";
                    else if (mail.MailBody.TextBodyPartCount == 2)
                    {
                        if (bodyType == BodyType.Plain)
                            body = " BODY[1.1]";
                        else
                            body = " BODY[1.2]";
                    }
                    else
                        body = " BODY[1]";
                    break;
                default:
                    body = " BODY[1]";
                    break;
            }
        }
        else
        {
            body = " BODY[1]";
        }

This works most of the time, but in some cases it returns NIL. Sorry if I have left any details out, but please do ask!

Thanks.

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

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

发布评论

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

评论(1

轮廓§2024-12-14 16:28:52

电子邮件消息以 MIME 格式存储 - 它允许创建具有无限深度的树结构。
您不能仅通过检查内容类型来假设此树结构的外观。

您应该使用 BODYSTRUCTURE 重新创建树结构而不下载消息,然后您可以决定需要获取哪些部分。

Email messages are stored in MIME format - it allows creating a tree structure with unlimited depth.
You can't assume how this tree structure looks like by only checking content-type.

You should use BODYSTRUCTURE to recreate the tree structure without downloading the message, and after that you can decide which parts you need to fetch.

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