mail139
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesemail139 — 139.com Email Downloader 📬
mail139 — 139.com邮件下载工具 📬
Download and search emails from 139.com via IMAP using pure Python stdlib. No pip installs needed.
使用纯Python标准库通过IMAP协议从139.com下载和搜索邮件,无需通过pip安装依赖。
Prerequisites
前置条件
- — 139.com email address (e.g.
MAIL139_ID)you@139.com - — account password/token (fallbacks: prompt or
MAIL139_TOKEN)MAIL139_PASSWORD - If either is missing, stop and tell the user to set them:
bash
export MAIL139_ID="you@139.com" export MAIL139_TOKEN="your-password" - IMAP access must be enabled in the 139.com account settings (设置 → POP3/SMTP/IMAP)
- — 139.com邮箱地址(例如
MAIL139_ID)you@139.com - — 账户密码/令牌(备选:手动输入或使用
MAIL139_TOKEN)MAIL139_PASSWORD - 如果以上任意一项缺失,请立即停止操作并告知用户进行配置:
bash
export MAIL139_ID="you@139.com" export MAIL139_TOKEN="your-password" - 必须在139.com账户设置中开启IMAP访问权限(设置 → POP3/SMTP/IMAP)
Tool Location
工具位置
The CLI script is bundled with this skill:
{baseDir}/mail139.pyAll commands follow the pattern:
bash
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" <command> [options]该CLI脚本随此技能捆绑提供:
{baseDir}/mail139.py所有命令遵循以下格式:
bash
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" <command> [options]or simply rely on env defaults:
或直接依赖环境变量默认值:
MAIL139_ID=you@139.com MAIL139_TOKEN=secret python3 {baseDir}/mail139.py <command> [options]
undefinedMAIL139_ID=you@139.com MAIL139_TOKEN=secret python3 {baseDir}/mail139.py <command> [options]
undefinedWhen to Use This Skill
适用场景
Activate when the user wants to:
- Read, check, or view emails from their 139.com inbox
- Download or save emails to disk
- Search emails by keyword or date
- List mailbox folders on 139.com
- Export emails as JSON or files
.eml - Save email attachments from 139.com
Trigger phrases: "check my 139 email", "read my 139.com inbox", "download emails from 139", "search my 139 mail", "list my 139 folders", "save emails from 139.com", "139邮箱", "中国移动邮箱", "check inbox"
当用户有以下需求时激活此技能:
- 读取、查看139.com收件箱中的邮件
- 下载邮件并保存到本地磁盘
- 按关键词或日期搜索邮件
- 列出139.com邮箱中的文件夹
- 将邮件导出为JSON或格式文件
.eml - 保存139.com邮件中的附件
触发短语: "check my 139 email", "read my 139.com inbox", "download emails from 139", "search my 139 mail", "list my 139 folders", "save emails from 139.com", "139邮箱", "中国移动邮箱", "check inbox"
Commands Reference
命令参考
List Folders
列出文件夹
bash
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" list-foldersLists all IMAP mailboxes/folders on the account. Run this first if the user wants to fetch from a non-INBOX folder and you don't know the exact folder name.
Folder names are decoded from IMAP modified UTF-7 (handles Chinese names); copy the exact output when passing .
--folderbash
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" list-folders列出账户下所有IMAP邮箱/文件夹。如果用户需要从非收件箱文件夹获取邮件,且你不清楚具体文件夹名称,请先执行此命令。
文件夹名称会从IMAP修改版UTF-7解码(支持中文名称);传递参数时请复制命令的精确输出内容。
--folderFetch Emails
获取邮件
bash
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch [options]| Option | Default | Description |
|---|---|---|
| | IMAP folder to fetch from |
| | Max emails to fetch (newest first) |
| — | Only emails on or after this date |
| — | Filter by text in headers or body |
| | Output format: |
| — | Directory to save output files |
| off | Save attachments (defaults to |
| off | Mark fetched emails as read on the server |
For, files are written to--format eml. If--outputis omitted, the existing--outputdirectory is used. If~/Downloadsdoes not exist, the command exits with an error.~/Downloads
HTML bodies are converted to plain text via(if installed), elsehtml2text, else an internal stripper. No HTML tags appear in printed/JSON bodies.lynx --dump
Examples:
bash
undefinedbash
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch [options]| 选项 | 默认值 | 描述 |
|---|---|---|
| | 要获取邮件的IMAP文件夹 |
| | 最多获取的邮件数量(按最新排序) |
| — | 仅获取指定日期或之后的邮件 |
| — | 按邮件头或正文中的文本过滤 |
| | 输出格式: |
| — | 保存输出文件的目录 |
| 关闭 | 保存附件(如果未指定 |
| 关闭 | 将获取的邮件在服务器上标记为已读 |
若使用格式,文件会保存到--format eml指定的目录。如果未指定--output,则使用已有的--output目录。如果~/Downloads不存在,命令会报错退出。~/Downloads
HTML格式的邮件正文会转换为纯文本,优先使用(如果已安装),其次是html2text,最后使用内置的HTML剥离工具。打印或JSON输出的正文中不会包含HTML标签。lynx --dump
示例:
bash
undefinedPrint latest 10 emails to console
在控制台打印最新10封邮件
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
Fetch last 20 emails as JSON
获取最新20封邮件并以JSON格式输出
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--limit 20 --format json
--limit 20 --format json
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--limit 20 --format json
--limit 20 --format json
Save as JSON to a directory
将邮件以JSON格式保存到指定目录
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--format json -o ./emails
--format json -o ./emails
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--format json -o ./emails
--format json -o ./emails
Save raw .eml files and extract attachments
保存原始.eml文件并提取附件
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--format eml --save-attachments -o ./emails
--format eml --save-attachments -o ./emails
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--format eml --save-attachments -o ./emails
--format eml --save-attachments -o ./emails
Fetch from Sent folder since a date
从已发送文件夹获取指定日期之后的邮件
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--folder "Sent Messages" --since "01-Jan-2025" --limit 50
--folder "Sent Messages" --since "01-Jan-2025" --limit 50
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--folder "Sent Messages" --since "01-Jan-2025" --limit 50
--folder "Sent Messages" --since "01-Jan-2025" --limit 50
Search for emails containing a keyword
搜索包含指定关键词的邮件
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--search "invoice" --format json
--search "invoice" --format json
undefinedpython3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--search "invoice" --format json
--search "invoice" --format json
undefinedOutput Format Details
输出格式详情
text
texttext
格式
textPrints each email to stdout with a header block (UID, Date, From, To, Subject, Attachments) and up to 2 000 characters of body text. Ideal for quick reading.
将每封邮件的标题块(UID、日期、发件人、收件人、主题、附件)和最多2000字符的正文打印到标准输出。适合快速阅读邮件内容。
json
jsonjson
格式
jsonProduces an array of objects. Each object has:
json
{
"uid": "1234",
"date": "Mon, 10 Mar 2025 09:00:00 +0800",
"from": "sender@example.com",
"to": "you@139.com",
"subject": "Hello",
"content_type": "text/plain",
"body": "Email body text…",
"attachments": ["report.pdf"]
}Written to inside , or printed to stdout if no is given.
emails.json--output--output生成一个对象数组,每个对象结构如下:
json
{
"uid": "1234",
"date": "Mon, 10 Mar 2025 09:00:00 +0800",
"from": "sender@example.com",
"to": "you@139.com",
"subject": "Hello",
"content_type": "text/plain",
"body": "Email body text…",
"attachments": ["report.pdf"]
}会保存到目录下的文件中,如果未指定,则直接打印到标准输出。
--outputemails.json--outputeml
emleml
格式
emlSaves each email as — a raw RFC 822 file openable in any email client. Requires .
<uid>.eml--output将每封邮件保存为文件——这是符合RFC 822标准的原始邮件文件,可在任意邮件客户端中打开。使用此格式必须指定参数。
<uid>.eml--outputImportant Details
重要说明
Date Format for --since
--since--since
参数的日期格式
--sinceUse IMAP date format: — e.g. , .
DD-Mon-YYYY01-Jan-202515-Mar-2026使用IMAP标准日期格式:,例如、。
DD-Mon-YYYY01-Jan-202515-Mar-2026Folder Names
文件夹名称
139.com folder names may be in Chinese. Always run first if unsure. Common folders:
list-folders- — inbox (always English)
INBOX - — sent mail
Sent Messages - — drafts
Drafts - — trash
Deleted Messages
139.com的文件夹名称可能为中文。如果不确定,请先执行命令。常见文件夹:
list-folders- — 收件箱(始终为英文)
INBOX - — 已发送邮件
Sent Messages - — 草稿
Drafts - — 垃圾箱
Deleted Messages
Attachment Saving
附件保存规则
Attachments are saved to . If is not set, attachments default to . The flag works independently of . By default attachments are saved to ~/Downloads if is not specified.
<output>/<uid>_attachments/<filename>--output~/Downloads/<uid>_attachments/--save-attachments--output--output附件会保存到目录下。如果未指定,附件默认保存到。参数可独立于使用。默认情况下,如果未指定,附件会保存到~/Downloads目录。
<output>/<uid>_attachments/<filename>--output~/Downloads/<uid>_attachments/--save-attachments--output--outputRead-Only by Default
默认只读模式
Without , the script opens the mailbox read-only and leaves no server-side trace. Pass only if the user explicitly asks to mark emails as read.
--mark-read--mark-read如果未添加参数,脚本会以只读模式打开邮箱,不会在服务器上留下任何操作痕迹。仅当用户明确要求标记邮件为已读时,才使用参数。
--mark-read--mark-readBehavioral Rules
行为规则
- Always use to invoke the script.
python3 - Prefer env vars for credentials (,
$MAIL139_IDfallback$MAIL139_TOKEN) — never echo passwords in plain text in explanations.$MAIL139_PASSWORD - If or
MAIL139_IDare not set, stop and ask the user to export them before proceeding (or be ready to prompt for password).MAIL139_TOKEN - Default to for casual "check my email" requests; use
--format textwhen the user wants to process or save data; usejsonwhen they want to archive or open in an email client.eml - When the user asks to search, use for keyword filters and
--searchfor date filters; combine both when appropriate.--since - When the user asks for a specific folder, run first if you are unsure of the exact folder name.
list-folders - Do not use unless the user explicitly asks to mark emails as read.
--mark-read - After fetching JSON, parse and summarise the results for the user — don't just dump the raw JSON unless asked.
- If a command fails, read stderr and explain the issue in plain language (e.g. wrong password, IMAP not enabled, network error).
- For attachment tasks, works without
--save-attachments— attachments will be saved to--outputby default. Only set~/Downloads/<uid>_attachments/if the user wants a specific location.--output
- **始终使用**调用脚本。
python3 - 优先使用环境变量存储凭证(、
$MAIL139_ID,备选$MAIL139_TOKEN)——在说明中绝对不要明文显示密码。$MAIL139_PASSWORD - 如果或
MAIL139_ID未设置,请停止操作并告知用户先配置环境变量(或准备提示用户输入密码)。MAIL139_TOKEN - 默认使用格式响应用户“查看邮件”的普通请求;当用户需要处理或保存数据时使用
--format text格式;当用户需要归档或在邮件客户端中打开时使用json格式。eml - 当用户要求搜索邮件时,使用进行关键词过滤,使用
--search进行日期过滤;必要时可同时使用两个参数。--since - 当用户需要访问特定文件夹时,如果不确定文件夹的准确名称,请先执行命令。
list-folders - 除非用户明确要求,否则不要使用参数。
--mark-read - 获取JSON格式的邮件后,请解析并为用户总结结果——除非用户要求,否则不要直接输出原始JSON内容。
- 如果命令执行失败,请读取标准错误输出并以通俗易懂的语言解释问题(例如:密码错误、IMAP未开启、网络错误)。
- 处理附件相关任务时,参数可独立于
--save-attachments使用——附件会默认保存到--output。仅当用户需要保存到指定位置时,才设置~/Downloads/<uid>_attachments/参数。--output