
mboxshell v0.7.3
mboxShell。适用于任意大小 MBOX 文件的快速终端查看器。无需加载到内存,即可打开、搜索和导出 Gmail Takeout 备份(50GB+)中的电子邮件。使用 Rust 构建。
mboxShell
适用于任意大小 MBOX 文件的快速终端查看器。无需将邮件加载到内存中,即可打开、搜索和导出 Gmail Takeout 备份(50 GB+)中的邮件。
为什么会有这个项目
当你使用 Google Takeout 从 Gmail 导出邮件时,会得到一个或多个 .mbox 文件,大小可能达到数十 GB——此外,你拥有的每个 Google Group 还会多出一个邮箱,这一点很容易被忽略,而且它可能比 Gmail 导出本身还要大。目前没有跨平台的终端工具能够在不将文件完全加载到内存的情况下高效地打开、搜索和浏览这些文件。
mboxShell 就是为了解决这个问题而构建的:在几秒内打开一个 50 GB 的 MBOX,流畅地浏览数十万封邮件,按发件人、日期或内容进行搜索,并导出你需要的任何内容。一切都在终端中完成,没有 GUI,没有服务器,没有外部依赖。
使用场景
- 浏览 Gmail 备份(Google Takeout),保留其原始标签
- 阅读你拥有的群组,Takeout 会将其导出为独立的邮箱——通常是归档中最大的文件
- 分析邮件归档,用于服务器、迁移或审计场景
- 搜索邮件,支持来自任何来源的 MBOX 文件(Thunderbird、Unix 服务器等)
- 导出邮件为 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 大致相同,约为 500 MB(只有元数据索引驻留在内存中)。
- 持久化索引。 首次打开时会创建二进制索引(
.mboxshell.idx),因此后续打开耗时不到一秒。 - 完整的 Gmail 支持。 检测
X-Gmail-Labels并将其作为虚拟文件夹显示在侧边栏面板中,让你可以按收件箱、已发送、星标、自定义标签等进行筛选。 - Google Groups 邮箱。 读取 Takeout 归档为每个你拥有的群组附带的
topics.mbox文件,以群组名称而非无意义的文件名来命名它们,将群组显示为虚拟标签,并按精确的X-GM-THRIDid 对会话进行线程化。 - 正确的编码。 解码 RFC 2047 编码字,支持 UTF-8、ISO-8859-1、Windows-1252、KOI8-R,以及
encoding_rs能识别的任何字符集。 - 会话线程化。 使用 JWZ 算法(与 Netscape/Mozilla 使用的算法相同)将邮件分组为线程,或者在邮箱自身带有会话 id 时使用该 id。
- 高级搜索。 字段特定过滤(
from:、subject:、date:、body:、has:attachment、label:等)、日期范围、大小过滤、AND/OR 运算符以及取反。 - 灵活的导出。 单个或批量导出为 EML、CSV(兼容 Excel)、纯文本。解码后的附件提取。
- 单一二进制文件。 无运行时,无依赖。一个约 5 MB 的可执行文件,可在 Linux、macOS 和 Windows 上运行。
- 完整的终端 UI。 键盘导航(vi 风格)、三种布局模式、交互式搜索栏、可配置的快捷键。
- 双语。 界面提供英语和西班牙语,根据系统区域设置自动检测。
安装
预构建二进制文件(推荐)
从 Releases 页面下载适用于你平台的最新版本:
| 平台 | 二进制文件 |
|---|---|
| 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
# Hand over only part of an archive: a new mailbox with just the matches
mboxshell export mail.mbox --format mbox --query "from:[email protected]" -o handover.mbox
# 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 命令
| 命令 | 描述 |
|---|---|
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、mbox) |
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 手册页 |
全局标志:
| 标志 | 描述 |
|---|---|
-f, --force | 即使索引已存在也强制重建(在 export 中,-f 是 --format——在那里请完整拼写 --force) |
-v, --verbose | 提高日志详细程度(-v info,-vv debug,-vvv trace) |
--lang <en|es> | 强制界面语言(默认自动检测) |
合并标志:
| 标志 | 描述 |
|---|---|
--no-dedup | 跳过重复 Message-ID 检测,逐字节拼接输入(默认开启去重) |
--source-header | 向每封邮件注入 X-Mbox-Source: <mailbox name> 头,使合并后的归档可追溯到每封邮件的来源邮箱 |
来源标签是你看到的邮箱名称:对于 Apple Mail 导出——一个包含字面名为 mbox 的文件的目录 Inbox.mbox——它读取为 Inbox.mbox,而不是 mbox。最终会共享同一标签的邮箱会相互消歧(Work/Inbox.mbox 与 Personal/Inbox.mbox)。
终端 UI

键盘快捷键
| 按键 | 操作 |
|---|---|
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 (that day excluded)
after:2024-01-01 From a date on (that day included)
after:2024-01-01 before:2025-01-01 All of 2024
size:>1mb Messages larger than 1 MB
size:>1mb size:<5mb Between 1 and 5 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
from:a OR from:b subject:budget OR binds tighter: (a OR b) AND subject
支持的输入格式
| 格式 | 扩展名 | 描述 |
|---|---|---|
| MBOX (mboxrd/mboxo) | .mbox | 标准格式。Google Takeout、Thunderbird、Unix 服务器 |
| Google Groups 导出 | topics.mbox | 位于 Takeout 归档内,路径为 <group>@googlegroups.com/。文件名已本地化(temas.mbox 等),因此邮箱以群组命名——参见 docs/GOOGLE-GROUPS.md |
| Apple Mail 包 | Name.mbox/mbox | 读取的是内部文件;邮箱以包命名 |
性能
使用真实的 Google Takeout MBOX 文件测试:
| 文件大小 | 邮件数 | 索引 | 重新打开 |
|---|---|---|---|
| 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 | 用途 |
|---|---|
ratatui + crossterm | 终端 UI |
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