使用纯.NET框架提取MIME主体
由于.NET Framework已经有了System.Net.Mime命名空间并且能够解析Http标头,我希望还应该有“标准”或“隐藏”方法来从消息(作为字符串或字符串传递)中提取mime主体(base64编码)溪流)。
在哪里?
PS 现在我使用正则表达式,但这不是那么有趣,也不是那么耐用...... PPS .Net框架3.5
Since .NET Framework already have System.Net.Mime namespace and is able to parse Http headers, I hope there should be also "standard" or "hidden" method to extract mime body (base64 encoded) from message (passed as a string or stream).
Where?
P.S. now I use regexps but that is not so interesting end not so durable...
P.P.S .Net Framework 3.5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您查看 MimeKit。它是一个完全托管的 (C#) MIME 解析器,速度非常快、非常强大且符合标准。
有一个名为 MIMER 的完全正则表达式实现,但解析消息所需的时间比 MimeKit 的解析器长 70 倍。
不存在用 C# 编写的 MIME 解析器比 MimeKit 更健壮或更快 - 哎呀,可能没有任何 C/C++ 解析器比 MimeKit 快(很多)(我已经针对一些最好的 C 解析器对 MimeKit 进行了基准测试)这与他们的表现相当)。
I would recommend taking a look at MimeKit. It is a fully managed (C#) MIME parser that is very very fast, very robust and standards-compliant.
There's a fully regex implementation called MIMER, but it takes 70x longer to parse a message than MimeKit's parser.
There exists no MIME parser written in C# that is more robust or faster than MimeKit - heck, there probably aren't any C/C++ parsers that are (much) faster than MimeKit (I've benchmarked MimeKit against some of the best C parsers and it is on par with their performance).
经过几个小时的反射器探索后,我在 .NET 框架中没有发现任何有趣的东西。
2 我发现HTTP headers parser也不是很有用,看看
WebHeaderCollection 的类,
内部 DataParseStatus ParseHeaders(byte[] buffer, int size, ref int unparsed, ref int totalResponseHeadersLength, int maxResponseHeadersLength, ref WebParseError parseError) 方法。它需要知道在哪里停止。这意味着准备。
I have not found any interesting inside .NET framework, after several hours of exploring with reflector.
2 I found that HTTP headers parser is also not very useful, have a look at
WebHeaderCollection's class,
internal DataParseStatus ParseHeaders(byte[] buffer, int size, ref int unparsed, ref int totalResponseHeadersLength, int maximumResponseHeadersLength, ref WebParseError parseError) method. It requires to know where to stop. That means preparsing.