Async IMAP client for streaming email messages
Project description
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()
# 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(poll_interval=10.0)
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mailstream-0.1.2.tar.gz.
File metadata
- Download URL: mailstream-0.1.2.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40088c1ecb06678a84d09bc59c5bb66c7ecb7264c1cb2219afe47c823efefd8e
|
|
| MD5 |
dbfc505fd52048e966c0df7ce2d9a568
|
|
| BLAKE2b-256 |
7f9f06e11e654109208c5d599b9daa11aa013f68c8e5ca2c82f6050d0f00503d
|
Provenance
The following attestation bundles were made for mailstream-0.1.2.tar.gz:
Publisher:
python-publish.yml on christianobora/mailstream
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mailstream-0.1.2.tar.gz -
Subject digest:
40088c1ecb06678a84d09bc59c5bb66c7ecb7264c1cb2219afe47c823efefd8e - Sigstore transparency entry: 153849188
- Sigstore integration time:
-
Permalink:
christianobora/mailstream@c27a809168f2b1cc0884589fb5f650934fa3b330 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/christianobora
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c27a809168f2b1cc0884589fb5f650934fa3b330 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mailstream-0.1.2-py3-none-any.whl.
File metadata
- Download URL: mailstream-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcf3c116f6374a966764e1aaa743aaaf48d1ab33ab890b03db7473ebf907f8a2
|
|
| MD5 |
75b81b210226731cbbf1d3f9c687392a
|
|
| BLAKE2b-256 |
d2897158d01e2b0f6becb0f65f71366e26d107baf6da027cd3e365a0af4ef8ab
|
Provenance
The following attestation bundles were made for mailstream-0.1.2-py3-none-any.whl:
Publisher:
python-publish.yml on christianobora/mailstream
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mailstream-0.1.2-py3-none-any.whl -
Subject digest:
fcf3c116f6374a966764e1aaa743aaaf48d1ab33ab890b03db7473ebf907f8a2 - Sigstore transparency entry: 153849189
- Sigstore integration time:
-
Permalink:
christianobora/mailstream@c27a809168f2b1cc0884589fb5f650934fa3b330 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/christianobora
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c27a809168f2b1cc0884589fb5f650934fa3b330 -
Trigger Event:
release
-
Statement type: