eml_rename project
Script that renames .eml email files in a directory or by specific path using email metadata (Date, From, Subject).
Idea
I needed this tool to classify and order my email files at work. I took this idea from an article by Armand Niculescu (August 20, 2014) at https://www.media-division.com/using-python-to-batch-rename-email-files/ , so thanks and I hope you like this code.
Installation
pip install eml_rename
Features
- Automatic Metadata Renaming: Extracts date, time, sender, and subject to generate filenames in the format:
YYYYMMDD HHMM [From] Subject.eml. - Target Single File, Directory, or Current Working Directory: By default processes all
*.emlfiles in the current working directory, or you can pass an optional path to a specific file or directory. - Directory Preservation: Renamed files stay in their original folder, even when targeting files in subdirectories or absolute paths.
- Safe Simulation by Default: Previews changes without renaming unless
--saveis specified. - Protects Manual Edits: If a file already has the
YYYYMMDD HHMM [From]format, the script won't overwrite manual edits to the subject unless--forceis used. - Gemini AI Subject Summarization (
--ai): Summarizes email content into concise subjects using Google Gemini models, optimized for low token consumption. - Model Selection & Persistence: List available models (
--ai_models) and save your preferred model in configuration (--ai_model MODEL). - Concurrent Processing: Uses multi-threading to process large archives fast.
Usage & Examples
1. Simulation (Default)
Run in the current directory to preview changes without modifying files:
eml_rename
2. Rename All Emails in Current Directory
Use --save to apply the renames:
eml_rename --save
3. Rename a Specific File or Directory
Pass a path to a single .eml file or a directory:
# Specific file
eml_rename path/to/email.eml --save
# Specific directory
eml_rename /path/to/archive/ --save
4. Force Overwriting Already Renamed Files
eml_rename --force --save
5. Custom Maximum Length
Set a custom length for generated filenames (default is 140 characters):
eml_rename --length 160 --save
6. AI-Powered Subject Summarization
Use Gemini AI to summarize the email content into a concise subject:
eml_rename --ai --save
AI Configuration (Optional)
To use the AI subject generation feature (--ai), a Google Gemini API Key is required.
1. Set API Key
Option A: Environment Variable
export GOOGLE_API_KEY='your_api_key_here'
Option B: Configuration File
Create a file in ~/.config/eml-rename/config.ini:
[auth]
GOOGLE_API_KEY = your_api_key_here
[ai]
model_name = gemini-2.5-flash
delay = 2
2. Manage AI Models
-
List available models:
eml_rename --ai_models -
Change and save your preferred model:
eml_rename --ai_model gemini-2.5-flash
(This automatically saves the model to your
config.iniso you don't need to specify it every time). -
Automatic Fallback: If a configured model becomes unavailable or deprecated,
eml_renamewarns you and falls back automatically togemini-2.5-flash.
Command-Line Options
| Option | Description |
|---|---|
path |
Optional path(s) to .eml file(s) or directory. Defaults to current directory. |
--save |
Actually rename files (default is simulation mode). |
--force |
Force subject update even if YYYYMMDD HHMM [From] format is already detected. |
--length LENGTH |
Maximum filename length (default: 140). |
--ai |
Use Google Gemini AI to summarize email content as subject. |
--ai_delay AI_DELAY |
Delay in seconds between AI requests (default: 2). |
--ai_models, --ai-models |
List available Gemini models for content generation and exit. |
--ai_model MODEL, --ai-model MODEL |
Specify Gemini model to use and persist it in configuration. |
--version |
Show program's version number and exit. |
-h, --help |
Show help message and exit. |
Metadata
Release files for eml-rename 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| eml_rename-1.2.0.tar.gz | 41.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| eml_rename-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 107.7 kB
Release files / eml_rename-1.2.0.tar.gz
| Download URL | eml_rename-1.2.0.tar.gz |
|---|---|
| Size | 41.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c86d2642f02f599b30d9bb31d6fe379fb5f761790ed9d329773496f25c14ccb1
|
|
BLAKE2b-256 checksum How to use checksums |
2437776c9b7433144c7f38fa5964e126d4dfe4aaba3c967b25475a96a98fcadf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.2 CPython/3.14.7 Linux/7.2.0-gentoo
|
Release files / eml_rename-1.2.0-py3-none-any.whl
| Download URL | eml_rename-1.2.0-py3-none-any.whl |
|---|---|
| Size | 66.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6e67cbcd773859c23f3fe00c22761b985d594e3268eb8771e2b4080d884ae5a6
|
|
BLAKE2b-256 checksum How to use checksums |
737fdefbff27ff8aa3e21a101c7ce40b595d24f6a6c411676ebb75645f09841e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.2 CPython/3.14.7 Linux/7.2.0-gentoo
|