Metadata-Version: 2.4
Name: Emlex
Version: 1.1.1
Summary: Download billing files from email with configurable providers
Author-email: Your Name <your.email@example.com>
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: typer>=0.9.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: imap_tools
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: requests>=2.31.0
Requires-Dist: beautifulsoup4>=4.12.0
Requires-Dist: lxml>=5.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"

# Emlex

Emlex 从邮箱中查找支付宝、微信等账单邮件，并把附件或邮件中的下载链接保存到本地。

## 安装

项目要求 Python 3.10 及以上版本：

```bash
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"
```

安装后使用 `em` 命令，也可以在源码目录运行 `python -m cli.main`。

## 交互式添加邮箱

启动终端配置向导：

```bash
em ui
```

旧命令 `em config email add` 仍可继续使用。

向导支持：

- Gmail（建议使用应用专用密码）；
- 任意支持 SSL 的 IMAP 邮箱；
- 支付宝和微信账单配置；
- 更新已有邮箱时保留下载方式和账单匹配规则；
- 密码隐藏输入、写入前确认以及 `0600` 配置文件权限。

如果不希望把密码直接写入 JSON，可保存环境变量引用：

```bash
em ui \
  --provider alipay \
  --email-type gmail \
  --username you@example.com \
  --password-env EMLEX_EMAIL_PASSWORD
```

然后在 `~/.flow/.env` 中设置密码：

```dotenv
EMLEX_EMAIL_PASSWORD=your-app-password
```

自定义 IMAP 示例：

```bash
em ui \
  --provider wechat \
  --email-type imap \
  --username you@example.com \
  --host imap.example.com \
  --port 993
```

默认配置文件为 `~/.flow/config.json`。开发和测试时可通过 `--config` 指定其他路径。

## 下载账单

```bash
em download --provider alipay
em download --provider wechat
```

使用其他配置文件：

```bash
em download --provider alipay --config /path/to/config.json
```

首次添加邮箱时，向导会生成可用的最小 provider 配置。你可以继续编辑 `profile` 来精确匹配邮件：

```json
{
  "alipay": {
    "email": "gmail",
    "auth_type": "pass",
    "auth": {
      "username": "you@example.com",
      "password": "${EMLEX_EMAIL_PASSWORD}"
    },
    "download": "attachment",
    "profile": {
      "name": "alipay",
      "search_subject": "支付宝",
      "sender_email": "service@example.com",
      "file_suffix": "zip",
      "encoding": "gbk"
    }
  }
}
```

`download` 可设为 `attachment`（兼容旧拼写 `attchment`）或 `link`。下载文件默认保存在 `~/.flow/data/<provider>/`。

## 测试

```bash
python -m pytest
```
