IMAP 正文命令。如何只获取正文的文本或 html 部分?
我对 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.
电子邮件消息以 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.