Mailstream
Overview
MailStream is an asynchronous IMAP email client built with aioimaplib. It supports streaming emails, polling for updates, and broadcasting new emails to listeners.
Features
- Asynchronous IMAP connection
- Fetch unseen emails
- Broadcast new emails to subscribers
- Easily integrate with context management
Installation
pip install mailstream
Quick Start
import asyncio
from mailstream import MailStreamClient, Config
async def process_email(mail):
print(f"New email from: {mail.from_email}")
print(f"Subject: {mail.subject}")
config = Config(
host="imap.example.com",
port=993,
email="your_email@example.com",
password="your_password",
debug=True
)
async def main():
client = MailStreamClient(config)
await client.connect()
# Start wait_for_updates in the background
asyncio.create_task(client.wait_for_updates())
# Subscribe to new emails
listener = client.subscribe()
# Process emails from listener
while True:
mail = await listener.get()
await process_email(mail)
# Close connection
await client.close()
asyncio.run(main())
Configuration Options
host: IMAP server hostname (required)email: Login email (required)password: Login password (required)port: IMAP server port (default: 993)mailbox: Target mailbox (default: 'INBOX')debug: Enable debug mode (default: False)
Advanced Usage
Fetching Unseen Mails
# Retrieve all unseen emails
unseen_mails = client.get_unseen_mails()
for mail in unseen_mails:
print(mail.subject)
Multiple Listeners
async def listener1(mail):
print("Listener 1 received:", mail.subject)
async def listener2(mail):
print("Listener 2 received:", mail.subject)
listener1_queue = client.subscribe()
listener2_queue = client.subscribe()
Waiting for New Emails
await client.wait_for_updates()
Examples
For more examples, including advanced usage, please see the examples directory.
Error Handling
from mailstream import ConnectionError, AuthenticationError
try:
client = MailStreamClient(
host='imap.example.com',
port=993,
email='your_email@example.com',
password='your_password',
debug=True
)
await client.connect()
except (ConnectionError, AuthenticationError) as e:
print(f"Connection failed: {e}")
Contributing
Contributions are welcome! Please see our contributing guidelines for more details.
License
Support
For issues, please open a GitHub issue in the repository.
Metadata
Release files for mailstream 0.1.6
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 | Actions |
|---|---|---|---|---|
| mailstream-0.1.6.tar.gz | 10.2 kB | With provenance | Details for mailstream-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mailstream-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for mailstream-0.1.6-py3-none-any.whl |
Total release size: 18.2 kB
Release files / mailstream-0.1.6.tar.gz
| Download URL | mailstream-0.1.6.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6bb048942cc6a7687cbc638781741ad9fe740c03bd861dfc0c9a3b7a4db4281b
|
|
BLAKE2b-256 checksum How to use checksums |
8f1c9bb72342f937889708b2d6a45eadc07f2731ec5fec8e997ab2862932fb80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 16, 2024.
Transparency logRelease files / mailstream-0.1.6-py3-none-any.whl
| Download URL | mailstream-0.1.6-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c134bbaf4565c35a608cfdd27611b67a6cc9b54eefef76ecfd151322ed4db95b
|
|
BLAKE2b-256 checksum How to use checksums |
5a3f50a36a7160d4e06c894c75dfa5532f78515af64a53fabc1481d4d7a84289
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 16, 2024.
Transparency logSecurity for mailstream 0.1.6
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mailstream-0.1.6.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 16, 2024.
Transparency logA 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.