有没有办法知道哪个Content-Type是System.Net.Mail.MailMessage的主体? [英] Is there a way to know which Content-Type is the body of System.Net.Mail.MailMessage?

查看:97
本文介绍了有没有办法知道哪个Content-Type是System.Net.Mail.MailMessage的主体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有点死胡同了.
我有以下EML:

这是我的eml文件的一部分:

hello, i''m a bit in a dead end here.
i have the following EML:

this is part of my eml file:

------=_NextPart_001_0046_01CD587D.979ABFF0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

aaaaaaaaaaa

------=_NextPart_001_0046_01CD587D.979ABFF0
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
...
...




如您所见,我有一个正文(HTML)和一个备用视图(纯文本).
外部插件将整个EML解析为MailMessage对象.

问题是,我不知道我的身体是什么类型? (可以是html/plain/richtext/xml).

MailMessage具有isBodyHtml,可以很好地了解它的html,但如果它为false,则它可以是纯文本/richtext/xml,我需要知道它是什么

任何帮助将不胜感激.
谢谢!




as you can see, i have a body (which is HTML), and an alternate view (plain text).
outside plugin parses the entire EML into a MailMessage object.

the problem is, i have no idea what type is my body? (it can be html/plain/richtext/xml).

the MailMessage has isBodyHtml, which is fine to know if its html, but if its false - then it can be either plaintext/richtext/xml, and i need to know what is it

any help will be appreciated.
thanks!

推荐答案

由于它来自另一方,因此您不能依赖于哑剧类型.
嗅探数据流以确定其内容类型并不容易.它依赖于文件签名知识库,在此进行描述: http://www.garykessler.net/library/file_sigs.html [^ ]

urlmon.dll中有一个FindMimeFromData()函数,但这是非托管代码,因此您需要PInvoke,请参阅:魔术数字 [
这可能对您也很有趣:
小型内容检测库 [ ^ ]
As it comes from another party you can not rely on mime types told it.
Sniffing a data stream to determine it''s content type is not easy. It relies on the file signature knowledge base, described here: http://www.garykessler.net/library/file_sigs.html[^]

There is a FindMimeFromData() function in the urlmon.dll, but that is unmanaged code, thus you need PInvoke, see: http://www.dotnet247.com/247reference/msgs/26/133278.aspx[^]. It has it''s limitations, it can detect only 26 mime types. In linux there is an implementation called "magic numbers[^]".

This might be also interesting for you: A small Content Detection Library[^]


您可以检测它是html还是plian文本-没错.
但是,电子邮件最初不支持HTML和纯文本格式.

因此,您可以做的是将每条纯文本消息都视为富文本格式.这样,可以正确处理Richtext,也可以正确表示纯文本.

现在到XML:
那个有点难以发现. XML的格式如何?是在正文中吗?在这种情况下,您应该能够在文本的第一行中找到.

不能将其添加为附件吗?您使用起来会更轻松,更安全.
You can detect whether it is html or plian text - that''s right.
But Email does originally not support more foramts than HTML and plaintext.

SO what you can do is to treat each plaintext message like it''s a richtext. That way, richtext is processed correctly and plaintext is also represented correctly.

Now to the XML:
That one is a bit hard to detect. How well formatted is your XML? is it in the bodytext? IN that case you should be able to find a in the first row of text.

Can''t it be added as an attachment? Would be easier and safer for you to work with.


这篇关于有没有办法知道哪个Content-Type是System.Net.Mail.MailMessage的主体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