腾讯企业邮箱 IMAP 命令行客户端
Project description
qqmail-cli
腾讯企业邮箱 IMAP 命令行客户端,用于搜索邮件、查看正文、下载附件。
核心亮点
- 零配置登录 —
.env文件管理账号密码,一条命令验证连通性 - 智能搜索兼容 — 腾讯企业邮箱 IMAP 的
FROM/SUBJECT搜索存在服务端缺陷,本工具采用SINCE日期搜索 + 本地二次过滤的策略绕过,确保结果准确 - 中文文件夹名自动解码 — Modified UTF-7 编码的文件夹名(如
&UXZO1mWHTvZZOQ-)自动解码为中文(如其他文件夹) - 纯标准库 IMAP 通信 — 不依赖第三方 IMAP 库,减少兼容性问题
- 分批拉取 — 大量邮件自动分批请求,避免超时
安装
依赖 uv 管理 Python 环境和依赖:
cd python-script
uv sync
配置
在项目根目录创建 .env 文件:
IMAP_HOST=imap.exmail.qq.com
IMAP_PORT=993
IMAP_USER=your_email@example.com
IMAP_PASSWORD=your_password_or_app_token
使用方法
所有命令通过 uv run main.py 执行:
检查登录
uv run main.py check
列举邮箱文件夹
uv run main.py folders
输出示例:
其他文件夹 (&UXZO1mWHTvZZOQ-)
Deleted Messages
Drafts
Sent Messages
INBOX
搜索邮件
--since 为必填参数,用于限定时间范围。--from 和 --subject 为可选的二次过滤条件。
# 搜索本周所有邮件
uv run main.py search --since 2026-04-13
# 按发件人过滤
uv run main.py search --since 2026-04-13 --from sender@example.com
# 按主题关键词过滤
uv run main.py search --since 2026-04-13 --subject 周报
# 组合过滤 + 限制数量
uv run main.py search --since 2026-04-13 --before 2026-04-20 \
--from sender@example.com --subject 周报 --limit 5
# 指定文件夹
uv run main.py search --since 2026-04-01 --folder "Sent Messages"
输出示例:
搜索条件: SINCE 2026-04-13, FROM sender@example.com, SUBJECT 含「周报」, 文件夹: INBOX
共 1 封匹配邮件:
--- ID: 1555 ---
主题: 项目周报 (2026.4.18)
发件人: sender@example.com <sender@example.com>
日期: Sat, 18 Apr 2026 14:58:04 +0800
获取邮件正文
使用 search 获取到的邮件 ID 来查看正文内容:
uv run main.py body 1555
正文按 MIME 结构输出纯文本和 HTML 两个部分。指定文件夹:
uv run main.py body 1555 --folder "Sent Messages"
下载附件
# 下载到指定目录
uv run main.py download 1555 -o /tmp/attachments
输出示例:
找到 2 个附件:
周报.xlsx (15360 bytes, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
截图.png (82456 bytes, image/png)
已下载 2 个附件到 /tmp/attachments:
/tmp/attachments/周报.xlsx
/tmp/attachments/截图.png
命令速查
| 命令 | 说明 |
|---|---|
check |
验证登录信息 |
folders |
列举邮箱文件夹 |
search |
搜索邮件(--since 必填) |
body <msg_id> |
获取邮件正文 |
download <msg_id> |
下载邮件附件(-o 指定目录) |
已知问题
腾讯企业邮箱 IMAP 服务端的 SEARCH FROM 和 SEARCH SUBJECT 指令无法正确过滤结果(返回全部邮件),本工具通过以下策略绕过:
- 使用服务端可靠的
SINCE/BEFORE日期搜索缩小范围 - 批量拉取候选邮件的头部字段
- 在客户端本地完成发件人和主题的过滤
许可证
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qqmail_cli-0.1.0.tar.gz.
File metadata
- Download URL: qqmail_cli-0.1.0.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce8bc10f20ac45b16607ae6bc54033ec6175683a3d62b6b330d5e31267236a3b
|
|
| MD5 |
b8854e1e20755c39b36a02bef0899cde
|
|
| BLAKE2b-256 |
560708d3f1f19759384880e2c4b13b758ff8ab50e01afe45c7237101443b7f9b
|
File details
Details for the file qqmail_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: qqmail_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b5e6443c5aa25ead925ea7d10c257c75df6389c0680c40c56cbb8b03e8c9ce3
|
|
| MD5 |
54c8ff5a8b5a9590120968cf2ebb3592
|
|
| BLAKE2b-256 |
7661b5013092c2dc0bc8278e5ffee0bcbc8346dd59d1ae6858aff82421108952
|