mail139

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

mail139 — 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

前置条件

  • MAIL139_ID
    — 139.com email address (e.g.
    you@139.com
    )
  • MAIL139_TOKEN
    — account password/token (fallbacks: prompt or
    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)
  • MAIL139_ID
    — 139.com邮箱地址(例如
    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.py
All 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]
undefined
MAIL139_ID=you@139.com MAIL139_TOKEN=secret python3 {baseDir}/mail139.py <command> [options]
undefined

When 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
    .eml
    files
  • 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-folders
Lists 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
--folder
.
bash
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" list-folders
列出账户下所有IMAP邮箱/文件夹。如果用户需要从非收件箱文件夹获取邮件,且你不清楚具体文件夹名称,请先执行此命令。 文件夹名称会从IMAP修改版UTF-7解码(支持中文名称);传递
--folder
参数时请复制命令的精确输出内容。

Fetch Emails

获取邮件

bash
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch [options]
OptionDefaultDescription
--folder <name>
INBOX
IMAP folder to fetch from
--limit <N>
10
Max emails to fetch (newest first)
--since <DD-Mon-YYYY>
Only emails on or after this date
--search <text>
Filter by text in headers or body
--format <fmt>
text
Output format:
text
,
json
, or
eml
--output <dir>
/
-o <dir>
Directory to save output files
--save-attachments
offSave attachments (defaults to
~/Downloads
if
--output
is omitted)
--mark-read
offMark fetched emails as read on the server
For
--format eml
, files are written to
--output
. If
--output
is omitted, the existing
~/Downloads
directory is used. If
~/Downloads
does not exist, the command exits with an error.
HTML bodies are converted to plain text via
html2text
(if installed), else
lynx --dump
, else an internal stripper. No HTML tags appear in printed/JSON bodies.
Examples:
bash
undefined
bash
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch [options]
选项默认值描述
--folder <name>
INBOX
要获取邮件的IMAP文件夹
--limit <N>
10
最多获取的邮件数量(按最新排序)
--since <DD-Mon-YYYY>
仅获取指定日期或之后的邮件
--search <text>
按邮件头或正文中的文本过滤
--format <fmt>
text
输出格式:
text
json
eml
--output <dir>
/
-o <dir>
保存输出文件的目录
--save-attachments
关闭保存附件(如果未指定
--output
,默认保存到
~/Downloads
--mark-read
关闭将获取的邮件在服务器上标记为已读
若使用
--format eml
格式,文件会保存到
--output
指定的目录。如果未指定
--output
,则使用已有的
~/Downloads
目录。如果
~/Downloads
不存在,命令会报错退出。
HTML格式的邮件正文会转换为纯文本,优先使用
html2text
(如果已安装),其次是
lynx --dump
,最后使用内置的HTML剥离工具。打印或JSON输出的正文中不会包含HTML标签。
示例:
bash
undefined

Print 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
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--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
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--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
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--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
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--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
undefined
python3 {baseDir}/mail139.py -u "$MAIL139_ID" -p "$MAIL139_TOKEN" fetch
--search "invoice" --format json
undefined

Output Format Details

输出格式详情

text

text
格式

Prints 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

json
格式

Produces 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
emails.json
inside
--output
, or printed to stdout if no
--output
is given.
生成一个对象数组,每个对象结构如下:
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"]
}
会保存到
--output
目录下的
emails.json
文件中,如果未指定
--output
,则直接打印到标准输出。

eml

eml
格式

Saves each email as
<uid>.eml
— a raw RFC 822 file openable in any email client. Requires
--output
.
将每封邮件保存为
<uid>.eml
文件——这是符合RFC 822标准的原始邮件文件,可在任意邮件客户端中打开。使用此格式必须指定
--output
参数。

Important Details

重要说明

Date Format for
--since

--since
参数的日期格式

Use IMAP date format:
DD-Mon-YYYY
— e.g.
01-Jan-2025
,
15-Mar-2026
.
使用IMAP标准日期格式:
DD-Mon-YYYY
,例如
01-Jan-2025
15-Mar-2026

Folder Names

文件夹名称

139.com folder names may be in Chinese. Always run
list-folders
first if unsure. Common folders:
  • INBOX
    — inbox (always English)
  • Sent Messages
    — sent mail
  • Drafts
    — drafts
  • Deleted Messages
    — trash
