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