MsgLens

io.github.AndyLiu0427v0.2.1更新于 Oct 2, 2026

Read Outlook .msg, .eml and winmail.dat files locally: headers, body and attachments.

概览

AI 生成的概览

在本地读取 Outlook 的 .msg、.eml 和 winmail.dat 邮件文件,向助手提供邮件头、正文和附件。

功能
运行一个本地 stdio MCP 服务器,提供三个工具:read_email 返回主题、发件人、收件人、日期、纯文本正文和附件列表(可选原始邮件头);save_attachments 将每个附件写入指定文件夹;convert_email 把 .msg 或 winmail.dat 转换为 .eml 或 .txt。它根据文件字节判断格式,解压压缩的 RTF 正文,解包 TNEF 格式的 winmail.dat,并按邮件声明的代码页解码非拉丁正文。它还能读取保存的约会和联系人。
适用场景
当助手需要打开本机已有的邮件文件时适用,例如总结一封邮件、提取发票等附件,或把一批 .msg 文件转换为 .eml,且无需安装 Outlook、也不上传任何内容。
运行要求
需要 Node.js 20 或更高版本;该包通过 npx 在本地运行,或全局安装为 msglens-cli。未声明任何账号、API 密钥、环境变量或请求头,服务器也不发起网络请求。
安装前请注意
save_attachments 和 convert_email 会向你指定的文件夹写入文件;已有文件不会被覆盖,附件名会被简化为纯文件名,因此邮件无法写到输出文件夹之外。邮件正文和 HTML 内容来自发件人,属于不可信数据——工具会提示助手将其视为数据,渲染 HTML 前应先做净化处理。文件始终留在本机。

安装

在 SourceWeft 中

  1. 打开 控制台中的 MsgLens,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

msglens-cli

Read Outlook .msg, .eml and winmail.dat files from the command line, from Node, or from an AI assistant over MCP. Headers, the message body and attachments, with no Outlook and nothing uploaded.

These are the same parsers that run in the browser at msglens.app.

bash
npx msglens-cli read message.msg

Why another .msg parser

Most real Outlook mail does not store its body as HTML or plain text. In a sample of 20 business .msg files, 17 kept the body only in PidTagRtfCompressed: compressed RTF with the original HTML wrapped inside it (MS-OXRTFCP and MS-OXRTFEX). A parser that reads PidTagHtml and PidTagBody and stops returns an empty body for those messages. This one decompresses the RTF and un-wraps the HTML, falling back through PidTagHtml, PidTagBodyHtml, compressed RTF and PidTagBody in that order.

It also:

  • detects the format from the bytes, so a renamed file still opens
  • unpacks winmail.dat (TNEF), including the attachments trapped inside it
  • decodes non-Latin bodies with the message's declared code page
  • reads saved appointments and contacts, not only mail

CLI

Install it with npm install -g msglens-cli and the command is msglens; or run it without installing as npx msglens-cli.

text
msglens read <file...> [--json]            print headers and the plain-text bodymsglens attachments <file...> [-o <dir>]   save every attachmentmsglens convert <file...> --to eml|txt [-o <dir>]msglens mcp                                MCP server on stdio (see below)
  • read --json prints the full parsed message (one object for one file, an array for several). Attachment bytes are left out; names, types and sizes stay.
  • attachments and convert never overwrite: a second invoice.pdf is saved as invoice (1).pdf. Attachment names are reduced to a plain file name, so a message cannot write outside the output folder.
  • Several files at once work, and a file that fails is reported without stopping the rest. The exit code is 1 if any file failed.

Convert a folder of .msg files to .eml:

bash
npx msglens-cli convert ./mail/*.msg --to eml -o ./eml

MCP server for AI assistants

msglens mcp runs a Model Context Protocol server on stdio, so Claude, Codex, Cursor and other assistants can open email files on your machine themselves. It has three tools:

  • read_email: subject, sender, recipients, date, plain-text body and the attachment list (optionally the raw headers)
  • save_attachments: writes every attachment into a folder
  • convert_email: .msg or winmail.dat to .eml or .txt

The files stay on your machine; the server makes no network requests.

Claude Code

bash
claude mcp add msglens -- npx -y msglens-cli mcp

Codex (~/.codex/config.toml)

toml
[mcp_servers.msglens]command = "npx"args = ["-y", "msglens-cli", "mcp"]

Claude Desktop, Cursor and other JSON-configured clients

json
{  "mcpServers": {    "msglens": { "command": "npx", "args": ["-y", "msglens-cli", "mcp"] }  }}

Then ask, for example, "summarise ~/Downloads/invoice-query.msg and save its attachments to ~/Desktop/invoice".

Message text is written by whoever sent the email, so the tools tell the assistant to treat it as data and not to follow instructions inside it.

Library

ts
import { parseFile, parse, toEml, toText } from "msglens-cli";
const email = await parseFile("message.msg");email.subject;          // stringemail.from;             // { name, address } | nullemail.date;             // Date | nullemail.bodyText;         // plain text, always filledemail.body;             // HTML when email.bodyKind === "html"email.attachments;      // [{ fileName, mimeType, size, content: Uint8Array, isEmbeddedMessage, ... }]
const again = await parse(bytes, "message.msg"); // from a Uint8Array or ArrayBufferconst eml = await toEml(email);                   // RFC 822 text

email.body is the message's HTML exactly as the sender wrote it. It is untrusted: sanitise it (for example with DOMPurify) before rendering it anywhere.

An attachment with isEmbeddedMessage: true is a message attached to a message; pass its content to parse() to read it.

Requires Node 20 or later.

Want to just look at a file?

msglens.app opens .msg, .eml and winmail.dat in the browser, parsed on your device, with attachments and PDF export.

Licence

MIT. Microsoft and Outlook are trademarks of Microsoft Corporation; this project is not affiliated with Microsoft.

来源:cli/README.md,提交 4f04b7a

工具

0
工具元数据尚未被收录。

版本历史

1
  1. v0.2.1最新Oct 2, 2026