在 JavaScript 中解析 .msg 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15613957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 01:25:00  来源:igfitidea点击:

Parsing .msg files in JavaScript

javascriptjqueryoutlookemlmsg

提问by Wongadob

Does anybody know of any JavaScript libraries that will read/parse a microsoft .msg file. I am writing a system that requires a viewer to dispay .msg files that have been stored on a server. I will probably also have to do .eml in the future too. I am not using .net framework or ASP. the project is HTML/CSS/Javascript+JQuery only.

有谁知道任何可以读取/解析 microsoft .msg 文件的 JavaScript 库。我正在编写一个需要查看器来显示已存储在服务器上的 .msg 文件的系统。将来我可能也必须做 .eml 。我没有使用 .net 框架或 ASP。该项目仅适用于 HTML/CSS/Javascript+JQuery。

I would need to extract only e-mail addresses for recipients / sender, subject, attachments (file names not the actual files), body (text & html), date sent etc.

我只需要提取收件人/发件人的电子邮件地址、主题、附件(文件名而不是实际文件)、正文(文本和 html)、发送日期等。

回答by Markus Per?bner

The msg.readerlibrary seems to do the job.

msg.reader库似乎做的工作。

回答by Nestor Urquiza

I believe pure JS is not possible but with the help of node and linux on the server side we can.

我相信纯 JS 是不可能的,但是在服务器端的 node 和 linux 的帮助下,我们可以

It would be great if nodemailer and/or msg.readerlibrary could support HTML emails in msg format though.

如果 nodemailer 和/或msg.reader库可以支持 msg 格式的 HTML 电子邮件,那就太好了

回答by SliverNinja - MSFT

You will need a MSG and/or EML converter library. I've used Mailbee.NETwith success in the past, but Asposeor any other commercial library should work the same. Of course you could always code your own MSG parser by following the specifications, but wouldn't you rather be focused on your web solution?

您将需要一个 MSG 和/或 EML 转换器库。我过去曾成功地使用过Mailbee.NET,但Aspose或任何其他商业库应该也能正常工作。当然,您始终可以按照规范编写自己的MSG 解析器,但您难道不想专注于您的 Web 解决方案吗?

Once you have the library - just wrap it up in a service facade and build AJAX requests in JS to retrieve the model data for display using your UI framework. You will need some server page handler for handling these dynamic AJAX requests - node.js, ASPX, JSP, PHP, etc.

一旦你有了这个库——只需将它包装在一个服务外观中,并在 JS 中构建 AJAX 请求,以检索模型数据以使用你的 UI 框架进行显示。您将需要一些服务器页面处理程序来处理这些动态 AJAX 请求 - node.js、ASPX、JSP、PHP 等。

As a side note - it would be very inefficient to pull down the entire MSG to the client just to retrieve part of the metadata. Consider an MSG with 50MB worth of attachments - if you only need the filenames - you're application will be useless/slow until it downloads all 50MB. I don't think the browser (or users) would like that.

作为旁注 - 将整个 MSG 下拉到客户端只是为了检索部分元数据是非常低效的。考虑一个带有 50MB 附件的 MSG - 如果您只需要文件名 - 在下载所有 50MB 之前,您的应用程序将毫无用处/缓慢。我不认为浏览器(或用户)会喜欢那样。

回答by Dmitry Streblechenko

You can also use Redemption and its RDOSession.GetMessageFromMsgFilemethod. It is accessible in JavaScript (IE only), Java (through COM bridge) and any .Net language.

您还可以使用 Redemption 及其RDOSession.GetMessageFromMsgFile方法。它可以在 JavaScript(仅限 IE)、Java(通过 COM 桥)和任何 .Net 语言中访问。