
mboxshell v0.6.2
mboxShell。适用于任意大小 MBOX 文件的快速终端查看器。无需加载到内存,即可打开、搜索和导出 Gmail Takeout 备份(50GB+)中的电子邮件。使用 Rust 构建。
mboxShell
面向任意规模 MBOX 文件的快速终端查看器。无需加载到内存,即可打开、搜索和导出 Gmail Takeout 备份(50 GB 以上)中的电子邮件。
为什么会有这个项目
当你通过 Google Takeout 从 Gmail 导出电子邮件时,会得到一个或多个可能重达数十 GB 的 .mbox 文件。目前没有一款跨平台的终端工具能够高效地打开、搜索和浏览这些文件,同时又不将它们的全部内容加载到内存中。
mboxShell 就是为解决这个问题而生的:几秒钟内打开 50 GB 的 MBOX,流畅浏览成千上万封邮件,按发件人、日期或内容搜索,并导出你需要的任何内容。全部在终端中完成,无需 GUI、无需服务器、没有外部依赖。
使用场景
- 浏览 Gmail 备份(Google Takeout),保留原始标签
- 分析邮件归档,适用于服务器、迁移或审计场景
- 搜索来自任何来源(Thunderbird、Unix 服务器等)的 MBOX 文件中的邮件
- 导出邮件为 EML、CSV 或纯文本,以便进一步处理
- 提取附件,可单个或批量
- 合并多个 MBOX 文件为一个文件,并去除重复
另有 Mac 版本:mboxViewer
如果你更倾向于在 macOS 上使用原生图形体验,请查看 mboxViewer —— 一个由同一团队打造的原生 Mac 应用。它提供熟悉的邮箱风格界面,可以直接打开、浏览和搜索 MBOX 文件,而无需将其导入邮件客户端。拖放你的 .mbox 文件,即可在一个简洁的 macOS 原生窗口中即时访问所有邮件、附件和标签。非常适合希望拥有 mboxShell 解析引擎能力、同时享受桌面 GUI 便利的用户。
也可在浏览器中使用:Online Mbox Viewer
需要在不安装任何东西的情况下快速查看 MBOX 文件?试试 Online Mbox Viewer —— 一个由同一位作者开发的、免费且基于 MIT 许可的 Web 应用。它完全在你的浏览器中打开并渲染 .mbox 文件:不会向任何服务器上传内容,因此你的电子邮件始终留在本机。非常适合在任何设备上快速查看。源代码位于 github.com/dcarrero/online-mbox-viewer。
功能特性
- 绝不将文件完全加载到内存。 使用带 1 MB 缓冲区的流式 I/O。100 GB 的 MBOX 与 1 GB 的 MBOX 消耗的 RAM 大致相同,约 500 MB(只有元数据索引驻留在内存中)。
- 持久化索引。 首次打开会创建二进制索引(
.mboxshell.idx),因此后续打开只需不到一秒钟。 - 完整的 Gmail 支持。 检测
X-Gmail-Labels并将其作为虚拟文件夹显示在侧边栏中,允许你按收件箱、已发送、已加星标、自定义标签等进行筛选。 - 正确的字符编码。 解码 RFC 2047 编码文本,支持 UTF-8、ISO-8859-1、Windows-1252、KOI8-R,以及
encoding_rs识别的任何字符集。 - 会话线程分组。 使用 JWZ 算法(与 Netscape/Mozilla 使用的算法相同)将邮件分组为会话线程。
- 高级搜索。 按字段筛选(
from:、subject:、date:、body:、has:attachment、label:等)、日期范围、大小筛选、AND/OR 运算符以及取反。 - 灵活的导出。 单个或批量导出为 EML、CSV(兼容 Excel)、纯文本。支持解码后的附件提取。
- 单一可执行文件。 无需运行时、无依赖。约 5 MB 的可执行文件,可在 Linux、macOS 和 Windows 上运行。
- 完整的终端界面。 键盘导航(vi 风格)、三种布局模式、交互式搜索栏、可配置快捷键。
- 双语支持。 界面支持英语和西班牙语,并根据系统区域设置自动检测。
安装
预编译二进制文件(推荐)
从 Releases 页面下载适用于你平台的最新版本:
| Platform | Binary |
|---|---|
| Linux x86_64 | mboxshell-linux-x86_64 |
| Linux ARM64 | mboxshell-linux-aarch64 |
| Linux RISC-V 64 | mboxshell-linux-riscv64 |
| FreeBSD x86_64 | mboxshell-freebsd-x86_64 |
| macOS Intel | mboxshell-macos-x86_64 |
| macOS Apple Silicon | mboxshell-macos-aarch64 |
| Windows x86_64 | mboxshell-windows-x86_64.exe |
| Windows ARM64 | mboxshell-windows-arm64.exe |
下载后,将其设为可执行文件并移动到你的 PATH 中:
# Linux / macOS
chmod +x mboxshell-*
sudo mv mboxshell-* /usr/local/bin/mboxshell
# Or place it in a user-local directory
mv mboxshell-* ~/.local/bin/mboxshell
在 Windows 上,将 mboxshell-windows-x86_64.exe 移动到你的 PATH 中的某个文件夹,或直接运行它。
从源码构建
要求:Rust 1.85 或更高版本。
# Clone and build
git clone https://github.com/dcarrero/mboxshell.git
cd mboxshell
cargo build --release
# The binary is at target/release/mboxshell
# Install it system-wide:
sudo cp target/release/mboxshell /usr/local/bin/
# Or for the current user only:
cp target/release/mboxshell ~/.local/bin/
为其他平台交叉编译
# Add the target you need
rustup target add aarch64-apple-darwin # macOS Apple Silicon
rustup target add x86_64-unknown-linux-gnu # Linux x86_64
rustup target add aarch64-unknown-linux-gnu # Linux ARM64
# Build for a specific target
cargo build --release --target aarch64-apple-darwin
通过 Cargo 安装
cargo install --git https://github.com/dcarrero/mboxshell.git
快速开始
# Open an MBOX file in the terminal UI
mboxshell mail.mbox
# Index and show statistics
mboxshell index mail.mbox
mboxshell stats mail.mbox
# Search from the command line
mboxshell search mail.mbox "from:[email protected] date:2024"
mboxshell search mail.mbox "has:attachment subject:invoice" --json
# Export messages
mboxshell export mail.mbox --format eml --output ./emails/
mboxshell export mail.mbox --format csv --output summary.csv
# Extract attachments
mboxshell attachments mail.mbox --output ./attachments/
# Merge multiple MBOX files (duplicates are removed by default)
mboxshell merge file1.mbox file2.mbox -o merged.mbox
# Merge tagging every message with the mailbox it came from
mboxshell merge Inbox.mbox Sent.mbox -o merged.mbox --source-header
# Generate shell completions
mboxshell completions bash > /etc/bash_completion.d/mboxshell
mboxshell completions zsh > ~/.zfunc/_mboxshell
mboxshell completions fish > ~/.config/fish/completions/mboxshell.fish
CLI 命令
| Command | Description |
|---|---|
mboxshell [FILE] | 在 TUI 中打开文件(默认操作) |
mboxshell open <path> | 在 TUI 中打开 MBOX 文件 |
mboxshell index <path> [-f/--force] | 构建或重新构建二进制索引 |
mboxshell stats <path> [--json] | 显示 MBOX 文件的统计信息 |
mboxshell search <path> <query> [--json] | 从命令行搜索邮件 |
mboxshell export <path> -f <format> -o <output> [--query <q>] | 导出邮件(格式:eml、csv、txt、html) |
mboxshell merge <files...> -o <output> [--no-dedup] [--source-header] | 将多个 MBOX 文件合并为一个文件 |
mboxshell attachments <path> -o <output> | 提取所有附件 |
mboxshell completions <shell> | 生成 shell 补全(bash、zsh、fish、powershell、elvish) |
mboxshell manpage | 生成 man 手册页 |
全局标志:
| Flag | Description |
|---|---|
-f, --force | 即使索引已存在也强制重新构建 |
-v, --verbose | 提高日志详细程度(-v info、-vv debug、-vvv trace) |
--lang <en|es> | 强制指定界面语言(默认自动检测) |
合并标志:
| Flag | Description |
|---|---|
--no-dedup | 跳过重复 Message-ID 检测,并按字节逐个拼接输入文件(默认开启去重) |
--source-header | 为每封邮件注入 X-Mbox-Source: <mailbox name> 头,以便合并后的归档可以追踪到每封邮件来源的邮箱 |
来源标签即你所看到的邮箱名称:对于 Apple Mail 导出——一个名为 Inbox.mbox 的目录,里面是一个实际上叫作 mbox 的文件——它读取的是 Inbox.mbox,而不是 mbox。如果多个邮箱最终会共用同一个标签,则会相互区分(如 Work/Inbox.mbox 与 Personal/Inbox.mbox)。
终端界面

