This Rust program downloads email attachments (specifically images) from a specified sender using IMAP. It connects to the IMAP server securely using TLS, searches for emails from or to a given sender, and saves image attachments to a specified directory.
- Prompts for IMAP configuration (email, password, server, sender email, download directory) if a configuration file is not found.
- Connects securely to the IMAP server using TLS.
- Supports searching emails by sender (both "FROM" and "TO" fields).
- Downloads image attachments (JPEG/JPG) from the emails and saves them locally.
- Supports parallel processing of emails in batches for better performance.
This program uses the following Rust crates:
async-imap
: For IMAP communication.async-native-tls
: For secure TLS connections.tokio
: For asynchronous runtime.futures
: For asynchronous stream processing.mailparse
: For parsing email messages.serde
,toml
: For configuration file handling.dialoguer
: For interactive prompts.anyhow
: For error handling.
The configuration is stored in a config.toml
file, which includes the following fields:
email = "[email protected]"
password = "your-password"
sender = "[email protected]"
server = "imap.example.com"
download_dir = "./downloaded_images"
email = "[email protected]"
password = "password123"
sender = "[email protected]"
server = "imap.gmail.com"
download_dir = "./attachments"
If the file does not exist, the program will prompt the user to enter the required settings and save them.
- Ensure Rust and Cargo are installed on your system.
- Clone this repository or copy the code into a Rust project.
- Run the following command to build and run the program:
cargo run --release
- Follow the prompts to enter your email configuration if
config.toml
does not exist.
- Connection: The program establishes a secure IMAP connection using TLS.
- Mailbox Selection: It lists available mailboxes and selects the one containing all emails.
- Search: It searches for emails from or to the specified sender.
- Attachment Extraction: It parses the emails and extracts image attachments (JPEG/JPG).
- Download: The attachments are saved to the specified download directory.
- Currently, it only supports downloading image attachments with the MIME type
image/jpeg
orimage/jpg
. - The IMAP server must support TLS for a secure connection.
- Authentication is done via email and password; OAuth is not supported.
- Add support for OAuth authentication.
- Improve MIME type detection for a wider range of attachments.
- Add support for more mailbox flags and folder selection.
This project is licensed under the MIT License. Feel free to use and modify it as per your needs.
Contributions are welcome! Please submit a pull request or open an issue for any feature requests or bug reports.