Extracting Content from MHT Document

六眼飞鱼酱① 提交于 2019-12-22 10:36:43

问题


Is anybody aware of any libraries for working with MHT files (Multi-Part MIME files) in .NET? I need to programmatically extract the contents from an existing MHT file containing a Flash website. I haven't been able to locate any such libraries.

Also, if there's a native way in .NET that I'm not aware of, please feel free to let me know.

EDIT: I know that the MailMessage class supports multi-part MIME messages through the AlternateViews property. The AlternateView class represents the alternative views in a multi-part MIME message. I'd like to believe that it's possible to use this knowledge to build something using code native to the .NET framework. I just haven't been able to find out the right combination to make it work, so I'm starting to loose faith. Does anybody out there know if it's possible to extract the contents of a MHT file through the AlternateView and other related classes? For example, it would be nice if it were possible to create an instance of the MailMessage class from a Stream.


回答1:


You might be interessed in my MIME parsing project at github (written in C#)

https://github.com/smithimage/MIMER/

Also has a Nuget package:

https://nuget.org/packages/MIMER/




回答2:


http://www.lumisoft.ee/lswww/ENG/Products/Mail_Server/mail_index_eng.aspx?type=info

This is open source email server which has good Mime Parser.




回答3:


David benko did a great job here his github project. I recently faced a this issue where I had an mhtml that needed to be converted to HTML file. for that I used HTMLAgility pack dll to extract content from the mhtml file and feed in this content to David's provided library:

string filePath = @"D:\Temp\myfile.mhtml";
var doc = new HtmlDocument();
doc.Load(filePath);
string mhtml = doc.DocumentNode.OuterHtml;
MHTMLParser parser = new MHTMLParser(mhtml);
string htmlContent = parser.getHTMLText();
System.IO.File.WriteAllText(@"D:\Temp\file.html", htmlContent);

I would really appreciate if someone could verify this approach. Cheers Vaqar



来源:https://stackoverflow.com/questions/1268486/extracting-content-from-mht-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!