键盘快捷键
| Key | Action |
|---|---|
j / k | 下一条 / 上一条邮件 |
g / G | 第一条 / 最后一条邮件 |
PgDn / PgUp | 向下 / 向上翻页 |
Enter | 打开邮件 / 切换到邮件视图 |
Shift-↑ / Shift-↓ | 滚动所选邮件的正文(保持列表焦点);邮件边框会显示位置指示器(Top / NN% / Bot) |
Tab / Shift-Tab | 循环切换面板焦点 |
Esc | 返回列表 / 关闭弹窗 |
/ | 打开搜索栏 |
f | 打开搜索筛选弹窗 |
n / N | 下一个 / 上一个搜索结果 |
Space | 标记 / 取消标记邮件 |
* | 标记 / 取消标记全部 |
s | 循环切换排序列(日期、发件人、主题、大小) |
S | 切换排序方向 |
e | 导出邮件(EML、TXT、CSV、附件) |
a | 显示附件(j/k 导航,Enter 保存,A 全部保存) |
t | 切换线程(会话)视图 |
l | 显示 / 聚焦 / 隐藏标签侧边栏 |
h | 切换完整邮件头 |
r | 切换原始邮件内容 |
1 / 2 / 3 | 布局:仅列表 / 水平分屏 / 垂直分屏 |
? | 帮助 |
q | 退出 |
搜索语法
from:[email protected] Search by sender
to:[email protected] Search by recipient
cc:[email protected] Search by Cc recipient
subject:invoice Search in subject line
body:important text Search in message body (full-text)
filename:report.pdf Search by attachment file name
id:<message-id@domain> Search by Message-ID
has:attachment Only messages with attachments
has:no-attachment Only messages without attachments
label:Inbox Filter by Gmail label
date:2024-01 Messages from January 2024
date:2024-01-01..2024-06-30 Date range
before:2024-06-01 Before a date
after:2024-01-01 After a date
size:>1mb Messages larger than 1 MB
-subject:spam Exclude messages with "spam" in subject
"exact phrase" Search for an exact phrase
from:john subject:budget Implicit AND (both must match)
term1 OR term2 Explicit OR
支持的输入格式
| Format | Extension | Description |
|---|---|---|
| MBOX (mboxrd/mboxo) | .mbox | 标准格式。Google Takeout、Thunderbird、Unix 服务器 |
性能
使用真实的 Google Takeout MBOX 文件测试:
| File size | Messages | Indexing | Re-open |
|---|---|---|---|
| 500 MB | ~5,000 | ~3 s | < 1 s |
| 5 GB | ~50,000 | ~30 s | < 1 s |
| 50 GB | ~500,000 | ~5 min | < 1 s |
邮件列表的导航即时响应,这得益于虚拟滚动(仅渲染可见行)。
配置
配置文件位于 ~/.config/mboxshell/config.toml:
[general]
default_sort = "date"
sort_order = "desc"
date_format = "%Y-%m-%d %H:%M"
log_level = "warn"
[display]
theme = "dark"
layout = "horizontal"
show_sidebar = false
max_cached_messages = 50
[export]
default_format = "eml"
csv_separator = ","
架构
src/
+-- main.rs # CLI with clap
+-- lib.rs # Module re-exports
+-- error.rs # Error types with thiserror
+-- config.rs # TOML configuration
+-- mailbox_naming.rs # Human-facing mailbox names (Apple Mail packages)
+-- i18n/ # Internationalization (EN/ES)
+-- parser/
| +-- mbox.rs # Streaming parser (never loads the file into memory)
| +-- eml.rs # Individual EML file parser
| +-- mime.rs # MIME decoding, multipart, charsets
| +-- header.rs # RFC 5322 headers, RFC 2047 encoded-words
+-- index/
| +-- builder.rs # Binary index construction
| +-- reader.rs # Index queries
| +-- format.rs # Binary format with SHA-256 integrity check
+-- model/
| +-- mail.rs # MailEntry, MailBody
| +-- attachment.rs # Attachment metadata
| +-- address.rs # RFC 5322 address parsing
+-- store/
| +-- reader.rs # Offset-based reading with LRU cache
+-- search/
| +-- query.rs # Search query parser
| +-- metadata.rs # Fast index search (O(n), < 200ms for 1M messages)
| +-- fulltext.rs # Streaming full-text search
+-- export/
| +-- eml.rs # Export to .eml
| +-- csv.rs # Export summary to CSV (UTF-8 BOM)
| +-- text.rs # Export to plain text
| +-- attachment.rs # Attachment extraction
| +-- mbox.rs # MBOX merge with deduplication and source header
+-- tui/
+-- app.rs # Global state (Elm Architecture)
+-- event.rs # Keyboard event handling
+-- ui.rs # Layout and render dispatch
+-- threading.rs # JWZ algorithm for conversation threads
+-- theme.rs # Color theme
+-- widgets/ # Visual components
+-- mail_list.rs # List with virtual scrolling
+-- mail_view.rs # Message viewer with scroll
+-- sidebar.rs # Labels/folders panel
+-- header_bar.rs # Top bar
+-- status_bar.rs # Status bar
+-- search_bar.rs # Search bar
+-- search_popup.rs # Search filter popup
+-- help_popup.rs # Help popup
+-- attachment_popup.rs # Attachment popup
+-- export_popup.rs # Export popup
主要依赖
| Crate | Purpose |
|---|---|
ratatui + crossterm | 终端界面 |
mail-parser | MIME/RFC 5322 解析 |
encoding_rs | 字符集解码 |
chrono | 日期与时区 |
clap | CLI 参数解析 |
serde + bincode | 索引序列化 |
sha2 | 索引完整性校验 |
lru | 已解码邮件缓存 |
tracing | 结构化日志 |
赞助商
mboxshell 以开源方式开发,并由以下机构支持:
- Colorvivo —— WordPress、AI 与数字媒体领域的专家。
- Stackscale —— 私有云基础设施领域的专家。
如果你的公司觉得 mboxshell 有用,并希望支持其持续开发,请查看 .github/FUNDING.yml,或通过 carrero.es 联系我们。
文档
完整用户手册涵盖每个命令、键盘快捷键、搜索运算符、导出选项和配置项:
- docs/MANUAL.md —— 用户手册(英文)
- docs/MANUAL-ES.md —— 用户手册(西班牙语)
更新日志
完整发布历史请参阅 CHANGELOG.md。
许可证
MIT - Copyright (c) 2026 David Carrero Fernandez-Baillo - https://carrero.es