139.com的文件夹名称可能为中文。如果不确定,请先执行
list-folders
命令。常见文件夹:
  • INBOX
    — 收件箱(始终为英文)
  • Sent Messages
    — 已发送邮件
  • Drafts
    — 草稿
  • Deleted Messages
    — 垃圾箱

Attachment Saving

附件保存规则

Attachments are saved to
<output>/<uid>_attachments/<filename>
. If
--output
is not set, attachments default to
~/Downloads/<uid>_attachments/
. The
--save-attachments
flag works independently of
--output
. By default attachments are saved to ~/Downloads if
--output
is not specified.
附件会保存到
<output>/<uid>_attachments/<filename>
目录下。如果未指定
--output
,附件默认保存到
~/Downloads/<uid>_attachments/
--save-attachments
参数可独立于
--output
使用。默认情况下,如果未指定
--output
,附件会保存到~/Downloads目录。

Read-Only by Default

默认只读模式

Without
--mark-read
, the script opens the mailbox read-only and leaves no server-side trace. Pass
--mark-read
only if the user explicitly asks to mark emails as read.
如果未添加
--mark-read
参数,脚本会以只读模式打开邮箱,不会在服务器上留下任何操作痕迹。仅当用户明确要求标记邮件为已读时,才使用
--mark-read
参数。

Behavioral Rules

行为规则

  1. Always use
    python3
    to invoke the script.
  2. Prefer env vars for credentials (
    $MAIL139_ID
    ,
    $MAIL139_TOKEN
    fallback
    $MAIL139_PASSWORD
    ) — never echo passwords in plain text in explanations.
  3. If
    MAIL139_ID
    or
    MAIL139_TOKEN
    are not set
    , stop and ask the user to export them before proceeding (or be ready to prompt for password).
  4. Default to
    --format text
    for casual "check my email" requests; use
    json
    when the user wants to process or save data; use
    eml
    when they want to archive or open in an email client.
  5. When the user asks to search, use
    --search
    for keyword filters and
    --since
    for date filters; combine both when appropriate.
  6. When the user asks for a specific folder, run
    list-folders
    first if you are unsure of the exact folder name.
  7. Do not use
    --mark-read
    unless the user explicitly asks to mark emails as read.
  8. After fetching JSON, parse and summarise the results for the user — don't just dump the raw JSON unless asked.
  9. If a command fails, read stderr and explain the issue in plain language (e.g. wrong password, IMAP not enabled, network error).
  10. For attachment tasks,
    --save-attachments
    works without
    --output
    — attachments will be saved to
    ~/Downloads/<uid>_attachments/
    by default. Only set
    --output
    if the user wants a specific location.
  1. **始终使用
    python3
    **调用脚本。
  2. 优先使用环境变量存储凭证
    $MAIL139_ID
    $MAIL139_TOKEN
    ,备选
    $MAIL139_PASSWORD
    )——在说明中绝对不要明文显示密码。
  3. 如果
    MAIL139_ID
    MAIL139_TOKEN
    未设置
    ,请停止操作并告知用户先配置环境变量(或准备提示用户输入密码)。
  4. 默认使用
    --format text
    格式
    响应用户“查看邮件”的普通请求;当用户需要处理或保存数据时使用
    json
    格式;当用户需要归档或在邮件客户端中打开时使用
    eml
    格式。
  5. 当用户要求搜索邮件时,使用
    --search
    进行关键词过滤,使用
    --since
    进行日期过滤;必要时可同时使用两个参数。
  6. 当用户需要访问特定文件夹时,如果不确定文件夹的准确名称,请先执行
    list-folders
    命令。
  7. 除非用户明确要求,否则不要使用
    --mark-read
    参数。
  8. 获取JSON格式的邮件后,请解析并为用户总结结果——除非用户要求,否则不要直接输出原始JSON内容。
  9. 如果命令执行失败,请读取标准错误输出并以通俗易懂的语言解释问题(例如:密码错误、IMAP未开启、网络错误)。
  10. 处理附件相关任务时
    --save-attachments
    参数可独立于
    --output
    使用——附件会默认保存到
    ~/Downloads/<uid>_attachments/
    。仅当用户需要保存到指定位置时,才设置
    --output
    参数。