📧 amelis-smime-decrypt
A Python library and CLI tool that connects to an IMAP email mailbox, fetches S/MIME encrypted emails, decrypts them using a P12/PFX certificate, and extracts PDF attachments with intelligent deduplication and flexible post-processing.
🚀 Features
✔️ IMAP Integration - Connect to any IMAP email server
✔️ S/MIME Decryption - Decrypt emails using P12/PFX certificates (RSA-OAEP support)
✔️ Subject Filtering - Fetch emails matching specific keywords
✔️ Deduplication - Automatically handle duplicate emails (same subject)
✔️ Flexible Actions - Mark as seen, delete, or move emails after processing
✔️ CLI + Library - Use as standalone tool or import as Python library
✔️ PDF Data Extraction - Extract patient data from PDFs and rename files with flexible patterns
📦 Installation
For Users
pip install amelis-smime-decrypt
For Development
Prerequisites (Linux/Debian)
sudo apt-get install libssl-dev swig python3-dev gcc python3-virtualenv
Clone and Setup
git clone https://github.com/nerdocs/amelis-smime-decrypt.git
cd amelis-smime-decrypt
# Using uv (recommended)
uv venv
. .venv/bin/activate # or: source .venv/bin/activate
uv sync
# Or using pip
pip install -e ".[dev]"
🔑 Configuration
Using .env File
Create an .env file from the template:
cp .env.example .env
Edit the configuration:
# IMAP Configuration
IMAP_SERVER=imap.example.com
IMAP_PORT=993
EMAIL_ACCOUNT=info@example.com
EMAIL_PASSWORD=supersecretpassword
# S/MIME Certificate (P12/PFX format)
P12_CERTIFICATE_PATH=./certificate.p12
PFX_PASSWORD=your_certificate_password
# Output Configuration
SAVE_DIRECTORY=./output
SUBJECT_KEYWORD="Auftrag"
# Email Post-Processing
EMAIL_ACTION=mark_seen # Options: mark_seen | delete | move:FolderName
DUPLICATE_ACTION=mark_seen # Action for older duplicate emails
# PDF Renaming Pattern (optional)
# Available variables: {last_name}, {first_name}, {birth_date}, {barcode_number},
# {samplecollectiondate}, {receiptdate}, {finalreport}, etc.
RENAME_PATTERN="{last_name}_{first_name}_{birth_date}_{barcode_number}.pdf"
Using CLI Arguments (Override .env)
All settings can be overridden via command-line arguments:
amelis-smime-decrypt \
--imap-server imap.example.com \
--imap-port 993 \
--imap-user user@example.com \
--imap-pass secret \
--cert certificate.p12 \
--password pfx_pass \
--subject "Order" \
--output ./orders \
--email-action delete \
--duplicate-action "move:Archive"
🛠️ Usage
Basic Usage
Run with default configuration from .env:
amelis-smime-decrypt
With Custom Arguments
amelis-smime-decrypt --subject "Auftrag" --output ./output_directory
Get Help
amelis-smime-decrypt --help
How It Works
- Connects to IMAP server with provided credentials
- Fetches emails matching the subject keyword
- Deduplicates emails with same subject (keeps latest)
- Decrypts S/MIME encrypted messages
- Extracts PDF attachments
- Renames PDFs based on extracted data (if pattern configured)
- Performs configured action (mark seen/delete/move)
📂 Output
Extracted PDFs are saved to SAVE_DIRECTORY (default: ./output/):
output/
├── Mueller_Hans_01.01.1980_BC123456.pdf
├── Schmidt_Anna_15.05.1975_BC789012.pdf
Security Considerations
- Protect your certificate: Keep P12/PFX files secure, never commit to version control
- Use environment variables: Store credentials in
.env(add to.gitignore) - Limit IMAP access: Use app-specific passwords when available
- Secure storage: Restrict file permissions on certificates and
.env
🧪 Development
Commands
# Run with arguments
amelis-smime-decrypt --subject "Auftrag" --output ./output_directory
# Format code
black src/
# Run tests
pytest
# Run tests with coverage
pytest --cov=amelis_smime_decrypt --cov-report=term-missing
# Verbose test output
pytest -v
📚 Architecture
Modular library structure in src/amelis_smime_decrypt/:
Core Modules
- certificate.py -
SMIMECertificateclass for P12/PFX certificate loading - imap.py -
MailboxClientclass for IMAP operations with context manager support - smime.py -
decrypt_email()function for S/MIME decryption - attachment.py -
extract_attachments()function for PDF extraction - cli.py - CLI entry point with argparse support
Key Dependencies
- endesive - S/MIME decryption (RSA-OAEP support)
- cryptography - Certificate/key handling
- imapclient - IMAP protocol wrapper
- python-dotenv - Environment configuration
- pypdf - PDF data extraction
📝 License
This project is licensed under the GPL v3.0 License or later.
🤝 Contributing
Pull requests are welcome! Feel free to fork and submit PRs.
📧 Support
For issues, please open a GitHub Issue.
Metadata
Release files for amelis-smime-decrypt 0.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 | Provenance | |
|---|---|---|---|---|
| amelis_smime_decrypt-0.2.0.tar.gz | 13.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| amelis_smime_decrypt-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.4 kB
Release files / amelis_smime_decrypt-0.2.0.tar.gz
| Download URL | amelis_smime_decrypt-0.2.0.tar.gz |
|---|---|
| Size | 13.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2b2e4ad0ca247cb6960e1a0c50766305275049633d6404145196e88f69c577c
|
|
BLAKE2b-256 checksum How to use checksums |
5b012ef99b508b0ad43d3f1171db2d9627c97aed32350b8296d2f7c44e256a4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"KDE neon","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / amelis_smime_decrypt-0.2.0-py3-none-any.whl
| Download URL | amelis_smime_decrypt-0.2.0-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2a07c34ddca833a2f961a106418f02d9f049579f2c4440bb85db837603ee8df
|
|
BLAKE2b-256 checksum How to use checksums |
0c408b655a557bfc110414686c64355022bfc79d0e4a377316fa6979d2fc0e4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"KDE neon","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for amelis-smime-decrypt 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.